@williamthorsen/release-kit 6.0.0 → 7.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/CHANGELOG.md +8 -0
- package/README.md +3 -3
- package/dist/esm/.cache +1 -1
- package/dist/esm/assertCleanWorkingTree.js +9 -14
- package/dist/esm/bin/release-kit.js +200 -199
- package/dist/esm/buildChangelogEntries.d.ts +2 -2
- package/dist/esm/buildChangelogEntries.js +142 -149
- package/dist/esm/buildDependencyGraph.d.ts +1 -1
- package/dist/esm/buildDependencyGraph.js +60 -59
- package/dist/esm/buildEmptyReleaseEntry.d.ts +1 -1
- package/dist/esm/buildEmptyReleaseEntry.js +12 -15
- package/dist/esm/buildReleaseSummary.d.ts +1 -1
- package/dist/esm/buildReleaseSummary.js +23 -26
- package/dist/esm/buildSyntheticChangelogEntry.d.ts +1 -1
- package/dist/esm/buildSyntheticChangelogEntry.js +9 -12
- package/dist/esm/bumpAllVersions.d.ts +1 -1
- package/dist/esm/bumpAllVersions.js +51 -52
- package/dist/esm/bumpVersion.d.ts +1 -1
- package/dist/esm/bumpVersion.js +25 -28
- package/dist/esm/changelogJsonFile.d.ts +1 -1
- package/dist/esm/changelogJsonFile.js +59 -62
- package/dist/esm/changelogJsonUtils.d.ts +1 -1
- package/dist/esm/changelogJsonUtils.js +35 -32
- package/dist/esm/changelogOverrides.d.ts +1 -1
- package/dist/esm/changelogOverrides.js +374 -377
- package/dist/esm/checkWorkTypesDrift.js +104 -102
- package/dist/esm/collectPolicyViolations.d.ts +2 -2
- package/dist/esm/collectPolicyViolations.js +11 -14
- package/dist/esm/commitCommand.js +48 -46
- package/dist/esm/compareVersions.js +20 -23
- package/dist/esm/createGithubRelease.js +56 -59
- package/dist/esm/createGithubReleaseCommand.js +21 -23
- package/dist/esm/createTags.js +57 -56
- package/dist/esm/decideRelease.d.ts +2 -2
- package/dist/esm/decideRelease.js +27 -41
- package/dist/esm/defaults.d.ts +3 -3
- package/dist/esm/defaults.js +36 -48
- package/dist/esm/deleteFileIfExists.js +10 -12
- package/dist/esm/deriveWorkspaceConfig.d.ts +1 -1
- package/dist/esm/deriveWorkspaceConfig.js +34 -36
- package/dist/esm/detectPackageManager.js +35 -37
- package/dist/esm/detectUndeclaredTagPrefixes.js +41 -40
- package/dist/esm/determineBumpFromCommits.d.ts +2 -2
- package/dist/esm/determineBumpFromCommits.js +25 -29
- package/dist/esm/determineBumpType.d.ts +1 -1
- package/dist/esm/determineBumpType.js +31 -32
- package/dist/esm/discoverWorkspaces.js +38 -40
- package/dist/esm/format.js +6 -11
- package/dist/esm/generateChangelogs.d.ts +1 -1
- package/dist/esm/generateChangelogs.js +13 -17
- package/dist/esm/getCommitsSinceTarget.d.ts +1 -1
- package/dist/esm/getCommitsSinceTarget.js +54 -55
- package/dist/esm/hasPrettierConfig.js +33 -35
- package/dist/esm/help/prepareHelp.js +4 -8
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +2 -8
- package/dist/esm/init/checks.js +28 -32
- package/dist/esm/init/detectRepoType.js +12 -15
- package/dist/esm/init/initCommand.js +60 -54
- package/dist/esm/init/parseJsonRecord.js +9 -11
- package/dist/esm/init/scaffold.d.ts +1 -1
- package/dist/esm/init/scaffold.js +32 -38
- package/dist/esm/init/templates.d.ts +1 -1
- package/dist/esm/init/templates.js +16 -22
- package/dist/esm/injectReleaseNotesIntoReadme.js +42 -49
- package/dist/esm/injectSection.js +17 -27
- package/dist/esm/loadConfig.d.ts +1 -1
- package/dist/esm/loadConfig.js +206 -225
- package/dist/esm/parseCommitMessage.d.ts +1 -1
- package/dist/esm/parseCommitMessage.js +72 -76
- package/dist/esm/parseRequestedTags.js +6 -9
- package/dist/esm/prepareCommand.d.ts +1 -1
- package/dist/esm/prepareCommand.js +225 -235
- package/dist/esm/previewTagPrefixes.d.ts +1 -1
- package/dist/esm/previewTagPrefixes.js +101 -96
- package/dist/esm/propagateBumps.d.ts +2 -2
- package/dist/esm/propagateBumps.js +48 -50
- package/dist/esm/publish.d.ts +2 -2
- package/dist/esm/publish.js +22 -28
- package/dist/esm/publishCommand.js +75 -80
- package/dist/esm/pushCommand.js +33 -34
- package/dist/esm/pushRelease.d.ts +1 -1
- package/dist/esm/pushRelease.js +21 -24
- package/dist/esm/readCurrentVersion.js +13 -17
- package/dist/esm/releasePrepare.d.ts +1 -1
- package/dist/esm/releasePrepare.js +213 -231
- package/dist/esm/releasePrepareMono.d.ts +2 -2
- package/dist/esm/releasePrepareMono.js +434 -494
- package/dist/esm/releasePrepareProject.d.ts +2 -2
- package/dist/esm/releasePrepareProject.js +143 -153
- package/dist/esm/renderChangelogMarkdown.d.ts +1 -1
- package/dist/esm/renderChangelogMarkdown.js +20 -24
- package/dist/esm/renderReleaseNotes.d.ts +1 -1
- package/dist/esm/renderReleaseNotes.js +50 -55
- package/dist/esm/reportPrepare.d.ts +1 -1
- package/dist/esm/reportPrepare.js +230 -231
- package/dist/esm/resolveCliffConfigPath.js +18 -23
- package/dist/esm/resolveCommandTags.d.ts +1 -1
- package/dist/esm/resolveCommandTags.js +47 -45
- package/dist/esm/resolveReleaseNotesConfig.d.ts +1 -1
- package/dist/esm/resolveReleaseNotesConfig.js +39 -43
- package/dist/esm/resolveReleaseTags.d.ts +1 -1
- package/dist/esm/resolveReleaseTags.js +39 -40
- package/dist/esm/runGitCliff.js +27 -30
- package/dist/esm/showTagPrefixesCommand.js +48 -70
- package/dist/esm/stripEmojiPrefix.js +2 -5
- package/dist/esm/stripScope.js +18 -21
- package/dist/esm/sync-labels/generateCommand.d.ts +1 -1
- package/dist/esm/sync-labels/generateCommand.js +51 -53
- package/dist/esm/sync-labels/initCommand.js +46 -48
- package/dist/esm/sync-labels/loadSyncLabelsConfig.d.ts +1 -1
- package/dist/esm/sync-labels/loadSyncLabelsConfig.js +46 -52
- package/dist/esm/sync-labels/presets.d.ts +1 -1
- package/dist/esm/sync-labels/presets.js +40 -43
- package/dist/esm/sync-labels/resolveLabels.d.ts +1 -1
- package/dist/esm/sync-labels/resolveLabels.js +28 -35
- package/dist/esm/sync-labels/syncCommand.js +30 -31
- package/dist/esm/sync-labels/templates.d.ts +1 -1
- package/dist/esm/sync-labels/templates.js +23 -26
- package/dist/esm/sync-labels/types.js +1 -0
- package/dist/esm/syncWorkTypes.js +83 -84
- package/dist/esm/tagCommand.js +12 -14
- package/dist/esm/typeGuards.js +4 -8
- package/dist/esm/types.js +66 -60
- package/dist/esm/validateConfig.d.ts +1 -1
- package/dist/esm/validateConfig.js +109 -115
- package/dist/esm/validateOnlyExcludesStrandedDependents.d.ts +2 -2
- package/dist/esm/validateOnlyExcludesStrandedDependents.js +97 -91
- package/dist/esm/validateOverridesCommand.d.ts +2 -2
- package/dist/esm/validateOverridesCommand.js +110 -111
- package/dist/esm/workTypesData.js +57 -60
- package/dist/esm/workTypesUtils.js +16 -21
- package/dist/esm/writeReleaseNotesPreviews.js +55 -57
- package/package.json +2 -2
|
@@ -1,120 +1,125 @@
|
|
|
1
|
-
import { execFileSync } from
|
|
2
|
-
import { basename } from
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
3
|
import { deriveWorkspaceConfig } from "./deriveWorkspaceConfig.js";
|
|
4
4
|
import { detectUndeclaredTagPrefixes } from "./detectUndeclaredTagPrefixes.js";
|
|
5
5
|
import { discoverWorkspaces } from "./discoverWorkspaces.js";
|
|
6
6
|
import { loadConfig } from "./loadConfig.js";
|
|
7
7
|
import { validateConfig } from "./validateConfig.js";
|
|
8
|
-
async function previewTagPrefixes() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
export async function previewTagPrefixes() {
|
|
9
|
+
const workspacePaths = (await discoverWorkspaces()) ?? [];
|
|
10
|
+
const userConfig = await loadUserConfig();
|
|
11
|
+
const overridesByDir = buildOverrideMap(userConfig);
|
|
12
|
+
const workspaces = [];
|
|
13
|
+
for (const workspacePath of workspacePaths) {
|
|
14
|
+
workspaces.push(buildPreviewRow(workspacePath, overridesByDir));
|
|
15
|
+
}
|
|
16
|
+
const retiredPackages = buildRetiredPreviewEntries(userConfig?.retiredPackages ?? []);
|
|
17
|
+
const collisions = detectCollisions(workspaces);
|
|
18
|
+
const knownPrefixes = collectKnownPrefixes(workspaces, retiredPackages);
|
|
19
|
+
const undeclaredCandidates = detectUndeclaredTagPrefixes(knownPrefixes);
|
|
20
|
+
return { workspaces, collisions, undeclaredCandidates, retiredPackages };
|
|
21
21
|
}
|
|
22
22
|
async function loadUserConfig() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
let raw;
|
|
24
|
+
try {
|
|
25
|
+
raw = await loadConfig();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (raw === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
const { config, errors } = validateConfig(raw);
|
|
33
|
+
return errors.length === 0 ? config : undefined;
|
|
32
34
|
}
|
|
33
35
|
function buildOverrideMap(userConfig) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const map = new Map();
|
|
37
|
+
if (userConfig?.workspaces === undefined)
|
|
38
|
+
return map;
|
|
39
|
+
for (const entry of userConfig.workspaces) {
|
|
40
|
+
if (entry.legacyIdentities !== undefined) {
|
|
41
|
+
map.set(entry.dir, entry.legacyIdentities);
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
return map;
|
|
44
|
+
return map;
|
|
42
45
|
}
|
|
43
46
|
function buildPreviewRow(workspacePath, overridesByDir) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
const dir = basename(workspacePath);
|
|
48
|
+
let derivedPrefix = null;
|
|
49
|
+
let derivationError = null;
|
|
50
|
+
try {
|
|
51
|
+
derivedPrefix = deriveWorkspaceConfig(workspacePath).tagPrefix;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
derivationError = error instanceof Error ? error.message : String(error);
|
|
55
|
+
}
|
|
56
|
+
const derivedTagCount = derivedPrefix === null ? 0 : countTagsMatching(derivedPrefix);
|
|
57
|
+
const declaredIdentities = overridesByDir.get(dir) ?? [];
|
|
58
|
+
const legacyEntries = declaredIdentities.map((identity) => ({
|
|
59
|
+
prefix: identity.tagPrefix,
|
|
60
|
+
tagCount: countTagsMatching(identity.tagPrefix),
|
|
61
|
+
}));
|
|
62
|
+
return {
|
|
63
|
+
workspacePath,
|
|
64
|
+
dir,
|
|
65
|
+
derivedPrefix,
|
|
66
|
+
derivationError,
|
|
67
|
+
derivedTagCount,
|
|
68
|
+
legacyEntries,
|
|
69
|
+
};
|
|
66
70
|
}
|
|
67
71
|
function countTagsMatching(prefix) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
try {
|
|
73
|
+
const output = execFileSync('git', ['tag', '--list', `${prefix}*`], {
|
|
74
|
+
encoding: 'utf8',
|
|
75
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
76
|
+
});
|
|
77
|
+
return output.split('\n').filter((line) => line.trim() !== '').length;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
77
82
|
}
|
|
78
83
|
function detectCollisions(rows) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const pathsByPrefix = new Map();
|
|
85
|
+
for (const row of rows) {
|
|
86
|
+
if (row.derivedPrefix === null)
|
|
87
|
+
continue;
|
|
88
|
+
const existing = pathsByPrefix.get(row.derivedPrefix);
|
|
89
|
+
if (existing === undefined) {
|
|
90
|
+
pathsByPrefix.set(row.derivedPrefix, [row.workspacePath]);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
existing.push(row.workspacePath);
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
const collisions = [];
|
|
97
|
+
for (const [tagPrefix, workspacePaths] of pathsByPrefix) {
|
|
98
|
+
if (workspacePaths.length > 1) {
|
|
99
|
+
collisions.push({ tagPrefix, workspacePaths });
|
|
100
|
+
}
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
return collisions;
|
|
102
|
+
return collisions;
|
|
96
103
|
}
|
|
97
104
|
function collectKnownPrefixes(rows, retiredPackages) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
const known = new Set();
|
|
106
|
+
for (const row of rows) {
|
|
107
|
+
if (row.derivedPrefix !== null)
|
|
108
|
+
known.add(row.derivedPrefix);
|
|
109
|
+
for (const entry of row.legacyEntries) {
|
|
110
|
+
known.add(entry.prefix);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const retired of retiredPackages) {
|
|
114
|
+
known.add(retired.tagPrefix);
|
|
103
115
|
}
|
|
104
|
-
|
|
105
|
-
for (const retired of retiredPackages) {
|
|
106
|
-
known.add(retired.tagPrefix);
|
|
107
|
-
}
|
|
108
|
-
return [...known];
|
|
116
|
+
return [...known];
|
|
109
117
|
}
|
|
110
118
|
function buildRetiredPreviewEntries(retiredPackages) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
return retiredPackages.map((retired) => ({
|
|
120
|
+
name: retired.name,
|
|
121
|
+
tagPrefix: retired.tagPrefix,
|
|
122
|
+
tagCount: countTagsMatching(retired.tagPrefix),
|
|
123
|
+
...(retired.successor !== undefined ? { successor: retired.successor } : {}),
|
|
124
|
+
}));
|
|
117
125
|
}
|
|
118
|
-
export {
|
|
119
|
-
previewTagPrefixes
|
|
120
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DependencyGraph } from './buildDependencyGraph.
|
|
2
|
-
import type { PropagationSource, ReleaseType } from './types.
|
|
1
|
+
import type { DependencyGraph } from './buildDependencyGraph.js';
|
|
2
|
+
import type { PropagationSource, ReleaseType } from './types.js';
|
|
3
3
|
export interface ReleaseEntry {
|
|
4
4
|
releaseType: ReleaseType;
|
|
5
5
|
propagatedFrom?: PropagationSource[];
|
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
import { bumpVersion } from "./bumpVersion.js";
|
|
2
|
-
function propagateBumps(directBumps, graph, currentVersions) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
const queue = [...directBumps.keys()];
|
|
8
|
-
const visited = /* @__PURE__ */ new Set();
|
|
9
|
-
while (queue.length > 0) {
|
|
10
|
-
const dir = queue.shift();
|
|
11
|
-
if (dir === void 0) {
|
|
12
|
-
break;
|
|
2
|
+
export function propagateBumps(directBumps, graph, currentVersions) {
|
|
3
|
+
const result = new Map();
|
|
4
|
+
for (const [dir, entry] of directBumps) {
|
|
5
|
+
result.set(dir, { ...entry });
|
|
13
6
|
}
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const queue = [...directBumps.keys()];
|
|
8
|
+
const visited = new Set();
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
const dir = queue.shift();
|
|
11
|
+
if (dir === undefined) {
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
if (visited.has(dir)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
visited.add(dir);
|
|
18
|
+
const packageName = graph.dirToPackageName.get(dir);
|
|
19
|
+
if (packageName === undefined) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const currentVersion = currentVersions.get(dir);
|
|
23
|
+
const entry = result.get(dir);
|
|
24
|
+
if (currentVersion === undefined || entry === undefined) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const newVersion = entry.newVersionOverride ?? bumpVersion(currentVersion, entry.releaseType);
|
|
28
|
+
const dependents = graph.dependentsOf.get(packageName);
|
|
29
|
+
if (dependents === undefined) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
for (const dependent of dependents) {
|
|
33
|
+
const dependentDir = dependent.dir;
|
|
34
|
+
const existing = result.get(dependentDir);
|
|
35
|
+
const propagationInfo = { packageName, newVersion };
|
|
36
|
+
if (existing === undefined) {
|
|
37
|
+
result.set(dependentDir, {
|
|
38
|
+
releaseType: 'patch',
|
|
39
|
+
propagatedFrom: [propagationInfo],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const existingPropagated = existing.propagatedFrom ?? [];
|
|
44
|
+
existing.propagatedFrom = [...existingPropagated, propagationInfo];
|
|
45
|
+
}
|
|
46
|
+
if (!visited.has(dependentDir)) {
|
|
47
|
+
queue.push(dependentDir);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
16
50
|
}
|
|
17
|
-
|
|
18
|
-
const packageName = graph.dirToPackageName.get(dir);
|
|
19
|
-
if (packageName === void 0) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
const currentVersion = currentVersions.get(dir);
|
|
23
|
-
const entry = result.get(dir);
|
|
24
|
-
if (currentVersion === void 0 || entry === void 0) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const newVersion = entry.newVersionOverride ?? bumpVersion(currentVersion, entry.releaseType);
|
|
28
|
-
const dependents = graph.dependentsOf.get(packageName);
|
|
29
|
-
if (dependents === void 0) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
for (const dependent of dependents) {
|
|
33
|
-
const dependentDir = dependent.dir;
|
|
34
|
-
const existing = result.get(dependentDir);
|
|
35
|
-
const propagationInfo = { packageName, newVersion };
|
|
36
|
-
if (existing === void 0) {
|
|
37
|
-
result.set(dependentDir, {
|
|
38
|
-
releaseType: "patch",
|
|
39
|
-
propagatedFrom: [propagationInfo]
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
const existingPropagated = existing.propagatedFrom ?? [];
|
|
43
|
-
existing.propagatedFrom = [...existingPropagated, propagationInfo];
|
|
44
|
-
}
|
|
45
|
-
if (!visited.has(dependentDir)) {
|
|
46
|
-
queue.push(dependentDir);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
+
return result;
|
|
51
52
|
}
|
|
52
|
-
export {
|
|
53
|
-
propagateBumps
|
|
54
|
-
};
|
package/dist/esm/publish.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PackageManager } from './detectPackageManager.
|
|
2
|
-
import type { ResolvedTag } from './resolveReleaseTags.
|
|
1
|
+
import type { PackageManager } from './detectPackageManager.js';
|
|
2
|
+
import type { ResolvedTag } from './resolveReleaseTags.js';
|
|
3
3
|
export interface PublishOptions {
|
|
4
4
|
dryRun: boolean;
|
|
5
5
|
provenance: boolean;
|
package/dist/esm/publish.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
import { execFileSync } from
|
|
2
|
-
function publishPackage(resolvedTag, packageManager, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
${dryRun ? "[dry-run] " : ""}Running: ${executable} ${args.join(" ")} (cwd: ${resolvedTag.workspacePath})`
|
|
9
|
-
);
|
|
10
|
-
execFileSync(executable, args, { cwd: resolvedTag.workspacePath, stdio: "inherit" });
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
export function publishPackage(resolvedTag, packageManager, options) {
|
|
3
|
+
const { dryRun, provenance } = options;
|
|
4
|
+
const executable = resolveExecutable(packageManager);
|
|
5
|
+
const args = buildPublishArgs(packageManager, { dryRun, provenance });
|
|
6
|
+
console.info(`\n${dryRun ? '[dry-run] ' : ''}Running: ${executable} ${args.join(' ')} (cwd: ${resolvedTag.workspacePath})`);
|
|
7
|
+
execFileSync(executable, args, { cwd: resolvedTag.workspacePath, stdio: 'inherit' });
|
|
11
8
|
}
|
|
12
9
|
function resolveExecutable(packageManager) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
if (packageManager === 'yarn-berry') {
|
|
11
|
+
return 'yarn';
|
|
12
|
+
}
|
|
13
|
+
return packageManager;
|
|
17
14
|
}
|
|
18
15
|
function buildPublishArgs(packageManager, options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const args = packageManager === 'yarn-berry' ? ['npm', 'publish'] : ['publish'];
|
|
17
|
+
if (options.dryRun) {
|
|
18
|
+
args.push('--dry-run');
|
|
19
|
+
}
|
|
20
|
+
if (packageManager === 'pnpm') {
|
|
21
|
+
args.push('--no-git-checks');
|
|
22
|
+
}
|
|
23
|
+
if (options.provenance && packageManager !== 'yarn') {
|
|
24
|
+
args.push('--provenance');
|
|
25
|
+
}
|
|
26
|
+
return args;
|
|
30
27
|
}
|
|
31
|
-
export {
|
|
32
|
-
publishPackage
|
|
33
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { writeFileSync } from
|
|
2
|
-
import { join } from
|
|
3
|
-
import { parseArgsOrExit, reportError } from
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parseArgsOrExit, reportError } from '@williamthorsen/nmr-core';
|
|
4
4
|
import { assertCleanWorkingTree } from "./assertCleanWorkingTree.js";
|
|
5
5
|
import { detectPackageManager } from "./detectPackageManager.js";
|
|
6
6
|
import { injectReleaseNotesIntoReadme, resolveReadmePath } from "./injectReleaseNotesIntoReadme.js";
|
|
@@ -9,89 +9,84 @@ import { publishPackage } from "./publish.js";
|
|
|
9
9
|
import { resolveCommandTags } from "./resolveCommandTags.js";
|
|
10
10
|
import { resolveReleaseNotesConfig } from "./resolveReleaseNotesConfig.js";
|
|
11
11
|
const publishFlagSchema = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
dryRun: { long: '--dry-run', type: 'boolean' },
|
|
13
|
+
noGitChecks: { long: '--no-git-checks', type: 'boolean' },
|
|
14
|
+
provenance: { long: '--provenance', type: 'boolean' },
|
|
15
|
+
tags: { long: '--tags', type: 'string' },
|
|
16
16
|
};
|
|
17
|
-
async function publishCommand(argv) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const requestedTags = parseRequestedTags(parsed.flags.tags);
|
|
29
|
-
const resolvedTags = await resolveCommandTags(requestedTags);
|
|
30
|
-
if (resolvedTags.length === 0) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const publishableTags = filterPublishableTags(resolvedTags, requestedTags !== void 0);
|
|
34
|
-
if (publishableTags.length === 0) {
|
|
35
|
-
console.info("Nothing to publish.");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const packageManager = detectPackageManager();
|
|
39
|
-
const { releaseNotes, changelogJsonOutputPath, sectionOrder } = await resolveReleaseNotesConfig();
|
|
40
|
-
const shouldInject = releaseNotes.shouldInjectIntoReadme;
|
|
41
|
-
console.info(dryRun ? "[dry-run] Would publish:" : "Publishing:");
|
|
42
|
-
for (const { tag, workspacePath } of publishableTags) {
|
|
43
|
-
console.info(` ${tag} (${workspacePath})`);
|
|
44
|
-
}
|
|
45
|
-
const published = [];
|
|
46
|
-
try {
|
|
47
|
-
for (const resolvedTag of publishableTags) {
|
|
48
|
-
let readmePath;
|
|
49
|
-
let originalReadme;
|
|
50
|
-
if (shouldInject) {
|
|
51
|
-
readmePath = resolveReadmePath(resolvedTag.workspacePath);
|
|
52
|
-
if (readmePath !== void 0) {
|
|
53
|
-
originalReadme = injectReleaseNotesIntoReadme(
|
|
54
|
-
readmePath,
|
|
55
|
-
join(resolvedTag.workspacePath, changelogJsonOutputPath),
|
|
56
|
-
resolvedTag.tag,
|
|
57
|
-
sectionOrder
|
|
58
|
-
);
|
|
17
|
+
export async function publishCommand(argv) {
|
|
18
|
+
const parsed = parseArgsOrExit(argv, publishFlagSchema);
|
|
19
|
+
const { dryRun, noGitChecks, provenance } = parsed.flags;
|
|
20
|
+
if (!dryRun && !noGitChecks) {
|
|
21
|
+
try {
|
|
22
|
+
assertCleanWorkingTree();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
reportError(error instanceof Error ? error.message : String(error));
|
|
26
|
+
process.exit(1);
|
|
59
27
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
28
|
+
}
|
|
29
|
+
const requestedTags = parseRequestedTags(parsed.flags.tags);
|
|
30
|
+
const resolvedTags = await resolveCommandTags(requestedTags);
|
|
31
|
+
if (resolvedTags.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const publishableTags = filterPublishableTags(resolvedTags, requestedTags !== undefined);
|
|
35
|
+
if (publishableTags.length === 0) {
|
|
36
|
+
console.info('Nothing to publish.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const packageManager = detectPackageManager();
|
|
40
|
+
const { releaseNotes, changelogJsonOutputPath, sectionOrder } = await resolveReleaseNotesConfig();
|
|
41
|
+
const shouldInject = releaseNotes.shouldInjectIntoReadme;
|
|
42
|
+
console.info(dryRun ? '[dry-run] Would publish:' : 'Publishing:');
|
|
43
|
+
for (const { tag, workspacePath } of publishableTags) {
|
|
44
|
+
console.info(` ${tag} (${workspacePath})`);
|
|
45
|
+
}
|
|
46
|
+
const published = [];
|
|
47
|
+
try {
|
|
48
|
+
for (const resolvedTag of publishableTags) {
|
|
49
|
+
let readmePath;
|
|
50
|
+
let originalReadme;
|
|
51
|
+
if (shouldInject) {
|
|
52
|
+
readmePath = resolveReadmePath(resolvedTag.workspacePath);
|
|
53
|
+
if (readmePath !== undefined) {
|
|
54
|
+
originalReadme = injectReleaseNotesIntoReadme(readmePath, join(resolvedTag.workspacePath, changelogJsonOutputPath), resolvedTag.tag, sectionOrder);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
publishPackage(resolvedTag, packageManager, { dryRun, provenance });
|
|
59
|
+
published.push(resolvedTag.tag);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (readmePath !== undefined && originalReadme !== undefined) {
|
|
63
|
+
writeFileSync(readmePath, originalReadme, 'utf8');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
67
66
|
}
|
|
68
|
-
}
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (published.length > 0) {
|
|
70
|
+
console.warn('Packages published before failure:');
|
|
71
|
+
for (const t of published) {
|
|
72
|
+
console.warn(` ${t}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
reportError(error instanceof Error ? error.message : String(error));
|
|
76
|
+
process.exit(1);
|
|
76
77
|
}
|
|
77
|
-
reportError(error instanceof Error ? error.message : String(error));
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
78
|
}
|
|
81
79
|
function filterPublishableTags(resolvedTags, isExplicit) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (isExplicit && unpublishable.length > 0) {
|
|
88
|
-
for (const { tag, workspacePath } of unpublishable) {
|
|
89
|
-
reportError(`${tag} (${workspacePath}) cannot be published: package.json#private is true.`);
|
|
80
|
+
const publishable = [];
|
|
81
|
+
const unpublishable = [];
|
|
82
|
+
for (const tag of resolvedTags) {
|
|
83
|
+
(tag.isPublishable ? publishable : unpublishable).push(tag);
|
|
90
84
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
if (isExplicit && unpublishable.length > 0) {
|
|
86
|
+
for (const { tag, workspacePath } of unpublishable) {
|
|
87
|
+
reportError(`${tag} (${workspacePath}) cannot be published: package.json#private is true.`);
|
|
88
|
+
}
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
return publishable;
|
|
94
92
|
}
|
|
95
|
-
export {
|
|
96
|
-
publishCommand
|
|
97
|
-
};
|
package/dist/esm/pushCommand.js
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { parseArgsOrExit, reportError } from
|
|
1
|
+
import { parseArgsOrExit, reportError } from '@williamthorsen/nmr-core';
|
|
2
2
|
import { parseRequestedTags } from "./parseRequestedTags.js";
|
|
3
3
|
import { pushRelease } from "./pushRelease.js";
|
|
4
4
|
import { resolveCommandTags } from "./resolveCommandTags.js";
|
|
5
5
|
const pushFlagSchema = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
dryRun: { long: '--dry-run', type: 'boolean' },
|
|
7
|
+
tags: { long: '--tags', type: 'string' },
|
|
8
|
+
tagsOnly: { long: '--tags-only', type: 'boolean' },
|
|
9
9
|
};
|
|
10
|
-
async function pushCommand(argv) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
export async function pushCommand(argv) {
|
|
11
|
+
const parsed = parseArgsOrExit(argv, pushFlagSchema);
|
|
12
|
+
const { dryRun, tagsOnly } = parsed.flags;
|
|
13
|
+
const requestedTags = parseRequestedTags(parsed.flags.tags);
|
|
14
|
+
const resolvedTags = await resolveCommandTags(requestedTags);
|
|
15
|
+
if (resolvedTags.length === 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const prefix = dryRun ? '[dry-run] Would push' : 'Pushing';
|
|
19
|
+
if (!tagsOnly) {
|
|
20
|
+
console.info(`${prefix} branch and ${resolvedTags.length} tag(s):`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.info(`${prefix} ${resolvedTags.length} tag(s):`);
|
|
24
|
+
}
|
|
25
|
+
for (const { tag } of resolvedTags) {
|
|
26
|
+
console.info(` ${tag}`);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const steps = pushRelease(resolvedTags, { dryRun, tagsOnly });
|
|
30
|
+
if (dryRun) {
|
|
31
|
+
for (const step of steps) {
|
|
32
|
+
console.info(`[dry-run] ${step.command.join(' ')}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
reportError(error instanceof Error ? error.message : String(error));
|
|
38
|
+
process.exit(1);
|
|
33
39
|
}
|
|
34
|
-
} catch (error) {
|
|
35
|
-
reportError(error instanceof Error ? error.message : String(error));
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
40
|
}
|
|
39
|
-
export {
|
|
40
|
-
pushCommand
|
|
41
|
-
};
|