[BUG] Inconsistent values for npm_package_*
env variable when executing command in workspace since npm v8.8.0
#4912
Labels
Bug
thing that needs fixing
Needs Triage
needs review for next steps
Release 8.x
work is associated with a specific npm 8 release
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Since npm v8.8.0 (also confirmed with v8.10.0), the environment variables available to a command execution in a workspace seem to be inconsistent:
While the
npm_package_json
variable still points to the package.json of the given workspace,npm_package_name
andnpm_package_version
are now taken from the root project's package.json.Example:
npm_package_json=/npm-workspace-test/my-module-a/package.json npm_package_name=npm-workspace-test # root package name npm_package_version=1.0.0
Expected Behavior
With npm v8.7.0,
npm_package_name
andnpm_package_version
where taken from the workspace:npm_package_json=/npm-workspace-test/my-module-a/package.json npm_package_name=my-module-a # workspace package name npm_package_version=0.0.1
This allowed tools to access for example the name of the package they are currently processing. I would not expect the root project's package name here and therefore suspect this to be a bug.
Steps To Reproduce
I created a demo repository for this issue: https://github.com/RandomByte/npm-workspace-test
Get all available environment variables for the workspace command and filter for npm_package_*:
Output with npm v8.8.0 and v8.10.0:
npm_package_json=/npm-workspace-test/my-module-a/package.json npm_package_name=npm-workspace-test # root package name npm_package_version=1.0.0
Output with npm v8.7.0:
npm_package_json=/my-module-a/package.json npm_package_name=my-module-a # workspace package name npm_package_version=0.0.1
Environment
The text was updated successfully, but these errors were encountered: