Socket
Socket
Sign inDemoInstall

standard-version

Package Overview
Dependencies
Maintainers
5
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 7.0.1 to 7.1.0

lib/updaters/index.js

22

CHANGELOG.md

@@ -5,2 +5,24 @@ # Changelog

## [7.1.0](https://github.com/conventional-changelog/standard-version/compare/v7.0.1...v7.1.0) (2019-12-08)
### Features
* Adds support for `header` (--header) configuration based on the spec. ([#364](https://github.com/conventional-changelog/standard-version/issues/364)) ([ba80a0c](https://github.com/conventional-changelog/standard-version/commit/ba80a0c27029f54c751fe845560504925b45eab8))
* custom 'bumpFiles' and 'packageFiles' support ([#372](https://github.com/conventional-changelog/standard-version/issues/372)) ([564d948](https://github.com/conventional-changelog/standard-version/commit/564d9482a459d5d7a2020c2972b4d39167ded4bf))
### Bug Fixes
* **deps:** update dependency conventional-changelog to v3.1.15 ([#479](https://github.com/conventional-changelog/standard-version/issues/479)) ([492e721](https://github.com/conventional-changelog/standard-version/commit/492e72192ebf35d7c58c00526b1e6bd2abac7f13))
* **deps:** update dependency conventional-changelog-conventionalcommits to v4.2.3 ([#496](https://github.com/conventional-changelog/standard-version/issues/496)) ([bc606f8](https://github.com/conventional-changelog/standard-version/commit/bc606f8e96bcef1d46b28305622fc76dfbf306cf))
* **deps:** update dependency conventional-recommended-bump to v6.0.5 ([#480](https://github.com/conventional-changelog/standard-version/issues/480)) ([1e1e215](https://github.com/conventional-changelog/standard-version/commit/1e1e215a633963188cdb02be1316b5506e3b99b7))
* **deps:** update dependency yargs to v15 ([#484](https://github.com/conventional-changelog/standard-version/issues/484)) ([35b90c3](https://github.com/conventional-changelog/standard-version/commit/35b90c3f24cfb8237e94482fd20997900569193e))
* use require.resolve for the default preset ([#465](https://github.com/conventional-changelog/standard-version/issues/465)) ([d557372](https://github.com/conventional-changelog/standard-version/commit/d55737239530f5eee684e9cbf959f7238d609fd4))
* **deps:** update dependency detect-newline to v3.1.0 ([#482](https://github.com/conventional-changelog/standard-version/issues/482)) ([04ab36a](https://github.com/conventional-changelog/standard-version/commit/04ab36a12be58915cfa9c60771890e074d1f5685))
* **deps:** update dependency figures to v3.1.0 ([#468](https://github.com/conventional-changelog/standard-version/issues/468)) ([63300a9](https://github.com/conventional-changelog/standard-version/commit/63300a935c0079fd03e8e1acc55fd5b1dcea677f))
* **deps:** update dependency git-semver-tags to v3.0.1 ([#485](https://github.com/conventional-changelog/standard-version/issues/485)) ([9cc188c](https://github.com/conventional-changelog/standard-version/commit/9cc188cbb84ee3ae80d5e66f5c54727877313b14))
* **deps:** update dependency yargs to v14.2.1 ([#483](https://github.com/conventional-changelog/standard-version/issues/483)) ([dc1fa61](https://github.com/conventional-changelog/standard-version/commit/dc1fa6170ffe12d4f8b44b70d23688a64d2ad0fb))
* **deps:** update dependency yargs to v14.2.2 ([#488](https://github.com/conventional-changelog/standard-version/issues/488)) ([ecf26b6](https://github.com/conventional-changelog/standard-version/commit/ecf26b6fc9421a78fb81793c4a932f579f7e9d4a))
### [7.0.1](https://github.com/conventional-changelog/standard-version/compare/v7.0.0...v7.0.1) (2019-11-07)

@@ -7,0 +29,0 @@

20

command.js
const spec = require('conventional-changelog-config-spec')
const { getConfiguration } = require('./lib/configuration')
const defaults = require('./defaults')
const { START_OF_LAST_RELEASE_PATTERN } = require('./lib/lifecycles/changelog')
const yargs = require('yargs')
.usage('Usage: $0 [options]')
.option('packageFiles', {
default: defaults.packageFiles,
array: true
})
.option('bumpFiles', {
default: defaults.bumpFiles,
array: true
})
.option('release-as', {

@@ -88,3 +95,3 @@ alias: 'r',

type: 'string',
describe: 'Use a custom header when generating and updating changelog.'
describe: '[DEPRECATED] Use a custom header when generating and updating changelog.\nThis option will be removed in the next major version, please use --header.'
})

@@ -112,9 +119,2 @@ .option('preset', {

.wrap(97)
.check((args) => {
if (args.changelogHeader && args.changelogHeader.search(START_OF_LAST_RELEASE_PATTERN) !== -1) {
throw Error(`custom changelog header must not match ${START_OF_LAST_RELEASE_PATTERN}`)
} else {
return true
}
})

@@ -126,3 +126,3 @@ Object.keys(spec.properties).forEach(propertyKey => {

describe: property.description,
default: property.default,
default: defaults[propertyKey] ? defaults[propertyKey] : property.default,
group: 'Preset Configuration:'

@@ -129,0 +129,0 @@ })

@@ -15,3 +15,3 @@ const spec = require('conventional-changelog-config-spec')

gitTagFallback: true,
preset: 'conventionalcommits'
preset: require.resolve('conventional-changelog-conventionalcommits')
}

@@ -27,2 +27,21 @@

/**
* Sets the default for `header` (provided by the spec) for backwards
* compatibility. This should be removed in the next major version.
*/
defaults.header = '# Changelog\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'
defaults.packageFiles = [
'package.json',
'bower.json',
'manifest.json',
'composer.json'
]
defaults.bumpFiles = defaults.packageFiles.concat([
'package-lock.json',
'npm-shrinkwrap.json',
'composer.lock'
])
module.exports = defaults

@@ -9,4 +9,6 @@ const bump = require('./lib/lifecycles/bump')

const tag = require('./lib/lifecycles/tag')
const { resolveUpdaterObjectFromArgument } = require('./lib/updaters')
module.exports = function standardVersion (argv) {
const defaults = require('./defaults')
/**

@@ -28,15 +30,28 @@ * `--message` (`-m`) support will be removed in the next major version.

if (argv.changelogHeader) {
argv.header = argv.changelogHeader
if (!argv.silent) {
console.warn('[standard-version]: --changelogHeader will be removed in the next major release. Use --header.')
}
}
if (argv.header && argv.header.search(changelog.START_OF_LAST_RELEASE_PATTERN) !== -1) {
throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`)
}
const args = Object.assign({}, defaults, argv)
let pkg
bump.pkgFiles.forEach((filename) => {
args.packageFiles.forEach((packageFile) => {
if (pkg) return
const pkgPath = path.resolve(process.cwd(), filename)
const updater = resolveUpdaterObjectFromArgument(packageFile)
const pkgPath = path.resolve(process.cwd(), updater.filename)
try {
const data = fs.readFileSync(pkgPath, 'utf8')
pkg = JSON.parse(data)
const contents = fs.readFileSync(pkgPath, 'utf8')
pkg = {
version: updater.updater.readVersion(contents),
private: typeof updater.updater.isPrivate === 'function' ? updater.updater.isPrivate(contents) : false
}
} catch (err) {}
})
let newVersion
const defaults = require('./defaults')
const args = Object.assign({}, defaults, argv)
return Promise.resolve()

@@ -43,0 +58,0 @@ .then(() => {

@@ -6,4 +6,2 @@ 'use strict'

const conventionalRecommendedBump = require('conventional-recommended-bump')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')
const figures = require('figures')

@@ -16,5 +14,4 @@ const fs = require('fs')

const semver = require('semver')
const stringifyPackage = require('stringify-package')
const writeFile = require('../write-file')
const { resolveUpdaterObjectFromArgument } = require('../updaters')
let configsToUpdate = {}

@@ -56,15 +53,2 @@

Bump.pkgFiles = [
'package.json',
'bower.json',
'manifest.json',
'composer.json'
]
Bump.lockFiles = [
'package-lock.json',
'npm-shrinkwrap.json',
'composer.lock'
]
function getReleaseType (prerelease, expectedReleaseType, currentVersion) {

@@ -160,28 +144,34 @@ if (isString(prerelease)) {

/**
* attempt to update the version # in a collection of common config
* files, e.g., package.json, bower.json.
*
* attempt to update the version number in provided `bumpFiles`
* @param args config object
* @param newVersion version # to update to.
* @return {string}
* @param newVersion version number to update to.
* @return void
*/
function updateConfigs (args, newVersion) {
const dotgit = DotGitignore()
Bump.pkgFiles.concat(Bump.lockFiles).forEach(function (filename) {
const configPath = path.resolve(process.cwd(), filename)
args.bumpFiles.forEach(function (bumpFile) {
const updater = resolveUpdaterObjectFromArgument(bumpFile)
if (!updater) {
return
}
const configPath = path.resolve(process.cwd(), updater.filename)
try {
if (dotgit.ignore(configPath)) return
const stat = fs.lstatSync(configPath)
if (stat.isFile()) {
const data = fs.readFileSync(configPath, 'utf8')
const indent = detectIndent(data).indent
const newline = detectNewline(data)
const config = JSON.parse(data)
checkpoint(args, 'bumping version in ' + filename + ' from %s to %s', [config.version, newVersion])
config.version = newVersion
writeFile(args, configPath, stringifyPackage(config, indent, newline))
// flag any config files that we modify the version # for
// as having been updated.
configsToUpdate[filename] = true
}
if (!stat.isFile()) return
const contents = fs.readFileSync(configPath, 'utf8')
checkpoint(
args,
'bumping version in ' + updater.filename + ' from %s to %s',
[updater.updater.readVersion(contents), newVersion]
)
writeFile(
args,
configPath,
updater.updater.writeVersion(contents, newVersion)
)
// flag any config files that we modify the version # for
// as having been updated.
configsToUpdate[updater.filename] = true
} catch (err) {

@@ -188,0 +178,0 @@ if (err.code !== 'ENOENT') console.warn(err.message)

@@ -29,3 +29,3 @@ const accessSync = require('fs-access').sync

createIfMissing(args)
const header = args.changelogHeader || '# Changelog\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'
const header = args.header

@@ -32,0 +32,0 @@ let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')

@@ -6,6 +6,7 @@ // TODO: this should be replaced with an object we maintain and

module.exports = (args) => {
let preset = args.preset || 'conventionalcommits'
if (preset === 'conventionalcommits') {
const defaultPreset = require.resolve('conventional-changelog-conventionalcommits')
let preset = args.preset || defaultPreset
if (preset === defaultPreset) {
preset = {
name: preset
name: defaultPreset
}

@@ -12,0 +13,0 @@ Object.keys(spec.properties).forEach(key => {

{
"name": "standard-version",
"version": "7.0.1",
"version": "7.1.0",
"description": "replacement for `npm version` with automatic CHANGELOG generation",

@@ -42,26 +42,27 @@ "bin": "bin/cli.js",

"chalk": "2.4.2",
"conventional-changelog": "3.1.12",
"conventional-changelog": "3.1.15",
"conventional-changelog-config-spec": "2.1.0",
"conventional-recommended-bump": "6.0.2",
"conventional-changelog-conventionalcommits": "4.2.3",
"conventional-recommended-bump": "6.0.5",
"detect-indent": "6.0.0",
"detect-newline": "3.0.0",
"detect-newline": "3.1.0",
"dotgitignore": "2.1.0",
"figures": "3.0.0",
"figures": "3.1.0",
"find-up": "4.1.0",
"fs-access": "1.0.1",
"git-semver-tags": "3.0.0",
"git-semver-tags": "3.0.1",
"semver": "6.3.0",
"stringify-package": "1.0.1",
"yargs": "14.2.0"
"yargs": "15.0.2"
},
"devDependencies": {
"chai": "4.2.0",
"coveralls": "3.0.7",
"eslint": "6.2.2",
"coveralls": "3.0.9",
"eslint": "6.7.2",
"eslint-config-standard": "14.1.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-node": "9.2.0",
"eslint-plugin-node": "10.0.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"mocha": "6.2.0",
"mocha": "6.2.2",
"mock-git": "2.0.0",

@@ -68,0 +69,0 @@ "mockery": "2.1.0",

# Standard Version
A utility for versioning using [semver](https://semver.org/) and CHANGELOG generation powered by [Conventional Commits](https://conventionalcommits.org).
[![Build Status](https://travis-ci.org/conventional-changelog/standard-version.svg?branch=master)](https://travis-ci.org/conventional-changelog/standard-version)

@@ -7,31 +9,40 @@ [![NPM version](https://img.shields.io/npm/v/standard-version.svg)](https://www.npmjs.com/package/standard-version)

[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![community slack](http://devtoolscommunity.herokuapp.com/badge.svg)](http://devtoolscommunity.herokuapp.com)
[![Community slack](http://devtoolscommunity.herokuapp.com/badge.svg)](http://devtoolscommunity.herokuapp.com)
_Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com)_.
_Having problems? Want to contribute? Join us on the [node-tooling community Slack](http://devtoolscommunity.herokuapp.com)_.
Automate versioning and CHANGELOG generation, with [semver](https://semver.org/) and
[conventional commit messages](https://conventionalcommits.org).
_How It Works:_
_how it works:_
1. Follow the [Conventional Commits Specification](https://conventionalcommits.org) in your repository.
2. When you're ready to release, run `standard-version`.
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 Commits Specification](https://conventionalcommits.org).
3. when you're ready to release:
1. `git checkout master; git pull origin master`
2. run `standard-version`
3. `git push --follow-tags origin master && npm publish`
_(or, `docker push`, `gem push`, etc.)_
`standard-version` will then do the following:
`standard-version` does the following:
1. Retreive the current version of your repository by looking at `bumpFiles`[1](), falling back to the last `git tag`.
2. `bump` the version in `bumpFiles`[1]() based on your commits.
4. Generates a `changelog` based on your commints (uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) under the hood).
5. Creates a new `commit` including your `bumpFiles`[1]() and updated CHANGELOG.
6. Creates a new `tag` with the new version number.
1. bumps the version in metadata files (package.json, composer.json, etc).
2. uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) to update _CHANGELOG.md_
3. commits _package.json (et al.)_ and _CHANGELOG.md_
4. tags a new release
## Installation
### `bumpFiles`, `packageFiles` and `updaters`
### As `npm run` script
`standard-version` uses a few key concepts for handling version bumping in your project.
- **`packageFiles`** – User-defined files where versions can be read from _and_ "bumped".
- Examples: `package.json`, `manifest.json`
- In most cases (including the default), `packageFiles` are a subset of `bumpFiles`.
- **`bumpFiles`** – User-defined files where versions should be "bumped", but not explicitly read from.
- Examples: `package-lock.json`, `npm-shrinkwrap.json`
- **`updaters`** – Simple modules used for reading `packageFiles` and writing to `bumpFiles`.
By default, `standard-version` assumes you're working in a NodeJS based project... because of this, for the majority of projects you might never need to interact with these options.
That said, if you find your self asking [How can I use standard-version for additional metadata files, languages or version files?](#can-i-use-standard-version-for-additional-metadata-files-languages-or-version-files) – these configuration options will help!
## Installing `standard-version`
### As a local `npm run` script
Install and add to `devDependencies`:

@@ -43,3 +54,3 @@

Add an [`npm run` script](https://docs.npmjs.com/cli/run-script) to your _package.json_:
Add an [`npm run` script](https://docs.npmjs.com/cli/run-script) to your `package.json`:

@@ -58,3 +69,3 @@ ```json

### As global bin
### As global `bin`

@@ -71,2 +82,8 @@ Install globally (add to your `PATH`):

### Using `npx`
As of `npm@5.2.0`, `npx` is installed alongside `npm`. Using `npx` you can use `standard-version` without having to keep a `package.json` file by running: `npx standard-version`.
This method is especially useful when using `standard-version` in non-JavaScript projects.
## Configuration

@@ -87,11 +104,11 @@

By default, `standard-version` uses the [conventionalcommits preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits).
By default (as of `6.0.0`), `standard-version` uses the [conventionalcommits preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits).
This preset:
* adheres closely to the [conventionalcommits.org](https://www.conventionalcommits.org)
* Adheres closely to the [conventionalcommits.org](https://www.conventionalcommits.org)
specification.
* is highly configurable, following the configuration specification
* Is highly configurable, following the configuration specification
[maintained here](https://github.com/conventional-changelog/conventional-changelog-config-spec).
* _we've documented these config settings as a recommendation to other tooling makers._
* _We've documented these config settings as a recommendation to other tooling makers._

@@ -119,11 +136,13 @@ There are a variety of dials and knobs you can turn related to CHANGELOG generation.

npm run release -- --first-release
# or global bin
# global bin
standard-version --first-release
# npx
npx standard-version --first-release
```
This will tag a release **without bumping the version in package.json (_et al._)**.
This will tag a release **without bumping the version `bumpFiles`[1]()**.
When ready, push the git tag and `npm publish` your first release. \o/
When you are ready, push the git tag and `npm publish` your first release. \o/
### Cut a Release
### Cutting Releases

@@ -143,3 +162,3 @@ If you typically use `npm version` to cut a new release, do this instead:

### Release as a pre-release
### Release as a Pre-Release

@@ -154,3 +173,3 @@ Use the flag `--prerelease` to generate pre-releases:

```
you will get version `1.0.1-0`.
This will tag your version as: `1.0.1-0`.

@@ -166,10 +185,10 @@ If you want to name the pre-release, you specify the name via `--prerelease <name>`.

this will tag the version `1.0.1-alpha.0`
This will tag the version as: `1.0.1-alpha.0`
### Release as a target type imperatively like `npm version`
### Release as a Target Type Imperatively (`npm version`-like)
To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`:
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:
you would like your next release to be a `minor`. Simply run the following:

@@ -183,3 +202,3 @@ ```bash

you will get version `1.1.0` rather than the auto generated version `1.0.1`.
you will get version `1.1.0` rather than what would be the auto-generated version `1.0.1`.

@@ -199,7 +218,7 @@ > **NOTE:** you can combine `--release-as` and `--prerelease` to generate a release. This is useful when publishing experimental feature(s).

### Signing commits and tags
### Signing Commits and Tags
If you have your GPG key set up, add the `--sign` or `-s` flag to your `standard-version` command.
### Lifecycle scripts
### Lifecycle Scripts

@@ -245,3 +264,3 @@ `standard-version` supports lifecycle scripts. These allow you to execute your

### Skipping lifecycle steps
### Skipping Lifecycle Steps

@@ -261,3 +280,3 @@ You can skip any of the lifecycle steps (`bump`, `changelog`, `commit`, `tag`),

### Committing generated artifacts in the release commit
### Committing Generated Artifacts in the Release Commit

@@ -271,3 +290,3 @@ 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:

### Dry run mode
### Dry Run Mode

@@ -305,7 +324,4 @@ running `standard-version` with the flag `--dry-run` allows you to see what

## Code usage
## Code Usage
Use the `silent` option to stop `standard-version` from printing anything
to the console.
```js

@@ -327,68 +343,114 @@ const standardVersion = require('standard-version')

## Commit Message Convention, at a Glance
_TIP: Use the `silent` option to prevent `standard-version` from printing to the `console`._
_patches:_
## FAQ
```sh
git commit -a -m "fix(parsing): fixed a bug in our parser"
```
### How is `standard-version` different from `semantic-release`?
_features:_
[`semantic-release`](https://github.com/semantic-release/semantic-release) is described as:
```sh
git commit -a -m "feat(parser): we now have a parser \o/"
```
> semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.
_breaking changes:_
While both are based on the same foundation of structured commit messages, `standard-version` takes a different approach by handling versioning, changelog generation, and git tagging for you **without** automatic pushing (to GitHub) or publishing (to an npm registry). Use of `standard-version` only affects your local git repo - it doesn't affect remote resources at all. After you run `standard-version`, you can review your release state, correct mistakes and follow the release strategy that makes the most sense for your codebase.
```sh
git commit -a -m "feat(new-parser): introduces a new parsing library
BREAKING CHANGE: new library does not support foo-construct"
```
We think they are both fantastic tools, and we encourage folks to use `semantic-release` instead of `standard-version` if it makes sense for their use-case.
_other changes:_
### Should I always squash commits when merging PRs?
You decide, e.g., docs, chore, etc.
The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**.
```sh
git commit -a -m "docs: fixed up the docs a bit"
```
If you have multiple features or fixes landing in a single PR and each commit uses a structured message, then you can do a standard merge when accepting the PR. This will preserve the commit history from your branch after the merge.
_but wait, there's more!_
Although this will allow each commit to be included as separate entries in your CHANGELOG, the entries will **not** be able to reference the PR that pulled the changes in because the preserved commit messages do not include the PR number.
Github usernames (`@bcoe`) and issue references (#133) will be swapped out for the
appropriate URLs in your CHANGELOG.
For this reason, we recommend keeping the scope of each PR to one general feature or fix. In practice, this allows you to use unstructured commit messages when committing each little change and then squash them into a single commit with a structured message (referencing the PR number) once they have been reviewed and accepted.
## Badges!
### Can I use `standard-version` for additional metadata files, languages or version files?
Tell your users that you adhere to the Conventional Commits specification:
YES! Using `bumpFiles` (and `packageFiles`) configurations you should be able to configure `standard-version` to work for you.
```markdown
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
1. Specify a custom `bumpFile` "`file`", this is the path to the file you want to "bump"
2. Specify the `bumpFile` "`updater`", this is _how_ the file will be bumped.
a. If your using a common type, you can use one of `standard-version`'s built-in `updaters` by specifying a `type`.
b. If your using an less-common version file, you can create your own `updater`.
```json
// .versionrc
{
"bumpFiles": [
{
"file": "MY_VERSION_TRACKER.txt",
// The `plain-text` updater assumes the file contents represents the version.
"type": "plain-text"
},
{
"file": "a/deep/package/dot/json/file/package.json",
// The `json` updater assumes the version is available under a `version` key in the provided JSON document.
"type": "json"
}
{
"file": "VERSION_TRACKER.json",
// See "Custom `updater`s" for more details.
"updater": "standard-version-updater.js"
}
]
}
```
## FAQ
#### Custom `updater`s
### How is `standard-version` different from `semantic-release`?
An `updater` is expected to be a Javascript module with _atleast_ two methods exposed: `readVersion` and `writeVersion`.
[`semantic-release`](https://github.com/semantic-release/semantic-release) is described as:
##### `readVersion(contents = string): string`
> semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.
This method is used to read the version from the provided file contents.
While both are based on the same foundation of structured commit messages, `standard-version` takes a different approach by handling versioning, changelog generation, and git tagging for you **without** automatic pushing (to GitHub) or publishing (to an npm registry). Use of `standard-version` only affects your local git repo - it doesn't affect remote resources at all. After you run `standard-version`, you can review your release state, correct mistakes and follow the release strategy that makes the most sense for your codebase.
The return value is expected to be a semantic version string.
We think they are both fantastic tools, and we encourage folks to use `semantic-release` instead of `standard-version` if it makes sense for their use-case.
##### `writeVersion(contents = string, version: string): string`
### Should I always squash commits when merging PRs?
This method is used to write the version to the provided contents.
The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**.
The return value will be written directly (overwrite) to the provided file.
If you have multiple features or fixes landing in a single PR and each commit uses a structured message, then you can do a standard merge when accepting the PR. This will preserve the commit history from your branch after the merge.
---
Although this will allow each commit to be included as separate entries in your CHANGELOG, the entries will **not** be able to reference the PR that pulled the changes in because the preserved commit messages do not include the PR number.
Let's assume our `VERSION_TRACKER.json` has the following contents:
For this reason, we recommend keeping the scope of each PR to one general feature or fix. In practice, this allows you to use unstructured commit messages when committing each little change and then squash them into a single commit with a structured message (referencing the PR number) once they have been reviewed and accepted.
```json
{
"tracker": {
"package": {
"version": "1.0.0"
}
}
}
```
An acceptable `standard-version-updater.js` would be:
```js
// standard-version-updater.js
const stringifyPackage = require('stringify-package')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')
module.exports.readVersion = function (contents) {
return JSON.parse(contents).tracker.package.version;
}
module.exports.writeVersion = function (contents, version) {
const json = JSON.parse(contents)
let indent = detectIndent(contents).indent
let newline = detectNewline(contents)
json.tracker.package.version = version
return stringifyPackage(json, indent, newline)
}
```
## License
ISC

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

it('allows for a custom changelog header', function () {
it('[DEPRECATED] (--changelogHeader) allows for a custom changelog header', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')

@@ -245,3 +245,3 @@ commit('feat: first commit')

it('exits with error if changelog header matches last version search regex', function () {
it('[DEPRECATED] (--changelogHeader) exits with error if changelog header matches last version search regex', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')

@@ -927,2 +927,70 @@ commit('feat: first commit')

describe('custom `bumpFiles` support', function () {
it('mix.exs + version.txt', function () {
// @todo This file path is relative to the `tmp` directory, which is a little confusing
fs.copyFileSync('../test/mocks/mix.exs', 'mix.exs')
fs.copyFileSync('../test/mocks/version.txt', 'version.txt')
fs.copyFileSync('../test/mocks/updater/customer-updater.js', 'custom-updater.js')
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
return require('./index')({
silent: true,
bumpFiles: [
'version.txt',
{
filename: 'mix.exs',
updater: 'custom-updater.js'
}
]
})
.then(() => {
fs.readFileSync('mix.exs', 'utf-8').should.contain('version: "1.1.0"')
fs.readFileSync('version.txt', 'utf-8').should.equal('1.1.0')
})
})
it('bumps a custom `plain-text` file', function () {
fs.copyFileSync('../test/mocks/VERSION-1.0.0.txt', 'VERSION_TRACKER.txt')
commit('feat: first commit')
return require('./index')({
silent: true,
bumpFiles: [
{
filename: 'VERSION_TRACKER.txt',
type: 'plain-text'
}
]
})
.then(() => {
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
})
})
})
describe('custom `packageFiles` support', function () {
it('reads and writes to a custom `plain-text` file', function () {
fs.copyFileSync('../test/mocks/VERSION-6.3.1.txt', 'VERSION_TRACKER.txt')
commit('feat: yet another commit')
return require('./index')({
silent: true,
packageFiles: [
{
filename: 'VERSION_TRACKER.txt',
type: 'plain-text'
}
],
bumpFiles: [
{
filename: 'VERSION_TRACKER.txt',
type: 'plain-text'
}
]
})
.then(() => {
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
})
})
})
describe('npm-shrinkwrap.json support', function () {

@@ -1079,2 +1147,18 @@ beforeEach(function () {

describe('configuration', () => {
it('reads config from package.json', function () {
writePackageJson('1.0.0', {
repository: {
url: 'git+https://company@scm.org/office/app.git'
},
'standard-version': {
issueUrlFormat: 'https://standard-version.company.net/browse/{{id}}'
}
})
commit('feat: another commit addresses issue #1')
execCli()
// CHANGELOG should have the new issue URL format.
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.include('https://standard-version.company.net/browse/1')
})
it('reads config from .versionrc', function () {

@@ -1185,2 +1269,10 @@ // write configuration that overrides default issue

it('--header', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')
commit('feat: first commit')
execCli('--header="# Welcome to our CHANGELOG.md"').code.should.equal(0)
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/# Welcome to our CHANGELOG.md/)
})
it('--issuePrefixes and --issueUrlFormat', function () {

@@ -1187,0 +1279,0 @@ commit('feat: another commit addresses issue ABC-1')

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