Skip to content

Commit 8666f62

Browse files
committed
fix(hooks): reach the global injector as a last resort in @hook
A class migrated off property injection has neither $hooksService nor $injector, so the decorator threw at hook-execution time. The global injector must stay last in the chain - tests stub the instance properties and rely on them winning.
1 parent be97b39 commit 8666f62

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lib/common/helpers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,19 @@ export function decorateMethod(
558558
};
559559
}
560560

561+
/**
562+
* @deprecated Emits the param-name hook payload contract (keyed off the
563+
* decorated method's parameter names); slated for replacement by a typed
564+
* hook API.
565+
*/
561566
export function hook(commandName: string) {
562567
function getHooksService(self: any): IHooksService {
563568
let hooksService: IHooksService = self.$hooksService;
564569
if (!hooksService) {
565-
const injector = self.$injector;
570+
// The global injector must stay the LAST resort: tests stub
571+
// self.$hooksService / self.$injector, and a class migrated off
572+
// property injection has neither — only then may the global be used.
573+
const injector = self.$injector || (<any>global).$injector;
566574
if (!injector) {
567575
throw Error(
568576
"Type with hooks needs to have either $hooksService or $injector injected.",
@@ -850,6 +858,12 @@ const FN_NAME_AND_ARGS =
850858
const FN_ARG_SPLIT = /,/;
851859
const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
852860

861+
/**
862+
* @deprecated Discovers dependencies by regex-parsing constructor source text —
863+
* the reason tests must run against tsc output and the CLI can never be
864+
* bundled. Kept only for the legacy provider kind and param-name hook
865+
* injection; never add new callers.
866+
*/
853867
export function annotate(fn: any) {
854868
let $inject: any, fnText: string, argDecl: string[];
855869

0 commit comments

Comments
 (0)