commit-and-tag-version 12.7.1 → 13.0.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.
Files changed (54) hide show
  1. package/.github/workflows/ci.yaml +8 -15
  2. package/.github/workflows/release-please.yml +7 -5
  3. package/CHANGELOG.md +36 -0
  4. package/MIGRATION.md +51 -0
  5. package/README.md +22 -21
  6. package/bin/cli.js +2 -2
  7. package/command.js +9 -4
  8. package/defaults.js +5 -3
  9. package/eslint.config.mjs +52 -42
  10. package/index.js +12 -12
  11. package/lib/checkpoint.js +5 -5
  12. package/lib/configuration.js +9 -6
  13. package/lib/detect-package-manager.js +4 -8
  14. package/lib/format-commit-message.js +2 -2
  15. package/lib/latest-semver-tag.js +30 -30
  16. package/lib/lifecycles/bump.js +97 -65
  17. package/lib/lifecycles/changelog.js +48 -60
  18. package/lib/lifecycles/commit.js +8 -8
  19. package/lib/lifecycles/tag.js +10 -10
  20. package/lib/preset-loader.js +73 -9
  21. package/lib/print-error.js +3 -3
  22. package/lib/run-exec.js +6 -5
  23. package/lib/run-execFile.js +6 -5
  24. package/lib/run-lifecycle-script.js +6 -6
  25. package/lib/stringify-package.js +1 -5
  26. package/lib/updaters/index.js +25 -12
  27. package/lib/updaters/types/csproj.js +4 -4
  28. package/lib/updaters/types/gradle.js +4 -4
  29. package/lib/updaters/types/json.js +9 -9
  30. package/lib/updaters/types/maven.js +25 -8
  31. package/lib/updaters/types/openapi.js +6 -6
  32. package/lib/updaters/types/plain-text.js +4 -4
  33. package/lib/updaters/types/python.js +4 -4
  34. package/lib/updaters/types/yaml.js +6 -6
  35. package/lib/write-file.js +3 -3
  36. package/package.json +25 -15
  37. package/test/commit-message-config.integration-test.js +23 -10
  38. package/test/config-files.integration-test.js +25 -10
  39. package/test/config-keys.integration-test.js +20 -7
  40. package/test/core.spec.js +103 -37
  41. package/test/git.integration-test.js +23 -15
  42. package/test/invalid-config.integration-test.js +19 -9
  43. package/test/mocks/pom-6.3.1-attrs-lf.xml +28 -0
  44. package/test/mocks/pom-6.4.0-attrs-lf.xml +29 -0
  45. package/test/mocks/vitest-mocks.js +260 -0
  46. package/test/package.json +3 -0
  47. package/test/pre-commit-hook.integration-test.js +22 -14
  48. package/test/preset.integration-test.js +7 -5
  49. package/test/setup-coverage.js +47 -0
  50. package/test/stringify-package.spec.js +1 -3
  51. package/test/utils.spec.js +3 -4
  52. package/vitest.config.js +26 -0
  53. package/jest.config.js +0 -28
  54. package/test/mocks/jest-mocks.js +0 -66
package/test/core.spec.js CHANGED
@@ -1,29 +1,64 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const stripAnsi = require('strip-ansi');
5
- const fs = require('fs');
6
-
7
- const mockers = require('./mocks/jest-mocks');
1
+ import shell from 'shelljs';
2
+ import stripAnsi from 'strip-ansi';
3
+
4
+ // Set up CJS require() hook + create mock fns (must be before any source imports)
5
+ const mockers = vi.hoisted(() =>
6
+ require('./mocks/vitest-mocks').setup({ mockRunExecFile: true }),
7
+ );
8
+
9
+ // Register vi.mock for ESM imports in this test file
10
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
11
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
12
+ mockers.conventionalRecommendedBumpModule(
13
+ await importOriginal(),
14
+ await import('@conventional-changelog/git-client'),
15
+ ),
16
+ );
17
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
18
+ mockers.gitClientModule(await importOriginal()),
19
+ );
20
+ vi.mock('../lib/run-execFile', () => ({ default: mockers.runExecFile }));
21
+ // Now that the source is ESM, this mock applies to the source's import of
22
+ // dotgitignore too (under CJS it only affected this file's import), so it
23
+ // needs a working default implementation rather than a bare automock.
24
+ vi.mock('dotgitignore', () => ({
25
+ default: vi.fn(() => ({ ignore: () => false })),
26
+ }));
27
+
28
+ // Mock fs at the Vitest ESM level so spies work for both test and source code.
29
+ vi.mock('fs', async (importOriginal) => {
30
+ const actual = await importOriginal();
31
+ const proxy = mockers.fsProxy;
32
+ return {
33
+ ...actual,
34
+ default: proxy,
35
+ readFileSync: (...args) => proxy.readFileSync(...args),
36
+ writeFileSync: (...args) => proxy.writeFileSync(...args),
37
+ lstatSync: (...args) => proxy.lstatSync(...args),
38
+ chmodSync: (...args) => proxy.chmodSync(...args),
39
+ promises: actual.promises,
40
+ };
41
+ });
8
42
 
9
- const runExecFile = require('../lib/run-execFile');
43
+ const runExecFile = mockers.runExecFile;
10
44
 
11
- const cli = require('../command');
12
- const formatCommitMessage = require('../lib/format-commit-message');
45
+ import cli from '../command';
46
+ import formatCommitMessage from '../lib/format-commit-message';
47
+ import standardVersion from '../index';
48
+ import { header as defaultHeader } from '../defaults';
49
+ import DotGitIgnore from 'dotgitignore';
50
+ import fs from 'fs';
13
51
 
14
52
  // set by mock()
15
- let standardVersion;
16
53
  let readFileSyncSpy;
17
54
  let lstatSyncSpy;
55
+ let writeFileSyncSpy = vi
56
+ .spyOn(fs, 'writeFileSync')
57
+ .mockImplementation(() => {});
18
58
 
19
- // Rather than trying to re-read something written out during tests, we can spy on writeFileSync
20
- // we can trust fs is capable of writing the file
21
- let writeFileSyncSpy;
22
-
23
- const consoleErrorSpy = jest.spyOn(console, 'warn').mockImplementation();
24
- const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
25
-
26
- jest.mock('../lib/run-execFile');
59
+ const consoleErrorSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
60
+ const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
61
+ vi.spyOn(console, 'error').mockImplementation(() => {});
27
62
 
28
63
  const { readFileSync: readFileSyncActual, lstatSync: lstatSyncActual } = fs;
29
64
 
@@ -54,7 +89,7 @@ const mockReadFilesFromDisk = ({
54
89
  testFiles,
55
90
  realTestFiles,
56
91
  }) =>
57
- jest.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
92
+ vi.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
58
93
  if (path === 'CHANGELOG.md') {
59
94
  if (existingChangelog) {
60
95
  return existingChangelog;
@@ -113,7 +148,7 @@ const mockReadFilesFromDisk = ({
113
148
  * @return Jest spy on lstatSync
114
149
  */
115
150
  const mockFsLStat = ({ fs, lstatSyncActual, testFiles, realTestFiles }) =>
116
- jest.spyOn(fs, 'lstatSync').mockImplementation((path) => {
151
+ vi.spyOn(fs, 'lstatSync').mockImplementation((path) => {
117
152
  if (testFiles) {
118
153
  const file = testFiles.find((otherFile) => {
119
154
  return path.includes(otherFile.path);
@@ -179,9 +214,6 @@ function mock({
179
214
  commits,
180
215
  });
181
216
 
182
- // needs to be set after mockery, but before mock-fs
183
- standardVersion = require('../index');
184
-
185
217
  // For fake and injected test files pretend they exist at root level when Fs queries lstat
186
218
  // Package.json works without this as it'll check the one in this actual repo...
187
219
  lstatSyncSpy = mockFsLStat({
@@ -200,7 +232,7 @@ function mock({
200
232
  });
201
233
 
202
234
  // Spies on writeFileSync to capture calls and ensure we don't actually try write anything to disc
203
- writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation();
235
+ writeFileSyncSpy = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
204
236
  }
205
237
 
206
238
  function clearCapturedSpyCalls() {
@@ -212,14 +244,17 @@ function restoreMocksToRealImplementation() {
212
244
  readFileSyncSpy.mockRestore();
213
245
  writeFileSyncSpy.mockRestore();
214
246
  lstatSyncSpy.mockRestore();
247
+ // Immediately re-protect against writes after restoring
248
+ writeFileSyncSpy = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
215
249
  }
216
250
 
217
251
  function unmock() {
218
252
  clearCapturedSpyCalls();
219
253
 
220
- restoreMocksToRealImplementation();
254
+ // Reset runExecFile mock between tests to prevent state leakage
255
+ runExecFile.mockReset();
221
256
 
222
- standardVersion = null;
257
+ restoreMocksToRealImplementation();
223
258
  }
224
259
 
225
260
  describe('format-commit-message', function () {
@@ -314,7 +349,7 @@ describe('cli', function () {
314
349
  });
315
350
 
316
351
  it('appends the new release above the last release, replacing the old header (standard-version format) with header (new format), and retains any front matter', async function () {
317
- const { header } = require('../defaults');
352
+ const header = defaultHeader;
318
353
 
319
354
  const standardVersionHeader =
320
355
  '# Changelog\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.';
@@ -346,7 +381,7 @@ describe('cli', function () {
346
381
  });
347
382
 
348
383
  it('appends the new release above the last release, removing the old header (new format), and retains any front matter', async function () {
349
- const { header } = require('../defaults');
384
+ const header = defaultHeader;
350
385
  const frontMatter = '---\nstatus: new\n---\n';
351
386
 
352
387
  const changelog101 =
@@ -374,7 +409,7 @@ describe('cli', function () {
374
409
  });
375
410
 
376
411
  it('appends the new release above the last release, removing the old header (new format)', async function () {
377
- const { header } = require('../defaults');
412
+ const header = defaultHeader;
378
413
  const changelog1 =
379
414
  '### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n';
380
415
  mock({ bump: 'patch', changelog: changelog1, tags: ['v1.0.0'] });
@@ -921,7 +956,7 @@ describe('cli', function () {
921
956
 
922
957
  it('bumps using actual recommendedBump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
923
958
  mock({
924
- bump: jest.requireActual('conventional-recommended-bump'),
959
+ bump: mockers.actualConventionalRecommendedBump,
925
960
  changelog: ['chore release\n'],
926
961
  tags: ['v1.0.0'],
927
962
  commits: ['chore: update deps\n\n-hash-\nabc123\n'],
@@ -934,7 +969,7 @@ describe('cli', function () {
934
969
 
935
970
  it('bumps using actual recommendedBump when there are semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
936
971
  mock({
937
- bump: jest.requireActual('conventional-recommended-bump'),
972
+ bump: mockers.actualConventionalRecommendedBump,
938
973
  changelog: ['feat release\n'],
939
974
  tags: ['v1.0.0'],
940
975
  commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
@@ -947,7 +982,7 @@ describe('cli', function () {
947
982
 
948
983
  it('does not bump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
949
984
  mock({
950
- bump: jest.requireActual('conventional-recommended-bump'),
985
+ bump: mockers.actualConventionalRecommendedBump,
951
986
  changelog: ['chore release\n'],
952
987
  tags: ['v1.0.0'],
953
988
  commits: ['chore: update deps\n\n-hash-\nabc123\n'],
@@ -960,7 +995,7 @@ describe('cli', function () {
960
995
 
961
996
  it('bumps when there are semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
962
997
  mock({
963
- bump: jest.requireActual('conventional-recommended-bump'),
998
+ bump: mockers.actualConventionalRecommendedBump,
964
999
  changelog: ['feat release\n'],
965
1000
  tags: ['v1.0.0'],
966
1001
  commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
@@ -1409,6 +1444,40 @@ describe('cli', function () {
1409
1444
  expect(calledWithContentStr).toEqual(expected);
1410
1445
  });
1411
1446
 
1447
+ it('bumps version in Maven `pom.xml` file preserving XML attributes', async function () {
1448
+ const expected = fs.readFileSync(
1449
+ './test/mocks/pom-6.4.0-attrs-lf.xml',
1450
+ 'utf-8',
1451
+ );
1452
+ const filename = 'pom.xml';
1453
+ mock({
1454
+ bump: 'minor',
1455
+ realTestFiles: [
1456
+ {
1457
+ filename,
1458
+ path: './test/mocks/pom-6.3.1-attrs-lf.xml',
1459
+ },
1460
+ ],
1461
+ });
1462
+ await exec({
1463
+ packageFiles: [{ filename, type: 'maven' }],
1464
+ bumpFiles: [{ filename, type: 'maven' }],
1465
+ });
1466
+
1467
+ // filePath is the first arg passed to writeFileSync
1468
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1469
+ writeFileSyncSpy,
1470
+ filename,
1471
+ });
1472
+
1473
+ if (!packageJsonWriteFileSynchCall) {
1474
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1475
+ }
1476
+
1477
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1478
+ expect(calledWithContentStr).toEqual(expected);
1479
+ });
1480
+
1412
1481
  it('bumps version in Gradle `build.gradle.kts` file', async function () {
1413
1482
  const expected = fs.readFileSync(
1414
1483
  './test/mocks/build-6.4.0.gradle.kts',
@@ -1652,9 +1721,6 @@ describe('cli', function () {
1652
1721
  });
1653
1722
 
1654
1723
  it('does not update files present in .gitignore', async function () {
1655
- const DotGitIgnore = require('dotgitignore');
1656
- jest.mock('dotgitignore');
1657
-
1658
1724
  DotGitIgnore.mockImplementation(() => {
1659
1725
  return {
1660
1726
  ignore: (filename) => {
@@ -1,21 +1,29 @@
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 = '') {
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
+ );
15
+
16
+ const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
17
+ const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
18
+
19
+ async function exec(opt = '') {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
14
22
  if (typeof opt === 'string') {
15
- const cli = require('../command');
16
23
  opt = cli.parse(`commit-and-tag-version ${opt}`);
17
24
  }
18
- return require('../index')(opt);
25
+ const { default: standardVersion } = await import('../index');
26
+ return standardVersion(opt);
19
27
  }
20
28
 
21
29
  function writePackageJson(version, option) {
@@ -1,15 +1,25 @@
1
- 'use strict';
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
2
3
 
3
- const shell = require('shelljs');
4
- const fs = require('fs');
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
+ );
5
15
 
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- function exec() {
9
- const cli = require('../command');
16
+ async function exec() {
17
+ vi.resetModules();
18
+ const { default: cli } = await import('../command');
10
19
  const opt = cli.parse('commit-and-tag-version');
11
20
  opt.skip = { commit: true, tag: true };
12
- return require('../index')(opt);
21
+ const { default: standardVersion } = await import('../index');
22
+ return standardVersion(opt);
13
23
  }
14
24
 
15
25
  /**
@@ -68,6 +78,6 @@ describe('invalid .versionrc', function () {
68
78
  mock({ bump: 'minor' });
69
79
  fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8');
70
80
 
71
- expect(exec).toThrow(/Invalid configuration/);
81
+ await expect(exec()).rejects.toThrow(/Invalid configuration/);
72
82
  });
73
83
  });
@@ -0,0 +1,28 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+ <modelVersion>4.0.0</modelVersion>
3
+ <groupId>com.mycompany.app</groupId>
4
+ <artifactId>my-module</artifactId>
5
+ <version>6.3.1</version>
6
+ <!-- preserved-comment -->
7
+ <build>
8
+ <plugins>
9
+ <plugin>
10
+ <groupId>org.apache.maven.plugins</groupId>
11
+ <artifactId>maven-antrun-plugin</artifactId>
12
+ <executions>
13
+ <execution>
14
+ <id>ktlint</id>
15
+ <configuration>
16
+ <target name="ktlint">
17
+ <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main">
18
+ <classpath refid="maven.plugin.classpath"/>
19
+ <arg value="src/**/*.kt"/>
20
+ </java>
21
+ </target>
22
+ </configuration>
23
+ </execution>
24
+ </executions>
25
+ </plugin>
26
+ </plugins>
27
+ </build>
28
+ </project>
@@ -0,0 +1,29 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+ <modelVersion>4.0.0</modelVersion>
3
+ <groupId>com.mycompany.app</groupId>
4
+ <artifactId>my-module</artifactId>
5
+ <version>6.4.0</version>
6
+ <!-- preserved-comment -->
7
+ <build>
8
+ <plugins>
9
+ <plugin>
10
+ <groupId>org.apache.maven.plugins</groupId>
11
+ <artifactId>maven-antrun-plugin</artifactId>
12
+ <executions>
13
+ <execution>
14
+ <id>ktlint</id>
15
+ <configuration>
16
+ <target name="ktlint">
17
+ <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main">
18
+ <classpath refid="maven.plugin.classpath"></classpath>
19
+ <arg value="src/**/*.kt"></arg>
20
+ </java>
21
+ </target>
22
+ </configuration>
23
+ </execution>
24
+ </executions>
25
+ </plugin>
26
+ </plugins>
27
+ </build>
28
+ </project>
29
+
@@ -0,0 +1,260 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Create mock state and module factories for the conventional-changelog
5
+ * ecosystem packages.
6
+ *
7
+ * Usage in test files:
8
+ *
9
+ * const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
10
+ *
11
+ * vi.mock('conventional-changelog', () =>
12
+ * mockers.conventionalChangelogModule(),
13
+ * );
14
+ * vi.mock('conventional-recommended-bump', async (importOriginal) =>
15
+ * mockers.conventionalRecommendedBumpModule(
16
+ * await importOriginal(),
17
+ * await import('@conventional-changelog/git-client'),
18
+ * ),
19
+ * );
20
+ * vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
21
+ * mockers.gitClientModule(await importOriginal()),
22
+ * );
23
+ */
24
+ function setup({ mockRunExecFile = false } = {}) {
25
+ const runExecFile = vi.fn();
26
+
27
+ // Use the actual fs module object directly for spying
28
+ const fsProxy = require('fs');
29
+
30
+ // Sentinel passed as `bump` by tests that want the real Bumper
31
+ // implementation to run (against the mocked git client).
32
+ const actualConventionalRecommendedBump = Symbol(
33
+ 'actual-conventional-recommended-bump',
34
+ );
35
+
36
+ // Shared mock data, updated by the mock* helpers below.
37
+ const state = {
38
+ tags: [], // string[] | Error - git tags yielded by the git client
39
+ commits: [], // string[] - raw commit bodies yielded by the git client
40
+ changelog: [], // Array<string | Error | fn | undefined> - changelog chunks
41
+ bump: undefined, // releaseType | Error | fn | actualConventionalRecommendedBump
42
+ };
43
+
44
+ /**
45
+ * Module factory for '@conventional-changelog/git-client': the real
46
+ * ConventionalGitClient with the raw git interactions (log for commits and
47
+ * tags) replaced by the mock state. Parsing and semver filtering still use
48
+ * the real implementation.
49
+ */
50
+ const gitClientModule = (actual) => {
51
+ class MockConventionalGitClient extends actual.ConventionalGitClient {
52
+ async *getRawCommits() {
53
+ for (const commit of state.commits || []) {
54
+ yield commit;
55
+ }
56
+ }
57
+
58
+ async *getTags() {
59
+ if (state.tags instanceof Error) throw state.tags;
60
+ for (const tag of state.tags || []) {
61
+ yield tag;
62
+ }
63
+ }
64
+ }
65
+
66
+ return { ...actual, ConventionalGitClient: MockConventionalGitClient };
67
+ };
68
+
69
+ /**
70
+ * Module factory for 'conventional-changelog': a chainable stub whose
71
+ * write() generator yields the queued changelog chunks.
72
+ */
73
+ const conventionalChangelogModule = () => {
74
+ class MockConventionalChangelog {
75
+ readPackage() {
76
+ return this;
77
+ }
78
+
79
+ package() {
80
+ return this;
81
+ }
82
+
83
+ loadPreset(preset) {
84
+ this.presetParams = preset;
85
+ return this;
86
+ }
87
+
88
+ config(config) {
89
+ this.configParams = config;
90
+ return this;
91
+ }
92
+
93
+ tags(params) {
94
+ this.tagsParams = params;
95
+ return this;
96
+ }
97
+
98
+ options(options) {
99
+ this.optionsParams = options;
100
+ return this;
101
+ }
102
+
103
+ context(context) {
104
+ this.contextParams = context;
105
+ return this;
106
+ }
107
+
108
+ commits(params, parserOptions) {
109
+ this.commitsParams = params;
110
+ this.parserOptions = parserOptions;
111
+ return this;
112
+ }
113
+
114
+ writer(options) {
115
+ this.writerOptions = options;
116
+ return this;
117
+ }
118
+
119
+ async *write() {
120
+ // Mirrors the behaviour of the old stream mock: consume queued
121
+ // entries until an empty entry ends the stream; an Error entry
122
+ // fails it; a function entry is called with the params captured
123
+ // from the chained setup calls.
124
+ for (;;) {
125
+ const next = state.changelog.shift();
126
+ if (next instanceof Error) throw next;
127
+ const chunk =
128
+ typeof next === 'function'
129
+ ? next({
130
+ preset: this.presetParams,
131
+ tags: this.tagsParams,
132
+ options: this.optionsParams,
133
+ context: this.contextParams,
134
+ commits: this.commitsParams,
135
+ parser: this.parserOptions,
136
+ writer: this.writerOptions,
137
+ })
138
+ : next;
139
+ if (!chunk) return;
140
+ yield chunk;
141
+ }
142
+ }
143
+ }
144
+
145
+ return { ConventionalChangelog: MockConventionalChangelog };
146
+ };
147
+
148
+ /**
149
+ * Module factory for 'conventional-recommended-bump': a chainable Bumper
150
+ * stub driven by the `bump` mock state. When `bump` is the
151
+ * `actualConventionalRecommendedBump` sentinel, the real Bumper runs with
152
+ * the mocked git client, so real presets, parsing and whatBump logic are
153
+ * exercised against the mock commits/tags.
154
+ */
155
+ const conventionalRecommendedBumpModule = (actual, gitClientMod) => {
156
+ class MockBumper {
157
+ loadPreset(preset) {
158
+ this.presetParams = preset;
159
+ return this;
160
+ }
161
+
162
+ config(config) {
163
+ this.configParams = config;
164
+ return this;
165
+ }
166
+
167
+ options(options) {
168
+ this.optionsParams = options;
169
+ return this;
170
+ }
171
+
172
+ tag(params) {
173
+ this.tagParams = params;
174
+ return this;
175
+ }
176
+
177
+ commits(params, parserOptions) {
178
+ this.commitsParams = params;
179
+ this.parserOptions = parserOptions;
180
+ return this;
181
+ }
182
+
183
+ async bump(whatBump) {
184
+ const bump = state.bump;
185
+
186
+ if (bump === actualConventionalRecommendedBump) {
187
+ const bumper = new actual.Bumper(
188
+ new gitClientMod.ConventionalGitClient(process.cwd()),
189
+ );
190
+ if (this.presetParams) bumper.loadPreset(this.presetParams);
191
+ if (this.tagParams) bumper.tag(this.tagParams);
192
+ if (this.commitsParams || this.parserOptions) {
193
+ bumper.commits(this.commitsParams || {}, this.parserOptions);
194
+ }
195
+ if (this.optionsParams) bumper.options(this.optionsParams);
196
+ return bumper.bump(whatBump);
197
+ }
198
+
199
+ if (bump instanceof Error) throw bump;
200
+
201
+ if (typeof bump === 'function') {
202
+ // Legacy callback-style test hook: (opt, parserOpts, cb)
203
+ return new Promise((resolve, reject) => {
204
+ bump(
205
+ {
206
+ preset: this.presetParams,
207
+ tag: this.tagParams,
208
+ commits: this.commitsParams,
209
+ },
210
+ this.parserOptions,
211
+ (err, release) => {
212
+ if (err) reject(err);
213
+ else resolve({ commits: [], ...release });
214
+ },
215
+ );
216
+ });
217
+ }
218
+
219
+ if (bump) {
220
+ return { releaseType: bump, commits: [] };
221
+ }
222
+ return { commits: [] };
223
+ }
224
+ }
225
+
226
+ return { ...actual, Bumper: MockBumper };
227
+ };
228
+
229
+ const mockGitSemverTags = ({ tags = [] }) => {
230
+ state.tags = tags;
231
+ };
232
+
233
+ const mockGitRawCommits = ({ commits = [] }) => {
234
+ state.commits = commits;
235
+ };
236
+
237
+ const mockConventionalChangelog = ({ changelog }) => {
238
+ state.changelog = Array.isArray(changelog) ? changelog : [changelog];
239
+ };
240
+
241
+ const mockRecommendedBump = ({ bump }) => {
242
+ state.bump = bump;
243
+ };
244
+
245
+ return {
246
+ fsProxy,
247
+ runExecFile,
248
+ mockRunExecFile,
249
+ actualConventionalRecommendedBump,
250
+ gitClientModule,
251
+ conventionalChangelogModule,
252
+ conventionalRecommendedBumpModule,
253
+ mockGitSemverTags,
254
+ mockGitRawCommits,
255
+ mockConventionalChangelog,
256
+ mockRecommendedBump,
257
+ };
258
+ }
259
+
260
+ module.exports = { setup };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }