From c70b2f7a7608272e08ecdb93ceeda5415471b0a5 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sat, 18 May 2024 21:37:25 -0400 Subject: [PATCH] cli: add `NODE_RUN_SCRIPT_NAME` env to `node --run` PR-URL: https://github.com/nodejs/node/pull/53032 Refs: https://github.com/nodejs/node/issues/52673 Reviewed-By: Daniel Lemire Reviewed-By: Benjamin Gruenbaum --- doc/api/cli.md | 11 +++ src/node_task_runner.cc | 76 ++++++++++--------- src/node_task_runner.h | 3 + .../node_modules/.bin/special-env-variables | 2 + .../.bin/special-env-variables.bat | 2 + test/fixtures/run-script/package.json | 4 +- test/message/node_run_non_existent.out | 2 + test/parallel/test-node-run.js | 12 +++ 8 files changed, 77 insertions(+), 35 deletions(-) create mode 100755 test/fixtures/run-script/node_modules/.bin/special-env-variables create mode 100755 test/fixtures/run-script/node_modules/.bin/special-env-variables.bat diff --git a/doc/api/cli.md b/doc/api/cli.md index b7ade9ffbe09b1..ad080e559987e1 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1857,6 +1857,10 @@ Modules preloaded with `--require` will run before modules preloaded with `--imp > Stability: 1.1 - Active development @@ -1897,6 +1901,13 @@ are: * Running `pre` or `post` scripts in addition to the specified script. * Defining package manager-specific environment variables. +#### Environment variables + +The following environment variables are set when running a script with `--run`: + +* `NODE_RUN_SCRIPT_NAME`: The name of the script being run. For example, if + `--run` is used to run `test`, the value of this variable will be `test`. + ### `--secure-heap=n`