src: add --enable-run-hooks for node --run pre scripts#63991
Open
anonrig wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
node --run intentionally does not run lifecycle scripts. Add an opt-in --enable-run-hooks flag that, together with --run, also runs the matching "pre<script>" hook (when present in the package.json "scripts" object) before the requested script. The hook is run first via a ProcessRunner; if it exits with a non-zero status the run is aborted and the main script is not executed. Mirroring npm, positional arguments after `--` are forwarded to the requested script only, not to the hook. Missing hooks, non-string hook values, and a missing main script are all handled without running anything spurious. Without the flag, --run never runs hooks, so existing behavior is unchanged. Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> Co-authored-by: Cursor <cursoragent@cursor.com>
123299a to
b782130
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.
Summary
node --runintentionally does not run lifecycle scripts. This adds anopt-in
--enable-run-hooksflag that, together with--run, also runs thematching
pre<script>hook (when present in the package.json"scripts"object) before the requested script.
script does not execute.
--are forwarded to the requestedscript only, not the hook.
handled without running anything spurious.
--runnever runs hooks — existing behavior isunchanged.
Only the
prehook is supported (nopost), keeping the feature minimal andopt-in; the docs' "intentional limitations" note is updated accordingly.
Example
Implementation
--enable-run-hooksper-process option (src/node_options.{h,cc}).task_runner::RunTasktakes arun_hooksflag; it resolvespre<command_id>up front (copying the command and rewinding the simdjson object so the main
lookup is untouched), runs it via a
ProcessRunner, and aborts on failure.src/node.ccpassescli_options->enable_run_hooksthrough.doc/api/cli.md+doc/node.1.Test plan
New
test/parallel/test-node-run-hooks.jswith a cross-platform fixture(
test/fixtures/run-script/hooks/,echo-based so it works on bothshandcmd.exe), covering:test-node-run.js/node_run_non_existent.jsstill passcpplintclean,test-cli-node-print-helppassesmake lint-js/lint-md+ full matrix)Made with Cursor