Forked from isaacs/gist:00fa33f93f309750bfbc423694829af7
Created
September 16, 2020 18:57
-
-
Save MylesBorins/95ea3eff7271415131348ae9494d6838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/npm.js b/lib/npm.js | |
index 79d276722..7fb234cc9 100644 | |
--- a/lib/npm.js | |
+++ b/lib/npm.js | |
@@ -3,6 +3,30 @@ | |
// we define and instantiate the singleton ahead of loading any modules | |
// required for its methods. | |
+/* istanbul ignore next */ { | |
+ const timers = {} | |
+ process.on('time', name => { | |
+ if (timers[name]) { | |
+ throw new Error('conflicting timer! ' + name) | |
+ } | |
+ timers[name] = process.hrtime() | |
+ }) | |
+ process.on('timeEnd', name => { | |
+ if (!timers[name]) { | |
+ throw new Error('timer not started! ' + name) | |
+ } | |
+ delete timers[name] | |
+ }) | |
+ process.on('exit', () => { | |
+ for (const name of Object.keys(timers)) { | |
+ if (name !== 'npm') { | |
+ console.error('Dangling timer: ', name) | |
+ process.exitCode = 1 | |
+ } | |
+ } | |
+ }) | |
+} | |
+ | |
// these are all dependencies used in the ctor | |
const EventEmitter = require('events') | |
const { resolve, dirname } = require('path') | |
@@ -108,6 +132,7 @@ const npm = module.exports = new class extends EventEmitter { | |
if (this.config.get('usage')) { | |
console.log(impl.usage) | |
cb() | |
+ process.emit('timeEnd', `command:${cmd}`) | |
} else { | |
impl(args, er => { | |
process.emit('timeEnd', `command:${cmd}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment