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