fork-version 1.4.6
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/README.md +13 -0
- package/dist/chunk-2I73SGKO.cjs +624 -0
- package/dist/chunk-2I73SGKO.cjs.map +1 -0
- package/dist/chunk-STAHBMPI.js +605 -0
- package/dist/chunk-STAHBMPI.js.map +1 -0
- package/dist/cli.cjs +27 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Fork-Version
|
|
2
|
+
|
|
3
|
+
Fork-version is a re-write of [standard-version](https://github.com/conventional-changelog/standard-version) following on from its deprecation in May 15, 2022.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the package locally to your project you can use one of the following commands:
|
|
8
|
+
|
|
9
|
+
| Manager | Command |
|
|
10
|
+
| ------- | -------------------------------------------------- |
|
|
11
|
+
| npm | `npm install fork-version --save-exact --save-dev` |
|
|
12
|
+
| yarn | `yarn add fork-version --exact --dev` |
|
|
13
|
+
| pnpm | `pnpm add fork-version --save-exact --save-dev` |
|
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var JoyCon = require('joycon');
|
|
5
|
+
var bundleRequire = require('bundle-require');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var conventionalChangelogConfigSpec = require('conventional-changelog-config-spec');
|
|
8
|
+
var fs = require('fs');
|
|
9
|
+
var gitSemverTags = require('git-semver-tags');
|
|
10
|
+
var semver = require('semver');
|
|
11
|
+
var conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
12
|
+
var detectIndent = require('detect-indent');
|
|
13
|
+
var detectNewLine = require('detect-newline');
|
|
14
|
+
var conventionalChangelog = require('conventional-changelog');
|
|
15
|
+
var child_process = require('child_process');
|
|
16
|
+
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
|
|
19
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
20
|
+
var JoyCon__default = /*#__PURE__*/_interopDefault(JoyCon);
|
|
21
|
+
var conventionalChangelogConfigSpec__default = /*#__PURE__*/_interopDefault(conventionalChangelogConfigSpec);
|
|
22
|
+
var gitSemverTags__default = /*#__PURE__*/_interopDefault(gitSemverTags);
|
|
23
|
+
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
24
|
+
var conventionalRecommendedBump__default = /*#__PURE__*/_interopDefault(conventionalRecommendedBump);
|
|
25
|
+
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
|
26
|
+
var detectNewLine__default = /*#__PURE__*/_interopDefault(detectNewLine);
|
|
27
|
+
var conventionalChangelog__default = /*#__PURE__*/_interopDefault(conventionalChangelog);
|
|
28
|
+
|
|
29
|
+
// src/configuration.ts
|
|
30
|
+
var ForkConfigSchema = zod.z.object({
|
|
31
|
+
/**
|
|
32
|
+
* The path where the changes should be calculated from.
|
|
33
|
+
* @default
|
|
34
|
+
* ```js
|
|
35
|
+
* process.cwd()
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
changePath: zod.z.string(),
|
|
39
|
+
/**
|
|
40
|
+
* The name of the changelog file.
|
|
41
|
+
* @default "CHANGELOG.md"
|
|
42
|
+
*/
|
|
43
|
+
changelog: zod.z.string(),
|
|
44
|
+
/**
|
|
45
|
+
* Files to be updated.
|
|
46
|
+
* @default
|
|
47
|
+
* ```js
|
|
48
|
+
* ["bower.json", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
outFiles: zod.z.array(zod.z.string()),
|
|
52
|
+
/**
|
|
53
|
+
* The header to be used in the changelog.
|
|
54
|
+
* @default
|
|
55
|
+
* ```markdown
|
|
56
|
+
* # Changelog
|
|
57
|
+
*
|
|
58
|
+
* All notable changes to this project will be documented in this file. See [fork-version](https://github.com/eglavin/fork-version) for commit guidelines.
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
header: zod.z.string(),
|
|
62
|
+
/**
|
|
63
|
+
* Specify a prefix for the git tag that will be taken into account during the comparison.
|
|
64
|
+
*
|
|
65
|
+
* For instance if your version tag is prefixed by `version/` instead of `v` you would
|
|
66
|
+
* have to specify `tagPrefix: "version/"`.
|
|
67
|
+
* @default `v`
|
|
68
|
+
*/
|
|
69
|
+
tagPrefix: zod.z.string(),
|
|
70
|
+
/**
|
|
71
|
+
* Make a pre-release with optional label to specify a tag id.
|
|
72
|
+
* @example true, "alpha", "beta", "rc", etc.
|
|
73
|
+
* @default undefined
|
|
74
|
+
*/
|
|
75
|
+
preReleaseTag: zod.z.string().or(zod.z.boolean()).optional(),
|
|
76
|
+
/**
|
|
77
|
+
* Commit all staged changes, not just files updated by fork-version.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
commitAll: zod.z.boolean(),
|
|
81
|
+
/**
|
|
82
|
+
* If true, no output will be written to disk or committed.
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
dryRun: zod.z.boolean(),
|
|
86
|
+
/**
|
|
87
|
+
* If true and we cant find a version in an `outFiles`, we'll fallback and attempt
|
|
88
|
+
* to use the latest git tag for the current version.
|
|
89
|
+
* @default true
|
|
90
|
+
*/
|
|
91
|
+
gitTagFallback: zod.z.boolean(),
|
|
92
|
+
/**
|
|
93
|
+
* Should we sign the git commit using GPG?
|
|
94
|
+
* @see {@link https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--Sltkeyidgt GPG Sign Commits}
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
sign: zod.z.boolean(),
|
|
98
|
+
/**
|
|
99
|
+
* If true, no output will be written to stdout.
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
silent: zod.z.boolean(),
|
|
103
|
+
/**
|
|
104
|
+
* If true, allow git to run git commit hooks.
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
verify: zod.z.boolean(),
|
|
108
|
+
/**
|
|
109
|
+
* If set, we'll use this version number instead of trying to find it in an `outFiles`.
|
|
110
|
+
* @example "1.0.0"
|
|
111
|
+
* @default undefined
|
|
112
|
+
*/
|
|
113
|
+
currentVersion: zod.z.string().optional(),
|
|
114
|
+
/**
|
|
115
|
+
* If set, we'll attempt to update the version number to this version.
|
|
116
|
+
* @example "2.0.0"
|
|
117
|
+
* @default undefined
|
|
118
|
+
*/
|
|
119
|
+
nextVersion: zod.z.string().optional(),
|
|
120
|
+
/**
|
|
121
|
+
* Override the default conventional-changelog preset configuration.
|
|
122
|
+
*/
|
|
123
|
+
changelogPresetConfig: zod.z.object({
|
|
124
|
+
/**
|
|
125
|
+
* An array of `type` objects representing the explicitly supported commit message types, and whether they should show up in generated `CHANGELOG`s.
|
|
126
|
+
*/
|
|
127
|
+
types: zod.z.array(
|
|
128
|
+
zod.z.object({
|
|
129
|
+
type: zod.z.string(),
|
|
130
|
+
section: zod.z.string().optional(),
|
|
131
|
+
hidden: zod.z.boolean().optional()
|
|
132
|
+
})
|
|
133
|
+
).optional(),
|
|
134
|
+
/**
|
|
135
|
+
* A URL representing a specific commit at a hash.
|
|
136
|
+
*/
|
|
137
|
+
commitUrlFormat: zod.z.string().optional(),
|
|
138
|
+
/**
|
|
139
|
+
* A URL representing the comparison between two git SHAs.
|
|
140
|
+
*/
|
|
141
|
+
compareUrlFormat: zod.z.string().optional(),
|
|
142
|
+
/**
|
|
143
|
+
* A URL representing the issue format (allowing a different URL format to be swapped in for Gitlab, Bitbucket, etc).
|
|
144
|
+
*/
|
|
145
|
+
issueUrlFormat: zod.z.string().optional(),
|
|
146
|
+
/**
|
|
147
|
+
* A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for substituting @bcoe with https://github.com/bcoe in commit messages.
|
|
148
|
+
*/
|
|
149
|
+
userUrlFormat: zod.z.string().optional(),
|
|
150
|
+
/**
|
|
151
|
+
* A string to be used to format the auto-generated release commit message.
|
|
152
|
+
*/
|
|
153
|
+
releaseCommitMessageFormat: zod.z.string().optional(),
|
|
154
|
+
/**
|
|
155
|
+
* An array of prefixes used to detect references to issues
|
|
156
|
+
*/
|
|
157
|
+
issuePrefixes: zod.z.array(zod.z.string()).optional()
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
var DEFAULT_CONFIG = {
|
|
161
|
+
changePath: process.cwd(),
|
|
162
|
+
changelog: "CHANGELOG.md",
|
|
163
|
+
outFiles: [
|
|
164
|
+
"bower.json",
|
|
165
|
+
"manifest.json",
|
|
166
|
+
// Chrome extensions
|
|
167
|
+
"npm-shrinkwrap.json",
|
|
168
|
+
"package-lock.json",
|
|
169
|
+
"package.json"
|
|
170
|
+
],
|
|
171
|
+
header: "# Changelog\n\nAll notable changes to this project will be documented in this file. See [fork-version](https://github.com/eglavin/fork-version) for commit guidelines.\n",
|
|
172
|
+
tagPrefix: "v",
|
|
173
|
+
commitAll: false,
|
|
174
|
+
dryRun: false,
|
|
175
|
+
gitTagFallback: true,
|
|
176
|
+
sign: false,
|
|
177
|
+
silent: false,
|
|
178
|
+
verify: false,
|
|
179
|
+
changelogPresetConfig: {},
|
|
180
|
+
log: console.log,
|
|
181
|
+
// eslint-disable-line no-console
|
|
182
|
+
error: console.error,
|
|
183
|
+
// eslint-disable-line no-console
|
|
184
|
+
debug: () => {
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
function defineConfig(config) {
|
|
188
|
+
const parsedConfig = ForkConfigSchema.partial().safeParse(config);
|
|
189
|
+
if (parsedConfig.success) {
|
|
190
|
+
return parsedConfig.data;
|
|
191
|
+
}
|
|
192
|
+
return DEFAULT_CONFIG;
|
|
193
|
+
}
|
|
194
|
+
function getPresetDefaults(usersChangelogPresetConfig) {
|
|
195
|
+
const preset = {
|
|
196
|
+
name: "conventionalcommits"
|
|
197
|
+
};
|
|
198
|
+
if (typeof conventionalChangelogConfigSpec__default.default.properties === "object") {
|
|
199
|
+
Object.entries(conventionalChangelogConfigSpec__default.default.properties).forEach(([key, value]) => {
|
|
200
|
+
const _value = value;
|
|
201
|
+
if ("default" in _value && _value.default !== void 0) {
|
|
202
|
+
preset[key] = _value.default;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (usersChangelogPresetConfig && typeof usersChangelogPresetConfig === "object") {
|
|
207
|
+
Object.entries(usersChangelogPresetConfig).forEach(([key, value]) => {
|
|
208
|
+
if (value !== void 0) {
|
|
209
|
+
preset[key] = value;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return preset;
|
|
214
|
+
}
|
|
215
|
+
async function getForkConfig() {
|
|
216
|
+
const cwd = process.cwd();
|
|
217
|
+
const joycon = new JoyCon__default.default.default();
|
|
218
|
+
const configPath = await joycon.resolve({
|
|
219
|
+
files: ["fork.config.js"],
|
|
220
|
+
cwd,
|
|
221
|
+
stopDir: path__default.default.parse(cwd).root
|
|
222
|
+
});
|
|
223
|
+
if (configPath) {
|
|
224
|
+
const foundConfig = await bundleRequire.bundleRequire({ filepath: configPath });
|
|
225
|
+
const parsedConfig = ForkConfigSchema.partial().safeParse(
|
|
226
|
+
foundConfig.mod.default || foundConfig.mod
|
|
227
|
+
);
|
|
228
|
+
if (parsedConfig.success) {
|
|
229
|
+
const mergedOutFiles = DEFAULT_CONFIG.outFiles.concat(parsedConfig.data?.outFiles || []);
|
|
230
|
+
const usersConfig = Object.assign(DEFAULT_CONFIG, parsedConfig.data, {
|
|
231
|
+
outFiles: Array.from(new Set(mergedOutFiles))
|
|
232
|
+
});
|
|
233
|
+
if (usersConfig.silent) {
|
|
234
|
+
usersConfig.log = () => {
|
|
235
|
+
};
|
|
236
|
+
usersConfig.error = () => {
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if ("debug" in parsedConfig && typeof parsedConfig.debug === "function") {
|
|
240
|
+
usersConfig.debug = parsedConfig.debug;
|
|
241
|
+
}
|
|
242
|
+
return Object.assign(usersConfig, {
|
|
243
|
+
changelogPresetConfig: getPresetDefaults(usersConfig?.changelogPresetConfig)
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return Object.assign(DEFAULT_CONFIG, {
|
|
248
|
+
changelogPresetConfig: getPresetDefaults()
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/libs/stringify-package.ts
|
|
253
|
+
var DEFAULT_INDENT = 2;
|
|
254
|
+
var CRLF = "\r\n";
|
|
255
|
+
var LF = "\n";
|
|
256
|
+
function stringifyPackage(data, indent, newline) {
|
|
257
|
+
const stringified = JSON.stringify(data, null, indent || (indent === 0 ? 0 : DEFAULT_INDENT));
|
|
258
|
+
if (newline === CRLF) {
|
|
259
|
+
return stringified.replace(new RegExp(LF, "g"), CRLF);
|
|
260
|
+
}
|
|
261
|
+
return stringified;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/process/version.ts
|
|
265
|
+
function getFile(options, fileToGet) {
|
|
266
|
+
try {
|
|
267
|
+
const fileExtension = path.extname(fileToGet);
|
|
268
|
+
if (fileExtension === ".json") {
|
|
269
|
+
const filePath = path.resolve(options.changePath, fileToGet);
|
|
270
|
+
if (fs.existsSync(filePath)) {
|
|
271
|
+
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
272
|
+
const parsedJson = JSON.parse(fileContents);
|
|
273
|
+
if (parsedJson.version) {
|
|
274
|
+
return {
|
|
275
|
+
name: fileToGet,
|
|
276
|
+
path: filePath,
|
|
277
|
+
type: "package-file",
|
|
278
|
+
version: parsedJson.version,
|
|
279
|
+
isPrivate: "private" in parsedJson && (typeof parsedJson.private === "boolean" ? parsedJson.private : false)
|
|
280
|
+
};
|
|
281
|
+
} else {
|
|
282
|
+
options.log(`Unable to find version in file: ${fileToGet}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
} catch (error) {
|
|
287
|
+
options.error(`Error reading file: ${fileToGet}`, error);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function getLatestGitTagVersion(tagPrefix) {
|
|
291
|
+
const gitTags = await gitSemverTags__default.default({ tagPrefix });
|
|
292
|
+
if (!gitTags.length) {
|
|
293
|
+
return "1.0.0";
|
|
294
|
+
}
|
|
295
|
+
const cleanedTags = [];
|
|
296
|
+
for (const tag of gitTags) {
|
|
297
|
+
const cleanedTag = semver__default.default.clean(tag.replace(new RegExp(`^${tagPrefix}`), ""));
|
|
298
|
+
if (cleanedTag) {
|
|
299
|
+
cleanedTags.push(cleanedTag);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return cleanedTags.sort(semver__default.default.rcompare)[0];
|
|
303
|
+
}
|
|
304
|
+
async function getCurrentVersion(options) {
|
|
305
|
+
const files = [];
|
|
306
|
+
const versions = [];
|
|
307
|
+
for (const file of options.outFiles) {
|
|
308
|
+
const fileState = getFile(options, file);
|
|
309
|
+
if (fileState) {
|
|
310
|
+
files.push(fileState);
|
|
311
|
+
if (options.currentVersion) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (!versions.includes(fileState.version)) {
|
|
315
|
+
versions.push(fileState.version);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (options.currentVersion) {
|
|
320
|
+
versions.push(options.currentVersion);
|
|
321
|
+
}
|
|
322
|
+
if (versions.length === 0) {
|
|
323
|
+
if (options.gitTagFallback) {
|
|
324
|
+
const version = await getLatestGitTagVersion(options.tagPrefix);
|
|
325
|
+
if (version) {
|
|
326
|
+
return {
|
|
327
|
+
files: [],
|
|
328
|
+
currentVersion: version
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
throw new Error("Unable to find current version");
|
|
333
|
+
} else if (versions.length > 1) {
|
|
334
|
+
throw new Error("Found multiple versions");
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
files,
|
|
338
|
+
currentVersion: versions[0]
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function getPriority(type) {
|
|
342
|
+
return ["patch", "minor", "major"].indexOf(type || "");
|
|
343
|
+
}
|
|
344
|
+
function getVersionType(version) {
|
|
345
|
+
const parseVersion = semver__default.default.parse(version);
|
|
346
|
+
if (parseVersion?.major) {
|
|
347
|
+
return "major";
|
|
348
|
+
} else if (parseVersion?.minor) {
|
|
349
|
+
return "minor";
|
|
350
|
+
} else if (parseVersion?.patch) {
|
|
351
|
+
return "patch";
|
|
352
|
+
}
|
|
353
|
+
return void 0;
|
|
354
|
+
}
|
|
355
|
+
function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
356
|
+
if (!preReleaseTag) {
|
|
357
|
+
return releaseType;
|
|
358
|
+
}
|
|
359
|
+
if (Array.isArray(semver__default.default.prerelease(currentVersion))) {
|
|
360
|
+
const currentReleaseType = getVersionType(currentVersion);
|
|
361
|
+
if (currentReleaseType === releaseType || getPriority(currentReleaseType) > getPriority(releaseType)) {
|
|
362
|
+
return "prerelease";
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return `pre${releaseType}`;
|
|
366
|
+
}
|
|
367
|
+
async function getNextVersion(options, currentVersion) {
|
|
368
|
+
if (options.nextVersion && semver__default.default.valid(options.nextVersion)) {
|
|
369
|
+
return { nextVersion: options.nextVersion };
|
|
370
|
+
}
|
|
371
|
+
const preMajor = semver__default.default.lt(currentVersion, "1.0.0");
|
|
372
|
+
const recommendedBump = await conventionalRecommendedBump__default.default({
|
|
373
|
+
preset: {
|
|
374
|
+
name: "conventionalcommits",
|
|
375
|
+
...options.changelogPresetConfig || {},
|
|
376
|
+
preMajor
|
|
377
|
+
},
|
|
378
|
+
path: options.changePath,
|
|
379
|
+
tagPrefix: options.tagPrefix,
|
|
380
|
+
cwd: options.changePath
|
|
381
|
+
});
|
|
382
|
+
if (recommendedBump.releaseType) {
|
|
383
|
+
const releaseType = getReleaseType(
|
|
384
|
+
recommendedBump.releaseType,
|
|
385
|
+
currentVersion,
|
|
386
|
+
options.preReleaseTag
|
|
387
|
+
);
|
|
388
|
+
return Object.assign(recommendedBump, {
|
|
389
|
+
preMajor,
|
|
390
|
+
releaseType,
|
|
391
|
+
nextVersion: semver__default.default.inc(
|
|
392
|
+
currentVersion,
|
|
393
|
+
releaseType,
|
|
394
|
+
typeof options.preReleaseTag === "string" ? options.preReleaseTag : void 0
|
|
395
|
+
) || ""
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
throw new Error("Unable to find next version");
|
|
399
|
+
}
|
|
400
|
+
function updateFile(options, fileToUpdate, type, nextVersion) {
|
|
401
|
+
try {
|
|
402
|
+
if (type === "package-file") {
|
|
403
|
+
if (!fs.lstatSync(fileToUpdate).isFile())
|
|
404
|
+
return;
|
|
405
|
+
const fileContents = fs.readFileSync(fileToUpdate, "utf8");
|
|
406
|
+
const indent = detectIndent__default.default(fileContents).indent;
|
|
407
|
+
const newline = detectNewLine__default.default(fileContents);
|
|
408
|
+
const parsedJson = JSON.parse(fileContents);
|
|
409
|
+
parsedJson.version = nextVersion;
|
|
410
|
+
if (parsedJson.packages && parsedJson.packages[""]) {
|
|
411
|
+
parsedJson.packages[""].version = nextVersion;
|
|
412
|
+
}
|
|
413
|
+
if (!options.dryRun) {
|
|
414
|
+
fs.writeFileSync(fileToUpdate, stringifyPackage(parsedJson, indent, newline), "utf8");
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} catch (error) {
|
|
418
|
+
options.error("Error writing: ", error);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async function bumpVersion(options) {
|
|
422
|
+
const current = await getCurrentVersion(options);
|
|
423
|
+
const next = await getNextVersion(options, current.currentVersion);
|
|
424
|
+
options.log(`Current version: ${current.currentVersion}
|
|
425
|
+
Next version: ${next.nextVersion} (${next.releaseType})
|
|
426
|
+
Updating Files: `);
|
|
427
|
+
for (const outFile of current.files) {
|
|
428
|
+
options.log(` ${outFile.path}`);
|
|
429
|
+
updateFile(options, outFile.path, outFile.type, next.nextVersion);
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
currentVersion: current.currentVersion,
|
|
433
|
+
files: current.files,
|
|
434
|
+
nextVersion: next.nextVersion,
|
|
435
|
+
level: next.level,
|
|
436
|
+
preMajor: next.preMajor,
|
|
437
|
+
reason: next.reason,
|
|
438
|
+
releaseType: next.releaseType
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function createChangelog(options) {
|
|
442
|
+
const changelogPath = path.resolve(options.changelog);
|
|
443
|
+
try {
|
|
444
|
+
fs.accessSync(changelogPath, fs.constants.F_OK);
|
|
445
|
+
} catch (err) {
|
|
446
|
+
if (!options.dryRun && err.code === "ENOENT") {
|
|
447
|
+
options.log(`Creating Changelog file: ${changelogPath}`);
|
|
448
|
+
fs.writeFileSync(changelogPath, "\n", "utf8");
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
path: changelogPath,
|
|
453
|
+
exists: fs.existsSync(changelogPath)
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
var RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
|
|
457
|
+
function getOldReleaseContent(changelog) {
|
|
458
|
+
if (changelog.exists) {
|
|
459
|
+
const fileContents = fs.readFileSync(changelog.path, "utf-8");
|
|
460
|
+
const oldContentStart = fileContents.search(RELEASE_PATTERN);
|
|
461
|
+
if (oldContentStart !== -1) {
|
|
462
|
+
return fileContents.substring(oldContentStart);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return "";
|
|
466
|
+
}
|
|
467
|
+
function getNewReleaseContent(options, bumpResult) {
|
|
468
|
+
return new Promise((resolve3) => {
|
|
469
|
+
let newContent = "";
|
|
470
|
+
conventionalChangelog__default.default(
|
|
471
|
+
{
|
|
472
|
+
preset: {
|
|
473
|
+
name: "conventionalcommits",
|
|
474
|
+
...options.changelogPresetConfig || {}
|
|
475
|
+
},
|
|
476
|
+
tagPrefix: options.tagPrefix,
|
|
477
|
+
warn: (...message) => options.error("conventional-changelog: ", ...message),
|
|
478
|
+
cwd: options.changePath
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
version: bumpResult.nextVersion
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
merges: null,
|
|
485
|
+
path: options.changePath
|
|
486
|
+
}
|
|
487
|
+
).on("error", (error) => {
|
|
488
|
+
options.error("conventional-changelog: Unable to parse changes");
|
|
489
|
+
throw error;
|
|
490
|
+
}).on("data", (chunk) => {
|
|
491
|
+
newContent += chunk.toString();
|
|
492
|
+
}).on("end", () => {
|
|
493
|
+
resolve3(newContent);
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
async function updateChangelog(options, bumpResult) {
|
|
498
|
+
if (options.header.search(RELEASE_PATTERN) !== -1) {
|
|
499
|
+
throw new Error("Header cannot contain release pattern");
|
|
500
|
+
}
|
|
501
|
+
const changelog = createChangelog(options);
|
|
502
|
+
const oldContent = getOldReleaseContent(changelog);
|
|
503
|
+
const newContent = await getNewReleaseContent(options, bumpResult);
|
|
504
|
+
options.log(`Updating Changelog:
|
|
505
|
+
${changelog.path}`);
|
|
506
|
+
if (!options.dryRun && newContent) {
|
|
507
|
+
fs.writeFileSync(changelog.path, `${options.header}
|
|
508
|
+
${newContent}
|
|
509
|
+
${oldContent}`, "utf8");
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
changelog,
|
|
513
|
+
oldContent,
|
|
514
|
+
newContent
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function createExecute(options) {
|
|
518
|
+
async function executeGit(...execArgs) {
|
|
519
|
+
const args = execArgs.filter(Boolean);
|
|
520
|
+
options.debug(`Executing: git ${args.join(" ")}`);
|
|
521
|
+
if (!options.dryRun) {
|
|
522
|
+
return new Promise((resolve3) => {
|
|
523
|
+
child_process.execFile("git", args, (error, stdout, stderr) => {
|
|
524
|
+
if (error) {
|
|
525
|
+
options.error(`git ${args[0]}:`);
|
|
526
|
+
throw error;
|
|
527
|
+
}
|
|
528
|
+
resolve3(stdout ? stdout : stderr);
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return "";
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
executeGit
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/utils/format-commit-message.ts
|
|
540
|
+
function formatCommitMessage(message, newVersion) {
|
|
541
|
+
if (!message) {
|
|
542
|
+
message = "chore(release): {{currentTag}}";
|
|
543
|
+
}
|
|
544
|
+
return message.replace(new RegExp("{{currentTag}}", "g"), newVersion);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/process/commit.ts
|
|
548
|
+
async function commitChanges(options, bumpResult) {
|
|
549
|
+
const { executeGit } = createExecute(options);
|
|
550
|
+
options.log("Committing changes");
|
|
551
|
+
const filesToCommit = [options.changelog];
|
|
552
|
+
for (const file of bumpResult.files) {
|
|
553
|
+
filesToCommit.push(file.name);
|
|
554
|
+
}
|
|
555
|
+
if (filesToCommit.length === 0) {
|
|
556
|
+
return {
|
|
557
|
+
filesToCommit
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
const gitAddOutput = await executeGit("add", ...filesToCommit);
|
|
561
|
+
const shouldVerify = options.verify ? void 0 : "--no-verify";
|
|
562
|
+
const shouldSign = options.sign ? "-S" : void 0;
|
|
563
|
+
const shouldCommitAll = options.commitAll ? [] : filesToCommit;
|
|
564
|
+
const gitCommitOutput = await executeGit(
|
|
565
|
+
"commit",
|
|
566
|
+
shouldVerify,
|
|
567
|
+
shouldSign,
|
|
568
|
+
...shouldCommitAll,
|
|
569
|
+
"-m",
|
|
570
|
+
formatCommitMessage(
|
|
571
|
+
options.changelogPresetConfig?.releaseCommitMessageFormat,
|
|
572
|
+
bumpResult.nextVersion
|
|
573
|
+
)
|
|
574
|
+
);
|
|
575
|
+
return {
|
|
576
|
+
filesToCommit,
|
|
577
|
+
gitAddOutput,
|
|
578
|
+
gitCommitOutput
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/process/tag.ts
|
|
583
|
+
async function tagChanges(options, bumpResult) {
|
|
584
|
+
const { executeGit } = createExecute(options);
|
|
585
|
+
const shouldSign = options.sign ? "-s" : "-a";
|
|
586
|
+
const tag = `${options.tagPrefix}${bumpResult.nextVersion}`;
|
|
587
|
+
options.log(`Creating Tag: ${tag}`);
|
|
588
|
+
const gitTagOutput = await executeGit(
|
|
589
|
+
"tag",
|
|
590
|
+
shouldSign,
|
|
591
|
+
tag,
|
|
592
|
+
"-m",
|
|
593
|
+
formatCommitMessage(
|
|
594
|
+
options.changelogPresetConfig?.releaseCommitMessageFormat,
|
|
595
|
+
bumpResult.nextVersion
|
|
596
|
+
)
|
|
597
|
+
);
|
|
598
|
+
const currentBranchName = await executeGit("rev-parse", "--abbrev-ref", "HEAD");
|
|
599
|
+
const hasPublicPackageFile = bumpResult.files.some(
|
|
600
|
+
(file) => file.name === "package.json" && file.isPrivate === false
|
|
601
|
+
);
|
|
602
|
+
const isPreRelease = `${bumpResult.releaseType}`.startsWith("pre");
|
|
603
|
+
const pushMessage = `Run \`git push --follow-tags origin ${currentBranchName.trim()}\` to push the changes and the tag.`;
|
|
604
|
+
const publishMessage = isPreRelease ? `Run \`npm publish --tag ${typeof options.preReleaseTag === "string" ? options.preReleaseTag : "prerelease"}\` to publish the package.` : "Run `npm publish` to publish the package.";
|
|
605
|
+
options.log(`
|
|
606
|
+
${pushMessage}
|
|
607
|
+
${hasPublicPackageFile ? publishMessage : ""}`);
|
|
608
|
+
return {
|
|
609
|
+
gitTagOutput,
|
|
610
|
+
currentBranchName,
|
|
611
|
+
hasPublicPackageFile,
|
|
612
|
+
pushMessage,
|
|
613
|
+
publishMessage
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
exports.bumpVersion = bumpVersion;
|
|
618
|
+
exports.commitChanges = commitChanges;
|
|
619
|
+
exports.defineConfig = defineConfig;
|
|
620
|
+
exports.getForkConfig = getForkConfig;
|
|
621
|
+
exports.tagChanges = tagChanges;
|
|
622
|
+
exports.updateChangelog = updateChangelog;
|
|
623
|
+
//# sourceMappingURL=out.js.map
|
|
624
|
+
//# sourceMappingURL=chunk-2I73SGKO.cjs.map
|