commit-and-tag-version 12.7.3 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yaml +8 -15
- package/.github/workflows/release-please.yml +2 -2
- package/CHANGELOG.md +29 -0
- package/MIGRATION.md +51 -0
- package/README.md +25 -24
- package/bin/cli.js +2 -2
- package/command.js +9 -4
- package/defaults.js +5 -3
- package/eslint.config.mjs +52 -42
- package/index.js +12 -12
- package/lib/checkpoint.js +5 -5
- package/lib/configuration.js +21 -8
- package/lib/detect-package-manager.js +4 -8
- package/lib/format-commit-message.js +2 -2
- package/lib/latest-semver-tag.js +30 -30
- package/lib/lifecycles/bump.js +97 -65
- package/lib/lifecycles/changelog.js +48 -60
- package/lib/lifecycles/commit.js +8 -8
- package/lib/lifecycles/tag.js +10 -10
- package/lib/preset-loader.js +73 -9
- package/lib/print-error.js +3 -3
- package/lib/run-exec.js +6 -5
- package/lib/run-execFile.js +6 -5
- package/lib/run-lifecycle-script.js +6 -6
- package/lib/stringify-package.js +1 -5
- package/lib/updaters/index.js +25 -12
- package/lib/updaters/types/csproj.js +4 -4
- package/lib/updaters/types/gradle.js +4 -4
- package/lib/updaters/types/json.js +9 -9
- package/lib/updaters/types/maven.js +10 -6
- package/lib/updaters/types/openapi.js +6 -6
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/updaters/types/python.js +4 -4
- package/lib/updaters/types/yaml.js +6 -6
- package/lib/write-file.js +3 -3
- package/package.json +20 -15
- package/test/commit-message-config.integration-test.js +23 -10
- package/test/config-files.integration-test.js +25 -10
- package/test/config-keys.integration-test.js +20 -7
- package/test/core.spec.js +82 -37
- package/test/esm-config.integration-test.js +97 -0
- package/test/git.integration-test.js +23 -15
- package/test/invalid-config.integration-test.js +19 -9
- package/test/mocks/pom-6.3.1-attrs-lf.xml +1 -0
- package/test/mocks/pom-6.4.0-attrs-lf.xml +1 -0
- package/test/mocks/vitest-mocks.js +260 -0
- package/test/package.json +3 -0
- package/test/pre-commit-hook.integration-test.js +22 -14
- package/test/preset.integration-test.js +7 -5
- package/test/setup-coverage.js +47 -0
- package/test/stringify-package.spec.js +1 -3
- package/test/utils.spec.js +3 -4
- package/vitest.config.js +26 -0
- package/jest.config.js +0 -28
- package/test/mocks/jest-mocks.js +0 -66
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import shell from 'shelljs';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
|
|
5
|
+
vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
|
|
6
|
+
vi.mock('conventional-recommended-bump', async (importOriginal) =>
|
|
7
|
+
mockers.conventionalRecommendedBumpModule(
|
|
8
|
+
await importOriginal(),
|
|
9
|
+
await import('@conventional-changelog/git-client'),
|
|
10
|
+
),
|
|
11
|
+
);
|
|
12
|
+
vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
|
|
13
|
+
mockers.gitClientModule(await importOriginal()),
|
|
14
|
+
);
|
|
7
15
|
|
|
8
16
|
// Jest swallows most standard console logs not explicitly defined into a custom logger
|
|
9
17
|
// see: https://stackoverflow.com/questions/51555568/remove-logging-the-origin-line-in-jest
|
|
10
|
-
const consoleWarnSpy =
|
|
18
|
+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
11
19
|
|
|
12
|
-
const consoleInfoSpy =
|
|
20
|
+
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
|
|
13
21
|
|
|
14
|
-
const consoleErrorSpy =
|
|
15
|
-
.spyOn(global.console, 'error')
|
|
16
|
-
.mockImplementation();
|
|
22
|
+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
23
|
|
|
18
|
-
function exec(opt = '') {
|
|
24
|
+
async function exec(opt = '') {
|
|
25
|
+
vi.resetModules();
|
|
26
|
+
const { default: cli } = await import('../command');
|
|
19
27
|
if (typeof opt === 'string') {
|
|
20
|
-
const cli = require('../command');
|
|
21
28
|
opt = cli.parse(`commit-and-tag-version ${opt}`);
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
const { default: standardVersion } = await import('../index');
|
|
31
|
+
return standardVersion(opt);
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
function writePackageJson(version, option) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import shell from 'shelljs';
|
|
2
|
+
import fs from 'fs';
|
|
3
3
|
|
|
4
|
-
function exec(opt) {
|
|
5
|
-
|
|
4
|
+
async function exec(opt) {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
const { default: cli } = await import('../command');
|
|
6
7
|
opt = cli.parse(`commit-and-tag-version ${opt} --silent`);
|
|
7
8
|
opt.skip = { commit: true, tag: true };
|
|
8
|
-
|
|
9
|
+
const { default: standardVersion } = await import('../index');
|
|
10
|
+
return standardVersion(opt);
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
function setupTempGitRepo() {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js require hook that applies Istanbul instrumentation to source files
|
|
3
|
+
* loaded via CJS require() chains.
|
|
4
|
+
*
|
|
5
|
+
* In Vitest with pool:'forks', files directly imported by tests go through
|
|
6
|
+
* Vite's transform pipeline (where @vitest/coverage-istanbul instruments them).
|
|
7
|
+
* But files loaded via CJS require() inside source code bypass Vite entirely
|
|
8
|
+
* and go through Node's native Module._load. This hook uses pirates to
|
|
9
|
+
* intercept those loads and apply Istanbul instrumentation, writing to the
|
|
10
|
+
* same __VITEST_COVERAGE__ global that the coverage provider reads.
|
|
11
|
+
*
|
|
12
|
+
* Preloaded via execArgv: ['--require', ...] in vitest.config.js.
|
|
13
|
+
*/
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { createInstrumenter } = require('istanbul-lib-instrument');
|
|
18
|
+
const { addHook } = require('pirates');
|
|
19
|
+
|
|
20
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
21
|
+
|
|
22
|
+
const instrumenter = createInstrumenter({
|
|
23
|
+
esModules: false,
|
|
24
|
+
compact: false,
|
|
25
|
+
produceSourceMap: false,
|
|
26
|
+
coverageVariable: '__VITEST_COVERAGE__',
|
|
27
|
+
coverageGlobalScope: 'globalThis',
|
|
28
|
+
coverageGlobalScopeFunc: false,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
addHook(
|
|
32
|
+
(code, filename) => {
|
|
33
|
+
return instrumenter.instrumentSync(code, filename);
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
exts: ['.js'],
|
|
37
|
+
matcher: (filename) => {
|
|
38
|
+
// Only instrument project source files, not node_modules or test files
|
|
39
|
+
return (
|
|
40
|
+
filename.startsWith(ROOT) &&
|
|
41
|
+
!filename.includes('node_modules') &&
|
|
42
|
+
!filename.includes(path.sep + 'test' + path.sep) &&
|
|
43
|
+
!filename.includes(path.sep + 'bin' + path.sep)
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
);
|
package/test/utils.spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { promises as fsp } from 'fs';
|
|
2
|
+
import { detectPMByLockFile } from '../lib/detect-package-manager';
|
|
2
3
|
|
|
3
4
|
let mockFs;
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ const setLockFile = (lockFile) => {
|
|
|
6
7
|
if (mockFs) {
|
|
7
8
|
mockFs.mockRestore();
|
|
8
9
|
}
|
|
9
|
-
mockFs =
|
|
10
|
+
mockFs = vi.spyOn(fsp, 'access').mockImplementation(async (path) => {
|
|
10
11
|
if (lockFile && path.endsWith(lockFile)) {
|
|
11
12
|
return Promise.resolve();
|
|
12
13
|
}
|
|
@@ -16,8 +17,6 @@ const setLockFile = (lockFile) => {
|
|
|
16
17
|
|
|
17
18
|
describe('utils', function () {
|
|
18
19
|
it('detectPMByLockFile should work', async function () {
|
|
19
|
-
const { detectPMByLockFile } = require('../lib/detect-package-manager');
|
|
20
|
-
|
|
21
20
|
let pm = await detectPMByLockFile();
|
|
22
21
|
expect(pm).toEqual('npm');
|
|
23
22
|
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
testTimeout: 30000,
|
|
7
|
+
include: ['test/**/*.spec.js', 'test/**/*.integration-test.js'],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'istanbul',
|
|
10
|
+
include: ['**/*.{js,jsx,ts}'],
|
|
11
|
+
exclude: [
|
|
12
|
+
'node_modules/**',
|
|
13
|
+
'tmp/**',
|
|
14
|
+
'test/**',
|
|
15
|
+
'coverage/**',
|
|
16
|
+
'bin/**',
|
|
17
|
+
],
|
|
18
|
+
reporter: ['lcov', 'text'],
|
|
19
|
+
},
|
|
20
|
+
pool: 'forks',
|
|
21
|
+
execArgv: ['--require', './test/setup-coverage.js'],
|
|
22
|
+
sequence: {
|
|
23
|
+
concurrent: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
package/jest.config.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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;
|
package/test/mocks/jest-mocks.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const gitSemverTags = require('git-semver-tags');
|
|
2
|
-
const conventionalChangelog = require('conventional-changelog');
|
|
3
|
-
const conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
4
|
-
const gitRawCommits = require('git-raw-commits');
|
|
5
|
-
|
|
6
|
-
const { Readable } = require('stream');
|
|
7
|
-
|
|
8
|
-
jest.mock('conventional-changelog');
|
|
9
|
-
jest.mock('conventional-recommended-bump');
|
|
10
|
-
jest.mock('git-semver-tags');
|
|
11
|
-
jest.mock('git-raw-commits');
|
|
12
|
-
|
|
13
|
-
const mockGitSemverTags = ({ tags = [] }) => {
|
|
14
|
-
gitSemverTags.mockImplementation((opts, cb) => {
|
|
15
|
-
if (tags instanceof Error) cb(tags);
|
|
16
|
-
else cb(null, tags);
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param { { commits: string[] } }
|
|
22
|
-
* a commit should look like `<rawBody>\n\n-hash-\n<hash>\n`
|
|
23
|
-
*/
|
|
24
|
-
const mockGitRawCommits = ({ commits = [] }) => {
|
|
25
|
-
gitRawCommits.mockImplementation(() => {
|
|
26
|
-
return new Readable({
|
|
27
|
-
read() {
|
|
28
|
-
commits.forEach((c) => this.push(c));
|
|
29
|
-
this.push(null);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const mockConventionalChangelog = ({ changelog }) => {
|
|
36
|
-
conventionalChangelog.mockImplementation(
|
|
37
|
-
(opt) =>
|
|
38
|
-
new Readable({
|
|
39
|
-
read(_size) {
|
|
40
|
-
const next = changelog.shift();
|
|
41
|
-
if (next instanceof Error) {
|
|
42
|
-
this.destroy(next);
|
|
43
|
-
} else if (typeof next === 'function') {
|
|
44
|
-
this.push(next(opt));
|
|
45
|
-
} else {
|
|
46
|
-
this.push(next ? Buffer.from(next, 'utf8') : null);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const mockRecommendedBump = ({ bump }) => {
|
|
54
|
-
conventionalRecommendedBump.mockImplementation((opt, parserOpts, cb) => {
|
|
55
|
-
if (typeof bump === 'function') bump(opt, parserOpts, cb);
|
|
56
|
-
else if (bump instanceof Error) cb(bump);
|
|
57
|
-
else cb(null, bump ? { releaseType: bump } : {});
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
module.exports = {
|
|
62
|
-
mockGitSemverTags,
|
|
63
|
-
mockGitRawCommits,
|
|
64
|
-
mockConventionalChangelog,
|
|
65
|
-
mockRecommendedBump,
|
|
66
|
-
};
|