Socket
Socket
Sign inDemoInstall

standard-version

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

standard-version - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0-0

bin/cli.js

23

CHANGELOG.md

@@ -5,2 +5,23 @@ # Change Log

<a name="4.0.0-0"></a>
# [4.0.0-0](https://github.com/conventional-changelog/standard-version/compare/v3.0.0...v4.0.0-0) (2016-11-26)
### Bug Fixes
* include merge commits in the changelog ([#139](https://github.com/conventional-changelog/standard-version/issues/139)) ([b6e1562](https://github.com/conventional-changelog/standard-version/commit/b6e1562))
* support a wording change made to git status in git v2.9.1 ([#140](https://github.com/conventional-changelog/standard-version/issues/140)) ([80004ec](https://github.com/conventional-changelog/standard-version/commit/80004ec))
### Features
* support releasing a custom version, including pre-releases ([#129](https://github.com/conventional-changelog/standard-version/issues/129)) ([068008d](https://github.com/conventional-changelog/standard-version/commit/068008d))
### BREAKING CHANGES
* merge commits are now included in the CHANGELOG.
<a name="3.0.0"></a>

@@ -12,3 +33,2 @@ # [3.0.0](https://github.com/conventional-changelog/standard-version/compare/v2.3.0...v3.0.0) (2016-10-06)

([f361c46](https://github.com/conventional-changelog/standard-version/commit/f361c46)), closes [#49](https://github.com/conventional-changelog/standard-version/issues/49)
* check the private field in package.json([#102](https://github.com/conventional-changelog/standard-version/issues/102)) ([#103](https://github.com/conventional-changelog/standard-version/issues/103)) ([2ce4160](https://github.com/conventional-changelog/standard-version/commit/2ce4160))

@@ -25,3 +45,2 @@ * **err:** don't fail on stderr output, but print the output to stderr ([#110](https://github.com/conventional-changelog/standard-version/issues/110)) ([f7a4915](https://github.com/conventional-changelog/standard-version/commit/f7a4915)), closes [#91](https://github.com/conventional-changelog/standard-version/issues/91)

([3e0aa84](https://github.com/conventional-changelog/standard-version/commit/3e0aa84))
* **options:** add --silent flag and option for squelching output ([2a3fa61](https://github.com/conventional-changelog/standard-version/commit/2a3fa61))

@@ -28,0 +47,0 @@ * added support for commitAll option in CLI ([#121](https://github.com/conventional-changelog/standard-version/issues/121)) ([a903f4d](https://github.com/conventional-changelog/standard-version/commit/a903f4d))

@@ -19,9 +19,7 @@ var conventionalRecommendedBump = require('conventional-recommended-bump')

argv = objectAssign(defaults, argv)
var args = objectAssign({}, defaults, argv)
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
bumpVersion(args.releaseAs, function (err, release) {
if (err) {
printError(argv, err.message)
printError(args, err.message)
return done(err)

@@ -31,20 +29,24 @@ }

var newVersion = pkg.version
if (!argv.firstRelease) {
newVersion = semver.inc(pkg.version, release.releaseType)
checkpoint(argv, 'bumping version in package.json from %s to %s', [pkg.version, newVersion])
if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
newVersion = semver.inc(pkg.version, releaseType, args.prerelease)
checkpoint(args, 'bumping version in package.json from %s to %s', [pkg.version, newVersion])
pkg.version = newVersion
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8')
} else {
checkpoint(argv, 'skip version bump on first release', [], chalk.red(figures.cross))
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}
outputChangelog(argv, function (err) {
outputChangelog(args, function (err) {
if (err) {
return done(err)
}
commit(argv, newVersion, function (err) {
commit(args, newVersion, function (err) {
if (err) {
return done(err)
}
return tag(newVersion, pkg.private, argv, done)
return tag(newVersion, pkg.private, args, done)
})

@@ -55,2 +57,81 @@ })

function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
if (isString(prerelease)) {
if (isInPrerelease(currentVersion)) {
if (shouldContinuePrerelease(currentVersion, expectedReleaseType) ||
getTypePriority(getCurrentActiveType(currentVersion)) > getTypePriority(expectedReleaseType)
) {
return 'prerelease'
}
}
return 'pre' + expectedReleaseType
} else {
return expectedReleaseType
}
}
function isString (val) {
return typeof val === 'string'
}
/**
* if a version is currently in pre-release state,
* and if it current in-pre-release type is same as expect type,
* it should continue the pre-release with the same type
*
* @param version
* @param expectType
* @return {boolean}
*/
function shouldContinuePrerelease (version, expectType) {
return getCurrentActiveType(version) === expectType
}
function isInPrerelease (version) {
return Array.isArray(semver.prerelease(version))
}
var TypeList = ['major', 'minor', 'patch'].reverse()
/**
* extract the in-pre-release type in target version
*
* @param version
* @return {string}
*/
function getCurrentActiveType (version) {
var typelist = TypeList
for (var i = 0; i < typelist.length; i++) {
if (semver[typelist[i]](version)) {
return typelist[i]
}
}
}
/**
* calculate the priority of release type,
* major - 2, minor - 1, patch - 0
*
* @param type
* @return {number}
*/
function getTypePriority (type) {
return TypeList.indexOf(type)
}
function bumpVersion (releaseAs, callback) {
if (releaseAs) {
callback(null, {
releaseType: releaseAs
})
} else {
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
callback(err, release)
})
}
}
function outputChangelog (argv, cb) {

@@ -67,3 +148,3 @@ createIfMissing(argv)

preset: 'angular'
})
}, undefined, {merges: null})
.on('error', function (err) {

@@ -70,0 +151,0 @@ return cb(err)

11

package.json
{
"name": "standard-version",
"version": "3.0.0",
"version": "4.0.0-0",
"description": "replacement for `npm version` with automatic CHANGELOG generation",
"bin": "cli.js",
"bin": "bin/cli.js",
"scripts": {

@@ -10,3 +10,3 @@ "pretest": "standard",

"test": "nyc mocha --timeout=20000 test.js",
"release": "./cli.js"
"release": "bin/cli.js"
},

@@ -47,2 +47,3 @@ "repository": {

"devDependencies": {
"bluebird": "^3.4.6",
"chai": "^3.5.0",

@@ -52,4 +53,4 @@ "coveralls": "^2.11.9",

"mock-git": "^1.0.2",
"mockery": "^1.7.0",
"nyc": "^8.1.0",
"mockery": "^2.0.0",
"nyc": "^10.0.0",
"shelljs": "^0.7.3",

@@ -56,0 +57,0 @@ "standard": "^8.0.0"

@@ -99,2 +99,41 @@ # Standard Version

### Release as a pre-release
Use the flag `--prerelease` to generate pre-releases:
Suppose the last version of your code is `1.0.0`, and your code to be committed has patched changes. Run:
```bash
# npm run script
npm run release -- --prerelease
```
you will get version `1.0.1-0`.
If you want to name the pre-release, you specify the name via `--prerelease <name>`.
For example, suppose your pre-release should contain the `alpha` prefix:
```bash
# npm run script
npm run release -- --prerelease alpha
```
this will tag the version `1.0.1-alpha.0`
### Release as a target type imperatively like `npm version`
To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`:
Suppose the last version of your code is `1.0.0`, you've only landed `fix:` commits, but
you would like your next release to be a `minor`. Simply do:
```bash
# npm run script
npm run release -- --release-as minor
```
you will get version `1.1.0` rather than the auto generated version `1.0.1`.
> **NOTE:** you can combine `--release-as` and `--prerelease` to generate a release. This is useful when publishing experimental feature(s).
### Prevent Git Hooks

@@ -115,2 +154,11 @@

### Committing generated artifacts in the release commit
If you want to commit generated artifacts in the release commit (e.g. [#96](https://github.com/conventional-changelog/standard-version/issues/96)), you can use the `--commit-all` or `-a` flag. You will need to stage the artifacts you want to commit, so your `release` command could look like this:
```json
"prerelease": "webpack -p --bail",
"release": "git add <file(s) to commit> && standard-version -a"
```
### CLI Help

@@ -117,0 +165,0 @@

@@ -5,3 +5,3 @@ /* global describe it beforeEach afterEach */

var extend = Object.assign || require('util')._extend
var objectAssign = require('object-assign')
var shell = require('shelljs')

@@ -13,7 +13,19 @@ var fs = require('fs')

var mockery = require('mockery')
var semver = require('semver')
var Promise = require('bluebird')
var cli = require('./command')
var standardVersion = require('./index')
var should = require('chai').should()
var cliPath = path.resolve(__dirname, './cli.js')
var cliPath = path.resolve(__dirname, './bin/cli.js')
function branch (branch) {
shell.exec('git branch ' + branch)
}
function checkout (branch) {
shell.exec('git checkout ' + branch)
}
function commit (msg) {

@@ -23,2 +35,6 @@ shell.exec('git commit --allow-empty -m"' + msg + '"')

function merge (msg, branch) {
shell.exec('git merge --no-ff -m"' + msg + '" ' + branch)
}
function execCli (argString) {

@@ -28,6 +44,11 @@ return shell.exec('node ' + cliPath + (argString != null ? ' ' + argString : ''))

function execCliAsync (argString) {
return Promise.promisify(standardVersion)(cli.parse('standard-version ' + argString + ' --silent'))
}
function writePackageJson (version, option) {
option = option || {}
var pkg = extend(option, {version: version})
var pkg = objectAssign(option, {version: version})
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
delete require.cache[require.resolve(path.join(process.cwd(), 'package.json'))]
}

@@ -55,2 +76,6 @@

function getPackageVersion () {
return JSON.parse(fs.readFileSync('package.json', 'utf-8')).version
}
describe('cli', function () {

@@ -115,5 +140,5 @@ beforeEach(initInTempFolder)

var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
var status = shell.exec('git status')
var status = shell.exec('git status --porcelain') // see http://unix.stackexchange.com/questions/155046/determine-if-git-working-directory-is-clean-from-a-script
status.should.match(/On branch master\nnothing to commit, working directory clean\n/)
status.should.equal('')
status.should.not.match(/STUFF.md/)

@@ -194,2 +219,122 @@

describe('pre-release', function () {
it('works fine without specifying a tag id when prereleasing', function () {
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
return execCliAsync('--prerelease')
.then(function () {
// it's a feature commit, so it's minor type
getPackageVersion().should.equal('1.1.0-0')
})
})
})
describe('manual-release', function () {
it('throws error when not specifying a release type', function () {
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('fix: first commit')
execCli('--release-as').code.should.above(0)
})
describe('release-types', function () {
var regularTypes = ['major', 'minor', 'patch']
regularTypes.forEach(function (type) {
it('creates a ' + type + ' release', function () {
var originVer = '1.0.0'
writePackageJson(originVer)
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('fix: first commit')
return execCliAsync('--release-as ' + type)
.then(function () {
var version = {
major: semver.major(originVer),
minor: semver.minor(originVer),
patch: semver.patch(originVer)
}
version[type] += 1
getPackageVersion().should.equal(version.major + '.' + version.minor + '.' + version.patch)
})
})
})
// this is for pre-releases
regularTypes.forEach(function (type) {
it('creates a pre' + type + ' release', function () {
var originVer = '1.0.0'
writePackageJson(originVer)
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('fix: first commit')
return execCliAsync('--release-as ' + type + ' --prerelease ' + type)
.then(function () {
var version = {
major: semver.major(originVer),
minor: semver.minor(originVer),
patch: semver.patch(originVer)
}
version[type] += 1
getPackageVersion().should.equal(version.major + '.' + version.minor + '.' + version.patch + '-' + type + '.0')
})
})
})
})
it('creates a prerelease with a new minor version after two prerelease patches', function () {
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('fix: first patch')
return execCliAsync('--release-as patch --prerelease dev')
.then(function () {
getPackageVersion().should.equal('1.0.1-dev.0')
})
// second
.then(function () {
commit('fix: second patch')
return execCliAsync('--prerelease dev')
})
.then(function () {
getPackageVersion().should.equal('1.0.1-dev.1')
})
// third
.then(function () {
commit('feat: first new feat')
return execCliAsync('--release-as minor --prerelease dev')
})
.then(function () {
getPackageVersion().should.equal('1.1.0-dev.0')
})
.then(function () {
commit('fix: third patch')
return execCliAsync('--release-as minor --prerelease dev')
})
.then(function () {
getPackageVersion().should.equal('1.1.0-dev.1')
})
.then(function () {
commit('fix: forth patch')
return execCliAsync('--prerelease dev')
})
.then(function () {
getPackageVersion().should.equal('1.1.0-dev.2')
})
})
})
it('handles commit messages longer than 80 characters', function () {

@@ -249,2 +394,21 @@ commit('feat: first commit')

})
it('includes merge commits', function () {
var branchName = 'new-feature'
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
branch(branchName)
checkout(branchName)
commit('Implementing new feature')
checkout('master')
merge('feat: new feature from branch', branchName)
execCli().code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/new feature from branch/)
var pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal(['{', ' "version": "1.1.0"', '}', ''].join('\n'))
})
})

@@ -251,0 +415,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc