Skip to content

Commit bf4c50f

Browse files
npm-robottargos
authored andcommitted
deps: upgrade npm to 7.19.0
PR-URL: #39148 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 8630b39 commit bf4c50f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2781
-1054
lines changed

Diff for: deps/npm/bin/npx-cli.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ process.argv.splice(2, 0, 'exec')
1010
const removedSwitches = new Set([
1111
'always-spawn',
1212
'ignore-existing',
13-
'shell-auto-fallback'
13+
'shell-auto-fallback',
1414
])
1515

1616
const removedOpts = new Set([
1717
'npm',
1818
'node-arg',
19-
'n'
19+
'n',
2020
])
2121

2222
const removed = new Set([
2323
...removedSwitches,
24-
...removedOpts
24+
...removedOpts,
2525
])
2626

2727
const { definitions, shorthands } = require('../lib/utils/config/index.js')
@@ -40,7 +40,7 @@ const switches = new Set([
4040
'version',
4141
'v',
4242
'help',
43-
'h'
43+
'h',
4444
])
4545

4646
// things that do take a value
@@ -55,7 +55,7 @@ const opts = new Set([
5555
'shell',
5656
'npm',
5757
'node-arg',
58-
'n'
58+
'n',
5959
])
6060

6161
// break out of loop when we find a positional argument or --
@@ -65,9 +65,9 @@ let i
6565
let sawRemovedFlags = false
6666
for (i = 3; i < process.argv.length; i++) {
6767
const arg = process.argv[i]
68-
if (arg === '--') {
68+
if (arg === '--')
6969
break
70-
} else if (/^-/.test(arg)) {
70+
else if (/^-/.test(arg)) {
7171
const [key, ...v] = arg.replace(/^-+/, '').split('=')
7272

7373
switch (key) {
@@ -87,9 +87,8 @@ for (i = 3; i < process.argv.length; i++) {
8787
// resolve shorthands and run again
8888
if (shorthands[key] && !removed.has(key)) {
8989
const a = [...shorthands[key]]
90-
if (v.length) {
90+
if (v.length)
9191
a.push(v.join('='))
92-
}
9392
process.argv.splice(i, 1, ...a)
9493
i--
9594
continue
@@ -110,9 +109,8 @@ for (i = 3; i < process.argv.length; i++) {
110109
if (removed.has(key)) {
111110
// also remove the value for the cut key.
112111
process.argv.splice(i + 1, 1)
113-
} else {
112+
} else
114113
i++
115-
}
116114
}
117115
} else {
118116
// found a positional arg, put -- in front of it, and we're done
@@ -121,8 +119,7 @@ for (i = 3; i < process.argv.length; i++) {
121119
}
122120
}
123121

124-
if (sawRemovedFlags) {
122+
if (sawRemovedFlags)
125123
console.error('See `npm help exec` for more information')
126-
}
127124

128125
cli(process)

Diff for: deps/npm/docs/content/using-npm/workspaces.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Workspaces are usually defined via the `workspaces` property of the
3636
```
3737

3838
Given the above `package.json` example living at a current working
39-
directory `.` that contains a folder named `workspace-a` that disposes
40-
of a `package.json` inside it, defining a nodejs package, e.g:
39+
directory `.` that contains a folder named `workspace-a` that itself contains
40+
a `package.json` inside it, defining a nodejs package, e.g:
4141

4242
```
4343
.

Diff for: deps/npm/docs/output/commands/npm-ls.html

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

Diff for: deps/npm/docs/output/commands/npm.html

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

Diff for: deps/npm/docs/output/using-npm/workspaces.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ <h3 id="defining-workspaces">Defining workspaces</h3>
168168
}
169169
</code></pre>
170170
<p>Given the above <code>package.json</code> example living at a current working
171-
directory <code>.</code> that contains a folder named <code>workspace-a</code> that disposes
172-
of a <code>package.json</code> inside it, defining a nodejs package, e.g:</p>
171+
directory <code>.</code> that contains a folder named <code>workspace-a</code> that itself contains
172+
a <code>package.json</code> inside it, defining a nodejs package, e.g:</p>
173173
<pre><code>.
174174
+-- package.json
175175
`-- workspace-a

Diff for: deps/npm/lib/cli.js

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Separated out for easier unit testing
2-
module.exports = (process) => {
2+
module.exports = async (process) => {
33
// set it here so that regardless of what happens later, we don't
44
// leak any private CLI configs to other programs
55
process.title = 'npm'
@@ -19,8 +19,8 @@ module.exports = (process) => {
1919
checkForUnsupportedNode()
2020

2121
const npm = require('../lib/npm.js')
22-
const errorHandler = require('../lib/utils/error-handler.js')
23-
errorHandler.setNpm(npm)
22+
const exitHandler = require('../lib/utils/exit-handler.js')
23+
exitHandler.setNpm(npm)
2424

2525
// if npm is called as "npmg" or "npm_g", then
2626
// run in global mode.
@@ -32,20 +32,18 @@ module.exports = (process) => {
3232
log.info('using', 'npm@%s', npm.version)
3333
log.info('using', 'node@%s', process.version)
3434

35-
process.on('uncaughtException', errorHandler)
36-
process.on('unhandledRejection', errorHandler)
35+
process.on('uncaughtException', exitHandler)
36+
process.on('unhandledRejection', exitHandler)
3737

38-
// now actually fire up npm and run the command.
39-
// this is how to use npm programmatically:
4038
const updateNotifier = require('../lib/utils/update-notifier.js')
41-
npm.load(async er => {
42-
if (er)
43-
return errorHandler(er)
4439

45-
// npm --version=cli
40+
// now actually fire up npm and run the command.
41+
// this is how to use npm programmatically:
42+
try {
43+
await npm.load()
4644
if (npm.config.get('version', 'cli')) {
4745
npm.output(npm.version)
48-
return errorHandler.exit(0)
46+
return exitHandler()
4947
}
5048

5149
// npm --versions=cli
@@ -57,22 +55,23 @@ module.exports = (process) => {
5755
updateNotifier(npm)
5856

5957
const cmd = npm.argv.shift()
58+
if (!cmd) {
59+
npm.output(npm.usage)
60+
process.exitCode = 1
61+
return exitHandler()
62+
}
63+
6064
const impl = npm.commands[cmd]
61-
if (impl)
62-
impl(npm.argv, errorHandler)
63-
else {
64-
try {
65-
if (cmd) {
66-
const didYouMean = require('./utils/did-you-mean.js')
67-
const suggestions = await didYouMean(npm, npm.localPrefix, cmd)
68-
npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`)
69-
} else
70-
npm.output(npm.usage)
71-
process.exitCode = 1
72-
return errorHandler()
73-
} catch (err) {
74-
errorHandler(err)
75-
}
65+
if (!impl) {
66+
const didYouMean = require('./utils/did-you-mean.js')
67+
const suggestions = await didYouMean(npm, npm.localPrefix, cmd)
68+
npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`)
69+
process.exitCode = 1
70+
return exitHandler()
7671
}
77-
})
72+
73+
impl(npm.argv, exitHandler)
74+
} catch (err) {
75+
return exitHandler(err)
76+
}
7877
}

Diff for: deps/npm/lib/init.js

+9-28
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const initJson = require('init-package-json')
55
const npa = require('npm-package-arg')
66
const rpj = require('read-package-json-fast')
77
const libexec = require('libnpmexec')
8-
const parseJSON = require('json-parse-even-better-errors')
98
const mapWorkspaces = require('@npmcli/map-workspaces')
9+
const PackageJson = require('@npmcli/package-json')
1010

1111
const getLocationMsg = require('./exec/get-workspace-location-msg.js')
1212
const BaseCommand = require('./base-command.js')
@@ -199,35 +199,16 @@ class Init extends BaseCommand {
199199
return
200200
}
201201

202-
let manifest
203-
try {
204-
manifest =
205-
fs.readFileSync(resolve(this.npm.localPrefix, 'package.json'), 'utf-8')
206-
} catch (error) {
207-
throw new Error('package.json not found')
208-
}
209-
210-
try {
211-
manifest = parseJSON(manifest)
212-
} catch (error) {
213-
throw new Error(`Invalid package.json: ${error}`)
214-
}
202+
const pkgJson = await PackageJson.load(this.npm.localPrefix)
215203

216-
if (!manifest.workspaces)
217-
manifest.workspaces = []
218-
219-
manifest.workspaces.push(relative(this.npm.localPrefix, workspacePath))
220-
221-
// format content
222-
const {
223-
[Symbol.for('indent')]: indent,
224-
[Symbol.for('newline')]: newline,
225-
} = manifest
226-
227-
const content = (JSON.stringify(manifest, null, indent) + '\n')
228-
.replace(/\n/g, newline)
204+
pkgJson.update({
205+
workspaces: [
206+
...(pkgJson.content.workspaces || []),
207+
relative(this.npm.localPrefix, workspacePath),
208+
],
209+
})
229210

230-
fs.writeFileSync(resolve(this.npm.localPrefix, 'package.json'), content)
211+
await pkgJson.save()
231212
}
232213
}
233214

Diff for: deps/npm/lib/ls.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ class LS extends ArboristWorkspaceCmd {
145145
dev,
146146
development,
147147
link,
148-
node,
149148
prod,
150149
production,
151150
only,
152-
tree,
153151
}))
154152
.map(mapEdgesToNodes({ seenPaths }))
155153
.concat(appendExtraneousChildren({ node, seenPaths }))
@@ -310,6 +308,9 @@ const getHumanOutputItem = (node, { args, color, global, long }) => {
310308
const targetLocation = node.root
311309
? relative(node.root.realpath, node.realpath)
312310
: node.targetLocation
311+
const invalid = node[_invalid]
312+
? `invalid: ${node[_invalid]}`
313+
: ''
313314
const label =
314315
(
315316
node[_missing]
@@ -323,8 +324,8 @@ const getHumanOutputItem = (node, { args, color, global, long }) => {
323324
: ''
324325
) +
325326
(
326-
node[_invalid]
327-
? ' ' + (color ? chalk.red.bgBlack('invalid') : 'invalid')
327+
invalid
328+
? ' ' + (color ? chalk.red.bgBlack(invalid) : invalid)
328329
: ''
329330
) +
330331
(
@@ -375,7 +376,7 @@ const getJsonOutputItem = (node, { global, long }) => {
375376
item.extraneous = true
376377

377378
if (node[_invalid])
378-
item.invalid = true
379+
item.invalid = node[_invalid]
379380

380381
if (node[_missing] && !isOptional(node)) {
381382
item.required = node[_required]
@@ -392,11 +393,9 @@ const filterByEdgesTypes = ({
392393
dev,
393394
development,
394395
link,
395-
node,
396396
prod,
397397
production,
398398
only,
399-
tree,
400399
}) => {
401400
// filter deps by type, allows for: `npm ls --dev`, `npm ls --prod`,
402401
// `npm ls --link`, `npm ls --only=dev`, etc
@@ -436,9 +435,15 @@ const mapEdgesToNodes = ({ seenPaths }) => (edge) => {
436435
if (node.path)
437436
seenPaths.add(node.path)
438437

439-
node[_required] = edge.spec
438+
node[_required] = edge.spec || '*'
440439
node[_type] = edge.type
441-
node[_invalid] = edge.invalid
440+
441+
if (edge.invalid) {
442+
const spec = JSON.stringify(node[_required])
443+
const from = edge.from.location || 'the root project'
444+
node[_invalid] = (node[_invalid] ? node[_invalid] + ', ' : '') +
445+
(`${spec} from ${from}`)
446+
}
442447

443448
return node
444449
}

0 commit comments

Comments
 (0)