Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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