From d6a616a4ddfab0119d4c60f8e49b428f8e0a2640 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 10 Feb 2022 03:26:56 -0700 Subject: [PATCH] feat: use proc-log instead of process.emit and drop support for `log` property BREAKING CHANGE: this drops support for the `log` property and all logs are now emitted on the process object via `proc-log`. --- lib/proc-log.js | 21 --------------------- lib/spawn.js | 3 +-- package.json | 1 + test/spawn.js | 4 ---- 4 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 lib/proc-log.js diff --git a/lib/proc-log.js b/lib/proc-log.js deleted file mode 100644 index a7c683b..0000000 --- a/lib/proc-log.js +++ /dev/null @@ -1,21 +0,0 @@ -// default logger. -// emits 'log' events on the process -const LEVELS = [ - 'notice', - 'error', - 'warn', - 'info', - 'verbose', - 'http', - 'silly', - 'pause', - 'resume', -] - -const log = level => (...args) => process.emit('log', level, ...args) - -const logger = {} -for (const level of LEVELS) { - logger[level] = log(level) -} -module.exports = logger diff --git a/lib/spawn.js b/lib/spawn.js index bcee408..40972a5 100644 --- a/lib/spawn.js +++ b/lib/spawn.js @@ -1,9 +1,9 @@ const spawn = require('@npmcli/promise-spawn') const promiseRetry = require('promise-retry') +const log = require('proc-log') const makeError = require('./make-error.js') const whichGit = require('./which.js') const makeOpts = require('./opts.js') -const procLog = require('./proc-log.js') module.exports = (gitArgs, opts = {}) => { const gitPath = whichGit(opts) @@ -17,7 +17,6 @@ module.exports = (gitArgs, opts = {}) => { ? gitArgs : ['--no-replace-objects', ...gitArgs] - const log = opts.log || procLog let retry = opts.retry if (retry === null || retry === undefined) { retry = { diff --git a/package.json b/package.json index ad7a86c..e087ee3 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "lru-cache": "^6.0.0", "mkdirp": "^1.0.4", "npm-pick-manifest": "^6.1.1", + "proc-log": "^2.0.0", "promise-inflight": "^1.0.1", "promise-retry": "^2.0.1", "semver": "^7.3.5", diff --git a/test/spawn.js b/test/spawn.js index c8331bc..667dd0c 100644 --- a/test/spawn.js +++ b/test/spawn.js @@ -1,5 +1,4 @@ const spawn = require('../lib/spawn.js') -const procLog = require('../lib/proc-log.js') const errors = require('../lib/errors.js') const t = require('tap') @@ -81,7 +80,6 @@ process.exit(1) cwd: repo, git: process.execPath, allowReplace: true, - log: procLog, ...(retryOptions[n]), }), er).then(() => { t.same(logs, [ @@ -121,7 +119,6 @@ process.exit(1) cwd: repo, git: process.execPath, allowReplace: true, - log: procLog, }), er) t.end() }) @@ -146,7 +143,6 @@ process.exit(1) cwd: repo, git: process.execPath, allowReplace: true, - log: procLog, }), er) t.end() })