feat(hooks): defineHook — typed hook authoring with ctx payload/wrap/abort - #6100
Draft
edusperoni wants to merge 2 commits into
Draft
feat(hooks): defineHook — typed hook authoring with ctx payload/wrap/abort#6100edusperoni wants to merge 2 commits into
edusperoni wants to merge 2 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
edusperoni
force-pushed
the
feat/define-hook
branch
4 times, most recently
from
July 30, 2026 02:25
d75fed7 to
514c272
Compare
Hook authors can now export a definition built with defineHook instead
of a plain function whose shape the CLI has to infer. The handler takes
a context object with the operation payload, an explicit wrap() for
middleware around the hooked method, and abort() for stopping the hook
as either a failure or a warning.
Definitions are marked with Symbol.for("nativescript:cli:hookDefinition")
so a duplicated CLI copy in an extension's dependency tree still
recognizes them. The definition path skips parameter-name resolution,
the projectData promotion hack and the deprecation report; plain
function hooks keep running through the existing path unchanged.
lib/common/define-hook.ts is import-free so a hook can load it without
booting a second runtime, and it is re-exported from
nativescript/contracts.
Yok extends Injector on the base branch, so definitions run in runInInjectionContext(this.$injector, ...) directly and inject(Injector) inside a hook returns the facade itself.
edusperoni
force-pushed
the
feat/define-hook
branch
from
July 30, 2026 02:51
514c272 to
077c41b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
Hooks are plain functions whose shape the CLI infers at runtime: services arrive via parameter-name injection (deprecated, runtime-traced), the payload via a magic
hookArgsparameter, middleware by returning a function (implicit and undocumented), and aborting by throwing an error carryingstopExecution/errorAsWarningfields.What is the new behavior?
A typed, explicit hook-authoring API — fully additive; every existing hook keeps working unchanged.
lib/common/define-hook.tsis import-free (loading it can never boot a second CLI runtime) and re-exported fromnativescript/contracts; definitions carry aSymbol.formarker so duplicated CLI copies in an extension tree recognize each other's definitions.projectDatapromotion hack, no deprecation report. Plain-function hooks are untouched..mjsdefault exports are recognized.wrap()middlewares feed the exact channel legacy returned-functions use, so they compose with the@hookdecorator chain identically (11 new tests pin payload identity/mutation, inject-in-handler, middleware wrap + short-circuit, abort both ways, legacy coexistence + tracer isolation,.mjs, and name-mismatch tracing).extending-cli.mdnow leads withdefineHook; plain-function hooks and parameter-name injection remain documented as the transitional and legacy tiers.Full suite: 110 files, 1609 passed / 38 skipped; the yok oracle, public-API test, and compat fixtures are untouched.