@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,5 +1,5 @@
1
- import type { ReleasePrepareOptions } from './releasePrepare.ts';
2
- import type { ChangelogOverride, MonorepoReleaseConfig, ProjectPrepareResult } from './types.ts';
1
+ import type { ReleasePrepareOptions } from './releasePrepare.js';
2
+ import type { ChangelogOverride, MonorepoReleaseConfig, ProjectPrepareResult } from './types.js';
3
3
  export interface ReleasePrepareProjectArgs {
4
4
  config: MonorepoReleaseConfig;
5
5
  options: ReleasePrepareOptions;
@@ -11,167 +11,157 @@ import { getCommitsSinceTarget } from "./getCommitsSinceTarget.js";
11
11
  import { writeChangelogMarkdown } from "./renderChangelogMarkdown.js";
12
12
  import { deriveSectionOrder } from "./resolveReleaseNotesConfig.js";
13
13
  import { writeReleaseNotesPreviews } from "./writeReleaseNotesPreviews.js";
14
- const ROOT_PACKAGE_FILE = "./package.json";
15
- const ROOT_CHANGELOG_PATH = ".";
16
- function releasePrepareProject(args) {
17
- const { config, options, modifiedFiles, tags } = args;
18
- const { rootOverrides, overrideWarnings, globalMatchedRootKeys } = resolveOptionalOverrideArgs(args);
19
- const { dryRun, bumpOverride, withReleaseNotes, force } = options;
20
- const project = config.project;
21
- if (project === void 0) {
22
- throw new Error("releasePrepareProject called without a configured project block");
23
- }
24
- const workTypes = config.workTypes ?? { ...DEFAULT_WORK_TYPES };
25
- const versionPatterns = config.versionPatterns ?? { ...DEFAULT_VERSION_PATTERNS };
26
- const breakingPolicies = config.breakingPolicies ?? DEFAULT_BREAKING_POLICIES;
27
- const contributingPaths = config.workspaces.flatMap((workspace) => workspace.paths);
28
- const { tag, commits } = getCommitsSinceTarget([project.tagPrefix], contributingPaths);
29
- const since = tag === void 0 ? "(no previous release found)" : `since ${tag}`;
30
- const collector = createPolicyViolationCollector();
31
- const decision = decideRelease({
32
- commits,
33
- force,
34
- bumpOverride,
35
- workTypes,
36
- versionPatterns,
37
- scopeAliases: config.scopeAliases,
38
- breakingPolicies,
39
- onPolicyViolation: collector.onPolicyViolation,
40
- skipReasons: {
41
- noCommits: `No commits ${since}. Pass --force to release at patch. Skipping.`,
42
- noBumpWorthy: `No bump-worthy commits ${since}. Pass --force to release at patch (or --force --bump=X for a different level). Skipping.`
14
+ const ROOT_PACKAGE_FILE = './package.json';
15
+ const ROOT_CHANGELOG_PATH = '.';
16
+ export function releasePrepareProject(args) {
17
+ const { config, options, modifiedFiles, tags } = args;
18
+ const { rootOverrides, overrideWarnings, globalMatchedRootKeys } = resolveOptionalOverrideArgs(args);
19
+ const { dryRun, bumpOverride, withReleaseNotes, force } = options;
20
+ const project = config.project;
21
+ if (project === undefined) {
22
+ throw new Error('releasePrepareProject called without a configured project block');
43
23
  }
44
- });
45
- const policyViolations = collector.violations.length > 0 ? collector.violations : void 0;
46
- if (decision.outcome === "skip") {
47
- const skipped = {
48
- status: "skipped",
49
- commitCount: commits.length,
50
- parsedCommitCount: decision.parsedCommitCount,
51
- skipReason: decision.skipReason
24
+ const workTypes = config.workTypes ?? { ...DEFAULT_WORK_TYPES };
25
+ const versionPatterns = config.versionPatterns ?? { ...DEFAULT_VERSION_PATTERNS };
26
+ const breakingPolicies = config.breakingPolicies ?? DEFAULT_BREAKING_POLICIES;
27
+ const contributingPaths = config.workspaces.flatMap((workspace) => workspace.paths);
28
+ const { tag, commits } = getCommitsSinceTarget([project.tagPrefix], contributingPaths);
29
+ const since = tag === undefined ? '(no previous release found)' : `since ${tag}`;
30
+ const collector = createPolicyViolationCollector();
31
+ const decision = decideRelease({
32
+ commits,
33
+ force,
34
+ bumpOverride,
35
+ workTypes,
36
+ versionPatterns,
37
+ scopeAliases: config.scopeAliases,
38
+ breakingPolicies,
39
+ onPolicyViolation: collector.onPolicyViolation,
40
+ skipReasons: {
41
+ noCommits: `No commits ${since}. Pass --force to release at patch. Skipping.`,
42
+ noBumpWorthy: `No bump-worthy commits ${since}. Pass --force to release at patch (or --force --bump=X for a different level). Skipping.`,
43
+ },
44
+ });
45
+ const policyViolations = collector.violations.length > 0 ? collector.violations : undefined;
46
+ if (decision.outcome === 'skip') {
47
+ const skipped = {
48
+ status: 'skipped',
49
+ commitCount: commits.length,
50
+ parsedCommitCount: decision.parsedCommitCount,
51
+ skipReason: decision.skipReason,
52
+ };
53
+ if (tag !== undefined) {
54
+ skipped.previousTag = tag;
55
+ }
56
+ if (decision.unparseableCommits !== undefined) {
57
+ skipped.unparseableCommits = decision.unparseableCommits;
58
+ }
59
+ if (policyViolations !== undefined) {
60
+ skipped.policyViolations = policyViolations;
61
+ }
62
+ return skipped;
63
+ }
64
+ const { releaseType, parsedCommitCount, unparseableCommits } = decision;
65
+ const bump = bumpAllVersions([ROOT_PACKAGE_FILE], releaseType, dryRun);
66
+ const newTag = `${project.tagPrefix}${bump.newVersion}`;
67
+ const { changelogFiles, changelogJsonFiles } = writeProjectChangelogs({
68
+ config,
69
+ project,
70
+ commits,
71
+ contributingPaths,
72
+ newTag,
73
+ newVersion: bump.newVersion,
74
+ dryRun,
75
+ rootOverrides,
76
+ overrideWarnings,
77
+ globalMatchedRootKeys,
78
+ });
79
+ const firstChangelogJsonPath = changelogJsonFiles[0];
80
+ if (withReleaseNotes === true && config.changelogJson.enabled && firstChangelogJsonPath !== undefined) {
81
+ const sectionOrder = deriveSectionOrder(workTypes);
82
+ writeReleaseNotesPreviews({
83
+ workspacePath: ROOT_CHANGELOG_PATH,
84
+ tag: newTag,
85
+ changelogJsonPath: firstChangelogJsonPath,
86
+ sectionOrder,
87
+ dryRun,
88
+ });
89
+ }
90
+ tags.push(newTag);
91
+ modifiedFiles.push(ROOT_PACKAGE_FILE, ...changelogFiles, ...changelogJsonFiles);
92
+ const result = {
93
+ status: 'released',
94
+ commitCount: commits.length,
95
+ parsedCommitCount,
96
+ releaseType,
97
+ currentVersion: bump.currentVersion,
98
+ newVersion: bump.newVersion,
99
+ tag: newTag,
100
+ bumpedFiles: bump.files,
101
+ changelogFiles,
102
+ commits,
52
103
  };
53
- if (tag !== void 0) {
54
- skipped.previousTag = tag;
104
+ if (tag !== undefined) {
105
+ result.previousTag = tag;
55
106
  }
56
- if (decision.unparseableCommits !== void 0) {
57
- skipped.unparseableCommits = decision.unparseableCommits;
107
+ if (unparseableCommits !== undefined) {
108
+ result.unparseableCommits = unparseableCommits;
58
109
  }
59
- if (policyViolations !== void 0) {
60
- skipped.policyViolations = policyViolations;
110
+ if (policyViolations !== undefined) {
111
+ result.policyViolations = policyViolations;
61
112
  }
62
- return skipped;
63
- }
64
- const { releaseType, parsedCommitCount, unparseableCommits } = decision;
65
- const bump = bumpAllVersions([ROOT_PACKAGE_FILE], releaseType, dryRun);
66
- const newTag = `${project.tagPrefix}${bump.newVersion}`;
67
- const { changelogFiles, changelogJsonFiles } = writeProjectChangelogs({
68
- config,
69
- project,
70
- commits,
71
- contributingPaths,
72
- newTag,
73
- newVersion: bump.newVersion,
74
- dryRun,
75
- rootOverrides,
76
- overrideWarnings,
77
- globalMatchedRootKeys
78
- });
79
- const firstChangelogJsonPath = changelogJsonFiles[0];
80
- if (withReleaseNotes === true && config.changelogJson.enabled && firstChangelogJsonPath !== void 0) {
81
- const sectionOrder = deriveSectionOrder(workTypes);
82
- writeReleaseNotesPreviews({
83
- workspacePath: ROOT_CHANGELOG_PATH,
84
- tag: newTag,
85
- changelogJsonPath: firstChangelogJsonPath,
86
- sectionOrder,
87
- dryRun
88
- });
89
- }
90
- tags.push(newTag);
91
- modifiedFiles.push(ROOT_PACKAGE_FILE, ...changelogFiles, ...changelogJsonFiles);
92
- const result = {
93
- status: "released",
94
- commitCount: commits.length,
95
- parsedCommitCount,
96
- releaseType,
97
- currentVersion: bump.currentVersion,
98
- newVersion: bump.newVersion,
99
- tag: newTag,
100
- bumpedFiles: bump.files,
101
- changelogFiles,
102
- commits
103
- };
104
- if (tag !== void 0) {
105
- result.previousTag = tag;
106
- }
107
- if (unparseableCommits !== void 0) {
108
- result.unparseableCommits = unparseableCommits;
109
- }
110
- if (policyViolations !== void 0) {
111
- result.policyViolations = policyViolations;
112
- }
113
- if (bumpOverride !== void 0) {
114
- result.bumpOverride = bumpOverride;
115
- }
116
- return result;
113
+ if (bumpOverride !== undefined) {
114
+ result.bumpOverride = bumpOverride;
115
+ }
116
+ return result;
117
117
  }
118
118
  function resolveOptionalOverrideArgs(args) {
119
- return {
120
- rootOverrides: args.rootOverrides ?? /* @__PURE__ */ new Map(),
121
- overrideWarnings: args.overrideWarnings ?? [],
122
- globalMatchedRootKeys: args.globalMatchedRootKeys ?? /* @__PURE__ */ new Set()
123
- };
119
+ return {
120
+ rootOverrides: args.rootOverrides ?? new Map(),
121
+ overrideWarnings: args.overrideWarnings ?? [],
122
+ globalMatchedRootKeys: args.globalMatchedRootKeys ?? new Set(),
123
+ };
124
124
  }
125
125
  function writeProjectChangelogs(args) {
126
- const {
127
- config,
128
- project,
129
- commits,
130
- contributingPaths,
131
- newTag,
132
- newVersion,
133
- dryRun,
134
- rootOverrides,
135
- overrideWarnings,
136
- globalMatchedRootKeys
137
- } = args;
138
- const isEmptyRange = commits.length === 0;
139
- const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
140
- const tagPattern = buildTagPattern([project.tagPrefix]);
141
- const newEntries = isEmptyRange ? [buildEmptyReleaseEntry(newVersion, today)] : buildChangelogEntries(config, newTag, { tagPattern, includePaths: contributingPaths });
142
- const applied = applyChangelogOverrides(newEntries, rootOverrides);
143
- if (applied.errors.length > 0) {
144
- throw new Error(`Changelog override application failed:
145
- - ${applied.errors.join("\n - ")}`);
146
- }
147
- overrideWarnings.push(...applied.warnings);
148
- for (const matched of applied.matchedKeys) {
149
- globalMatchedRootKeys.add(matched);
150
- }
151
- const changelogJsonPath = resolveChangelogJsonPath(config, ROOT_CHANGELOG_PATH);
152
- const sectionOrder = deriveSectionOrder(config.workTypes ?? { ...DEFAULT_WORK_TYPES });
153
- const renderEntries = isEmptyRange ? mergeChangelogEntriesWithDisk(changelogJsonPath, applied.entries) : applied.entries;
154
- if (config.changelogJson.enabled && !dryRun) {
155
- if (isEmptyRange) {
156
- writeChangelogJson(changelogJsonPath, renderEntries);
157
- } else {
158
- writeChangelogJson(changelogJsonPath, applied.entries);
126
+ const { config, project, commits, contributingPaths, newTag, newVersion, dryRun, rootOverrides, overrideWarnings, globalMatchedRootKeys, } = args;
127
+ const isEmptyRange = commits.length === 0;
128
+ const today = new Date().toISOString().slice(0, 10);
129
+ const tagPattern = buildTagPattern([project.tagPrefix]);
130
+ const newEntries = isEmptyRange
131
+ ? [buildEmptyReleaseEntry(newVersion, today)]
132
+ : buildChangelogEntries(config, newTag, { tagPattern, includePaths: contributingPaths });
133
+ const applied = applyChangelogOverrides(newEntries, rootOverrides);
134
+ if (applied.errors.length > 0) {
135
+ throw new Error(`Changelog override application failed:\n - ${applied.errors.join('\n - ')}`);
136
+ }
137
+ overrideWarnings.push(...applied.warnings);
138
+ for (const matched of applied.matchedKeys) {
139
+ globalMatchedRootKeys.add(matched);
140
+ }
141
+ const changelogJsonPath = resolveChangelogJsonPath(config, ROOT_CHANGELOG_PATH);
142
+ const sectionOrder = deriveSectionOrder(config.workTypes ?? { ...DEFAULT_WORK_TYPES });
143
+ const renderEntries = isEmptyRange
144
+ ? mergeChangelogEntriesWithDisk(changelogJsonPath, applied.entries)
145
+ : applied.entries;
146
+ if (config.changelogJson.enabled && !dryRun) {
147
+ if (isEmptyRange) {
148
+ writeChangelogJson(changelogJsonPath, renderEntries);
149
+ }
150
+ else {
151
+ writeChangelogJson(changelogJsonPath, applied.entries);
152
+ }
153
+ }
154
+ const changelogFiles = [
155
+ writeChangelogMarkdown({
156
+ changelogPath: ROOT_CHANGELOG_PATH,
157
+ entries: renderEntries,
158
+ sectionOrder,
159
+ dryRun,
160
+ }),
161
+ ];
162
+ const changelogJsonFiles = [];
163
+ if (config.changelogJson.enabled) {
164
+ changelogJsonFiles.push(changelogJsonPath);
159
165
  }
160
- }
161
- const changelogFiles = [
162
- writeChangelogMarkdown({
163
- changelogPath: ROOT_CHANGELOG_PATH,
164
- entries: renderEntries,
165
- sectionOrder,
166
- dryRun
167
- })
168
- ];
169
- const changelogJsonFiles = [];
170
- if (config.changelogJson.enabled) {
171
- changelogJsonFiles.push(changelogJsonPath);
172
- }
173
- return { changelogFiles, changelogJsonFiles };
166
+ return { changelogFiles, changelogJsonFiles };
174
167
  }
175
- export {
176
- releasePrepareProject
177
- };
@@ -1,4 +1,4 @@
1
- import type { ChangelogEntry } from './types.ts';
1
+ import type { ChangelogEntry } from './types.js';
2
2
  export interface RenderChangelogMarkdownOptions {
3
3
  sectionOrder?: string[];
4
4
  }
@@ -1,32 +1,28 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
2
- import { dirname, join as joinPath } from "node:path";
1
+ import { mkdirSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join as joinPath } from 'node:path';
3
3
  import { renderReleaseNotesMulti } from "./renderReleaseNotes.js";
4
4
  const CHANGELOG_HEADER = `# Changelog
5
5
 
6
6
  All notable changes to this project will be documented in this file.`;
7
7
  const CHANGELOG_FOOTER = `<!-- Generated by release-kit. Do not edit this file. Use .meta/changelog-overrides.json to override entries. -->`;
8
- function renderChangelogMarkdown(entries, options) {
9
- const body = renderReleaseNotesMulti(entries, options);
10
- const trimmedBody = body.trimEnd();
11
- const parts = [CHANGELOG_HEADER];
12
- if (trimmedBody.length > 0) {
13
- parts.push(trimmedBody);
14
- }
15
- parts.push(CHANGELOG_FOOTER);
16
- return parts.join("\n\n") + "\n";
8
+ export function renderChangelogMarkdown(entries, options) {
9
+ const body = renderReleaseNotesMulti(entries, options);
10
+ const trimmedBody = body.trimEnd();
11
+ const parts = [CHANGELOG_HEADER];
12
+ if (trimmedBody.length > 0) {
13
+ parts.push(trimmedBody);
14
+ }
15
+ parts.push(CHANGELOG_FOOTER);
16
+ return parts.join('\n\n') + '\n';
17
17
  }
18
- function writeChangelogMarkdown(params) {
19
- const { changelogPath, entries, sectionOrder, dryRun = false } = params;
20
- const filePath = joinPath(changelogPath, "CHANGELOG.md");
21
- if (dryRun) {
18
+ export function writeChangelogMarkdown(params) {
19
+ const { changelogPath, entries, sectionOrder, dryRun = false } = params;
20
+ const filePath = joinPath(changelogPath, 'CHANGELOG.md');
21
+ if (dryRun) {
22
+ return filePath;
23
+ }
24
+ const rendered = renderChangelogMarkdown(entries, sectionOrder !== undefined ? { sectionOrder } : undefined);
25
+ mkdirSync(dirname(filePath), { recursive: true });
26
+ writeFileSync(filePath, rendered, 'utf8');
22
27
  return filePath;
23
- }
24
- const rendered = renderChangelogMarkdown(entries, sectionOrder !== void 0 ? { sectionOrder } : void 0);
25
- mkdirSync(dirname(filePath), { recursive: true });
26
- writeFileSync(filePath, rendered, "utf8");
27
- return filePath;
28
28
  }
29
- export {
30
- renderChangelogMarkdown,
31
- writeChangelogMarkdown
32
- };
@@ -1,4 +1,4 @@
1
- import type { ChangelogAudience, ChangelogEntry, ChangelogSection } from './types.ts';
1
+ import type { ChangelogAudience, ChangelogEntry, ChangelogSection } from './types.js';
2
2
  export interface RenderOptions {
3
3
  filter?: (section: ChangelogSection) => boolean;
4
4
  includeHeading?: boolean;
@@ -1,73 +1,68 @@
1
1
  import { WORK_TYPES_DATA } from "./workTypesData.js";
2
2
  function getBreakingPrefix() {
3
- const { emoji, label } = WORK_TYPES_DATA.markers.breaking;
4
- return `${emoji} **${label}:** `;
3
+ const { emoji, label } = WORK_TYPES_DATA.markers.breaking;
4
+ return `${emoji} **${label}:** `;
5
5
  }
6
6
  function allSections() {
7
- return true;
7
+ return true;
8
8
  }
9
9
  function publicSections(section) {
10
- return section.audience === "all";
10
+ return section.audience === 'all';
11
11
  }
12
- function matchesAudience(audience) {
13
- return audience === "dev" ? allSections : publicSections;
12
+ export function matchesAudience(audience) {
13
+ return audience === 'dev' ? allSections : publicSections;
14
14
  }
15
- function renderReleaseNotesSingle(entry, options) {
16
- const filter = options?.filter;
17
- const includeHeading = options?.includeHeading ?? true;
18
- const sectionOrder = options?.sectionOrder;
19
- const filtered = filter !== void 0 ? entry.sections.filter(filter) : entry.sections;
20
- const sections = sectionOrder !== void 0 ? sortSectionsByOrder(filtered, sectionOrder) : filtered;
21
- if (sections.length === 0) {
22
- return "";
23
- }
24
- const lines = [];
25
- if (includeHeading) {
26
- lines.push(`## ${entry.version} \u2014 ${entry.date}`);
27
- }
28
- for (const section of sections) {
29
- if (lines.length > 0) {
30
- lines.push("");
15
+ export function renderReleaseNotesSingle(entry, options) {
16
+ const filter = options?.filter;
17
+ const includeHeading = options?.includeHeading ?? true;
18
+ const sectionOrder = options?.sectionOrder;
19
+ const filtered = filter !== undefined ? entry.sections.filter(filter) : entry.sections;
20
+ const sections = sectionOrder !== undefined ? sortSectionsByOrder(filtered, sectionOrder) : filtered;
21
+ if (sections.length === 0) {
22
+ return '';
31
23
  }
32
- lines.push(`### ${section.title}`, "");
33
- for (const [index, item] of section.items.entries()) {
34
- const prefix = item.breaking === true ? getBreakingPrefix() : "";
35
- lines.push(`- ${prefix}${item.description}`);
36
- if (item.body !== void 0 && item.body.length > 0) {
37
- lines.push("", ...indentBodyLines(item.body));
38
- if (index < section.items.length - 1) {
39
- lines.push("");
24
+ const lines = [];
25
+ if (includeHeading) {
26
+ lines.push(`## ${entry.version} — ${entry.date}`);
27
+ }
28
+ for (const section of sections) {
29
+ if (lines.length > 0) {
30
+ lines.push('');
31
+ }
32
+ lines.push(`### ${section.title}`, '');
33
+ for (const [index, item] of section.items.entries()) {
34
+ const prefix = item.breaking === true ? getBreakingPrefix() : '';
35
+ lines.push(`- ${prefix}${item.description}`);
36
+ if (item.body !== undefined && item.body.length > 0) {
37
+ lines.push('', ...indentBodyLines(item.body));
38
+ if (index < section.items.length - 1) {
39
+ lines.push('');
40
+ }
41
+ }
40
42
  }
41
- }
42
43
  }
43
- }
44
- return lines.join("\n") + "\n";
44
+ return lines.join('\n') + '\n';
45
45
  }
46
46
  function sortSectionsByOrder(sections, order) {
47
- const priority = /* @__PURE__ */ new Map();
48
- for (const [index, title] of order.entries()) {
49
- priority.set(title, index);
50
- }
51
- const indexed = sections.map((section, index) => ({ section, index }));
52
- indexed.sort((a, b) => {
53
- const priorityA = priority.get(a.section.title) ?? Number.POSITIVE_INFINITY;
54
- const priorityB = priority.get(b.section.title) ?? Number.POSITIVE_INFINITY;
55
- if (priorityA !== priorityB) {
56
- return priorityA - priorityB;
47
+ const priority = new Map();
48
+ for (const [index, title] of order.entries()) {
49
+ priority.set(title, index);
57
50
  }
58
- return a.index - b.index;
59
- });
60
- return indexed.map(({ section }) => section);
51
+ const indexed = sections.map((section, index) => ({ section, index }));
52
+ indexed.sort((a, b) => {
53
+ const priorityA = priority.get(a.section.title) ?? Number.POSITIVE_INFINITY;
54
+ const priorityB = priority.get(b.section.title) ?? Number.POSITIVE_INFINITY;
55
+ if (priorityA !== priorityB) {
56
+ return priorityA - priorityB;
57
+ }
58
+ return a.index - b.index;
59
+ });
60
+ return indexed.map(({ section }) => section);
61
61
  }
62
62
  function indentBodyLines(body) {
63
- return body.split("\n").map((line) => line.length === 0 ? "" : ` ${line}`);
63
+ return body.split('\n').map((line) => (line.length === 0 ? '' : ` ${line}`));
64
64
  }
65
- function renderReleaseNotesMulti(entries, options) {
66
- const parts = entries.map((entry) => renderReleaseNotesSingle(entry, options)).filter((part) => part.length > 0);
67
- return parts.join("\n");
65
+ export function renderReleaseNotesMulti(entries, options) {
66
+ const parts = entries.map((entry) => renderReleaseNotesSingle(entry, options)).filter((part) => part.length > 0);
67
+ return parts.join('\n');
68
68
  }
69
- export {
70
- matchesAudience,
71
- renderReleaseNotesMulti,
72
- renderReleaseNotesSingle
73
- };
@@ -1,2 +1,2 @@
1
- import type { PrepareResult } from './types.ts';
1
+ import type { PrepareResult } from './types.js';
2
2
  export declare function reportPrepare(result: PrepareResult): string;