Socket
Socket
Sign inDemoInstall

standard-version

Package Overview
Dependencies
Maintainers
2
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 2.4.0 to 3.0.0

.editorconfig

31

CHANGELOG.md

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

<a name="3.0.0"></a>
# [3.0.0](https://github.com/conventional-changelog/standard-version/compare/v2.3.0...v3.0.0) (2016-10-06)
### Bug Fixes
([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))
* **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)
### Chores
* package.json engines field >=4.0, drop Node 0.10 and 0.12 ([28ff65a](https://github.com/conventional-changelog/standard-version/commit/28ff65a))
### Features
([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))
* 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))
* separate cli and defaults from base functionality ([34a6a4e](https://github.com/conventional-changelog/standard-version/commit/34a6a4e))
### BREAKING CHANGES
* drop support for Node < 4.0 to enable usage of
new tools and packages.
<a name="2.4.0"></a>

@@ -7,0 +38,0 @@ # [2.4.0](https://github.com/conventional-changelog/standard-version/compare/v2.3.1...v2.4.0) (2016-07-13)

190

index.js

@@ -1,47 +0,4 @@

#!/usr/bin/env node
var conventionalRecommendedBump = require('conventional-recommended-bump')
var conventionalChangelog = require('conventional-changelog')
var path = require('path')
var argv = require('yargs')
.usage('Usage: $0 [options]')
.option('infile', {
alias: 'i',
describe: 'Read the CHANGELOG from this file',
default: 'CHANGELOG.md',
global: true
})
.option('message', {
alias: 'm',
describe: 'Commit message, replaces %s with new version',
type: 'string',
default: 'chore(release): %s',
global: true
})
.option('first-release', {
alias: 'f',
describe: 'Is this the first release?',
type: 'boolean',
default: false,
global: true
})
.option('sign', {
alias: 's',
describe: 'Should the git commit and tag be signed?',
type: 'boolean',
default: false,
global: true
})
.option('no-verify', {
alias: 'n',
describe: 'Bypass pre-commit or commit-msg git hooks during the commit phase',
type: 'boolean',
default: false,
global: true
})
.help()
.alias('help', 'h')
.example('$0', 'Update changelog and tag release')
.example('$0 -m "%s: see changelog for details"', 'Update changelog and tag release with custom commit message')
.wrap(97)
.argv

@@ -53,31 +10,44 @@ var chalk = require('chalk')

var accessSync = require('fs-access').sync
var pkgPath = path.resolve(process.cwd(), './package.json')
var pkg = require(pkgPath)
var semver = require('semver')
var util = require('util')
var objectAssign = require('object-assign')
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
if (err) {
console.error(chalk.red(err.message))
return
}
module.exports = function standardVersion (argv, done) {
var pkgPath = path.resolve(process.cwd(), './package.json')
var pkg = require(pkgPath)
var defaults = require('./defaults')
var newVersion = pkg.version
if (!argv.firstRelease) {
newVersion = semver.inc(pkg.version, release.releaseAs)
checkpoint('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('skip version bump on first release', [], chalk.red(figures.cross))
}
argv = objectAssign(defaults, argv)
outputChangelog(argv, function () {
commit(argv, newVersion, function () {
return tag(newVersion, argv)
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
if (err) {
printError(argv, err.message)
return done(err)
}
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])
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))
}
outputChangelog(argv, function (err) {
if (err) {
return done(err)
}
commit(argv, newVersion, function (err) {
if (err) {
return done(err)
}
return tag(newVersion, pkg.private, argv, done)
})
})
})
})
}

@@ -96,6 +66,5 @@ function outputChangelog (argv, cb) {

})
.on('error', function (err) {
console.error(chalk.red(err.message))
process.exit(1)
})
.on('error', function (err) {
return cb(err)
})

@@ -107,3 +76,3 @@ changelogStream.on('data', function (buffer) {

changelogStream.on('end', function () {
checkpoint('outputting changes to %s', [argv.infile])
checkpoint(argv, 'outputting changes to %s', [argv.infile])
fs.writeFileSync(argv.infile, header + '\n' + (content + oldContent).replace(/\n+$/, '\n'), 'utf-8')

@@ -114,2 +83,18 @@ return cb()

function handledExec (argv, cmd, errorCb, successCb) {
// Exec given cmd and handle possible errors
exec(cmd, function (err, stdout, stderr) {
// If exec returns content in stderr, but no error, print it as a warning
// If exec returns an error, print it and exit with return code 1
if (err) {
printError(argv, stderr || err.message)
return errorCb(err)
} else if (stderr) {
printError(argv, stderr, {level: 'warn', color: 'yellow'})
}
successCb()
})
}
function commit (argv, newVersion, cb) {

@@ -123,17 +108,7 @@ var msg = 'committing %s'

}
checkpoint(msg, args)
checkpoint(argv, msg, args)
function handleExecError (err, stderr) {
// If exec returns an error or content in stderr, log it and exit with return code 1
var errMessage = stderr || (err && err.message)
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
}
}
exec('git add package.json ' + argv.infile, function (err, stdout, stderr) {
handleExecError(err, stderr)
exec('git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
handleExecError(err, stderr)
return cb()
handledExec(argv, 'git add package.json ' + argv.infile, cb, function () {
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : ('package.json ' + argv.infile)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
cb()
})

@@ -147,3 +122,3 @@ })

function tag (newVersion, argv) {
function tag (newVersion, pkgPrivate, argv, cb) {
var tagOption

@@ -155,15 +130,9 @@ if (argv.sign) {

}
checkpoint('tagging release %s', [newVersion])
exec('git tag ' + tagOption + 'v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
} else {
checkpoint('Run `%s` to publish', [
'git push --follow-tags origin master; npm publish'
], chalk.blue(figures.info))
}
checkpoint(argv, 'tagging release %s', [newVersion])
handledExec(argv, 'git tag ' + tagOption + 'v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
var message = 'git push --follow-tags origin master'
if (pkgPrivate !== true) message += '; npm publish'
checkpoint(argv, 'Run `%s` to publish', [message], chalk.blue(figures.info))
cb()
})

@@ -177,3 +146,3 @@ }

if (err.code === 'ENOENT') {
checkpoint('created %s', [argv.infile])
checkpoint(argv, 'created %s', [argv.infile])
argv.outputUnreleased = true

@@ -185,6 +154,19 @@ fs.writeFileSync(argv.infile, '\n', 'utf-8')

function checkpoint (msg, args, figure) {
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
return chalk.bold(arg)
}))))
};
function checkpoint (argv, msg, args, figure) {
if (!argv.silent) {
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
return chalk.bold(arg)
}))))
}
}
function printError (argv, msg, opts) {
if (!argv.silent) {
opts = objectAssign({
level: 'error',
color: 'red'
}, opts)
console[opts.level](chalk[opts.color](msg))
}
}
{
"name": "standard-version",
"version": "2.4.0",
"version": "3.0.0",
"description": "replacement for `npm version` with automatic CHANGELOG generation",
"bin": "index.js",
"bin": "cli.js",
"scripts": {
"pretest": "standard",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test": "nyc mocha --timeout=20000 test.js"
"test": "nyc mocha --timeout=20000 test.js",
"release": "./cli.js"
},

@@ -15,2 +16,5 @@ "repository": {

},
"engines": {
"node": ">=4.0"
},
"keywords": [

@@ -35,7 +39,8 @@ "conventional-changelog",

"conventional-changelog": "^1.1.0",
"conventional-recommended-bump": "^0.2.1",
"conventional-recommended-bump": "^0.3.0",
"figures": "^1.5.0",
"fs-access": "^1.0.0",
"object-assign": "^4.1.0",
"semver": "^5.1.0",
"yargs": "^4.6.0"
"yargs": "^6.0.0"
},

@@ -45,8 +50,9 @@ "devDependencies": {

"coveralls": "^2.11.9",
"mocha": "^2.5.1",
"mocha": "^3.1.0",
"mock-git": "^1.0.2",
"nyc": "^7.0.0",
"shelljs": "^0.7.0",
"standard": "^7.0.1"
"mockery": "^1.7.0",
"nyc": "^8.1.0",
"shelljs": "^0.7.3",
"standard": "^8.0.0"
}
}
# Standard Version
[![Build Status](https://travis-ci.org/conventional-changelog/standard-version.svg)](https://travis-ci.org/conventional-changelog/standard-version)
[![Join the chat at https://gitter.im/conventional-changelog/standard-version](https://badges.gitter.im/conventional-changelog/standard-version.svg)](https://gitter.im/conventional-changelog/standard-version?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/conventional-changelog/standard-version.svg?branch=master)](https://travis-ci.org/conventional-changelog/standard-version)
[![NPM version](https://img.shields.io/npm/v/standard-version.svg)](https://www.npmjs.com/package/standard-version)

@@ -65,3 +67,3 @@ [![Coverage Status](https://coveralls.io/repos/conventional-changelog/standard-version/badge.svg?branch=)](https://coveralls.io/r/conventional-changelog/standard-version?branch=master)

## Usage
## CLI Usage

@@ -109,2 +111,6 @@ ### First Release

### Signing commits and tags
If you have your GPG key set up, add the `--sign` or `-s` flag to your `standard-version` command.
### CLI Help

@@ -119,2 +125,23 @@

## Code usage
Use the `silent` option to stop `standard-version` from printing anything
to the console.
```js
var standardVersion = require('standard-version')
// Options are the same as command line, except camelCase
standardVersion({
noVerify: true,
infile: 'docs/CHANGELOG.md',
silent: true
}, function (err) {
if (err) {
console.error(`standard-version failed with message: ${err.message}`)
}
// standard-version is done
})
```
## Commit Message Convention, at a Glance

@@ -121,0 +148,0 @@

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

var extend = Object.assign || require('util')._extend
var shell = require('shelljs')
var fs = require('fs')
var path = require('path')
var stream = require('stream')
var mockGit = require('mock-git')
var cliPath = path.resolve(__dirname, './index.js')
var mockery = require('mockery')
require('chai').should()
var should = require('chai').should()
var cliPath = path.resolve(__dirname, './cli.js')
function commit (msg) {

@@ -22,6 +26,6 @@ shell.exec('git commit --allow-empty -m"' + msg + '"')

function writePackageJson (version) {
fs.writeFileSync('package.json', JSON.stringify({
version: version
}), 'utf-8')
function writePackageJson (version, option) {
option = option || {}
var pkg = extend(option, {version: version})
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
}

@@ -34,21 +38,23 @@

function initInTempFolder () {
shell.rm('-rf', 'tmp')
shell.config.silent = true
shell.mkdir('tmp')
shell.cd('tmp')
shell.exec('git init')
commit('root-commit')
writePackageJson('1.0.0')
}
function finishTemp () {
shell.cd('../')
shell.rm('-rf', 'tmp')
}
describe('cli', function () {
beforeEach(function () {
shell.rm('-rf', 'tmp')
shell.config.silent = true
shell.mkdir('tmp')
shell.cd('tmp')
shell.exec('git init')
commit('root-commit')
})
beforeEach(initInTempFolder)
afterEach(finishTemp)
afterEach(function () {
shell.cd('../')
shell.rm('-rf', 'tmp')
})
describe('CHANGELOG.md does not exist', function () {
it('populates changelog with commits since last tag by default', function () {
writePackageJson('1.0.0')
commit('feat: first commit')

@@ -81,3 +87,2 @@ shell.exec('git tag -a v1.0.0 -m "my awesome first release"')

it('appends the new release above the last release, removing the old header', function () {
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')

@@ -94,2 +99,25 @@

})
it('commits all staged files', function () {
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('fix: patch release')
fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8')
shell.exec('git add STUFF.md')
execCli('--commit-all').code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
var status = shell.exec('git status')
status.should.match(/On branch master\nnothing to commit, working directory clean\n/)
status.should.not.match(/STUFF.md/)
content.should.match(/1\.0\.1/)
content.should.not.match(/legacy header format/)
})
})

@@ -102,4 +130,2 @@

.then(function (unmock) {
writePackageJson('1.0.0')
execCli('--sign').code.should.equal(0)

@@ -121,7 +147,5 @@

.then(function (unmock) {
writePackageJson('1.0.0')
var result = execCli()
result.code.should.equal(1)
result.stdout.should.match(/commit yourself/)
result.stderr.should.match(/commit yourself/)

@@ -136,7 +160,5 @@ unmock()

.then(function (unmock) {
writePackageJson('1.0.0')
var result = execCli()
result.code.should.equal(1)
result.stdout.should.match(/addition is hard/)
result.stderr.should.match(/addition is hard/)

@@ -151,7 +173,19 @@ unmock()

.then(function (unmock) {
var result = execCli()
result.code.should.equal(1)
result.stderr.should.match(/tag, you're it/)
unmock()
})
})
it('doesn\'t fail fast on stderr output from git', function () {
// mock git by throwing on attempt to commit
return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add')
.then(function (unmock) {
writePackageJson('1.0.0')
var result = execCli()
result.code.should.equal(1)
result.stdout.should.match(/tag, you're it/)
result.code.should.equal(0)
result.stderr.should.match(/haha, kidding, this is just a warning/)

@@ -164,4 +198,2 @@ unmock()

it('handles commit messages longer than 80 characters', function () {
writePackageJson('1.0.0')
commit('feat: first commit')

@@ -178,4 +210,2 @@ shell.exec('git tag -a v1.0.0 -m "my awesome first release"')

it('formats the commit and tag messages appropriately', function () {
writePackageJson('1.0.0')
commit('feat: first commit')

@@ -194,4 +224,2 @@ shell.exec('git tag -a v1.0.0 -m "my awesome first release"')

it('appends line feed at end of package.json', function () {
writePackageJson('1.0.0')
execCli().code.should.equal(0)

@@ -204,3 +232,2 @@

it('does not run git hooks if the --no-verify flag is passed', function () {
writePackageJson('1.0.0')
writeGitPreCommitHook()

@@ -213,2 +240,94 @@

})
it('does not print output when the --silent flag is passed', function () {
var result = execCli('--silent')
result.code.should.equal(0)
result.stdout.should.equal('')
result.stderr.should.equal('')
})
it('does not display `npm publish` if the package is private', function () {
writePackageJson('1.0.0', {private: true})
var result = execCli()
result.code.should.equal(0)
result.stdout.should.not.match(/npm publish/)
})
})
describe('standard-version', function () {
beforeEach(initInTempFolder)
afterEach(finishTemp)
describe('with mocked conventionalRecommendedBump', function () {
beforeEach(function () {
mockery.enable({warnOnUnregistered: false, useCleanCache: true})
mockery.registerMock('conventional-recommended-bump', function (_, cb) {
cb(new Error('bump err'))
})
})
afterEach(function () {
mockery.deregisterMock('conventional-recommended-bump')
mockery.disable()
})
it('should exit on bump error', function (done) {
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
require('./index')({silent: true}, function (err) {
should.exist(err)
err.message.should.match(/bump err/)
done()
})
})
})
describe('with mocked conventionalChangelog', function () {
beforeEach(function () {
mockery.enable({warnOnUnregistered: false, useCleanCache: true})
mockery.registerMock('conventional-changelog', function () {
var readable = new stream.Readable({objectMode: true})
readable._read = function () {
}
setImmediate(readable.emit.bind(readable), 'error', new Error('changelog err'))
return readable
})
})
afterEach(function () {
mockery.deregisterMock('conventional-changelog')
mockery.disable()
})
it('should exit on changelog error', function (done) {
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
require('./index')({silent: true}, function (err) {
should.exist(err)
err.message.should.match(/changelog err/)
done()
})
})
})
it('formats the commit and tag messages appropriately', function (done) {
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
require('./index')({silent: true}, function (err) {
should.not.exist(err)
// check last commit message
shell.exec('git log --oneline -n1').stdout.should.match(/chore\(release\): 1\.1\.0/)
// check annotated tag message
shell.exec('git tag -l -n1 v1.1.0').stdout.should.match(/chore\(release\): 1\.1\.0/)
done()
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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