Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MaxBlack-dev
Copy link
Contributor

Description

This PR updates the npm_package_* environment variables documentation to reflect the changes made in npm 7.

Changes

  • Listed the specific environment variables that npm still provides in npm 7+
  • Added note explaining that most package.json fields are no longer provided as environment variables
  • Documented that npm_package_json provides the path to package.json for scripts that need to read other fields

Context

In npm 7, the behavior changed from providing all package.json fields as environment variables to only providing a specific subset. This was documented in RFC 21. The old documentation was misleading as it suggested all fields were still available.

Fixes

Fixes #2452

@MaxBlack-dev MaxBlack-dev requested a review from a team as a code owner December 3, 2025 21:04
Copy link
Contributor

@owlstronaut owlstronaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you open to documenting the install-specific envars that aren't currently documented anywhere?

npm_package_resolved: resolved,
npm_package_integrity: integrity,
npm_package_json: resolve(path, 'package.json'),
npm_package_optional: boolEnv(optional),
npm_package_dev: boolEnv(dev),
npm_package_peer: boolEnv(peer),
npm_package_dev_optional:

Also, i don't think main is actually included. I'm not sure if that was missed last time this was updated or why, but it isn't here and in my local tests I'm not seeing a value.

@MaxBlack-dev MaxBlack-dev force-pushed the docs/2452-update-npm-package-vars-clean branch from 2329a66 to 09455b7 Compare December 4, 2025 19:23
@MaxBlack-dev
Copy link
Contributor Author

Thank you for the review! I've updated the documentation based on your feedback:

Changes Made

  1. Removed npm_package_main - You're correct, this is not actually provided. I verified this in the source code at node_modules/@npmcli/run-script/lib/package-envs.js which only exports name, version, config, engines, and bin.

  2. Added install-specific environment variables - Documented the additional variables that are set during install scripts (preinstall, install, postinstall):

    • npm_package_resolved - The resolved URL for the package
    • npm_package_integrity - The integrity hash for the package
    • npm_package_optional - Set to "true" if the package is optional
    • npm_package_dev - Set to "true" if the package is a dev dependency
    • npm_package_peer - Set to "true" if the package is a peer dependency
    • npm_package_dev_optional - Set to "true" if the package is both dev and optional

These are sourced from workspaces/arborist/lib/arborist/rebuild.js lines 310-316 as you referenced.

The updated documentation now accurately reflects what environment variables are actually available to scripts.

Copy link
Contributor

@owlstronaut owlstronaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

@owlstronaut owlstronaut merged commit 33a50d7 into npm:latest Dec 4, 2025
8 checks passed
@github-actions github-actions bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Broken link in npm v7 series beta re. $npm_package_* environment variables (now gone)

2 participants