From 0277f435ceb0543433476bc3d43014b43a64a326 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 22 Mar 2024 17:32:16 -0400 Subject: [PATCH] cli: implement `node run ` --- doc/api/cli.md | 22 ++++++ lib/internal/main/run.js | 71 +++++++++++++++++++ src/node.cc | 4 ++ src/node_modules.cc | 39 ++++++++++ src/node_modules.h | 3 + .../run-script/node_modules/.bin/fastify | 2 + .../node_modules/.bin/positional-args | 2 + test/fixtures/run-script/package.json | 7 ++ test/parallel/test-node-run.js | 54 ++++++++++++++ typings/internalBinding/modules.d.ts | 1 + 10 files changed, 205 insertions(+) create mode 100644 lib/internal/main/run.js create mode 100755 test/fixtures/run-script/node_modules/.bin/fastify 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 0f08c81794b5b2d..fe041c9e08327d1 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -51,6 +51,28 @@ 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 [command]` + + + +This runs an arbitrary command from a package.json's `"scripts"` object. +If no `"command"` is provided, it will list the available scripts. + +By default, this command adds the current path appended by +`node_modules/.bin` directory to the PATH in order to execute the binaries +from dependencies. + +For example, the following command will run the `test` script of +the current project's `package.json`: + +```console +$ node run test +``` + ## Options