diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bb920942a..d17b4fcc5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,7 +23,7 @@ jobs: OS: ${{ matrix.os }} NODE_VERSION: ${{ matrix.node }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4 - run: git fetch --prune --unshallow - run: git config --global user.name 'Actions' - run: git config --global user.email 'dummy@example.org' diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 9fdbbe7b8..c3ffddc2b 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -15,7 +15,7 @@ jobs: release-type: node package-name: commit-and-tag-version # The logic below handles the npm publication: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4 # these if statements ensure that a publication only occurs when # a new release is created: if: ${{ steps.release.outputs.release_created }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 770201d3b..79efe5bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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. +## [12.6.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.5.2...v12.6.0) (2025-08-27) + + +### Features + +* add --config option to allow custom config file path ([#237](https://github.com/absolute-version/commit-and-tag-version/issues/237)) ([3958e68](https://github.com/absolute-version/commit-and-tag-version/commit/3958e688a60df4f1ba46137d1f4147a65817c8d7)) + ## [12.5.2](https://github.com/absolute-version/commit-and-tag-version/compare/v12.5.1...v12.5.2) (2025-07-30) diff --git a/README.md b/README.md index 85a850241..b466a5e13 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ _Having problems? Want to contribute? Join us on the [node-tooling community Sla - [Release as a Pre-Release](#release-as-a-pre-release) - [Release as a Target Type Imperatively (`npm version`-like)](#release-as-a-target-type-imperatively-npm-version-like) - [Prevent Git Hooks](#prevent-git-hooks) + - [Custom Config Path](#custom-config-path) - [Signing Commits and Tags](#signing-commits-and-tags) - [Lifecycle Scripts](#lifecycle-scripts) - [Skipping Lifecycle Steps](#skipping-lifecycle-steps) @@ -312,6 +313,23 @@ npm run release -- --no-verify commit-and-tag-version --no-verify ``` +### Custom Config Path + +Specify a custom path to the configuration file using the `--config` option + +```sh +commit-and-tag-version --config ./path/to/.versionrc.js + +# or using alias +commit-and-tag-version -c ./path/to/.versionrc.js +``` + +All config file formats can be used: + +```sh +commit-and-tag-version -c ./path/to/.versionrc[.js|.cjs|.json] +``` + ### Signing Commits and Tags If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command. diff --git a/command.js b/command.js index c5d98480e..8d04da3d6 100755 --- a/command.js +++ b/command.js @@ -132,6 +132,12 @@ const yargs = require('yargs') default: defaults.npmPublishHint, describe: 'Customized publishing hint', }) + .option('config', { + type: 'string', + default: defaults.config, + alias: 'c', + describe: 'Path to a custom configuration file', + }) .check((argv) => { if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) { throw Error('scripts must be an object'); @@ -150,9 +156,10 @@ const yargs = require('yargs') ) .pkgConf('standard-version') .pkgConf('commit-and-tag-version') - .config(getConfiguration()) .wrap(97); +yargs.config(getConfiguration(yargs.argv.config)); + Object.keys(spec.properties).forEach((propertyKey) => { const property = spec.properties[propertyKey]; yargs.option(propertyKey, { diff --git a/defaults.js b/defaults.js index 9cf40e034..83d69d225 100644 --- a/defaults.js +++ b/defaults.js @@ -17,6 +17,7 @@ const defaults = { gitTagFallback: true, preset: require.resolve('conventional-changelog-conventionalcommits'), npmPublishHint: undefined, + config: undefined, }; /** diff --git a/lib/configuration.js b/lib/configuration.js index f169631ea..be8c634ef 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -9,9 +9,13 @@ const CONFIGURATION_FILES = [ '.versionrc.js', ]; -module.exports.getConfiguration = function () { +module.exports.getConfiguration = function (configFile) { let config = {}; - const configPath = findUp.sync(CONFIGURATION_FILES); + + // If the user has provided a configuration file via the `--config` argument, we use that. + const configurationFiles = configFile ?? CONFIGURATION_FILES; + + const configPath = findUp.sync(configurationFiles); if (!configPath) { return config; } diff --git a/package-lock.json b/package-lock.json index f46c12f94..69bd560bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commit-and-tag-version", - "version": "12.5.2", + "version": "12.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "commit-and-tag-version", - "version": "12.5.2", + "version": "12.6.0", "license": "ISC", "dependencies": { "chalk": "^2.4.2", @@ -40,7 +40,7 @@ "jest": "^29.7.0", "jest-serial-runner": "^1.2.1", "prettier": "^3.3.3", - "shelljs": "^0.8.5", + "shelljs": "^0.10.0", "strip-ansi": "^6.0.1" }, "engines": { @@ -4504,14 +4504,6 @@ "node": ">= 0.4" } }, - "node_modules/interpret": { - "version": "1.4.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, "node_modules/is-array-buffer": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", @@ -7531,16 +7523,6 @@ "node": ">= 6" } }, - "node_modules/rechoir": { - "version": "0.6.2", - "dev": true, - "dependencies": { - "resolve": "^1.1.6" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/redent": { "version": "3.0.0", "license": "MIT", @@ -7798,19 +7780,17 @@ } }, "node_modules/shelljs": { - "version": "0.8.5", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.10.0.tgz", + "integrity": "sha512-Jex+xw5Mg2qMZL3qnzXIfaxEtBaC4n7xifqaqtrZDdlheR70OGkydrPJWT0V1cA1k3nanC86x9FwAmQl6w3Klw==", "dev": true, "license": "BSD-3-Clause", "dependencies": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - }, - "bin": { - "shjs": "bin/shjs" + "execa": "^5.1.1", + "fast-glob": "^3.3.2" }, "engines": { - "node": ">=4" + "node": ">=18" } }, "node_modules/side-channel": { diff --git a/package.json b/package.json index 466aad691..46f347be2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commit-and-tag-version", - "version": "12.5.2", + "version": "12.6.0", "description": "replacement for `npm version` with automatic CHANGELOG generation", "bin": "bin/cli.js", "scripts": { @@ -67,7 +67,7 @@ "jest": "^29.7.0", "jest-serial-runner": "^1.2.1", "prettier": "^3.3.3", - "shelljs": "^0.8.5", + "shelljs": "^0.10.0", "strip-ansi": "^6.0.1" } } diff --git a/test/config-files.integration-test.js b/test/config-files.integration-test.js index e1c54f3c9..dba07a780 100644 --- a/test/config-files.integration-test.js +++ b/test/config-files.integration-test.js @@ -86,6 +86,30 @@ describe('config files', function () { expect(content).toContain(issueUrlFormat); }); + it('reads config from custom path', async function () { + const issueUrlFormat = 'http://www.foo.com/{{id}}'; + const changelog = ({ preset }) => preset.issueUrlFormat; + mock({ bump: 'minor', changelog }); + fs.mkdirSync('custom-folder'); + fs.writeFileSync( + 'custom-folder/.versionrc.json', + JSON.stringify({ issueUrlFormat }), + 'utf-8', + ); + + // Override process.argv to simulate CLI arguments before `exec`. + // This ensures yargs parses the custom config argument. + const originalArgv = process.argv; + process.argv = ['node', 'script.js', '-c', 'custom-folder/.versionrc.json']; + + await exec(['-c', 'custom-folder/.versionrc.json']); + const content = fs.readFileSync('CHANGELOG.md', 'utf-8'); + expect(content).toContain(issueUrlFormat); + + // Restore original process.argv + process.argv = originalArgv; + }); + it('evaluates a config-function from .versionrc.js', async function () { const issueUrlFormat = 'http://www.foo.com/{{id}}'; const src = `module.exports = function() { return ${JSON.stringify({