├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── ask-a-question.md │ └── bug-report.md ├── dependabot.yml └── workflows │ ├── ci.yaml │ └── release-please.yml ├── .gitignore ├── .prettierrc ├── .versionrc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── bin └── cli.js ├── command.js ├── defaults.js ├── eslint.config.mjs ├── index.js ├── jest.config.js ├── lib ├── checkpoint.js ├── configuration.js ├── detect-package-manager.js ├── format-commit-message.js ├── latest-semver-tag.js ├── lifecycles │ ├── bump.js │ ├── changelog.js │ ├── commit.js │ └── tag.js ├── preset-loader.js ├── print-error.js ├── run-exec.js ├── run-execFile.js ├── run-lifecycle-script.js ├── stringify-package.js ├── updaters │ ├── index.js │ └── types │ │ ├── csproj.js │ │ ├── gradle.js │ │ ├── json.js │ │ ├── maven.js │ │ ├── openapi.js │ │ ├── plain-text.js │ │ ├── python.js │ │ └── yaml.js └── write-file.js ├── package-lock.json ├── package.json └── test ├── commit-message-config.integration-test.js ├── config-files.integration-test.js ├── config-keys.integration-test.js ├── core.spec.js ├── git.integration-test.js ├── invalid-config.integration-test.js ├── mocks ├── Project-6.3.1.csproj ├── Project-6.4.0.csproj ├── VERSION-1.0.0.txt ├── VERSION-6.3.1.txt ├── build-6.3.1.gradle.kts ├── build-6.4.0.gradle.kts ├── increment-version.txt ├── jest-mocks.js ├── manifest-6.3.1.json ├── mix.exs ├── openapi-1.2.3-crlf.yaml ├── openapi-1.2.3-lf.yaml ├── openapi-1.3.0-crlf.yaml ├── openapi-1.3.0-lf.yaml ├── pom-6.3.1-crlf.xml ├── pom-6.3.1-lf.xml ├── pom-6.4.0-crlf.xml ├── pom-6.4.0-lf.xml ├── pubspec-6.3.1-crlf.yaml ├── pubspec-6.3.1.yaml ├── pubspec-6.4.0-crlf.yaml ├── pubspec-6.4.0.yaml ├── pyproject-1.0.0.toml ├── pyproject-1.1.0.toml ├── updater │ ├── customer-updater.js │ └── increment-updater.js └── version.txt ├── pre-commit-hook.integration-test.js ├── preset.integration-test.js ├── stringify-package.spec.js └── utils.spec.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | trim_trailing_whitespace=true 7 | indent_style = space 8 | indent_size = 2 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ts text eol=lf 2 | *.js text eol=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ask-a-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a Question 3 | about: '"How can I X?" – ask a question about how to use commit-and-tag-version.' 4 | title: "" 5 | labels: question 6 | assignees: "" 7 | --- 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Use this template if something isn't working as expected. 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **Current behavior** 13 | A clear and concise description of the behavior. 14 | 15 | **Expected behavior** 16 | A clear and concise description of what you expected to happen. 17 | 18 | **Environment** 19 | 20 | - `commit-and-tag-version` version(s): [e.g. v6.0.0, v8.0.0, master] 21 | - Node/npm version: [e.g. Node 10/npm 6] 22 | - OS: [e.g. OSX 10.13.4, Windows 10] 23 | 24 | **Possible Solution** 25 | 26 | 27 | 28 | **Additional context** 29 | Add any other context about the problem here. Or a screenshot if applicable 30 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | # Node / npm 9 | - package-ecosystem: "npm" # See documentation for possible values 10 | directory: "/" # Location of package manifests 11 | versioning-strategy: increase 12 | schedule: 13 | interval: "weekly" 14 | 15 | # Maintain dependencies for GitHub Actions 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | schedule: 19 | interval: "weekly" 20 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | pull_request: 6 | types: [ assigned, opened, synchronize, reopened, labeled ] 7 | name: ci 8 | jobs: 9 | test: 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | node: [ 14 | 18, 15 | 20, 16 | lts/* 17 | ] 18 | os: [ 19 | ubuntu-latest, 20 | windows-latest 21 | ] 22 | env: 23 | OS: ${{ matrix.os }} 24 | NODE_VERSION: ${{ matrix.node }} 25 | steps: 26 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 27 | - run: git fetch --prune --unshallow 28 | - run: git config --global user.name 'Actions' 29 | - run: git config --global user.email 'dummy@example.org' 30 | - uses: actions/setup-node@v4 31 | with: 32 | node-version: ${{ matrix.node }} 33 | - run: node --version 34 | - run: npm install --engine-strict 35 | - run: npm test 36 | - name: Codecov 37 | uses: codecov/codecov-action@v5 38 | with: 39 | env_vars: OS, NODE_VERSION 40 | -------------------------------------------------------------------------------- /.github/workflows/release-please.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | push: 4 | branches: 5 | - master 6 | name: release-please 7 | jobs: 8 | release-please: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: GoogleCloudPlatform/release-please-action@v4 12 | id: release 13 | with: 14 | token: ${{ secrets.GITHUB_TOKEN }} 15 | release-type: node 16 | package-name: commit-and-tag-version 17 | # The logic below handles the npm publication: 18 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 19 | # these if statements ensure that a publication only occurs when 20 | # a new release is created: 21 | if: ${{ steps.release.outputs.release_created }} 22 | - uses: actions/setup-node@v4 23 | with: 24 | node-version: 20 25 | registry-url: 'https://registry.npmjs.org' 26 | if: ${{ steps.release.outputs.release_created }} 27 | - run: npm ci 28 | if: ${{ steps.release.outputs.release_created }} 29 | - run: npm publish 30 | env: 31 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 32 | if: ${{ steps.release.outputs.release_created }} 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS 2 | .DS_Store 3 | 4 | # node.js & npm 5 | node_modules 6 | .nyc_output 7 | npm-debug.log 8 | 9 | # Editor files 10 | /.project 11 | /.settings 12 | /.idea 13 | /.vscode 14 | 15 | # coverage 16 | coverage 17 | 18 | # temp dirs 19 | *-temp 20 | tmp 21 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.versionrc: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | {"type":"feat","section":"Features"}, 4 | {"type":"fix","section":"Bug Fixes"}, 5 | {"type":"test","section":"Tests", "hidden": true}, 6 | {"type":"build","section":"Build System", "hidden": true}, 7 | {"type":"ci","hidden":true} 8 | ] 9 | } 10 | 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. 4 | 5 | ## [12.5.1](https://github.com/absolute-version/commit-and-tag-version/compare/v12.5.0...v12.5.1) (2025-04-09) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * ignore other prerelease tags when finding latest tag ([#211](https://github.com/absolute-version/commit-and-tag-version/issues/211)) ([#213](https://github.com/absolute-version/commit-and-tag-version/issues/213)) ([1bcdf40](https://github.com/absolute-version/commit-and-tag-version/commit/1bcdf408cac54aff37aa4d5611444f6877aad6f9)) 11 | 12 | ## [12.5.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.4.4...v12.5.0) (2024-10-10) 13 | 14 | 15 | ### Features 16 | 17 | * **python:** add poetry support ([#188](https://github.com/absolute-version/commit-and-tag-version/issues/188)) ([01f08e9](https://github.com/absolute-version/commit-and-tag-version/commit/01f08e9093e255f81394c97bcac59e057f5717dc)) 18 | 19 | ## [12.4.4](https://github.com/absolute-version/commit-and-tag-version/compare/v12.4.3...v12.4.4) (2024-09-15) 20 | 21 | 22 | ### Bug Fixes 23 | 24 | * sanitize double quotes result from stdout ([#186](https://github.com/absolute-version/commit-and-tag-version/issues/186)) ([8dbeb79](https://github.com/absolute-version/commit-and-tag-version/commit/8dbeb794b960c6ea27527353ad2c55884f48b469)) 25 | 26 | ## [12.4.3](https://github.com/absolute-version/commit-and-tag-version/compare/v12.4.2...v12.4.3) (2024-09-09) 27 | 28 | 29 | ### Bug Fixes 30 | 31 | * Correct issue where downstream dependency would throw `options.debug is not a function` ([4280bcf](https://github.com/absolute-version/commit-and-tag-version/commit/4280bcf102b78d1995b24ec9238219db81730ebd)) 32 | 33 | ## [12.4.2](https://github.com/absolute-version/commit-and-tag-version/compare/v12.4.1...v12.4.2) (2024-08-25) 34 | 35 | 36 | ### Bug Fixes 37 | 38 | * **deps:** update dependency conventional-changelog to v4 ([#176](https://github.com/absolute-version/commit-and-tag-version/issues/176)) ([8d15fc7](https://github.com/absolute-version/commit-and-tag-version/commit/8d15fc788edc2fd5d901ccbbbacb3452eabc3091)) 39 | 40 | ## [12.4.1](https://github.com/absolute-version/commit-and-tag-version/compare/v12.4.0...v12.4.1) (2024-04-28) 41 | 42 | 43 | ### Bug Fixes 44 | 45 | * raise the 'openapi'-updater to a higher order of precedence above the 'yaml'-updater ([#143](https://github.com/absolute-version/commit-and-tag-version/issues/143)) ([37fe178](https://github.com/absolute-version/commit-and-tag-version/commit/37fe178fdba051c665414565fe4b0e61336aff18)) 46 | 47 | ## [12.4.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.3.0...v12.4.0) (2024-04-19) 48 | 49 | 50 | ### Features 51 | 52 | * Add OpenAPI version support ([#136](https://github.com/absolute-version/commit-and-tag-version/issues/136)) ([007b1b0](https://github.com/absolute-version/commit-and-tag-version/commit/007b1b0386651f2fbd6e8a9f552a2a34702086ca)) 53 | 54 | ## [12.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.2.0...v12.3.0) (2024-04-19) 55 | 56 | 57 | ### Features 58 | 59 | * **updater:** add YAML support ([#137](https://github.com/absolute-version/commit-and-tag-version/issues/137)) ([b9dccc2](https://github.com/absolute-version/commit-and-tag-version/commit/b9dccc23ec05e4026899c676f3275d4dedf8c686)) 60 | 61 | 62 | ### Bug Fixes 63 | 64 | * Add debug messages for exclusions during bump lifecycle ([#131](https://github.com/absolute-version/commit-and-tag-version/issues/131)) ([a9191f2](https://github.com/absolute-version/commit-and-tag-version/commit/a9191f293eb9302afb1093ad37e9fa076f6b37a2)) 65 | 66 | ## [12.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.1.0...v12.2.0) (2024-01-15) 67 | 68 | 69 | ### Features 70 | 71 | * **updater:** add maven pom.xml file support ([#33](https://github.com/absolute-version/commit-and-tag-version/issues/33), [#109](https://github.com/absolute-version/commit-and-tag-version/issues/109)) ([#123](https://github.com/absolute-version/commit-and-tag-version/issues/123)) ([6466beb](https://github.com/absolute-version/commit-and-tag-version/commit/6466bebf849bbdcdaebf493a1ccce9670c469fde)) 72 | 73 | ## [12.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.0.0...v12.1.0) (2024-01-06) 74 | 75 | 76 | ### Features 77 | 78 | * Add signoff option ([#120](https://github.com/absolute-version/commit-and-tag-version/issues/120)) ([d107e38](https://github.com/absolute-version/commit-and-tag-version/commit/d107e38eb906dfb21658d12803b7308f2e3dda7d)) 79 | 80 | ## [12.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.3.0...v12.0.0) (2023-10-31) 81 | 82 | 83 | ### ⚠ BREAKING CHANGES 84 | 85 | * Drop support for node 14, 16. Now supports node 18 and 20. 86 | 87 | ### Bug Fixes 88 | 89 | * Drop support for node 14, 16. Now supports node 18 and 20. ([b1a58bc](https://github.com/absolute-version/commit-and-tag-version/commit/b1a58bc2a786da48fbcec248204ff8631c79606e)) 90 | * preserve frontmatter when updating changelog ([#108](https://github.com/absolute-version/commit-and-tag-version/issues/108)) ([abdcfe2](https://github.com/absolute-version/commit-and-tag-version/commit/abdcfe295023f46c8724463940fff6a220434fad)) 91 | 92 | ## [11.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.4...v11.3.0) (2023-10-10) 93 | 94 | 95 | ### Features 96 | 97 | * **updater:** add .csproj file support ([#95](https://github.com/absolute-version/commit-and-tag-version/issues/95)) ([a96554c](https://github.com/absolute-version/commit-and-tag-version/commit/a96554c9467bacdf6c9d898b223883ee32f63c15)) 98 | 99 | ## [11.2.4](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.3...v11.2.4) (2023-10-02) 100 | 101 | 102 | ### Bug Fixes 103 | 104 | * allow bump task to handle versions with build metadata ([33913ee](https://github.com/absolute-version/commit-and-tag-version/commit/33913ee03bff2dfc26c9ffc942e1191c1f767949)) 105 | * handle invalid versions passed to releaseAs ([33913ee](https://github.com/absolute-version/commit-and-tag-version/commit/33913ee03bff2dfc26c9ffc942e1191c1f767949)) 106 | 107 | ## [11.2.3](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.2...v11.2.3) (2023-08-22) 108 | 109 | 110 | ### Bug Fixes 111 | 112 | * **bump:** propagate the parserOpts from args to conventionalRecommendedBump, fixing an issue with custom headerPatterns ([#89](https://github.com/absolute-version/commit-and-tag-version/issues/89)) ([bc685be](https://github.com/absolute-version/commit-and-tag-version/commit/bc685be46ca90417a03867717393bb9018e6036c)) 113 | 114 | ## [11.2.2](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.1...v11.2.2) (2023-06-18) 115 | 116 | 117 | ### Bug Fixes 118 | 119 | * **deps:** update dependency conventional-changelog-conventionalcommits to v6 ([285f5e7](https://github.com/absolute-version/commit-and-tag-version/commit/285f5e7c9d415c029fe6b6f4781f6ccfa71a0151)) 120 | * **deps:** update dependency conventional-changelog-conventionalcommits to v6 ([#81](https://github.com/absolute-version/commit-and-tag-version/issues/81)) ([ab67fa4](https://github.com/absolute-version/commit-and-tag-version/commit/ab67fa43b644f8078530ca7927054cd8cf5add77)) 121 | * **deps:** update dependency conventional-changelog-conventionalcommits to v6.1.0 ([39827d3](https://github.com/absolute-version/commit-and-tag-version/commit/39827d386ce8c3dbad7605ef872975ebe48db72a)) 122 | * **deps:** update dependency conventional-changelog-conventionalcommits to v6.1.0 ([#86](https://github.com/absolute-version/commit-and-tag-version/issues/86)) ([a8580d5](https://github.com/absolute-version/commit-and-tag-version/commit/a8580d5859c6c44ed82ac244eabad967eca0d4b8)) 123 | * **deps:** update dependency conventional-recommended-bump to v7 ([5978564](https://github.com/absolute-version/commit-and-tag-version/commit/59785644f2cd7980139c49086f3ba662f63a7179)) 124 | * **deps:** update dependency conventional-recommended-bump to v7 ([#83](https://github.com/absolute-version/commit-and-tag-version/issues/83)) ([1c9f82e](https://github.com/absolute-version/commit-and-tag-version/commit/1c9f82eca486dceda244d37f5264f992b9a5c57e)) 125 | * **deps:** update dependency git-semver-tags to v5 ([97e0237](https://github.com/absolute-version/commit-and-tag-version/commit/97e0237d645e1686f96418a1f2d8dbd6bfeca90b)) 126 | * **deps:** update dependency git-semver-tags to v5 ([#80](https://github.com/absolute-version/commit-and-tag-version/issues/80)) ([46ea506](https://github.com/absolute-version/commit-and-tag-version/commit/46ea506c5f2e5300f195462a6c2339cbe4b98fcb)) 127 | 128 | ## [11.2.1](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.0...v11.2.1) (2023-04-05) 129 | 130 | 131 | ### Bug Fixes 132 | 133 | * **dep:** add stringify-package to project source, removing the deprecation warning on npm install ([#65](https://github.com/absolute-version/commit-and-tag-version/issues/65)) ([3a959a7](https://github.com/absolute-version/commit-and-tag-version/commit/3a959a7eba86ad42b98592167df7c67f00b661a0)) 134 | 135 | ## [11.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.1.0...v11.2.0) (2023-03-15) 136 | 137 | 138 | ### Features 139 | 140 | * implement detect pm name ([174a8bd](https://github.com/absolute-version/commit-and-tag-version/commit/174a8bd00106dcc2a6b1c5bcb75bf3fbfd0317da)) 141 | * support config npmClient ([c33686a](https://github.com/absolute-version/commit-and-tag-version/commit/c33686aec080162645466ed962d64133f71e4214)) 142 | * Support customizing the npm publish hint message with a new option: `npmPublishHint` ([1f77110](https://github.com/absolute-version/commit-and-tag-version/commit/1f77110deefa8a394a37c421eb3d313f6c87aea5)) 143 | 144 | ## [11.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.0.0...v11.1.0) (2023-02-14) 145 | 146 | 147 | ### Features 148 | 149 | * Expose release count option ([40d27f8](https://github.com/absolute-version/commit-and-tag-version/commit/40d27f8782c0621f6ec0ab796b4ae674ec6d43c8)) 150 | * replace the changelog if releaseCount = 0 ([d18af90](https://github.com/absolute-version/commit-and-tag-version/commit/d18af9040fdc2a5798681fa747a43a71cb75e47b)) 151 | 152 | 153 | ### Bug Fixes 154 | 155 | * ensure git signatures are not present ([268800b](https://github.com/absolute-version/commit-and-tag-version/commit/268800b3c5e01993902cb0df0d123ac8b3388359)) 156 | 157 | ## [11.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v10.1.0...v11.0.0) (2023-01-17) 158 | 159 | 160 | ### ⚠ BREAKING CHANGES 161 | 162 | * **deps:** update dependency conventional-changelog-conventionalcommits to v5. This is technically a breaking change for anyone relying on the exact formatting of the changelog, as it ensures that versions are always written with H2 headers. 163 | 164 | ### Bug Fixes 165 | 166 | * **deps:** update dependency conventional-changelog-conventionalcommits to v5 ([b38e900](https://github.com/absolute-version/commit-and-tag-version/commit/b38e900c2b8577b492b4bb42e88d327e80e663a4)) 167 | * **deps:** update dependency conventional-changelog-conventionalcommits to v5. This is technically a breaking change for anyone relying on the exact formatting of the changelog, as it ensures that versions are always written with H2 headers. ([ffa799a](https://github.com/absolute-version/commit-and-tag-version/commit/ffa799aa335f9b912a224336cf2ea2537b8aa310)) 168 | 169 | ## [10.1.0](https://github.com/absolute-version/commit-and-tag-version/compare/v10.0.1...v10.1.0) (2022-08-11) 170 | 171 | 172 | ### Features 173 | 174 | * **options:** Expose parser and writer options from `conventional-commits-parser` and `conventional-commits-writer` ([185a461](https://github.com/absolute-version/commit-and-tag-version/commit/185a461acc1caf947bf78dd2185f4687afad66fc)) 175 | * **updater:** add Gradle support ([0cf439f](https://github.com/absolute-version/commit-and-tag-version/commit/0cf439fe4047ffa10d21196714c25517535b6302)) 176 | 177 | 178 | ### Bug Fixes 179 | 180 | * use correct param for dryRun check ([300b907](https://github.com/absolute-version/commit-and-tag-version/commit/300b90777c5c8c9cca15f69122af1d41981ca47d)) 181 | 182 | ### [10.0.1](https://github.com/absolute-version/commit-and-tag-version/compare/v10.0.0...v10.0.1) (2022-05-28) 183 | 184 | 185 | ### Bug Fixes 186 | 187 | * No longer warn inappropriately when a custom updater is provided as an object ([5eb8886](https://github.com/absolute-version/commit-and-tag-version/commit/5eb8886a56c6b14c13544192edb3d0e18f91184a)) 188 | 189 | ## [10.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v9.6.0...v10.0.0) (2022-05-25) 190 | 191 | 192 | ### ⚠ BREAKING CHANGES 193 | 194 | * Drop support for node 10 and 12, support node 16 and 18 195 | 196 | ### Bug Fixes 197 | 198 | * **deps:** update dependency yargs to v17 ([d190c51](https://github.com/absolute-version/commit-and-tag-version/commit/d190c51507026adefe640cdd75f0a643afd81b87)) 199 | 200 | 201 | ### Build System 202 | 203 | * Drop support for node 10 and 12, support node 16 and 18 ([0f75115](https://github.com/absolute-version/commit-and-tag-version/commit/0f751158c2df9cbf7a2c16bef55a5de084f0d17d)) 204 | 205 | ## [9.6.0](https://github.com/absolute-version/commit-and-tag-version/compare/v9.5.0...v9.6.0) (2022-05-25) 206 | 207 | 208 | ### Features 209 | 210 | * **tag:** add an option to force tag replacement ([df5a94a](https://github.com/absolute-version/commit-and-tag-version/commit/df5a94a978c6966e334ec0e4c9f082fae8deb4f9)) 211 | 212 | 213 | ### Bug Fixes 214 | 215 | * Combining both release-as and prerelease now doesn't break package ([5ecfa2e](https://github.com/absolute-version/commit-and-tag-version/commit/5ecfa2e250e134dbfd3ce8d3c6e9d3be28f6f2b8)) 216 | * Fallback to git tag if no version in package file ([57e7091](https://github.com/absolute-version/commit-and-tag-version/commit/57e70916c8afbce16347ed1f710984f5a483152a)) 217 | * No longer skips the commit if changelog and bump are both skipped but `commitAll` is set ([08a0121](https://github.com/absolute-version/commit-and-tag-version/commit/08a01212f0eea7ee5e454adf560755df67234d2f)) 218 | * Use relative path from .gitignore to avoid files matching inappropriately ([d2491bc](https://github.com/absolute-version/commit-and-tag-version/commit/d2491bc8b61a60cd438045ac409278f5b84621dd)) 219 | * When a custom updater reports a version other than the new computed semver, that version is now correctly reported in log output ([f2e83bf](https://github.com/absolute-version/commit-and-tag-version/commit/f2e83bfac711ac5ba4de940d654269af69fc7312)) 220 | 221 | ## [9.5.0](https://github.com/conventional-changelog/standard-version/compare/v9.4.0...v9.5.0) (2022-05-15) 222 | 223 | 224 | ### Features 225 | 226 | * **deprecated:** add deprecation message ([#907](https://github.com/conventional-changelog/standard-version/issues/907)) ([61b41fa](https://github.com/conventional-changelog/standard-version/commit/61b41fa47ef690f55b92e2edb82fe554e3c1e13a)) 227 | 228 | 229 | ### Bug Fixes 230 | 231 | * **deps:** update dependency conventional-changelog to v3.1.25 ([#865](https://github.com/conventional-changelog/standard-version/issues/865)) ([4c938a2](https://github.com/conventional-changelog/standard-version/commit/4c938a2baac11385d655144429bc73b2199bb027)) 232 | * **deps:** update dependency conventional-changelog-conventionalcommits to v4.6.3 ([#866](https://github.com/conventional-changelog/standard-version/issues/866)) ([6c75ed0](https://github.com/conventional-changelog/standard-version/commit/6c75ed0b1456913ae7e4d6fe8532fb4106df1bdf)) 233 | 234 | ## [9.4.0](https://github.com/conventional-changelog/standard-version/compare/v9.3.2...v9.4.0) (2021-12-31) 235 | 236 | 237 | ### Features 238 | 239 | * add .cjs config file ([#717](https://github.com/conventional-changelog/standard-version/issues/717)) ([eceaedf](https://github.com/conventional-changelog/standard-version/commit/eceaedf8b3cdeb282ee06bfa9c65503f42404858)) 240 | 241 | 242 | ### Bug Fixes 243 | 244 | * Ensures provided `packageFiles` arguments are merged with `bumpFiles` when no `bumpFiles` argument is specified (default). ([#534](https://github.com/conventional-changelog/standard-version/issues/534)) ([2785023](https://github.com/conventional-changelog/standard-version/commit/2785023c91668e7300e6a22e55d31b6bd9dae59b)), closes [#533](https://github.com/conventional-changelog/standard-version/issues/533) 245 | 246 | ### [9.3.2](https://www.github.com/conventional-changelog/standard-version/compare/v9.3.1...v9.3.2) (2021-10-17) 247 | 248 | 249 | ### Bug Fixes 250 | 251 | * **deps:** update dependency conventional-changelog-conventionalcommits to v4.6.1 ([#752](https://www.github.com/conventional-changelog/standard-version/issues/752)) ([bb8869d](https://www.github.com/conventional-changelog/standard-version/commit/bb8869de7d8bcace1ec92f29e389e7fab506d64e)) 252 | 253 | ### [9.3.1](https://www.github.com/conventional-changelog/standard-version/compare/v9.3.0...v9.3.1) (2021-07-14) 254 | 255 | 256 | ### Bug Fixes 257 | 258 | * **updater:** npm7 package lock's inner version not being updated ([#713](https://www.github.com/conventional-changelog/standard-version/issues/713)) ([a316dd0](https://www.github.com/conventional-changelog/standard-version/commit/a316dd02f5a7d8dee33d99370afda8738985bc10)) 259 | 260 | ## [9.3.0](https://www.github.com/conventional-changelog/standard-version/compare/v9.2.0...v9.3.0) (2021-05-04) 261 | 262 | 263 | ### Features 264 | 265 | * add --lerna-package flag used to extract tags in case of lerna repo ([#503](https://www.github.com/conventional-changelog/standard-version/issues/503)) ([f579ff0](https://www.github.com/conventional-changelog/standard-version/commit/f579ff08f386aaae022a395ed0dbec9af77a5d49)) 266 | 267 | ## [9.2.0](https://www.github.com/conventional-changelog/standard-version/compare/v9.1.1...v9.2.0) (2021-04-06) 268 | 269 | 270 | ### Features 271 | 272 | * allows seperate prefixTag version sequences ([#573](https://www.github.com/conventional-changelog/standard-version/issues/573)) ([3bbba02](https://www.github.com/conventional-changelog/standard-version/commit/3bbba025057ba40c3e15880fede2af851841165b)) 273 | 274 | ### [9.1.1](https://www.github.com/conventional-changelog/standard-version/compare/v9.1.0...v9.1.1) (2021-02-06) 275 | 276 | 277 | ### Bug Fixes 278 | 279 | * **deps:** update dependency conventional-recommended-bump to v6.1.0 ([#695](https://www.github.com/conventional-changelog/standard-version/issues/695)) ([65dd070](https://www.github.com/conventional-changelog/standard-version/commit/65dd070b9f01ffe1764e64ba739bc064b84f4129)) 280 | * **deps:** update dependency yargs to v16 ([#660](https://www.github.com/conventional-changelog/standard-version/issues/660)) ([f6a7430](https://www.github.com/conventional-changelog/standard-version/commit/f6a7430329919874e1e744ac5dca2f83bba355df)) 281 | 282 | ## [9.1.0](https://www.github.com/conventional-changelog/standard-version/compare/v9.0.0...v9.1.0) (2020-12-01) 283 | 284 | 285 | ### Features 286 | 287 | * support custom updater as object as well as path ([#630](https://www.github.com/conventional-changelog/standard-version/issues/630)) ([55bbde8](https://www.github.com/conventional-changelog/standard-version/commit/55bbde8476013de7a2f24bf29c7c12cb07f96e3f)) 288 | 289 | 290 | ### Bug Fixes 291 | 292 | * **deps:** update dependency conventional-changelog to v3.1.24 ([#677](https://www.github.com/conventional-changelog/standard-version/issues/677)) ([cc45036](https://www.github.com/conventional-changelog/standard-version/commit/cc45036d9960b6d83e0e850ccbbe8e8098d36ae6)) 293 | * **deps:** update dependency conventional-changelog-conventionalcommits to v4.5.0 ([#678](https://www.github.com/conventional-changelog/standard-version/issues/678)) ([6317d36](https://www.github.com/conventional-changelog/standard-version/commit/6317d36130767cfd85114ab9033a6f1ef110388d)) 294 | * **deps:** update dependency conventional-recommended-bump to v6.0.11 ([#679](https://www.github.com/conventional-changelog/standard-version/issues/679)) ([360789a](https://www.github.com/conventional-changelog/standard-version/commit/360789ab84957a67d3919cb28db1882cb68296fc)) 295 | * **deps:** update dependency find-up to v5 ([#651](https://www.github.com/conventional-changelog/standard-version/issues/651)) ([df8db83](https://www.github.com/conventional-changelog/standard-version/commit/df8db832327a751d5c62fe361b6ac2d2b5f66bf6)) 296 | 297 | ## [9.0.0](https://www.github.com/conventional-changelog/standard-version/compare/v8.0.2...v9.0.0) (2020-08-15) 298 | 299 | 300 | ### ⚠ BREAKING CHANGES 301 | 302 | * NodeJS@8 is no longer supported. (#612) 303 | 304 | ### Bug Fixes 305 | 306 | * **deps:** update dependency conventional-changelog to v3.1.23 ([#652](https://www.github.com/conventional-changelog/standard-version/issues/652)) ([00dd3c0](https://www.github.com/conventional-changelog/standard-version/commit/00dd3c01aab20d28a8bbd1e174e416d6c2b34d90)) 307 | * **deps:** update dependency conventional-changelog-conventionalcommits to v4.4.0 ([#650](https://www.github.com/conventional-changelog/standard-version/issues/650)) ([9f201a6](https://www.github.com/conventional-changelog/standard-version/commit/9f201a61bb50ec12053a04faccfaea20e44d6ff2)) 308 | * **deps:** update dependency conventional-recommended-bump to v6.0.10 ([#653](https://www.github.com/conventional-changelog/standard-version/issues/653)) ([c360d6a](https://www.github.com/conventional-changelog/standard-version/commit/c360d6a307909c6e571b29d4a329fd786b4d4543)) 309 | 310 | 311 | ### Build System 312 | 313 | * NodeJS@8 is no longer supported. ([#612](https://www.github.com/conventional-changelog/standard-version/issues/612)) ([05edef2](https://www.github.com/conventional-changelog/standard-version/commit/05edef2de79d8d4939a6e699ce0979ff8da12de9)) 314 | 315 | ### [8.0.2](https://www.github.com/conventional-changelog/standard-version/compare/v8.0.1...v8.0.2) (2020-07-14) 316 | 317 | 318 | ### Bug Fixes 319 | 320 | * Commit message and tag name is no longer enclosed in quotes. ([#619](https://www.github.com/conventional-changelog/standard-version/issues/619)) ([ae032bf](https://www.github.com/conventional-changelog/standard-version/commit/ae032bfa9268a0a14351b0d78b6deedee7891e3a)), closes [#621](https://www.github.com/conventional-changelog/standard-version/issues/621) [#620](https://www.github.com/conventional-changelog/standard-version/issues/620) 321 | 322 | ### [8.0.1](https://www.github.com/conventional-changelog/standard-version/compare/v8.0.0...v8.0.1) (2020-07-12) 323 | 324 | 325 | ### Bug Fixes 326 | 327 | * **deps:** update dependency conventional-changelog to v3.1.21 ([#586](https://www.github.com/conventional-changelog/standard-version/issues/586)) ([fd456c9](https://www.github.com/conventional-changelog/standard-version/commit/fd456c995f3f88497fbb912fb8aabb8a42d97dbb)) 328 | * **deps:** update dependency conventional-changelog-conventionalcommits to v4.3.0 ([#587](https://www.github.com/conventional-changelog/standard-version/issues/587)) ([b3b5eed](https://www.github.com/conventional-changelog/standard-version/commit/b3b5eedea3eaf062d74d1004a55a0a6b1e3ca6c6)) 329 | * **deps:** update dependency conventional-recommended-bump to v6.0.9 ([#588](https://www.github.com/conventional-changelog/standard-version/issues/588)) ([d4d2ac2](https://www.github.com/conventional-changelog/standard-version/commit/d4d2ac2a99c095227118da795e1c9e19d06c9a0a)) 330 | * **deps:** update dependency git-semver-tags to v4 ([#589](https://www.github.com/conventional-changelog/standard-version/issues/589)) ([a0f0e81](https://www.github.com/conventional-changelog/standard-version/commit/a0f0e813b2be4a2065600a19075fda4d6f331ef8)) 331 | * Vulnerability Report GHSL-2020-11101 ([9d978ac](https://www.github.com/conventional-changelog/standard-version/commit/9d978ac9d4f64be4c7b9d514712ab3757732d561)) 332 | 333 | ## [8.0.0](https://www.github.com/conventional-changelog/standard-version/compare/v7.1.0...v8.0.0) (2020-05-06) 334 | 335 | 336 | ### ⚠ BREAKING CHANGES 337 | 338 | * `composer.json` and `composer.lock` will no longer be read from or bumped by default. If you need to obtain a version or write a version to these files, please use `bumpFiles` and/or `packageFiles` options accordingly. 339 | 340 | ### Bug Fixes 341 | 342 | * composer.json and composer.lock have been removed from default package and bump files. ([c934f3a](https://www.github.com/conventional-changelog/standard-version/commit/c934f3a38da4e7234d9dba3b2405f3b7e4dc5aa8)), closes [#495](https://www.github.com/conventional-changelog/standard-version/issues/495) [#394](https://www.github.com/conventional-changelog/standard-version/issues/394) 343 | * **deps:** update dependency conventional-changelog to v3.1.18 ([#510](https://www.github.com/conventional-changelog/standard-version/issues/510)) ([e6aeb77](https://www.github.com/conventional-changelog/standard-version/commit/e6aeb779fe53ffed2a252e6cfd69cfcb786b9ef9)) 344 | * **deps:** update dependency yargs to v15.1.0 ([#518](https://www.github.com/conventional-changelog/standard-version/issues/518)) ([8f36f9e](https://www.github.com/conventional-changelog/standard-version/commit/8f36f9e073119fcbf5ad843237fb06a4ca42a0f9)) 345 | * **deps:** update dependency yargs to v15.3.1 ([#559](https://www.github.com/conventional-changelog/standard-version/issues/559)) ([d98cd46](https://www.github.com/conventional-changelog/standard-version/commit/d98cd4674b4d074c0b7f4d50d052ae618cf494c6)) 346 | 347 | ## [7.1.0](https://github.com/conventional-changelog/standard-version/compare/v7.0.1...v7.1.0) (2019-12-08) 348 | 349 | 350 | ### Features 351 | 352 | * 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)) 353 | * 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)) 354 | 355 | 356 | ### Bug Fixes 357 | 358 | * **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)) 359 | * **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)) 360 | * **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)) 361 | * **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)) 362 | * 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)) 363 | * **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)) 364 | * **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)) 365 | * **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)) 366 | * **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)) 367 | * **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)) 368 | 369 | ### [7.0.1](https://github.com/conventional-changelog/standard-version/compare/v7.0.0...v7.0.1) (2019-11-07) 370 | 371 | 372 | ### Bug Fixes 373 | 374 | * **deps:** update dependency conventional-changelog to v3.1.12 ([#463](https://github.com/conventional-changelog/standard-version/issues/463)) ([f04161a](https://github.com/conventional-changelog/standard-version/commit/f04161ae624705e68f9018d563e9f3c09ccf6f30)) 375 | * **deps:** update dependency conventional-changelog-config-spec to v2.1.0 ([#442](https://github.com/conventional-changelog/standard-version/issues/442)) ([a2c5747](https://github.com/conventional-changelog/standard-version/commit/a2c574735ac5a165a190661b7735ea284bdc7dda)) 376 | * **deps:** update dependency conventional-recommended-bump to v6.0.2 ([#462](https://github.com/conventional-changelog/standard-version/issues/462)) ([84bb581](https://github.com/conventional-changelog/standard-version/commit/84bb581209b50357761cbec45bb8253f6a182801)) 377 | * **deps:** update dependency stringify-package to v1.0.1 ([#459](https://github.com/conventional-changelog/standard-version/issues/459)) ([e06a835](https://github.com/conventional-changelog/standard-version/commit/e06a835c8296a92f4fa7c07f98057d765c1a91e5)) 378 | * **deps:** update dependency yargs to v14 ([#440](https://github.com/conventional-changelog/standard-version/issues/440)) ([fe37e73](https://github.com/conventional-changelog/standard-version/commit/fe37e7390760d8d16d1b94ca58d8123e292c46a8)) 379 | * **deps:** update dependency yargs to v14.2.0 ([#461](https://github.com/conventional-changelog/standard-version/issues/461)) ([fb21851](https://github.com/conventional-changelog/standard-version/commit/fb2185107a90ba4b9dc7c9c1d873ed1283706ac1)) 380 | 381 | ## [7.0.0](https://github.com/conventional-changelog/standard-version/compare/v6.0.1...v7.0.0) (2019-07-30) 382 | 383 | 384 | ### ⚠ BREAKING CHANGES 385 | 386 | * we were accepting .version.json as a config file, rather than .versionrc.json 387 | 388 | ### Bug Fixes 389 | 390 | * **bump:** transmit tag prefix argument to conventionalRecommendedBump ([#393](https://github.com/conventional-changelog/standard-version/issues/393)) ([8205222](https://github.com/conventional-changelog/standard-version/commit/8205222)) 391 | * **cli:** display only one, correct default for --preset flag ([#377](https://github.com/conventional-changelog/standard-version/issues/377)) ([d17fc81](https://github.com/conventional-changelog/standard-version/commit/d17fc81)) 392 | * **commit:** don't try to process and add changelog if skipped ([#318](https://github.com/conventional-changelog/standard-version/issues/318)) ([3e4fdec](https://github.com/conventional-changelog/standard-version/commit/3e4fdec)) 393 | * **deps:** update dependency conventional-changelog-config-spec to v2 ([#352](https://github.com/conventional-changelog/standard-version/issues/352)) ([f586844](https://github.com/conventional-changelog/standard-version/commit/f586844)) 394 | * **deps:** update dependency conventional-recommended-bump to v6 ([#417](https://github.com/conventional-changelog/standard-version/issues/417)) ([4c5cad1](https://github.com/conventional-changelog/standard-version/commit/4c5cad1)) 395 | * **deps:** update dependency find-up to v4 ([#355](https://github.com/conventional-changelog/standard-version/issues/355)) ([73b35f8](https://github.com/conventional-changelog/standard-version/commit/73b35f8)) 396 | * **deps:** update dependency find-up to v4.1.0 ([#383](https://github.com/conventional-changelog/standard-version/issues/383)) ([b621a4a](https://github.com/conventional-changelog/standard-version/commit/b621a4a)) 397 | * **deps:** update dependency git-semver-tags to v3 ([#418](https://github.com/conventional-changelog/standard-version/issues/418)) ([1ce3f4a](https://github.com/conventional-changelog/standard-version/commit/1ce3f4a)) 398 | * **deps:** update dependency semver to v6.3.0 ([#366](https://github.com/conventional-changelog/standard-version/issues/366)) ([cd866c7](https://github.com/conventional-changelog/standard-version/commit/cd866c7)) 399 | * **deps:** update dependency yargs to v13.3.0 ([#401](https://github.com/conventional-changelog/standard-version/issues/401)) ([3d0e8c7](https://github.com/conventional-changelog/standard-version/commit/3d0e8c7)) 400 | * adds support for `releaseCommitMessageFormat` ([#351](https://github.com/conventional-changelog/standard-version/issues/351)) ([a7133cc](https://github.com/conventional-changelog/standard-version/commit/a7133cc)) 401 | * stop suggesting npm publish if package.json was not updated ([#319](https://github.com/conventional-changelog/standard-version/issues/319)) ([a5ac845](https://github.com/conventional-changelog/standard-version/commit/a5ac845)) 402 | * Updates package.json to _actual_ supported (tested) NodeJS versions. ([#379](https://github.com/conventional-changelog/standard-version/issues/379)) ([15eec8a](https://github.com/conventional-changelog/standard-version/commit/15eec8a)) 403 | * **deps:** update dependency yargs to v13.2.4 ([#356](https://github.com/conventional-changelog/standard-version/issues/356)) ([00b2ce6](https://github.com/conventional-changelog/standard-version/commit/00b2ce6)) 404 | * update config file name in command based on README.md ([#357](https://github.com/conventional-changelog/standard-version/issues/357)) ([ce44dd2](https://github.com/conventional-changelog/standard-version/commit/ce44dd2)) 405 | 406 | ### [6.0.1](https://github.com/conventional-changelog/standard-version/compare/v6.0.0...v6.0.1) (2019-05-05) 407 | 408 | 409 | ### Bug Fixes 410 | 411 | * don't pass args to git rev-parse ([1ac72f7](https://github.com/conventional-changelog/standard-version/commit/1ac72f7)) 412 | 413 | 414 | 415 | ## [6.0.0](https://github.com/conventional-changelog/standard-version/compare/v5.0.2...v6.0.0) (2019-05-05) 416 | 417 | 418 | ### Bug Fixes 419 | 420 | * always pass version to changelog context ([#327](https://github.com/conventional-changelog/standard-version/issues/327)) ([00e3381](https://github.com/conventional-changelog/standard-version/commit/00e3381)) 421 | * **deps:** update dependency detect-indent to v6 ([#341](https://github.com/conventional-changelog/standard-version/issues/341)) ([234d9dd](https://github.com/conventional-changelog/standard-version/commit/234d9dd)) 422 | * **deps:** update dependency detect-newline to v3 ([#342](https://github.com/conventional-changelog/standard-version/issues/342)) ([02a6093](https://github.com/conventional-changelog/standard-version/commit/02a6093)) 423 | * **deps:** update dependency figures to v3 ([#343](https://github.com/conventional-changelog/standard-version/issues/343)) ([7208ded](https://github.com/conventional-changelog/standard-version/commit/7208ded)) 424 | * **deps:** update dependency semver to v6 ([#344](https://github.com/conventional-changelog/standard-version/issues/344)) ([c40487a](https://github.com/conventional-changelog/standard-version/commit/c40487a)) 425 | * **deps:** update dependency yargs to v13 ([#345](https://github.com/conventional-changelog/standard-version/issues/345)) ([b2c8e59](https://github.com/conventional-changelog/standard-version/commit/b2c8e59)) 426 | * prevent duplicate headers from being added ([#305](https://github.com/conventional-changelog/standard-version/issues/305)) ([#307](https://github.com/conventional-changelog/standard-version/issues/307)) ([db2c6e5](https://github.com/conventional-changelog/standard-version/commit/db2c6e5)) 427 | 428 | 429 | ### Build System 430 | 431 | * add renovate.json ([#273](https://github.com/conventional-changelog/standard-version/issues/273)) ([bf41474](https://github.com/conventional-changelog/standard-version/commit/bf41474)) 432 | * drop Node 6 from testing matrix ([#346](https://github.com/conventional-changelog/standard-version/issues/346)) ([6718428](https://github.com/conventional-changelog/standard-version/commit/6718428)) 433 | 434 | 435 | ### Features 436 | 437 | * adds configurable conventionalcommits preset ([#323](https://github.com/conventional-changelog/standard-version/issues/323)) ([4fcd4a7](https://github.com/conventional-changelog/standard-version/commit/4fcd4a7)) 438 | * allow a user to provide a custom changelog header ([#335](https://github.com/conventional-changelog/standard-version/issues/335)) ([1c51064](https://github.com/conventional-changelog/standard-version/commit/1c51064)) 439 | * bump minor rather than major, if release is < 1.0.0 ([#347](https://github.com/conventional-changelog/standard-version/issues/347)) ([5d972cf](https://github.com/conventional-changelog/standard-version/commit/5d972cf)) 440 | * suggest branch name other than master ([#331](https://github.com/conventional-changelog/standard-version/issues/331)) ([304b49a](https://github.com/conventional-changelog/standard-version/commit/304b49a)) 441 | * update commit msg for when using commitAll ([#320](https://github.com/conventional-changelog/standard-version/issues/320)) ([74a040a](https://github.com/conventional-changelog/standard-version/commit/74a040a)) 442 | 443 | 444 | ### Tests 445 | 446 | * disable gpg signing in temporary test repositories. ([#311](https://github.com/conventional-changelog/standard-version/issues/311)) ([bd0fcdf](https://github.com/conventional-changelog/standard-version/commit/bd0fcdf)) 447 | * use const based on new eslint rules ([#329](https://github.com/conventional-changelog/standard-version/issues/329)) ([b6d3d13](https://github.com/conventional-changelog/standard-version/commit/b6d3d13)) 448 | 449 | 450 | ### BREAKING CHANGES 451 | 452 | * we now bump the minor rather than major if version < 1.0.0; --release-as can be used to bump to 1.0.0. 453 | * tests are no longer run for Node 6 454 | * we now use the conventionalcommits preset by default, which directly tracks conventionalcommits.org. 455 | 456 | 457 | 458 | ## [5.0.2](https://github.com/conventional-changelog/standard-version/compare/v5.0.1...v5.0.2) (2019-03-16) 459 | 460 | 461 | 462 | ## [5.0.1](https://github.com/conventional-changelog/standard-version/compare/v5.0.0...v5.0.1) (2019-02-28) 463 | 464 | 465 | ### Bug Fixes 466 | 467 | * make pattern for finding CHANGELOG sections work for non anchors ([#292](https://github.com/conventional-changelog/standard-version/issues/292)) ([b684c78](https://github.com/conventional-changelog/standard-version/commit/b684c78)) 468 | 469 | 470 | 471 | # [5.0.0](https://github.com/conventional-changelog/standard-version/compare/v4.4.0...v5.0.0) (2019-02-14) 472 | 473 | 474 | ### Bug Fixes 475 | 476 | * bin now enforces Node.js > 4 ([#274](https://github.com/conventional-changelog/standard-version/issues/274)) ([e1b5780](https://github.com/conventional-changelog/standard-version/commit/e1b5780)) 477 | * no --tag prerelease for private module ([#296](https://github.com/conventional-changelog/standard-version/issues/296)) ([27e2ab4](https://github.com/conventional-changelog/standard-version/commit/27e2ab4)), closes [#294](https://github.com/conventional-changelog/standard-version/issues/294) 478 | * show correct pre-release tag in help output ([#259](https://github.com/conventional-changelog/standard-version/issues/259)) ([d90154a](https://github.com/conventional-changelog/standard-version/commit/d90154a)) 479 | 480 | 481 | ### chore 482 | 483 | * update testing matrix ([1d46627](https://github.com/conventional-changelog/standard-version/commit/1d46627)) 484 | 485 | 486 | ### Features 487 | 488 | * adds support for bumping for composer versions ([#262](https://github.com/conventional-changelog/standard-version/issues/262)) ([fee872f](https://github.com/conventional-changelog/standard-version/commit/fee872f)) 489 | * cli application accept path/preset option ([#279](https://github.com/conventional-changelog/standard-version/issues/279)) ([69c62cf](https://github.com/conventional-changelog/standard-version/commit/69c62cf)) 490 | * fallback to tags if no meta-information file found ([#275](https://github.com/conventional-changelog/standard-version/issues/275)) ([844cde6](https://github.com/conventional-changelog/standard-version/commit/844cde6)) 491 | * preserve formatting when writing to package.json ([#282](https://github.com/conventional-changelog/standard-version/issues/282)) ([96216da](https://github.com/conventional-changelog/standard-version/commit/96216da)) 492 | 493 | 494 | ### BREAKING CHANGES 495 | 496 | * if no package.json, bower.json, etc., is found, we now fallback to git tags 497 | * removed Node 4/5 from testing matrix 498 | 499 | 500 | 501 | 502 | # [4.4.0](https://github.com/conventional-changelog/standard-version/compare/v4.3.0...v4.4.0) (2018-05-21) 503 | 504 | 505 | ### Bug Fixes 506 | 507 | * show full tag name in checkpoint ([#241](https://github.com/conventional-changelog/standard-version/issues/241)) ([b4ed4f9](https://github.com/conventional-changelog/standard-version/commit/b4ed4f9)) 508 | * use tagPrefix in CHANGELOG lifecycle step ([#243](https://github.com/conventional-changelog/standard-version/issues/243)) ([a56c7ac](https://github.com/conventional-changelog/standard-version/commit/a56c7ac)) 509 | 510 | 511 | ### Features 512 | 513 | * add prerelease lifecycle script hook (closes [#217](https://github.com/conventional-changelog/standard-version/issues/217)) ([#234](https://github.com/conventional-changelog/standard-version/issues/234)) ([ba4e7f6](https://github.com/conventional-changelog/standard-version/commit/ba4e7f6)) 514 | * manifest.json support ([#236](https://github.com/conventional-changelog/standard-version/issues/236)) ([371d992](https://github.com/conventional-changelog/standard-version/commit/371d992)) 515 | 516 | 517 | 518 | 519 | # [4.3.0](https://github.com/conventional-changelog/standard-version/compare/v4.2.0...v4.3.0) (2018-01-03) 520 | 521 | 522 | ### Bug Fixes 523 | 524 | * recommend `--tag` prerelease for npm publish of prereleases ([#196](https://github.com/conventional-changelog/standard-version/issues/196)) ([709dae1](https://github.com/conventional-changelog/standard-version/commit/709dae1)), closes [#183](https://github.com/conventional-changelog/standard-version/issues/183) 525 | * use the `skip` default value for skip cli arg ([#211](https://github.com/conventional-changelog/standard-version/issues/211)) ([3fdd7fa](https://github.com/conventional-changelog/standard-version/commit/3fdd7fa)) 526 | 527 | 528 | ### Features 529 | 530 | * **format-commit-message:** support multiple %s in the message ([45fcad5](https://github.com/conventional-changelog/standard-version/commit/45fcad5)) 531 | * do not update/commit files in .gitignore ([#230](https://github.com/conventional-changelog/standard-version/issues/230)) ([4fd3bc2](https://github.com/conventional-changelog/standard-version/commit/4fd3bc2)) 532 | * publish only if commit+push succeed ([#229](https://github.com/conventional-changelog/standard-version/issues/229)) ([c5e1ee2](https://github.com/conventional-changelog/standard-version/commit/c5e1ee2)) 533 | 534 | 535 | 536 | 537 | # [4.2.0](https://github.com/conventional-changelog/standard-version/compare/v4.1.0...v4.2.0) (2017-06-12) 538 | 539 | 540 | ### Features 541 | 542 | * add support for `package-lock.json` ([#190](https://github.com/conventional-changelog/standard-version/issues/190)) ([bc0fc53](https://github.com/conventional-changelog/standard-version/commit/bc0fc53)) 543 | 544 | 545 | 546 | 547 | # [4.1.0](https://github.com/conventional-changelog/standard-version/compare/v4.0.0...v4.1.0) (2017-06-06) 548 | 549 | 550 | ### Features 551 | 552 | * **cli:** print error and don't run with node <4, closes [#124](https://github.com/conventional-changelog/standard-version/issues/124) ([d0d71a5](https://github.com/conventional-changelog/standard-version/commit/d0d71a5)) 553 | * add dry-run mode ([#187](https://github.com/conventional-changelog/standard-version/issues/187)) ([d073353](https://github.com/conventional-changelog/standard-version/commit/d073353)) 554 | * add prebump, postbump, precommit, lifecycle scripts ([#186](https://github.com/conventional-changelog/standard-version/issues/186)) ([dfd1d12](https://github.com/conventional-changelog/standard-version/commit/dfd1d12)) 555 | * add support for `npm-shrinkwrap.json` ([#185](https://github.com/conventional-changelog/standard-version/issues/185)) ([86af7fc](https://github.com/conventional-changelog/standard-version/commit/86af7fc)) 556 | * add support for skipping lifecycle steps, polish lifecycle work ([#188](https://github.com/conventional-changelog/standard-version/issues/188)) ([d31dcdb](https://github.com/conventional-changelog/standard-version/commit/d31dcdb)) 557 | * allow a version # to be provided for release-as, rather than just major, minor, patch. ([13eb9cd](https://github.com/conventional-changelog/standard-version/commit/13eb9cd)) 558 | 559 | 560 | 561 | 562 | # [4.0.0](https://github.com/conventional-changelog/standard-version/compare/v4.0.0-1...v4.0.0) (2016-12-02) 563 | 564 | 565 | ### Bug Fixes 566 | 567 | * 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)) 568 | * should print message before we bump version ([2894bbc](https://github.com/conventional-changelog/standard-version/commit/2894bbc)) 569 | * 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)) 570 | 571 | 572 | ### Features 573 | 574 | * add support for bumping version # in bower.json ([#148](https://github.com/conventional-changelog/standard-version/issues/148)) ([b788c5f](https://github.com/conventional-changelog/standard-version/commit/b788c5f)) 575 | * make tag prefix configurable ([#143](https://github.com/conventional-changelog/standard-version/issues/143)) ([70b20c8](https://github.com/conventional-changelog/standard-version/commit/70b20c8)) 576 | * 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)) 577 | 578 | 579 | ### BREAKING CHANGES 580 | 581 | * merge commits are now included in the CHANGELOG. 582 | 583 | 584 | 585 | # [3.0.0](https://github.com/conventional-changelog/standard-version/compare/v2.3.0...v3.0.0) (2016-10-06) 586 | 587 | 588 | ### Bug Fixes 589 | 590 | * 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)) 591 | * **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) 592 | 593 | 594 | ### Chores 595 | 596 | * package.json engines field >=4.0, drop Node 0.10 and 0.12 ([28ff65a](https://github.com/conventional-changelog/standard-version/commit/28ff65a)) 597 | 598 | 599 | ### Features 600 | 601 | * **options:** add --silent flag and option for squelching output ([2a3fa61](https://github.com/conventional-changelog/standard-version/commit/2a3fa61)) 602 | * 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)) 603 | * separate cli and defaults from base functionality ([34a6a4e](https://github.com/conventional-changelog/standard-version/commit/34a6a4e)) 604 | 605 | 606 | ### BREAKING CHANGES 607 | 608 | * drop support for Node < 4.0 to enable usage of 609 | new tools and packages. 610 | 611 | 612 | 613 | 614 | # [2.4.0](https://github.com/conventional-changelog/standard-version/compare/v2.3.1...v2.4.0) (2016-07-13) 615 | 616 | 617 | ### Bug Fixes 618 | 619 | * **index.js:** use blue figures.info for last checkpoint ([#64](https://github.com/conventional-changelog/standard-version/issues/64)) ([e600b42](https://github.com/conventional-changelog/standard-version/commit/e600b42)) 620 | 621 | 622 | ### Features 623 | 624 | * **changelogStream:** use more default opts ([#67](https://github.com/conventional-changelog/standard-version/issues/67)) ([3e0aa84](https://github.com/conventional-changelog/standard-version/commit/3e0aa84)) 625 | 626 | 627 | 628 | 629 | ## [2.3.1](https://github.com/conventional-changelog/standard-version/compare/v2.3.0...v2.3.1) (2016-06-15) 630 | 631 | 632 | ### Bug Fixes 633 | 634 | * **commit:** fix windows by separating add and commit exec ([#55](https://github.com/conventional-changelog/standard-version/issues/55)) ([f361c46](https://github.com/conventional-changelog/standard-version/commit/f361c46)), closes [#55](https://github.com/conventional-changelog/standard-version/issues/55) [#49](https://github.com/conventional-changelog/standard-version/issues/49) 635 | 636 | 637 | 638 | 639 | # [2.3.0](https://github.com/conventional-changelog/standard-version/compare/v2.2.1...v2.3.0) (2016-06-02) 640 | 641 | 642 | ### Bug Fixes 643 | 644 | * append line feed to end of package.json ([#42](https://github.com/conventional-changelog/standard-version/issues/42))([178e001](https://github.com/conventional-changelog/standard-version/commit/178e001)) 645 | 646 | 647 | ### Features 648 | 649 | * **index.js:** add checkpoint for publish script after tag successfully ([#47](https://github.com/conventional-changelog/standard-version/issues/47))([e414ed7](https://github.com/conventional-changelog/standard-version/commit/e414ed7)) 650 | * add a --no-verify option to prevent git hooks from being verified ([#44](https://github.com/conventional-changelog/standard-version/issues/44))([026d844](https://github.com/conventional-changelog/standard-version/commit/026d844)) 651 | 652 | 653 | 654 | 655 | ## [2.2.1](https://github.com/conventional-changelog/standard-version/compare/v2.2.0...v2.2.1) (2016-05-02) 656 | 657 | 658 | ### Bug Fixes 659 | 660 | * upgrade to version of nyc that works with new shelljs([c7ac6e2](https://github.com/conventional-changelog/standard-version/commit/c7ac6e2)) 661 | 662 | 663 | 664 | 665 | # [2.2.0](https://github.com/conventional-changelog/standard-version/compare/v2.1.2...v2.2.0) (2016-05-01) 666 | 667 | 668 | ### Bug Fixes 669 | 670 | * format the annotated tag message ([#28](https://github.com/conventional-changelog/standard-version/issues/28))([8f02736](https://github.com/conventional-changelog/standard-version/commit/8f02736)) 671 | * upgraded dependencies, switched back to angular format (fixes [#27](https://github.com/conventional-changelog/standard-version/issues/27)), pinned shelljs to version that works with nyc ([#30](https://github.com/conventional-changelog/standard-version/issues/30))([3f51e94](https://github.com/conventional-changelog/standard-version/commit/3f51e94)) 672 | 673 | 674 | ### Features 675 | 676 | * add --sign flag to sign git commit and tag ([#29](https://github.com/conventional-changelog/standard-version/issues/29))([de758bc](https://github.com/conventional-changelog/standard-version/commit/de758bc)) 677 | 678 | 679 | 680 | 681 | ## [2.1.2](https://github.com/conventional-changelog/standard-version/compare/v2.1.1...v2.1.2) (2016-04-11) 682 | 683 | 684 | ### Bug Fixes 685 | 686 | * we had too many \n characters ([#17](https://github.com/conventional-changelog/standard-version/issues/17)) ([67a01cd](https://github.com/conventional-changelog/standard-version/commit/67a01cd)) 687 | 688 | 689 | 690 | 691 | ## [2.1.1](https://github.com/conventional-changelog/standard-version/compare/v2.1.0...v2.1.1) (2016-04-10) 692 | 693 | 694 | ### Bug Fixes 695 | 696 | * **docs:** had a bad URL in package.json, which was breaking all of our links ([caa6359](https://github.com/conventional-changelog/standard-version/commit/caa6359)) 697 | 698 | 699 | 700 | 701 | # [2.1.0](https://github.com/conventional-changelog/standard-version/compare/v2.0.0...v2.1.0) (2016-04-10) 702 | 703 | 704 | ### Features 705 | 706 | * adds support for GitHub links (see [#13](https://github.com/conventional-changelog/standard-version/issues/13)), great idea [@bcoe](https://github.com/bcoe)! ([7bf6597](https://github.com/conventional-changelog/standard-version/commit/7bf6597)) 707 | 708 | 709 | 710 | 711 | # [2.0.0](https://github.com/conventional-changelog/standard-version/compare/v1.1.0...v2.0.0) (2016-04-09) 712 | 713 | 714 | * feat(conventional-changelog-standard): Move to conventional-changelog-standard style. This style lifts the character limit on commit messages, and puts us in a position to make more opinionated decisions in the future. ([c7ccadb](https://github.com/conventional-changelog/standard-version/commit/c7ccadb)) 715 | 716 | 717 | ### BREAKING CHANGES 718 | 719 | * we no longer accept the preset configuration option. 720 | 721 | 722 | 723 | # [1.1.0](https://github.com/conventional-changelog/standard-version/compare/v1.0.0...v1.1.0) (2016-04-08) 724 | 725 | 726 | ### Features 727 | 728 | * **cli:** use conventional default commit message with version ([9fadc5f](https://github.com/conventional-changelog/standard-version/commit/9fadc5f)) 729 | * **rebrand:** rebrand recommended-workflow to standard-version (#9) ([1f673c0](https://github.com/conventional-changelog/standard-version/commit/1f673c0)) 730 | * **tests:** adds test suite, fixed several Node 0.10 issues along the way ([03bd86c](https://github.com/conventional-changelog/standard-version/commit/03bd86c)) 731 | 732 | 733 | 734 | 735 | # 1.0.0 (2016-04-04) 736 | 737 | 738 | ### Features 739 | 740 | * **initial-release:** adds flag for generating CHANGELOG.md on the first release. ([b812b44](https://github.com/bcoe/conventional-recommended-workflow/commit/b812b44)) 741 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to `commit-and-tag-version` 2 | 3 | Thank you for considering contributing to `commit-and-tag-version`! Your help is greatly appreciated. 4 | 5 | ## How to Get Started 6 | 7 | 1. **Fork** this repository to your GitHub account. 8 | 2. **Clone** the forked repository to your local machine. 9 | 3. **Create** a new branch for your contributions. 10 | 4. **Make** your changes or additions. 11 | 5. **Push** the branch to your forked repository. 12 | 6. **Submit** a pull request and describe the changes made. 13 | 14 | ## Bug Reports 15 | 16 | If you encounter any bugs, please open an [issue](https://github.com/absolute-version/commit-and-tag-version/issues) and include: 17 | 18 | - A detailed description of the bug. 19 | - Steps to reproduce the bug. 20 | - Expected and actual behavior. 21 | - Your environment (OS, browser, etc.). 22 | 23 | ## Feature Requests 24 | 25 | To suggest new features or enhancements, please open an [issue](https://github.com/absolute-version/commit-and-tag-version/issues) with: 26 | 27 | - A clear and detailed description of the feature. 28 | - The problem it would solve or the use case it would address. 29 | - Any implementation suggestions. 30 | 31 | ## Pull Request Guidelines 32 | 33 | - Ensure your code adheres to the project’s coding standards. 34 | - Write tests for new features or bug fixes. 35 | - Update documentation as necessary. If there are user facing changes / new features, please ensure the `Readme.md` is updated 36 | - Provide a comprehensive description of your changes in the pull request. 37 | - Do not include `package.lock.json` modifications; only include `package.json`. Maintainers will be responsible to generate it. 38 | - Do not include multiple features in a single commit/PR 39 | - Please title the PR with [conventional commits](https://www.conventionalcommits.org/), as PRs are squash merged 40 | 41 | We look forward to your contributions and value your time and effort! 42 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2016, Contributors 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice 8 | appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 12 | OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE 13 | LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 14 | OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 15 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 16 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Commit and Tag Version 2 | 3 | > **`commit-and-tag-version` is a fork of `standard-version`**. Because of maintainer availability, `standard-version` was [deprecated on 15th May 2022](https://github.com/conventional-changelog/standard-version/pull/907). The previous maintainer recommends [release-please](https://github.com/googleapis/release-please) as an alternative for those who are using GitHub actions. This fork exists for those who can't switch to `release-please`, or who would like to continue using `standard-version`. 4 | 5 | > **`Can I simply swap the library to migrate?`** To migrate, you can drop in `commit-and-tag-version` in place of `standard-version`. There are no changes in 9.5.0, other than to add the package.json config key `commit-and-tag-version` (the previous configuration key `standard-version` will still work). 10.x drops support for deprecated node versions, 11.x is a formatting change if you're relying on the exact markdown format in the changelog, and 12.x drops support for node 14/16. 6 | 7 | > **`Why was it renamed commit-and-tag-version?`**. I didn't want to scope the package or name it `standard-version-fork`, and it was a good opportunity to make the purpose of the tool clearer. I also wanted to distinguish it from the other tool in this organisation, [`absolute-version`](https://github.com/absolute-version/absolute-version-js), which just prints version information for pre-releases. 8 | 9 | A utility for versioning using [semver](https://semver.org/) and CHANGELOG generation powered by [Conventional Commits](https://conventionalcommits.org). 10 | 11 | ![ci](https://github.com/absolute-version/commit-and-tag-version/workflows/ci/badge.svg) 12 | [![NPM version](https://img.shields.io/npm/v/commit-and-tag-version.svg)](https://www.npmjs.com/package/commit-and-tag-version) 13 | [![codecov](https://codecov.io/gh/absolute-version/commit-and-tag-version/branch/master/graph/badge.svg?token=J7zMN7vTTd)](https://codecov.io/gh/absolute-version/commit-and-tag-version) 14 | [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) 15 | [![Community slack](http://devtoolscommunity.herokuapp.com/badge.svg)](http://devtoolscommunity.herokuapp.com) 16 | 17 | _Having problems? Want to contribute? Join us on the [node-tooling community Slack](http://devtoolscommunity.herokuapp.com)_. 18 | 19 | - [Commit and Tag Version](#commit-and-tag-version) 20 | - [How It Works:](#how-it-works) 21 | - [`bumpFiles`, `packageFiles` and `updaters`](#bumpfiles-packagefiles-and-updaters) 22 | - [Maven Support (Java/Kotlin)](#maven-support-javakotlin) 23 | - [Gradle Support (Java/Kotlin)](#gradle-support-javakotlin) 24 | - [.NET Support](#net-support) 25 | - [YAML Support](#yaml-support) 26 | - [OpenAPI Support](#openapi-support) 27 | - [Python Support](#python-support) 28 | - [Installing `commit-and-tag-version`](#installing-commit-and-tag-version) 29 | - [As a local `npm run` script](#as-a-local-npm-run-script) 30 | - [As global `bin`](#as-global-bin) 31 | - [Using `npx`](#using-npx) 32 | - [Configuration](#configuration) 33 | - [Customizing CHANGELOG Generation](#customizing-changelog-generation) 34 | - [Deeper customization](#deeper-customization) 35 | - [CLI Usage](#cli-usage) 36 | - [First Release](#first-release) 37 | - [Cutting Releases](#cutting-releases) 38 | - [Release as a Pre-Release](#release-as-a-pre-release) 39 | - [Release as a Target Type Imperatively (`npm version`-like)](#release-as-a-target-type-imperatively-npm-version-like) 40 | - [Prevent Git Hooks](#prevent-git-hooks) 41 | - [Signing Commits and Tags](#signing-commits-and-tags) 42 | - [Lifecycle Scripts](#lifecycle-scripts) 43 | - [Skipping Lifecycle Steps](#skipping-lifecycle-steps) 44 | - [Committing Generated Artifacts in the Release Commit](#committing-generated-artifacts-in-the-release-commit) 45 | - [Dry Run Mode](#dry-run-mode) 46 | - [Prefix Tags](#prefix-tags) 47 | - [Tag replacement](#tag-replacement) 48 | - [Generate changelogs for old releases](#generate-changelogs-for-old-releases) 49 | - [CLI Help](#cli-help) 50 | - [Code Usage](#code-usage) 51 | - [FAQ](#faq) 52 | - [How is `commit-and-tag-version` different from `semantic-release`?](#how-is-commit-and-tag-version-different-from-semantic-release) 53 | - [Should I always squash commits when merging PRs?](#should-i-always-squash-commits-when-merging-prs) 54 | - [Can I use `commit-and-tag-version` for additional metadata files, languages or version files?](#can-i-use-commit-and-tag-version-for-additional-metadata-files-languages-or-version-files) 55 | - [Custom `updater`s](#custom-updaters) 56 | - [`readVersion(contents = string): string`](#readversioncontents--string-string) 57 | - [`writeVersion(contents = string, version: string): string`](#writeversioncontents--string-version-string-string) 58 | - [License](#license) 59 | 60 | 61 | ### How It Works 62 | 63 | 1. Follow the [Conventional Commits Specification](https://conventionalcommits.org) in your repository. 64 | 2. When you're ready to release, run `commit-and-tag-version`. 65 | 66 | `commit-and-tag-version` will then do the following: 67 | 68 | 1. Retrieve the current version of your repository by looking at `packageFiles`[[1]](#bumpfiles-packagefiles-and-updaters), falling back to the last `git tag`. 69 | 2. `bump` the version in `bumpFiles`[[1]](#bumpfiles-packagefiles-and-updaters) based on your commits. 70 | 3. Generates a `changelog` based on your commits (uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) under the hood). 71 | 4. Creates a new `commit` including your `bumpFiles`[[1]](#bumpfiles-packagefiles-and-updaters) and updated CHANGELOG. 72 | 5. Creates a new `tag` with the new version number. 73 | 74 | ### `bumpFiles`, `packageFiles` and `updaters` 75 | 76 | `commit-and-tag-version` uses a few key concepts for handling version bumping in your project. 77 | 78 | - **`packageFiles`** – User-defined files where versions can be read from _and_ be "bumped". 79 | - Examples: `package.json`, `manifest.json` 80 | - In most cases (including the default), `packageFiles` are a subset of `bumpFiles`. 81 | - **`bumpFiles`** – User-defined files where versions should be "bumped", but not explicitly read from. 82 | - Examples: `package-lock.json`, `npm-shrinkwrap.json` 83 | - **`updaters`** – Simple modules used for reading `packageFiles` and writing to `bumpFiles`. 84 | 85 | By default, `commit-and-tag-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. 86 | 87 | That said, if you find your self asking [How can I use commit-and-tag-version for additional metadata files, languages or version files?](#can-i-use-commit-and-tag-version-for-additional-metadata-files-languages-or-version-files) – these configuration options will help! 88 | 89 | ### Maven Support (Java/Kotlin) 90 | 91 | If you are using Maven, then just point to your `pom.xml` file. 92 | 93 | ```sh 94 | commit-and-tag-version --packageFiles pom.xml --bumpFiles pom.xml 95 | ``` 96 | 97 | ### Gradle Support (Java/Kotlin) 98 | 99 | If you are using Gradle, then just point to your `build.gradle` file (or `build.gradle.kts` if using Kotlin DSL). 100 | 101 | ```sh 102 | commit-and-tag-version --packageFiles build.gradle --bumpFiles build.gradle 103 | ``` 104 | 105 | ### .NET Support 106 | 107 | If you are using .NET with `.csproj` files. 108 | This is going to read and update only the `` tag in the file. 109 | 110 | ```sh 111 | commit-and-tag-version --packageFiles .csproj --bumpFiles .csproj 112 | ``` 113 | 114 | ### YAML Support 115 | 116 | If you are using YAML files. 117 | This is going to read and update only the `version:` tag in the file. 118 | 119 | ```sh 120 | commit-and-tag-version --packageFiles file.yaml --bumpFiles file.yaml 121 | ``` 122 | 123 | ### OpenAPI Support 124 | 125 | If you are using OpenAPI, then just point to your `openapi.yaml` file. 126 | 127 | ```sh 128 | commit-and-tag-version --packageFiles openapi.yaml --bumpFiles openapi.yaml 129 | ``` 130 | 131 | ### Python Support 132 | 133 | If you are using Python ***with Poetry***, then point to your `pyproject.toml` file. 134 | 135 | ```sh 136 | commit-and-tag-version --packageFiles pyproject.toml --bumpFiles pyproject.toml 137 | ``` 138 | 139 | ## Installing `commit-and-tag-version` 140 | 141 | ### As a local `npm run` script 142 | 143 | Install and add to `devDependencies`: 144 | 145 | ``` 146 | npm i --save-dev commit-and-tag-version 147 | ``` 148 | 149 | Add an [`npm run` script](https://docs.npmjs.com/cli/run-script) to your `package.json`: 150 | 151 | ```json 152 | { 153 | "scripts": { 154 | "release": "commit-and-tag-version" 155 | } 156 | } 157 | ``` 158 | 159 | Now you can use `npm run release` in place of `npm version`. 160 | 161 | This has the benefit of making your repo/package more portable, so that other developers can cut releases without having to globally install `commit-and-tag-version` on their machine. 162 | 163 | ### As global `bin` 164 | 165 | Install globally (add to your `PATH`): 166 | 167 | ``` 168 | npm i -g commit-and-tag-version 169 | ``` 170 | 171 | Now you can use `commit-and-tag-version` in place of `npm version`. 172 | 173 | This has the benefit of allowing you to use `commit-and-tag-version` on any repo/package without adding a dev dependency to each one. 174 | 175 | ### Using `npx` 176 | 177 | As of `npm@5.2.0`, `npx` is installed alongside `npm`. Using `npx` you can use `commit-and-tag-version` without having to keep a `package.json` file by running: `npx commit-and-tag-version`. 178 | 179 | This method is especially useful when using `commit-and-tag-version` in non-JavaScript projects. 180 | 181 | ## Configuration 182 | 183 | You can configure `commit-and-tag-version` either by: 184 | 185 | 1. Placing a `commit-and-tag-version` stanza in your `package.json` (assuming 186 | your project is JavaScript). 187 | 188 | > Note for users who have migrated to 189 | `commit-and-tag-version` from `standard-version`: the previous package.json configuration key of `standard-version` will still work. 190 | 191 | 2. Creating a `.versionrc`, `.versionrc.json` or `.versionrc.js`. 192 | 193 | - If you are using a `.versionrc.js` your default export must be a configuration object, or a function returning a configuration object. 194 | 195 | Any of the command line parameters accepted by `commit-and-tag-version` can instead 196 | be provided via configuration. Please refer to the [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec/) for details on available configuration options. 197 | 198 | ### Customizing CHANGELOG Generation 199 | 200 | By default, `commit-and-tag-version` uses the [conventionalcommits preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits). 201 | 202 | This preset adheres closely to the [conventionalcommits.org](https://www.conventionalcommits.org) specification. 203 | 204 | Suppose you're using GitLab, rather than GitHub, you might modify the following variables: 205 | 206 | - `commitUrlFormat`: the URL format of commit SHAs detected in commit messages. 207 | - `compareUrlFormat`: the URL format used to compare two tags. 208 | - `issueUrlFormat`: the URL format used to link to issues. 209 | 210 | Making these URLs match GitLab's format, rather than GitHub's. 211 | 212 | ### Deeper customization 213 | 214 | You can override both [parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser) and [writer](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer) options (they will be merged into the preset we just mentioned). As an example, to list commits in the order that they were committed: 215 | 216 | ```json 217 | { 218 | "commit-and-tag-version": { 219 | "writerOpts": { 220 | "commitsSort": false 221 | } 222 | } 223 | } 224 | ``` 225 | 226 | ## CLI Usage 227 | 228 | > **NOTE:** To pass nested configurations to the CLI without defining them in the `package.json` use dot notation as the parameters `e.g. --skip.changelog`. 229 | 230 | ### First Release 231 | 232 | To generate your changelog for your first release, simply do: 233 | 234 | ```sh 235 | # npm run script 236 | npm run release -- --first-release 237 | # global bin 238 | commit-and-tag-version --first-release 239 | # npx 240 | npx commit-and-tag-version --first-release 241 | ``` 242 | 243 | This will tag a release **without bumping the version `bumpFiles`[1]()**. 244 | 245 | When you are ready, push the git tag and `npm publish` your first release. \o/ 246 | 247 | ### Cutting Releases 248 | 249 | If you typically use `npm version` to cut a new release, do this instead: 250 | 251 | ```sh 252 | # npm run script 253 | npm run release 254 | # or global bin 255 | commit-and-tag-version 256 | ``` 257 | 258 | As long as your git commit messages are conventional and accurate, you no longer need to specify the semver type - and you get CHANGELOG generation for free! \o/ 259 | 260 | After you cut a release, you can push the new git tag and `npm publish` (or `npm publish --tag next`) when you're ready. 261 | 262 | ### Release as a Pre-Release 263 | 264 | Use the flag `--prerelease` to generate pre-releases: 265 | 266 | Suppose the last version of your code is `1.0.0`, and your code to be committed has patched changes. Run: 267 | 268 | ```bash 269 | # npm run script 270 | npm run release -- --prerelease 271 | ``` 272 | 273 | This will tag your version as: `1.0.1-0`. 274 | 275 | If you want to name the pre-release, you specify the name via `--prerelease `. 276 | 277 | For example, suppose your pre-release should contain the `alpha` prefix: 278 | 279 | ```bash 280 | # npm run script 281 | npm run release -- --prerelease alpha 282 | ``` 283 | 284 | This will tag the version as: `1.0.1-alpha.0` 285 | 286 | ### Release as a Target Type Imperatively (`npm version`-like) 287 | 288 | To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`. 289 | 290 | Suppose the last version of your code is `1.0.0`, you've only landed `fix:` commits, but 291 | you would like your next release to be a `minor`. Simply run the following: 292 | 293 | ```bash 294 | # npm run script 295 | npm run release -- --release-as minor 296 | # Or 297 | npm run release -- --release-as 1.1.0 298 | ``` 299 | 300 | You will get version `1.1.0` rather than what would be the auto-generated version `1.0.1`. 301 | 302 | > **NOTE:** you can combine `--release-as` and `--prerelease` to generate a release. This is useful when publishing experimental feature(s). 303 | 304 | ### Prevent Git Hooks 305 | 306 | If you use git hooks, like pre-commit, to test your code before committing, you can prevent hooks from being verified during the commit step by passing the `--no-verify` option: 307 | 308 | ```sh 309 | # npm run script 310 | npm run release -- --no-verify 311 | # or global bin 312 | commit-and-tag-version --no-verify 313 | ``` 314 | 315 | ### Signing Commits and Tags 316 | 317 | If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command. 318 | 319 | ### Signed-off-by trailer 320 | 321 | To add the "Signed-off-by" trailer to the commit message add the `--signoff` flag to your `commit-and-tag-version` command. 322 | 323 | ### Lifecycle Scripts 324 | 325 | `commit-and-tag-version` supports lifecycle scripts. These allow you to execute your 326 | own supplementary commands during the release. The following 327 | hooks are available and execute in the order documented: 328 | 329 | - `prerelease`: executed before anything happens. If the `prerelease` script returns a 330 | non-zero exit code, versioning will be aborted, but it has no other effect on the 331 | process. 332 | - `prebump`/`postbump`: executed before and after the version is bumped. If the `prebump` 333 | script returns a version #, it will be used rather than 334 | the version calculated by `commit-and-tag-version`. 335 | - `prechangelog`/`postchangelog`: executes before and after the CHANGELOG is generated. 336 | - `precommit`/`postcommit`: called before and after the commit step. 337 | - `pretag`/`posttag`: called before and after the tagging step. 338 | 339 | Simply add the following to your package.json to configure lifecycle scripts: 340 | 341 | ```json 342 | { 343 | "commit-and-tag-version": { 344 | "scripts": { 345 | "prebump": "echo 9.9.9" 346 | } 347 | } 348 | } 349 | ``` 350 | 351 | As an example to change from using GitHub to track your items to using your projects Jira use a 352 | `postchangelog` script to replace the url fragment containing '' 353 | with a link to your Jira - assuming you have already installed [replace](https://www.npmjs.com/package/replace) 354 | 355 | ```json 356 | { 357 | "commit-and-tag-version": { 358 | "scripts": { 359 | "postchangelog": "replace 'https://github.com/myproject/issues/' 'https://myjira/browse/' CHANGELOG.md" 360 | } 361 | } 362 | } 363 | ``` 364 | 365 | ### Skipping Lifecycle Steps 366 | 367 | You can skip any of the lifecycle steps (`bump`, `changelog`, `commit`, `tag`), 368 | by adding the following to your package.json: 369 | 370 | ```json 371 | { 372 | "commit-and-tag-version": { 373 | "skip": { 374 | "changelog": true 375 | } 376 | } 377 | } 378 | ``` 379 | 380 | ### Committing Generated Artifacts in the Release Commit 381 | 382 | If you want to commit generated artifacts in the release commit, 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: 383 | 384 | ```json 385 | { 386 | "commit-and-tag-version": { 387 | "scripts": { 388 | "prerelease": "webpack -p --bail && git add " 389 | } 390 | } 391 | } 392 | ``` 393 | 394 | ```json 395 | { 396 | "scripts": { 397 | "release": "commit-and-tag-version -a" 398 | } 399 | } 400 | ``` 401 | 402 | ### Dry Run Mode 403 | 404 | running `commit-and-tag-version` with the flag `--dry-run` allows you to see what 405 | commands would be run, without committing to git or updating files. 406 | 407 | ```sh 408 | # npm run script 409 | npm run release -- --dry-run 410 | # or global bin 411 | commit-and-tag-version --dry-run 412 | ``` 413 | 414 | ### Prefix Tags 415 | 416 | Tags are prefixed with `v` by default. If you would like to prefix your tags with something else, you can do so with the `-t` flag. 417 | 418 | ```sh 419 | commit-and-tag-version -t @scope/package\@ 420 | ``` 421 | 422 | This will prefix your tags to look something like `@scope/package@2.0.0` 423 | 424 | If you do not want to have any tag prefix you can use the `-t` flag and provide it with an **empty string** as value. 425 | 426 | > Note: simply -t or --tag-prefix without any value will fallback to the default 'v' 427 | 428 | ### Tag replacement 429 | 430 | If you've already run `commit-and-tag-version` when creating your release, you may want to alter the release content and changelog without bumping 431 | the version, by using `commit-and-tag-version --skip.bump`. By default, tagging with an already existing tag make `git` fails. 432 | You can add the `--tag-force` flag to make use of `-f` option when calling `git tag`, then the existing version tag will be replaced. 433 | 434 | ### Generate changelogs for old releases 435 | 436 | Normally only the changelog for the last release will be generated and prepended to the `changelog.md`. If you want to generate changelogs for previous releases you can do so by setting the `releaseCount` option like described [here](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core#releasecount). 437 | 438 | When setting releaseCount=0 the whole changelog gets regenerated and replaced. 439 | 440 | You can set the option either in the`.versionrc` file or inside `package.json` like below 441 | 442 | ```json 443 | //.versionrc 444 | { 445 | "releaseCount": 0 446 | } 447 | 448 | //package.json 449 | 450 | "commit-and-tag-version": { 451 | "releaseCount": 0 452 | } 453 | ``` 454 | 455 | ### CLI Help 456 | 457 | ```sh 458 | # npm run script 459 | npm run release -- --help 460 | # or global bin 461 | commit-and-tag-version --help 462 | ``` 463 | 464 | ## Code Usage 465 | 466 | ```js 467 | const commitAndTagVersion = require("commit-and-tag-version"); 468 | 469 | // Options are the same as command line, except camelCase 470 | // commitAndTagVersion returns a Promise 471 | commitAndTagVersion({ 472 | noVerify: true, 473 | infile: "docs/CHANGELOG.md", 474 | silent: true, 475 | }) 476 | .then(() => { 477 | // commit-and-tag-version is done 478 | }) 479 | .catch((err) => { 480 | console.error(`commit-and-tag-version failed with message: ${err.message}`); 481 | }); 482 | ``` 483 | 484 | _TIP: Use the `silent` option to prevent `commit-and-tag-version` from printing to the `console`._ 485 | 486 | ## FAQ 487 | 488 | ### How is `commit-and-tag-version` different from `semantic-release`? 489 | 490 | [`semantic-release`](https://github.com/semantic-release/semantic-release) is described as: 491 | 492 | > semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package. 493 | 494 | While both are based on the same foundation of structured commit messages, `commit-and-tag-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 `commit-and-tag-version` only affects your local git repo - it doesn't affect remote resources at all. After you run `commit-and-tag-version`, you can review your release state, correct mistakes and follow the release strategy that makes the most sense for your codebase. 495 | 496 | We think they are both fantastic tools, and we encourage folks to use `semantic-release` instead of `commit-and-tag-version` if it makes sense for their use-case. 497 | 498 | ### Should I always squash commits when merging PRs? 499 | 500 | The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**. 501 | 502 | 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. 503 | 504 | 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. 505 | 506 | 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. 507 | 508 | ### Can I use `commit-and-tag-version` for additional metadata files, languages or version files? 509 | 510 | You can configure multiple `bumpFiles` and `packageFiles`: 511 | 512 | 1. Specify a custom `bumpFile` "`filename`", this is the path to the file you want to "bump" 513 | 2. Specify the `bumpFile` "`updater`", this is _how_ the file will be bumped. 514 | a. If you're using a common type, you can use one of `commit-and-tag-version`'s built-in `updaters` by specifying a `type`. 515 | b. If your using an less-common version file, you can create your own `updater`. 516 | 517 | ```js 518 | // .versionrc 519 | { 520 | "bumpFiles": [ 521 | { 522 | "filename": "MY_VERSION_TRACKER.txt", 523 | // The `plain-text` updater assumes the file contents represents the version. 524 | "type": "plain-text" 525 | }, 526 | { 527 | "filename": "a/deep/package/dot/json/file/package.json", 528 | // The `json` updater assumes the version is available under a `version` key in the provided JSON document. 529 | "type": "json" 530 | }, 531 | { 532 | "filename": "VERSION_TRACKER.json", 533 | // See "Custom `updater`s" for more details. 534 | "updater": "commit-and-tag-version-updater.js" 535 | } 536 | ] 537 | } 538 | ``` 539 | 540 | If using `.versionrc.js` as your configuration file, the `updater` may also be set as an object, rather than a path: 541 | 542 | ```js 543 | // .versionrc.js 544 | const tracker = { 545 | filename: "VERSION_TRACKER.json", 546 | updater: require("./path/to/custom-version-updater"), 547 | }; 548 | 549 | module.exports = { 550 | bumpFiles: [tracker], 551 | packageFiles: [tracker], 552 | }; 553 | ``` 554 | 555 | #### Custom `updater`s 556 | 557 | An `updater` is expected to be a Javascript module with _atleast_ two methods exposed: `readVersion` and `writeVersion`. 558 | 559 | ##### `readVersion(contents = string): string` 560 | 561 | This method is used to read the version from the provided file contents. 562 | 563 | The return value is expected to be a semantic version string. 564 | 565 | ##### `writeVersion(contents = string, version: string): string` 566 | 567 | This method is used to write the version to the provided contents. 568 | 569 | The return value will be written directly (overwrite) to the provided file. 570 | 571 | --- 572 | 573 | Let's assume our `VERSION_TRACKER.json` has the following contents: 574 | 575 | ```json 576 | { 577 | "tracker": { 578 | "package": { 579 | "version": "1.0.0" 580 | } 581 | } 582 | } 583 | ``` 584 | 585 | An acceptable `commit-and-tag-version-updater.js` would be: 586 | 587 | ```js 588 | // commit-and-tag-version-updater.js 589 | const stringifyPackage = require("stringify-package"); 590 | const detectIndent = require("detect-indent"); 591 | const detectNewline = require("detect-newline"); 592 | 593 | module.exports.readVersion = function (contents) { 594 | return JSON.parse(contents).tracker.package.version; 595 | }; 596 | 597 | module.exports.writeVersion = function (contents, version) { 598 | const json = JSON.parse(contents); 599 | let indent = detectIndent(contents).indent; 600 | let newline = detectNewline(contents); 601 | json.tracker.package.version = version; 602 | return stringifyPackage(json, indent, newline); 603 | }; 604 | ``` 605 | 606 | ### Why do breaking changes before 1.0.0 not trigger a 1.0.0 release? 607 | 608 | Below 1.0.0, the semver specification doesn't give any guarantees about the 609 | meaning of version numbers. However, with npm there is a community convention, 610 | and implementation-defined behaviour: If your version is between 0.1.0 and 611 | 1.0.0, npm treats an update to the minor version as a breaking change - that is 612 | ^0.1.0 will match 0.1.2 but not 0.2.0. Rust's cargo package manager also behaves 613 | the same way. 614 | 615 | This tool (via conventional-commits) also follows that convention - breaking 616 | changes below v1.0.0 are treated as a minor version bump. Here's an example 617 | series of commits with tagged versions: 618 | 619 | ``` 620 | 1017b00 chore: initial commit 621 | 9e2ba95 (tag: v0.0.2) chore(release): 0.0.2 622 | 3598012 fix!: Example breaking change 623 | 1a4994a (tag: v0.1.0) chore(release): 0.1.0 624 | ``` 625 | 626 | Semver's only guarantee is "all bets are off", but npm has made a choice about 627 | what bets to make. `commit-and-tag-version` follows the same convention (along 628 | with other package managers for other ecosystems). 629 | 630 | When you are ready to release v1.0.0, add `--release-as 1.0.0` to the options. 631 | 632 | ### Why do my `refactor`, `chore` etc changes not appear in the changelog? 633 | 634 | By default, the conventional commits preset is used. This means that only `fix`, `feat` and anything marked as a breaking change will appear in the changelog. 635 | 636 | Conventional commits is meant to make it easy for machines to reason about the user-facing changes, 637 | and the changelog generation makes it easy for humans to consume this information too. 638 | Usually, you wouldn't want non-user facing changes like refactor in the changelog. 639 | 640 | ## License 641 | 642 | ISC 643 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* istanbul ignore if */ 4 | if (process.version.match(/v(\d+)\./)[1] < 6) { 5 | console.error( 6 | 'commit-and-tag-version: Node v6 or greater is required. `commit-and-tag-version` did not run.', 7 | ); 8 | } else { 9 | const standardVersion = require('../index'); 10 | const cmdParser = require('../command'); 11 | standardVersion(cmdParser.argv).catch(() => { 12 | process.exit(1); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /command.js: -------------------------------------------------------------------------------- 1 | const spec = require('conventional-changelog-config-spec'); 2 | const { getConfiguration } = require('./lib/configuration'); 3 | const defaults = require('./defaults'); 4 | 5 | const yargs = require('yargs') 6 | .usage('Usage: $0 [options]') 7 | .option('packageFiles', { 8 | default: defaults.packageFiles, 9 | array: true, 10 | }) 11 | .option('bumpFiles', { 12 | default: defaults.bumpFiles, 13 | array: true, 14 | }) 15 | .option('release-as', { 16 | alias: 'r', 17 | describe: 18 | 'Specify the release type manually (like npm version )', 19 | requiresArg: true, 20 | string: true, 21 | }) 22 | .option('prerelease', { 23 | alias: 'p', 24 | describe: 25 | 'make a pre-release with optional option value to specify a tag id', 26 | string: true, 27 | }) 28 | .option('infile', { 29 | alias: 'i', 30 | describe: 'Read the CHANGELOG from this file', 31 | default: defaults.infile, 32 | }) 33 | .option('message', { 34 | alias: ['m'], 35 | describe: 36 | '[DEPRECATED] Commit message, replaces %s with new version.\nThis option will be removed in the next major version, please use --releaseCommitMessageFormat.', 37 | type: 'string', 38 | }) 39 | .option('first-release', { 40 | alias: 'f', 41 | describe: 'Is this the first release?', 42 | type: 'boolean', 43 | default: defaults.firstRelease, 44 | }) 45 | .option('sign', { 46 | alias: 's', 47 | describe: 'Should the git commit and tag be signed?', 48 | type: 'boolean', 49 | default: defaults.sign, 50 | }) 51 | .option('signoff', { 52 | describe: 'Should the git commit have a "Signed-off-by" trailer', 53 | type: 'boolean', 54 | default: defaults.signoff, 55 | }) 56 | .option('no-verify', { 57 | alias: 'n', 58 | describe: 59 | 'Bypass pre-commit or commit-msg git hooks during the commit phase', 60 | type: 'boolean', 61 | default: defaults.noVerify, 62 | }) 63 | .option('commit-all', { 64 | alias: 'a', 65 | describe: 66 | 'Commit all staged changes, not just files affected by commit-and-tag-version', 67 | type: 'boolean', 68 | default: defaults.commitAll, 69 | }) 70 | .option('silent', { 71 | describe: "Don't print logs and errors", 72 | type: 'boolean', 73 | default: defaults.silent, 74 | }) 75 | .option('tag-prefix', { 76 | alias: 't', 77 | describe: 'Set a custom prefix for the git tag to be created', 78 | type: 'string', 79 | default: defaults.tagPrefix, 80 | }) 81 | .option('release-count', { 82 | describe: 83 | 'How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all.', 84 | type: 'number', 85 | default: defaults.releaseCount, 86 | }) 87 | .option('tag-force', { 88 | describe: 'Allow tag replacement', 89 | type: 'boolean', 90 | default: defaults.tagForce, 91 | }) 92 | .option('scripts', { 93 | describe: 94 | 'Provide scripts to execute for lifecycle events (prebump, precommit, etc.,)', 95 | default: defaults.scripts, 96 | }) 97 | .option('skip', { 98 | describe: 'Map of steps in the release process that should be skipped', 99 | default: defaults.skip, 100 | }) 101 | .option('dry-run', { 102 | type: 'boolean', 103 | default: defaults.dryRun, 104 | describe: 'See the commands that running commit-and-tag-version would run', 105 | }) 106 | .option('git-tag-fallback', { 107 | type: 'boolean', 108 | default: defaults.gitTagFallback, 109 | describe: 110 | 'fallback to git tags for version, if no meta-information file is found (e.g., package.json)', 111 | }) 112 | .option('path', { 113 | type: 'string', 114 | describe: 'Only populate commits made under this path', 115 | }) 116 | .option('changelogHeader', { 117 | type: 'string', 118 | describe: 119 | '[DEPRECATED] Use a custom header when generating and updating changelog.\nThis option will be removed in the next major version, please use --header.', 120 | }) 121 | .option('preset', { 122 | type: 'string', 123 | default: defaults.preset, 124 | describe: 'Commit message guideline preset', 125 | }) 126 | .option('lerna-package', { 127 | type: 'string', 128 | describe: 'Name of the package from which the tags will be extracted', 129 | }) 130 | .option('npmPublishHint', { 131 | type: 'string', 132 | default: defaults.npmPublishHint, 133 | describe: 'Customized publishing hint', 134 | }) 135 | .check((argv) => { 136 | if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) { 137 | throw Error('scripts must be an object'); 138 | } else if (typeof argv.skip !== 'object' || Array.isArray(argv.skip)) { 139 | throw Error('skip must be an object'); 140 | } else { 141 | return true; 142 | } 143 | }) 144 | .alias('version', 'v') 145 | .alias('help', 'h') 146 | .example('$0', 'Update changelog and tag release') 147 | .example( 148 | '$0 -m "%s: see changelog for details"', 149 | 'Update changelog and tag release with custom commit message', 150 | ) 151 | .pkgConf('standard-version') 152 | .pkgConf('commit-and-tag-version') 153 | .config(getConfiguration()) 154 | .wrap(97); 155 | 156 | Object.keys(spec.properties).forEach((propertyKey) => { 157 | const property = spec.properties[propertyKey]; 158 | yargs.option(propertyKey, { 159 | type: property.type, 160 | describe: property.description, 161 | default: defaults[propertyKey] ? defaults[propertyKey] : property.default, 162 | group: 'Preset Configuration:', 163 | }); 164 | }); 165 | 166 | module.exports = yargs; 167 | -------------------------------------------------------------------------------- /defaults.js: -------------------------------------------------------------------------------- 1 | const spec = require('conventional-changelog-config-spec'); 2 | 3 | const defaults = { 4 | infile: 'CHANGELOG.md', 5 | firstRelease: false, 6 | sign: false, 7 | signoff: false, 8 | noVerify: false, 9 | commitAll: false, 10 | silent: false, 11 | tagPrefix: 'v', 12 | releaseCount: 1, 13 | scripts: {}, 14 | skip: {}, 15 | dryRun: false, 16 | tagForce: false, 17 | gitTagFallback: true, 18 | preset: require.resolve('conventional-changelog-conventionalcommits'), 19 | npmPublishHint: undefined, 20 | }; 21 | 22 | /** 23 | * Merge in defaults provided by the spec 24 | */ 25 | Object.keys(spec.properties).forEach((propertyKey) => { 26 | const property = spec.properties[propertyKey]; 27 | defaults[propertyKey] = property.default; 28 | }); 29 | 30 | /** 31 | * Sets the default for `header` (provided by the spec) for backwards 32 | * compatibility. This should be removed in the next major version. 33 | */ 34 | defaults.header = 35 | '# Changelog\n\nAll notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.\n'; 36 | 37 | defaults.packageFiles = ['package.json', 'bower.json', 'manifest.json']; 38 | 39 | defaults.bumpFiles = defaults.packageFiles.concat([ 40 | 'package-lock.json', 41 | 'npm-shrinkwrap.json', 42 | ]); 43 | 44 | module.exports = defaults; 45 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import js from "@eslint/js"; 3 | import jest from "eslint-plugin-jest"; 4 | import eslintConfigPrettier from "eslint-config-prettier"; 5 | 6 | /** 7 | * @type {import("eslint").Linter.Config} 8 | */ 9 | export default [ 10 | { 11 | "ignores": [".git/", ".github/", ".husky/", ".scannerwork/", ".vscode/", "coverage/", "node_modules/"], 12 | "name": "Files to ignore" 13 | }, 14 | { 15 | ...eslintConfigPrettier, 16 | "name": "Prettier" 17 | }, 18 | { 19 | ...js.configs.recommended, 20 | "files": ["**/*.{js,cjs,mjs}"], 21 | "languageOptions": { 22 | "ecmaVersion": 2023 23 | }, 24 | "name": "JavaScript files", 25 | "rules": { 26 | ...js.configs.recommended.rules, 27 | "no-var": "error", 28 | "no-unused-vars": [ 29 | "error", 30 | { 31 | "argsIgnorePattern": "_.*" 32 | } 33 | ] 34 | } 35 | }, 36 | { 37 | "files": ["**/*.mjs"], 38 | "languageOptions": { 39 | "sourceType": "module" 40 | }, 41 | "name": "JavaScript modules" 42 | }, 43 | { 44 | "files": ["**/*.{js,cjs,mjs}"], 45 | "languageOptions": { 46 | "globals": { 47 | ...globals.node 48 | } 49 | }, 50 | "name": "Node.js files" 51 | }, 52 | { 53 | ...jest.configs["flat/recommended"], 54 | "files": ["test/**/*{spec,test}.{js,cjs,mjs}", "test/mocks/jest-mocks.js"], 55 | "languageOptions": { 56 | "globals": { 57 | ...globals.jest 58 | } 59 | }, 60 | "name": "Test files", 61 | "rules": { 62 | ...jest.configs["flat/recommended"].rules, 63 | "jest/prefer-expect-assertions": "off", 64 | "jest/expect-expect": "off" 65 | } 66 | } 67 | ]; 68 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const bump = require('./lib/lifecycles/bump'); 2 | const changelog = require('./lib/lifecycles/changelog'); 3 | const commit = require('./lib/lifecycles/commit'); 4 | const fs = require('fs'); 5 | const latestSemverTag = require('./lib/latest-semver-tag'); 6 | const path = require('path'); 7 | const printError = require('./lib/print-error'); 8 | const tag = require('./lib/lifecycles/tag'); 9 | const { resolveUpdaterObjectFromArgument } = require('./lib/updaters'); 10 | 11 | module.exports = async function standardVersion(argv) { 12 | const defaults = require('./defaults'); 13 | /** 14 | * `--message` (`-m`) support will be removed in the next major version. 15 | */ 16 | const message = argv.m || argv.message; 17 | if (message) { 18 | /** 19 | * The `--message` flag uses `%s` for version substitutions, we swap this 20 | * for the substitution defined in the config-spec for future-proofing upstream 21 | * handling. 22 | */ 23 | argv.releaseCommitMessageFormat = message.replace(/%s/g, '{{currentTag}}'); 24 | if (!argv.silent) { 25 | console.warn( 26 | '[commit-and-tag-version]: --message (-m) will be removed in the next major release. Use --releaseCommitMessageFormat.', 27 | ); 28 | } 29 | } 30 | 31 | if (argv.changelogHeader) { 32 | argv.header = argv.changelogHeader; 33 | if (!argv.silent) { 34 | console.warn( 35 | '[commit-and-tag-version]: --changelogHeader will be removed in the next major release. Use --header.', 36 | ); 37 | } 38 | } 39 | 40 | if ( 41 | argv.header && 42 | argv.header.search(changelog.START_OF_LAST_RELEASE_PATTERN) !== -1 43 | ) { 44 | throw Error( 45 | `custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`, 46 | ); 47 | } 48 | 49 | /** 50 | * If an argument for `packageFiles` provided, we include it as a "default" `bumpFile`. 51 | */ 52 | if (argv.packageFiles) { 53 | defaults.bumpFiles = defaults.bumpFiles.concat(argv.packageFiles); 54 | } 55 | 56 | const args = Object.assign({}, defaults, argv); 57 | let pkg; 58 | for (const packageFile of args.packageFiles) { 59 | const updater = resolveUpdaterObjectFromArgument(packageFile); 60 | if (!updater) return; 61 | const pkgPath = path.resolve(process.cwd(), updater.filename); 62 | try { 63 | const contents = fs.readFileSync(pkgPath, 'utf8'); 64 | pkg = { 65 | version: updater.updater.readVersion(contents), 66 | private: 67 | typeof updater.updater.isPrivate === 'function' 68 | ? updater.updater.isPrivate(contents) 69 | : false, 70 | }; 71 | break; 72 | // eslint-disable-next-line no-unused-vars 73 | } catch (err) { 74 | /* This probably shouldn't be empty? */ 75 | } 76 | } 77 | try { 78 | let version; 79 | if (pkg && pkg.version) { 80 | version = pkg.version; 81 | } else if (args.gitTagFallback) { 82 | version = await latestSemverTag(args); 83 | } else { 84 | throw new Error('no package file found'); 85 | } 86 | 87 | const newVersion = await bump(args, version); 88 | await changelog(args, newVersion); 89 | await commit(args, newVersion); 90 | await tag(newVersion, pkg ? pkg.private : false, args); 91 | } catch (err) { 92 | printError(args, err.message); 93 | throw err; 94 | } 95 | }; 96 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | collectCoverage: true, 3 | collectCoverageFrom: [ 4 | '**/*.{js,jsx,ts}', 5 | '!**/node_modules/**', 6 | '!**/tmp/**', 7 | '!**/test/**', 8 | '!**/coverage/**', 9 | '!**/bin/**', 10 | ], 11 | coverageReporters: ['lcov', 'text'], 12 | projects: [ 13 | { 14 | displayName: 'Unit Test', 15 | testMatch: ['**/test/*.spec.js'], 16 | }, 17 | { 18 | displayName: 'Integration Test', 19 | runner: 'jest-serial-runner', 20 | testMatch: ['**/test/*.integration-test.js'], 21 | }, 22 | ], 23 | silent: true, // Suppresses runtime console logs during test runs 24 | testTimeout: 30000, 25 | verbose: true, // Prints test describe/it names into console during test runs 26 | }; 27 | 28 | module.exports = config; 29 | -------------------------------------------------------------------------------- /lib/checkpoint.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const figures = require('figures'); 3 | const util = require('util'); 4 | 5 | module.exports = function (argv, msg, args, figure) { 6 | const defaultFigure = argv.dryRun 7 | ? chalk.yellow(figures.tick) 8 | : chalk.green(figures.tick); 9 | if (!argv.silent) { 10 | console.info( 11 | (figure || defaultFigure) + 12 | ' ' + 13 | util.format.apply( 14 | util, 15 | [msg].concat( 16 | args.map(function (arg) { 17 | return chalk.bold(arg); 18 | }), 19 | ), 20 | ), 21 | ); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/configuration.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const findUp = require('find-up'); 3 | const { readFileSync } = require('fs'); 4 | 5 | const CONFIGURATION_FILES = [ 6 | '.versionrc', 7 | '.versionrc.cjs', 8 | '.versionrc.json', 9 | '.versionrc.js', 10 | ]; 11 | 12 | module.exports.getConfiguration = function () { 13 | let config = {}; 14 | const configPath = findUp.sync(CONFIGURATION_FILES); 15 | if (!configPath) { 16 | return config; 17 | } 18 | const ext = path.extname(configPath); 19 | if (ext === '.js' || ext === '.cjs') { 20 | const jsConfiguration = require(configPath); 21 | if (typeof jsConfiguration === 'function') { 22 | config = jsConfiguration(); 23 | } else { 24 | config = jsConfiguration; 25 | } 26 | } else { 27 | config = JSON.parse(readFileSync(configPath)); 28 | } 29 | 30 | /** 31 | * @todo we could eventually have deeper validation of the configuration (using `ajv`) and 32 | * provide a more helpful error. 33 | */ 34 | if (typeof config !== 'object') { 35 | throw Error( 36 | `[commit-and-tag-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`, 37 | ); 38 | } 39 | 40 | return config; 41 | }; 42 | -------------------------------------------------------------------------------- /lib/detect-package-manager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * modified from 3 | * the original code is licensed under MIT 4 | * modified to support only detecting lock file and not detecting global package manager 5 | */ 6 | 7 | const { promises: fs } = require('fs'); 8 | const { resolve } = require('path'); 9 | 10 | /** 11 | * Check if a path exists 12 | */ 13 | async function pathExists(p) { 14 | try { 15 | await fs.access(p); 16 | return true; 17 | } catch { 18 | return false; 19 | } 20 | } 21 | 22 | function getTypeofLockFile(cwd = '.') { 23 | return Promise.all([ 24 | pathExists(resolve(cwd, 'yarn.lock')), 25 | pathExists(resolve(cwd, 'package-lock.json')), 26 | pathExists(resolve(cwd, 'pnpm-lock.yaml')), 27 | ]).then(([isYarn, isNpm, isPnpm]) => { 28 | let value = null; 29 | 30 | if (isYarn) { 31 | value = 'yarn'; 32 | } else if (isPnpm) { 33 | value = 'pnpm'; 34 | } else if (isNpm) { 35 | value = 'npm'; 36 | } 37 | 38 | return value; 39 | }); 40 | } 41 | 42 | const detectPMByLockFile = async (cwd) => { 43 | const type = await getTypeofLockFile(cwd); 44 | if (type) { 45 | return type; 46 | } 47 | 48 | return 'npm'; 49 | }; 50 | 51 | module.exports = { 52 | detectPMByLockFile, 53 | }; 54 | -------------------------------------------------------------------------------- /lib/format-commit-message.js: -------------------------------------------------------------------------------- 1 | module.exports = function (rawMsg, newVersion) { 2 | const message = String(rawMsg); 3 | return message.replace(/{{currentTag}}/g, newVersion); 4 | }; 5 | -------------------------------------------------------------------------------- /lib/latest-semver-tag.js: -------------------------------------------------------------------------------- 1 | const gitSemverTags = require('git-semver-tags'); 2 | const semver = require('semver'); 3 | 4 | module.exports = function ({ tagPrefix, prerelease }) { 5 | return new Promise((resolve, reject) => { 6 | gitSemverTags({ tagPrefix }, function (err, tags) { 7 | if (err) return reject(err); 8 | else if (!tags.length) return resolve('1.0.0'); 9 | // Respect tagPrefix 10 | tags = tags.map((tag) => tag.replace(new RegExp('^' + tagPrefix), '')); 11 | if (prerelease) { 12 | // ignore any other prelease tags 13 | tags = tags.filter((tag) => { 14 | if (!semver.valid(tag)) return false; 15 | if (!semver.prerelease(tag)) { 16 | // include all non-prerelease versions 17 | return true; 18 | } 19 | // check if the name of the prerelease matches the one we are looking for 20 | if (semver.prerelease(tag)[0] === prerelease) { 21 | return true; 22 | } 23 | return false; 24 | }); 25 | } 26 | // ensure that the largest semver tag is at the head. 27 | tags = tags.map((tag) => { 28 | return semver.clean(tag); 29 | }); 30 | tags.sort(semver.rcompare); 31 | return resolve(tags[0]); 32 | }); 33 | }); 34 | }; 35 | -------------------------------------------------------------------------------- /lib/lifecycles/bump.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const chalk = require('chalk'); 4 | const checkpoint = require('../checkpoint'); 5 | const conventionalRecommendedBump = require('conventional-recommended-bump'); 6 | const figures = require('figures'); 7 | const fs = require('fs'); 8 | const DotGitignore = require('dotgitignore'); 9 | const path = require('path'); 10 | const presetLoader = require('../preset-loader'); 11 | const runLifecycleScript = require('../run-lifecycle-script'); 12 | const semver = require('semver'); 13 | const writeFile = require('../write-file'); 14 | const { resolveUpdaterObjectFromArgument } = require('../updaters'); 15 | let configsToUpdate = {}; 16 | const sanitizeQuotesRegex = /['"]+/g; 17 | 18 | async function Bump(args, version) { 19 | // reset the cache of updated config files each 20 | // time we perform the version bump step. 21 | configsToUpdate = {}; 22 | 23 | if (args.skip.bump) return version; 24 | 25 | if ( 26 | args.releaseAs && 27 | !( 28 | ['major', 'minor', 'patch'].includes(args.releaseAs.toLowerCase()) || 29 | semver.valid(args.releaseAs) 30 | ) 31 | ) { 32 | throw new Error( 33 | "releaseAs must be one of 'major', 'minor' or 'patch', or a valid semvar version.", 34 | ); 35 | } 36 | 37 | let newVersion = version; 38 | await runLifecycleScript(args, 'prerelease'); 39 | const stdout = await runLifecycleScript(args, 'prebump'); 40 | if (stdout?.trim().length) { 41 | const prebumpString = stdout.trim().replace(sanitizeQuotesRegex, ''); 42 | if (semver.valid(prebumpString)) args.releaseAs = prebumpString; 43 | } 44 | if (!args.firstRelease) { 45 | if (semver.valid(args.releaseAs)) { 46 | const releaseAs = new semver.SemVer(args.releaseAs); 47 | if ( 48 | isString(args.prerelease) && 49 | releaseAs.prerelease.length && 50 | releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease 51 | ) { 52 | // If both releaseAs and the prerelease identifier are supplied, they must match. The behavior 53 | // for a mismatch is undefined, so error out instead. 54 | throw new Error( 55 | 'releaseAs and prerelease have conflicting prerelease identifiers', 56 | ); 57 | } else if (isString(args.prerelease) && releaseAs.prerelease.length) { 58 | newVersion = releaseAs.version; 59 | } else if (isString(args.prerelease)) { 60 | newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`; 61 | } else { 62 | newVersion = releaseAs.version; 63 | } 64 | 65 | // Check if the previous version is the same version and prerelease, and increment if so 66 | if ( 67 | isString(args.prerelease) && 68 | ['prerelease', null].includes(semver.diff(version, newVersion)) && 69 | semver.lte(newVersion, version) 70 | ) { 71 | newVersion = semver.inc(version, 'prerelease', args.prerelease); 72 | } 73 | 74 | // Append any build info from releaseAs 75 | newVersion = semvarToVersionStr(newVersion, releaseAs.build); 76 | } else { 77 | const release = await bumpVersion(args.releaseAs, version, args); 78 | const releaseType = getReleaseType( 79 | args.prerelease, 80 | release.releaseType, 81 | version, 82 | ); 83 | 84 | newVersion = semver.inc(version, releaseType, args.prerelease); 85 | } 86 | updateConfigs(args, newVersion); 87 | } else { 88 | checkpoint( 89 | args, 90 | 'skip version bump on first release', 91 | [], 92 | chalk.red(figures.cross), 93 | ); 94 | } 95 | await runLifecycleScript(args, 'postbump'); 96 | return newVersion; 97 | } 98 | 99 | Bump.getUpdatedConfigs = function () { 100 | return configsToUpdate; 101 | }; 102 | 103 | /** 104 | * Convert a semver object to a full version string including build metadata 105 | * @param {string} semverVersion The semvar version string 106 | * @param {string[]} semverBuild An array of the build metadata elements, to be joined with '.' 107 | * @returns {string} 108 | */ 109 | function semvarToVersionStr(semverVersion, semverBuild) { 110 | return [semverVersion, semverBuild.join('.')].filter(Boolean).join('+'); 111 | } 112 | 113 | function getReleaseType(prerelease, expectedReleaseType, currentVersion) { 114 | if (isString(prerelease)) { 115 | if (isInPrerelease(currentVersion)) { 116 | if ( 117 | shouldContinuePrerelease(currentVersion, expectedReleaseType) || 118 | getTypePriority(getCurrentActiveType(currentVersion)) > 119 | getTypePriority(expectedReleaseType) 120 | ) { 121 | return 'prerelease'; 122 | } 123 | } 124 | 125 | return 'pre' + expectedReleaseType; 126 | } else { 127 | return expectedReleaseType; 128 | } 129 | } 130 | 131 | function isString(val) { 132 | return typeof val === 'string'; 133 | } 134 | 135 | /** 136 | * if a version is currently in pre-release state, 137 | * and if it current in-pre-release type is same as expect type, 138 | * it should continue the pre-release with the same type 139 | * 140 | * @param version 141 | * @param expectType 142 | * @return {boolean} 143 | */ 144 | function shouldContinuePrerelease(version, expectType) { 145 | return getCurrentActiveType(version) === expectType; 146 | } 147 | 148 | function isInPrerelease(version) { 149 | return Array.isArray(semver.prerelease(version)); 150 | } 151 | 152 | const TypeList = ['major', 'minor', 'patch'].reverse(); 153 | 154 | /** 155 | * extract the in-pre-release type in target version 156 | * 157 | * @param version 158 | * @return {string} 159 | */ 160 | function getCurrentActiveType(version) { 161 | const typelist = TypeList; 162 | for (let i = 0; i < typelist.length; i++) { 163 | if (semver[typelist[i]](version)) { 164 | return typelist[i]; 165 | } 166 | } 167 | } 168 | 169 | /** 170 | * calculate the priority of release type, 171 | * major - 2, minor - 1, patch - 0 172 | * 173 | * @param type 174 | * @return {number} 175 | */ 176 | function getTypePriority(type) { 177 | return TypeList.indexOf(type); 178 | } 179 | 180 | function bumpVersion(releaseAs, currentVersion, args) { 181 | return new Promise((resolve, reject) => { 182 | if (releaseAs) { 183 | return resolve({ 184 | releaseType: releaseAs, 185 | }); 186 | } else { 187 | const presetOptions = presetLoader(args); 188 | if (typeof presetOptions === 'object') { 189 | if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true; 190 | } 191 | conventionalRecommendedBump( 192 | { 193 | preset: presetOptions, 194 | path: args.path, 195 | tagPrefix: args.tagPrefix, 196 | lernaPackage: args.lernaPackage, 197 | ...(args.verbose 198 | ? { 199 | debug: console.info.bind( 200 | console, 201 | 'conventional-recommended-bump', 202 | ), 203 | } 204 | : {}), 205 | }, 206 | args.parserOpts, 207 | function (err, release) { 208 | if (err) return reject(err); 209 | else return resolve(release); 210 | }, 211 | ); 212 | } 213 | }); 214 | } 215 | 216 | /** 217 | * attempt to update the version number in provided `bumpFiles` 218 | * @param args config object 219 | * @param newVersion version number to update to. 220 | * @return void 221 | */ 222 | function updateConfigs(args, newVersion) { 223 | const dotgit = DotGitignore(); 224 | args.bumpFiles.forEach(function (bumpFile) { 225 | const updater = resolveUpdaterObjectFromArgument(bumpFile); 226 | if (!updater) { 227 | return; 228 | } 229 | const configPath = path.resolve(process.cwd(), updater.filename); 230 | try { 231 | if (dotgit.ignore(updater.filename)) { 232 | console.debug( 233 | `Not updating file '${updater.filename}', as it is ignored in Git`, 234 | ); 235 | return; 236 | } 237 | const stat = fs.lstatSync(configPath); 238 | 239 | if (!stat.isFile()) { 240 | console.debug( 241 | `Not updating '${updater.filename}', as it is not a file`, 242 | ); 243 | return; 244 | } 245 | const contents = fs.readFileSync(configPath, 'utf8'); 246 | const newContents = updater.updater.writeVersion(contents, newVersion); 247 | const realNewVersion = updater.updater.readVersion(newContents); 248 | checkpoint( 249 | args, 250 | 'bumping version in ' + updater.filename + ' from %s to %s', 251 | [updater.updater.readVersion(contents), realNewVersion], 252 | ); 253 | writeFile(args, configPath, newContents); 254 | // flag any config files that we modify the version # for 255 | // as having been updated. 256 | configsToUpdate[updater.filename] = true; 257 | } catch (err) { 258 | if (err.code !== 'ENOENT') console.warn(err.message); 259 | } 260 | }); 261 | } 262 | 263 | module.exports = Bump; 264 | -------------------------------------------------------------------------------- /lib/lifecycles/changelog.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const checkpoint = require('../checkpoint'); 3 | const conventionalChangelog = require('conventional-changelog'); 4 | const fs = require('fs'); 5 | const presetLoader = require('../preset-loader'); 6 | const runLifecycleScript = require('../run-lifecycle-script'); 7 | const writeFile = require('../write-file'); 8 | const START_OF_LAST_RELEASE_PATTERN = 9 | /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+| { 45 | createIfMissing(args); 46 | const header = args.header; 47 | 48 | const oldContent = 49 | args.dryRun || args.releaseCount === 0 50 | ? '' 51 | : fs.readFileSync(args.infile, 'utf-8'); 52 | 53 | const oldContentBody = extractChangelogBody(oldContent); 54 | 55 | const changelogFrontMatter = extractFrontMatter(oldContent); 56 | 57 | let content = ''; 58 | const context = { version: newVersion }; 59 | const changelogStream = conventionalChangelog( 60 | { 61 | preset: presetLoader(args), 62 | tagPrefix: args.tagPrefix, 63 | releaseCount: args.releaseCount, 64 | ...(args.verbose 65 | ? { 66 | debug: console.info.bind( 67 | console, 68 | 'conventional-recommended-bump', 69 | ), 70 | } 71 | : {}), 72 | }, 73 | context, 74 | { merges: null, path: args.path, showSignature: false }, 75 | args.parserOpts, 76 | args.writerOpts, 77 | ).on('error', function (err) { 78 | return reject(err); 79 | }); 80 | 81 | changelogStream.on('data', function (buffer) { 82 | content += buffer.toString(); 83 | }); 84 | 85 | changelogStream.on('end', function () { 86 | checkpoint(args, 'outputting changes to %s', [args.infile]); 87 | if (args.dryRun) 88 | console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`); 89 | else 90 | writeFile( 91 | args, 92 | args.infile, 93 | changelogFrontMatter + 94 | header + 95 | '\n' + 96 | (content + oldContentBody).replace(/\n+$/, '\n'), 97 | ); 98 | return resolve(); 99 | }); 100 | }); 101 | } 102 | 103 | function createIfMissing(args) { 104 | try { 105 | fs.accessSync(args.infile, fs.F_OK); 106 | } catch (err) { 107 | if (err.code === 'ENOENT') { 108 | checkpoint(args, 'created %s', [args.infile]); 109 | args.outputUnreleased = true; 110 | writeFile(args, args.infile, '\n'); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /lib/lifecycles/commit.js: -------------------------------------------------------------------------------- 1 | const bump = require('../lifecycles/bump'); 2 | const checkpoint = require('../checkpoint'); 3 | const formatCommitMessage = require('../format-commit-message'); 4 | const path = require('path'); 5 | const runExecFile = require('../run-execFile'); 6 | const runLifecycleScript = require('../run-lifecycle-script'); 7 | 8 | module.exports = async function (args, newVersion) { 9 | if (args.skip.commit) return; 10 | const message = await runLifecycleScript(args, 'precommit'); 11 | if (message && message.length) args.releaseCommitMessageFormat = message; 12 | await execCommit(args, newVersion); 13 | await runLifecycleScript(args, 'postcommit'); 14 | }; 15 | 16 | async function execCommit(args, newVersion) { 17 | let msg = 'committing %s'; 18 | let paths = []; 19 | const verify = args.verify === false || args.n ? ['--no-verify'] : []; 20 | const sign = args.sign ? ['-S'] : []; 21 | const signoff = args.signoff ? ['--signoff'] : []; 22 | const toAdd = []; 23 | 24 | // only start with a pre-populated paths list when CHANGELOG processing is not skipped 25 | if (!args.skip.changelog) { 26 | paths = [args.infile]; 27 | toAdd.push(args.infile); 28 | } 29 | 30 | // commit any of the config files that we've updated 31 | // the version # for. 32 | Object.keys(bump.getUpdatedConfigs()).forEach(function (p) { 33 | paths.unshift(p); 34 | toAdd.push(path.relative(process.cwd(), p)); 35 | 36 | // account for multiple files in the output message 37 | if (paths.length > 1) { 38 | msg += ' and %s'; 39 | } 40 | }); 41 | 42 | if (args.commitAll) { 43 | msg += ' and %s'; 44 | paths.push('all staged files'); 45 | } 46 | 47 | checkpoint(args, msg, paths); 48 | 49 | // nothing to do, exit without commit anything 50 | if ( 51 | !args.commitAll && 52 | args.skip.changelog && 53 | args.skip.bump && 54 | toAdd.length === 0 55 | ) { 56 | return; 57 | } 58 | 59 | await runExecFile(args, 'git', ['add'].concat(toAdd)); 60 | await runExecFile( 61 | args, 62 | 'git', 63 | ['commit'].concat(verify, sign, signoff, args.commitAll ? [] : toAdd, [ 64 | '-m', 65 | `${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`, 66 | ]), 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /lib/lifecycles/tag.js: -------------------------------------------------------------------------------- 1 | const bump = require('../lifecycles/bump'); 2 | const chalk = require('chalk'); 3 | const checkpoint = require('../checkpoint'); 4 | const figures = require('figures'); 5 | const formatCommitMessage = require('../format-commit-message'); 6 | const runExecFile = require('../run-execFile'); 7 | const runLifecycleScript = require('../run-lifecycle-script'); 8 | const { detectPMByLockFile } = require('../detect-package-manager'); 9 | 10 | module.exports = async function (newVersion, pkgPrivate, args) { 11 | if (args.skip.tag) return; 12 | await runLifecycleScript(args, 'pretag'); 13 | await execTag(newVersion, pkgPrivate, args); 14 | await runLifecycleScript(args, 'posttag'); 15 | }; 16 | 17 | async function detectPublishHint() { 18 | const npmClientName = await detectPMByLockFile(); 19 | const publishCommand = 'publish'; 20 | return `${npmClientName} ${publishCommand}`; 21 | } 22 | 23 | async function execTag(newVersion, pkgPrivate, args) { 24 | const tagOption = []; 25 | if (args.sign) { 26 | tagOption.push('-s'); 27 | } else { 28 | tagOption.push('-a'); 29 | } 30 | if (args.tagForce) { 31 | tagOption.push('-f'); 32 | } 33 | checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion]); 34 | await runExecFile(args, 'git', [ 35 | 'tag', 36 | ...tagOption, 37 | args.tagPrefix + newVersion, 38 | '-m', 39 | `${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`, 40 | ]); 41 | const currentBranch = await runExecFile('', 'git', [ 42 | 'rev-parse', 43 | '--abbrev-ref', 44 | 'HEAD', 45 | ]); 46 | let message = 'git push --follow-tags origin ' + currentBranch.trim(); 47 | if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) { 48 | const npmPublishHint = args.npmPublishHint || (await detectPublishHint()); 49 | message += ` && ${npmPublishHint}`; 50 | if (args.prerelease !== undefined) { 51 | if (args.prerelease === '') { 52 | message += ' --tag prerelease'; 53 | } else { 54 | message += ' --tag ' + args.prerelease; 55 | } 56 | } 57 | } 58 | 59 | checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info)); 60 | } 61 | -------------------------------------------------------------------------------- /lib/preset-loader.js: -------------------------------------------------------------------------------- 1 | // TODO: this should be replaced with an object we maintain and 2 | // describe in: https://github.com/conventional-changelog/conventional-changelog-config-spec 3 | const spec = require('conventional-changelog-config-spec'); 4 | 5 | module.exports = (args) => { 6 | const defaultPreset = require.resolve( 7 | 'conventional-changelog-conventionalcommits', 8 | ); 9 | let preset = args.preset || defaultPreset; 10 | if (preset === defaultPreset) { 11 | preset = { 12 | name: defaultPreset, 13 | }; 14 | Object.keys(spec.properties).forEach((key) => { 15 | if (args[key] !== undefined) preset[key] = args[key]; 16 | }); 17 | } 18 | return preset; 19 | }; 20 | -------------------------------------------------------------------------------- /lib/print-error.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | 3 | module.exports = function (args, msg, opts) { 4 | if (!args.silent) { 5 | opts = Object.assign( 6 | { 7 | level: 'error', 8 | color: 'red', 9 | }, 10 | opts, 11 | ); 12 | 13 | console[opts.level](chalk[opts.color](msg)); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /lib/run-exec.js: -------------------------------------------------------------------------------- 1 | const { promisify } = require('util'); 2 | const printError = require('./print-error'); 3 | 4 | const exec = promisify(require('child_process').exec); 5 | 6 | module.exports = async function (args, cmd) { 7 | if (args.dryRun) return; 8 | try { 9 | const { stderr, stdout } = await exec(cmd); 10 | // If exec returns content in stderr, but no error, print it as a warning 11 | if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' }); 12 | return stdout; 13 | } catch (error) { 14 | // If exec returns an error, print it and exit with return code 1 15 | printError(args, error.stderr || error.message); 16 | throw error; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /lib/run-execFile.js: -------------------------------------------------------------------------------- 1 | const { promisify } = require('util'); 2 | const printError = require('./print-error'); 3 | 4 | const execFile = promisify(require('child_process').execFile); 5 | 6 | module.exports = async function (args, cmd, cmdArgs) { 7 | if (args.dryRun) return; 8 | try { 9 | const { stderr, stdout } = await execFile(cmd, cmdArgs); 10 | // If execFile returns content in stderr, but no error, print it as a warning 11 | if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' }); 12 | return stdout; 13 | } catch (error) { 14 | // If execFile returns an error, print it and exit with return code 1 15 | printError(args, error.stderr || error.message); 16 | throw error; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /lib/run-lifecycle-script.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const checkpoint = require('./checkpoint'); 3 | const figures = require('figures'); 4 | const runExec = require('./run-exec'); 5 | 6 | module.exports = function (args, hookName) { 7 | const scripts = args.scripts; 8 | if (!scripts || !scripts[hookName]) return Promise.resolve(); 9 | const command = scripts[hookName]; 10 | checkpoint(args, 'Running lifecycle script "%s"', [hookName]); 11 | checkpoint( 12 | args, 13 | '- execute command: "%s"', 14 | [command], 15 | chalk.blue(figures.info), 16 | ); 17 | return runExec(args, command); 18 | }; 19 | -------------------------------------------------------------------------------- /lib/stringify-package.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright npm, Inc 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | 16 | https://github.com/npm/stringify-package/blob/main/LICENSE 17 | */ 18 | 19 | 'use strict'; 20 | 21 | module.exports = stringifyPackage; 22 | 23 | const DEFAULT_INDENT = 2; 24 | const CRLF = '\r\n'; 25 | const LF = '\n'; 26 | 27 | function stringifyPackage(data, indent, newline) { 28 | indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT); 29 | const json = JSON.stringify(data, null, indent); 30 | 31 | if (newline === CRLF) { 32 | return json.replace(/\n/g, CRLF) + CRLF; 33 | } 34 | 35 | return json + LF; 36 | } 37 | -------------------------------------------------------------------------------- /lib/updaters/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const JSON_BUMP_FILES = require('../../defaults').bumpFiles; 3 | const updatersByType = { 4 | json: require('./types/json'), 5 | 'plain-text': require('./types/plain-text'), 6 | maven: require('./types/maven'), 7 | gradle: require('./types/gradle'), 8 | csproj: require('./types/csproj'), 9 | yaml: require('./types/yaml'), 10 | openapi: require('./types/openapi'), 11 | python: require('./types/python'), 12 | }; 13 | const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']; 14 | 15 | function getUpdaterByType(type) { 16 | const updater = updatersByType[type]; 17 | if (!updater) { 18 | throw Error(`Unable to locate updater for provided type (${type}).`); 19 | } 20 | return updater; 21 | } 22 | 23 | function getUpdaterByFilename(filename) { 24 | if (JSON_BUMP_FILES.includes(path.basename(filename))) { 25 | return getUpdaterByType('json'); 26 | } 27 | if (PLAIN_TEXT_BUMP_FILES.includes(filename)) { 28 | return getUpdaterByType('plain-text'); 29 | } 30 | if (/pom.xml/.test(filename)) { 31 | return getUpdaterByType('maven'); 32 | } 33 | if (/build.gradle/.test(filename)) { 34 | return getUpdaterByType('gradle'); 35 | } 36 | if (filename.endsWith('.csproj')) { 37 | return getUpdaterByType('csproj'); 38 | } 39 | if (/openapi.yaml/.test(filename)) { 40 | return getUpdaterByType('openapi'); 41 | } 42 | if (/\.ya?ml$/.test(filename)) { 43 | return getUpdaterByType('yaml'); 44 | } 45 | if (/pyproject.toml/.test(filename)) { 46 | return getUpdaterByType('python'); 47 | } 48 | throw Error( 49 | `Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`, 50 | ); 51 | } 52 | 53 | function getCustomUpdaterFromPath(updater) { 54 | if (typeof updater === 'string') { 55 | return require(path.resolve(process.cwd(), updater)); 56 | } 57 | if ( 58 | typeof updater.readVersion === 'function' && 59 | typeof updater.writeVersion === 'function' 60 | ) { 61 | return updater; 62 | } 63 | throw new Error( 64 | 'Updater must be a string path or an object with readVersion and writeVersion methods', 65 | ); 66 | } 67 | 68 | /** 69 | * Simple check to determine if the object provided is a compatible updater. 70 | */ 71 | function isValidUpdater(obj) { 72 | return ( 73 | obj && 74 | typeof obj.readVersion === 'function' && 75 | typeof obj.writeVersion === 'function' 76 | ); 77 | } 78 | 79 | module.exports.resolveUpdaterObjectFromArgument = function (arg) { 80 | /** 81 | * If an Object was not provided, we assume it's the path/filename 82 | * of the updater. 83 | */ 84 | let updater = arg; 85 | if (isValidUpdater(updater)) { 86 | return updater; 87 | } 88 | if (typeof updater !== 'object') { 89 | updater = { 90 | filename: arg, 91 | }; 92 | } 93 | 94 | if (!isValidUpdater(updater.updater)) { 95 | try { 96 | if (typeof updater.updater === 'string') { 97 | updater.updater = getCustomUpdaterFromPath(updater.updater); 98 | } else if (updater.type) { 99 | updater.updater = getUpdaterByType(updater.type); 100 | } else { 101 | updater.updater = getUpdaterByFilename(updater.filename); 102 | } 103 | } catch (err) { 104 | if (err.code !== 'ENOENT') 105 | console.warn( 106 | `Unable to obtain updater for: ${JSON.stringify(arg)}\n - Error: ${ 107 | err.message 108 | }\n - Skipping...`, 109 | ); 110 | } 111 | } 112 | /** 113 | * We weren't able to resolve an updater for the argument. 114 | */ 115 | if (!isValidUpdater(updater.updater)) { 116 | return false; 117 | } 118 | 119 | return updater; 120 | }; 121 | -------------------------------------------------------------------------------- /lib/updaters/types/csproj.js: -------------------------------------------------------------------------------- 1 | const versionRegex = /(.*)<\/Version>/; 2 | 3 | module.exports.readVersion = function (contents) { 4 | const matches = versionRegex.exec(contents); 5 | if (matches === null || matches.length !== 2) { 6 | throw new Error( 7 | 'Failed to read the Version field in your csproj file - is it present?', 8 | ); 9 | } 10 | return matches[1]; 11 | }; 12 | 13 | module.exports.writeVersion = function (contents, version) { 14 | return contents.replace(versionRegex, `${version}`); 15 | }; 16 | -------------------------------------------------------------------------------- /lib/updaters/types/gradle.js: -------------------------------------------------------------------------------- 1 | const versionRegex = /^version\s+=\s+['"]([\d.]+)['"]/m; 2 | 3 | module.exports.readVersion = function (contents) { 4 | const matches = versionRegex.exec(contents); 5 | if (matches === null) { 6 | throw new Error( 7 | 'Failed to read the version field in your gradle file - is it present?', 8 | ); 9 | } 10 | 11 | return matches[1]; 12 | }; 13 | 14 | module.exports.writeVersion = function (contents, version) { 15 | return contents.replace(versionRegex, () => { 16 | return `version = "${version}"`; 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /lib/updaters/types/json.js: -------------------------------------------------------------------------------- 1 | const stringifyPackage = require('../../stringify-package'); 2 | const detectIndent = require('detect-indent'); 3 | const detectNewline = require('detect-newline'); 4 | 5 | module.exports.readVersion = function (contents) { 6 | return JSON.parse(contents).version; 7 | }; 8 | 9 | module.exports.writeVersion = function (contents, version) { 10 | const json = JSON.parse(contents); 11 | const indent = detectIndent(contents).indent; 12 | const newline = detectNewline(contents); 13 | json.version = version; 14 | 15 | if (json.packages && json.packages['']) { 16 | // package-lock v2 stores version there too 17 | json.packages[''].version = version; 18 | } 19 | 20 | return stringifyPackage(json, indent, newline); 21 | }; 22 | 23 | module.exports.isPrivate = function (contents) { 24 | return JSON.parse(contents).private; 25 | }; 26 | -------------------------------------------------------------------------------- /lib/updaters/types/maven.js: -------------------------------------------------------------------------------- 1 | const jsdom = require('jsdom'); 2 | const serialize = require('w3c-xmlserializer'); 3 | const detectNewline = require('detect-newline'); 4 | const CRLF = '\r\n'; 5 | const LF = '\n'; 6 | 7 | function pomDocument(contents) { 8 | const dom = new jsdom.JSDOM(''); 9 | const parser = new dom.window.DOMParser(); 10 | return parser.parseFromString(contents, 'application/xml'); 11 | } 12 | 13 | function pomVersionElement(document) { 14 | const versionElement = document.querySelector('project > version'); 15 | 16 | if (!versionElement) { 17 | throw new Error( 18 | 'Failed to read the version field in your pom file - is it present?', 19 | ); 20 | } 21 | 22 | return versionElement; 23 | } 24 | 25 | module.exports.readVersion = function (contents) { 26 | const document = pomDocument(contents); 27 | return pomVersionElement(document).textContent; 28 | }; 29 | 30 | module.exports.writeVersion = function (contents, version) { 31 | const newline = detectNewline(contents); 32 | const document = pomDocument(contents); 33 | const versionElement = pomVersionElement(document); 34 | 35 | versionElement.textContent = version; 36 | 37 | const xml = serialize(document); 38 | 39 | if (newline === CRLF) { 40 | return xml.replace(/\n/g, CRLF) + CRLF; 41 | } 42 | 43 | return xml + LF; 44 | }; 45 | -------------------------------------------------------------------------------- /lib/updaters/types/openapi.js: -------------------------------------------------------------------------------- 1 | const yaml = require('yaml'); 2 | const detectNewline = require('detect-newline'); 3 | 4 | module.exports.readVersion = function (contents) { 5 | return yaml.parse(contents).info.version; 6 | }; 7 | 8 | module.exports.writeVersion = function (contents, version) { 9 | const newline = detectNewline(contents); 10 | const document = yaml.parseDocument(contents); 11 | 12 | document.get('info').set('version', version); 13 | 14 | return document.toString().replace(/\r?\n/g, newline); 15 | }; 16 | -------------------------------------------------------------------------------- /lib/updaters/types/plain-text.js: -------------------------------------------------------------------------------- 1 | module.exports.readVersion = function (contents) { 2 | return contents; 3 | }; 4 | 5 | module.exports.writeVersion = function (_contents, version) { 6 | return version; 7 | }; 8 | -------------------------------------------------------------------------------- /lib/updaters/types/python.js: -------------------------------------------------------------------------------- 1 | const versionExtractRegex = /version[" ]*=[ ]*["'](.*)["']/i; 2 | 3 | const getVersionIndex = function (lines) { 4 | let version; 5 | const lineNumber = lines.findIndex((line) => { 6 | const versionMatcher = line.match(versionExtractRegex); 7 | // if version not found in lines provided, return false 8 | if (versionMatcher == null) { 9 | return false; 10 | } 11 | version = versionMatcher[1]; 12 | return true; 13 | }); 14 | return { version, lineNumber }; 15 | }; 16 | 17 | module.exports.readVersion = function (contents) { 18 | const lines = contents.split('\n'); 19 | const versionIndex = getVersionIndex(lines); 20 | return versionIndex.version; 21 | }; 22 | 23 | module.exports.writeVersion = function (contents, version) { 24 | const lines = contents.split('\n'); 25 | const versionIndex = getVersionIndex(lines); 26 | const versionLine = lines[versionIndex.lineNumber]; 27 | const newVersionLine = versionLine.replace(versionIndex.version, version); 28 | lines[versionIndex.lineNumber] = newVersionLine; 29 | return lines.join('\n'); 30 | }; 31 | -------------------------------------------------------------------------------- /lib/updaters/types/yaml.js: -------------------------------------------------------------------------------- 1 | const yaml = require('yaml'); 2 | const detectNewline = require('detect-newline'); 3 | 4 | module.exports.readVersion = function (contents) { 5 | return yaml.parse(contents).version; 6 | }; 7 | 8 | module.exports.writeVersion = function (contents, version) { 9 | const newline = detectNewline(contents); 10 | const document = yaml.parseDocument(contents); 11 | 12 | document.set('version', version); 13 | 14 | return document.toString().replace(/\r?\n/g, newline); 15 | }; 16 | -------------------------------------------------------------------------------- /lib/write-file.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | module.exports = function (args, filePath, content) { 4 | if (args.dryRun) return; 5 | fs.writeFileSync(filePath, content, 'utf8'); 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "commit-and-tag-version", 3 | "version": "12.5.1", 4 | "description": "replacement for `npm version` with automatic CHANGELOG generation", 5 | "bin": "bin/cli.js", 6 | "scripts": { 7 | "lint": "eslint .", 8 | "lint:fix": "npm run lint -- --fix", 9 | "posttest": "npm run lint && npm run format:check", 10 | "format:base": "prettier \"./**/*.{ts,js}\"", 11 | "format:fix": "npm run format:base -- --write", 12 | "format:check": "npm run format:base -- --check", 13 | "test": "jest", 14 | "test:unit": "jest --testPathIgnorePatterns test/git.integration-test.js", 15 | "test:git-integration": "jest --testPathPattern test/git.integration-test.js", 16 | "release": "bin/cli.js" 17 | }, 18 | "repository": "absolute-version/commit-and-tag-version", 19 | "engines": { 20 | "node": ">=18" 21 | }, 22 | "keywords": [ 23 | "conventional-changelog", 24 | "recommended", 25 | "changelog", 26 | "automatic", 27 | "workflow", 28 | "version", 29 | "angular", 30 | "standard" 31 | ], 32 | "author": "Ben Coe ", 33 | "contributors": [ 34 | "Timothy Jones (https://github.com/TimothyJones)" 35 | ], 36 | "license": "ISC", 37 | "bugs": { 38 | "url": "https://github.com/absolute-version/commit-and-tag-version/issues" 39 | }, 40 | "homepage": "https://github.com/absolute-version/commit-and-tag-version#readme", 41 | "dependencies": { 42 | "chalk": "^2.4.2", 43 | "conventional-changelog": "4.0.0", 44 | "conventional-changelog-config-spec": "2.1.0", 45 | "conventional-changelog-conventionalcommits": "6.1.0", 46 | "conventional-recommended-bump": "7.0.1", 47 | "detect-indent": "^6.1.0", 48 | "detect-newline": "^3.1.0", 49 | "dotgitignore": "^2.1.0", 50 | "figures": "^3.2.0", 51 | "find-up": "^5.0.0", 52 | "git-semver-tags": "^5.0.1", 53 | "jsdom": "^25.0.1", 54 | "semver": "^7.6.3", 55 | "w3c-xmlserializer": "^5.0.0", 56 | "yaml": "^2.6.0", 57 | "yargs": "^17.7.2" 58 | }, 59 | "devDependencies": { 60 | "@eslint/js": "^9.13.0", 61 | "eslint": "^9.13.0", 62 | "eslint-config-prettier": "^9.1.0", 63 | "eslint-plugin-import": "^2.31.0", 64 | "eslint-plugin-jest": "^28.8.3", 65 | "eslint-plugin-n": "^17.11.1", 66 | "eslint-plugin-promise": "^7.1.0", 67 | "jest": "^29.7.0", 68 | "jest-serial-runner": "^1.2.1", 69 | "prettier": "^3.3.3", 70 | "shelljs": "^0.8.5", 71 | "strip-ansi": "^6.0.1" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/commit-message-config.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | function exec(opt = '') { 9 | if (typeof opt === 'string') { 10 | const cli = require('../command'); 11 | opt = cli.parse(`commit-and-tag-version ${opt}`); 12 | } 13 | return require('../index')(opt); 14 | } 15 | 16 | /** 17 | * Mock external conventional-changelog modules 18 | * 19 | * bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 20 | * changelog?: string | Error | Array string | null> 21 | * tags?: string[] | Error 22 | */ 23 | function mock({ bump, changelog, tags }) { 24 | if (bump === undefined) throw new Error('bump must be defined for mock()'); 25 | 26 | mockers.mockRecommendedBump({ bump }); 27 | 28 | if (!Array.isArray(changelog)) changelog = [changelog]; 29 | mockers.mockConventionalChangelog({ changelog }); 30 | 31 | mockers.mockGitSemverTags({ tags }); 32 | } 33 | 34 | function writePackageJson(version, option) { 35 | const pkg = Object.assign({}, option, { version }); 36 | fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8'); 37 | } 38 | 39 | function setupTempGitRepo() { 40 | shell.rm('-rf', 'commit-message-config-temp'); 41 | shell.config.silent = true; 42 | shell.mkdir('commit-message-config-temp'); 43 | shell.cd('commit-message-config-temp'); 44 | shell.exec('git init'); 45 | shell.exec('git config commit.gpgSign false'); 46 | shell.exec('git config core.autocrlf false'); 47 | shell.exec('git commit --allow-empty -m"root-commit"'); 48 | } 49 | 50 | function setup() { 51 | setupTempGitRepo(); 52 | writePackageJson('1.0.0'); 53 | } 54 | 55 | function reset() { 56 | shell.cd('../'); 57 | shell.rm('-rf', 'commit-message-config-temp'); 58 | } 59 | 60 | describe('configuration', function () { 61 | beforeEach(function () { 62 | setup(); 63 | }); 64 | 65 | afterEach(function () { 66 | reset(); 67 | }); 68 | 69 | it('.versionrc : releaseCommitMessageFormat', async function () { 70 | fs.writeFileSync( 71 | '.versionrc', 72 | JSON.stringify({ 73 | releaseCommitMessageFormat: 74 | 'This commit represents release: {{currentTag}}', 75 | }), 76 | 'utf-8', 77 | ); 78 | mock({ bump: 'minor' }); 79 | await exec(''); 80 | expect(shell.exec('git log --oneline -n1').stdout).toMatch( 81 | 'This commit represents release: 1.1.0', 82 | ); 83 | }); 84 | 85 | it('--releaseCommitMessageFormat', async function () { 86 | mock({ bump: 'minor' }); 87 | await exec('--releaseCommitMessageFormat="{{currentTag}} is the version."'); 88 | expect(shell.exec('git log --oneline -n1').stdout).toContain( 89 | '1.1.0 is the version.', 90 | ); 91 | }); 92 | 93 | it('[LEGACY] supports --message (and single %s replacement)', async function () { 94 | mock({ bump: 'minor' }); 95 | await exec('--message="V:%s"'); 96 | expect(shell.exec('git log --oneline -n1').stdout).toContain('V:1.1.0'); 97 | }); 98 | 99 | it('[LEGACY] supports -m (and multiple %s replacements)', async function () { 100 | mock({ bump: 'minor' }); 101 | await exec('--message="V:%s is the %s."'); 102 | expect(shell.exec('git log --oneline -n1').stdout).toContain( 103 | 'V:1.1.0 is the 1.1.0.', 104 | ); 105 | }); 106 | }); 107 | -------------------------------------------------------------------------------- /test/config-files.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | function exec() { 9 | const cli = require('../command'); 10 | const opt = cli.parse('commit-and-tag-version'); 11 | opt.skip = { commit: true, tag: true }; 12 | return require('../index')(opt); 13 | } 14 | 15 | /** 16 | * Mock external conventional-changelog modules 17 | * 18 | * Mocks should be unregistered in test cleanup by calling unmock() 19 | * 20 | * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 21 | * changelog?: string | Error | Array string | null> 22 | * tags?: string[] | Error 23 | */ 24 | function mock({ bump, changelog, tags } = {}) { 25 | mockers.mockRecommendedBump({ bump }); 26 | 27 | if (!Array.isArray(changelog)) changelog = [changelog]; 28 | 29 | mockers.mockConventionalChangelog({ changelog }); 30 | 31 | mockers.mockGitSemverTags({ tags }); 32 | } 33 | 34 | function setupTestDirectory() { 35 | shell.rm('-rf', 'config-files-temp'); 36 | shell.config.silent = true; 37 | shell.mkdir('config-files-temp'); 38 | shell.cd('config-files-temp'); 39 | } 40 | 41 | function resetShell() { 42 | shell.cd('../'); 43 | shell.rm('-rf', 'config-files-temp'); 44 | } 45 | 46 | describe('config files', function () { 47 | beforeEach(function () { 48 | setupTestDirectory(); 49 | 50 | fs.writeFileSync( 51 | 'package.json', 52 | JSON.stringify({ version: '1.0.0' }), 53 | 'utf-8', 54 | ); 55 | }); 56 | 57 | afterEach(function () { 58 | resetShell(); 59 | 4; 60 | }); 61 | 62 | it('reads config from .versionrc', async function () { 63 | const issueUrlFormat = 'http://www.foo.com/{{id}}'; 64 | const changelog = ({ preset }) => preset.issueUrlFormat; 65 | 66 | mock({ bump: 'minor', changelog }); 67 | fs.writeFileSync('.versionrc', JSON.stringify({ issueUrlFormat }), 'utf-8'); 68 | 69 | await exec(); 70 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 71 | expect(content).toContain(issueUrlFormat); 72 | }); 73 | 74 | it('reads config from .versionrc.json', async function () { 75 | const issueUrlFormat = 'http://www.foo.com/{{id}}'; 76 | const changelog = ({ preset }) => preset.issueUrlFormat; 77 | mock({ bump: 'minor', changelog }); 78 | fs.writeFileSync( 79 | '.versionrc.json', 80 | JSON.stringify({ issueUrlFormat }), 81 | 'utf-8', 82 | ); 83 | 84 | await exec(); 85 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 86 | expect(content).toContain(issueUrlFormat); 87 | }); 88 | 89 | it('evaluates a config-function from .versionrc.js', async function () { 90 | const issueUrlFormat = 'http://www.foo.com/{{id}}'; 91 | const src = `module.exports = function() { return ${JSON.stringify({ 92 | issueUrlFormat, 93 | })} }`; 94 | const changelog = ({ preset }) => preset.issueUrlFormat; 95 | mock({ bump: 'minor', changelog }); 96 | fs.writeFileSync('.versionrc.js', src, 'utf-8'); 97 | 98 | await exec(); 99 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 100 | expect(content).toContain(issueUrlFormat); 101 | }); 102 | 103 | it('evaluates a config-object from .versionrc.js', async function () { 104 | const issueUrlFormat = 'http://www.foo.com/{{id}}'; 105 | const src = `module.exports = ${JSON.stringify({ issueUrlFormat })}`; 106 | const changelog = ({ preset }) => preset.issueUrlFormat; 107 | mock({ bump: 'minor', changelog }); 108 | fs.writeFileSync('.versionrc.js', src, 'utf-8'); 109 | 110 | await exec(); 111 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 112 | expect(content).toContain(issueUrlFormat); 113 | }); 114 | }); 115 | -------------------------------------------------------------------------------- /test/config-keys.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | function exec() { 9 | const cli = require('../command'); 10 | const opt = cli.parse('commit-and-tag-version'); 11 | opt.skip = { commit: true, tag: true }; 12 | return require('../index')(opt); 13 | } 14 | 15 | /** 16 | * Mock external conventional-changelog modules 17 | * 18 | * Mocks should be unregistered in test cleanup by calling unmock() 19 | * 20 | * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 21 | * changelog?: string | Error | Array string | null> 22 | * tags?: string[] | Error 23 | */ 24 | function mock({ bump, changelog, tags } = {}) { 25 | mockers.mockRecommendedBump({ bump }); 26 | 27 | if (!Array.isArray(changelog)) changelog = [changelog]; 28 | 29 | mockers.mockConventionalChangelog({ changelog }); 30 | 31 | mockers.mockGitSemverTags({ tags }); 32 | } 33 | 34 | function setupTempGitRepo() { 35 | shell.rm('-rf', 'config-keys-temp'); 36 | shell.config.silent = true; 37 | shell.mkdir('config-keys-temp'); 38 | shell.cd('config-keys-temp'); 39 | } 40 | 41 | function resetShell() { 42 | shell.cd('../'); 43 | shell.rm('-rf', 'config-keys-temp'); 44 | } 45 | 46 | describe('config files', function () { 47 | beforeEach(function () { 48 | setupTempGitRepo(); 49 | 50 | fs.writeFileSync( 51 | 'package.json', 52 | JSON.stringify({ version: '1.0.0' }), 53 | 'utf-8', 54 | ); 55 | }); 56 | 57 | afterEach(function () { 58 | resetShell(); 59 | }); 60 | 61 | const configKeys = ['commit-and-tag-version', 'standard-version']; 62 | 63 | configKeys.forEach((configKey) => { 64 | it(`reads config from package.json key '${configKey}'`, async function () { 65 | const issueUrlFormat = 66 | 'https://commit-and-tag-version.company.net/browse/{{id}}'; 67 | mock({ 68 | bump: 'minor', 69 | changelog: ({ preset }) => preset.issueUrlFormat, 70 | }); 71 | const pkg = { 72 | version: '1.0.0', 73 | repository: { url: 'git+https://company@scm.org/office/app.git' }, 74 | [configKey]: { issueUrlFormat }, 75 | }; 76 | fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8'); 77 | 78 | await exec(); 79 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 80 | expect(content).toMatch(issueUrlFormat); 81 | }); 82 | }); 83 | }); 84 | -------------------------------------------------------------------------------- /test/git.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | // Jest swallows most standard console logs not explicitly defined into a custom logger 9 | // see: https://stackoverflow.com/questions/51555568/remove-logging-the-origin-line-in-jest 10 | const consoleWarnSpy = jest.spyOn(global.console, 'warn').mockImplementation(); 11 | const consoleInfoSpy = jest.spyOn(global.console, 'info').mockImplementation(); 12 | 13 | function exec(opt = '') { 14 | if (typeof opt === 'string') { 15 | const cli = require('../command'); 16 | opt = cli.parse(`commit-and-tag-version ${opt}`); 17 | } 18 | return require('../index')(opt); 19 | } 20 | 21 | function writePackageJson(version, option) { 22 | const pkg = Object.assign({}, option, { version }); 23 | fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8'); 24 | } 25 | 26 | function getPackageVersion() { 27 | return JSON.parse(fs.readFileSync('package.json', 'utf-8')).version; 28 | } 29 | 30 | /** 31 | * Mock external conventional-changelog modules 32 | * 33 | * bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 34 | * changelog?: string | Error | Array string | null> 35 | * tags?: string[] | Error 36 | */ 37 | function mock({ bump, changelog, tags }) { 38 | if (bump === undefined) throw new Error('bump must be defined for mock()'); 39 | 40 | mockers.mockRecommendedBump({ bump }); 41 | 42 | if (!Array.isArray(changelog)) changelog = [changelog]; 43 | mockers.mockConventionalChangelog({ changelog }); 44 | 45 | mockers.mockGitSemverTags({ tags }); 46 | } 47 | 48 | function getLog(expectedLog, spy = consoleInfoSpy) { 49 | const consoleInfoLogs = spy.mock.calls.map((args) => args[0]); 50 | return consoleInfoLogs.find((log) => log.includes(expectedLog)); 51 | } 52 | 53 | function verifyLogPrinted(expectedLog, spy = consoleInfoSpy) { 54 | const logType = spy === consoleInfoSpy ? 'info' : 'error'; 55 | const desiredLog = getLog(expectedLog, spy); 56 | if (desiredLog) { 57 | expect(desiredLog).toMatch(expectedLog); 58 | } else { 59 | expect(`no ${logType} Log printed matching`).toMatch(expectedLog); 60 | } 61 | } 62 | 63 | function verifyLogNotPrinted(expectedLog, spy = consoleInfoSpy) { 64 | const desiredLog = getLog(expectedLog, spy); 65 | expect(desiredLog).toBeUndefined(); 66 | } 67 | 68 | function clearCapturedSpyCalls() { 69 | consoleInfoSpy.mockClear(); 70 | consoleWarnSpy.mockClear(); 71 | } 72 | 73 | function resetShell() { 74 | shell.cd('../'); 75 | shell.rm('-rf', 'git-repo-temp'); 76 | } 77 | 78 | function setupTempGitRepo() { 79 | shell.rm('-rf', 'git-repo-temp'); 80 | shell.config.silent = true; 81 | shell.mkdir('git-repo-temp'); 82 | shell.cd('git-repo-temp'); 83 | shell.exec('git init'); 84 | shell.exec('git config commit.gpgSign false'); 85 | shell.exec('git config core.autocrlf false'); 86 | shell.exec('git commit --allow-empty -m"root-commit"'); 87 | } 88 | 89 | describe('git', function () { 90 | function setup() { 91 | setupTempGitRepo(); 92 | writePackageJson('1.0.0'); 93 | } 94 | 95 | function reset() { 96 | resetShell(); 97 | 98 | clearCapturedSpyCalls(); 99 | } 100 | 101 | beforeEach(function () { 102 | setup(); 103 | }); 104 | 105 | afterEach(function () { 106 | reset(); 107 | }); 108 | 109 | describe('tagPrefix', function () { 110 | beforeEach(function () { 111 | setup(); 112 | }); 113 | 114 | afterEach(function () { 115 | reset(); 116 | }); 117 | 118 | // TODO: Use unmocked git-semver-tags and stage a git environment 119 | it('will add prefix onto tag based on version from package', async function () { 120 | writePackageJson('1.2.0'); 121 | mock({ bump: 'minor', tags: ['p-v1.2.0'] }); 122 | await exec('--tag-prefix p-v'); 123 | expect(shell.exec('git tag').stdout).toMatch(/p-v1\.3\.0/); 124 | }); 125 | 126 | it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () { 127 | shell.rm('package.json'); 128 | mock({ 129 | bump: 'minor', 130 | tags: ['android/production/v1.2.0', 'android/production/v1.0.0'], 131 | }); 132 | await exec('--tag-prefix android/production/v'); 133 | expect(shell.exec('git tag').stdout).toMatch( 134 | /android\/production\/v1\.3\.0/, 135 | ); 136 | }); 137 | 138 | it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () { 139 | mock({ 140 | bump: 'minor', 141 | tags: ['android/production/v1.2.0', 'android/production/v1.0.0'], 142 | }); 143 | await exec({ tagPrefix: 'android/production/v', packageFiles: [] }); 144 | expect(shell.exec('git tag').stdout).toMatch( 145 | /android\/production\/v1\.3\.0/, 146 | ); 147 | }); 148 | }); 149 | 150 | it('formats the commit and tag messages appropriately', async function () { 151 | mock({ bump: 'minor', tags: ['v1.0.0'] }); 152 | await exec({}); 153 | // check last commit message 154 | expect(shell.exec('git log --oneline -n1').stdout).toMatch( 155 | /chore\(release\): 1\.1\.0/, 156 | ); 157 | // check annotated tag message 158 | expect(shell.exec('git tag -l -n1 v1.1.0').stdout).toMatch( 159 | /chore\(release\): 1\.1\.0/, 160 | ); 161 | }); 162 | 163 | it('formats the tag if --first-release is true', async function () { 164 | writePackageJson('1.0.1'); 165 | mock({ bump: 'minor' }); 166 | await exec('--first-release'); 167 | expect(shell.exec('git tag').stdout).toMatch(/1\.0\.1/); 168 | }); 169 | 170 | it('commits all staged files', async function () { 171 | fs.writeFileSync( 172 | 'CHANGELOG.md', 173 | 'legacy header format\n', 174 | 'utf-8', 175 | ); 176 | fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8'); 177 | shell.exec('git add STUFF.md'); 178 | 179 | mock({ bump: 'patch', changelog: 'release 1.0.1\n', tags: ['v1.0.0'] }); 180 | await exec('--commit-all'); 181 | const status = shell.exec('git status --porcelain').stdout; // see http://unix.stackexchange.com/questions/155046/determine-if-git-working-directory-is-clean-from-a-script 182 | expect(status).toEqual(''); 183 | expect(status).not.toMatch(/STUFF.md/); 184 | 185 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 186 | expect(content).toMatch(/1\.0\.1/); 187 | expect(content).not.toMatch(/legacy header format/); 188 | }); 189 | 190 | it('does not run git hooks if the --no-verify flag is passed', async function () { 191 | fs.writeFileSync( 192 | '.git/hooks/pre-commit', 193 | '#!/bin/sh\necho "precommit ran"\nexit 1', 194 | 'utf-8', 195 | ); 196 | fs.chmodSync('.git/hooks/pre-commit', '755'); 197 | 198 | mock({ bump: 'minor' }); 199 | await exec('--no-verify'); 200 | await exec('-n'); 201 | }); 202 | 203 | it('replaces tags if version not bumped', async function () { 204 | mock({ bump: 'minor', tags: ['v1.0.0'] }); 205 | await exec({}); 206 | expect(shell.exec('git describe').stdout).toMatch(/v1\.1\.0/); 207 | await exec('--tag-force --skip.bump'); 208 | expect(shell.exec('git describe').stdout).toMatch(/v1\.1\.0/); 209 | }); 210 | 211 | it('allows the commit phase to be skipped', async function () { 212 | const changelogContent = 'legacy header format\n'; 213 | writePackageJson('1.0.0'); 214 | fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8'); 215 | 216 | mock({ bump: 'minor', changelog: 'new feature\n' }); 217 | await exec('--skip.commit true'); 218 | expect(getPackageVersion()).toEqual('1.1.0'); 219 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 220 | expect(content).toMatch(/new feature/); 221 | expect(shell.exec('git log --oneline -n1').stdout).toMatch(/root-commit/); 222 | }); 223 | 224 | it('dry-run skips all non-idempotent steps', async function () { 225 | shell.exec('git tag -a v1.0.0 -m "my awesome first release"'); 226 | mock({ 227 | bump: 'minor', 228 | changelog: '### Features\n', 229 | tags: ['v1.0.0'], 230 | }); 231 | await exec('--dry-run'); 232 | verifyLogPrinted('### Features'); 233 | 234 | expect(shell.exec('git log --oneline -n1').stdout).toMatch(/root-commit/); 235 | expect(shell.exec('git tag').stdout).toMatch(/1\.0\.0/); 236 | expect(getPackageVersion()).toEqual('1.0.0'); 237 | }); 238 | 239 | it('works fine without specifying a tag id when prereleasing', async function () { 240 | writePackageJson('1.0.0'); 241 | fs.writeFileSync( 242 | 'CHANGELOG.md', 243 | 'legacy header format\n', 244 | 'utf-8', 245 | ); 246 | mock({ bump: 'minor' }); 247 | await exec('--prerelease'); 248 | expect(getPackageVersion()).toEqual('1.1.0-0'); 249 | }); 250 | 251 | describe('gitTagFallback', function () { 252 | beforeEach(function () { 253 | setup(); 254 | }); 255 | 256 | afterEach(function () { 257 | reset(); 258 | }); 259 | 260 | it('defaults to 1.0.0 if no tags in git history', async function () { 261 | shell.rm('package.json'); 262 | mock({ bump: 'minor' }); 263 | await exec({}); 264 | const output = shell.exec('git tag'); 265 | expect(output.stdout).toContain('v1.1.0'); 266 | }); 267 | 268 | it('bases version on greatest version tag, if tags are found', async function () { 269 | shell.rm('package.json'); 270 | mock({ bump: 'minor', tags: ['v3.9.0', 'v5.0.0', 'v3.0.0'] }); 271 | await exec({}); 272 | const output = shell.exec('git tag'); 273 | expect(output.stdout).toContain('v5.1.0'); 274 | }); 275 | 276 | it('uses only relevant prerelease tags', async function () { 277 | shell.rm('package.json'); 278 | mock({ bump: 'minor', tags: ['v1.1.0-b.0', 'v1.1.0-a.0', 'v1.0.0-b.0'] }); 279 | await exec('--prerelease a'); 280 | const output = shell.exec('git tag'); 281 | expect(output.stdout).toContain('1.1.0-a.1'); 282 | }); 283 | }); 284 | 285 | describe('Run ... to publish', function () { 286 | beforeEach(function () { 287 | setup(); 288 | }); 289 | 290 | afterEach(function () { 291 | reset(); 292 | }); 293 | 294 | it('does normally display `npm publish`', async function () { 295 | mock({ bump: 'patch' }); 296 | await exec(''); 297 | verifyLogPrinted('npm publish'); 298 | }); 299 | 300 | it('can display publish hints with custom npm client name', async function () { 301 | mock({ bump: 'patch' }); 302 | await exec('--npmPublishHint "yarn publish"'); 303 | verifyLogPrinted('yarn publish'); 304 | }); 305 | 306 | it('does not display `npm publish` if the package is private', async function () { 307 | writePackageJson('1.0.0', { private: true }); 308 | mock({ bump: 'patch' }); 309 | await exec(''); 310 | verifyLogNotPrinted('npm publish'); 311 | }); 312 | 313 | it('does not display `npm publish` if there is no package.json', async function () { 314 | shell.rm('package.json'); 315 | mock({ bump: 'patch' }); 316 | await exec(''); 317 | verifyLogNotPrinted('npm publish'); 318 | }); 319 | 320 | it('does not display `all staged files` without the --commit-all flag', async function () { 321 | mock({ bump: 'patch' }); 322 | await exec(''); 323 | verifyLogNotPrinted('all staged files'); 324 | }); 325 | 326 | it('does display `all staged files` if the --commit-all flag is passed', async function () { 327 | mock({ bump: 'patch' }); 328 | await exec('--commit-all'); 329 | verifyLogPrinted('all staged files'); 330 | }); 331 | 332 | it('advises use of --tag prerelease for publishing to npm', async function () { 333 | writePackageJson('1.0.0'); 334 | fs.writeFileSync( 335 | 'CHANGELOG.md', 336 | 'legacy header format\n', 337 | 'utf-8', 338 | ); 339 | 340 | mock({ bump: 'patch' }); 341 | await exec('--prerelease'); 342 | verifyLogPrinted('--tag prerelease'); 343 | }); 344 | 345 | it('advises use of --tag alpha for publishing to npm when tagging alpha', async function () { 346 | writePackageJson('1.0.0'); 347 | fs.writeFileSync( 348 | 'CHANGELOG.md', 349 | 'legacy header format\n', 350 | 'utf-8', 351 | ); 352 | 353 | mock({ bump: 'patch' }); 354 | await exec('--prerelease alpha'); 355 | verifyLogPrinted('--tag alpha'); 356 | }); 357 | 358 | it('does not advise use of --tag prerelease for private modules', async function () { 359 | writePackageJson('1.0.0', { private: true }); 360 | fs.writeFileSync( 361 | 'CHANGELOG.md', 362 | 'legacy header format\n', 363 | 'utf-8', 364 | ); 365 | 366 | mock({ bump: 'minor' }); 367 | await exec('--prerelease'); 368 | verifyLogNotPrinted('--tag prerelease'); 369 | }); 370 | }); 371 | }); 372 | -------------------------------------------------------------------------------- /test/invalid-config.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | function exec() { 9 | const cli = require('../command'); 10 | const opt = cli.parse('commit-and-tag-version'); 11 | opt.skip = { commit: true, tag: true }; 12 | return require('../index')(opt); 13 | } 14 | 15 | /** 16 | * Mock external conventional-changelog modules 17 | * 18 | * Mocks should be unregistered in test cleanup by calling unmock() 19 | * 20 | * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 21 | * changelog?: string | Error | Array string | null> 22 | * tags?: string[] | Error 23 | */ 24 | function mock({ bump, changelog, tags } = {}) { 25 | mockers.mockRecommendedBump({ bump }); 26 | 27 | if (!Array.isArray(changelog)) changelog = [changelog]; 28 | 29 | mockers.mockConventionalChangelog({ changelog }); 30 | 31 | mockers.mockGitSemverTags({ tags }); 32 | } 33 | 34 | function setupTestDirectory() { 35 | shell.rm('-rf', 'invalid-config-temp'); 36 | shell.config.silent = true; 37 | shell.mkdir('invalid-config-temp'); 38 | shell.cd('invalid-config-temp'); 39 | } 40 | 41 | function resetShell() { 42 | shell.cd('../'); 43 | shell.rm('-rf', 'invalid-config-temp'); 44 | } 45 | 46 | /** 47 | * This test is very sensitive to the setup of "tmp" directories and must currently be run in it's own "Jest" runner instance. 48 | * By default Jest spawns a Runner per-test file even if running serially each test in a File 49 | * When we refactored from Mocha -> Jest, if this test was run as part of a larger test-suite, it would always fail, due to presence of a valid .verisonrc 50 | * somewhere in the "real" or "tmp" filesystem, despite the shell code seemingly setting up and tearing down correctly 51 | */ 52 | describe('invalid .versionrc', function () { 53 | beforeEach(function () { 54 | setupTestDirectory(); 55 | 56 | fs.writeFileSync( 57 | 'package.json', 58 | JSON.stringify({ version: '1.0.0' }), 59 | 'utf-8', 60 | ); 61 | }); 62 | 63 | afterEach(function () { 64 | resetShell(); 65 | }); 66 | 67 | it('throws an error when a non-object is returned from .versionrc.js', async function () { 68 | mock({ bump: 'minor' }); 69 | fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8'); 70 | 71 | expect(exec).toThrow(/Invalid configuration/); 72 | }); 73 | }); 74 | -------------------------------------------------------------------------------- /test/mocks/Project-6.3.1.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 6.3.1 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/mocks/Project-6.4.0.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 6.4.0 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/mocks/VERSION-1.0.0.txt: -------------------------------------------------------------------------------- 1 | 1.0.0 -------------------------------------------------------------------------------- /test/mocks/VERSION-6.3.1.txt: -------------------------------------------------------------------------------- 1 | 6.3.1 -------------------------------------------------------------------------------- /test/mocks/build-6.3.1.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.springframework.boot") version "2.4.6" 3 | kotlin("jvm") version "1.4.31" 4 | kotlin("plugin.spring") version "1.4.31" 5 | } 6 | 7 | version = "6.3.1" 8 | java.sourceCompatibility = JavaVersion.VERSION_1_8 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/mocks/build-6.4.0.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.springframework.boot") version "2.4.6" 3 | kotlin("jvm") version "1.4.31" 4 | kotlin("plugin.spring") version "1.4.31" 5 | } 6 | 7 | version = "6.4.0" 8 | java.sourceCompatibility = JavaVersion.VERSION_1_8 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/mocks/increment-version.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /test/mocks/jest-mocks.js: -------------------------------------------------------------------------------- 1 | const gitSemverTags = require('git-semver-tags'); 2 | const conventionalChangelog = require('conventional-changelog'); 3 | const conventionalRecommendedBump = require('conventional-recommended-bump'); 4 | 5 | const { Readable } = require('stream'); 6 | 7 | jest.mock('conventional-changelog'); 8 | jest.mock('conventional-recommended-bump'); 9 | jest.mock('git-semver-tags'); 10 | 11 | const mockGitSemverTags = ({ tags = [] }) => { 12 | gitSemverTags.mockImplementation((opts, cb) => { 13 | if (tags instanceof Error) cb(tags); 14 | else cb(null, tags); 15 | }); 16 | }; 17 | 18 | const mockConventionalChangelog = ({ changelog }) => { 19 | conventionalChangelog.mockImplementation( 20 | (opt) => 21 | new Readable({ 22 | read(_size) { 23 | const next = changelog.shift(); 24 | if (next instanceof Error) { 25 | this.destroy(next); 26 | } else if (typeof next === 'function') { 27 | this.push(next(opt)); 28 | } else { 29 | this.push(next ? Buffer.from(next, 'utf8') : null); 30 | } 31 | }, 32 | }), 33 | ); 34 | }; 35 | 36 | const mockRecommendedBump = ({ bump }) => { 37 | conventionalRecommendedBump.mockImplementation((opt, parserOpts, cb) => { 38 | if (typeof bump === 'function') bump(opt, parserOpts, cb); 39 | else if (bump instanceof Error) cb(bump); 40 | else cb(null, bump ? { releaseType: bump } : {}); 41 | }); 42 | }; 43 | 44 | module.exports = { 45 | mockGitSemverTags, 46 | mockConventionalChangelog, 47 | mockRecommendedBump, 48 | }; 49 | -------------------------------------------------------------------------------- /test/mocks/manifest-6.3.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "6.3.1" 3 | } -------------------------------------------------------------------------------- /test/mocks/mix.exs: -------------------------------------------------------------------------------- 1 | defmodule StandardVersion.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :standard_version, 7 | version: "0.1.0", 8 | elixir: "~> 1.9", 9 | start_permanent: Mix.env() == :prod, 10 | deps: deps() 11 | ] 12 | end 13 | 14 | # Run "mix help compile.app" to learn about applications. 15 | def application do 16 | [ 17 | extra_applications: [:logger] 18 | ] 19 | end 20 | 21 | # Run "mix help deps" to learn about dependencies. 22 | defp deps do 23 | [ 24 | # {:dep_from_hexpm, "~> 0.3.0"}, 25 | # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} 26 | ] 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /test/mocks/openapi-1.2.3-crlf.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.2" 2 | info: 3 | title: Mock API 4 | description: >- 5 | Description of Mock API 6 | version: "1.2.3" 7 | termsOfService: http://swagger.io/terms/ 8 | externalDocs: 9 | description: Find out more 10 | url: https://example.com/foo/bar 11 | servers: 12 | - url: http://example.com 13 | -------------------------------------------------------------------------------- /test/mocks/openapi-1.2.3-lf.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.2" 2 | info: 3 | title: Mock API 4 | description: >- 5 | Description of Mock API 6 | version: "1.2.3" 7 | termsOfService: http://swagger.io/terms/ 8 | externalDocs: 9 | description: Find out more 10 | url: https://example.com/foo/bar 11 | servers: 12 | - url: http://example.com 13 | -------------------------------------------------------------------------------- /test/mocks/openapi-1.3.0-crlf.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.2" 2 | info: 3 | title: Mock API 4 | description: >- 5 | Description of Mock API 6 | version: "1.3.0" 7 | termsOfService: http://swagger.io/terms/ 8 | externalDocs: 9 | description: Find out more 10 | url: https://example.com/foo/bar 11 | servers: 12 | - url: http://example.com 13 | -------------------------------------------------------------------------------- /test/mocks/openapi-1.3.0-lf.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.2" 2 | info: 3 | title: Mock API 4 | description: >- 5 | Description of Mock API 6 | version: "1.3.0" 7 | termsOfService: http://swagger.io/terms/ 8 | externalDocs: 9 | description: Find out more 10 | url: https://example.com/foo/bar 11 | servers: 12 | - url: http://example.com 13 | -------------------------------------------------------------------------------- /test/mocks/pom-6.3.1-crlf.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.mycompany.app 6 | my-app 7 | 3.0.0 8 | 9 | 10 | com.mycompany.app 11 | my-module 12 | 6.3.1 13 | 14 | 15 | 2.0.0 16 | 17 | 18 | 19 | 20 | org.some.dependency 21 | some-artifact 22 | ${some.version} 23 | 24 | 25 | org.another.dependency 26 | another-artifact 27 | 1.0.0 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/mocks/pom-6.3.1-lf.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.mycompany.app 6 | my-app 7 | 3.0.0 8 | 9 | 10 | com.mycompany.app 11 | my-module 12 | 6.3.1 13 | 14 | 15 | 2.0.0 16 | 17 | 18 | 19 | 20 | org.some.dependency 21 | some-artifact 22 | ${some.version} 23 | 24 | 25 | org.another.dependency 26 | another-artifact 27 | 1.0.0 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/mocks/pom-6.4.0-crlf.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.mycompany.app 6 | my-app 7 | 3.0.0 8 | 9 | 10 | com.mycompany.app 11 | my-module 12 | 6.4.0 13 | 14 | 15 | 2.0.0 16 | 17 | 18 | 19 | 20 | org.some.dependency 21 | some-artifact 22 | ${some.version} 23 | 24 | 25 | org.another.dependency 26 | another-artifact 27 | 1.0.0 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/mocks/pom-6.4.0-lf.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.mycompany.app 6 | my-app 7 | 3.0.0 8 | 9 | 10 | com.mycompany.app 11 | my-module 12 | 6.4.0 13 | 14 | 15 | 2.0.0 16 | 17 | 18 | 19 | 20 | org.some.dependency 21 | some-artifact 22 | ${some.version} 23 | 24 | 25 | org.another.dependency 26 | another-artifact 27 | 1.0.0 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/mocks/pubspec-6.3.1-crlf.yaml: -------------------------------------------------------------------------------- 1 | # This is a comment that should be preserved 2 | name: mock 3 | description: "A mock YAML file" 4 | version: 6.3.1 5 | 6 | environment: 7 | dart: ">=3.2.6 <4.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | # For information on the generic Dart part of this file, see the 19 | # following page: https://dart.dev/tools/pub/pubspec 20 | 21 | # The following section is specific to Flutter packages. 22 | flutter: 23 | uses-material-design: true 24 | generate: true 25 | 26 | # More comments here nested under one entry 27 | # 28 | # These comments should also be preserved. 29 | 30 | # Another comment block, separated from the first one 31 | assets: 32 | - assets/icons/ 33 | - assets/images/ 34 | -------------------------------------------------------------------------------- /test/mocks/pubspec-6.3.1.yaml: -------------------------------------------------------------------------------- 1 | # This is a comment that should be preserved 2 | name: mock 3 | description: "A mock YAML file" 4 | version: 6.3.1 5 | 6 | environment: 7 | dart: ">=3.2.6 <4.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | # For information on the generic Dart part of this file, see the 19 | # following page: https://dart.dev/tools/pub/pubspec 20 | 21 | # The following section is specific to Flutter packages. 22 | flutter: 23 | uses-material-design: true 24 | generate: true 25 | 26 | # More comments here nested under one entry 27 | # 28 | # These comments should also be preserved. 29 | 30 | # Another comment block, separated from the first one 31 | assets: 32 | - assets/icons/ 33 | - assets/images/ 34 | -------------------------------------------------------------------------------- /test/mocks/pubspec-6.4.0-crlf.yaml: -------------------------------------------------------------------------------- 1 | # This is a comment that should be preserved 2 | name: mock 3 | description: "A mock YAML file" 4 | version: 6.4.0 5 | 6 | environment: 7 | dart: ">=3.2.6 <4.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | # For information on the generic Dart part of this file, see the 19 | # following page: https://dart.dev/tools/pub/pubspec 20 | 21 | # The following section is specific to Flutter packages. 22 | flutter: 23 | uses-material-design: true 24 | generate: true 25 | 26 | # More comments here nested under one entry 27 | # 28 | # These comments should also be preserved. 29 | 30 | # Another comment block, separated from the first one 31 | assets: 32 | - assets/icons/ 33 | - assets/images/ 34 | -------------------------------------------------------------------------------- /test/mocks/pubspec-6.4.0.yaml: -------------------------------------------------------------------------------- 1 | # This is a comment that should be preserved 2 | name: mock 3 | description: "A mock YAML file" 4 | version: 6.4.0 5 | 6 | environment: 7 | dart: ">=3.2.6 <4.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | # For information on the generic Dart part of this file, see the 19 | # following page: https://dart.dev/tools/pub/pubspec 20 | 21 | # The following section is specific to Flutter packages. 22 | flutter: 23 | uses-material-design: true 24 | generate: true 25 | 26 | # More comments here nested under one entry 27 | # 28 | # These comments should also be preserved. 29 | 30 | # Another comment block, separated from the first one 31 | assets: 32 | - assets/icons/ 33 | - assets/images/ 34 | -------------------------------------------------------------------------------- /test/mocks/pyproject-1.0.0.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "test" 3 | version = "1.0.0" 4 | description = "" 5 | authors = [] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.8" 9 | 10 | [build-system] 11 | requires = ["poetry>=1"] 12 | build-backend = "poetry.masonry.api" 13 | -------------------------------------------------------------------------------- /test/mocks/pyproject-1.1.0.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "test" 3 | version = "1.1.0" 4 | description = "" 5 | authors = [] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.8" 9 | 10 | [build-system] 11 | requires = ["poetry>=1"] 12 | build-backend = "poetry.masonry.api" 13 | -------------------------------------------------------------------------------- /test/mocks/updater/customer-updater.js: -------------------------------------------------------------------------------- 1 | const REPLACER = /version: "(.*)"/; 2 | 3 | module.exports.readVersion = function (contents) { 4 | return REPLACER.exec(contents)[1]; 5 | }; 6 | 7 | module.exports.writeVersion = function (contents, version) { 8 | return contents.replace(REPLACER.exec(contents)[0], `version: "${version}"`); 9 | }; 10 | -------------------------------------------------------------------------------- /test/mocks/updater/increment-updater.js: -------------------------------------------------------------------------------- 1 | module.exports.readVersion = function (contents) { 2 | return Number.parseInt(contents); 3 | }; 4 | 5 | module.exports.writeVersion = function (contents) { 6 | return this.readVersion(contents) + 1; 7 | }; 8 | -------------------------------------------------------------------------------- /test/mocks/version.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absolute-version/commit-and-tag-version/400e3c17616cfc2481c5a17dad85c0d4d67a49f1/test/mocks/version.txt -------------------------------------------------------------------------------- /test/pre-commit-hook.integration-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const fs = require('fs'); 5 | 6 | const mockers = require('./mocks/jest-mocks'); 7 | 8 | // Jest swallows most standard console logs not explicitly defined into a custom logger 9 | // see: https://stackoverflow.com/questions/51555568/remove-logging-the-origin-line-in-jest 10 | const consoleWarnSpy = jest.spyOn(global.console, 'warn').mockImplementation(); 11 | 12 | const consoleInfoSpy = jest.spyOn(global.console, 'info').mockImplementation(); 13 | 14 | const consoleErrorSpy = jest 15 | .spyOn(global.console, 'error') 16 | .mockImplementation(); 17 | 18 | function exec(opt = '') { 19 | if (typeof opt === 'string') { 20 | const cli = require('../command'); 21 | opt = cli.parse(`commit-and-tag-version ${opt}`); 22 | } 23 | return require('../index')(opt); 24 | } 25 | 26 | function writePackageJson(version, option) { 27 | const pkg = Object.assign({}, option, { version }); 28 | fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8'); 29 | } 30 | 31 | function writeHook(hookName, causeError, script) { 32 | shell.mkdir('-p', 'scripts'); 33 | let content = script || 'console.error("' + hookName + ' ran")'; 34 | content += causeError ? '\nthrow new Error("' + hookName + '-failure")' : ''; 35 | fs.writeFileSync('scripts/' + hookName + '.js', content, 'utf-8'); 36 | fs.chmodSync('scripts/' + hookName + '.js', '755'); 37 | } 38 | 39 | function setupTempGitRepo() { 40 | shell.rm('-rf', 'pre-commit-hook-temp'); 41 | shell.config.silent = true; 42 | shell.mkdir('pre-commit-hook-temp'); 43 | shell.cd('pre-commit-hook-temp'); 44 | shell.exec('git init'); 45 | shell.exec('git config commit.gpgSign false'); 46 | shell.exec('git config core.autocrlf false'); 47 | shell.exec('git commit --allow-empty -m"root-commit"'); 48 | } 49 | 50 | function setup() { 51 | setupTempGitRepo(); 52 | writePackageJson('1.0.0'); 53 | } 54 | 55 | function clearCapturedSpyCalls() { 56 | consoleInfoSpy.mockClear(); 57 | consoleWarnSpy.mockClear(); 58 | consoleErrorSpy.mockClear(); 59 | } 60 | 61 | function resetShell() { 62 | shell.cd('../'); 63 | shell.rm('-rf', 'pre-commit-hook-temp'); 64 | } 65 | 66 | function reset() { 67 | resetShell(); 68 | 69 | clearCapturedSpyCalls(); 70 | } 71 | 72 | /** 73 | * Mock external conventional-changelog modules 74 | * 75 | * bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } 76 | * changelog?: string | Error | Array string | null> 77 | * tags?: string[] | Error 78 | */ 79 | function mock({ bump, changelog, tags }) { 80 | if (bump === undefined) throw new Error('bump must be defined for mock()'); 81 | 82 | mockers.mockRecommendedBump({ bump }); 83 | 84 | if (!Array.isArray(changelog)) changelog = [changelog]; 85 | mockers.mockConventionalChangelog({ changelog }); 86 | 87 | mockers.mockGitSemverTags({ tags }); 88 | } 89 | 90 | function getLog(expectedLog, spy = consoleInfoSpy) { 91 | const consoleInfoLogs = spy.mock.calls.map((args) => args[0]); 92 | return consoleInfoLogs.find((log) => log.includes(expectedLog)); 93 | } 94 | 95 | function verifyLogPrinted(expectedLog, spy = consoleInfoSpy) { 96 | const logType = spy === consoleInfoSpy ? 'info' : 'warn'; 97 | const desiredLog = getLog(expectedLog, spy); 98 | if (desiredLog) { 99 | expect(desiredLog).toMatch(expectedLog); 100 | } else { 101 | expect(`no ${logType} Log printed matching`).toMatch(expectedLog); 102 | } 103 | } 104 | 105 | describe('precommit hook', function () { 106 | beforeEach(function () { 107 | setup(); 108 | }); 109 | 110 | afterEach(function () { 111 | reset(); 112 | }); 113 | 114 | it('should run the precommit hook when provided via .versionrc.json (#371)', async function () { 115 | fs.writeFileSync( 116 | '.versionrc.json', 117 | JSON.stringify({ 118 | scripts: { precommit: 'node scripts/precommit' }, 119 | }), 120 | 'utf-8', 121 | ); 122 | 123 | writeHook('precommit'); 124 | fs.writeFileSync( 125 | 'CHANGELOG.md', 126 | 'legacy header format\n', 127 | 'utf-8', 128 | ); 129 | mock({ bump: 'minor' }); 130 | await exec(''); 131 | verifyLogPrinted('precommit ran', consoleWarnSpy); 132 | }); 133 | 134 | it('should run the precommit hook when provided', async function () { 135 | writePackageJson('1.0.0', { 136 | 'commit-and-tag-version': { 137 | scripts: { precommit: 'node scripts/precommit' }, 138 | }, 139 | }); 140 | writeHook('precommit'); 141 | fs.writeFileSync( 142 | 'CHANGELOG.md', 143 | 'legacy header format\n', 144 | 'utf-8', 145 | ); 146 | 147 | mock({ bump: 'minor' }); 148 | await exec('--patch'); 149 | verifyLogPrinted('precommit ran', consoleWarnSpy); 150 | }); 151 | 152 | it('should run the precommit hook and throw error when precommit fails', async function () { 153 | writePackageJson('1.0.0', { 154 | 'commit-and-tag-version': { 155 | scripts: { precommit: 'node scripts/precommit' }, 156 | }, 157 | }); 158 | writeHook('precommit', true); 159 | fs.writeFileSync( 160 | 'CHANGELOG.md', 161 | 'legacy header format\n', 162 | 'utf-8', 163 | ); 164 | 165 | mock({ bump: 'minor' }); 166 | let errorMessage = ''; 167 | try { 168 | await exec('--patch'); 169 | } catch (e) { 170 | errorMessage = e.message; 171 | } 172 | expect(errorMessage).toMatch('precommit-failure'); 173 | }); 174 | 175 | it('should allow an alternate commit message to be provided by precommit script', async function () { 176 | writePackageJson('1.0.0', { 177 | 'commit-and-tag-version': { 178 | scripts: { precommit: 'node scripts/precommit' }, 179 | }, 180 | }); 181 | writeHook('precommit', false, 'console.log("releasing %s delivers #222")'); 182 | fs.writeFileSync( 183 | 'CHANGELOG.md', 184 | 'legacy header format\n', 185 | 'utf-8', 186 | ); 187 | 188 | mock({ bump: 'minor' }); 189 | await exec('--patch'); 190 | expect(shell.exec('git log --oneline -n1').stdout).toMatch(/delivers #222/); 191 | }); 192 | }); 193 | -------------------------------------------------------------------------------- /test/preset.integration-test.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs'); 2 | const fs = require('fs'); 3 | 4 | function exec(opt) { 5 | const cli = require('../command'); 6 | opt = cli.parse(`commit-and-tag-version ${opt} --silent`); 7 | opt.skip = { commit: true, tag: true }; 8 | return require('../index')(opt); 9 | } 10 | 11 | function setupTempGitRepo() { 12 | shell.rm('-rf', 'preset-temp'); 13 | shell.config.silent = true; 14 | shell.mkdir('preset-temp'); 15 | shell.cd('preset-temp'); 16 | shell.exec('git init'); 17 | shell.exec('git config commit.gpgSign false'); 18 | shell.exec('git config core.autocrlf false'); 19 | shell.exec('git commit --allow-empty -m "initial commit"'); 20 | shell.exec('git commit --allow-empty -m "feat: A feature commit."'); 21 | shell.exec('git commit --allow-empty -m "perf: A performance change."'); 22 | shell.exec('git commit --allow-empty -m "chore: A chore commit."'); 23 | shell.exec('git commit --allow-empty -m "ci: A ci commit."'); 24 | shell.exec('git commit --allow-empty -m "custom: A custom commit."'); 25 | } 26 | 27 | function resetShell() { 28 | shell.cd('../'); 29 | shell.rm('-rf', 'preset-temp'); 30 | } 31 | 32 | describe('presets', function () { 33 | beforeEach(function () { 34 | setupTempGitRepo(); 35 | }); 36 | 37 | afterEach(function () { 38 | resetShell(); 39 | }); 40 | 41 | it('Conventional Commits (default)', async function () { 42 | await exec(); 43 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 44 | expect(content).toContain('### Features'); 45 | expect(content).not.toContain('### Performance Improvements'); 46 | expect(content).not.toContain('### Custom'); 47 | }); 48 | 49 | it('Angular', async function () { 50 | await exec('--preset angular'); 51 | const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); 52 | expect(content).toContain('### Features'); 53 | expect(content).toContain('### Performance Improvements'); 54 | expect(content).not.toContain('### Custom'); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /test/stringify-package.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const stringifyPackage = require('../lib/stringify-package'); 4 | 5 | describe('stringifyPackage()', function () { 6 | const dummy = { name: 'dummy' }; 7 | 8 | it('with no params uses \\n', function () { 9 | expect(stringifyPackage(dummy)).toMatch(/\n$/m); 10 | }); 11 | 12 | it('uses \\n', function () { 13 | expect(stringifyPackage(dummy, 2, '\n')).toMatch(/\n$/m); 14 | }); 15 | 16 | it('uses \\r\\n', function () { 17 | expect(stringifyPackage(dummy, 2, '\r\n')).toMatch(/\r\n$/m); 18 | }); 19 | 20 | it('with no params uses 2-space indent', function () { 21 | expect(stringifyPackage(dummy)).toMatch(/^ {2}"name": "dummy"/m); 22 | }); 23 | 24 | it('uses 2-space indent', function () { 25 | expect(stringifyPackage(dummy, 2, '\n')).toMatch(/^ {2}"name": "dummy"/m); 26 | }); 27 | 28 | it('uses 4-space indent', function () { 29 | expect(stringifyPackage(dummy, 4, '\n')).toMatch(/^ {4}"name": "dummy"/m); 30 | }); 31 | 32 | it('0 works', function () { 33 | expect(stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length).toEqual(2); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/utils.spec.js: -------------------------------------------------------------------------------- 1 | const { promises: fsp } = require('fs'); 2 | 3 | let mockFs; 4 | 5 | const setLockFile = (lockFile) => { 6 | if (mockFs) { 7 | mockFs.mockRestore(); 8 | } 9 | mockFs = jest.spyOn(fsp, 'access').mockImplementation(async (path) => { 10 | if (lockFile && path.endsWith(lockFile)) { 11 | return Promise.resolve(); 12 | } 13 | return Promise.reject(new Error('Invalid lockfile')); 14 | }); 15 | }; 16 | 17 | describe('utils', function () { 18 | it('detectPMByLockFile should work', async function () { 19 | const { detectPMByLockFile } = require('../lib/detect-package-manager'); 20 | 21 | let pm = await detectPMByLockFile(); 22 | expect(pm).toEqual('npm'); 23 | 24 | setLockFile('yarn.lock'); 25 | pm = await detectPMByLockFile(); 26 | expect(pm).toEqual('yarn'); 27 | 28 | setLockFile('package-lock.json'); 29 | pm = await detectPMByLockFile(); 30 | expect(pm).toEqual('npm'); 31 | 32 | setLockFile('pnpm-lock.yaml'); 33 | pm = await detectPMByLockFile(); 34 | expect(pm).toEqual('pnpm'); 35 | }); 36 | }); 37 | --------------------------------------------------------------------------------