From 88d82085774bde3baa85794f08afdfea224a4550 Mon Sep 17 00:00:00 2001 From: Daniel Wilches Date: Sat, 30 Jun 2018 13:07:26 -0700 Subject: [PATCH 1/2] version: allow prerelease identifier --- AUTHORS | 1 + doc/cli/npm-version.md | 2 +- doc/misc/npm-config.md | 8 ++++ lib/config/defaults.js | 2 + lib/version.js | 4 +- test/tap/version-prerelease-id.js | 61 +++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 test/tap/version-prerelease-id.js diff --git a/AUTHORS b/AUTHORS index 5cc378ab0593f..a80f7974afaf8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -579,3 +579,4 @@ Thomas Reggi David Gilbertson Rob Lourens Karan Thakkar +Daniel Wilches diff --git a/doc/cli/npm-version.md b/doc/cli/npm-version.md index 49f842fbb9d36..a20f4a982a603 100644 --- a/doc/cli/npm-version.md +++ b/doc/cli/npm-version.md @@ -3,7 +3,7 @@ npm-version(1) -- Bump a package version ## SYNOPSIS - npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git] + npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=] | from-git] 'npm [-v | --version]' to print npm version 'npm view version' to view a package's published version diff --git a/doc/misc/npm-config.md b/doc/misc/npm-config.md index 8d439331845e1..10a97f2ae55c7 100644 --- a/doc/misc/npm-config.md +++ b/doc/misc/npm-config.md @@ -798,6 +798,14 @@ for updates immediately even for fresh package data. The location to install global items. If set on the command line, then it forces non-global commands to run in the specified folder. +### preid + +* Default: "" +* Type: String + +The "prerelease identifier" to use as a prefix for the "prerelease" part of a +semver. Like the `rc` in `1.2.0-rc.8`. + ### production * Default: false diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 5c324239f2adf..2ea37c37adf43 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -190,6 +190,7 @@ Object.defineProperty(exports, 'defaults', {get: function () { 'prefer-offline': false, 'prefer-online': false, prefix: globalPrefix, + preid: '', production: process.env.NODE_ENV === 'production', 'progress': !process.env.TRAVIS && !process.env.CI, proxy: null, @@ -328,6 +329,7 @@ exports.types = { 'prefer-offline': Boolean, 'prefer-online': Boolean, prefix: path, + preid: String, production: Boolean, progress: Boolean, proxy: [null, false, url], // allow proxy to be disabled explicitly diff --git a/lib/version.js b/lib/version.js index a8bc3123a9c80..53a1d5515d51a 100644 --- a/lib/version.js +++ b/lib/version.js @@ -18,7 +18,7 @@ const semver = require('semver') const stringifyPackage = require('./utils/stringify-package') const writeFileAtomic = require('write-file-atomic') -version.usage = 'npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]' + +version.usage = 'npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=] | from-git]' + '\n(run in package dir)\n' + "'npm -v' or 'npm --version' to print npm version " + '(' + npm.version + ')\n' + @@ -47,7 +47,7 @@ function version (args, silent, cb_) { retrieveTagVersion(silent, data, cb_) } else { var newVersion = semver.valid(args[0]) - if (!newVersion) newVersion = semver.inc(data.version, args[0]) + if (!newVersion) newVersion = semver.inc(data.version, args[0], npm.config.get('preid')) if (!newVersion) return cb_(version.usage) persistVersion(newVersion, silent, data, cb_) } diff --git a/test/tap/version-prerelease-id.js b/test/tap/version-prerelease-id.js new file mode 100644 index 0000000000000..1a206aa116649 --- /dev/null +++ b/test/tap/version-prerelease-id.js @@ -0,0 +1,61 @@ +var fs = require('fs') +var path = require('path') + +var mkdirp = require('mkdirp') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var npm = require('../../') +var common = require('../common-tap.js') + +var pkg = path.resolve(__dirname, 'version-shrinkwrap') +var cache = path.resolve(pkg, 'cache') + +var EXEC_OPTS = { cwd: pkg } + +test('setup', function (t) { + setup() + t.end() +}) + +test('npm version --preid=rc uses prerelease id', function (t) { + setup() + + npm.load({ cache: pkg + '/cache', registry: common.registry }, function () { + common.npm(['version', 'prerelease', '--preid=rc'], EXEC_OPTS, function (err) { + if (err) return t.fail('Error perform version prerelease') + var newVersion = require(path.resolve(pkg, 'package.json')).version + t.equal(newVersion, '0.0.1-rc.0', 'got expected version') + t.end() + }) + }) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + +function setup () { + cleanup() + mkdirp.sync(pkg) + mkdirp.sync(cache) + var contents = { + author: 'Daniel Wilches', + name: 'version-prerelease-id', + version: '0.0.0', + description: 'Test for version of prereleases with preids' + } + + fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(contents), 'utf8') + fs.writeFileSync(path.resolve(pkg, 'npm-shrinkwrap.json'), JSON.stringify(contents), 'utf8') + process.chdir(pkg) +} + +function cleanup () { + // windows fix for locked files + process.chdir(osenv.tmpdir()) + rimraf.sync(cache) + rimraf.sync(pkg) +} From bdc523c3fae686846533feacf9420284af4db1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 23 Jul 2018 09:43:56 -0700 Subject: [PATCH 2/2] remove manually-added author npm itself updates AUTHORS when we release. No need to do this in a PR. --- AUTHORS | 1 - 1 file changed, 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 8c1f85ff86481..4b9b627102d6b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -584,4 +584,3 @@ Geoffrey Mattie Luis Lobo Borobia Aaron Tribou 刘祺 -Daniel Wilches