@vitejs/release-scripts 1.0.4 → 1.1.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 (2) hide show
  1. package/dist/index.js +56 -84
  2. package/package.json +11 -3
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,9 +95,9 @@ 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
102
  async function publishPackage(pkdDir, tag) {
141
103
  const publicArgs = ["publish", "--access", "public"];
@@ -169,24 +131,23 @@ var publish = async ({ defaultPackage, getPkgDir }) => {
169
131
  version = tag;
170
132
  if (version.startsWith("v"))
171
133
  version = version.slice(1);
172
- const { npmName, currentVersion, pkgDir } = getPackageInfo(
173
- pkgName,
174
- getPkgDir
175
- );
176
- if (currentVersion !== version)
134
+ const { pkg, pkgDir } = getPackageInfo(pkgName, getPkgDir);
135
+ if (pkg.version !== version)
177
136
  throw new Error(
178
- `Package version from tag "${version}" mismatches with current version "${currentVersion}"`
137
+ `Package version from tag "${version}" mismatches with current version "${pkg.version}"`
179
138
  );
180
- const activeVersion = await getActiveVersion(npmName);
139
+ const activeVersion = await getActiveVersion(pkg.name);
181
140
  step("Publishing package...");
182
- const releaseTag = version.includes("beta") ? "beta" : version.includes("alpha") ? "alpha" : activeVersion && import_semver2.default.lt(currentVersion, activeVersion) ? "previous" : void 0;
141
+ const releaseTag = version.includes("beta") ? "beta" : version.includes("alpha") ? "alpha" : activeVersion && semver2.lt(pkg.version, activeVersion) ? "previous" : void 0;
183
142
  await publishPackage(pkgDir, releaseTag);
184
143
  };
185
144
 
186
145
  // src/release.ts
187
- var import_prompts = __toESM(require("prompts"));
188
- var import_semver3 = __toESM(require("semver"));
189
- var import_picocolors2 = __toESM(require("picocolors"));
146
+ import prompts from "prompts";
147
+ import semver3 from "semver";
148
+ import colors2 from "picocolors";
149
+ import { publint } from "publint";
150
+ import { printMessage } from "publint/utils";
190
151
  var release = async ({
191
152
  repo,
192
153
  packages,
@@ -196,55 +157,67 @@ var release = async ({
196
157
  getPkgDir
197
158
  }) => {
198
159
  let targetVersion;
199
- const pkg = packages.length === 1 ? packages[0] : (await (0, import_prompts.default)({
160
+ const selectedPkg = packages.length === 1 ? packages[0] : (await prompts({
200
161
  type: "select",
201
162
  name: "pkg",
202
163
  message: "Select package",
203
164
  choices: packages.map((i) => ({ value: i, title: i }))
204
165
  })).pkg;
205
- if (!pkg)
166
+ if (!selectedPkg)
206
167
  return;
207
- await logChangelog(pkg);
208
- const { currentVersion, pkgPath } = getPackageInfo(pkg, getPkgDir);
168
+ await logChangelog(selectedPkg);
169
+ const { pkg, pkgPath, pkgDir } = getPackageInfo(selectedPkg, getPkgDir);
170
+ const messages = await publint({ pkgDir });
171
+ if (messages.length) {
172
+ for (const message of messages)
173
+ console.log(printMessage(message, pkg));
174
+ const { yes: yes2 } = await prompts({
175
+ type: "confirm",
176
+ name: "yes",
177
+ message: `${messages.length} messages from publint. Continue anyway?`
178
+ });
179
+ if (!yes2)
180
+ process.exit(1);
181
+ }
209
182
  if (!targetVersion) {
210
- const { release: release2 } = await (0, import_prompts.default)({
183
+ const { release: release2 } = await prompts({
211
184
  type: "select",
212
185
  name: "release",
213
186
  message: "Select release type",
214
- choices: getVersionChoices(currentVersion)
187
+ choices: getVersionChoices(pkg.version)
215
188
  });
216
189
  if (release2 === "custom") {
217
- const res = await (0, import_prompts.default)({
190
+ const res = await prompts({
218
191
  type: "text",
219
192
  name: "version",
220
193
  message: "Input custom version",
221
- initial: currentVersion
194
+ initial: pkg.version
222
195
  });
223
196
  targetVersion = res.version;
224
197
  } else {
225
198
  targetVersion = release2;
226
199
  }
227
200
  }
228
- if (!import_semver3.default.valid(targetVersion)) {
201
+ if (!semver3.valid(targetVersion)) {
229
202
  throw new Error(`invalid target version: ${targetVersion}`);
230
203
  }
231
- const tag = toTag(pkg, targetVersion);
204
+ const tag = toTag(selectedPkg, targetVersion);
232
205
  if (targetVersion.includes("beta") && !args.tag) {
233
206
  args.tag = "beta";
234
207
  }
235
208
  if (targetVersion.includes("alpha") && !args.tag) {
236
209
  args.tag = "alpha";
237
210
  }
238
- const { yes } = await (0, import_prompts.default)({
211
+ const { yes } = await prompts({
239
212
  type: "confirm",
240
213
  name: "yes",
241
- message: `Releasing ${import_picocolors2.default.yellow(tag)} Confirm?`
214
+ message: `Releasing ${colors2.yellow(tag)} Confirm?`
242
215
  });
243
216
  if (!yes)
244
217
  return;
245
218
  step("\nUpdating package version...");
246
219
  updateVersion(pkgPath, targetVersion);
247
- await generateChangelog(pkg, targetVersion);
220
+ await generateChangelog(selectedPkg, targetVersion);
248
221
  const { stdout } = await run("git", ["diff"], { stdio: "pipe" });
249
222
  if (stdout) {
250
223
  step("\nCommitting changes...");
@@ -263,7 +236,7 @@ var release = async ({
263
236
  Dry run finished - run git diff to see package changes.`);
264
237
  } else {
265
238
  console.log(
266
- import_picocolors2.default.green(
239
+ colors2.green(
267
240
  `
268
241
  Pushed, publishing should starts shortly on CI.
269
242
  https://github.com/vitejs/${repo}/actions/workflows/publish.yml`
@@ -272,8 +245,7 @@ https://github.com/vitejs/${repo}/actions/workflows/publish.yml`
272
245
  }
273
246
  console.log();
274
247
  };
275
- // Annotate the CommonJS export names for ESM import in node:
276
- 0 && (module.exports = {
248
+ export {
277
249
  publish,
278
250
  release
279
- });
251
+ };
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@vitejs/release-scripts",
3
- "version": "1.0.4",
3
+ "version": "1.1.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",
@@ -22,6 +29,7 @@
22
29
  "minimist": "^1.2.7",
23
30
  "picocolors": "^1.0.0",
24
31
  "prompts": "^2.4.2",
32
+ "publint": "^0.1.9",
25
33
  "semver": "^7.3.8"
26
34
  },
27
35
  "devDependencies": {
@@ -29,8 +37,8 @@
29
37
  "@types/node": "^18.11.18",
30
38
  "@types/prompts": "^2.4.2",
31
39
  "@types/semver": "^7.3.13",
32
- "esbuild": "^0.16.17",
33
- "prettier": "^2.8.2",
40
+ "esbuild": "^0.17.4",
41
+ "prettier": "^2.8.3",
34
42
  "tsx": "^3.12.2",
35
43
  "typescript": "^4.9.4"
36
44
  }