From f1e6743a6e8e32ddad6d1964eb05d17e6c50a456 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 14 Apr 2021 09:22:25 -0700 Subject: [PATCH] libnpmversion@1.2.0 --- node_modules/libnpmversion/lib/commit.js | 11 ++++-- .../libnpmversion/lib/enforce-clean.js | 11 +++--- node_modules/libnpmversion/lib/index.js | 4 +- node_modules/libnpmversion/lib/read-json.js | 2 +- .../libnpmversion/lib/retrieve-tag.js | 12 +++--- node_modules/libnpmversion/lib/tag.js | 20 +++++++--- node_modules/libnpmversion/lib/version.js | 38 +++++++++---------- node_modules/libnpmversion/lib/write-json.js | 4 +- node_modules/libnpmversion/package.json | 11 +++++- package-lock.json | 14 +++---- package.json | 2 +- 11 files changed, 74 insertions(+), 55 deletions(-) diff --git a/node_modules/libnpmversion/lib/commit.js b/node_modules/libnpmversion/lib/commit.js index bd621acb4393d..dec6edbec98c3 100644 --- a/node_modules/libnpmversion/lib/commit.js +++ b/node_modules/libnpmversion/lib/commit.js @@ -1,14 +1,17 @@ const git = require('@npmcli/git') module.exports = (version, opts) => { - const {commitHooks, allowSameVersion, signGitCommit, message} = opts + const { commitHooks, allowSameVersion, signGitCommit, message } = opts const args = ['commit'] - if (commitHooks === false) + if (commitHooks === false) { args.push('-n') - if (allowSameVersion) + } + if (allowSameVersion) { args.push('--allow-empty') - if (signGitCommit) + } + if (signGitCommit) { args.push('-S') + } args.push('-m') return git.spawn([...args, message.replace(/%s/g, version)], opts) } diff --git a/node_modules/libnpmversion/lib/enforce-clean.js b/node_modules/libnpmversion/lib/enforce-clean.js index 980419ffb43d8..6103da9bd96af 100644 --- a/node_modules/libnpmversion/lib/enforce-clean.js +++ b/node_modules/libnpmversion/lib/enforce-clean.js @@ -15,17 +15,16 @@ module.exports = async opts => { hadError = true // how can merges be real if our git isn't real? return true - } else + } else { throw er + } }) if (!clean) { - if (!force) + if (!force) { throw new Error('Git working directory not clean.') - log.warn( - 'version', - 'Git working directory not clean, proceeding forcefully.' - ) + } + log.warn('version', 'Git working directory not clean, proceeding forcefully.') } return !hadError diff --git a/node_modules/libnpmversion/lib/index.js b/node_modules/libnpmversion/lib/index.js index 683941cdea4f3..b10b3e6ba4123 100644 --- a/node_modules/libnpmversion/lib/index.js +++ b/node_modules/libnpmversion/lib/index.js @@ -16,7 +16,7 @@ module.exports = async (newversion, opts = {}) => { scriptShell = undefined, preid = null, log = proclog, - message = 'v%s', + message = 'v%s' } = opts const pkg = opts.pkg || await readJson(path + '/package.json') @@ -36,6 +36,6 @@ module.exports = async (newversion, opts = {}) => { preid, pkg, log, - message, + message }) } diff --git a/node_modules/libnpmversion/lib/read-json.js b/node_modules/libnpmversion/lib/read-json.js index 0a1f64f2f70e7..2dd0f7aa4902e 100644 --- a/node_modules/libnpmversion/lib/read-json.js +++ b/node_modules/libnpmversion/lib/read-json.js @@ -1,6 +1,6 @@ // can't use read-package-json-fast, because we want to ensure // that we make as few changes as possible, even for safety issues. -const {promisify} = require('util') +const { promisify } = require('util') const readFile = promisify(require('fs').readFile) const parse = require('json-parse-even-better-errors') diff --git a/node_modules/libnpmversion/lib/retrieve-tag.js b/node_modules/libnpmversion/lib/retrieve-tag.js index b657561b861e7..7aa2abfda8651 100644 --- a/node_modules/libnpmversion/lib/retrieve-tag.js +++ b/node_modules/libnpmversion/lib/retrieve-tag.js @@ -1,11 +1,11 @@ -const {spawn} = require('@npmcli/git') +const { spawn } = require('@npmcli/git') const semver = require('semver') module.exports = async opts => { - const tag = (await spawn(['describe', '--abbrev=0'], opts)).stdout.trim() - const match = tag.match(/v?(\d+\.\d+\.\d+(?:[-+].+)?)/) - const ver = match && semver.clean(match[1], { loose: true }) - if (ver) - return ver + const tag = (await spawn(['describe', '--tags', '--abbrev=0', '--match=\'*.*.*\''], opts)).stdout.trim() + const ver = semver.coerce(tag, { loose: true }) + if (ver) { + return ver.version + } throw new Error(`Tag is not a valid version: ${JSON.stringify(tag)}`) } diff --git a/node_modules/libnpmversion/lib/tag.js b/node_modules/libnpmversion/lib/tag.js index bd6c803a38499..73134dd25e6fe 100644 --- a/node_modules/libnpmversion/lib/tag.js +++ b/node_modules/libnpmversion/lib/tag.js @@ -1,20 +1,30 @@ const git = require('@npmcli/git') module.exports = async (version, opts) => { - const { signGitTag, allowSameVersion, tagVersionPrefix, message } = opts - const tag = `${tagVersionPrefix}${version}` + const { + signGitTag, + allowSameVersion, + tagVersionPrefix, + message + } = opts + const tag = `${tagVersionPrefix}${version}` const flags = ['-'] - if (signGitTag) + + if (signGitTag) { flags.push('s') - if (allowSameVersion) + } + + if (allowSameVersion) { flags.push('f') + } + flags.push('m') return git.spawn([ 'tag', flags.join(''), message.replace(/%s/g, version), - tag, + tag ], opts) } diff --git a/node_modules/libnpmversion/lib/version.js b/node_modules/libnpmversion/lib/version.js index 0fe1ea6213fc6..2ef79173fca76 100644 --- a/node_modules/libnpmversion/lib/version.js +++ b/node_modules/libnpmversion/lib/version.js @@ -15,31 +15,30 @@ module.exports = async (newversion, opts) => { const { path, allowSameVersion, - tagVersionPrefix, - commitHooks, gitTagVersion, - signGitCommit, - signGitTag, - force, ignoreScripts, preid, pkg, - log, - message, + log } = opts const { valid, clean, inc } = semver const current = pkg.version || '0.0.0' const currentClean = clean(current) - const newV = valid(newversion, { loose: true }) ? clean(newversion, { loose: true }) - : newversion === 'from-git' ? await retrieveTag(opts) - : inc(currentClean, newversion, { loose: true }, preid) + let newV + if (valid(newversion, { loose: true })) { + newV = clean(newversion, { loose: true }) + } else if (newversion === 'from-git') { + newV = await retrieveTag(opts) + } else { + newV = inc(currentClean, newversion, { loose: true }, preid) + } if (!newV) { throw Object.assign(new Error('Invalid version: ' + newversion), { current, - requested: newversion, + requested: newversion }) } @@ -47,7 +46,7 @@ module.exports = async (newversion, opts) => { throw Object.assign(new Error('Version not changed'), { current, requested: newversion, - newVersion: newV, + newVersion: newV }) } @@ -68,8 +67,8 @@ module.exports = async (newversion, opts) => { banner: log.level !== 'silent', env: { npm_old_version: current, - npm_new_version: newV, - }, + npm_new_version: newV + } }) } @@ -102,8 +101,8 @@ module.exports = async (newversion, opts) => { banner: log.level !== 'silent', env: { npm_old_version: current, - npm_new_version: newV, - }, + npm_new_version: newV + } }) } @@ -116,8 +115,7 @@ module.exports = async (newversion, opts) => { } await commit(newV, opts) await tag(newV, opts) - } else - log.verbose('version', 'Not tagging: not in a git repo or no git cmd') + } else { log.verbose('version', 'Not tagging: not in a git repo or no git cmd') } if (!ignoreScripts) { await runScript({ @@ -128,8 +126,8 @@ module.exports = async (newversion, opts) => { banner: log.level !== 'silent', env: { npm_old_version: current, - npm_new_version: newV, - }, + npm_new_version: newV + } }) } diff --git a/node_modules/libnpmversion/lib/write-json.js b/node_modules/libnpmversion/lib/write-json.js index 30ca1af0f19ed..813bb7ffc279b 100644 --- a/node_modules/libnpmversion/lib/write-json.js +++ b/node_modules/libnpmversion/lib/write-json.js @@ -1,5 +1,5 @@ // write the json back, preserving the line breaks and indent -const {promisify} = require('util') +const { promisify } = require('util') const writeFile = promisify(require('fs').writeFile) const kIndent = Symbol.for('indent') const kNewline = Symbol.for('newline') @@ -7,7 +7,7 @@ const kNewline = Symbol.for('newline') module.exports = async (path, pkg) => { const { [kIndent]: indent = 2, - [kNewline]: newline = '\n', + [kNewline]: newline = '\n' } = pkg delete pkg._id const raw = JSON.stringify(pkg, null, indent) + '\n' diff --git a/node_modules/libnpmversion/package.json b/node_modules/libnpmversion/package.json index 574fc6e70d551..ebc88a1fc5754 100644 --- a/node_modules/libnpmversion/package.json +++ b/node_modules/libnpmversion/package.json @@ -1,6 +1,6 @@ { "name": "libnpmversion", - "version": "1.1.1", + "version": "1.2.0", "main": "lib/index.js", "files": [ "lib/*.js" @@ -13,18 +13,27 @@ "author": "Isaac Z. Schlueter (https://izs.me)", "license": "ISC", "scripts": { + "lint": "standard", + "lint:fix": "standard --fix", "test": "tap", + "posttest": "npm run lint", "snap": "tap", "preversion": "npm test", "postversion": "npm publish", "prepublishOnly": "git push origin --follow-tags" }, + "standard": { + "ignore": [ + "tap-snapshots" + ] + }, "tap": { "coverage-map": "map.js", "check-coverage": true }, "devDependencies": { "require-inject": "^1.4.4", + "standard": "^16.0.3", "tap": "^14.11.0" }, "dependencies": { diff --git a/package-lock.json b/package-lock.json index 6881dcb92e6b4..78a2be26cf7da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -283,7 +283,7 @@ "libnpmpublish": "^4.0.0", "libnpmsearch": "^3.1.0", "libnpmteam": "^2.0.2", - "libnpmversion": "^1.1.1", + "libnpmversion": "^1.2.0", "make-fetch-happen": "^8.0.14", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", @@ -4954,9 +4954,9 @@ } }, "node_modules/libnpmversion": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.1.1.tgz", - "integrity": "sha512-Ha4NoUwq/gvQc+2QvuNLbiCJdVylt04N5qDQT7Oq0VqkmBdojrcfy2Dbb+DCfWtWsflm/RwzENBllRUfsUiIqA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.2.0.tgz", + "integrity": "sha512-0pfmobLZbOvq1cLIONZk8ISvEM1k3JdkNXWhMDZvUeH+ijBNvMVdPu/CPUr1eDFbNINS3b6R/0PbTIZDVz7thg==", "inBundle": true, "dependencies": { "@npmcli/git": "^2.0.7", @@ -14139,9 +14139,9 @@ } }, "libnpmversion": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.1.1.tgz", - "integrity": "sha512-Ha4NoUwq/gvQc+2QvuNLbiCJdVylt04N5qDQT7Oq0VqkmBdojrcfy2Dbb+DCfWtWsflm/RwzENBllRUfsUiIqA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/libnpmversion/-/libnpmversion-1.2.0.tgz", + "integrity": "sha512-0pfmobLZbOvq1cLIONZk8ISvEM1k3JdkNXWhMDZvUeH+ijBNvMVdPu/CPUr1eDFbNINS3b6R/0PbTIZDVz7thg==", "requires": { "@npmcli/git": "^2.0.7", "@npmcli/run-script": "^1.8.4", diff --git a/package.json b/package.json index 55d2045ab02a6..65f9b8e7adf43 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "libnpmpublish": "^4.0.0", "libnpmsearch": "^3.1.0", "libnpmteam": "^2.0.2", - "libnpmversion": "^1.1.1", + "libnpmversion": "^1.2.0", "make-fetch-happen": "^8.0.14", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4",