@williamthorsen/release-kit 2.3.1 → 4.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 (43) hide show
  1. package/CHANGELOG.md +61 -37
  2. package/README.md +29 -12
  3. package/cliff.toml.template +16 -13
  4. package/dist/esm/.cache +1 -1
  5. package/dist/esm/bin/release-kit.js +28 -0
  6. package/dist/esm/buildDependencyGraph.d.ts +7 -0
  7. package/dist/esm/buildDependencyGraph.js +59 -0
  8. package/dist/esm/buildReleaseSummary.d.ts +2 -0
  9. package/dist/esm/buildReleaseSummary.js +22 -0
  10. package/dist/esm/commitCommand.d.ts +1 -0
  11. package/dist/esm/commitCommand.js +55 -0
  12. package/dist/esm/createTags.js +12 -1
  13. package/dist/esm/determineBumpFromCommits.d.ts +7 -0
  14. package/dist/esm/determineBumpFromCommits.js +26 -0
  15. package/dist/esm/generateChangelogs.d.ts +2 -0
  16. package/dist/esm/generateChangelogs.js +9 -1
  17. package/dist/esm/index.d.ts +5 -2
  18. package/dist/esm/index.js +10 -2
  19. package/dist/esm/init/initCommand.js +4 -2
  20. package/dist/esm/init/scaffold.js +3 -2
  21. package/dist/esm/init/templates.d.ts +1 -0
  22. package/dist/esm/init/templates.js +24 -2
  23. package/dist/esm/loadConfig.js +6 -6
  24. package/dist/esm/parseCommitMessage.d.ts +2 -1
  25. package/dist/esm/parseCommitMessage.js +19 -7
  26. package/dist/esm/prepareCommand.d.ts +1 -0
  27. package/dist/esm/prepareCommand.js +20 -0
  28. package/dist/esm/propagateBumps.d.ts +8 -0
  29. package/dist/esm/propagateBumps.js +54 -0
  30. package/dist/esm/publish.d.ts +1 -0
  31. package/dist/esm/publish.js +6 -3
  32. package/dist/esm/publishCommand.js +3 -2
  33. package/dist/esm/releasePrepare.js +10 -6
  34. package/dist/esm/releasePrepareMono.js +244 -52
  35. package/dist/esm/reportPrepare.js +46 -3
  36. package/dist/esm/stripScope.d.ts +1 -0
  37. package/dist/esm/stripScope.js +24 -0
  38. package/dist/esm/sync-labels/templates.js +1 -1
  39. package/dist/esm/types.d.ts +12 -4
  40. package/dist/esm/validateConfig.js +6 -6
  41. package/dist/esm/writeSyntheticChangelog.d.ts +9 -0
  42. package/dist/esm/writeSyntheticChangelog.js +27 -0
  43. package/package.json +1 -1
@@ -56,8 +56,10 @@ function initCommand({ dryRun, force, withConfig }) {
56
56
  const configHint = withConfig ? "1. (Optional) Customize .config/release-kit.config.ts and .config/git-cliff.toml." : "1. (Optional) Run again with --with-config to scaffold config files.";
57
57
  console.info(`
58
58
  ${configHint}
59
- 2. Test by running: npx @williamthorsen/release-kit prepare --dry-run
60
- 3. Commit the generated files.
59
+ 2. If this is a public repo, set provenance: true in .github/workflows/publish.yaml.
60
+ 3. Test by running: npx @williamthorsen/release-kit prepare --dry-run
61
+ 4. Commit the generated files.
62
+ 5. Register each package as a trusted publisher on npmjs.com.
61
63
  `);
62
64
  return 0;
63
65
  }
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { writeFileWithCheck } from "@williamthorsen/node-monorepo-core";
4
4
  import { findPackageRoot } from "../findPackageRoot.js";
5
- import { releaseConfigScript, releaseWorkflow } from "./templates.js";
5
+ import { publishWorkflow, releaseConfigScript, releaseWorkflow } from "./templates.js";
6
6
  function copyCliffTemplate(dryRun, overwrite) {
7
7
  const destPath = ".config/git-cliff.toml";
8
8
  const root = findPackageRoot(import.meta.url);
@@ -21,7 +21,8 @@ function copyCliffTemplate(dryRun, overwrite) {
21
21
  }
22
22
  function scaffoldFiles({ repoType, dryRun, overwrite, withConfig }) {
23
23
  const results = [
24
- writeFileWithCheck(".github/workflows/release.yaml", releaseWorkflow(repoType), { dryRun, overwrite })
24
+ writeFileWithCheck(".github/workflows/release.yaml", releaseWorkflow(repoType), { dryRun, overwrite }),
25
+ writeFileWithCheck(".github/workflows/publish.yaml", publishWorkflow(repoType), { dryRun, overwrite })
25
26
  ];
26
27
  if (withConfig) {
27
28
  results.push(
@@ -1,3 +1,4 @@
1
1
  import type { RepoType } from './detectRepoType.ts';
2
2
  export declare function releaseConfigScript(repoType: RepoType): string;
3
+ export declare function publishWorkflow(repoType: RepoType): string;
3
4
  export declare function releaseWorkflow(repoType: RepoType): string;
@@ -35,6 +35,27 @@ const config: ReleaseKitConfig = {
35
35
  export default config;
36
36
  `;
37
37
  }
38
+ function publishWorkflow(repoType) {
39
+ const tagPattern = repoType === "monorepo" ? "'*-v[0-9]*'" : "'v[0-9]*'";
40
+ return `# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
41
+ name: Publish
42
+
43
+ on:
44
+ push:
45
+ tags:
46
+ - ${tagPattern}
47
+
48
+ permissions:
49
+ id-token: write
50
+ contents: read
51
+
52
+ jobs:
53
+ publish:
54
+ uses: williamthorsen/node-monorepo-tools/.github/workflows/publish.reusable.yaml@publish-workflow-v1
55
+ with:
56
+ provenance: false # Set to true for public repos to generate npm provenance attestations
57
+ `;
58
+ }
38
59
  function releaseWorkflow(repoType) {
39
60
  if (repoType === "monorepo") {
40
61
  return `# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
@@ -68,7 +89,7 @@ permissions:
68
89
 
69
90
  jobs:
70
91
  release:
71
- uses: williamthorsen/node-monorepo-tools/.github/workflows/release-workflow.yaml@release-workflow-v1
92
+ uses: williamthorsen/node-monorepo-tools/.github/workflows/release.reusable.yaml@release-workflow-v1
72
93
  with:
73
94
  only: \${{ inputs.only }}
74
95
  bump: \${{ inputs.bump }}
@@ -102,13 +123,14 @@ permissions:
102
123
 
103
124
  jobs:
104
125
  release:
105
- uses: williamthorsen/node-monorepo-tools/.github/workflows/release-workflow.yaml@release-workflow-v1
126
+ uses: williamthorsen/node-monorepo-tools/.github/workflows/release.reusable.yaml@release-workflow-v1
106
127
  with:
107
128
  bump: \${{ inputs.bump }}
108
129
  force: \${{ inputs.force }}
109
130
  `;
110
131
  }
111
132
  export {
133
+ publishWorkflow,
112
134
  releaseConfigScript,
113
135
  releaseWorkflow
114
136
  };
@@ -47,9 +47,9 @@ function mergeMonorepoConfig(discoveredPaths, userConfig) {
47
47
  if (cliffConfigPath !== void 0) {
48
48
  result.cliffConfigPath = cliffConfigPath;
49
49
  }
50
- const workspaceAliases = userConfig?.workspaceAliases;
51
- if (workspaceAliases !== void 0) {
52
- result.workspaceAliases = workspaceAliases;
50
+ const scopeAliases = userConfig?.scopeAliases;
51
+ if (scopeAliases !== void 0) {
52
+ result.scopeAliases = scopeAliases;
53
53
  }
54
54
  return result;
55
55
  }
@@ -71,9 +71,9 @@ function mergeSinglePackageConfig(userConfig) {
71
71
  if (cliffConfigPath !== void 0) {
72
72
  result.cliffConfigPath = cliffConfigPath;
73
73
  }
74
- const workspaceAliases = userConfig?.workspaceAliases;
75
- if (workspaceAliases !== void 0) {
76
- result.workspaceAliases = workspaceAliases;
74
+ const scopeAliases = userConfig?.scopeAliases;
75
+ if (scopeAliases !== void 0) {
76
+ result.scopeAliases = scopeAliases;
77
77
  }
78
78
  return result;
79
79
  }
@@ -1,2 +1,3 @@
1
1
  import type { ParsedCommit, WorkTypeConfig } from './types.ts';
2
- export declare function parseCommitMessage(message: string, hash: string, workTypes: Record<string, WorkTypeConfig>, workspaceAliases?: Record<string, string>): ParsedCommit | undefined;
2
+ export declare const COMMIT_PREPROCESSOR_PATTERNS: readonly RegExp[];
3
+ export declare function parseCommitMessage(message: string, hash: string, workTypes: Record<string, WorkTypeConfig>, scopeAliases?: Record<string, string>): ParsedCommit | undefined;
@@ -1,12 +1,15 @@
1
- function parseCommitMessage(message, hash, workTypes, workspaceAliases) {
2
- const match = message.match(/^(?:([^|]+)\|)?(\w+)(!)?:\s*(.*)$/);
1
+ const COMMIT_PREPROCESSOR_PATTERNS = [/^#\d+\s+/, /^[A-Z]+-\d+\s+/];
2
+ function parseCommitMessage(message, hash, workTypes, scopeAliases) {
3
+ const stripped = stripTicketPrefix(message);
4
+ const match = stripped.match(/^(?:([^|]+)\|)?(\w+)(?:\(([^)]+)\))?(!)?:\s*(.*)$/);
3
5
  if (!match) {
4
6
  return void 0;
5
7
  }
6
- const workspace = match[1];
8
+ const pipeScope = match[1];
7
9
  const rawType = match[2];
8
- const breakingMarker = match[3];
9
- const description = match[4];
10
+ const parenthesizedScope = match[3];
11
+ const breakingMarker = match[4];
12
+ const description = match[5];
10
13
  if (rawType === void 0 || description === void 0) {
11
14
  return void 0;
12
15
  }
@@ -15,14 +18,15 @@ function parseCommitMessage(message, hash, workTypes, workspaceAliases) {
15
18
  return void 0;
16
19
  }
17
20
  const breaking = breakingMarker === "!" || message.includes("BREAKING CHANGE:");
18
- const resolvedWorkspace = workspace !== void 0 && workspaceAliases !== void 0 ? workspaceAliases[workspace] ?? workspace : workspace;
21
+ const rawScope = pipeScope ?? parenthesizedScope;
22
+ const resolvedScope = rawScope !== void 0 && scopeAliases !== void 0 ? scopeAliases[rawScope] ?? rawScope : rawScope;
19
23
  return {
20
24
  message,
21
25
  hash,
22
26
  type: resolvedType,
23
27
  description,
24
28
  breaking,
25
- ...resolvedWorkspace !== void 0 && { workspace: resolvedWorkspace }
29
+ ...resolvedScope !== void 0 && { scope: resolvedScope }
26
30
  };
27
31
  }
28
32
  function resolveType(rawType, workTypes) {
@@ -41,6 +45,14 @@ function resolveType(rawType, workTypes) {
41
45
  }
42
46
  return void 0;
43
47
  }
48
+ function stripTicketPrefix(message) {
49
+ let result = message;
50
+ for (const pattern of COMMIT_PREPROCESSOR_PATTERNS) {
51
+ result = result.replace(pattern, "");
52
+ }
53
+ return result;
54
+ }
44
55
  export {
56
+ COMMIT_PREPROCESSOR_PATTERNS,
45
57
  parseCommitMessage
46
58
  };
@@ -1,6 +1,7 @@
1
1
  import type { WriteResult } from '@williamthorsen/node-monorepo-core';
2
2
  import type { ReleaseType } from './types.ts';
3
3
  export declare const RELEASE_TAGS_FILE = "tmp/.release-tags";
4
+ export declare const RELEASE_SUMMARY_FILE = "tmp/.release-summary";
4
5
  export declare function parseArgs(argv: string[]): {
5
6
  dryRun: boolean;
6
7
  force: boolean;
@@ -1,4 +1,5 @@
1
1
  import { writeFileWithCheck } from "@williamthorsen/node-monorepo-core";
2
+ import { buildReleaseSummary } from "./buildReleaseSummary.js";
2
3
  import { discoverWorkspaces } from "./discoverWorkspaces.js";
3
4
  import { dim } from "./format.js";
4
5
  import { loadConfig, mergeMonorepoConfig, mergeSinglePackageConfig } from "./loadConfig.js";
@@ -7,6 +8,7 @@ import { releasePrepareMono } from "./releasePrepareMono.js";
7
8
  import { reportPrepare } from "./reportPrepare.js";
8
9
  import { validateConfig } from "./validateConfig.js";
9
10
  const RELEASE_TAGS_FILE = "tmp/.release-tags";
11
+ const RELEASE_SUMMARY_FILE = "tmp/.release-summary";
10
12
  const VALID_BUMP_TYPES = ["major", "minor", "patch"];
11
13
  function isReleaseType(value) {
12
14
  return VALID_BUMP_TYPES.includes(value);
@@ -148,8 +150,26 @@ function runAndReport(execute, dryRun) {
148
150
  Release tags file: ${RELEASE_TAGS_FILE}`));
149
151
  }
150
152
  }
153
+ const summary = buildReleaseSummary(result);
154
+ if (summary.length > 0) {
155
+ const summaryResult = writeFileWithCheck(RELEASE_SUMMARY_FILE, summary, { dryRun, overwrite: true });
156
+ if (summaryResult.outcome === "failed") {
157
+ console.error(`Error writing release summary: ${summaryResult.error ?? "unknown error"}`);
158
+ process.exit(1);
159
+ }
160
+ if (dryRun) {
161
+ console.info(dim(` [dry-run] Would write ${RELEASE_SUMMARY_FILE}`));
162
+ } else {
163
+ console.info(dim(` Wrote ${RELEASE_SUMMARY_FILE}`));
164
+ }
165
+ }
166
+ if (writeResult && !dryRun) {
167
+ console.error(`
168
+ Run 'release-kit commit' to create the release commit.`);
169
+ }
151
170
  }
152
171
  export {
172
+ RELEASE_SUMMARY_FILE,
153
173
  RELEASE_TAGS_FILE,
154
174
  parseArgs,
155
175
  prepareCommand,
@@ -0,0 +1,8 @@
1
+ import type { DependencyGraph } from './buildDependencyGraph.ts';
2
+ import type { PropagationSource, ReleaseType } from './types.ts';
3
+ export interface ReleaseEntry {
4
+ releaseType: ReleaseType;
5
+ propagatedFrom?: PropagationSource[];
6
+ }
7
+ export type CurrentVersions = Map<string, string>;
8
+ export declare function propagateBumps(directBumps: Map<string, ReleaseEntry>, graph: DependencyGraph, currentVersions: CurrentVersions): Map<string, ReleaseEntry>;
@@ -0,0 +1,54 @@
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;
13
+ }
14
+ if (visited.has(dir)) {
15
+ continue;
16
+ }
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 = 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
+ }
52
+ export {
53
+ propagateBumps
54
+ };
@@ -3,5 +3,6 @@ import type { ResolvedTag } from './resolveReleaseTags.ts';
3
3
  export interface PublishOptions {
4
4
  dryRun: boolean;
5
5
  noGitChecks: boolean;
6
+ provenance: boolean;
6
7
  }
7
8
  export declare function publish(resolvedTags: ResolvedTag[], packageManager: PackageManager, options: PublishOptions): void;
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  function publish(resolvedTags, packageManager, options) {
3
- const { dryRun, noGitChecks } = options;
3
+ const { dryRun, noGitChecks, provenance } = options;
4
4
  if (resolvedTags.length === 0) {
5
5
  return;
6
6
  }
@@ -9,9 +9,9 @@ function publish(resolvedTags, packageManager, options) {
9
9
  console.info(` ${tag} (${workspacePath})`);
10
10
  }
11
11
  const published = [];
12
+ const executable = resolveExecutable(packageManager);
13
+ const args = buildPublishArgs(packageManager, { dryRun, noGitChecks, provenance });
12
14
  for (const { tag, workspacePath } of resolvedTags) {
13
- const executable = resolveExecutable(packageManager);
14
- const args = buildPublishArgs(packageManager, { dryRun, noGitChecks });
15
15
  try {
16
16
  console.info(`
17
17
  ${dryRun ? "[dry-run] " : ""}Running: ${executable} ${args.join(" ")} (cwd: ${workspacePath})`);
@@ -42,6 +42,9 @@ function buildPublishArgs(packageManager, options) {
42
42
  if (options.noGitChecks && packageManager === "pnpm") {
43
43
  args.push("--no-git-checks");
44
44
  }
45
+ if (options.provenance && packageManager !== "yarn") {
46
+ args.push("--provenance");
47
+ }
45
48
  return args;
46
49
  }
47
50
  export {
@@ -4,7 +4,7 @@ import { discoverWorkspaces } from "./discoverWorkspaces.js";
4
4
  import { publish } from "./publish.js";
5
5
  import { resolveReleaseTags } from "./resolveReleaseTags.js";
6
6
  async function publishCommand(argv) {
7
- const knownFlags = /* @__PURE__ */ new Set(["--dry-run", "--no-git-checks"]);
7
+ const knownFlags = /* @__PURE__ */ new Set(["--dry-run", "--no-git-checks", "--provenance"]);
8
8
  const unknownFlags = argv.filter((f) => !f.startsWith("--only=") && !knownFlags.has(f));
9
9
  if (unknownFlags.length > 0) {
10
10
  console.error(`Error: Unknown option: ${unknownFlags[0]}`);
@@ -12,6 +12,7 @@ async function publishCommand(argv) {
12
12
  }
13
13
  const dryRun = argv.includes("--dry-run");
14
14
  const noGitChecks = argv.includes("--no-git-checks");
15
+ const provenance = argv.includes("--provenance");
15
16
  const onlyArg = argv.find((f) => f.startsWith("--only="));
16
17
  const only = onlyArg?.slice("--only=".length).split(",");
17
18
  let discoveredPaths;
@@ -43,7 +44,7 @@ async function publishCommand(argv) {
43
44
  }
44
45
  const packageManager = detectPackageManager();
45
46
  try {
46
- publish(resolvedTags, packageManager, { dryRun, noGitChecks });
47
+ publish(resolvedTags, packageManager, { dryRun, noGitChecks, provenance });
47
48
  } catch (error) {
48
49
  console.error(error instanceof Error ? error.message : String(error));
49
50
  process.exit(1);
@@ -1,11 +1,10 @@
1
1
  import { execSync } from "node:child_process";
2
2
  import { bumpAllVersions } from "./bumpAllVersions.js";
3
3
  import { DEFAULT_VERSION_PATTERNS, DEFAULT_WORK_TYPES } from "./defaults.js";
4
- import { determineBumpType } from "./determineBumpType.js";
4
+ import { determineBumpFromCommits } from "./determineBumpFromCommits.js";
5
5
  import { generateChangelogs } from "./generateChangelogs.js";
6
6
  import { getCommitsSinceTarget } from "./getCommitsSinceTarget.js";
7
7
  import { hasPrettierConfig } from "./hasPrettierConfig.js";
8
- import { parseCommitMessage } from "./parseCommitMessage.js";
9
8
  function releasePrepare(config, options) {
10
9
  const { dryRun, bumpOverride } = options;
11
10
  const workTypes = config.workTypes ?? { ...DEFAULT_WORK_TYPES };
@@ -13,10 +12,12 @@ function releasePrepare(config, options) {
13
12
  const { tag, commits } = getCommitsSinceTarget(config.tagPrefix);
14
13
  let releaseType;
15
14
  let parsedCommitCount;
15
+ let unparseableCommits;
16
16
  if (bumpOverride === void 0) {
17
- const parsedCommits = commits.map((c) => parseCommitMessage(c.message, c.hash, workTypes, config.workspaceAliases)).filter((c) => c !== void 0);
18
- parsedCommitCount = parsedCommits.length;
19
- releaseType = determineBumpType(parsedCommits, workTypes, versionPatterns);
17
+ const determination = determineBumpFromCommits(commits, workTypes, versionPatterns, config.scopeAliases);
18
+ parsedCommitCount = determination.parsedCommitCount;
19
+ unparseableCommits = determination.unparseableCommits;
20
+ releaseType = determination.releaseType;
20
21
  } else {
21
22
  releaseType = bumpOverride;
22
23
  }
@@ -28,6 +29,7 @@ function releasePrepare(config, options) {
28
29
  previousTag: tag,
29
30
  commitCount: commits.length,
30
31
  parsedCommitCount,
32
+ unparseableCommits,
31
33
  bumpedFiles: [],
32
34
  changelogFiles: [],
33
35
  skipReason: "No release-worthy changes found. Skipping."
@@ -70,7 +72,9 @@ function releasePrepare(config, options) {
70
72
  newVersion: bump.newVersion,
71
73
  tag: newTag,
72
74
  bumpedFiles: bump.files,
73
- changelogFiles
75
+ changelogFiles,
76
+ commits,
77
+ unparseableCommits
74
78
  }
75
79
  ],
76
80
  tags: [newTag],