Skip to content

Commit babff18

Browse files
committed
fix(hooks): only trace hooks that use param-name service injection
A hook declaring nothing but hookArgs (or no parameters) already follows the recommended pattern - resolving services through the typed container - and must not be reported as deprecated usage.
1 parent 6d4d45e commit babff18

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

lib/common/services/hooks-service.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,19 @@ export class HooksService implements IHooksService {
246246
projectDataHookArg;
247247
}
248248

249-
reportDeprecation({
250-
api: "hooks.param-name-signature",
251-
detail: hook.fullPath,
252-
logger: this.$logger,
253-
});
249+
// Only param-name *service* injection is on the deprecation track; a
250+
// hook declaring nothing but `hookArgs` (or no parameters) already
251+
// follows the recommended pattern and must not be flagged.
252+
const usesParamNameInjection = (<string[]>(
253+
hookEntryPoint.$inject.args
254+
)).some((argument) => argument !== this.hookArgsName);
255+
if (usesParamNameInjection) {
256+
reportDeprecation({
257+
api: "hooks.param-name-signature",
258+
detail: hook.fullPath,
259+
logger: this.$logger,
260+
});
261+
}
254262

255263
const maybePromise = this.$injector.resolve(
256264
hookEntryPoint,

test/compat/legacy-hooks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ describe("legacy hook contract", () => {
138138
});
139139

140140
assert.deepEqual(args, ["assembleDebug", "--offline"]);
141+
// A hookArgs-only signature is the recommended pattern and must not be
142+
// reported as param-name injection.
143+
assert.notInclude(logger().traceOutput, "hooks.param-name-signature");
141144
});
142145

143146
it("treats a rejection carrying stopExecution + errorAsWarning as a warning, not a failure", async () => {

0 commit comments

Comments
 (0)