npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.09k stars 2.92k forks source link

fix(refactor): use output buffer and error for more commands #7513

Closed lukekarrys closed 2 weeks ago

lukekarrys commented 2 weeks ago

This changes a bunch of commands to use the new output.buffer capabilities from proc-log as well as the outputError helper from utils/output-error.js.

This also adds a few comments about future display related breaking changes that npm should make.

There is some new behavior around run-script and how it outputs errors. It now displays the error for each workspace similar to how that error would get displayed when the process exits.

Here are some screenshots of the new run-script output to show with coloring. These are all represented in snapshots as well both those can be hard to decipher with ansi codes. The screenshots are run via set -x; npm $@; npmlocal $@ so the output preceded with + npm is just to show the command being run.

Running a non-existent command from multiple workspaces

Screenshot 2024-05-14 at 9 50 06 AM

Running a script that errors from multiple workspaces

Screenshot 2024-05-14 at 9 57 24 AM

Listing scripts

The only change here is I removed the newline between lifecycle scripts and run scripts. I find the indent shows the hierarchy of information and the extra newline made it difficult to quickly scan multiple workspaces which are also separated by newlines.

Screenshot 2024-05-14 at 10 14 13 AM
npm-cli-bot commented 2 weeks ago

no statistically significant performance changes detected

timing results |**app-large**|clean|lock-only|cache-only|modules-only|no-lock|no-cache|no-modules|no-clean|show-version|run-script|cache-only
peer-deps|no-clean
audit| |---|---|---|---|---|---|---|---|---|---|---|---|---| |npm@latest|37.754 ±0.71|10.985 ±0.00|12.062 ±0.05|1.588 ±0.00|1.587 ±0.01|1.307 ±0.00|8.415 ±0.08|1.319 ±0.01|0.143 ±0.00|0.170 ±0.00|13.827 ±0.15|3.965 ±2.58| |#7513|35.637 ±0.80|10.876 ±0.00|12.096 ±0.21|1.585 ±0.01|1.564 ±0.01|1.291 ±0.01|8.687 ±0.39|1.325 ±0.00|0.142 ±0.00|0.170 ±0.00|15.174 ±0.19|2.163 ±0.01| |**app-medium**|clean|lock-only|cache-only|modules-only|no-lock|no-cache|no-modules|no-clean|show-version|run-script|cache-only
peer-deps|no-clean
audit| |---|---|---|---|---|---|---|---|---|---|---|---|---| |npm@latest|28.833 ±0.18|8.128 ±0.08|9.090 ±0.00|1.554 ±0.01|1.530 ±0.00|1.454 ±0.00|5.951 ±0.03|1.358 ±0.02|0.143 ±0.00|0.170 ±0.00|9.642 ±0.02|3.307 ±1.87| |#7513|27.231 ±3.68|8.240 ±0.04|9.029 ±0.02|1.534 ±0.01|1.540 ±0.03|1.518 ±0.02|5.882 ±0.01|1.335 ±0.01|0.142 ±0.00|0.170 ±0.00|9.944 ±0.12|2.049 ±0.09|