diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index 9146378..eb629af 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -4,6 +4,8 @@ import ReflectService from './reflect.ts' import Registry from './registry.ts' import { getTraceable, resolveConfig, symbols } from './utils.ts' +export { Lifecycle, ReflectService, Registry } + export namespace Context { export type Parameterized = C & { config: T } diff --git a/packages/core/src/reflect.ts b/packages/core/src/reflect.ts index 28e0b01..8e884bc 100644 --- a/packages/core/src/reflect.ts +++ b/packages/core/src/reflect.ts @@ -27,7 +27,7 @@ class ReflectService { return [name, internal] as const } - static checkInject(ctx: Context, name: string) { + static checkInject(ctx: Context, name: string, error: Error) { ctx = ctx[symbols.shadow] ?? ctx // Case 1: built-in services and special properties // - prototype: prototype detection @@ -39,8 +39,7 @@ class ReflectService { if (!ctx.runtime.plugin) return // Case 4: custom inject checks if (ctx.bail(ctx, 'internal/inject', name)) return - const warning = new Error(`property ${name} is not registered, declare it as \`inject\` to suppress this warning`) - ctx.emit(ctx, 'internal/warning', warning) + ctx.emit(ctx, 'internal/warning', error) } static handler: ProxyHandler = { @@ -52,13 +51,18 @@ class ReflectService { } const [name, internal] = ReflectService.resolveInject(ctx, prop) + // trace caller + const error = new Error(`property ${name} is not registered, declare it as \`inject\` to suppress this warning`) + const lines = error.stack!.split('\n') + lines.splice(1, 1) + error.stack = lines.join('\n') if (!internal) { - ReflectService.checkInject(ctx, name) + ReflectService.checkInject(ctx, name, error) return Reflect.get(target, name, ctx) } else if (internal.type === 'accessor') { return internal.get.call(ctx, ctx[symbols.receiver]) } else { - if (!internal.builtin) ReflectService.checkInject(ctx, name) + if (!internal.builtin) ReflectService.checkInject(ctx, name, error) return ctx.reflect.get(name) } },