Skip to content

Commit

Permalink
feat: add spinner (#7432)
Browse files Browse the repository at this point in the history
Closes #7425

This is a little hard to test because everything should continue to work
without progress, as evidenced by the lack of churn in the tests and
snapshots here. The only existing tests that changed are the addition of
newlines after prompts which is new behavior as part of this PR.

I resorted to manually running some commands to get an idea of how the
various states worked together:

**`node . exec -- npm@4`**
This should show progress at the start and then hide it as it prompts
the user to install `npm@4`. `Ctrl+C` should exit from the prompt and
the error should display on the next line (this is a current bug).

**`node . audit signatures --loglevel=http`**
This should show a lot of http log messages while always keeping the
spinner on the last line of output. The spinner also should not jump
between frames regardless of how quickly the log messages show up.

**`node . pack`**
This should immediately show the banners and output from `prepack` and
not show the spinner until the actual packing is happening.

**`node . login`**
The spinner should never while the prompt is being displayed.

**`node . view npm`**
The spinner should appear while data is being fetched and then disappear
for the rest of the command as output is being displayed. The end output
on completion should not have any spinner frames rendered on new lines
in the output. The old progress bar achieved this by calling
`npmlog.disableProgress()` but now it is able to hide the spinner
appropriately even while outputting individual lines to stdout.
  • Loading branch information
lukekarrys authored Apr 29, 2024
1 parent 104fcb5 commit 7e349f4
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 167 deletions.
2 changes: 0 additions & 2 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ graph LR;
npm-->pacote;
npm-->parse-conflict-json;
npm-->proc-log;
npm-->proggy;
npm-->read;
npm-->semver;
npm-->ssri;
Expand Down Expand Up @@ -527,7 +526,6 @@ graph LR;
npm-->pacote;
npm-->parse-conflict-json;
npm-->proc-log;
npm-->proggy;
npm-->qrcode-terminal;
npm-->read;
npm-->remark-gfm;
Expand Down
8 changes: 2 additions & 6 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const npa = require('npm-package-arg')
const libexec = require('libnpmexec')
const mapWorkspaces = require('@npmcli/map-workspaces')
const PackageJson = require('@npmcli/package-json')
const { log, output } = require('proc-log')
const { log, output, input } = require('proc-log')
const updateWorkspaces = require('../utils/update-workspaces.js')
const BaseCommand = require('../base-cmd.js')

Expand Down Expand Up @@ -148,8 +148,6 @@ class Init extends BaseCommand {
}

async template (path = process.cwd()) {
log.pause()

const initFile = this.npm.config.get('init-module')
if (!this.npm.config.get('yes') && !this.npm.config.get('force')) {
output.standard([
Expand All @@ -167,7 +165,7 @@ class Init extends BaseCommand {
}

try {
const data = await initJson(path, initFile, this.npm.config)
const data = await input.read(() => initJson(path, initFile, this.npm.config))
log.silly('package data', data)
return data
} catch (er) {
Expand All @@ -176,8 +174,6 @@ class Init extends BaseCommand {
} else {
throw er
}
} finally {
log.resume()
}
}

Expand Down
Loading

0 comments on commit 7e349f4

Please sign in to comment.