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

Linting for #5225 #5323

Merged
merged 9 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ graph LR;
normalize-package-data-->semver;
npm-->abbrev;
npm-->cacache;
npm-->fs-minipass;
npm-->hosted-git-info;
npm-->ini;
npm-->init-package-json;
Expand Down Expand Up @@ -115,6 +116,7 @@ graph LR;
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-package-json["@npmcli/package-json"];
npm-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npm-->npmcli-run-script["@npmcli/run-script"];
npm-->npmcli-template-oss["@npmcli/template-oss"];
npm-->npmlog;
Expand Down Expand Up @@ -342,7 +344,9 @@ graph LR;
libnpmdiff-->tar;
libnpmexec-->bin-links;
libnpmexec-->chalk;
libnpmexec-->minify-registry-metadata;
libnpmexec-->mkdirp-infer-owner;
libnpmexec-->mkdirp;
libnpmexec-->npm-package-arg;
libnpmexec-->npmcli-arborist["@npmcli/arborist"];
libnpmexec-->npmcli-ci-detect["@npmcli/ci-detect"];
Expand Down Expand Up @@ -472,6 +476,7 @@ graph LR;
npm-->columnify;
npm-->docs;
npm-->fastest-levenshtein;
npm-->fs-minipass;
npm-->glob;
npm-->graceful-fs;
npm-->hosted-git-info;
Expand All @@ -493,6 +498,7 @@ graph LR;
npm-->libnpmversion;
npm-->licensee;
npm-->make-fetch-happen;
npm-->minimatch;
npm-->minipass-pipeline;
npm-->minipass;
npm-->mkdirp-infer-owner;
Expand All @@ -515,6 +521,7 @@ graph LR;
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-package-json["@npmcli/package-json"];
npm-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npm-->npmcli-run-script["@npmcli/run-script"];
npm-->npmcli-template-oss["@npmcli/template-oss"];
npm-->npmlog;
Expand Down
1 change: 1 addition & 0 deletions docs/.eslintrc.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "rules": { "import/no-extraneous-dependencies": "off" } }
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@mdx-js/mdx": "^1.6.22",
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/eslint-config": "^3.1.0",
"@npmcli/fs": "^2.1.0",
"@npmcli/promise-spawn": "^3.0.0",
"@npmcli/template-oss": "3.5.0",
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ class VerifySignatures {
let name = edge.name
try {
name = npa(edge.spec).subSpec.name
} catch (_) {
} catch {
// leave it as edge.name
}
try {
return npa(`${name}@${edge.spec}`)
} catch (_) {
} catch {
// Skip packages with invalid spec
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ class Edit extends BaseCommand {
}
const [bin, ...args] = this.npm.config.get('editor').split(/\s+/)
const editor = cp.spawn(bin, [...args, dir], { stdio: 'inherit' })
editor.on('exit', (code) => {
editor.on('exit', async (code) => {
if (code) {
return reject(new Error(`editor process exited with code: ${code}`))
}
this.npm.exec('rebuild', [dir]).catch(reject).then(resolve)
try {
await this.npm.exec('rebuild', [dir])
} catch (err) {
reject(err)
}
resolve()
})
})
})
Expand Down
135 changes: 64 additions & 71 deletions lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Org extends BaseCommand {
})
}

set (org, user, role, opts) {
async set (org, user, role, opts) {
role = role || 'developer'
if (!org) {
throw new Error('First argument `orgname` is required.')
Expand All @@ -67,27 +67,26 @@ class Org extends BaseCommand {
)
}

return liborg.set(org, user, role, opts).then(memDeets => {
if (opts.json) {
this.npm.output(JSON.stringify(memDeets, null, 2))
} else if (opts.parseable) {
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
this.npm.output(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!this.npm.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
const memDeets = await liborg.set(org, user, role, opts)
if (opts.json) {
this.npm.output(JSON.stringify(memDeets, null, 2))
} else if (opts.parseable) {
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
this.npm.output(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!this.npm.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
memDeets.org.size
} member${memDeets.org.size === 1 ? '' : 's'} in this org.`
)
}
)
}

return memDeets
})
return memDeets
}

rm (org, user, opts) {
async rm (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}
Expand All @@ -96,68 +95,62 @@ class Org extends BaseCommand {
throw new Error('Second argument `username` is required.')
}

return liborg
.rm(org, user, opts)
.then(() => {
return liborg.ls(org, opts)
})
.then(roster => {
user = user.replace(/^[~@]?/, '')
org = org.replace(/^[~@]?/, '')
const userCount = Object.keys(roster).length
if (opts.json) {
this.npm.output(
JSON.stringify({
user,
org,
userCount,
deleted: true,
})
)
} else if (opts.parseable) {
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
this.npm.output([user, org, userCount, true].join('\t'))
} else if (!this.npm.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
} in this org.`
)
}
})
await liborg.rm(org, user, opts)
const roster = await liborg.ls(org, opts)
user = user.replace(/^[~@]?/, '')
org = org.replace(/^[~@]?/, '')
const userCount = Object.keys(roster).length
if (opts.json) {
this.npm.output(
JSON.stringify({
user,
org,
userCount,
deleted: true,
})
)
} else if (opts.parseable) {
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
this.npm.output([user, org, userCount, true].join('\t'))
} else if (!this.npm.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
} in this org.`
)
}
}

ls (org, user, opts) {
async ls (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}

return liborg.ls(org, opts).then(roster => {
if (user) {
const newRoster = {}
if (roster[user]) {
newRoster[user] = roster[user]
}

roster = newRoster
let roster = await liborg.ls(org, opts)
if (user) {
const newRoster = {}
if (roster[user]) {
newRoster[user] = roster[user]
}
if (opts.json) {
this.npm.output(JSON.stringify(roster, null, 2))
} else if (opts.parseable) {
this.npm.output(['user', 'role'].join('\t'))
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))

roster = newRoster
}
if (opts.json) {
this.npm.output(JSON.stringify(roster, null, 2))
} else if (opts.parseable) {
this.npm.output(['user', 'role'].join('\t'))
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))
})
} else if (!this.npm.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
.forEach(user => {
table.push([user, roster[user]])
})
} else if (!this.npm.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
.forEach(user => {
table.push([user, roster[user]])
})
this.npm.output(table.toString())
}
})
this.npm.output(table.toString())
}
}
}
module.exports = Org
1 change: 1 addition & 0 deletions lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Outdated extends ArboristWorkspaceCmd {
try {
alias = npa(edge.spec).subSpec
} catch (err) {
// ignore errors, no alias
}
const spec = npa(alias ? alias.name : edge.name)
const node = edge.to || edge
Expand Down
45 changes: 20 additions & 25 deletions lib/commands/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,27 @@ class Token extends BaseCommand {
const cidr = conf.cidr
const readonly = conf.readOnly

return readUserInfo
.password()
.then(password => {
const validCIDR = this.validateCIDRList(cidr)
log.info('token', 'creating')
return pulseTillDone.withPromise(
otplease(this.npm, conf, conf => {
return profile.createToken(password, readonly, validCIDR, conf)
})
)
})
.then(result => {
delete result.key
delete result.updated
if (conf.json) {
this.npm.output(JSON.stringify(result))
} else if (conf.parseable) {
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
} else {
const table = new Table()
for (const k of Object.keys(result)) {
table.push({ [chalk.bold(k)]: String(result[k]) })
}
this.npm.output(table.toString())
}
const password = await readUserInfo.password()
const validCIDR = this.validateCIDRList(cidr)
log.info('token', 'creating')
const result = await pulseTillDone.withPromise(
otplease(this.npm, conf, conf => {
return profile.createToken(password, readonly, validCIDR, conf)
})
)
delete result.key
delete result.updated
if (conf.json) {
this.npm.output(JSON.stringify(result))
} else if (conf.parseable) {
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
} else {
const table = new Table()
for (const k of Object.keys(result)) {
table.push({ [chalk.bold(k)]: String(result[k]) })
}
this.npm.output(table.toString())
}
}

config () {
Expand Down
20 changes: 11 additions & 9 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Npm extends EventEmitter {
// this is async but we dont await it, since its ok if it doesnt
// finish before the command finishes running. it uses command and argv
// so it must be initiated here, after the command name is set
// eslint-disable-next-line promise/catch-or-return
updateNotifier(this).then((msg) => (this.updateNotification = msg))

// Options are prefixed by a hyphen-minus (-, \u2d).
Expand Down Expand Up @@ -173,16 +174,15 @@ class Npm extends EventEmitter {

async load () {
if (!this.#loadPromise) {
this.#loadPromise = this.time('npm:load', () => this[_load]().catch(er => er).then((er) => {
this.loadErr = er
if (!er) {
if (this.config.get('force')) {
log.warn('using --force', 'Recommended protections disabled.')
}
} else {
this.#loadPromise = this.time('npm:load', async () => {
await this[_load]().catch((er) => {
this.loadErr = er
throw er
})
if (this.config.get('force')) {
log.warn('using --force', 'Recommended protections disabled.')
}
}))
})
}
return this.#loadPromise
}
Expand Down Expand Up @@ -229,7 +229,9 @@ class Npm extends EventEmitter {
const node = this.time('npm:load:whichnode', () => {
try {
return which.sync(process.argv[0])
} catch {} // TODO should we throw here?
} catch {
// TODO should we throw here?
}
})

if (node && node.toUpperCase() !== process.execPath.toUpperCase()) {
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/queryable.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ const setter = ({ data, key, value, force }) => {
let maybeIndex = Number.NaN
try {
maybeIndex = Number(_key)
} catch (err) {}
} catch {
// leave it NaN
}
if (!Number.isNaN(maybeIndex)) {
_key = maybeIndex
}
Expand Down
Loading