Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Inconsistent values for npm_package_* env variable when executing command in workspace since npm v8.8.0 #4912

Open
2 tasks done
RandomByte opened this issue May 18, 2022 · 0 comments
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

Comments

@RandomByte
Copy link

RandomByte commented May 18, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant