From 369eb671e8d51c34823d4dccb7026ce9d7adf617 Mon Sep 17 00:00:00 2001 From: Tarek Wfa Date: Mon, 19 May 2025 16:10:52 +0300 Subject: [PATCH 1/6] docs: Clarify script working directory behavior (fixes #8305) --- DEPENDENCIES.json | 74 +++---------- DEPENDENCIES.md | 151 +------------------------- docs/lib/content/using-npm/scripts.md | 24 +++- 3 files changed, 39 insertions(+), 210 deletions(-) diff --git a/DEPENDENCIES.json b/DEPENDENCIES.json index 4b4fad53428c2..d7eff7135529b 100644 --- a/DEPENDENCIES.json +++ b/DEPENDENCIES.json @@ -10,87 +10,43 @@ "libnpmpack" ], [ - "@npmcli/arborist" - ], - [ - "@npmcli/metavuln-calculator" - ], - [ - "pacote", + "@npmcli/arborist", "@npmcli/config", "libnpmversion" ], [ - "@npmcli/run-script", "@npmcli/map-workspaces", - "libnpmaccess", - "libnpmorg", - "libnpmpublish", - "libnpmsearch", - "libnpmteam", - "init-package-json", - "npm-profile" + "@npmcli/run-script" ], [ - "@npmcli/package-json", - "npm-registry-fetch" - ], - [ - "@npmcli/git", - "make-fetch-happen" + "@npmcli/package-json" ], [ "@npmcli/smoke-tests", - "npm-pick-manifest", - "@npmcli/installed-package-contents", - "cacache", - "promzard" + "@npmcli/git", + "libnpmpublish" ], [ "@npmcli/docs", - "npm-package-arg", "@npmcli/promise-spawn", - "npm-install-checks", - "npm-bundled", - "@npmcli/fs", - "unique-filename", - "npm-packlist", "@npmcli/mock-globals", - "bin-links", - "nopt", - "parse-conflict-json", - "read-package-json-fast", - "read", - "normalize-package-data" + "@npmcli/fs", + "@npmcli/metavuln-calculator", + "libnpmaccess", + "libnpmorg", + "libnpmsearch", + "libnpmteam" ], [ "@npmcli/eslint-config", "@npmcli/template-oss", - "ignore-walk", "semver", - "hosted-git-info", - "proc-log", - "validate-npm-package-name", "which", - "ini", - "npm-normalize-package-bin", - "json-parse-even-better-errors", - "@npmcli/node-gyp", - "ssri", - "unique-slug", - "@npmcli/redact", - "@npmcli/agent", - "minipass-fetch", + "@npmcli/installed-package-contents", "@npmcli/name-from-folder", + "@npmcli/node-gyp", "@npmcli/query", - "cmd-shim", - "read-cmd-shim", - "write-file-atomic", - "abbrev", - "proggy", - "minify-registry-metadata", - "mute-stream", - "npm-audit-report", - "npm-user-validate" + "@npmcli/redact", + "abbrev" ] ] diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index a4bfa4c4471b8..806416b220c78 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -3,93 +3,44 @@ ## `github.com/npm/` only ```mermaid graph LR; - bin-links-->cmd-shim; - bin-links-->npm-normalize-package-bin; - bin-links-->proc-log; - bin-links-->read-cmd-shim; - bin-links-->write-file-atomic; - cacache-->npmcli-fs["@npmcli/fs"]; - cacache-->ssri; - cacache-->unique-filename; - init-package-json-->npm-package-arg; - init-package-json-->npmcli-package-json["@npmcli/package-json"]; - init-package-json-->promzard; - init-package-json-->read; - init-package-json-->semver; - init-package-json-->validate-npm-package-name; - libnpmaccess-->npm-package-arg; - libnpmaccess-->npm-registry-fetch; libnpmaccess-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmaccess-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmaccess-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmdiff-->npm-package-arg; libnpmdiff-->npmcli-arborist["@npmcli/arborist"]; libnpmdiff-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmdiff-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; libnpmdiff-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmdiff-->pacote; - libnpmexec-->bin-links; - libnpmexec-->npm-package-arg; libnpmexec-->npmcli-arborist["@npmcli/arborist"]; libnpmexec-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmexec-->npmcli-package-json["@npmcli/package-json"]; libnpmexec-->npmcli-run-script["@npmcli/run-script"]; libnpmexec-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmexec-->pacote; - libnpmexec-->proc-log; - libnpmexec-->read-package-json-fast; - libnpmexec-->read; libnpmexec-->semver; libnpmfund-->npmcli-arborist["@npmcli/arborist"]; libnpmfund-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmfund-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmorg-->npm-registry-fetch; libnpmorg-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmorg-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmpack-->npm-package-arg; libnpmpack-->npmcli-arborist["@npmcli/arborist"]; libnpmpack-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmpack-->npmcli-run-script["@npmcli/run-script"]; libnpmpack-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmpack-->pacote; - libnpmpublish-->normalize-package-data; - libnpmpublish-->npm-package-arg; - libnpmpublish-->npm-registry-fetch; libnpmpublish-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmpublish-->npmcli-mock-globals["@npmcli/mock-globals"]; libnpmpublish-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmpublish-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmpublish-->proc-log; libnpmpublish-->semver; - libnpmpublish-->ssri; - libnpmsearch-->npm-registry-fetch; libnpmsearch-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmsearch-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmteam-->npm-registry-fetch; libnpmteam-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmteam-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmversion-->json-parse-even-better-errors; libnpmversion-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmversion-->npmcli-git["@npmcli/git"]; libnpmversion-->npmcli-run-script["@npmcli/run-script"]; libnpmversion-->npmcli-template-oss["@npmcli/template-oss"]; - libnpmversion-->proc-log; libnpmversion-->semver; - make-fetch-happen-->cacache; - make-fetch-happen-->minipass-fetch; - make-fetch-happen-->npmcli-agent["@npmcli/agent"]; - make-fetch-happen-->proc-log; - make-fetch-happen-->ssri; - nopt-->abbrev; - normalize-package-data-->hosted-git-info; - normalize-package-data-->semver; npm-->abbrev; - npm-->cacache; - npm-->hosted-git-info; - npm-->ini; - npm-->init-package-json; - npm-->json-parse-even-better-errors; npm-->libnpmaccess; npm-->libnpmdiff; npm-->libnpmexec; @@ -100,17 +51,6 @@ graph LR; npm-->libnpmsearch; npm-->libnpmteam; npm-->libnpmversion; - npm-->make-fetch-happen; - npm-->nopt; - npm-->normalize-package-data; - npm-->npm-audit-report; - npm-->npm-install-checks; - npm-->npm-package-arg; - npm-->npm-packlist; - npm-->npm-pick-manifest; - npm-->npm-profile; - npm-->npm-registry-fetch; - npm-->npm-user-validate; npm-->npmcli-arborist["@npmcli/arborist"]; npm-->npmcli-config["@npmcli/config"]; npm-->npmcli-docs["@npmcli/docs"]; @@ -126,41 +66,8 @@ graph LR; npm-->npmcli-run-script["@npmcli/run-script"]; npm-->npmcli-smoke-tests["@npmcli/smoke-tests"]; npm-->npmcli-template-oss["@npmcli/template-oss"]; - npm-->pacote; - npm-->parse-conflict-json; - npm-->proc-log; - npm-->read; npm-->semver; - npm-->ssri; - npm-->validate-npm-package-name; npm-->which; - npm-bundled-->npm-normalize-package-bin; - npm-install-checks-->semver; - npm-package-arg-->hosted-git-info; - npm-package-arg-->proc-log; - npm-package-arg-->semver; - npm-package-arg-->validate-npm-package-name; - npm-packlist-->ignore-walk; - npm-pick-manifest-->npm-install-checks; - npm-pick-manifest-->npm-normalize-package-bin; - npm-pick-manifest-->npm-package-arg; - npm-pick-manifest-->semver; - npm-profile-->npm-registry-fetch; - npm-profile-->proc-log; - npm-registry-fetch-->make-fetch-happen; - npm-registry-fetch-->minipass-fetch; - npm-registry-fetch-->npm-package-arg; - npm-registry-fetch-->npmcli-redact["@npmcli/redact"]; - npm-registry-fetch-->proc-log; - npmcli-arborist-->bin-links; - npmcli-arborist-->cacache; - npmcli-arborist-->hosted-git-info; - npmcli-arborist-->minify-registry-metadata; - npmcli-arborist-->nopt; - npmcli-arborist-->npm-install-checks; - npmcli-arborist-->npm-package-arg; - npmcli-arborist-->npm-pick-manifest; - npmcli-arborist-->npm-registry-fetch; npmcli-arborist-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-arborist-->npmcli-fs["@npmcli/fs"]; npmcli-arborist-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; @@ -174,83 +81,40 @@ graph LR; npmcli-arborist-->npmcli-redact["@npmcli/redact"]; npmcli-arborist-->npmcli-run-script["@npmcli/run-script"]; npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"]; - npmcli-arborist-->pacote; - npmcli-arborist-->parse-conflict-json; - npmcli-arborist-->proc-log; - npmcli-arborist-->proggy; - npmcli-arborist-->read-package-json-fast; npmcli-arborist-->semver; - npmcli-arborist-->ssri; - npmcli-config-->ini; - npmcli-config-->nopt; npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"]; npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"]; npmcli-config-->npmcli-package-json["@npmcli/package-json"]; npmcli-config-->npmcli-template-oss["@npmcli/template-oss"]; - npmcli-config-->proc-log; npmcli-config-->semver; - npmcli-docs-->ignore-walk; npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"]; npmcli-docs-->semver; npmcli-fs-->semver; - npmcli-git-->ini; - npmcli-git-->npm-pick-manifest; npmcli-git-->npmcli-promise-spawn["@npmcli/promise-spawn"]; - npmcli-git-->proc-log; npmcli-git-->semver; npmcli-git-->which; - npmcli-installed-package-contents-->npm-bundled; - npmcli-installed-package-contents-->npm-normalize-package-bin; npmcli-map-workspaces-->npmcli-name-from-folder["@npmcli/name-from-folder"]; npmcli-map-workspaces-->npmcli-package-json["@npmcli/package-json"]; - npmcli-metavuln-calculator-->cacache; - npmcli-metavuln-calculator-->json-parse-even-better-errors; - npmcli-metavuln-calculator-->pacote; - npmcli-metavuln-calculator-->proc-log; npmcli-metavuln-calculator-->semver; npmcli-mock-globals-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-mock-globals-->npmcli-template-oss["@npmcli/template-oss"]; - npmcli-mock-registry-->npm-package-arg; npmcli-mock-registry-->npmcli-arborist["@npmcli/arborist"]; npmcli-mock-registry-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-mock-registry-->npmcli-template-oss["@npmcli/template-oss"]; - npmcli-mock-registry-->pacote; - npmcli-package-json-->hosted-git-info; - npmcli-package-json-->json-parse-even-better-errors; npmcli-package-json-->npmcli-git["@npmcli/git"]; - npmcli-package-json-->proc-log; npmcli-package-json-->semver; npmcli-promise-spawn-->which; npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"]; npmcli-run-script-->npmcli-package-json["@npmcli/package-json"]; npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"]; - npmcli-run-script-->proc-log; npmcli-run-script-->which; npmcli-smoke-tests-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-smoke-tests-->npmcli-mock-registry["@npmcli/mock-registry"]; npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"]; npmcli-smoke-tests-->npmcli-template-oss["@npmcli/template-oss"]; npmcli-smoke-tests-->which; - pacote-->cacache; - pacote-->npm-package-arg; - pacote-->npm-packlist; - pacote-->npm-pick-manifest; - pacote-->npm-registry-fetch; - pacote-->npmcli-git["@npmcli/git"]; - pacote-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; - pacote-->npmcli-package-json["@npmcli/package-json"]; - pacote-->npmcli-promise-spawn["@npmcli/promise-spawn"]; - pacote-->npmcli-run-script["@npmcli/run-script"]; - pacote-->proc-log; - pacote-->ssri; - parse-conflict-json-->json-parse-even-better-errors; - promzard-->read; - read-->mute-stream; - read-package-json-fast-->json-parse-even-better-errors; - read-package-json-fast-->npm-normalize-package-bin; - unique-filename-->unique-slug; ``` ## all dependencies @@ -778,12 +642,9 @@ packages higher up the chain. - npm - @npmcli/mock-registry, libnpmdiff, libnpmexec, libnpmfund, libnpmpack - - @npmcli/arborist - - @npmcli/metavuln-calculator - - pacote, @npmcli/config, libnpmversion - - @npmcli/run-script, @npmcli/map-workspaces, libnpmaccess, libnpmorg, libnpmpublish, libnpmsearch, libnpmteam, init-package-json, npm-profile - - @npmcli/package-json, npm-registry-fetch - - @npmcli/git, make-fetch-happen - - @npmcli/smoke-tests, npm-pick-manifest, @npmcli/installed-package-contents, cacache, promzard - - @npmcli/docs, npm-package-arg, @npmcli/promise-spawn, npm-install-checks, npm-bundled, @npmcli/fs, unique-filename, npm-packlist, @npmcli/mock-globals, bin-links, nopt, parse-conflict-json, read-package-json-fast, read, normalize-package-data - - @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, hosted-git-info, proc-log, validate-npm-package-name, which, ini, npm-normalize-package-bin, json-parse-even-better-errors, @npmcli/node-gyp, ssri, unique-slug, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/name-from-folder, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, mute-stream, npm-audit-report, npm-user-validate + - @npmcli/arborist, @npmcli/config, libnpmversion + - @npmcli/map-workspaces, @npmcli/run-script + - @npmcli/package-json + - @npmcli/smoke-tests, @npmcli/git, libnpmpublish + - @npmcli/docs, @npmcli/promise-spawn, @npmcli/mock-globals, @npmcli/fs, @npmcli/metavuln-calculator, libnpmaccess, libnpmorg, libnpmsearch, libnpmteam + - @npmcli/eslint-config, @npmcli/template-oss, semver, which, @npmcli/installed-package-contents, @npmcli/name-from-folder, @npmcli/node-gyp, @npmcli/query, @npmcli/redact, abbrev diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index 48cb2eb1c9f4c..d2b4427f63c76 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -228,6 +228,22 @@ Reasons for a package removal include: Due to the lack of necessary context, `uninstall` lifecycle scripts are not implemented and will not function. +### Working Directory for Scripts + +Scripts are always run from the root of the package folder, regardless of what the current working directory is when npm is invoked. This means your scripts can reliably assume they are running in the package root. + +If you want your script to behave differently based on the directory you were in when you ran npm, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. + +#### Historical Behavior in Older npm Versions + +In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. + +For npm v6 and earlier, scripts were generally run from the root of the package, but there were rare cases and bugs in older versions where this was not guaranteed. If your package must support very old npm versions, you may wish to add a safeguard in your scripts (for example, by checking process.cwd()). + +For more details, see: +- [npm v7 release notes](https://github.com/npm/cli/releases/tag/v7.0.0) +- [Discussion about script working directory reliability in npm v6 and earlier](https://github.com/npm/npm/issues/12356) + ### User When npm is run as root, scripts are always run with the effective uid @@ -350,15 +366,11 @@ file. preinstall or install script. If you are doing this, please consider if there is another option. The only valid use of `install` or `preinstall` scripts is for compilation which must be done on the target architecture. -* Scripts are run from the root of the package folder, regardless of what the - current working directory is when `npm` is invoked. If you want your - script to use different behavior based on what subdirectory you're in, you - can use the `INIT_CWD` environment variable, which holds the full path you - were in when you ran `npm run`. + ### See Also * [npm run](/commands/npm-run) * [package.json](/configuring-npm/package-json) * [npm developers](/using-npm/developers) -* [npm install](/commands/npm-install) +* [npm install](/commands/npm-install) \ No newline at end of file From 85a35823aba59ffcaea896cc988334d06f1caafc Mon Sep 17 00:00:00 2001 From: Tarek Wfa Date: Mon, 19 May 2025 16:27:05 +0300 Subject: [PATCH 2/6] Revert "docs: Clarify script working directory behavior (fixes #8305)" This reverts commit 369eb671e8d51c34823d4dccb7026ce9d7adf617. --- DEPENDENCIES.json | 74 ++++++++++--- DEPENDENCIES.md | 151 +++++++++++++++++++++++++- docs/lib/content/using-npm/scripts.md | 24 +--- 3 files changed, 210 insertions(+), 39 deletions(-) diff --git a/DEPENDENCIES.json b/DEPENDENCIES.json index d7eff7135529b..4b4fad53428c2 100644 --- a/DEPENDENCIES.json +++ b/DEPENDENCIES.json @@ -10,43 +10,87 @@ "libnpmpack" ], [ - "@npmcli/arborist", + "@npmcli/arborist" + ], + [ + "@npmcli/metavuln-calculator" + ], + [ + "pacote", "@npmcli/config", "libnpmversion" ], [ + "@npmcli/run-script", "@npmcli/map-workspaces", - "@npmcli/run-script" + "libnpmaccess", + "libnpmorg", + "libnpmpublish", + "libnpmsearch", + "libnpmteam", + "init-package-json", + "npm-profile" ], [ - "@npmcli/package-json" + "@npmcli/package-json", + "npm-registry-fetch" ], [ - "@npmcli/smoke-tests", "@npmcli/git", - "libnpmpublish" + "make-fetch-happen" + ], + [ + "@npmcli/smoke-tests", + "npm-pick-manifest", + "@npmcli/installed-package-contents", + "cacache", + "promzard" ], [ "@npmcli/docs", + "npm-package-arg", "@npmcli/promise-spawn", - "@npmcli/mock-globals", + "npm-install-checks", + "npm-bundled", "@npmcli/fs", - "@npmcli/metavuln-calculator", - "libnpmaccess", - "libnpmorg", - "libnpmsearch", - "libnpmteam" + "unique-filename", + "npm-packlist", + "@npmcli/mock-globals", + "bin-links", + "nopt", + "parse-conflict-json", + "read-package-json-fast", + "read", + "normalize-package-data" ], [ "@npmcli/eslint-config", "@npmcli/template-oss", + "ignore-walk", "semver", + "hosted-git-info", + "proc-log", + "validate-npm-package-name", "which", - "@npmcli/installed-package-contents", - "@npmcli/name-from-folder", + "ini", + "npm-normalize-package-bin", + "json-parse-even-better-errors", "@npmcli/node-gyp", - "@npmcli/query", + "ssri", + "unique-slug", "@npmcli/redact", - "abbrev" + "@npmcli/agent", + "minipass-fetch", + "@npmcli/name-from-folder", + "@npmcli/query", + "cmd-shim", + "read-cmd-shim", + "write-file-atomic", + "abbrev", + "proggy", + "minify-registry-metadata", + "mute-stream", + "npm-audit-report", + "npm-user-validate" ] ] diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 806416b220c78..a4bfa4c4471b8 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -3,44 +3,93 @@ ## `github.com/npm/` only ```mermaid graph LR; + bin-links-->cmd-shim; + bin-links-->npm-normalize-package-bin; + bin-links-->proc-log; + bin-links-->read-cmd-shim; + bin-links-->write-file-atomic; + cacache-->npmcli-fs["@npmcli/fs"]; + cacache-->ssri; + cacache-->unique-filename; + init-package-json-->npm-package-arg; + init-package-json-->npmcli-package-json["@npmcli/package-json"]; + init-package-json-->promzard; + init-package-json-->read; + init-package-json-->semver; + init-package-json-->validate-npm-package-name; + libnpmaccess-->npm-package-arg; + libnpmaccess-->npm-registry-fetch; libnpmaccess-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmaccess-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmaccess-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmdiff-->npm-package-arg; libnpmdiff-->npmcli-arborist["@npmcli/arborist"]; libnpmdiff-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmdiff-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; libnpmdiff-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmdiff-->pacote; + libnpmexec-->bin-links; + libnpmexec-->npm-package-arg; libnpmexec-->npmcli-arborist["@npmcli/arborist"]; libnpmexec-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmexec-->npmcli-package-json["@npmcli/package-json"]; libnpmexec-->npmcli-run-script["@npmcli/run-script"]; libnpmexec-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmexec-->pacote; + libnpmexec-->proc-log; + libnpmexec-->read-package-json-fast; + libnpmexec-->read; libnpmexec-->semver; libnpmfund-->npmcli-arborist["@npmcli/arborist"]; libnpmfund-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmfund-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmorg-->npm-registry-fetch; libnpmorg-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmorg-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmpack-->npm-package-arg; libnpmpack-->npmcli-arborist["@npmcli/arborist"]; libnpmpack-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmpack-->npmcli-run-script["@npmcli/run-script"]; libnpmpack-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmpack-->pacote; + libnpmpublish-->normalize-package-data; + libnpmpublish-->npm-package-arg; + libnpmpublish-->npm-registry-fetch; libnpmpublish-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmpublish-->npmcli-mock-globals["@npmcli/mock-globals"]; libnpmpublish-->npmcli-mock-registry["@npmcli/mock-registry"]; libnpmpublish-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmpublish-->proc-log; libnpmpublish-->semver; + libnpmpublish-->ssri; + libnpmsearch-->npm-registry-fetch; libnpmsearch-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmsearch-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmteam-->npm-registry-fetch; libnpmteam-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmteam-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmversion-->json-parse-even-better-errors; libnpmversion-->npmcli-eslint-config["@npmcli/eslint-config"]; libnpmversion-->npmcli-git["@npmcli/git"]; libnpmversion-->npmcli-run-script["@npmcli/run-script"]; libnpmversion-->npmcli-template-oss["@npmcli/template-oss"]; + libnpmversion-->proc-log; libnpmversion-->semver; + make-fetch-happen-->cacache; + make-fetch-happen-->minipass-fetch; + make-fetch-happen-->npmcli-agent["@npmcli/agent"]; + make-fetch-happen-->proc-log; + make-fetch-happen-->ssri; + nopt-->abbrev; + normalize-package-data-->hosted-git-info; + normalize-package-data-->semver; npm-->abbrev; + npm-->cacache; + npm-->hosted-git-info; + npm-->ini; + npm-->init-package-json; + npm-->json-parse-even-better-errors; npm-->libnpmaccess; npm-->libnpmdiff; npm-->libnpmexec; @@ -51,6 +100,17 @@ graph LR; npm-->libnpmsearch; npm-->libnpmteam; npm-->libnpmversion; + npm-->make-fetch-happen; + npm-->nopt; + npm-->normalize-package-data; + npm-->npm-audit-report; + npm-->npm-install-checks; + npm-->npm-package-arg; + npm-->npm-packlist; + npm-->npm-pick-manifest; + npm-->npm-profile; + npm-->npm-registry-fetch; + npm-->npm-user-validate; npm-->npmcli-arborist["@npmcli/arborist"]; npm-->npmcli-config["@npmcli/config"]; npm-->npmcli-docs["@npmcli/docs"]; @@ -66,8 +126,41 @@ graph LR; npm-->npmcli-run-script["@npmcli/run-script"]; npm-->npmcli-smoke-tests["@npmcli/smoke-tests"]; npm-->npmcli-template-oss["@npmcli/template-oss"]; + npm-->pacote; + npm-->parse-conflict-json; + npm-->proc-log; + npm-->read; npm-->semver; + npm-->ssri; + npm-->validate-npm-package-name; npm-->which; + npm-bundled-->npm-normalize-package-bin; + npm-install-checks-->semver; + npm-package-arg-->hosted-git-info; + npm-package-arg-->proc-log; + npm-package-arg-->semver; + npm-package-arg-->validate-npm-package-name; + npm-packlist-->ignore-walk; + npm-pick-manifest-->npm-install-checks; + npm-pick-manifest-->npm-normalize-package-bin; + npm-pick-manifest-->npm-package-arg; + npm-pick-manifest-->semver; + npm-profile-->npm-registry-fetch; + npm-profile-->proc-log; + npm-registry-fetch-->make-fetch-happen; + npm-registry-fetch-->minipass-fetch; + npm-registry-fetch-->npm-package-arg; + npm-registry-fetch-->npmcli-redact["@npmcli/redact"]; + npm-registry-fetch-->proc-log; + npmcli-arborist-->bin-links; + npmcli-arborist-->cacache; + npmcli-arborist-->hosted-git-info; + npmcli-arborist-->minify-registry-metadata; + npmcli-arborist-->nopt; + npmcli-arborist-->npm-install-checks; + npmcli-arborist-->npm-package-arg; + npmcli-arborist-->npm-pick-manifest; + npmcli-arborist-->npm-registry-fetch; npmcli-arborist-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-arborist-->npmcli-fs["@npmcli/fs"]; npmcli-arborist-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; @@ -81,40 +174,83 @@ graph LR; npmcli-arborist-->npmcli-redact["@npmcli/redact"]; npmcli-arborist-->npmcli-run-script["@npmcli/run-script"]; npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"]; + npmcli-arborist-->pacote; + npmcli-arborist-->parse-conflict-json; + npmcli-arborist-->proc-log; + npmcli-arborist-->proggy; + npmcli-arborist-->read-package-json-fast; npmcli-arborist-->semver; + npmcli-arborist-->ssri; + npmcli-config-->ini; + npmcli-config-->nopt; npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"]; npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"]; npmcli-config-->npmcli-package-json["@npmcli/package-json"]; npmcli-config-->npmcli-template-oss["@npmcli/template-oss"]; + npmcli-config-->proc-log; npmcli-config-->semver; + npmcli-docs-->ignore-walk; npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"]; npmcli-docs-->semver; npmcli-fs-->semver; + npmcli-git-->ini; + npmcli-git-->npm-pick-manifest; npmcli-git-->npmcli-promise-spawn["@npmcli/promise-spawn"]; + npmcli-git-->proc-log; npmcli-git-->semver; npmcli-git-->which; + npmcli-installed-package-contents-->npm-bundled; + npmcli-installed-package-contents-->npm-normalize-package-bin; npmcli-map-workspaces-->npmcli-name-from-folder["@npmcli/name-from-folder"]; npmcli-map-workspaces-->npmcli-package-json["@npmcli/package-json"]; + npmcli-metavuln-calculator-->cacache; + npmcli-metavuln-calculator-->json-parse-even-better-errors; + npmcli-metavuln-calculator-->pacote; + npmcli-metavuln-calculator-->proc-log; npmcli-metavuln-calculator-->semver; npmcli-mock-globals-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-mock-globals-->npmcli-template-oss["@npmcli/template-oss"]; + npmcli-mock-registry-->npm-package-arg; npmcli-mock-registry-->npmcli-arborist["@npmcli/arborist"]; npmcli-mock-registry-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-mock-registry-->npmcli-template-oss["@npmcli/template-oss"]; + npmcli-mock-registry-->pacote; + npmcli-package-json-->hosted-git-info; + npmcli-package-json-->json-parse-even-better-errors; npmcli-package-json-->npmcli-git["@npmcli/git"]; + npmcli-package-json-->proc-log; npmcli-package-json-->semver; npmcli-promise-spawn-->which; npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"]; npmcli-run-script-->npmcli-package-json["@npmcli/package-json"]; npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"]; + npmcli-run-script-->proc-log; npmcli-run-script-->which; npmcli-smoke-tests-->npmcli-eslint-config["@npmcli/eslint-config"]; npmcli-smoke-tests-->npmcli-mock-registry["@npmcli/mock-registry"]; npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"]; npmcli-smoke-tests-->npmcli-template-oss["@npmcli/template-oss"]; npmcli-smoke-tests-->which; + pacote-->cacache; + pacote-->npm-package-arg; + pacote-->npm-packlist; + pacote-->npm-pick-manifest; + pacote-->npm-registry-fetch; + pacote-->npmcli-git["@npmcli/git"]; + pacote-->npmcli-installed-package-contents["@npmcli/installed-package-contents"]; + pacote-->npmcli-package-json["@npmcli/package-json"]; + pacote-->npmcli-promise-spawn["@npmcli/promise-spawn"]; + pacote-->npmcli-run-script["@npmcli/run-script"]; + pacote-->proc-log; + pacote-->ssri; + parse-conflict-json-->json-parse-even-better-errors; + promzard-->read; + read-->mute-stream; + read-package-json-fast-->json-parse-even-better-errors; + read-package-json-fast-->npm-normalize-package-bin; + unique-filename-->unique-slug; ``` ## all dependencies @@ -642,9 +778,12 @@ packages higher up the chain. - npm - @npmcli/mock-registry, libnpmdiff, libnpmexec, libnpmfund, libnpmpack - - @npmcli/arborist, @npmcli/config, libnpmversion - - @npmcli/map-workspaces, @npmcli/run-script - - @npmcli/package-json - - @npmcli/smoke-tests, @npmcli/git, libnpmpublish - - @npmcli/docs, @npmcli/promise-spawn, @npmcli/mock-globals, @npmcli/fs, @npmcli/metavuln-calculator, libnpmaccess, libnpmorg, libnpmsearch, libnpmteam - - @npmcli/eslint-config, @npmcli/template-oss, semver, which, @npmcli/installed-package-contents, @npmcli/name-from-folder, @npmcli/node-gyp, @npmcli/query, @npmcli/redact, abbrev + - @npmcli/arborist + - @npmcli/metavuln-calculator + - pacote, @npmcli/config, libnpmversion + - @npmcli/run-script, @npmcli/map-workspaces, libnpmaccess, libnpmorg, libnpmpublish, libnpmsearch, libnpmteam, init-package-json, npm-profile + - @npmcli/package-json, npm-registry-fetch + - @npmcli/git, make-fetch-happen + - @npmcli/smoke-tests, npm-pick-manifest, @npmcli/installed-package-contents, cacache, promzard + - @npmcli/docs, npm-package-arg, @npmcli/promise-spawn, npm-install-checks, npm-bundled, @npmcli/fs, unique-filename, npm-packlist, @npmcli/mock-globals, bin-links, nopt, parse-conflict-json, read-package-json-fast, read, normalize-package-data + - @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, hosted-git-info, proc-log, validate-npm-package-name, which, ini, npm-normalize-package-bin, json-parse-even-better-errors, @npmcli/node-gyp, ssri, unique-slug, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/name-from-folder, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, mute-stream, npm-audit-report, npm-user-validate diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index d2b4427f63c76..48cb2eb1c9f4c 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -228,22 +228,6 @@ Reasons for a package removal include: Due to the lack of necessary context, `uninstall` lifecycle scripts are not implemented and will not function. -### Working Directory for Scripts - -Scripts are always run from the root of the package folder, regardless of what the current working directory is when npm is invoked. This means your scripts can reliably assume they are running in the package root. - -If you want your script to behave differently based on the directory you were in when you ran npm, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. - -#### Historical Behavior in Older npm Versions - -In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. - -For npm v6 and earlier, scripts were generally run from the root of the package, but there were rare cases and bugs in older versions where this was not guaranteed. If your package must support very old npm versions, you may wish to add a safeguard in your scripts (for example, by checking process.cwd()). - -For more details, see: -- [npm v7 release notes](https://github.com/npm/cli/releases/tag/v7.0.0) -- [Discussion about script working directory reliability in npm v6 and earlier](https://github.com/npm/npm/issues/12356) - ### User When npm is run as root, scripts are always run with the effective uid @@ -366,11 +350,15 @@ file. preinstall or install script. If you are doing this, please consider if there is another option. The only valid use of `install` or `preinstall` scripts is for compilation which must be done on the target architecture. - +* Scripts are run from the root of the package folder, regardless of what the + current working directory is when `npm` is invoked. If you want your + script to use different behavior based on what subdirectory you're in, you + can use the `INIT_CWD` environment variable, which holds the full path you + were in when you ran `npm run`. ### See Also * [npm run](/commands/npm-run) * [package.json](/configuring-npm/package-json) * [npm developers](/using-npm/developers) -* [npm install](/commands/npm-install) \ No newline at end of file +* [npm install](/commands/npm-install) From 45c12d7ad7853361ace5256c9ba84546ca59b376 Mon Sep 17 00:00:00 2001 From: Tarek Wfa Date: Mon, 19 May 2025 16:34:06 +0300 Subject: [PATCH 3/6] docs: Clarify script working directory behavior (fixes #8305) --- docs/lib/content/using-npm/scripts.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index 48cb2eb1c9f4c..d2b4427f63c76 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -228,6 +228,22 @@ Reasons for a package removal include: Due to the lack of necessary context, `uninstall` lifecycle scripts are not implemented and will not function. +### Working Directory for Scripts + +Scripts are always run from the root of the package folder, regardless of what the current working directory is when npm is invoked. This means your scripts can reliably assume they are running in the package root. + +If you want your script to behave differently based on the directory you were in when you ran npm, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. + +#### Historical Behavior in Older npm Versions + +In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. + +For npm v6 and earlier, scripts were generally run from the root of the package, but there were rare cases and bugs in older versions where this was not guaranteed. If your package must support very old npm versions, you may wish to add a safeguard in your scripts (for example, by checking process.cwd()). + +For more details, see: +- [npm v7 release notes](https://github.com/npm/cli/releases/tag/v7.0.0) +- [Discussion about script working directory reliability in npm v6 and earlier](https://github.com/npm/npm/issues/12356) + ### User When npm is run as root, scripts are always run with the effective uid @@ -350,15 +366,11 @@ file. preinstall or install script. If you are doing this, please consider if there is another option. The only valid use of `install` or `preinstall` scripts is for compilation which must be done on the target architecture. -* Scripts are run from the root of the package folder, regardless of what the - current working directory is when `npm` is invoked. If you want your - script to use different behavior based on what subdirectory you're in, you - can use the `INIT_CWD` environment variable, which holds the full path you - were in when you ran `npm run`. + ### See Also * [npm run](/commands/npm-run) * [package.json](/configuring-npm/package-json) * [npm developers](/using-npm/developers) -* [npm install](/commands/npm-install) +* [npm install](/commands/npm-install) \ No newline at end of file From 4e9963612b4e38ad3df8ab27e0b9a29d46468e23 Mon Sep 17 00:00:00 2001 From: tarekwfa0110 <109884541+tarekwfa0110@users.noreply.github.com> Date: Tue, 20 May 2025 04:12:04 +0300 Subject: [PATCH 4/6] Update scripts.md --- docs/lib/content/using-npm/scripts.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index d2b4427f63c76..cf53f1ec26a8e 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -236,8 +236,6 @@ If you want your script to behave differently based on the directory you were in #### Historical Behavior in Older npm Versions -In npm v7 and later, scripts are always executed from the root of the package folder, regardless of your current working directory. This behavior is now reliable and consistent. - For npm v6 and earlier, scripts were generally run from the root of the package, but there were rare cases and bugs in older versions where this was not guaranteed. If your package must support very old npm versions, you may wish to add a safeguard in your scripts (for example, by checking process.cwd()). For more details, see: @@ -367,10 +365,9 @@ file. there is another option. The only valid use of `install` or `preinstall` scripts is for compilation which must be done on the target architecture. - ### See Also * [npm run](/commands/npm-run) * [package.json](/configuring-npm/package-json) * [npm developers](/using-npm/developers) -* [npm install](/commands/npm-install) \ No newline at end of file +* [npm install](/commands/npm-install) From 455cb2465ee1293f60a17b4d95608de9666cf1e5 Mon Sep 17 00:00:00 2001 From: tarekwfa0110 <109884541+tarekwfa0110@users.noreply.github.com> Date: Tue, 20 May 2025 20:12:02 +0300 Subject: [PATCH 5/6] Update scripts.md with missing backticks Co-authored-by: Michael Smith --- docs/lib/content/using-npm/scripts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index cf53f1ec26a8e..2ebf82cedb5e5 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -232,7 +232,7 @@ Due to the lack of necessary context, `uninstall` lifecycle scripts are not impl Scripts are always run from the root of the package folder, regardless of what the current working directory is when npm is invoked. This means your scripts can reliably assume they are running in the package root. -If you want your script to behave differently based on the directory you were in when you ran npm, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. +If you want your script to behave differently based on the directory you were in when you ran `npm`, you can use the `INIT_CWD` environment variable, which holds the full path you were in when you ran `npm run`. #### Historical Behavior in Older npm Versions From 103fb78c211855e465217e95d94eea2d0ea4e782 Mon Sep 17 00:00:00 2001 From: tarekwfa0110 <109884541+tarekwfa0110@users.noreply.github.com> Date: Wed, 21 May 2025 15:59:16 +0300 Subject: [PATCH 6/6] Update scripts.md with missing backticks 2 --- docs/lib/content/using-npm/scripts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lib/content/using-npm/scripts.md b/docs/lib/content/using-npm/scripts.md index 2ebf82cedb5e5..3ebd1bb37e4cc 100644 --- a/docs/lib/content/using-npm/scripts.md +++ b/docs/lib/content/using-npm/scripts.md @@ -230,7 +230,7 @@ Due to the lack of necessary context, `uninstall` lifecycle scripts are not impl ### Working Directory for Scripts -Scripts are always run from the root of the package folder, regardless of what the current working directory is when npm is invoked. This means your scripts can reliably assume they are running in the package root. +Scripts are always run from the root of the package folder, regardless of what the current working directory is when `npm` is invoked. This means your scripts can reliably assume they are running in the package root. If you want your script to behave differently based on the directory you were in when you ran `npm`, you can use the `INIT_CWD` environment variable, which holds the full path you were in when you ran `npm run`.