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.
- package/.github/workflows/ci.yaml +8 -15
- package/.github/workflows/release-please.yml +7 -5
- package/CHANGELOG.md +36 -0
- package/MIGRATION.md +51 -0
- package/README.md +22 -21
- 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 +9 -6
- 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 +25 -8
- 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 +25 -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 +103 -37
- 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 +28 -0
- package/test/mocks/pom-6.4.0-attrs-lf.xml +29 -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
package/lib/latest-semver-tag.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ConventionalGitClient } from '@conventional-changelog/git-client';
|
|
2
|
+
import semver from 'semver';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (semver.prerelease(tag)[0] === prerelease) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
});
|
|
4
|
+
export default async function ({ tagPrefix, prerelease }) {
|
|
5
|
+
const gitClient = new ConventionalGitClient(process.cwd());
|
|
6
|
+
let tags = [];
|
|
7
|
+
for await (const tag of gitClient.getSemverTags({ prefix: tagPrefix })) {
|
|
8
|
+
tags.push(tag);
|
|
9
|
+
}
|
|
10
|
+
if (!tags.length) return '1.0.0';
|
|
11
|
+
// Respect tagPrefix
|
|
12
|
+
tags = tags.map((tag) => tag.replace(new RegExp('^' + tagPrefix), ''));
|
|
13
|
+
if (prerelease) {
|
|
14
|
+
// ignore any other prelease tags
|
|
15
|
+
tags = tags.filter((tag) => {
|
|
16
|
+
if (!semver.valid(tag)) return false;
|
|
17
|
+
if (!semver.prerelease(tag)) {
|
|
18
|
+
// include all non-prerelease versions
|
|
19
|
+
return true;
|
|
25
20
|
}
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return resolve(tags[0]);
|
|
21
|
+
// check if the name of the prerelease matches the one we are looking for
|
|
22
|
+
if (semver.prerelease(tag)[0] === prerelease) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
32
26
|
});
|
|
27
|
+
}
|
|
28
|
+
// ensure that the largest semver tag is at the head.
|
|
29
|
+
tags = tags.map((tag) => {
|
|
30
|
+
return semver.clean(tag);
|
|
33
31
|
});
|
|
34
|
-
|
|
32
|
+
tags.sort(semver.rcompare);
|
|
33
|
+
return tags[0];
|
|
34
|
+
}
|
package/lib/lifecycles/bump.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const gitSemverTags = require('git-semver-tags');
|
|
16
|
-
const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes');
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Bumper, packagePrefix } from 'conventional-recommended-bump';
|
|
3
|
+
import figures from 'figures';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import DotGitignore from 'dotgitignore';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import semver from 'semver';
|
|
8
|
+
import { ConventionalGitClient } from '@conventional-changelog/git-client';
|
|
9
|
+
import checkpoint from '../checkpoint.js';
|
|
10
|
+
import presetLoader from '../preset-loader.js';
|
|
11
|
+
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
12
|
+
import writeFile from '../write-file.js';
|
|
13
|
+
import { resolveUpdaterObjectFromArgument } from '../updaters/index.js';
|
|
14
|
+
|
|
17
15
|
let configsToUpdate = {};
|
|
18
16
|
const sanitizeQuotesRegex = /['"]+/g;
|
|
19
17
|
|
|
@@ -24,7 +22,6 @@ function noBumpWhenEmptyChanges(config, commits) {
|
|
|
24
22
|
let fix = 0;
|
|
25
23
|
|
|
26
24
|
commits.forEach((commit) => {
|
|
27
|
-
addBangNotes(commit);
|
|
28
25
|
if (commit.notes.length > 0) {
|
|
29
26
|
breakings += commit.notes.length;
|
|
30
27
|
level = 0;
|
|
@@ -43,7 +40,44 @@ function noBumpWhenEmptyChanges(config, commits) {
|
|
|
43
40
|
level++;
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
if (!breakings && !features && !fix) return
|
|
43
|
+
if (!breakings && !features && !fix) return null;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
level,
|
|
47
|
+
reason:
|
|
48
|
+
breakings === 1
|
|
49
|
+
? `There is ${breakings} BREAKING CHANGE and ${features} features`
|
|
50
|
+
: `There are ${breakings} BREAKING CHANGES and ${features} features`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The `whatBump` implementation of conventional-changelog-conventionalcommits
|
|
56
|
+
* before v10: the release is always at least a patch, even when there are no
|
|
57
|
+
* relevant commits. From v10 the preset only recommends a bump when there is
|
|
58
|
+
* at least one commit of a type with the 'bump' effect, so we keep the
|
|
59
|
+
* historical behaviour here (`--no-bump-when-empty-changes` opts out of it).
|
|
60
|
+
*/
|
|
61
|
+
function legacyWhatBump(config, commits) {
|
|
62
|
+
let level = 2;
|
|
63
|
+
let breakings = 0;
|
|
64
|
+
let features = 0;
|
|
65
|
+
|
|
66
|
+
commits.forEach((commit) => {
|
|
67
|
+
if (commit.notes.length > 0) {
|
|
68
|
+
breakings += commit.notes.length;
|
|
69
|
+
level = 0;
|
|
70
|
+
} else if (commit.type === 'feat' || commit.type === 'feature') {
|
|
71
|
+
features += 1;
|
|
72
|
+
if (level === 2) {
|
|
73
|
+
level = 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (config.preMajor && level < 2) {
|
|
79
|
+
level++;
|
|
80
|
+
}
|
|
47
81
|
|
|
48
82
|
return {
|
|
49
83
|
level,
|
|
@@ -231,47 +265,45 @@ function getTypePriority(type) {
|
|
|
231
265
|
return TypeList.indexOf(type);
|
|
232
266
|
}
|
|
233
267
|
|
|
234
|
-
function bumpVersion(releaseAs, currentVersion, args) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
});
|
|
268
|
+
async function bumpVersion(releaseAs, currentVersion, args) {
|
|
269
|
+
if (releaseAs) {
|
|
270
|
+
return {
|
|
271
|
+
releaseType: releaseAs,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const presetOptions = presetLoader(args);
|
|
276
|
+
// `whatBump` stays undefined for third-party presets so that the preset's
|
|
277
|
+
// own recommendation logic is used.
|
|
278
|
+
let whatBump;
|
|
279
|
+
if (typeof presetOptions === 'object') {
|
|
280
|
+
if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true;
|
|
281
|
+
whatBump = args.noBumpWhenEmptyChanges
|
|
282
|
+
? (commits) => noBumpWhenEmptyChanges(presetOptions, commits)
|
|
283
|
+
: (commits) => legacyWhatBump(presetOptions, commits);
|
|
284
|
+
} else if (args.noBumpWhenEmptyChanges) {
|
|
285
|
+
whatBump = (commits) => noBumpWhenEmptyChanges({}, commits);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const bumper = new Bumper()
|
|
289
|
+
.loadPreset(presetOptions)
|
|
290
|
+
.tag({
|
|
291
|
+
prefix: args.lernaPackage
|
|
292
|
+
? packagePrefix(args.lernaPackage)
|
|
293
|
+
: args.tagPrefix,
|
|
294
|
+
})
|
|
295
|
+
.commits({ path: args.path }, args.parserOpts);
|
|
296
|
+
|
|
297
|
+
if (args.verbose) {
|
|
298
|
+
bumper.options({
|
|
299
|
+
debug: console.info.bind(console, 'conventional-recommended-bump'),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const release = await bumper.bump(whatBump);
|
|
304
|
+
// A recommendation without a releaseType means no bump is warranted;
|
|
305
|
+
// normalize to the empty object the caller expects.
|
|
306
|
+
return release.releaseType ? release : {};
|
|
275
307
|
}
|
|
276
308
|
|
|
277
309
|
/**
|
|
@@ -321,7 +353,7 @@ function updateConfigs(args, newVersion) {
|
|
|
321
353
|
});
|
|
322
354
|
}
|
|
323
355
|
|
|
324
|
-
|
|
356
|
+
export default Bump;
|
|
325
357
|
|
|
326
358
|
/**
|
|
327
359
|
* Ensure prerelease version uniqueness by checking existing git tags.
|
|
@@ -353,11 +385,11 @@ async function resolveUniquePrereleaseVersion(
|
|
|
353
385
|
}
|
|
354
386
|
}
|
|
355
387
|
|
|
356
|
-
const tags =
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
);
|
|
360
|
-
}
|
|
388
|
+
const tags = [];
|
|
389
|
+
const gitClient = new ConventionalGitClient(process.cwd());
|
|
390
|
+
for await (const tag of gitClient.getSemverTags({ prefix: tagPrefix })) {
|
|
391
|
+
tags.push(tag);
|
|
392
|
+
}
|
|
361
393
|
|
|
362
394
|
// strip prefix and clean
|
|
363
395
|
const cleaned = tags
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ConventionalChangelog } from 'conventional-changelog';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import checkpoint from '../checkpoint.js';
|
|
5
|
+
import presetLoader from '../preset-loader.js';
|
|
6
|
+
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
7
|
+
import writeFile from '../write-file.js';
|
|
8
|
+
|
|
8
9
|
const START_OF_LAST_RELEASE_PATTERN =
|
|
9
10
|
/(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
|
|
10
11
|
|
|
@@ -17,7 +18,7 @@ async function Changelog(args, newVersion) {
|
|
|
17
18
|
|
|
18
19
|
Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
export default Changelog;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Front matter is only extracted and therefore retained in final output where Changelog "header" begins with #Changelog,
|
|
@@ -40,64 +41,51 @@ function extractChangelogBody(oldContent) {
|
|
|
40
41
|
: oldContent;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
function outputChangelog(args, newVersion) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const header = args.header;
|
|
44
|
+
async function outputChangelog(args, newVersion) {
|
|
45
|
+
createIfMissing(args);
|
|
46
|
+
const header = args.header;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const oldContent =
|
|
49
|
+
args.dryRun || args.releaseCount === 0
|
|
50
|
+
? ''
|
|
51
|
+
: fs.readFileSync(args.infile, 'utf-8');
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const oldContentBody = extractChangelogBody(oldContent);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const changelogFrontMatter = extractFrontMatter(oldContent);
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
});
|
|
57
|
+
const generator = new ConventionalChangelog()
|
|
58
|
+
.readPackage()
|
|
59
|
+
.loadPreset(presetLoader(args))
|
|
60
|
+
.tags({ prefix: args.tagPrefix })
|
|
61
|
+
.options({
|
|
62
|
+
releaseCount: args.releaseCount,
|
|
63
|
+
...(args.verbose
|
|
64
|
+
? {
|
|
65
|
+
debug: console.info.bind(console, 'conventional-changelog'),
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
})
|
|
69
|
+
.context({ version: newVersion })
|
|
70
|
+
.commits({ merges: null, path: args.path }, args.parserOpts)
|
|
71
|
+
.writer(args.writerOpts || {});
|
|
80
72
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
let content = '';
|
|
74
|
+
for await (const chunk of generator.write()) {
|
|
75
|
+
content += chunk;
|
|
76
|
+
}
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
(content + oldContentBody).replace(/\n+$/, '\n'),
|
|
97
|
-
);
|
|
98
|
-
return resolve();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
78
|
+
checkpoint(args, 'outputting changes to %s', [args.infile]);
|
|
79
|
+
if (args.dryRun) console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`);
|
|
80
|
+
else
|
|
81
|
+
writeFile(
|
|
82
|
+
args,
|
|
83
|
+
args.infile,
|
|
84
|
+
changelogFrontMatter +
|
|
85
|
+
header +
|
|
86
|
+
'\n' +
|
|
87
|
+
(content + oldContentBody).replace(/\n+$/, '\n'),
|
|
88
|
+
);
|
|
101
89
|
}
|
|
102
90
|
|
|
103
91
|
function createIfMissing(args) {
|
package/lib/lifecycles/commit.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import bump from '../lifecycles/bump.js';
|
|
3
|
+
import checkpoint from '../checkpoint.js';
|
|
4
|
+
import formatCommitMessage from '../format-commit-message.js';
|
|
5
|
+
import runExecFile from '../run-execFile.js';
|
|
6
|
+
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export default async function (args, newVersion) {
|
|
9
9
|
if (args.skip.commit) return;
|
|
10
10
|
const message = await runLifecycleScript(args, 'precommit');
|
|
11
11
|
if (message && message.length) args.releaseCommitMessageFormat = message;
|
|
12
12
|
await execCommit(args, newVersion);
|
|
13
13
|
await runLifecycleScript(args, 'postcommit');
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
|
|
16
16
|
async function execCommit(args, newVersion) {
|
|
17
17
|
let msg = 'committing %s';
|
package/lib/lifecycles/tag.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import figures from 'figures';
|
|
3
|
+
import bump from '../lifecycles/bump.js';
|
|
4
|
+
import checkpoint from '../checkpoint.js';
|
|
5
|
+
import formatCommitMessage from '../format-commit-message.js';
|
|
6
|
+
import runExecFile from '../run-execFile.js';
|
|
7
|
+
import runLifecycleScript from '../run-lifecycle-script.js';
|
|
8
|
+
import { detectPMByLockFile } from '../detect-package-manager.js';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export default async function (newVersion, pkgPrivate, args) {
|
|
11
11
|
if (args.skip.tag) return;
|
|
12
12
|
await runLifecycleScript(args, 'pretag');
|
|
13
13
|
await execTag(newVersion, pkgPrivate, args);
|
|
14
14
|
await runLifecycleScript(args, 'posttag');
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
async function detectPublishHint() {
|
|
18
18
|
const npmClientName = await detectPMByLockFile();
|
package/lib/preset-loader.js
CHANGED
|
@@ -1,19 +1,83 @@
|
|
|
1
1
|
// TODO: this should be replaced with an object we maintain and
|
|
2
2
|
// describe in: https://github.com/conventional-changelog/conventional-changelog-config-spec
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import spec from 'conventional-changelog-config-spec';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_PRESET = 'conventional-changelog-conventionalcommits';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Expand a conventional-changelog-config-spec URL format template
|
|
9
|
+
* (e.g. "{{host}}/{{owner}}/{{repository}}/issues/{{id}}") using the
|
|
10
|
+
* variables available at render time.
|
|
11
|
+
*/
|
|
12
|
+
function expandTemplate(template, variables) {
|
|
13
|
+
return template.replace(/{{\s*(\w+)\s*}}/g, (_, key) => variables[key] ?? '');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* conventional-changelog-conventionalcommits >= 10 dropped support for the
|
|
18
|
+
* config-spec's declarative options in favour of new equivalents. Translate
|
|
19
|
+
* the config-spec options so existing user configuration keeps working:
|
|
20
|
+
*
|
|
21
|
+
* - `types[].hidden` (boolean) became `types[].effect`
|
|
22
|
+
* ('bump' | 'changelog' | 'hidden')
|
|
23
|
+
* - `commitUrlFormat`, `compareUrlFormat`, `issueUrlFormat` and
|
|
24
|
+
* `userUrlFormat` (handlebars-style template strings) became the
|
|
25
|
+
* `formatCommitUrl`, `formatCompareUrl`, `formatIssueUrl` and
|
|
26
|
+
* `formatUserUrl` functions
|
|
27
|
+
*/
|
|
28
|
+
function translateSpecOptionsToPresetConfig(preset) {
|
|
29
|
+
if (Array.isArray(preset.types)) {
|
|
30
|
+
preset.types = preset.types.map((entry) => {
|
|
31
|
+
if (typeof entry !== 'object' || entry === null || entry.effect) {
|
|
32
|
+
return entry;
|
|
33
|
+
}
|
|
34
|
+
const { hidden, ...rest } = entry;
|
|
35
|
+
return { ...rest, effect: hidden ? 'hidden' : 'bump' };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (preset.commitUrlFormat && !preset.formatCommitUrl) {
|
|
40
|
+
const template = preset.commitUrlFormat;
|
|
41
|
+
preset.formatCommitUrl = (context, commit) =>
|
|
42
|
+
expandTemplate(template, { ...context, hash: commit.hash });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (preset.compareUrlFormat && !preset.formatCompareUrl) {
|
|
46
|
+
const template = preset.compareUrlFormat;
|
|
47
|
+
preset.formatCompareUrl = (context) => expandTemplate(template, context);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (preset.issueUrlFormat && !preset.formatIssueUrl) {
|
|
51
|
+
const template = preset.issueUrlFormat;
|
|
52
|
+
preset.formatIssueUrl = (context, reference) =>
|
|
53
|
+
expandTemplate(template, {
|
|
54
|
+
...context,
|
|
55
|
+
id: reference.issue,
|
|
56
|
+
prefix: reference.prefix,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (preset.userUrlFormat && !preset.formatUserUrl) {
|
|
61
|
+
const template = preset.userUrlFormat;
|
|
62
|
+
preset.formatUserUrl = (context, user) =>
|
|
63
|
+
expandTemplate(template, { ...context, user });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return preset;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default (args) => {
|
|
70
|
+
let preset = args.preset || DEFAULT_PRESET;
|
|
71
|
+
if (preset === DEFAULT_PRESET) {
|
|
11
72
|
preset = {
|
|
12
|
-
name:
|
|
73
|
+
name: DEFAULT_PRESET,
|
|
13
74
|
};
|
|
14
75
|
Object.keys(spec.properties).forEach((key) => {
|
|
15
76
|
if (args[key] !== undefined) preset[key] = args[key];
|
|
16
77
|
});
|
|
17
78
|
}
|
|
79
|
+
if (typeof preset === 'object') {
|
|
80
|
+
preset = translateSpecOptionsToPresetConfig(preset);
|
|
81
|
+
}
|
|
18
82
|
return preset;
|
|
19
83
|
};
|
package/lib/print-error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default function (args, msg, opts) {
|
|
4
4
|
if (!args.silent) {
|
|
5
5
|
opts = Object.assign(
|
|
6
6
|
{
|
|
@@ -12,4 +12,4 @@ module.exports = function (args, msg, opts) {
|
|
|
12
12
|
|
|
13
13
|
console[opts.level](chalk[opts.color](msg));
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
package/lib/run-exec.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import childProcess from 'child_process';
|
|
3
|
+
import printError from './print-error.js';
|
|
3
4
|
|
|
4
|
-
const exec = promisify(
|
|
5
|
+
const exec = promisify(childProcess.exec);
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export default async function (args, cmd) {
|
|
7
8
|
if (args.dryRun) return;
|
|
8
9
|
try {
|
|
9
10
|
const { stderr, stdout } = await exec(cmd);
|
|
@@ -15,4 +16,4 @@ module.exports = async function (args, cmd) {
|
|
|
15
16
|
printError(args, error.stderr || error.message);
|
|
16
17
|
throw error;
|
|
17
18
|
}
|
|
18
|
-
}
|
|
19
|
+
}
|
package/lib/run-execFile.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import childProcess from 'child_process';
|
|
3
|
+
import printError from './print-error.js';
|
|
3
4
|
|
|
4
|
-
const execFile = promisify(
|
|
5
|
+
const execFile = promisify(childProcess.execFile);
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export default async function (args, cmd, cmdArgs) {
|
|
7
8
|
if (args.dryRun) return;
|
|
8
9
|
try {
|
|
9
10
|
const { stderr, stdout } = await execFile(cmd, cmdArgs);
|
|
@@ -15,4 +16,4 @@ module.exports = async function (args, cmd, cmdArgs) {
|
|
|
15
16
|
printError(args, error.stderr || error.message);
|
|
16
17
|
throw error;
|
|
17
18
|
}
|
|
18
|
-
}
|
|
19
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import figures from 'figures';
|
|
3
|
+
import checkpoint from './checkpoint.js';
|
|
4
|
+
import runExec from './run-exec.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export default function (args, hookName) {
|
|
7
7
|
const scripts = args.scripts;
|
|
8
8
|
if (!scripts || !scripts[hookName]) return Promise.resolve();
|
|
9
9
|
const command = scripts[hookName];
|
|
@@ -15,4 +15,4 @@ module.exports = function (args, hookName) {
|
|
|
15
15
|
chalk.blue(figures.info),
|
|
16
16
|
);
|
|
17
17
|
return runExec(args, command);
|
|
18
|
-
}
|
|
18
|
+
}
|
package/lib/stringify-package.js
CHANGED
|
@@ -16,15 +16,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
16
16
|
https://github.com/npm/stringify-package/blob/main/LICENSE
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
module.exports = stringifyPackage;
|
|
22
|
-
|
|
23
19
|
const DEFAULT_INDENT = 2;
|
|
24
20
|
const CRLF = '\r\n';
|
|
25
21
|
const LF = '\n';
|
|
26
22
|
|
|
27
|
-
function stringifyPackage(data, indent, newline) {
|
|
23
|
+
export default function stringifyPackage(data, indent, newline) {
|
|
28
24
|
indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT);
|
|
29
25
|
const json = JSON.stringify(data, null, indent);
|
|
30
26
|
|