Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
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
and npm_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
and npm_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
git clone https://github.com/RandomByte/npm-workspace-test.git
cd npm-workspace-test && npm install
Get all available environment variables for the workspace command and filter for npm_package_*:
npm exec -w my-module-a -c "env" | grep "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
- npm: 8.10.0
- Node.js: v17.9.0
- OS Name: macOS Monterey
- System Model Name: MacBook Pro