@vitejs/release-scripts 1.5.0 → 1.7.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/dist/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ export declare function generateChangelog(options: {
2
+ /** @example () => `packages/${pkgName}` */
3
+ getPkgDir: () => string;
4
+ /** @example `${pkgName}@` */
5
+ tagPrefix?: string;
6
+ }): Promise<void>;
7
+
1
8
  export declare function publish(options: {
2
9
  defaultPackage?: string;
3
10
  getPkgDir?: (pkg: string) => string;
@@ -14,6 +21,8 @@ export declare function publish(options: {
14
21
  }): Promise<void>;
15
22
 
16
23
  export declare function release(options: {
24
+ /** @default 'vitejs' */
25
+ org?: string;
17
26
  repo: string;
18
27
  packages: string[];
19
28
  logChangelog: (pkg: string) => void | Promise<void>;
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // src/publish.ts
2
- import semver2 from "semver";
2
+ import * as semver2 from "semver";
3
3
 
4
4
  // src/utils.ts
5
5
  import { writeFileSync, readFileSync } from "node:fs";
6
6
  import path from "node:path";
7
7
  import colors from "picocolors";
8
- import { execa } from "execa";
9
- import semver from "semver";
8
+ import { exec } from "tinyexec";
9
+ import * as semver from "semver";
10
10
  import mri from "mri";
11
11
  var args = mri(process.argv.slice(2));
12
12
  var isDryRun = !!args.dry;
@@ -24,7 +24,14 @@ function getPackageInfo(pkgName, getPkgDir = (pkg) => `packages/${pkg}`) {
24
24
  return { pkg, pkgDir, pkgPath };
25
25
  }
26
26
  async function run(bin, args2, opts = {}) {
27
- return execa(bin, args2, { stdio: "inherit", ...opts });
27
+ return exec(bin, args2, {
28
+ throwOnError: true,
29
+ ...opts,
30
+ nodeOptions: {
31
+ stdio: "inherit",
32
+ ...opts.nodeOptions
33
+ }
34
+ });
28
35
  }
29
36
  async function dryRun(bin, args2, opts) {
30
37
  return console.log(
@@ -40,51 +47,51 @@ function getVersionChoices(currentVersion) {
40
47
  const currentBeta = currentVersion.includes("beta");
41
48
  const currentAlpha = currentVersion.includes("alpha");
42
49
  const isStable = !currentBeta && !currentAlpha;
43
- function inc(i, tag = currentAlpha ? "alpha" : "beta") {
50
+ function inc2(i, tag = currentAlpha ? "alpha" : "beta") {
44
51
  return semver.inc(currentVersion, i, tag);
45
52
  }
46
53
  let versionChoices = [
47
54
  {
48
55
  title: "next",
49
- value: inc(isStable ? "patch" : "prerelease")
56
+ value: inc2(isStable ? "patch" : "prerelease")
50
57
  }
51
58
  ];
52
59
  if (isStable) {
53
60
  versionChoices.push(
54
61
  {
55
62
  title: "beta-minor",
56
- value: inc("preminor")
63
+ value: inc2("preminor")
57
64
  },
58
65
  {
59
66
  title: "beta-major",
60
- value: inc("premajor")
67
+ value: inc2("premajor")
61
68
  },
62
69
  {
63
70
  title: "alpha-minor",
64
- value: inc("preminor", "alpha")
71
+ value: inc2("preminor", "alpha")
65
72
  },
66
73
  {
67
74
  title: "alpha-major",
68
- value: inc("premajor", "alpha")
75
+ value: inc2("premajor", "alpha")
69
76
  },
70
77
  {
71
78
  title: "minor",
72
- value: inc("minor")
79
+ value: inc2("minor")
73
80
  },
74
81
  {
75
82
  title: "major",
76
- value: inc("major")
83
+ value: inc2("major")
77
84
  }
78
85
  );
79
86
  } else if (currentAlpha) {
80
87
  versionChoices.push({
81
88
  title: "beta",
82
- value: inc("patch") + "-beta.0"
89
+ value: inc2("patch") + "-beta.0"
83
90
  });
84
91
  } else {
85
92
  versionChoices.push({
86
93
  title: "stable",
87
- value: inc("patch")
94
+ value: inc2("patch")
88
95
  });
89
96
  }
90
97
  versionChoices.push({ value: "custom", title: "custom" });
@@ -111,7 +118,7 @@ async function publishPackage(pkgDir, tag, provenance, packageManager = "npm") {
111
118
  publicArgs.push(`--no-git-checks`);
112
119
  }
113
120
  await runIfNotDry(packageManager, publicArgs, {
114
- cwd: pkgDir
121
+ nodeOptions: { cwd: pkgDir }
115
122
  });
116
123
  }
117
124
  async function getActiveVersion(npmName) {
@@ -119,7 +126,7 @@ async function getActiveVersion(npmName) {
119
126
  const { stdout } = await run(
120
127
  "npm",
121
128
  ["info", npmName, "version", "--json"],
122
- { stdio: "pipe" }
129
+ { nodeOptions: { stdio: "pipe" } }
123
130
  );
124
131
  return JSON.parse(stdout);
125
132
  } catch (e) {
@@ -169,10 +176,11 @@ import colors2 from "picocolors";
169
176
  import { publint } from "publint";
170
177
  import { formatMessage } from "publint/utils";
171
178
  var release = async ({
179
+ org = "vitejs",
172
180
  repo,
173
181
  packages,
174
182
  logChangelog,
175
- generateChangelog,
183
+ generateChangelog: generateChangelog2,
176
184
  toTag,
177
185
  getPkgDir
178
186
  }) => {
@@ -233,8 +241,10 @@ var release = async ({
233
241
  if (!yes) return;
234
242
  step("\nUpdating package version...");
235
243
  updateVersion(pkgPath, targetVersion);
236
- await generateChangelog(selectedPkg, targetVersion);
237
- const { stdout } = await run("git", ["diff"], { stdio: "pipe" });
244
+ await generateChangelog2(selectedPkg, targetVersion);
245
+ const { stdout } = await run("git", ["diff"], {
246
+ nodeOptions: { stdio: "pipe" }
247
+ });
238
248
  if (stdout) {
239
249
  step("\nCommitting changes...");
240
250
  await runIfNotDry("git", ["add", "-A"]);
@@ -255,13 +265,89 @@ Dry run finished - run git diff to see package changes.`);
255
265
  colors2.green(
256
266
  `
257
267
  Pushed, publishing should starts shortly on CI.
258
- https://github.com/vitejs/${repo}/actions/workflows/publish.yml`
268
+ https://github.com/${org}/${repo}/actions/workflows/publish.yml`
259
269
  )
260
270
  );
261
271
  }
262
272
  console.log();
263
273
  };
274
+
275
+ // src/changelog.ts
276
+ import fs from "node:fs";
277
+ import path2 from "node:path";
278
+ import { ConventionalChangelog } from "conventional-changelog";
279
+ import createPreset, {
280
+ DEFAULT_COMMIT_TYPES
281
+ } from "conventional-changelog-conventionalcommits";
282
+ var generateChangelog = async ({
283
+ getPkgDir,
284
+ tagPrefix
285
+ }) => {
286
+ const preset = await createPreset({
287
+ types: DEFAULT_COMMIT_TYPES.map((t) => ({ ...t, hidden: false }))
288
+ });
289
+ preset.writer ??= {};
290
+ preset.writer.headerPartial = `
291
+ ## {{#if isPatch~}} <small> {{~/if~}}
292
+ {{#if @root.linkCompare~}}
293
+ [{{version}}](
294
+ {{~#if @root.repository~}}
295
+ {{~#if @root.host}}
296
+ {{~@root.host}}/
297
+ {{~/if}}
298
+ {{~#if @root.owner}}
299
+ {{~@root.owner}}/
300
+ {{~/if}}
301
+ {{~@root.repository}}
302
+ {{~else}}
303
+ {{~@root.repoUrl}}
304
+ {{~/if~}}
305
+ /compare/{{previousTag}}...{{currentTag}})
306
+ {{~else}}
307
+ {{~version}}
308
+ {{~/if}}
309
+ {{~#if title}} "{{title}}"
310
+ {{~/if}}
311
+ {{~#if date}} ({{date}})
312
+ {{~/if}}
313
+ {{~#if isPatch~}} </small> {{~/if}}
314
+ `.trim();
315
+ preset.writer.mainTemplate = `
316
+ {{> header}}
317
+ {{#if noteGroups}}
318
+ {{#each noteGroups}}
319
+
320
+ ### \u26A0 {{title}}
321
+
322
+ {{#each notes}}
323
+ * {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{commit.subject}} {{#if commit.hash}}([{{commit.shortHash}}](https://github.com/{{@root.owner}}/{{@root.repository}}/commit/{{commit.hash}})){{/if}}
324
+ {{/each}}
325
+ {{/each}}
326
+ {{/if}}
327
+ {{#each commitGroups}}
328
+
329
+ {{#if title}}
330
+ ### {{title}}
331
+
332
+ {{/if}}
333
+ {{#each commits}}
334
+ {{> commit root=@root}}
335
+ {{/each}}
336
+ {{/each}}`.trim() + "\n";
337
+ const pkgDir = getPkgDir();
338
+ const generator = new ConventionalChangelog(pkgDir).readPackage().config(preset).options({ releaseCount: 1 });
339
+ if (tagPrefix) {
340
+ generator.tags({ prefix: tagPrefix });
341
+ }
342
+ const originalChangelog = fs.existsSync(path2.join(pkgDir, "CHANGELOG.md")) ? fs.readFileSync(path2.join(pkgDir, "CHANGELOG.md"), "utf-8") : "";
343
+ const writeStream = fs.createWriteStream(path2.join(pkgDir, "CHANGELOG.md"));
344
+ for await (const chunk of generator.write()) {
345
+ writeStream.write(chunk);
346
+ }
347
+ writeStream.write(originalChangelog);
348
+ };
264
349
  export {
350
+ generateChangelog,
265
351
  publish,
266
352
  release
267
353
  };
package/package.json CHANGED
@@ -1,46 +1,44 @@
1
1
  {
2
2
  "name": "@vitejs/release-scripts",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "@vitejs release scripts",
5
5
  "license": "MIT",
6
- "main": "dist/index.js",
7
6
  "type": "module",
8
7
  "files": [
9
8
  "dist"
10
9
  ],
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
15
- }
16
- },
10
+ "exports": "./dist/index.js",
17
11
  "repository": {
18
12
  "type": "git",
19
13
  "url": "git+https://github.com/vitejs/release-scripts.git"
20
14
  },
21
15
  "scripts": {
22
- "build": "tnode scripts/build.ts",
16
+ "build": "node scripts/build.ts",
17
+ "test": "vitest",
23
18
  "prettier": "pnpm prettier-ci --write",
24
19
  "prettier-ci": "prettier --cache --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
25
- "qa": "tsc && pnpm prettier-ci && pnpm build",
26
- "release": "tnode scripts/release.ts"
20
+ "qa": "tsc && pnpm prettier-ci && pnpm build && vitest run",
21
+ "release": "node scripts/release.ts"
27
22
  },
28
23
  "dependencies": {
29
- "execa": "^8.0.1",
24
+ "conventional-changelog": "^7.2.0",
25
+ "conventional-changelog-conventionalcommits": "^9.3.1",
30
26
  "mri": "^1.2.0",
31
27
  "picocolors": "^1.1.1",
32
28
  "prompts": "^2.4.2",
33
- "publint": "^0.3.2",
34
- "semver": "^7.6.3"
29
+ "publint": "^0.3.18",
30
+ "semver": "^7.7.4",
31
+ "tinyexec": "^1.1.1"
35
32
  },
36
33
  "devDependencies": {
37
- "@arnaud-barre/tnode": "^0.24.0",
38
- "@types/node": "^22.10.9",
34
+ "@types/node": "^24.12.2",
39
35
  "@types/prompts": "^2.4.9",
40
- "@types/semver": "^7.5.8",
41
- "esbuild": "^0.24.2",
42
- "prettier": "^3.4.2",
43
- "typescript": "^5.7.3"
36
+ "@types/semver": "^7.7.1",
37
+ "esbuild": "^0.28.0",
38
+ "fs-fixture": "^2.13.0",
39
+ "prettier": "^3.8.3",
40
+ "typescript": "^6.0.3",
41
+ "vitest": "^4.1.5"
44
42
  },
45
- "packageManager": "pnpm@9.15.4"
43
+ "packageManager": "pnpm@10.33.0"
46
44
  }