diff options
author | Luke Karrys <luke@lukekarrys.com> | 2022-02-22 08:25:21 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-02-24 02:58:59 +0300 |
commit | 174dd88cba31b25461619fe796fe1d3ac34eae70 (patch) | |
tree | e0dfdd2afd9ab50e53497b0265dfedc5c6ed3382 /workspaces/libnpmversion | |
parent | 55e9ef01f1ee6a71489b32b31d17d2cbdc2d1a64 (diff) |
feat(libnpmversion): rm log opt and add silent opt to control run script
BREAKING CHANGE: this removes the log option
Diffstat (limited to 'workspaces/libnpmversion')
-rw-r--r-- | workspaces/libnpmversion/README.md | 1 | ||||
-rw-r--r-- | workspaces/libnpmversion/lib/enforce-clean.js | 3 | ||||
-rw-r--r-- | workspaces/libnpmversion/lib/index.js | 5 | ||||
-rw-r--r-- | workspaces/libnpmversion/lib/proc-log.js | 21 | ||||
-rw-r--r-- | workspaces/libnpmversion/lib/version.js | 9 | ||||
-rw-r--r-- | workspaces/libnpmversion/tap-snapshots/test/index.js.test.cjs | 14 | ||||
-rw-r--r-- | workspaces/libnpmversion/test/enforce-clean.js | 12 | ||||
-rw-r--r-- | workspaces/libnpmversion/test/index.js | 1 | ||||
-rw-r--r-- | workspaces/libnpmversion/test/proc-log.js | 11 | ||||
-rw-r--r-- | workspaces/libnpmversion/test/version.js | 53 |
10 files changed, 44 insertions, 86 deletions
diff --git a/workspaces/libnpmversion/README.md b/workspaces/libnpmversion/README.md index e82e7cd6f..165d16a2b 100644 --- a/workspaces/libnpmversion/README.md +++ b/workspaces/libnpmversion/README.md @@ -27,6 +27,7 @@ npmVersion(arg, { ignoreScripts: false, // do not run pre/post/version lifecycle scripts scriptShell: '/bin/bash', // shell to run lifecycle scripts in message: 'v%s', // message for tag and commit, replace %s with the version + silent: false, // passed to @npmcli/run-script to control whether it logs }).then(newVersion => { console.error('version updated!', newVersion) }) diff --git a/workspaces/libnpmversion/lib/enforce-clean.js b/workspaces/libnpmversion/lib/enforce-clean.js index 6103da9bd..721f14622 100644 --- a/workspaces/libnpmversion/lib/enforce-clean.js +++ b/workspaces/libnpmversion/lib/enforce-clean.js @@ -1,9 +1,10 @@ const git = require('@npmcli/git') +const log = require('proc-log') // returns true if it's cool to do git stuff // throws if it's unclean, and not forced. module.exports = async opts => { - const { force, log } = opts + const { force } = opts let hadError = false const clean = await git.isClean(opts).catch(er => { if (er.code === 'ENOGIT') { diff --git a/workspaces/libnpmversion/lib/index.js b/workspaces/libnpmversion/lib/index.js index 683941cde..95acd11b5 100644 --- a/workspaces/libnpmversion/lib/index.js +++ b/workspaces/libnpmversion/lib/index.js @@ -1,6 +1,5 @@ const readJson = require('./read-json.js') const version = require('./version.js') -const proclog = require('./proc-log.js') module.exports = async (newversion, opts = {}) => { const { @@ -15,8 +14,8 @@ module.exports = async (newversion, opts = {}) => { ignoreScripts = false, scriptShell = undefined, preid = null, - log = proclog, message = 'v%s', + silent, } = opts const pkg = opts.pkg || await readJson(path + '/package.json') @@ -35,7 +34,7 @@ module.exports = async (newversion, opts = {}) => { scriptShell, preid, pkg, - log, message, + silent, }) } diff --git a/workspaces/libnpmversion/lib/proc-log.js b/workspaces/libnpmversion/lib/proc-log.js deleted file mode 100644 index a7c683ba2..000000000 --- a/workspaces/libnpmversion/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/workspaces/libnpmversion/lib/version.js b/workspaces/libnpmversion/lib/version.js index 116a37555..12be89b04 100644 --- a/workspaces/libnpmversion/lib/version.js +++ b/workspaces/libnpmversion/lib/version.js @@ -8,6 +8,7 @@ const readJson = require('./read-json.js') const git = require('@npmcli/git') const commit = require('./commit.js') const tag = require('./tag.js') +const log = require('proc-log') const runScript = require('@npmcli/run-script') @@ -19,7 +20,7 @@ module.exports = async (newversion, opts) => { ignoreScripts, preid, pkg, - log, + silent, } = opts const { valid, clean, inc } = semver @@ -64,7 +65,7 @@ module.exports = async (newversion, opts) => { pkg, stdio: 'inherit', event: 'preversion', - banner: log.level !== 'silent', + banner: !silent, env: { npm_old_version: current, npm_new_version: newV, @@ -98,7 +99,7 @@ module.exports = async (newversion, opts) => { pkg, stdio: 'inherit', event: 'version', - banner: log.level !== 'silent', + banner: !silent, env: { npm_old_version: current, npm_new_version: newV, @@ -125,7 +126,7 @@ module.exports = async (newversion, opts) => { pkg, stdio: 'inherit', event: 'postversion', - banner: log.level !== 'silent', + banner: !silent, env: { npm_old_version: current, npm_new_version: newV, diff --git a/workspaces/libnpmversion/tap-snapshots/test/index.js.test.cjs b/workspaces/libnpmversion/tap-snapshots/test/index.js.test.cjs index 6b79d41eb..59224e13f 100644 --- a/workspaces/libnpmversion/tap-snapshots/test/index.js.test.cjs +++ b/workspaces/libnpmversion/tap-snapshots/test/index.js.test.cjs @@ -15,17 +15,6 @@ Array [ "force": false, "gitTagVersion": true, "ignoreScripts": false, - "log": Object { - "error": Function (...args), - "http": Function (...args), - "info": Function (...args), - "notice": Function (...args), - "pause": Function (...args), - "resume": Function (...args), - "silly": Function (...args), - "verbose": Function (...args), - "warn": Function (...args), - }, "message": "v%s", "path": "{CWD}", "pkg": Object { @@ -35,6 +24,7 @@ Array [ "scriptShell": undefined, "signGitCommit": false, "signGitTag": false, + "silent": undefined, "tagVersionPrefix": "v", }, ] @@ -50,7 +40,6 @@ Array [ "force": true, "gitTagVersion": false, "ignoreScripts": true, - "log": Object {}, "message": "hello, i have a message for you", "path": "/some/path", "pkg": Object { @@ -60,6 +49,7 @@ Array [ "scriptShell": "/bin/bash", "signGitCommit": true, "signGitTag": true, + "silent": undefined, "tagVersionPrefix": "=", }, ] diff --git a/workspaces/libnpmversion/test/enforce-clean.js b/workspaces/libnpmversion/test/enforce-clean.js index 9a489d6f5..d96fb09ff 100644 --- a/workspaces/libnpmversion/test/enforce-clean.js +++ b/workspaces/libnpmversion/test/enforce-clean.js @@ -16,27 +16,27 @@ const enforceClean = requireInject('../lib/enforce-clean.js', { } }, }, + 'proc-log': { warn: (...msg) => warnings.push(msg) }, }) const warnings = [] -const log = { warn: (...msg) => warnings.push(msg) } t.test('clean, ok', t => - t.resolveMatch(enforceClean({ log, cwd: 'clean' }), true) + t.resolveMatch(enforceClean({ cwd: 'clean' }), true) .then(() => t.strictSame(warnings, [])) .then(() => { warnings.length = 0 })) t.test('unclean, no force, throws', t => - t.rejects(enforceClean({ log, cwd: 'unclean' })) + t.rejects(enforceClean({ cwd: 'unclean' })) .then(() => t.strictSame(warnings, [])) .then(() => { warnings.length = 0 })) t.test('unclean, forced, no throw', t => - t.resolveMatch(enforceClean({ log, cwd: 'unclean', force: true }), true) + t.resolveMatch(enforceClean({ cwd: 'unclean', force: true }), true) .then(() => t.strictSame(warnings, [ [ 'version', @@ -48,7 +48,7 @@ t.test('unclean, forced, no throw', t => })) t.test('nogit, return false, no throw', t => - t.resolveMatch(enforceClean({ log, cwd: 'nogit' }), false) + t.resolveMatch(enforceClean({ cwd: 'nogit' }), false) .then(() => t.strictSame(warnings, [ [ 'version', @@ -61,7 +61,7 @@ t.test('nogit, return false, no throw', t => })) t.test('other error, throw it', t => - t.rejects(enforceClean({ log, cwd: 'error' }), new Error('poop')) + t.rejects(enforceClean({ cwd: 'error' }), new Error('poop')) .then(() => t.strictSame(warnings, [])) .then(() => { warnings.length = 0 diff --git a/workspaces/libnpmversion/test/index.js b/workspaces/libnpmversion/test/index.js index 8c853c679..9dcef7b4c 100644 --- a/workspaces/libnpmversion/test/index.js +++ b/workspaces/libnpmversion/test/index.js @@ -33,7 +33,6 @@ t.test('set the package ahead of time', async t => ignoreScripts: true, scriptShell: '/bin/bash', preid: 'rc', - log: {}, message: 'hello, i have a message for you', someOtherRandomField: 'this should not show up', }))) diff --git a/workspaces/libnpmversion/test/proc-log.js b/workspaces/libnpmversion/test/proc-log.js deleted file mode 100644 index 54f7d0b57..000000000 --- a/workspaces/libnpmversion/test/proc-log.js +++ /dev/null @@ -1,11 +0,0 @@ -const procLog = require('../lib/proc-log.js') -const t = require('tap') -process.once('log', (...args) => t.same(args, ['warn', 1, 2, 3])) -procLog.warn(1, 2, 3) -t.same(Object.keys(procLog), [ - 'notice', 'error', - 'warn', 'info', - 'verbose', 'http', - 'silly', 'pause', - 'resume', -]) diff --git a/workspaces/libnpmversion/test/version.js b/workspaces/libnpmversion/test/version.js index dfaa95de3..19cf7ea0a 100644 --- a/workspaces/libnpmversion/test/version.js +++ b/workspaces/libnpmversion/test/version.js @@ -3,10 +3,6 @@ const requireInject = require('require-inject') const actionLog = [] -const log = { - verbose: (...msg) => actionLog.push(['verbose', ...msg]), -} - const gitMock = { is: async opts => !/\bnot-git$/.test(opts.path), spawn: async (args, opts) => actionLog.push(['spawn', args, opts]), @@ -26,6 +22,9 @@ const version = requireInject('../lib/version.js', { }, '@npmcli/git': gitMock, '@npmcli/run-script': async opt => actionLog.push(['run-script', opt.event, opt.env, opt]), + 'proc-log': { + verbose: (...msg) => actionLog.push(['verbose', ...msg]), + }, }) t.test('test out bumping the version in all the ways', async t => { @@ -70,7 +69,7 @@ t.test('test out bumping the version in all the ways', async t => { } throw new Error('no addy the locky fiel please & thanky i ignoring it') } - t.equal(await version('major', { path, log, pkg, gitTagVersion: true }), '2.0.0') + t.equal(await version('major', { path, pkg, gitTagVersion: true }), '2.0.0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '1.2.0', npm_new_version: '2.0.0' }], ['write-json', path + '/package.json', pkg], @@ -85,7 +84,7 @@ t.test('test out bumping the version in all the ways', async t => { }) await t.test('minor (ignore scripts)', async t => { t.equal(await version('minor', - { path, log, pkg, ignoreScripts: true, gitTagVersion: true }), '2.1.0') + { path, pkg, ignoreScripts: true, gitTagVersion: true }), '2.1.0') t.match(actionLog, [ ['write-json', path + '/package.json', pkg], ['write-json', path + '/package-lock.json', pkg], @@ -97,7 +96,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.0') }) await t.test('patch', async t => { - t.equal(await version('patch', { path, log, pkg, gitTagVersion: true }), '2.1.1') + t.equal(await version('patch', { path, pkg, gitTagVersion: true }), '2.1.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.0', npm_new_version: '2.1.1' }], ['write-json', path + '/package.json', pkg], @@ -112,7 +111,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1') }) await t.test('pre', async t => { - t.equal(await version('pre', { path, log, pkg, gitTagVersion: true }), '2.1.1-0') + t.equal(await version('pre', { path, pkg, gitTagVersion: true }), '2.1.1-0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.1', npm_new_version: '2.1.1-0' }], ['write-json', path + '/package.json', pkg], @@ -127,7 +126,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1-0') }) await t.test('pre with preid', async t => { - t.equal(await version('pre', { path, log, preid: 'alpha', pkg, gitTagVersion: true }), + t.equal(await version('pre', { path, preid: 'alpha', pkg, gitTagVersion: true }), '2.1.1-alpha.0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.1-0', @@ -145,7 +144,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1-alpha.0') }) await t.test('skips git tag when gitTagVersion is false', async t => { - t.equal(await version('minor', { path, log, pkg, ignoreScripts: true, gitTagVersion: false }), + t.equal(await version('minor', { path, pkg, ignoreScripts: true, gitTagVersion: false }), '2.2.0') t.match(actionLog, [ ['write-json', path + '/package.json', pkg], @@ -155,7 +154,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.2.0') }) await t.test('explicit version', async t => { - t.equal(await version('=v3.2.1', { path, log, pkg, gitTagVersion: true }), '3.2.1') + t.equal(await version('=v3.2.1', { path, pkg, gitTagVersion: true }), '3.2.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.2.0', npm_new_version: '3.2.1' }], ['write-json', path + '/package.json', pkg], @@ -170,14 +169,14 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '3.2.1') }) await t.test('invalid version', async t => { - await t.rejects(version('invalid version', { path, log, pkg }), { + await t.rejects(version('invalid version', { path, pkg }), { message: 'Invalid version: invalid version', current: '3.2.1', requested: 'invalid version', }) }) await t.test('same version, not allowed', async t => { - await t.rejects(version('=v3.2.1', { path, log, pkg }), { + await t.rejects(version('=v3.2.1', { path, pkg }), { message: 'Version not changed', current: '3.2.1', requested: '=v3.2.1', @@ -186,7 +185,7 @@ t.test('test out bumping the version in all the ways', async t => { }) await t.test('same version, is allowed', async t => { t.equal(await version('=v3.2.1', - { path, log, pkg, allowSameVersion: true, gitTagVersion: true }), '3.2.1') + { path, pkg, allowSameVersion: true, gitTagVersion: true }), '3.2.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '3.2.1', npm_new_version: '3.2.1' }], ['write-json', path + '/package.json', pkg], @@ -201,7 +200,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '3.2.1') }) await t.test('from git', async t => { - t.equal(await version('from-git', { path, log, pkg, gitTagVersion: true }), '1.2.3') + t.equal(await version('from-git', { path, pkg, gitTagVersion: true }), '1.2.3') t.match(actionLog, [ ['retrieve-tag', { path, pkg }], ['run-script', 'preversion', { npm_old_version: '3.2.1', npm_new_version: '1.2.3' }], @@ -218,7 +217,7 @@ t.test('test out bumping the version in all the ways', async t => { }) await t.test('no current version', async t => { delete pkg.version - t.equal(await version('2.3.4', { path, log, pkg, gitTagVersion: true }), '2.3.4') + t.equal(await version('2.3.4', { path, pkg, gitTagVersion: true }), '2.3.4') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '0.0.0', npm_new_version: '2.3.4' }], ['write-json', path + '/package.json', pkg], @@ -241,7 +240,7 @@ t.test('test out bumping the version in all the ways', async t => { }) const path = `${dir}/not-git` await t.test('major', async t => { - t.equal(await version('major', { path, log, pkg }), '2.0.0') + t.equal(await version('major', { path, pkg }), '2.0.0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '1.2.0', npm_new_version: '2.0.0' }], ['write-json', path + '/package.json', pkg], @@ -253,7 +252,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.0.0') }) await t.test('minor (ignore scripts)', async t => { - t.equal(await version('minor', { path, log, pkg, ignoreScripts: true }), '2.1.0') + t.equal(await version('minor', { path, pkg, ignoreScripts: true }), '2.1.0') t.match(actionLog, [ ['write-json', path + '/package.json', pkg], ['write-json', path + '/npm-shrinkwrap.json', pkg], @@ -262,7 +261,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.0') }) await t.test('patch', async t => { - t.equal(await version('patch', { path, log, pkg }), '2.1.1') + t.equal(await version('patch', { path, pkg }), '2.1.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.0', npm_new_version: '2.1.1' }], ['write-json', path + '/package.json', pkg], @@ -274,7 +273,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1') }) await t.test('pre', async t => { - t.equal(await version('pre', { path, log, pkg }), '2.1.1-0') + t.equal(await version('pre', { path, pkg }), '2.1.1-0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.1', npm_new_version: '2.1.1-0' }], ['write-json', path + '/package.json', pkg], @@ -286,7 +285,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1-0') }) await t.test('pre with preid', async t => { - t.equal(await version('pre', { path, log, preid: 'alpha', pkg }), '2.1.1-alpha.0') + t.equal(await version('pre', { path, preid: 'alpha', pkg }), '2.1.1-alpha.0') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.1-0', npm_new_version: '2.1.1-alpha.0' }], @@ -300,7 +299,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '2.1.1-alpha.0') }) await t.test('explicit version', async t => { - t.equal(await version('=v3.2.1', { path, log, pkg }), '3.2.1') + t.equal(await version('=v3.2.1', { path, pkg }), '3.2.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '2.1.1-alpha.0', npm_new_version: '3.2.1' }], @@ -314,14 +313,14 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '3.2.1') }) await t.test('invalid version', async t => { - await t.rejects(version('invalid version', { path, log, pkg }), { + await t.rejects(version('invalid version', { path, pkg }), { message: 'Invalid version: invalid version', current: '3.2.1', requested: 'invalid version', }) }) await t.test('same version, not allowed', async t => { - await t.rejects(version('=v3.2.1', { path, log, pkg }), { + await t.rejects(version('=v3.2.1', { path, pkg }), { message: 'Version not changed', current: '3.2.1', requested: '=v3.2.1', @@ -329,7 +328,7 @@ t.test('test out bumping the version in all the ways', async t => { }) }) await t.test('same version, is allowed', async t => { - t.equal(await version('=v3.2.1', { path, log, pkg, allowSameVersion: true }), '3.2.1') + t.equal(await version('=v3.2.1', { path, pkg, allowSameVersion: true }), '3.2.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '3.2.1', npm_new_version: '3.2.1' }, { banner: true }], @@ -345,7 +344,7 @@ t.test('test out bumping the version in all the ways', async t => { }) await t.test('same version, is allowed (silent mode)', async t => { t.equal(await version('=v3.2.1', - { path, log: { ...log, level: 'silent' }, pkg, allowSameVersion: true }), '3.2.1') + { path, silent: true, pkg, allowSameVersion: true }), '3.2.1') t.match(actionLog, [ ['run-script', 'preversion', { npm_old_version: '3.2.1', npm_new_version: '3.2.1' }, { banner: false }], @@ -360,7 +359,7 @@ t.test('test out bumping the version in all the ways', async t => { t.equal(pkg.version, '3.2.1') }) await t.test('from git', async t => { - await t.rejects(version('from-git', { path, log, pkg }), { + await t.rejects(version('from-git', { path, pkg }), { message: 'not a git dir', }) }) |