Skip to content

Commit fae4945

Browse files
npm-robotdanielleadams
authored andcommitted
deps: upgrade npm to 8.3.0
PR-URL: #41127 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 34c6c59 commit fae4945

39 files changed

+1077
-109
lines changed

deps/npm/docs/content/configuring-npm/package-json.md

+103
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,109 @@ if (foo) {
871871
Entries in `optionalDependencies` will override entries of the same name in
872872
`dependencies`, so it's usually best to only put in one place.
873873

874+
### overrides
875+
876+
If you need to make specific changes to dependencies of your dependencies, for
877+
example replacing the version of a dependency with a known security issue,
878+
replacing an existing dependency with a fork, or making sure that the same
879+
version of a package is used everywhere, then you may add an override.
880+
881+
Overrides provide a way to replace a package in your dependency tree with
882+
another version, or another package entirely. These changes can be scoped as
883+
specific or as vague as desired.
884+
885+
To make sure the package `foo` is always installed as version `1.0.0` no matter
886+
what version your dependencies rely on:
887+
888+
```json
889+
{
890+
"overrides": {
891+
"foo": "1.0.0"
892+
}
893+
}
894+
```
895+
896+
The above is a short hand notation, the full object form can be used to allow
897+
overriding a package itself as well as a child of the package. This will cause
898+
`foo` to always be `1.0.0` while also making `bar` at any depth beyond `foo`
899+
also `1.0.0`:
900+
901+
```json
902+
{
903+
"overrides": {
904+
"foo": {
905+
".": "1.0.0",
906+
"bar": "1.0.0"
907+
}
908+
}
909+
}
910+
```
911+
912+
To only override `foo` to be `1.0.0` when it's a child (or grandchild, or great
913+
grandchild, etc) of the package `bar`:
914+
915+
```json
916+
{
917+
"overrides": {
918+
"bar": {
919+
"foo": "1.0.0"
920+
}
921+
}
922+
}
923+
```
924+
925+
Keys can be nested to any arbitrary length. To override `foo` only when it's a
926+
child of `bar` and only when `bar` is a child of `baz`:
927+
928+
```json
929+
{
930+
"overrides": {
931+
"baz": {
932+
"bar": {
933+
"foo": "1.0.0"
934+
}
935+
}
936+
}
937+
}
938+
```
939+
940+
The key of an override can also include a version, or range of versions.
941+
To override `foo` to `1.0.0`, but only when it's a child of `[email protected]`:
942+
943+
```json
944+
{
945+
"overrides": {
946+
947+
"foo": "1.0.0"
948+
}
949+
}
950+
}
951+
```
952+
953+
You may not set an override for a package that you directly depend on unless
954+
both the dependency and the override itself share the exact same spec. To make
955+
this limitation easier to deal with, overrides may also be defined as a
956+
reference to a spec for a direct dependency by prefixing the name of the
957+
package you wish the version to match with a `$`.
958+
959+
```json
960+
{
961+
"dependencies": {
962+
"foo": "^1.0.0"
963+
},
964+
"overrides": {
965+
// BAD, will throw an EOVERRIDE error
966+
// "foo": "^2.0.0"
967+
// GOOD, specs match so override is allowed
968+
// "foo": "^1.0.0"
969+
// BEST, the override is defined as a reference to the dependency
970+
"foo": "$foo",
971+
// the referenced package does not need to match the overridden one
972+
"bar": "$foo"
973+
}
974+
}
975+
```
976+
874977
### engines
875978
876979
You can specify the version of node that your stuff works on:

deps/npm/docs/output/commands/npm-ls.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ <h3 id="description">Description</h3>
160160
the results to only the paths to the packages named. Note that nested
161161
packages will <em>also</em> show the paths to the specified packages. For
162162
example, running <code>npm ls promzard</code> in npm's source tree will show:</p>
163-
<pre lang="bash"><code>npm@8.2.0 /path/to/npm
163+
<pre lang="bash"><code>npm@8.3.0 /path/to/npm
164164
165165
166166
</code></pre>

deps/npm/docs/output/commands/npm.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ <h2 id="table-of-contents">Table of contents</h2>
149149
<pre lang="bash"><code>npm &lt;command&gt; [args]
150150
</code></pre>
151151
<h3 id="version">Version</h3>
152-
<p>8.2.0</p>
152+
<p>8.3.0</p>
153153
<h3 id="description">Description</h3>
154154
<p>npm is the package manager for the Node JavaScript platform. It puts
155155
modules in place so that node can find them, and manages dependency

deps/npm/docs/output/configuring-npm/package-json.html

+83-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ <h1 id="packagejson">package.json</h1>
142142

143143
<section id="table_of_contents">
144144
<h2 id="table-of-contents">Table of contents</h2>
145-
<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#name">name</a></li><li><a href="#version">version</a></li><li><a href="#description2">description</a></li><li><a href="#keywords">keywords</a></li><li><a href="#homepage">homepage</a></li><li><a href="#bugs">bugs</a></li><li><a href="#license">license</a></li><li><a href="#people-fields-author-contributors">people fields: author, contributors</a></li><li><a href="#funding">funding</a></li><li><a href="#files">files</a></li><li><a href="#main">main</a></li><li><a href="#browser">browser</a></li><li><a href="#bin">bin</a></li><li><a href="#man">man</a></li><li><a href="#directories">directories</a></li><ul><li><a href="#directoriesbin">directories.bin</a></li><li><a href="#directoriesman">directories.man</a></li></ul><li><a href="#repository">repository</a></li><li><a href="#scripts">scripts</a></li><li><a href="#config">config</a></li><li><a href="#dependencies">dependencies</a></li><ul><li><a href="#urls-as-dependencies">URLs as Dependencies</a></li><li><a href="#git-urls-as-dependencies">Git URLs as Dependencies</a></li><li><a href="#github-urls">GitHub URLs</a></li><li><a href="#local-paths">Local Paths</a></li></ul><li><a href="#devdependencies">devDependencies</a></li><li><a href="#peerdependencies">peerDependencies</a></li><li><a href="#peerdependenciesmeta">peerDependenciesMeta</a></li><li><a href="#bundleddependencies">bundledDependencies</a></li><li><a href="#optionaldependencies">optionalDependencies</a></li><li><a href="#engines">engines</a></li><li><a href="#os">os</a></li><li><a href="#cpu">cpu</a></li><li><a href="#private">private</a></li><li><a href="#publishconfig">publishConfig</a></li><li><a href="#workspaces">workspaces</a></li><li><a href="#default-values">DEFAULT VALUES</a></li><li><a href="#see-also">SEE ALSO</a></li></ul></div>
145+
<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#name">name</a></li><li><a href="#version">version</a></li><li><a href="#description2">description</a></li><li><a href="#keywords">keywords</a></li><li><a href="#homepage">homepage</a></li><li><a href="#bugs">bugs</a></li><li><a href="#license">license</a></li><li><a href="#people-fields-author-contributors">people fields: author, contributors</a></li><li><a href="#funding">funding</a></li><li><a href="#files">files</a></li><li><a href="#main">main</a></li><li><a href="#browser">browser</a></li><li><a href="#bin">bin</a></li><li><a href="#man">man</a></li><li><a href="#directories">directories</a></li><ul><li><a href="#directoriesbin">directories.bin</a></li><li><a href="#directoriesman">directories.man</a></li></ul><li><a href="#repository">repository</a></li><li><a href="#scripts">scripts</a></li><li><a href="#config">config</a></li><li><a href="#dependencies">dependencies</a></li><ul><li><a href="#urls-as-dependencies">URLs as Dependencies</a></li><li><a href="#git-urls-as-dependencies">Git URLs as Dependencies</a></li><li><a href="#github-urls">GitHub URLs</a></li><li><a href="#local-paths">Local Paths</a></li></ul><li><a href="#devdependencies">devDependencies</a></li><li><a href="#peerdependencies">peerDependencies</a></li><li><a href="#peerdependenciesmeta">peerDependenciesMeta</a></li><li><a href="#bundleddependencies">bundledDependencies</a></li><li><a href="#optionaldependencies">optionalDependencies</a></li><li><a href="#overrides">overrides</a></li><li><a href="#engines">engines</a></li><li><a href="#os">os</a></li><li><a href="#cpu">cpu</a></li><li><a href="#private">private</a></li><li><a href="#publishconfig">publishConfig</a></li><li><a href="#workspaces">workspaces</a></li><li><a href="#default-values">DEFAULT VALUES</a></li><li><a href="#see-also">SEE ALSO</a></li></ul></div>
146146
</section>
147147

148148
<div id="_content"><h3 id="description">Description</h3>
@@ -800,6 +800,88 @@ <h3 id="optionaldependencies">optionalDependencies</h3>
800800
</code></pre>
801801
<p>Entries in <code>optionalDependencies</code> will override entries of the same name in
802802
<code>dependencies</code>, so it's usually best to only put in one place.</p>
803+
<h3 id="overrides">overrides</h3>
804+
<p>If you need to make specific changes to dependencies of your dependencies, for
805+
example replacing the version of a dependency with a known security issue,
806+
replacing an existing dependency with a fork, or making sure that the same
807+
version of a package is used everywhere, then you may add an override.</p>
808+
<p>Overrides provide a way to replace a package in your dependency tree with
809+
another version, or another package entirely. These changes can be scoped as
810+
specific or as vague as desired.</p>
811+
<p>To make sure the package <code>foo</code> is always installed as version <code>1.0.0</code> no matter
812+
what version your dependencies rely on:</p>
813+
<pre lang="json"><code>{
814+
"overrides": {
815+
"foo": "1.0.0"
816+
}
817+
}
818+
</code></pre>
819+
<p>The above is a short hand notation, the full object form can be used to allow
820+
overriding a package itself as well as a child of the package. This will cause
821+
<code>foo</code> to always be <code>1.0.0</code> while also making <code>bar</code> at any depth beyond <code>foo</code>
822+
also <code>1.0.0</code>:</p>
823+
<pre lang="json"><code>{
824+
"overrides": {
825+
"foo": {
826+
".": "1.0.0",
827+
"bar": "1.0.0"
828+
}
829+
}
830+
}
831+
</code></pre>
832+
<p>To only override <code>foo</code> to be <code>1.0.0</code> when it's a child (or grandchild, or great
833+
grandchild, etc) of the package <code>bar</code>:</p>
834+
<pre lang="json"><code>{
835+
"overrides": {
836+
"bar": {
837+
"foo": "1.0.0"
838+
}
839+
}
840+
}
841+
</code></pre>
842+
<p>Keys can be nested to any arbitrary length. To override <code>foo</code> only when it's a
843+
child of <code>bar</code> and only when <code>bar</code> is a child of <code>baz</code>:</p>
844+
<pre lang="json"><code>{
845+
"overrides": {
846+
"baz": {
847+
"bar": {
848+
"foo": "1.0.0"
849+
}
850+
}
851+
}
852+
}
853+
</code></pre>
854+
<p>The key of an override can also include a version, or range of versions.
855+
To override <code>foo</code> to <code>1.0.0</code>, but only when it's a child of <code>[email protected]</code>:</p>
856+
<pre lang="json"><code>{
857+
"overrides": {
858+
859+
"foo": "1.0.0"
860+
}
861+
}
862+
}
863+
</code></pre>
864+
<p>You may not set an override for a package that you directly depend on unless
865+
both the dependency and the override itself share the exact same spec. To make
866+
this limitation easier to deal with, overrides may also be defined as a
867+
reference to a spec for a direct dependency by prefixing the name of the
868+
package you wish the version to match with a <code>$</code>.</p>
869+
<pre lang="json"><code>{
870+
"dependencies": {
871+
"foo": "^1.0.0"
872+
},
873+
"overrides": {
874+
// BAD, will throw an EOVERRIDE error
875+
// "foo": "^2.0.0"
876+
// GOOD, specs match so override is allowed
877+
// "foo": "^1.0.0"
878+
// BEST, the override is defined as a reference to the dependency
879+
"foo": "$foo",
880+
// the referenced package does not need to match the overridden one
881+
"bar": "$foo"
882+
}
883+
}
884+
</code></pre>
803885
<h3 id="engines">engines</h3>
804886
<p>You can specify the version of node that your stuff works on:</p>
805887
<pre lang="json"><code>{

deps/npm/lib/commands/config.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const configDefs = require('../utils/config/index.js')
33

44
const mkdirp = require('mkdirp-infer-owner')
5-
const { dirname } = require('path')
5+
const { dirname, resolve } = require('path')
66
const { promisify } = require('util')
77
const fs = require('fs')
88
const readFile = promisify(fs.readFile)
@@ -11,6 +11,7 @@ const { spawn } = require('child_process')
1111
const { EOL } = require('os')
1212
const ini = require('ini')
1313
const localeCompare = require('@isaacs/string-locale-compare')('en')
14+
const rpj = require('read-package-json-fast')
1415
const log = require('../utils/log-shim.js')
1516

1617
// take an array of `[key, value, k2=v2, k3, v3, ...]` and turn into
@@ -28,7 +29,17 @@ const keyValues = args => {
2829
return kv
2930
}
3031

31-
const publicVar = k => !/^(\/\/[^:]+:)?_/.test(k)
32+
const publicVar = k => {
33+
// _password
34+
if (k.startsWith('_')) {
35+
return false
36+
}
37+
// //localhost:8080/:_password
38+
if (k.startsWith('//') && k.includes(':_')) {
39+
return false
40+
}
41+
return true
42+
}
3243

3344
const BaseCommand = require('../base-command.js')
3445
class Config extends BaseCommand {
@@ -147,7 +158,7 @@ class Config extends BaseCommand {
147158
const out = []
148159
for (const key of keys) {
149160
if (!publicVar(key)) {
150-
throw `The ${key} option is protected, and cannot be retrieved in this way`
161+
throw new Error(`The ${key} option is protected, and cannot be retrieved in this way`)
151162
}
152163

153164
const pref = keys.length > 1 ? `${key}=` : ''
@@ -257,6 +268,23 @@ ${defData}
257268
`; HOME = ${process.env.HOME}`,
258269
'; Run `npm config ls -l` to show all defaults.'
259270
)
271+
msg.push('')
272+
}
273+
274+
if (!this.npm.config.get('global')) {
275+
const pkgPath = resolve(this.npm.prefix, 'package.json')
276+
const pkg = await rpj(pkgPath).catch(() => ({}))
277+
278+
if (pkg.publishConfig) {
279+
msg.push(`; "publishConfig" from ${pkgPath}`)
280+
msg.push('; This set of config values will be used at publish-time.', '')
281+
const pkgKeys = Object.keys(pkg.publishConfig).sort(localeCompare)
282+
for (const k of pkgKeys) {
283+
const v = publicVar(k) ? JSON.stringify(pkg.publishConfig[k]) : '(protected)'
284+
msg.push(`${k} = ${v}`)
285+
}
286+
msg.push('')
287+
}
260288
}
261289

262290
this.npm.output(msg.join('\n').trim())

deps/npm/lib/commands/publish.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,15 @@ class Publish extends BaseCommand {
104104
const resolved = npa.resolve(manifest.name, manifest.version)
105105
const registry = npmFetch.pickRegistry(resolved, opts)
106106
const creds = this.npm.config.getCredentialsByURI(registry)
107+
const outputRegistry = replaceInfo(registry)
107108
if (!creds.token && !creds.username) {
108-
throw Object.assign(new Error('This command requires you to be logged in.'), {
109-
code: 'ENEEDAUTH',
110-
})
109+
throw Object.assign(
110+
new Error(`This command requires you to be logged in to ${outputRegistry}`), {
111+
code: 'ENEEDAUTH',
112+
}
113+
)
111114
}
115+
log.notice('', `Publishing to ${outputRegistry}`)
112116
await otplease(opts, opts => libpub(manifest, tarballData, opts))
113117
}
114118

deps/npm/lib/utils/exit-handler.js

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const exitHandler = err => {
116116
exitCode = err.code
117117
noLogMessage = true
118118
} else if (typeof err === 'string') {
119+
// XXX: we should stop throwing strings
119120
log.error('', err)
120121
noLogMessage = true
121122
} else if (!(err instanceof Error)) {

0 commit comments

Comments
 (0)