Skip to content

Warn on unknown configs #8071

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

Merged
merged 5 commits into from
Jan 30, 2025
Merged

Warn on unknown configs #8071

merged 5 commits into from
Jan 30, 2025

Conversation

wraithgar
Copy link
Member

@wraithgar wraithgar commented Jan 28, 2025

This PR will:

  • Make npm log a warning when it is parsing a config item that is not defined.
  • Make npm log a warning when it is expanding abbreviated config items.
  • Warn when an unknown cli flag is making what the user may have intended as a config value be parsed as a positional arg.
  • Move nerf-dart configs that were originally hard coded in the npm config command into @npmcli/config for reuse.
  • Update nopt to 8.1.0 which has the new features needed to implement these new warnings for cli flags.

terminal output showing new warnings in effect
terminal output showing how to use -- to isolate npm args from script args in npm exec

It is not a valid cli flag, single-hyphen flags should all be single-character.  Eventually `-ws` will need to go away so will at least stop suggesting it now.
@wraithgar wraithgar requested a review from a team as a code owner January 28, 2025 19:09
Copy link

@Tayvon Tayvon left a comment

Choose a reason for hiding this comment

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

LGTM!

@ljharb
Copy link
Contributor

ljharb commented Jan 30, 2025

Can there be a config to silence these warnings?

@wraithgar
Copy link
Member Author

No there will not. This is an important warning that npm is doing something unexpected. The only place this will likely remain a permanent warning and not an eventual exception is publishConfig because that is ostensibly something other package managers may use. cli flags and npmrc files are not for parsing by things that aren't npm. The warnings from publishConfig will likely change to a "this is being ignored" message when we move to fully disallowing undefined configs, but it will always be there. npm has no way of knowing what in there is legitimate or a mistake so it will always warn.

@wraithgar wraithgar merged commit ed85b01 into latest Jan 30, 2025
46 checks passed
@wraithgar wraithgar deleted the gar/invalid-config branch January 30, 2025 16:45
@github-actions github-actions bot mentioned this pull request Jan 30, 2025
@ljharb
Copy link
Contributor

ljharb commented Jan 30, 2025

I agree that anything in npmrc or cli flags is npm's sole purview, and warnings make sense - but things in package.json aren't and they often won't.

wraithgar added a commit that referenced this pull request Mar 6, 2025
pr #8071 originally had this but that appears to have gotten lost along the way.
wraithgar added a commit that referenced this pull request Mar 7, 2025
PR #8071 originally had this but that appears to have gotten lost along
the way.
kirrg001 added a commit to instana/nodejs that referenced this pull request May 9, 2025
kirrg001 added a commit to instana/nodejs that referenced this pull request May 14, 2025
kirrg001 added a commit to instana/nodejs that referenced this pull request May 14, 2025
refs https://jsw.ibm.com/browse/INSTA-36236

- using custom npm configs is longer supported: npm/cli#8071
- removed $npm_config_watch
@nikitaeverywhere
Copy link

This is an important warning

We 💜 breaking changes (no)

As I understand, I will no longer be able to put something like

ENV_VAR=123

into my .npmrc file and get npm_config_ENV_VAR environment variable when running npm scripts?

@wraithgar can we at least make this warning not just say "we'll drop it" but SUGGEST AN ALTERNATIVE for envs in .npmrc file? Setting envs via .npmrc file was documented and I guess is quite used around (also in my project), people will have to migrate (as I understand, an alternative is package.json "config"?).

Thanks.

@nikitaeverywhere
Copy link

@Tayvon @wraithgar guys with this update you'll break some existing packages.

In prev npm versions, I was able to have this .npmrc file:

ANY_ENV_VAR=dev

...which would set npm_config_ANY_ENV_VAR env var to dev when running npm install and so.

I used this to install @mycompany/mypackage which internally reads process.env["npm_config_ANY_ENV_VAR"] in its "postinstall" script with

process.env[`npm_config_ANY_ENV_VAR`];

How to do it now with this new update?

I've tried reading process.env["npm_package_config_ANY_ENV_VAR"] but there's no npm_package_config_ANY_ENV_VAR (maybe it's not populated for postinstall of dependent packages?).

Setting envs manually is not an option, as I want people to just npm install (when pulling the repo) and do nothing more (like settings envs)

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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy