Skip to content

Commit

Permalink
deps: upgrade npm to 7.19.0
Browse files Browse the repository at this point in the history
PR-URL: #39148
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
npm-robot authored and targos committed Jul 11, 2021
1 parent 8630b39 commit bf4c50f
Show file tree
Hide file tree
Showing 78 changed files with 2,781 additions and 1,054 deletions.
23 changes: 10 additions & 13 deletions deps/npm/bin/npx-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ process.argv.splice(2, 0, 'exec')
const removedSwitches = new Set([
'always-spawn',
'ignore-existing',
'shell-auto-fallback'
'shell-auto-fallback',
])

const removedOpts = new Set([
'npm',
'node-arg',
'n'
'n',
])

const removed = new Set([
...removedSwitches,
...removedOpts
...removedOpts,
])

const { definitions, shorthands } = require('../lib/utils/config/index.js')
Expand All @@ -40,7 +40,7 @@ const switches = new Set([
'version',
'v',
'help',
'h'
'h',
])

// things that do take a value
Expand All @@ -55,7 +55,7 @@ const opts = new Set([
'shell',
'npm',
'node-arg',
'n'
'n',
])

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

switch (key) {
Expand All @@ -87,9 +87,8 @@ for (i = 3; i < process.argv.length; i++) {
// resolve shorthands and run again
if (shorthands[key] && !removed.has(key)) {
const a = [...shorthands[key]]
if (v.length) {
if (v.length)
a.push(v.join('='))
}
process.argv.splice(i, 1, ...a)
i--
continue
Expand All @@ -110,9 +109,8 @@ for (i = 3; i < process.argv.length; i++) {
if (removed.has(key)) {
// also remove the value for the cut key.
process.argv.splice(i + 1, 1)
} else {
} else
i++
}
}
} else {
// found a positional arg, put -- in front of it, and we're done
Expand All @@ -121,8 +119,7 @@ for (i = 3; i < process.argv.length; i++) {
}
}

if (sawRemovedFlags) {
if (sawRemovedFlags)
console.error('See `npm help exec` for more information')
}

cli(process)
4 changes: 2 additions & 2 deletions deps/npm/docs/content/using-npm/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Workspaces are usually defined via the `workspaces` property of the
```

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

```
.
Expand Down
2 changes: 1 addition & 1 deletion deps/npm/docs/output/commands/npm-ls.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ <h3 id="description">Description</h3>
the results to only the paths to the packages named. Note that nested
packages will <em>also</em> show the paths to the specified packages. For
example, running <code>npm ls promzard</code> in npm’s source tree will show:</p>
<pre lang="bash"><code>npm@7.18.1 /path/to/npm
<pre lang="bash"><code>npm@7.19.0 /path/to/npm
└─┬ init-package-json@0.0.4
└── promzard@0.1.5
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion deps/npm/docs/output/commands/npm.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h2 id="table-of-contents">Table of contents</h2>
<pre lang="bash"><code>npm &lt;command&gt; [args]
</code></pre>
<h3 id="version">Version</h3>
<p>7.18.1</p>
<p>7.19.0</p>
<h3 id="description">Description</h3>
<p>npm is the package manager for the Node JavaScript platform. It puts
modules in place so that node can find them, and manages dependency
Expand Down
4 changes: 2 additions & 2 deletions deps/npm/docs/output/using-npm/workspaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ <h3 id="defining-workspaces">Defining workspaces</h3>
}
</code></pre>
<p>Given the above <code>package.json</code> example living at a current working
directory <code>.</code> that contains a folder named <code>workspace-a</code> that disposes
of a <code>package.json</code> inside it, defining a nodejs package, e.g:</p>
directory <code>.</code> that contains a folder named <code>workspace-a</code> that itself contains
a <code>package.json</code> inside it, defining a nodejs package, e.g:</p>
<pre><code>.
+-- package.json
`-- workspace-a
Expand Down
55 changes: 27 additions & 28 deletions deps/npm/lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Separated out for easier unit testing
module.exports = (process) => {
module.exports = async (process) => {
// set it here so that regardless of what happens later, we don't
// leak any private CLI configs to other programs
process.title = 'npm'
Expand All @@ -19,8 +19,8 @@ module.exports = (process) => {
checkForUnsupportedNode()

const npm = require('../lib/npm.js')
const errorHandler = require('../lib/utils/error-handler.js')
errorHandler.setNpm(npm)
const exitHandler = require('../lib/utils/exit-handler.js')
exitHandler.setNpm(npm)

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

process.on('uncaughtException', errorHandler)
process.on('unhandledRejection', errorHandler)
process.on('uncaughtException', exitHandler)
process.on('unhandledRejection', exitHandler)

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

// npm --version=cli
// now actually fire up npm and run the command.
// this is how to use npm programmatically:
try {
await npm.load()
if (npm.config.get('version', 'cli')) {
npm.output(npm.version)
return errorHandler.exit(0)
return exitHandler()
}

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

const cmd = npm.argv.shift()
if (!cmd) {
npm.output(npm.usage)
process.exitCode = 1
return exitHandler()
}

const impl = npm.commands[cmd]
if (impl)
impl(npm.argv, errorHandler)
else {
try {
if (cmd) {
const didYouMean = require('./utils/did-you-mean.js')
const suggestions = await didYouMean(npm, npm.localPrefix, cmd)
npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`)
} else
npm.output(npm.usage)
process.exitCode = 1
return errorHandler()
} catch (err) {
errorHandler(err)
}
if (!impl) {
const didYouMean = require('./utils/did-you-mean.js')
const suggestions = await didYouMean(npm, npm.localPrefix, cmd)
npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`)
process.exitCode = 1
return exitHandler()
}
})

impl(npm.argv, exitHandler)
} catch (err) {
return exitHandler(err)
}
}
37 changes: 9 additions & 28 deletions deps/npm/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const initJson = require('init-package-json')
const npa = require('npm-package-arg')
const rpj = require('read-package-json-fast')
const libexec = require('libnpmexec')
const parseJSON = require('json-parse-even-better-errors')
const mapWorkspaces = require('@npmcli/map-workspaces')
const PackageJson = require('@npmcli/package-json')

const getLocationMsg = require('./exec/get-workspace-location-msg.js')
const BaseCommand = require('./base-command.js')
Expand Down Expand Up @@ -199,35 +199,16 @@ class Init extends BaseCommand {
return
}

let manifest
try {
manifest =
fs.readFileSync(resolve(this.npm.localPrefix, 'package.json'), 'utf-8')
} catch (error) {
throw new Error('package.json not found')
}

try {
manifest = parseJSON(manifest)
} catch (error) {
throw new Error(`Invalid package.json: ${error}`)
}
const pkgJson = await PackageJson.load(this.npm.localPrefix)

if (!manifest.workspaces)
manifest.workspaces = []

manifest.workspaces.push(relative(this.npm.localPrefix, workspacePath))

// format content
const {
[Symbol.for('indent')]: indent,
[Symbol.for('newline')]: newline,
} = manifest

const content = (JSON.stringify(manifest, null, indent) + '\n')
.replace(/\n/g, newline)
pkgJson.update({
workspaces: [
...(pkgJson.content.workspaces || []),
relative(this.npm.localPrefix, workspacePath),
],
})

fs.writeFileSync(resolve(this.npm.localPrefix, 'package.json'), content)
await pkgJson.save()
}
}

Expand Down
23 changes: 14 additions & 9 deletions deps/npm/lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,9 @@ class LS extends ArboristWorkspaceCmd {
dev,
development,
link,
node,
prod,
production,
only,
tree,
}))
.map(mapEdgesToNodes({ seenPaths }))
.concat(appendExtraneousChildren({ node, seenPaths }))
Expand Down Expand Up @@ -310,6 +308,9 @@ const getHumanOutputItem = (node, { args, color, global, long }) => {
const targetLocation = node.root
? relative(node.root.realpath, node.realpath)
: node.targetLocation
const invalid = node[_invalid]
? `invalid: ${node[_invalid]}`
: ''
const label =
(
node[_missing]
Expand All @@ -323,8 +324,8 @@ const getHumanOutputItem = (node, { args, color, global, long }) => {
: ''
) +
(
node[_invalid]
? ' ' + (color ? chalk.red.bgBlack('invalid') : 'invalid')
invalid
? ' ' + (color ? chalk.red.bgBlack(invalid) : invalid)
: ''
) +
(
Expand Down Expand Up @@ -375,7 +376,7 @@ const getJsonOutputItem = (node, { global, long }) => {
item.extraneous = true

if (node[_invalid])
item.invalid = true
item.invalid = node[_invalid]

if (node[_missing] && !isOptional(node)) {
item.required = node[_required]
Expand All @@ -392,11 +393,9 @@ const filterByEdgesTypes = ({
dev,
development,
link,
node,
prod,
production,
only,
tree,
}) => {
// filter deps by type, allows for: `npm ls --dev`, `npm ls --prod`,
// `npm ls --link`, `npm ls --only=dev`, etc
Expand Down Expand Up @@ -436,9 +435,15 @@ const mapEdgesToNodes = ({ seenPaths }) => (edge) => {
if (node.path)
seenPaths.add(node.path)

node[_required] = edge.spec
node[_required] = edge.spec || '*'
node[_type] = edge.type
node[_invalid] = edge.invalid

if (edge.invalid) {
const spec = JSON.stringify(node[_required])
const from = edge.from.location || 'the root project'
node[_invalid] = (node[_invalid] ? node[_invalid] + ', ' : '') +
(`${spec} from ${from}`)
}

return node
}
Expand Down
Loading

0 comments on commit bf4c50f

Please sign in to comment.