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

chore(refactor): refactor exit handler and tests #3482

Merged
merged 1 commit into from Jul 12, 2021

Conversation

wraithgar
Copy link
Member

@wraithgar wraithgar commented Jun 29, 2021

  • npm mock logger writes to npm.log.record too now
  • No more extra process.exit from within the process exit event handle.
  • No more exit() function. Logic is rolled up into the exit handler.
  • Now there is only an exit handler and an exit event listener.
    lib/utils/perf.js was rolled up into npm.js itself.

Unfortunately the tests were written in such a way that any further
refactoring of the exit handler was going to require also rewriting the
tests. Fortunately NOW the tests are interacting with the exit handler
in a way that shouldn't require them to be rewritten AGAIN if we change
the internals of the exit handler.

Needs #3479 to land first

@wraithgar wraithgar requested a review from a team as a code owner June 29, 2021 21:36
@wraithgar
Copy link
Member Author

wraithgar commented Jun 30, 2021

We are either going to need to put process.exit() back into the exit handler or find a way to unref/cancel the update notifier promise.

This is done, with a more meaningful comment explaining why it's in there

@wraithgar wraithgar force-pushed the gar/exit-handler-mark-two branch 4 times, most recently from 6ba68c9 to 44e234d Compare June 30, 2021 18:00
@darcyclarke darcyclarke added the Release 7.x work is associated with a specific npm 7 release label Jul 12, 2021
Copy link
Contributor

@nlf nlf left a comment

Choose a reason for hiding this comment

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

i'm a big fan of these pull requests that delete a bunch of misdirection and just generally unnecessary code

left one question, but this all looks good as far as i can see. much simpler and much more clear 👍

@@ -75,7 +75,6 @@ class BaseCommand {
}

async setWorkspaces (filters) {
// TODO npm guards workspaces/global mode so we should use this.npm.prefix?
Copy link
Contributor

Choose a reason for hiding this comment

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

is this TODO not something we still need to do? is this an answered question already?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the entire approach to npm.prefix vs npm.localPrefix etc needs addressing and I'd rather leave these comments in until we actually properly audit and review how we're using those.

this.started = Date.now()
this.command = null
this.commands = proxyCmds
this.timings = timings
this.timers = timers
this.perfStart()
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a great intermediate step to avoid the singleton issue 🎉

process.on('exit', code => {
// process.emit is synchronous, so the timeEnd handler will run before the
// unfinished timer check below
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 thank you for calling this out, it's a super nice reminder!

@wraithgar
Copy link
Member Author

rebasing fixed the conflicts w/o having to change anything. PHEW

 * npm mock logger writes to npm.log.record too now
 * No more extra process.exit from within the process `exit` event handle.
 * No more `exit()` function.  Logic is rolled up into the exit handler.
 * Now there is only an exit handler and an exit event listener.
   `lib/utils/perf.js` was rolled up into npm.js itself.

Unfortunately the tests were written in such a way that any further
refactoring of the exit handler was going to require also rewriting the
tests.  Fortunately NOW the tests are interacting with the exit handler
in a way that shouldn't require them to be rewritten AGAIN if we change
the internals of the exit handler.

PR-URL: #3482
Credit: @wraithgar
Close: #3482
Reviewed-by: @nlf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants