diff options
author | Gar <gar+gh@danger.computer> | 2021-04-14 19:22:25 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-04-14 19:22:25 +0300 |
commit | f1e6743a6e8e32ddad6d1964eb05d17e6c50a456 (patch) | |
tree | 397ddc934f4ffdd076b14808753bebe918b4a907 /node_modules/libnpmversion | |
parent | 42965fdfa08072e2b172d777569900522de63802 (diff) |
libnpmversion@1.2.0
Diffstat (limited to 'node_modules/libnpmversion')
-rw-r--r-- | node_modules/libnpmversion/lib/commit.js | 11 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/enforce-clean.js | 11 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/index.js | 4 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/read-json.js | 2 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/retrieve-tag.js | 12 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/tag.js | 20 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/version.js | 38 | ||||
-rw-r--r-- | node_modules/libnpmversion/lib/write-json.js | 4 | ||||
-rw-r--r-- | node_modules/libnpmversion/package.json | 11 |
9 files changed, 66 insertions, 47 deletions
diff --git a/node_modules/libnpmversion/lib/commit.js b/node_modules/libnpmversion/lib/commit.js index bd621acb4..dec6edbec 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 980419ffb..6103da9bd 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 683941cde..b10b3e6ba 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 0a1f64f2f..2dd0f7aa4 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 b657561b8..7aa2abfda 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 bd6c803a3..73134dd25 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 0fe1ea621..2ef79173f 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 30ca1af0f..813bb7ffc 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 574fc6e70..ebc88a1fc 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 <i@izs.me> (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": { |