Skip to content

Commit

Permalink
feat: refactor terminal display (#7339)
Browse files Browse the repository at this point in the history
This removes `npmlog` and similar dependencies in favor of
`lib/utils/display` doing that part.
  • Loading branch information
lukekarrys committed Apr 12, 2024
1 parent 2a80dab commit 9622597
Show file tree
Hide file tree
Showing 161 changed files with 2,720 additions and 6,590 deletions.
29 changes: 6 additions & 23 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ graph LR;
libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"];
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
libnpmexec-->npmlog;
libnpmexec-->pacote;
libnpmexec-->proc-log;
libnpmexec-->read-package-json-fast;
Expand Down Expand Up @@ -131,10 +130,10 @@ graph LR;
npm-->npmcli-run-script["@npmcli/run-script"];
npm-->npmcli-smoke-tests["@npmcli/smoke-tests"];
npm-->npmcli-template-oss["@npmcli/template-oss"];
npm-->npmlog;
npm-->pacote;
npm-->parse-conflict-json;
npm-->proc-log;
npm-->proggy;
npm-->read;
npm-->semver;
npm-->ssri;
Expand Down Expand Up @@ -180,10 +179,10 @@ graph LR;
npmcli-arborist-->npmcli-redact["@npmcli/redact"];
npmcli-arborist-->npmcli-run-script["@npmcli/run-script"];
npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-arborist-->npmlog;
npmcli-arborist-->pacote;
npmcli-arborist-->parse-conflict-json;
npmcli-arborist-->proc-log;
npmcli-arborist-->proggy;
npmcli-arborist-->read-package-json-fast;
npmcli-arborist-->semver;
npmcli-arborist-->ssri;
Expand Down Expand Up @@ -234,8 +233,6 @@ graph LR;
npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-smoke-tests-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-smoke-tests-->semver;
npmlog-->are-we-there-yet;
npmlog-->gauge;
pacote-->cacache;
pacote-->fs-minipass;
pacote-->npm-package-arg;
Expand Down Expand Up @@ -303,14 +300,6 @@ graph LR;
foreground-child-->cross-spawn;
foreground-child-->signal-exit;
fs-minipass-->minipass;
gauge-->aproba;
gauge-->color-support;
gauge-->console-control-strings;
gauge-->has-unicode;
gauge-->signal-exit;
gauge-->string-width;
gauge-->strip-ansi;
gauge-->wide-align;
glob-->foreground-child;
glob-->jackspeak;
glob-->minimatch;
Expand Down Expand Up @@ -373,7 +362,6 @@ graph LR;
libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"];
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
libnpmexec-->npmlog;
libnpmexec-->pacote;
libnpmexec-->proc-log;
libnpmexec-->read-package-json-fast;
Expand Down Expand Up @@ -548,11 +536,11 @@ graph LR;
npm-->npmcli-run-script["@npmcli/run-script"];
npm-->npmcli-smoke-tests["@npmcli/smoke-tests"];
npm-->npmcli-template-oss["@npmcli/template-oss"];
npm-->npmlog;
npm-->p-map;
npm-->pacote;
npm-->parse-conflict-json;
npm-->proc-log;
npm-->proggy;
npm-->qrcode-terminal;
npm-->read;
npm-->remark-gfm;
Expand Down Expand Up @@ -627,10 +615,10 @@ graph LR;
npmcli-arborist-->npmcli-redact["@npmcli/redact"];
npmcli-arborist-->npmcli-run-script["@npmcli/run-script"];
npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-arborist-->npmlog;
npmcli-arborist-->pacote;
npmcli-arborist-->parse-conflict-json;
npmcli-arborist-->proc-log;
npmcli-arborist-->proggy;
npmcli-arborist-->promise-all-reject-late;
npmcli-arborist-->promise-call-limit;
npmcli-arborist-->read-package-json-fast;
Expand Down Expand Up @@ -721,10 +709,6 @@ graph LR;
npmcli-smoke-tests-->semver;
npmcli-smoke-tests-->tap;
npmcli-smoke-tests-->which;
npmlog-->are-we-there-yet;
npmlog-->console-control-strings;
npmlog-->gauge;
npmlog-->set-blocking;
p-map-->aggregate-error;
pacote-->cacache;
pacote-->fs-minipass;
Expand Down Expand Up @@ -812,7 +796,6 @@ graph LR;
validate-npm-package-name-->builtins;
wcwidth-->defaults;
which-->isexe;
wide-align-->string-width;
wrap-ansi-->ansi-styles;
wrap-ansi-->string-width;
wrap-ansi-->strip-ansi;
Expand All @@ -836,5 +819,5 @@ packages higher up the chain.
- @npmcli/package-json, npm-registry-fetch
- @npmcli/git, make-fetch-happen, @npmcli/config
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, read-package-json, promzard
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, npmlog, parse-conflict-json, @npmcli/mock-globals, read
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, parse-conflict-json, @npmcli/mock-globals, read
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate
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('./utils/log-shim.js')
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
2 changes: 1 addition & 1 deletion 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('./utils/log-shim.js')
const log = require('proc-log')

class BaseCommand {
static workspaces = false
Expand Down
2 changes: 1 addition & 1 deletion 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('./utils/log-shim.js')
const log = 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 Down
3 changes: 1 addition & 2 deletions lib/commands/adduser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const log = require('../utils/log-shim.js')
const log = require('proc-log')
const { redactLog: replaceInfo } = require('@npmcli/redact')
const auth = require('../utils/auth.js')

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

const creds = this.npm.config.getCredentialsByURI(registry)

log.disableProgress()
log.notice('', `Log in on ${replaceInfo(registry)}`)

const { message, newCreds } = await auth.adduser(this.npm, {
Expand Down
10 changes: 3 additions & 7 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('../utils/log-shim.js')
const log = require('proc-log')
const reifyFinish = require('../utils/reify-finish.js')

const sortAlphabetically = (a, b) => localeCompare(a.name, b.name)
Expand Down Expand Up @@ -45,12 +45,8 @@ class VerifySignatures {
})
await Promise.all([...registries].map(registry => this.setKeys({ registry, tuf })))

const progress = log.newItem('verifying registry signatures', edges.size)
const mapper = async (edge) => {
progress.completeWork(1)
await this.getVerifiedInfo(edge)
}
await pMap(edges, mapper, { concurrency: 20, stopOnError: true })
log.verbose('verifying registry signatures')
await pMap(edges, (e) => this.getVerifiedInfo(e), { concurrency: 20, stopOnError: true })

// Didn't find any dependencies that could be verified, e.g. only local
// deps, missing version, not on a registry etc.
Expand Down
2 changes: 1 addition & 1 deletion 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('../utils/log-shim')
const log = require('proc-log')

const searchCachePackage = async (path, parsed, cacheKeys) => {
/* eslint-disable-next-line max-len */
Expand Down
2 changes: 1 addition & 1 deletion 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('../utils/log-shim.js')
const log = require('proc-log')
const validateLockfile = require('../utils/validate-lockfile.js')

const ArboristWorkspaceCmd = require('../arborist-cmd.js')
Expand Down
55 changes: 25 additions & 30 deletions lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ini = require('ini')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const pkgJson = require('@npmcli/package-json')
const { defaults, definitions } = require('@npmcli/config/lib/definitions')
const log = require('../utils/log-shim.js')
const log = require('proc-log')

// These are the configs that we can nerf-dart. Not all of them currently even
// *have* config definitions so we have to explicitly validate them here
Expand Down Expand Up @@ -111,35 +111,30 @@ class Config extends BaseCommand {
}

async exec ([action, ...args]) {
log.disableProgress()
try {
switch (action) {
case 'set':
await this.set(args)
break
case 'get':
await this.get(args)
break
case 'delete':
case 'rm':
case 'del':
await this.del(args)
break
case 'list':
case 'ls':
await (this.npm.flatOptions.json ? this.listJson() : this.list())
break
case 'edit':
await this.edit()
break
case 'fix':
await this.fix()
break
default:
throw this.usageError()
}
} finally {
log.enableProgress()
switch (action) {
case 'set':
await this.set(args)
break
case 'get':
await this.get(args)
break
case 'delete':
case 'rm':
case 'del':
await this.del(args)
break
case 'list':
case 'ls':
await (this.npm.flatOptions.json ? this.listJson() : this.list())
break
case 'edit':
await this.edit()
break
case 'fix':
await this.fix()
break
default:
throw this.usageError()
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const libnpmdiff = require('libnpmdiff')
const npa = require('npm-package-arg')
const pacote = require('pacote')
const pickManifest = require('npm-pick-manifest')
const log = require('../utils/log-shim')
const log = require('proc-log')
const pkgJson = require('@npmcli/package-json')
const BaseCommand = require('../base-command.js')

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const npa = require('npm-package-arg')
const regFetch = require('npm-registry-fetch')
const semver = require('semver')
const log = require('../utils/log-shim')
const log = require('proc-log')
const otplease = require('../utils/otplease.js')
const pkgJson = require('@npmcli/package-json')
const BaseCommand = require('../base-command.js')
Expand Down

0 comments on commit 9622597

Please sign in to comment.