From a896aa80b2e4690ada4c1d8b6201b3039cf7f56b Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 22 Mar 2024 17:32:16 -0400 Subject: [PATCH 1/3] cli: implement `node run ` --- doc/api/cli.md | 31 ++++++++ lib/internal/main/run.js | 71 +++++++++++++++++++ src/node.cc | 4 ++ src/node_modules.cc | 39 ++++++++++ src/node_modules.h | 3 + test/fixtures/run-script/.env | 1 + .../fixtures/run-script/node_modules/.bin/ada | 2 + .../run-script/node_modules/.bin/custom-env | 2 + .../node_modules/.bin/positional-args | 2 + test/fixtures/run-script/package.json | 8 +++ test/parallel/test-node-run.js | 64 +++++++++++++++++ typings/internalBinding/modules.d.ts | 1 + 12 files changed, 228 insertions(+) create mode 100644 lib/internal/main/run.js create mode 100644 test/fixtures/run-script/.env create mode 100755 test/fixtures/run-script/node_modules/.bin/ada create mode 100755 test/fixtures/run-script/node_modules/.bin/custom-env create mode 100755 test/fixtures/run-script/node_modules/.bin/positional-args create mode 100644 test/fixtures/run-script/package.json create mode 100644 test/parallel/test-node-run.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 0f08c81794b5b2..4a7dc98b2ce5d8 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -51,6 +51,37 @@ entry point, the `node` command will accept as input only files with `.js`, [`--experimental-wasm-modules`][] is enabled; and with no extension when [`--experimental-default-type=module`][] is passed. +## Sub-commands + +### `node run []` + + + +> Stability: 1.1 - Active development + +This runs a specified command from a package.json's `"scripts"` object. +If no `"command"` is provided, it will list the available scripts. + +`node run` prepends `./node_modules/.bin`, relative to the current +working directory, to the `PATH` in order to execute the binaries from +dependencies. + +For example, the following command will run the `test` script of +the `package.json` in the current folder: + +```console +$ node run test +``` + +You can also pass arguments to the command. Any argument after the script +name will be appended to the script: + +```console +$ node run test --verbose +``` + ## Options