Skip to content
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

deps: upgrade npm to 8.5.4 #42288

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/npm/docs/content/configuring-npm/package-json.md
Expand Up @@ -323,7 +323,7 @@ This should be a module relative to the root of your package folder.
For most modules, it makes the most sense to have a main script and often
not much else.

If `main` is not set it defaults to `index.js` in the packages root folder.
If `main` is not set it defaults to `index.js` in the package's root folder.

### browser

Expand Down
2 changes: 1 addition & 1 deletion deps/npm/docs/output/commands/npm-ls.html
Expand Up @@ -166,7 +166,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@8.5.3 /path/to/npm
<pre lang="bash"><code>npm@8.5.4 /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
Expand Up @@ -149,7 +149,7 @@ <h2 id="table-of-contents">Table of contents</h2>
<!-- raw HTML omitted -->
<!-- raw HTML omitted -->
<h3 id="version">Version</h3>
<p>8.5.3</p>
<p>8.5.4</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
2 changes: 1 addition & 1 deletion deps/npm/docs/output/configuring-npm/package-json.html
Expand Up @@ -391,7 +391,7 @@ <h3 id="main">main</h3>
<p>This should be a module relative to the root of your package folder.</p>
<p>For most modules, it makes the most sense to have a main script and often
not much else.</p>
<p>If <code>main</code> is not set it defaults to <code>index.js</code> in the packages root folder.</p>
<p>If <code>main</code> is not set it defaults to <code>index.js</code> in the package's root folder.</p>
<h3 id="browser">browser</h3>
<p>If your module is meant to be used client-side the browser field should be
used instead of the main field. This is helpful to hint users that it might
Expand Down
45 changes: 24 additions & 21 deletions deps/npm/lib/commands/doctor.js
Expand Up @@ -10,7 +10,6 @@ const semver = require('semver')
const { promisify } = require('util')
const log = require('../utils/log-shim.js')
const ansiTrim = require('../utils/ansi-trim.js')
const isWindows = require('../utils/is-windows.js')
const ping = require('../utils/ping.js')
const {
registry: { default: defaultRegistry },
Expand Down Expand Up @@ -55,32 +54,36 @@ class Doctor extends BaseCommand {
['node -v', 'getLatestNodejsVersion', []],
['npm config get registry', 'checkNpmRegistry', []],
['which git', 'getGitPath', []],
...(isWindows
...(process.platform === 'win32'
? []
: [
['Perms check on cached files', 'checkFilesPermission', [this.npm.cache, true, R_OK]],
[
'Perms check on cached files',
'checkFilesPermission',
[this.npm.cache, true, R_OK],
], [
'Perms check on local node_modules',
'checkFilesPermission',
[this.npm.localDir, true],
],
[
[this.npm.localDir, true, R_OK | W_OK, true],
], [
'Perms check on global node_modules',
'checkFilesPermission',
[this.npm.globalDir, false],
],
[
[this.npm.globalDir, false, R_OK],
], [
'Perms check on local bin folder',
'checkFilesPermission',
[this.npm.localBin, false, R_OK | W_OK | X_OK],
],
[
[this.npm.localBin, false, R_OK | W_OK | X_OK, true],
], [
'Perms check on global bin folder',
'checkFilesPermission',
[this.npm.globalBin, false, X_OK],
],
]),
['Verify cache contents', 'verifyCachedFiles', [this.npm.flatOptions.cache]],
[
'Verify cache contents',
'verifyCachedFiles',
[this.npm.flatOptions.cache],
],
// TODO:
// - ensure arborist.loadActual() runs without errors and no invalid edges
// - ensure package-lock.json matches loadActual()
Expand Down Expand Up @@ -129,6 +132,7 @@ class Doctor extends BaseCommand {
if (!this.npm.silent) {
this.npm.output(table(outTable, tableOpts))
if (!allOk) {
// TODO is this really needed?
console.error('')
}
}
Expand All @@ -141,7 +145,7 @@ class Doctor extends BaseCommand {
const tracker = log.newItem('checkPing', 1)
tracker.info('checkPing', 'Pinging registry')
try {
await ping(this.npm.flatOptions)
await ping({ ...this.npm.flatOptions, retry: false })
return ''
} catch (er) {
if (/^E\d{3}$/.test(er.code || '')) {
Expand Down Expand Up @@ -201,11 +205,7 @@ class Doctor extends BaseCommand {
}
}

async checkFilesPermission (root, shouldOwn, mask = null) {
if (mask === null) {
mask = shouldOwn ? R_OK | W_OK : R_OK
}

async checkFilesPermission (root, shouldOwn, mask, missingOk) {
let ok = true

const tracker = log.newItem(root, 1)
Expand All @@ -217,8 +217,11 @@ class Doctor extends BaseCommand {
for (const f of files) {
tracker.silly('checkFilesPermission', f.substr(root.length + 1))
const st = await lstat(f).catch(er => {
ok = false
tracker.warn('checkFilesPermission', 'error getting info for ' + f)
// if it can't be missing, or if it can and the error wasn't that it was missing
if (!missingOk || er.code !== 'ENOENT') {
ok = false
tracker.warn('checkFilesPermission', 'error getting info for ' + f)
}
})

tracker.completeWork(1)
Expand Down
169 changes: 56 additions & 113 deletions deps/npm/lib/commands/owner.js
Expand Up @@ -59,60 +59,39 @@ class Owner extends BaseCommand {
}

async exec ([action, ...args]) {
const opts = {
...this.npm.flatOptions,
}
switch (action) {
case 'ls':
case 'list':
return this.ls(args[0], opts)
return this.ls(args[0])
case 'add':
return this.add(args[0], args[1], opts)
return this.changeOwners(args[0], args[1], 'add')
case 'rm':
case 'remove':
return this.rm(args[0], args[1], opts)
return this.changeOwners(args[0], args[1], 'rm')
default:
throw this.usageError()
}
}

async ls (pkg, opts) {
if (!pkg) {
if (this.npm.config.get('global')) {
throw this.usageError()
}

const pkgName = await readLocalPkgName(this.npm.prefix)
if (!pkgName) {
throw this.usageError()
}

pkg = pkgName
}

async ls (pkg) {
pkg = await this.getPkg(pkg)
const spec = npa(pkg)

try {
const packumentOpts = { ...opts, fullMetadata: true }
const packumentOpts = { ...this.npm.flatOptions, fullMetadata: true }
const { maintainers } = await pacote.packument(spec, packumentOpts)
if (!maintainers || !maintainers.length) {
this.npm.output('no admin found')
} else {
this.npm.output(maintainers.map(o => `${o.name} <${o.email}>`).join('\n'))
this.npm.output(maintainers.map(m => `${m.name} <${m.email}>`).join('\n'))
}

return maintainers
} catch (err) {
log.error('owner ls', "Couldn't get owner data", pkg)
throw err
}
}

async add (user, pkg, opts) {
if (!user) {
throw this.usageError()
}

async getPkg (pkg) {
if (!pkg) {
if (this.npm.config.get('global')) {
throw this.usageError()
Expand All @@ -122,44 +101,25 @@ class Owner extends BaseCommand {
throw this.usageError()
}

pkg = pkgName
return pkgName
}
log.verbose('owner add', '%s to %s', user, pkg)

const spec = npa(pkg)
return this.putOwners(spec, user, opts,
(newOwner, owners) => this.validateAddOwner(newOwner, owners))
return pkg
}

async rm (user, pkg, opts) {
async changeOwners (user, pkg, addOrRm) {
if (!user) {
throw this.usageError()
}

if (!pkg) {
if (this.npm.config.get('global')) {
throw this.usageError()
}
const pkgName = await readLocalPkgName(this.npm.prefix)
if (!pkgName) {
throw this.usageError()
}

pkg = pkgName
}
log.verbose('owner rm', '%s from %s', user, pkg)
pkg = await this.getPkg(pkg)
log.verbose(`owner ${addOrRm}`, '%s to %s', user, pkg)

const spec = npa(pkg)
return this.putOwners(spec, user, opts,
(rmOwner, owners) => this.validateRmOwner(rmOwner, owners))
}

async putOwners (spec, user, opts, validation) {
const uri = `/-/user/org.couchdb.user:${encodeURIComponent(user)}`
let u = ''
let u

try {
u = await npmFetch.json(uri, opts)
u = await npmFetch.json(uri, this.npm.flatOptions)
} catch (err) {
log.error('owner mutate', `Error getting user data for ${user}`)
throw err
Expand All @@ -177,36 +137,60 @@ class Owner extends BaseCommand {
// normalize user data
u = { name: u.name, email: u.email }

const data = await pacote.packument(spec, { ...opts, fullMetadata: true })
const data = await pacote.packument(spec, { ...this.npm.flatOptions, fullMetadata: true })

// save the number of maintainers before validation for comparison
const before = data.maintainers ? data.maintainers.length : 0
const owners = data.maintainers || []
let maintainers
if (addOrRm === 'add') {
const existing = owners.find(o => o.name === u.name)
if (existing) {
log.info(
'owner add',
`Already a package owner: ${existing.name} <${existing.email}>`
)
return
}
maintainers = [
...owners,
u,
]
} else {
maintainers = owners.filter(o => o.name !== u.name)

const m = validation(u, data.maintainers)
if (!m) {
return
} // invalid owners
if (maintainers.length === owners.length) {
log.info('owner rm', 'Not a package owner: ' + u.name)
return false
}

const body = {
_id: data._id,
_rev: data._rev,
maintainers: m,
if (!maintainers.length) {
throw Object.assign(
new Error(
'Cannot remove all owners of a package. Add someone else first.'
),
{ code: 'EOWNERRM' }
)
}
}

const dataPath = `/${spec.escapedName}/-rev/${encodeURIComponent(data._rev)}`
const res = await otplease(opts, opts => {
const res = await otplease(this.npm.flatOptions, opts => {
return npmFetch.json(dataPath, {
...opts,
method: 'PUT',
body,
body: {
_id: data._id,
_rev: data._rev,
maintainers,
},
spec,
})
})

if (!res.error) {
if (m.length < before) {
this.npm.output(`- ${user} (${spec.name})`)
} else {
if (addOrRm === 'add') {
this.npm.output(`+ ${user} (${spec.name})`)
} else {
this.npm.output(`- ${user} (${spec.name})`)
}
} else {
throw Object.assign(
Expand All @@ -216,47 +200,6 @@ class Owner extends BaseCommand {
}
return res
}

validateAddOwner (newOwner, owners) {
owners = owners || []
for (const o of owners) {
if (o.name === newOwner.name) {
log.info(
'owner add',
'Already a package owner: ' + o.name + ' <' + o.email + '>'
)
return false
}
}
return [
...owners,
newOwner,
]
}

validateRmOwner (rmOwner, owners) {
let found = false
const m = owners.filter(function (o) {
var match = (o.name === rmOwner.name)
found = found || match
return !match
})

if (!found) {
log.info('owner rm', 'Not a package owner: ' + rmOwner.name)
return false
}

if (!m.length) {
throw Object.assign(
new Error(
'Cannot remove all owners of a package. Add someone else first.'
),
{ code: 'EOWNERRM' }
)
}

return m
}
}

module.exports = Owner