Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MylesBorins/95ea3eff7271415131348ae9494d6838 to your computer and use it in GitHub Desktop.
Save MylesBorins/95ea3eff7271415131348ae9494d6838 to your computer and use it in GitHub Desktop.
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