Skip to content
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
2 changes: 2 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ graph LR;
npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"];
npmcli-run-script-->npmcli-package-json["@npmcli/package-json"];
npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-run-script-->proc-log;
npmcli-smoke-tests-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-smoke-tests-->npmcli-mock-registry["@npmcli/mock-registry"];
npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"];
Expand Down Expand Up @@ -700,6 +701,7 @@ graph LR;
npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"];
npmcli-run-script-->npmcli-package-json["@npmcli/package-json"];
npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-run-script-->proc-log;
npmcli-run-script-->which;
npmcli-smoke-tests-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-smoke-tests-->npmcli-mock-registry["@npmcli/mock-registry"];
Expand Down
2 changes: 1 addition & 1 deletion lib/arborist-cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const log = require('proc-log')
const { log } = require('proc-log')

// This is the base for all commands whose execWorkspaces just gets
// a list of workspace names and passes it on to new Arborist() to
Expand Down
4 changes: 2 additions & 2 deletions lib/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { relative } = require('path')

const { definitions } = require('@npmcli/config/lib/definitions')
const { aliases: cmdAliases } = require('./utils/cmd-list')
const log = require('proc-log')
const { log, output } = require('proc-log')

class BaseCommand {
static workspaces = false
Expand Down Expand Up @@ -119,7 +119,7 @@ class BaseCommand {
const { config } = this.npm

if (config.get('usage')) {
return this.npm.output(this.usage)
return output.standard(this.usage)
}

const hasWsConfig = config.get('workspaces') || config.get('workspace').length
Expand Down
10 changes: 5 additions & 5 deletions lib/cli-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = async (process, validateEngines) => {
exitHandler.setNpm(npm)

// only log node and npm paths in argv initially since argv can contain sensitive info. a cleaned version will be logged later
const log = require('proc-log')
const { log, output } = require('proc-log')
log.verbose('cli', process.argv.slice(0, 2).join(' '))
log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)
Expand All @@ -41,7 +41,7 @@ module.exports = async (process, validateEngines) => {

// npm -v
if (npm.config.get('version', 'cli')) {
npm.output(npm.version)
output.standard(npm.version)
return exitHandler()
}

Expand All @@ -53,7 +53,7 @@ module.exports = async (process, validateEngines) => {

cmd = npm.argv.shift()
if (!cmd) {
npm.output(npm.usage)
output.standard(npm.usage)
process.exitCode = 1
return exitHandler()
}
Expand All @@ -64,8 +64,8 @@ module.exports = async (process, validateEngines) => {
if (err.code === 'EUNKNOWNCOMMAND') {
const didYouMean = require('./utils/did-you-mean.js')
const suggestions = await didYouMean(npm.localPrefix, cmd)
npm.output(`Unknown command: "${cmd}"${suggestions}\n`)
npm.output('To see a list of supported npm commands, run:\n npm help')
output.standard(`Unknown command: "${cmd}"${suggestions}\n`)
output.standard('To see a list of supported npm commands, run:\n npm help')
process.exitCode = 1
return exitHandler()
}
Expand Down
11 changes: 6 additions & 5 deletions lib/commands/access.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const libnpmaccess = require('libnpmaccess')
const npa = require('npm-package-arg')
const { output } = require('proc-log')
const pkgJson = require('@npmcli/package-json')
const localeCompare = require('@isaacs/string-locale-compare')('en')

Expand Down Expand Up @@ -197,22 +198,22 @@ class Access extends BaseCommand {
}

#output (items, limiter) {
const output = {}
const outputs = {}
const lookup = {
__proto__: null,
read: 'read-only',
write: 'read-write',
}
for (const item in items) {
const val = items[item]
output[item] = lookup[val] || val
outputs[item] = lookup[val] || val
}
if (this.npm.config.get('json')) {
this.npm.output(JSON.stringify(output, null, 2))
output.standard(JSON.stringify(outputs, null, 2))
} else {
for (const item of Object.keys(output).sort(localeCompare)) {
for (const item of Object.keys(outputs).sort(localeCompare)) {
if (!limiter || limiter === item) {
this.npm.output(`${item}: ${output[item]}`)
output.standard(`${item}: ${outputs[item]}`)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/adduser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const log = require('proc-log')
const { log, output } = require('proc-log')
const { redactLog: replaceInfo } = require('@npmcli/redact')
const auth = require('../utils/auth.js')

Expand Down Expand Up @@ -44,7 +44,7 @@ class AddUser extends BaseCommand {

await this.npm.config.save('user')

this.npm.output(message)
output.standard(message)
}
}
module.exports = AddUser
58 changes: 29 additions & 29 deletions lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const tufClient = require('@sigstore/tuf')

const ArboristWorkspaceCmd = require('../arborist-cmd.js')
const auditError = require('../utils/audit-error.js')
const log = require('proc-log')
const { log, output } = require('proc-log')
const reifyFinish = require('../utils/reify-finish.js')

const sortAlphabetically = (a, b) => localeCompare(a.name, b.name)
Expand Down Expand Up @@ -65,7 +65,7 @@ class VerifySignatures {
}

if (this.npm.config.get('json')) {
this.npm.output(JSON.stringify({
output.standard(JSON.stringify({
invalid,
missing,
}, null, 2))
Expand All @@ -77,91 +77,91 @@ class VerifySignatures {
const auditedPlural = this.auditedWithKeysCount > 1 ? 's' : ''
const timing = `audited ${this.auditedWithKeysCount} package${auditedPlural} in ` +
`${Math.floor(Number(elapsed) / 1e9)}s`
this.npm.output(timing)
this.npm.output('')
output.standard(timing)
output.standard('')

const verifiedBold = this.npm.chalk.bold('verified')
if (this.verifiedSignatureCount) {
if (this.verifiedSignatureCount === 1) {
/* eslint-disable-next-line max-len */
this.npm.output(`${this.verifiedSignatureCount} package has a ${verifiedBold} registry signature`)
output.standard(`${this.verifiedSignatureCount} package has a ${verifiedBold} registry signature`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`${this.verifiedSignatureCount} packages have ${verifiedBold} registry signatures`)
output.standard(`${this.verifiedSignatureCount} packages have ${verifiedBold} registry signatures`)
}
this.npm.output('')
output.standard('')
}

if (this.verifiedAttestationCount) {
if (this.verifiedAttestationCount === 1) {
/* eslint-disable-next-line max-len */
this.npm.output(`${this.verifiedAttestationCount} package has a ${verifiedBold} attestation`)
output.standard(`${this.verifiedAttestationCount} package has a ${verifiedBold} attestation`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`${this.verifiedAttestationCount} packages have ${verifiedBold} attestations`)
output.standard(`${this.verifiedAttestationCount} packages have ${verifiedBold} attestations`)
}
this.npm.output('')
output.standard('')
}

if (missing.length) {
const missingClr = this.npm.chalk.bold(this.npm.chalk.red('missing'))
if (missing.length === 1) {
/* eslint-disable-next-line max-len */
this.npm.output(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
output.standard(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`${missing.length} packages have ${missingClr} registry signatures but the registry is providing signing keys:`)
output.standard(`${missing.length} packages have ${missingClr} registry signatures but the registry is providing signing keys:`)
}
this.npm.output('')
output.standard('')
missing.map(m =>
this.npm.output(`${this.npm.chalk.red(`${m.name}@${m.version}`)} (${m.registry})`)
output.standard(`${this.npm.chalk.red(`${m.name}@${m.version}`)} (${m.registry})`)
)
}

if (invalid.length) {
if (missing.length) {
this.npm.output('')
output.standard('')
}
const invalidClr = this.npm.chalk.bold(this.npm.chalk.red('invalid'))
// We can have either invalid signatures or invalid provenance
const invalidSignatures = this.invalid.filter(i => i.code === 'EINTEGRITYSIGNATURE')
if (invalidSignatures.length) {
if (invalidSignatures.length === 1) {
this.npm.output(`1 package has an ${invalidClr} registry signature:`)
output.standard(`1 package has an ${invalidClr} registry signature:`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`${invalidSignatures.length} packages have ${invalidClr} registry signatures:`)
output.standard(`${invalidSignatures.length} packages have ${invalidClr} registry signatures:`)
}
this.npm.output('')
output.standard('')
invalidSignatures.map(i =>
this.npm.output(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
output.standard(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
)
this.npm.output('')
output.standard('')
}

const invalidAttestations = this.invalid.filter(i => i.code === 'EATTESTATIONVERIFY')
if (invalidAttestations.length) {
if (invalidAttestations.length === 1) {
this.npm.output(`1 package has an ${invalidClr} attestation:`)
output.standard(`1 package has an ${invalidClr} attestation:`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`${invalidAttestations.length} packages have ${invalidClr} attestations:`)
output.standard(`${invalidAttestations.length} packages have ${invalidClr} attestations:`)
}
this.npm.output('')
output.standard('')
invalidAttestations.map(i =>
this.npm.output(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
output.standard(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
)
this.npm.output('')
output.standard('')
}

if (invalid.length === 1) {
/* eslint-disable-next-line max-len */
this.npm.output(`Someone might have tampered with this package since it was published on the registry!`)
output.standard(`Someone might have tampered with this package since it was published on the registry!`)
} else {
/* eslint-disable-next-line max-len */
this.npm.output(`Someone might have tampered with these packages since they were published on the registry!`)
output.standard(`Someone might have tampered with these packages since they were published on the registry!`)
}
this.npm.output('')
output.standard('')
}
}

Expand Down Expand Up @@ -463,7 +463,7 @@ class Audit extends ArboristWorkspaceCmd {
chalk: this.npm.chalk,
})
process.exitCode = process.exitCode || result.exitCode
this.npm.output(result.report)
output.standard(result.report)
}
}

Expand Down
22 changes: 11 additions & 11 deletions lib/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const BaseCommand = require('../base-command.js')
const npa = require('npm-package-arg')
const jsonParse = require('json-parse-even-better-errors')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const log = require('proc-log')
const { log, output } = require('proc-log')

const searchCachePackage = async (path, parsed, cacheKeys) => {
/* eslint-disable-next-line max-len */
Expand Down Expand Up @@ -135,7 +135,7 @@ class Cache extends BaseCommand {
log.warn(`Not Found: ${key}`)
break
}
this.npm.output(`Deleted: ${key}`)
output.standard(`Deleted: ${key}`)
await cacache.rm.entry(cachePath, key)
// XXX this could leave other entries without content!
await cacache.rm.content(cachePath, entry.integrity)
Expand Down Expand Up @@ -170,20 +170,20 @@ class Cache extends BaseCommand {
? `~${cache.slice(process.env.HOME.length)}`
: cache
const stats = await cacache.verify(cache)
this.npm.output(`Cache verified and compressed (${prefix})`)
this.npm.output(`Content verified: ${stats.verifiedContent} (${stats.keptSize} bytes)`)
output.standard(`Cache verified and compressed (${prefix})`)
output.standard(`Content verified: ${stats.verifiedContent} (${stats.keptSize} bytes)`)
if (stats.badContentCount) {
this.npm.output(`Corrupted content removed: ${stats.badContentCount}`)
output.standard(`Corrupted content removed: ${stats.badContentCount}`)
}
if (stats.reclaimedCount) {
/* eslint-disable-next-line max-len */
this.npm.output(`Content garbage-collected: ${stats.reclaimedCount} (${stats.reclaimedSize} bytes)`)
output.standard(`Content garbage-collected: ${stats.reclaimedCount} (${stats.reclaimedSize} bytes)`)
}
if (stats.missingContent) {
this.npm.output(`Missing content: ${stats.missingContent}`)
output.standard(`Missing content: ${stats.missingContent}`)
}
this.npm.output(`Index entries: ${stats.totalEntries}`)
this.npm.output(`Finished in ${stats.runTime.total / 1000}s`)
output.standard(`Index entries: ${stats.totalEntries}`)
output.standard(`Finished in ${stats.runTime.total / 1000}s`)
}

// npm cache ls [--package <spec> ...]
Expand All @@ -203,10 +203,10 @@ class Cache extends BaseCommand {
results.add(key)
}
}
[...results].sort(localeCompare).forEach(key => this.npm.output(key))
[...results].sort(localeCompare).forEach(key => output.standard(key))
return
}
cacheKeys.sort(localeCompare).forEach(key => this.npm.output(key))
cacheKeys.sort(localeCompare).forEach(key => output.standard(key))
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const reifyFinish = require('../utils/reify-finish.js')
const runScript = require('@npmcli/run-script')
const fs = require('fs/promises')
const log = require('proc-log')
const { log } = require('proc-log')
const validateLockfile = require('../utils/validate-lockfile.js')

const ArboristWorkspaceCmd = require('../arborist-cmd.js')
Expand Down Expand Up @@ -109,7 +109,6 @@ class CI extends ArboristWorkspaceCmd {
args: [],
scriptShell,
stdio: 'inherit',
banner: !this.npm.silent,
event,
})
}
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
const fs = require('fs/promises')
const nopt = require('nopt')
const { resolve } = require('path')
const { output } = require('proc-log')

const Npm = require('../npm.js')
const { definitions, shorthands } = require('@npmcli/config/lib/definitions')
Expand Down Expand Up @@ -185,7 +186,7 @@ class Completion extends BaseCommand {
}

if (compls.length > 0) {
this.npm.output(compls.join('\n'))
output.standard(compls.join('\n'))
}
}
}
Expand Down
Loading