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

[v7] Update output of npm install command #1017

Closed
wants to merge 51 commits into from

Conversation

mikemimik
Copy link
Contributor

@mikemimik mikemimik commented Mar 12, 2020

What / Why

We previous added arborist and used it to install dependencies. This pull-request contains changes to how that command now outputs to the terminal for the user.

Arborist Functionality

There is a pull-request on npm/arborist#52 which adds some additional functionality, exposing the diff tree, that the cli is now going to leverage to get change actions from commands run with arborist.

References

claudiahdz and others added 30 commits February 4, 2020 16:01
Still a lot to do, and this has a lot of very rought edges.
- Stop sending an HTTP Referer header to the registry
- Install global packages properly
- Save added packages in the appropriate dep type in package.json
- Dedupe npm-registry-fetch and pacote to top level
This is a defense for all cases where we might be trying to open a web
url based on either a response from the server, or some form of user
input.  As far as we can tell, they're all being validated, but defense
in depth is always a good idea.
@mikemimik mikemimik added Enhancement new feature or improvement Release 7.x work is associated with a specific npm 7 release labels Mar 12, 2020
@mikemimik mikemimik added this to the OSS - Sprint 6 milestone Mar 12, 2020
@mikemimik mikemimik requested a review from a team as a code owner March 12, 2020 17:04
@mikemimik mikemimik self-assigned this Mar 12, 2020
@mikemimik mikemimik force-pushed the mikemimik/feature/npm-install branch from 319f189 to 616fa0c Compare March 12, 2020 19:04
@mikemimik mikemimik force-pushed the mikemimik/feature/npm-install branch from 616fa0c to e32956f Compare March 13, 2020 03:31
lib/install.js Outdated Show resolved Hide resolved
lib/install.js Outdated Show resolved Hide resolved
const arbCallOpts = { ...npm.flatOptions, add: args }

try {
const start = Date.now()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love opinions on this start/stop logic. I don't love it, but I was trying to keep the output from the previous version of the command.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, Date.now() is a bit blunt, but probably fine enough accuracy for our purposes. It'd of course be more precise to use process.hrtime(), and get nanosecond precision, but since big installs are sometimes several minutes long, we probably don't need that much precision.

- functionality to get diff and explicitRequets from arborist instace
  requires @npmcli/arborist@0.0.0-pre.12
- create printResult function
- output install action time (fairly naively)
- added functionality to create and print archy dep tree
@mikemimik mikemimik force-pushed the mikemimik/feature/npm-install branch from e32956f to 1e0ee77 Compare March 17, 2020 04:46
Copy link
Contributor

@isaacs isaacs left a comment

Choose a reason for hiding this comment

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

Some thoughts about the specifics of the output. I think dumping the physical tree is probably less useful than something related to the diffs, since that shows what actually changed.

}
}

function printResults (timing, tree, arb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it probably would be more useful to silly-log a representation of the diff rather than just the top-level deps.

Maybe just iterate through the nodes in the diff and report what we're doing at each path (adding, removing, or replacing) and the version/integrity of what's getting put there?


// Collect information about command action taken
const pkgCount = arb.diff.children.length
const contribCount = pkgCount
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a count of contributors, not a count of packages. Ie, unique maintainers or something?

const contribCount = pkgCount
const added = `added ${pkgCount}`

const from = `from ${contribCount} contributor${contribCount ? 's' : ''}`
Copy link
Contributor

Choose a reason for hiding this comment

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

The pluralizing logic is a little off here. It'll add the s for any number other than zero?

const added = `added ${pkgCount}`

const from = `from ${contribCount} contributor${contribCount ? 's' : ''}`
const audited = `audited ${0} package${'s'}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Pluralizing logic even more weird here ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see, this is a placeholder until we have quick audits back in place.

I'd rather stub a function to return 0 or whatever, and have the correct logic here, or omit the audited bit entirely until it's correct, just so it's not a bug lying in wait.

@ruyadorno ruyadorno added the semver:major backwards-incompatible breaking changes label Mar 24, 2020
@darcyclarke darcyclarke self-assigned this Apr 7, 2020
@isaacs
Copy link
Contributor

isaacs commented May 8, 2020

Closed by #1245

@isaacs isaacs closed this May 8, 2020
@nlf nlf deleted the mikemimik/feature/npm-install branch March 28, 2022 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement Release 7.x work is associated with a specific npm 7 release semver:major backwards-incompatible breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants