Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/lib/content/configuring-npm/npmrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ _authToken=MYTOKEN
//somewhere-else.com/another/:_authToken=MYTOKEN2
```

### Custom / third-party config keys

npm only recognizes its own [configuration options](/using-npm/config).
If your `.npmrc` contains keys that are not part of npm's config definitions
(for example, `electron_mirror` or `sass_binary_site`), npm will emit a
warning:

```
warn Unknown user config "electron_mirror".
This will stop working in the next major version of npm.
```

These keys were historically tolerated but are not officially supported.
A future major version of npm will treat unknown top-level keys as errors.

Some tools (such as `@electron/get` or `node-sass`) read their own
configuration from environment variables or from `.npmrc` by convention.
You can set these values as environment variables instead:

```bash
export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
Copy link
Member

Choose a reason for hiding this comment

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

In the past these example domains have been vectors for people to squat on them and claim a vulnerability. We try our best now to only use domains that npm itself owns, even in examples.

Can we change the example domains here to be something like mirrorexample.npmjs.org?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wraithgar Updated! Changed example domain to mirrorexample.npmjs.org

export ELECTRON_CUSTOM_DIR="{{ version }}"
```

Environment variables are the most portable approach and work regardless
of `.npmrc` format.

### See also

* [npm folders](/configuring-npm/folders)
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,6 @@ registry = "https://some.registry"

exports[`test/lib/commands/config.js TAP config list with publishConfig local > warns about unknown config 1`] = `
Array [
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm.",
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See \`npm help npmrc\`.",
Copy link
Member

Choose a reason for hiding this comment

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

Still recommending ini section here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wraithgar Thanks for the feedback! Made all the changes:

  • Removed the [sectionName] hint from the warning message
  • Updated it to just say "See npm help npmrc for supported config options."
  • Removed the ini [section] recommendation from docs
  • Fixed the example domain to mirrorexample.npmjs.org
  • All tests and snapshots updated (108 suites passing)

Let me know if anything else needs tweaking!

]
`
2 changes: 1 addition & 1 deletion test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ t.test('respects publishConfig.registry, runs appropriate scripts', async t => {
t.equal(fs.existsSync(path.join(prefix, 'scripts-prepublish')), false, 'did not run prepublish')
t.equal(fs.existsSync(path.join(prefix, 'scripts-publish')), true, 'ran publish')
t.equal(fs.existsSync(path.join(prefix, 'scripts-postpublish')), true, 'ran postpublish')
t.same(logs.warn, ['Unknown publishConfig config "other". This will stop working in the next major version of npm.'])
t.same(logs.warn, ['Unknown publishConfig config "other". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'])
})

t.test('re-loads publishConfig.registry if added during script process', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ t.test('publishConfig no spec', async t => {
t.equal(joinedOutput(), '- test-package')
t.same(logs.warn, [
'using --force Recommended protections disabled.',
'Unknown publishConfig config "other". This will stop working in the next major version of npm.',
'Unknown publishConfig config "other". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.',
])
})

Expand Down
7 changes: 5 additions & 2 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,16 @@ class Config {
if (internalEnv.includes(key)) {
return
}
const hint = where !== 'cli'
? ' To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'
: ''
if (!key.includes(':')) {
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.${hint}`)
return
}
const baseKey = key.split(':').pop()
if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.`)
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.${hint}`)
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions workspaces/config/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ loglevel = yolo
// warn logs are emitted as a side effect of validate
config.validate()
t.strictSame(logs.filter(l => l[0] === 'warn'), [
['warn', 'Unknown builtin config "builtin-config". This will stop working in the next major version of npm.'],
['warn', 'Unknown builtin config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown builtin config "builtin-config". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown builtin config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'invalid config', 'registry="hello"', 'set in command line options'],
['warn', 'invalid config', 'Must be', 'full url with "http://"'],
['warn', 'invalid config', 'proxy="hello"', 'set in command line options'],
Expand All @@ -399,13 +399,13 @@ loglevel = yolo
['warn', 'invalid config', 'prefix=true', 'set in command line options'],
['warn', 'invalid config', 'Must be', 'valid filesystem path'],
['warn', 'config', 'also', 'Please use --include=dev instead.'],
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown project config "project-config". This will stop working in the next major version of npm.'],
['warn', 'Unknown project config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown user config "user-config-from-builtin". This will stop working in the next major version of npm.'],
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm.'],
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown project config "project-config". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown project config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown user config "user-config-from-builtin". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'invalid config', 'loglevel="yolo"', `set in ${resolve(path, 'project/.npmrc')}`],
['warn', 'invalid config', 'Must be one of:',
['silent', 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'].join(', '),
Expand Down Expand Up @@ -600,12 +600,12 @@ loglevel = yolo
['warn', 'invalid config', 'prefix=true', 'set in command line options'],
['warn', 'invalid config', 'Must be', 'valid filesystem path'],
['warn', 'config', 'also', 'Please use --include=dev instead.'],
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown user config "default-user-config-in-home". This will stop working in the next major version of npm.'],
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm.'],
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm.'],
['warn', 'Unknown global config "asdf". This will stop working in the next major version of npm.'],
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown user config "default-user-config-in-home". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
['warn', 'Unknown global config "asdf". This will stop working in the next major version of npm. To pass package-specific config, use a scoped [sectionName] in .npmrc. See `npm help npmrc`.'],
])
logs.length = 0
})
Expand Down