Socket
Socket
Sign inDemoInstall

standard-version

Package Overview
Dependencies
168
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.1.0-candidate.0

lib/checkpoint.js

14

bin/cli.js

@@ -5,6 +5,10 @@ #!/usr/bin/env node

standardVersion(cmdParser.argv, function (err) {
if (err) {
process.exit(1)
}
})
/* istanbul ignore if */
if (process.version.match(/v(\d+)\./)[1] < 4) {
console.error('standard-version: Node v4 or greater is required. `standard-version` did not run.')
} else {
standardVersion(cmdParser.argv)
.catch(() => {
process.exit(1)
})
}

@@ -10,3 +10,2 @@ var defaults = require('./defaults')

string: true,
choices: ['major', 'minor', 'patch'],
global: true

@@ -74,2 +73,13 @@ })

})
.option('scripts', {
describe: 'Scripts to execute for lifecycle events (prebump, precommit, etc.,)',
default: {}
})
.check((argv) => {
if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
throw Error('hooks must be an object')
} else {
return true
}
})
.version()

@@ -81,2 +91,3 @@ .alias('version', 'v')

.example('$0 -m "%s: see changelog for details"', 'Update changelog and tag release with custom commit message')
.pkgConf('standard-version')
.wrap(97)

@@ -1,48 +0,58 @@

var conventionalRecommendedBump = require('conventional-recommended-bump')
var conventionalChangelog = require('conventional-changelog')
var path = require('path')
const conventionalRecommendedBump = require('conventional-recommended-bump')
const conventionalChangelog = require('conventional-changelog')
const path = require('path')
var chalk = require('chalk')
var figures = require('figures')
var exec = require('child_process').exec
var fs = require('fs')
var accessSync = require('fs-access').sync
var semver = require('semver')
var util = require('util')
var objectAssign = require('object-assign')
const chalk = require('chalk')
const figures = require('figures')
const fs = require('fs')
const accessSync = require('fs-access').sync
const semver = require('semver')
const util = require('util')
module.exports = function standardVersion (argv, done) {
const checkpoint = require('./lib/checkpoint')
const printError = require('./lib/print-error')
const runExec = require('./lib/run-exec')
const runLifecycleScript = require('./lib/run-lifecycle-script')
module.exports = function standardVersion (argv) {
var pkgPath = path.resolve(process.cwd(), './package.json')
var pkg = require(pkgPath)
var newVersion = pkg.version
var scripts = argv.scripts || {}
var defaults = require('./defaults')
var args = objectAssign({}, defaults, argv)
var args = Object.assign({}, defaults, argv)
bumpVersion(args.releaseAs, function (err, release) {
if (err) {
printError(args, err.message)
return done(err)
}
return runLifecycleScript(args, 'prebump', null, scripts)
.then((stdout) => {
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
return bumpVersion(args.releaseAs)
})
.then((release) => {
if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
newVersion = semver.valid(releaseType) || semver.inc(pkg.version, releaseType, args.prerelease)
updateConfigs(args, newVersion)
} else {
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}
var newVersion = pkg.version
if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
newVersion = semver.inc(pkg.version, releaseType, args.prerelease)
updateConfigs(args, newVersion)
} else {
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}
outputChangelog(args, function (err) {
if (err) {
return done(err)
}
commit(args, newVersion, function (err) {
if (err) {
return done(err)
}
return tag(newVersion, pkg.private, args, done)
})
return runLifecycleScript(args, 'postbump', newVersion, scripts)
})
})
.then(() => {
return outputChangelog(args)
})
.then(() => {
return runLifecycleScript(args, 'precommit', newVersion, scripts)
})
.then((message) => {
if (message && message.length) args.message = message
return commit(args, newVersion)
})
.then(() => {
return tag(newVersion, pkg.private, args)
})
.catch((err) => {
printError(args, err.message)
throw err
})
}

@@ -61,2 +71,3 @@

configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false

@@ -148,58 +159,48 @@ Object.keys(configsToUpdate).forEach(function (configPath) {

function bumpVersion (releaseAs, callback) {
if (releaseAs) {
callback(null, {
releaseType: releaseAs
})
} else {
conventionalRecommendedBump({
return new Promise((resolve, reject) => {
if (releaseAs) {
return resolve({
releaseType: releaseAs
})
} else {
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
if (err) return reject(err)
else return resolve(release)
})
}
})
}
function outputChangelog (argv) {
return new Promise((resolve, reject) => {
createIfMissing(argv)
var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
var oldContent = fs.readFileSync(argv.infile, 'utf-8')
// find the position of the last release and remove header:
if (oldContent.indexOf('<a name=') !== -1) {
oldContent = oldContent.substring(oldContent.indexOf('<a name='))
}
var content = ''
var changelogStream = conventionalChangelog({
preset: 'angular'
}, function (err, release) {
callback(err, release)
}, undefined, {merges: null})
.on('error', function (err) {
return reject(err)
})
changelogStream.on('data', function (buffer) {
content += buffer.toString()
})
}
}
function outputChangelog (argv, cb) {
createIfMissing(argv)
var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
var oldContent = fs.readFileSync(argv.infile, 'utf-8')
// find the position of the last release and remove header:
if (oldContent.indexOf('<a name=') !== -1) {
oldContent = oldContent.substring(oldContent.indexOf('<a name='))
}
var content = ''
var changelogStream = conventionalChangelog({
preset: 'angular'
}, undefined, {merges: null})
.on('error', function (err) {
return cb(err)
changelogStream.on('end', function () {
checkpoint(argv, 'outputting changes to %s', [argv.infile])
fs.writeFileSync(argv.infile, header + '\n' + (content + oldContent).replace(/\n+$/, '\n'), 'utf-8')
return resolve()
})
changelogStream.on('data', function (buffer) {
content += buffer.toString()
})
changelogStream.on('end', function () {
checkpoint(argv, 'outputting changes to %s', [argv.infile])
fs.writeFileSync(argv.infile, header + '\n' + (content + oldContent).replace(/\n+$/, '\n'), 'utf-8')
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) {
function commit (argv, newVersion) {
var msg = 'committing %s'

@@ -219,7 +220,6 @@ var args = [argv.infile]

checkpoint(argv, msg, args)
handledExec(argv, 'git add' + toAdd + ' ' + argv.infile, cb, function () {
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : (argv.infile + toAdd)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
cb()
return runExec(argv, 'git add' + toAdd + ' ' + argv.infile)
.then(() => {
return runExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : (argv.infile + toAdd)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"')
})
})
}

@@ -231,3 +231,3 @@

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

@@ -240,9 +240,9 @@ if (argv.sign) {

checkpoint(argv, 'tagging release %s', [newVersion])
handledExec(argv, 'git tag ' + tagOption + argv.tagPrefix + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
var message = 'git push --follow-tags origin master'
if (pkgPrivate !== true) message += '; npm publish'
return runExec(argv, 'git tag ' + tagOption + argv.tagPrefix + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"')
.then(() => {
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()
})
checkpoint(argv, 'Run `%s` to publish', [message], chalk.blue(figures.info))
})
}

@@ -261,20 +261,1 @@

}
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": "4.0.0",
"version": "4.1.0-candidate.0",
"description": "replacement for `npm version` with automatic CHANGELOG generation",

@@ -12,2 +12,5 @@ "bin": "bin/cli.js",

},
"nyc": {
"exclude": ["tmp/**"]
},
"repository": {

@@ -39,11 +42,9 @@ "type": "git",

"conventional-changelog": "^1.1.0",
"conventional-recommended-bump": "^0.3.0",
"conventional-recommended-bump": "^1.0.0",
"figures": "^1.5.0",
"fs-access": "^1.0.0",
"object-assign": "^4.1.0",
"semver": "^5.1.0",
"yargs": "^6.0.0"
"yargs": "^8.0.1"
},
"devDependencies": {
"bluebird": "^3.4.6",
"chai": "^3.5.0",

@@ -54,6 +55,6 @@ "coveralls": "^2.11.9",

"mockery": "^2.0.0",
"nyc": "^10.0.0",
"nyc": "^11.0.2",
"shelljs": "^0.7.3",
"standard": "^8.0.0"
"standard": "^10.0.0"
}
}

@@ -8,8 +8,8 @@ # Standard Version

[![Coverage Status](https://coveralls.io/repos/conventional-changelog/standard-version/badge.svg?branch=)](https://coveralls.io/r/conventional-changelog/standard-version?branch=master)
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
> stop using `npm version`, use `standard-version` it rocks!
Automatic versioning and CHANGELOG management, using GitHub's new squash button and
the [recommended workflow](https://github.com/conventional-changelog/conventional-changelog-cli#recommended-workflow) for `conventional-changelog`.
Automatic versioning and CHANGELOG generation, using GitHub's squash button and
[conventional commit messages](https://conventionalcommits.org).

@@ -19,3 +19,3 @@ _how it works:_

1. when you land commits on your `master` branch, select the _Squash and Merge_ option.
2. add a title and body that follows the [conventional-changelog-standard conventions](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md).
2. add a title and body that follows the [Conventional Commits Specification](https://conventionalcommits.org).
3. when you're ready to release to npm:

@@ -134,2 +134,4 @@ 1. `git checkout master; git pull origin master`

npm run release -- --release-as minor
# Or
npm run release -- --release-as 1.1.0
```

@@ -156,2 +158,29 @@

### Lifecycle scripts
`standard-version` supports lifecycle scripts. These allow you to execute your
own supplementary commands during the release. The following
hooks are available:
* `prebump`: executed before the version bump is calculated. If the `prebump`
script returns a version #, it will be used rather than
the version calculated by `standard-version`.
* `postbump`: executed after the version has been bumped and written to
package.json. The flag `--new-version` is populated with the version that is
being released.
* `precommit`: called after CHANGELOG.md and package.json have been updated,
but before changes have been committed to git.
Simply add the following to your package.json, to enable lifecycle scripts:
```json
{
"standard-version": {
"scripts": {
"prebump": "echo 9.9.9"
}
}
}
```
### Committing generated artifacts in the release commit

@@ -232,6 +261,6 @@

Tell your users that you adhere to the `standard-version` commit guidelines:
Tell your users that you adhere to the Conventional Commits specification:
```markdown
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
```

@@ -238,0 +267,0 @@

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

var objectAssign = require('object-assign')
var shell = require('shelljs')

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

var semver = require('semver')
var Promise = require('bluebird')
var cli = require('./command')
var standardVersion = require('./index')
var should = require('chai').should()
require('chai').should()

@@ -44,3 +42,3 @@ var cliPath = path.resolve(__dirname, './bin/cli.js')

function execCliAsync (argString) {
return Promise.promisify(standardVersion)(cli.parse('standard-version ' + argString + ' --silent'))
return standardVersion(cli.parse('standard-version ' + argString + ' --silent'))
}

@@ -50,3 +48,3 @@

option = option || {}
var pkg = objectAssign(option, {version: version})
var pkg = Object.assign(option, {version: version})
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')

@@ -58,6 +56,12 @@ delete require.cache[require.resolve(path.join(process.cwd(), 'package.json'))]

option = option || {}
var bower = objectAssign(option, { version: version })
var bower = Object.assign(option, {version: version})
fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8')
}
function writeNpmShrinkwrapJson (version, option) {
option = option || {}
var shrinkwrap = Object.assign(option, { version: version })
fs.writeFileSync('npm-shrinkwrap.json', JSON.stringify(shrinkwrap), 'utf-8')
}
function writeGitPreCommitHook () {

@@ -68,2 +72,14 @@ fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')

function writePostBumpHook (causeError) {
writeHook('postbump', causeError)
}
function writeHook (hookName, causeError, script) {
shell.mkdir('-p', 'scripts')
var content = script || 'console.error("' + hookName + ' ran")'
content += causeError ? '\nthrow new Error("' + hookName + '-failure")' : ''
fs.writeFileSync('scripts/' + hookName + '.js', content, 'utf-8')
fs.chmodSync('scripts/' + hookName + '.js', '755')
}
function initInTempFolder () {

@@ -225,2 +241,112 @@ shell.rm('-rf', 'tmp')

describe('lifecycle scripts', () => {
describe('prebump hook', function () {
it('should allow prebump hook to return an alternate version #', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'prebump': 'node scripts/prebump'
}
}
})
writeHook('prebump', false, 'console.log("9.9.9")')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.stdout.should.match(/9\.9\.9/)
result.code.should.equal(0)
})
})
describe('postbump hook', function () {
it('should run the postbump hook when provided', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'postbump': 'node scripts/postbump'
}
}
})
writePostBumpHook()
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.code.should.equal(0)
result.stderr.should.match(/postbump ran/)
})
it('should run the postbump and exit with error when postbump fails', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'postbump': 'node scripts/postbump'
}
}
})
writePostBumpHook(true)
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.code.should.equal(1)
result.stderr.should.match(/postbump-failure/)
})
})
describe('precommit hook', function () {
it('should run the precommit hook when provided', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'precommit': 'node scripts/precommit'
}
}
})
writeHook('precommit')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.code.should.equal(0)
result.stderr.should.match(/precommit ran/)
})
it('should run the precommit hook and exit with error when precommit fails', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'precommit': 'node scripts/precommit'
}
}
})
writeHook('precommit', true)
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.code.should.equal(1)
result.stderr.should.match(/precommit-failure/)
})
it('should allow an alternate commit message to be provided by precommit script', function () {
writePackageJson('1.0.0', {
'standard-version': {
'scripts': {
'precommit': 'node scripts/precommit'
}
}
})
writeHook('precommit', false, 'console.log("releasing %s delivers #222")')
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
commit('feat: first commit')
var result = execCli('--patch')
result.code.should.equal(0)
shell.exec('git log --oneline -n1').should.match(/delivers #222/)
})
})
})
describe('pre-release', function () {

@@ -300,2 +426,30 @@ it('works fine without specifying a tag id when prereleasing', function () {

describe('release-as-exact', function () {
it('releases as v100.0.0', 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 v100.0.0')
.then(function () {
getPackageVersion().should.equal('100.0.0')
})
})
it('releases as 200.0.0-amazing', 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 200.0.0-amazing')
.then(function () {
getPackageVersion().should.equal('200.0.0-amazing')
})
})
})
it('creates a prerelease with a new minor version after two prerelease patches', function () {

@@ -444,7 +598,7 @@ writePackageJson('1.0.0')

require('./index')({silent: true}, function (err) {
should.exist(err)
err.message.should.match(/bump err/)
done()
})
require('./index')({silent: true})
.catch((err) => {
err.message.should.match(/bump err/)
done()
})
})

@@ -475,7 +629,7 @@ })

require('./index')({silent: true}, function (err) {
should.exist(err)
err.message.should.match(/changelog err/)
done()
})
require('./index')({silent: true})
.catch((err) => {
err.message.should.match(/changelog err/)
return done()
})
})

@@ -489,11 +643,10 @@ })

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()
})
require('./index')({silent: true})
.then(() => {
// 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()
})
})

@@ -506,14 +659,32 @@

it('bumps verson # in bower.json', function (done) {
it('bumps version # in bower.json', 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) {
if (err) return done(err)
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
done()
})
require('./index')({silent: true})
.then(() => {
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
return done()
})
})
})
describe('npm-shrinkwrap.json support', function () {
beforeEach(function () {
writeNpmShrinkwrapJson('1.0.0')
})
it('bumps version # in npm-shrinkwrap.json', 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})
.then(() => {
JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8')).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
return done()
})
})
})
})

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc