@vitejs/release-scripts 1.0.4 → 1.2.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,6 +1,11 @@
1
1
  export declare function publish(options: {
2
2
  defaultPackage: string;
3
3
  getPkgDir?: (pkg: string) => string;
4
+ /**
5
+ * Enables npm package provenance https://docs.npmjs.com/generating-provenance-statements
6
+ * @default false
7
+ */
8
+ provenance?: boolean;
4
9
  }): Promise<void>;
5
10
 
6
11
  export declare function release(options: {
package/dist/index.js CHANGED
@@ -1,85 +1,47 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- publish: () => publish,
34
- release: () => release
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
1
  // src/publish.ts
39
- var import_semver2 = __toESM(require("semver"));
2
+ import semver2 from "semver";
40
3
 
41
4
  // src/utils.ts
42
- var import_node_fs = require("node:fs");
43
- var import_node_path = __toESM(require("node:path"));
44
- var import_picocolors = __toESM(require("picocolors"));
45
- var import_execa = require("execa");
46
- var import_semver = __toESM(require("semver"));
47
- var import_minimist = __toESM(require("minimist"));
48
- var args = (0, import_minimist.default)(process.argv.slice(2));
5
+ import { writeFileSync, readFileSync } from "node:fs";
6
+ import path from "node:path";
7
+ import colors from "picocolors";
8
+ import { execa } from "execa";
9
+ import semver from "semver";
10
+ import minimist from "minimist";
11
+ var args = minimist(process.argv.slice(2));
49
12
  var isDryRun = !!args.dry;
50
13
  if (isDryRun) {
51
- console.log(import_picocolors.default.inverse(import_picocolors.default.yellow(" DRY RUN ")));
14
+ console.log(colors.inverse(colors.yellow(" DRY RUN ")));
52
15
  console.log();
53
16
  }
54
17
  function getPackageInfo(pkgName, getPkgDir = (pkg) => `packages/${pkg}`) {
55
18
  const pkgDir = getPkgDir(pkgName);
56
- const pkgPath = import_node_path.default.resolve(pkgDir, "package.json");
57
- const pkg = require(pkgPath);
58
- const currentVersion = pkg.version;
19
+ const pkgPath = path.resolve(pkgDir, "package.json");
20
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
59
21
  if (pkg.private) {
60
22
  throw new Error(`Package ${pkgName} is private`);
61
23
  }
62
- return { npmName: pkg.name, pkgDir, pkgPath, currentVersion };
24
+ return { pkg, pkgDir, pkgPath };
63
25
  }
64
26
  async function run(bin, args2, opts = {}) {
65
- return (0, import_execa.execa)(bin, args2, { stdio: "inherit", ...opts });
27
+ return execa(bin, args2, { stdio: "inherit", ...opts });
66
28
  }
67
29
  async function dryRun(bin, args2, opts) {
68
30
  return console.log(
69
- import_picocolors.default.blue(`[dryrun] ${bin} ${args2.join(" ")}`),
31
+ colors.blue(`[dryrun] ${bin} ${args2.join(" ")}`),
70
32
  opts || ""
71
33
  );
72
34
  }
73
35
  var runIfNotDry = isDryRun ? dryRun : run;
74
36
  function step(msg) {
75
- return console.log(import_picocolors.default.cyan(msg));
37
+ return console.log(colors.cyan(msg));
76
38
  }
77
39
  function getVersionChoices(currentVersion) {
78
40
  const currentBeta = currentVersion.includes("beta");
79
41
  const currentAlpha = currentVersion.includes("alpha");
80
42
  const isStable = !currentBeta && !currentAlpha;
81
43
  function inc(i, tag = currentAlpha ? "alpha" : "beta") {
82
- return import_semver.default.inc(currentVersion, i, tag);
44
+ return semver.inc(currentVersion, i, tag);
83
45
  }
84
46
  let versionChoices = [
85
47
  {
@@ -133,15 +95,18 @@ function getVersionChoices(currentVersion) {
133
95
  return versionChoices;
134
96
  }
135
97
  function updateVersion(pkgPath, version) {
136
- const pkg = JSON.parse((0, import_node_fs.readFileSync)(pkgPath, "utf-8"));
98
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
137
99
  pkg.version = version;
138
- (0, import_node_fs.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
100
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
139
101
  }
140
- async function publishPackage(pkdDir, tag) {
102
+ async function publishPackage(pkdDir, tag, provenance) {
141
103
  const publicArgs = ["publish", "--access", "public"];
142
104
  if (tag) {
143
105
  publicArgs.push(`--tag`, tag);
144
106
  }
107
+ if (provenance) {
108
+ publicArgs.push(`--provenance`);
109
+ }
145
110
  await runIfNotDry("npm", publicArgs, {
146
111
  cwd: pkdDir
147
112
  });
@@ -157,7 +122,11 @@ async function getActiveVersion(npmName) {
157
122
  }
158
123
 
159
124
  // src/publish.ts
160
- var publish = async ({ defaultPackage, getPkgDir }) => {
125
+ var publish = async ({
126
+ defaultPackage,
127
+ getPkgDir,
128
+ provenance
129
+ }) => {
161
130
  const tag = args._[0];
162
131
  if (!tag)
163
132
  throw new Error("No tag specified");
@@ -169,24 +138,23 @@ var publish = async ({ defaultPackage, getPkgDir }) => {
169
138
  version = tag;
170
139
  if (version.startsWith("v"))
171
140
  version = version.slice(1);
172
- const { npmName, currentVersion, pkgDir } = getPackageInfo(
173
- pkgName,
174
- getPkgDir
175
- );
176
- if (currentVersion !== version)
141
+ const { pkg, pkgDir } = getPackageInfo(pkgName, getPkgDir);
142
+ if (pkg.version !== version)
177
143
  throw new Error(
178
- `Package version from tag "${version}" mismatches with current version "${currentVersion}"`
144
+ `Package version from tag "${version}" mismatches with current version "${pkg.version}"`
179
145
  );
180
- const activeVersion = await getActiveVersion(npmName);
146
+ const activeVersion = await getActiveVersion(pkg.name);
181
147
  step("Publishing package...");
182
- const releaseTag = version.includes("beta") ? "beta" : version.includes("alpha") ? "alpha" : activeVersion && import_semver2.default.lt(currentVersion, activeVersion) ? "previous" : void 0;
183
- await publishPackage(pkgDir, releaseTag);
148
+ const releaseTag = version.includes("beta") ? "beta" : version.includes("alpha") ? "alpha" : activeVersion && semver2.lt(pkg.version, activeVersion) ? "previous" : void 0;
149
+ await publishPackage(pkgDir, releaseTag, provenance);
184
150
  };
185
151
 
186
152
  // src/release.ts
187
- var import_prompts = __toESM(require("prompts"));
188
- var import_semver3 = __toESM(require("semver"));
189
- var import_picocolors2 = __toESM(require("picocolors"));
153
+ import prompts from "prompts";
154
+ import semver3 from "semver";
155
+ import colors2 from "picocolors";
156
+ import { publint } from "publint";
157
+ import { printMessage } from "publint/utils";
190
158
  var release = async ({
191
159
  repo,
192
160
  packages,
@@ -196,55 +164,67 @@ var release = async ({
196
164
  getPkgDir
197
165
  }) => {
198
166
  let targetVersion;
199
- const pkg = packages.length === 1 ? packages[0] : (await (0, import_prompts.default)({
167
+ const selectedPkg = packages.length === 1 ? packages[0] : (await prompts({
200
168
  type: "select",
201
169
  name: "pkg",
202
170
  message: "Select package",
203
171
  choices: packages.map((i) => ({ value: i, title: i }))
204
172
  })).pkg;
205
- if (!pkg)
173
+ if (!selectedPkg)
206
174
  return;
207
- await logChangelog(pkg);
208
- const { currentVersion, pkgPath } = getPackageInfo(pkg, getPkgDir);
175
+ await logChangelog(selectedPkg);
176
+ const { pkg, pkgPath, pkgDir } = getPackageInfo(selectedPkg, getPkgDir);
177
+ const messages = await publint({ pkgDir });
178
+ if (messages.length) {
179
+ for (const message of messages)
180
+ console.log(printMessage(message, pkg));
181
+ const { yes: yes2 } = await prompts({
182
+ type: "confirm",
183
+ name: "yes",
184
+ message: `${messages.length} messages from publint. Continue anyway?`
185
+ });
186
+ if (!yes2)
187
+ process.exit(1);
188
+ }
209
189
  if (!targetVersion) {
210
- const { release: release2 } = await (0, import_prompts.default)({
190
+ const { release: release2 } = await prompts({
211
191
  type: "select",
212
192
  name: "release",
213
193
  message: "Select release type",
214
- choices: getVersionChoices(currentVersion)
194
+ choices: getVersionChoices(pkg.version)
215
195
  });
216
196
  if (release2 === "custom") {
217
- const res = await (0, import_prompts.default)({
197
+ const res = await prompts({
218
198
  type: "text",
219
199
  name: "version",
220
200
  message: "Input custom version",
221
- initial: currentVersion
201
+ initial: pkg.version
222
202
  });
223
203
  targetVersion = res.version;
224
204
  } else {
225
205
  targetVersion = release2;
226
206
  }
227
207
  }
228
- if (!import_semver3.default.valid(targetVersion)) {
208
+ if (!semver3.valid(targetVersion)) {
229
209
  throw new Error(`invalid target version: ${targetVersion}`);
230
210
  }
231
- const tag = toTag(pkg, targetVersion);
211
+ const tag = toTag(selectedPkg, targetVersion);
232
212
  if (targetVersion.includes("beta") && !args.tag) {
233
213
  args.tag = "beta";
234
214
  }
235
215
  if (targetVersion.includes("alpha") && !args.tag) {
236
216
  args.tag = "alpha";
237
217
  }
238
- const { yes } = await (0, import_prompts.default)({
218
+ const { yes } = await prompts({
239
219
  type: "confirm",
240
220
  name: "yes",
241
- message: `Releasing ${import_picocolors2.default.yellow(tag)} Confirm?`
221
+ message: `Releasing ${colors2.yellow(tag)} Confirm?`
242
222
  });
243
223
  if (!yes)
244
224
  return;
245
225
  step("\nUpdating package version...");
246
226
  updateVersion(pkgPath, targetVersion);
247
- await generateChangelog(pkg, targetVersion);
227
+ await generateChangelog(selectedPkg, targetVersion);
248
228
  const { stdout } = await run("git", ["diff"], { stdio: "pipe" });
249
229
  if (stdout) {
250
230
  step("\nCommitting changes...");
@@ -263,7 +243,7 @@ var release = async ({
263
243
  Dry run finished - run git diff to see package changes.`);
264
244
  } else {
265
245
  console.log(
266
- import_picocolors2.default.green(
246
+ colors2.green(
267
247
  `
268
248
  Pushed, publishing should starts shortly on CI.
269
249
  https://github.com/vitejs/${repo}/actions/workflows/publish.yml`
@@ -272,8 +252,7 @@ https://github.com/vitejs/${repo}/actions/workflows/publish.yml`
272
252
  }
273
253
  console.log();
274
254
  };
275
- // Annotate the CommonJS export names for ESM import in node:
276
- 0 && (module.exports = {
255
+ export {
277
256
  publish,
278
257
  release
279
- });
258
+ };
package/package.json CHANGED
@@ -1,37 +1,45 @@
1
1
  {
2
2
  "name": "@vitejs/release-scripts",
3
- "version": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "description": "@vitejs release scripts",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
+ "type": "module",
7
8
  "files": [
8
9
  "dist"
9
10
  ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
10
17
  "scripts": {
11
18
  "build": "tsx scripts/build.ts",
12
19
  "prettier": "pnpm prettier-ci --write",
13
20
  "prettier-ci": "prettier --cache --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
14
- "ci": "tsc && pnpm prettier-ci && pnpm build",
21
+ "qa": "tsc && pnpm prettier-ci && pnpm build",
15
22
  "release": "tsx scripts/release.ts"
16
23
  },
17
24
  "prettier": {
18
25
  "trailingComma": "all"
19
26
  },
20
27
  "dependencies": {
21
- "execa": "^6.1.0",
22
- "minimist": "^1.2.7",
28
+ "execa": "^7.1.1",
29
+ "minimist": "^1.2.8",
23
30
  "picocolors": "^1.0.0",
24
31
  "prompts": "^2.4.2",
25
- "semver": "^7.3.8"
32
+ "publint": "^0.1.11",
33
+ "semver": "^7.5.0"
26
34
  },
27
35
  "devDependencies": {
28
36
  "@types/minimist": "^1.2.2",
29
- "@types/node": "^18.11.18",
30
- "@types/prompts": "^2.4.2",
37
+ "@types/node": "^18.16.3",
38
+ "@types/prompts": "^2.4.4",
31
39
  "@types/semver": "^7.3.13",
32
- "esbuild": "^0.16.17",
33
- "prettier": "^2.8.2",
34
- "tsx": "^3.12.2",
35
- "typescript": "^4.9.4"
40
+ "esbuild": "^0.17.18",
41
+ "prettier": "^2.8.8",
42
+ "tsx": "^3.12.7",
43
+ "typescript": "^5.0.4"
36
44
  }
37
45
  }