-
Notifications
You must be signed in to change notification settings - Fork 3.4k
docs: Explain environment variables from package.json
, .npmrc
and npm
#7856
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
base: latest
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this addition. LGTM 👍
The package.json fields are tacked onto the `npm_package_` prefix. So, | ||
for instance, if you had `{"name":"foo", "version":"1.2.5"}` in your | ||
package.json file, then your package scripts would have the | ||
`npm_package_name` environment variable set to "foo", and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These still exist and are very load bearing
$ npm run env|grep name
npm_package_name=npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this what the extended example includes (L282)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No the name/version entries are distinct from the config. They are powered by entries in package.json and can't be change via config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the example matches the code:
Agree. We should be more explicit. How about:
- Only
name
,version
,engines
,config
, andbin
frompackage.json
are available. Other fields are not exposed as environment variables (see RFC). If you want to know what is inpackage.json
, you can read and parse the file or userequire('./package.json')
, for example.
Environment variables explanation was incorrect before.
I haven't been able to get any more env vars from the package.json other than the name, version, engines, config and bin. If more env vars are populated, I'll adjust the documentation, but they're the only ones afaict