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: add spinner #7432

Merged
merged 1 commit into from Apr 29, 2024
Merged

feat: add spinner #7432

merged 1 commit into from Apr 29, 2024

Conversation

lukekarrys
Copy link
Member

@lukekarrys lukekarrys commented Apr 27, 2024

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.

@lukekarrys lukekarrys force-pushed the lk/spinner branch 18 times, most recently from a38b050 to ccd4fd0 Compare April 29, 2024 03:32
@lukekarrys lukekarrys marked this pull request as ready for review April 29, 2024 03:32
@lukekarrys lukekarrys requested a review from a team as a code owner April 29, 2024 03:32
@lukekarrys lukekarrys force-pushed the lk/spinner branch 6 times, most recently from 550db9b to 7747e03 Compare April 29, 2024 17:32
@@ -527,7 +526,6 @@ graph LR;
npm-->pacote;
npm-->parse-conflict-json;
npm-->proc-log;
npm-->proggy;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proggy was previously required in display.js as a placeholder for how progress messages could be rendered, but not actually used. I opted to remove it as we now are showing a spinner without any specific messages. A future iteration that should useful progress messages would bring this dependency back.


// clear the prompt line
output.standard('')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed because we clear the prompt line in display.js. This is good because currently we wouldn't clear the input in cases besides the emitter's abort event.

this.#enabled = enabled
this.#spinner = unicode ? Progress.dots : Progress.lines
// Dont render the spinner for short durations
this.#render(200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the performance cost here? Is 500 still readable but measurably faster? Ultimately if performance is that important folks should turn this off but ... a sensible default should be something that comes from a place of some testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should affect performance. This delay is more for UI. A command that only takes 100ms shouldn't attempt to render the spinner since it won't appear as more than a flash of a spinner. I landed on 200ms as the "if nothing has been output yet, let the user know that things are happening". But this number should be very open to changing in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the next comment, I see what you're talking about with the interval frame rate. That number is located in the Progress.dots.duration and Progress.lines.duration and we should also feel free to experiment with those as well.

Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally. One question about what the default interval should be.

Since pulse-till-done was at 150ms I think this is ok to land as-is but we should definitely be asking ourselves what the "best" interval is.

@lukekarrys lukekarrys merged commit 7e349f4 into latest Apr 29, 2024
37 checks passed
@lukekarrys lukekarrys deleted the lk/spinner branch April 29, 2024 23:34
@github-actions github-actions bot mentioned this pull request Apr 29, 2024
@lorand-horvath
Copy link

@lukekarrys @wraithgar Thanks for taking the time to add the spinner! However, this could be improved upon, compared to how it was before in 10.5.2. My concerns are the following:

  1. The spinner is there as expected, but there's a constant blinking cursor overlapping with it and it looks a bit unfinished or buggy.
  2. The installation process seems slower. I could revert to 10.5.2 and time the installations to see what the difference is.
  3. The spinner is not enough as default information. In previous versions I really liked the way it informed the user about what was currently doing, for example during npm install, so I would very much like to see something of the sort:
\ install react@18.3.1
| install react-dom@18.3.1
/ install styled-components@6.1.9
- update vite@5.2.10
\ update vite-plugin-eslint@1.8.1
| reify etc...

Wouldn't that be nicer?

@HanabishiRecca
Copy link

The installation process seems slower.

Measured time with --offline - no difference.

The spinner is not enough as default information.

This. We need more verbosity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] npm 10.6.0 doesn't log anything while npm install
4 participants