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

feat: refactor terminal display #7339

Merged
merged 48 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
45fc1de
wip: remove npmlog
lukekarrys Apr 4, 2024
9f5e7f2
wip: remove calls to npmlog progress methods
lukekarrys Apr 7, 2024
4886bfd
wip: use display class to actually display logs
lukekarrys Apr 7, 2024
234f94f
wip: move control char cleaning to new format file
lukekarrys Apr 7, 2024
043491c
wip: make colors settable based on options
lukekarrys Apr 7, 2024
fa3c6b8
wip: refactor and some todos
lukekarrys Apr 7, 2024
c3d4ebf
wip: add forceLog method
lukekarrys Apr 7, 2024
c491b9a
wip: a few more todos
lukekarrys Apr 7, 2024
d245917
wip: fix arborist create trackers to not error
lukekarrys Apr 7, 2024
57b7ea8
wip: start some run-script changes
lukekarrys Apr 7, 2024
a231383
wip: get new way to mock logs working in tests
lukekarrys Apr 7, 2024
429766f
Revert cli entry changes
lukekarrys Apr 10, 2024
49cd457
Delete unused sandbox fixture
lukekarrys Apr 11, 2024
bcc2071
Remove superflous if statement
lukekarrys Apr 11, 2024
5703dec
Do not remove titles or significant whitespace from logs in tests
lukekarrys Apr 11, 2024
89c574d
Remove ping debugging code
lukekarrys Apr 11, 2024
cb3935c
Add init prefix to logs in init command
lukekarrys Apr 11, 2024
ad73f08
Remove default values from private display properties
lukekarrys Apr 11, 2024
940f47e
Fix snapshots that relied on colorized logs
lukekarrys Apr 11, 2024
f165ba4
wip shrinkwrap
lukekarrys Apr 11, 2024
0aec6b0
Properly test shrinkwrap warnings
lukekarrys Apr 11, 2024
41ab3f0
Revert unnecessary token test changes
lukekarrys Apr 11, 2024
133d2b6
Revert unnecessary token test changes
lukekarrys Apr 11, 2024
cf02e32
Opt in to timing logs on specific tests
lukekarrys Apr 11, 2024
6f06833
Fix config snapshots
lukekarrys Apr 11, 2024
3e475a8
Fix config snapshots more
lukekarrys Apr 11, 2024
8548f1d
Fix cross platform config snapshots
lukekarrys Apr 11, 2024
7a33264
Add comment about forceLog behavior
lukekarrys Apr 11, 2024
27f160b
Test display and formatting
lukekarrys Apr 11, 2024
3d51c5e
Use config instead of global process.argv for npm.js tests
lukekarrys Apr 11, 2024
12cc702
Add test for timing message when loglevel hides it
lukekarrys Apr 11, 2024
52b7208
Dont force logs when silent and add coverage
lukekarrys Apr 12, 2024
78cf951
Better replacements for config snapshots
lukekarrys Apr 12, 2024
ff8a663
Even better replacements for config snapshots
lukekarrys Apr 12, 2024
475e626
Actually update snapshot files
lukekarrys Apr 12, 2024
def5e77
Make symlink log match a string for windows
lukekarrys Apr 12, 2024
87fd3df
Fix cache dir in config snapshots
lukekarrys Apr 12, 2024
743b0d0
Change how execPath is cleaned in snapshots
lukekarrys Apr 12, 2024
fb9d47a
Update smoke test snapshots for whitespace
lukekarrys Apr 12, 2024
983f8a5
Refactor config snapshot cleaning for ini comments
lukekarrys Apr 12, 2024
896c12e
Revert arborist shrinkwrap changes but add a comment warning to not d…
lukekarrys Apr 12, 2024
c645c1f
Revert leftover console.log
lukekarrys Apr 12, 2024
de7b362
Remove npmlog from arborist and libnpmexec
lukekarrys Apr 12, 2024
64164f5
Run dependencies script
lukekarrys Apr 12, 2024
1b5e75b
use inline setBlocking function for display
lukekarrys Apr 12, 2024
93a68a6
Update config snapshots again
lukekarrys Apr 12, 2024
3a0de03
Revert changed check in arborist tracker condition
lukekarrys Apr 12, 2024
1e46f0c
Only output and log unix newlines
lukekarrys Apr 12, 2024
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
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
Loading
Loading