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 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
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_jsonvariable still points to the package.json of the given workspace,npm_package_nameandnpm_package_versionare 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.0Expected Behavior
With npm v8.7.0,
npm_package_nameandnpm_package_versionwhere 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.1This 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.0Output 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.1Environment