Skip to content

Commit d6aa091

Browse files
authored
fix: fix file path for advice decorator (#64)
1 parent de0d2cd commit d6aa091

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

core/aop-decorator/src/decorator/Advice.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
EggProtoImplClass,
44
ObjectInitType,
55
Prototype,
6-
PrototypeParams,
6+
PrototypeParams, PrototypeUtil,
77
} from '@eggjs/core-decorator';
88
import { AdviceInfoUtil } from '../util/AdviceInfoUtil';
9+
import { StackUtil } from '@eggjs/tegg-common-util';
910

1011
export interface AdviceContext<T = object> {
1112
that: T;
@@ -62,5 +63,6 @@ export function Advice(param?: PrototypeParams) {
6263
...param,
6364
});
6465
func(constructor);
66+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
6567
};
6668
}

core/aop-decorator/test/AspectMetaBuilder.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
PointcutAdviceOverwriteChildExample,
2222
PointcutAdviceOverwriteParentExample,
2323
} from './fixtures/InheritExample';
24+
import { PrototypeUtil } from '@eggjs/core-decorator';
2425

2526
describe('test/AspectMetaBuild.test.ts', () => {
2627
const crosscutAdviceFactory = new CrosscutAdviceFactory();
@@ -133,4 +134,9 @@ describe('test/AspectMetaBuild.test.ts', () => {
133134
const aspects = builder.build();
134135
assert(aspects.length === 1);
135136
});
137+
138+
it('should has right file path', () => {
139+
const filePath = PrototypeUtil.getFilePath(CrosscutClassAdviceExample);
140+
assert(filePath === require.resolve('./fixtures/CrosscutExample'));
141+
});
136142
});

0 commit comments

Comments
 (0)