Switch semver to verkit in release script (#19976)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-09-23 13:09:48 +08:00
1 parent cc6edc3e93
commit 0fc9e3eab8
12 files changed
+37 -44

No files matched your search

+4 -4
View File
@@ -1,11 +1,11 @@
// TODO: Implement this in `utilities.js` when jest.importActual is landed.
export default function getFormattedDate() {
const date = new Date();
const isoStr = date.toISOString();
const isoString = date.toISOString();
const year = isoStr.slice(0, 4);
const month = isoStr.slice(5, 7);
const day = isoStr.slice(8, 10);
const year = isoString.slice(0, 4);
const month = isoString.slice(5, 7);
const day = isoString.slice(8, 10);
return { year, month, day };
}
+1 -1
View File
@@ -10,7 +10,7 @@
"nano-spawn": "2.1.0",
"node-style-text": "2.1.2",
"outdent": "0.8.0",
"semver": "7.8.5"
"verkit": "0.5.0"
},
"engines": {
"node": ">=20"
+3 -5
View File
@@ -1,4 +1,4 @@
import semver from "semver";
import * as verkit from "verkit";
import parseArguments from "./parse-arguments.js";
import * as steps from "./steps/index.js";
import { logPromise, readJson } from "./utilities.js";
@@ -6,10 +6,8 @@ import { logPromise, readJson } from "./utilities.js";
const params = parseArguments();
const {
default: { version: previousVersion },
} = await import("prettier/package.json", {
with: { type: "json" },
});
if (semver.parse(previousVersion) === null) {
} = await import("prettier/package.json", { with: { type: "json" } });
if (!verkit.isValid(previousVersion)) {
throw new Error(`Unexpected previousVersion: ${previousVersion}`);
}
+3 -3
View File
@@ -1,5 +1,5 @@
import fs from "node:fs";
import semver from "semver";
import * as verkit from "verkit";
import {
logPromise,
readJson,
@@ -45,10 +45,10 @@ async function bump({
previousVersionOnDefaultBranch,
}) {
const pkg = await readJson("package.json");
if (semver.diff(version, previousVersion) === "patch") {
if (verkit.difference(version, previousVersion) === "patch") {
pkg.version = previousVersionOnDefaultBranch; // restore the `-dev` version
} else {
pkg.version = semver.inc(version, "minor") + "-dev";
pkg.version = verkit.increment(version, "minor") + "-dev";
}
await writeJson("package.json", pkg);
}
+2 -2
View File
@@ -1,5 +1,5 @@
import enquirer from "enquirer";
import semver from "semver";
import * as verkit from "verkit";
const SEMVER_INCREMENTS = ["patch", "minor", "major"];
const CUSTOM_VERSION_VALUE_PLACEHOLDER = "custom-version";
@@ -10,7 +10,7 @@ export default async function chooseVersion(params) {
message: `Choose a version to release (current: ${params.previousVersion})`,
choices: [
...SEMVER_INCREMENTS.map((type) => {
const version = semver.inc(params.previousVersion, type);
const version = verkit.increment(params.previousVersion, type);
return {
message: `${type}: ${version}`,
+2 -2
View File
@@ -1,5 +1,5 @@
import styleText from "node-style-text";
import semver from "semver";
import * as verkit from "verkit";
import { runGit, waitForEnter } from "../utilities.js";
export default async function mergeBlogPost({
@@ -12,7 +12,7 @@ export default async function mergeBlogPost({
return;
}
if (semver.diff(version, previousVersion) === "patch") {
if (verkit.difference(version, previousVersion) === "patch") {
return;
}
@@ -1,6 +1,6 @@
import styleText from "node-style-text";
import outdent from "outdent";
import semver from "semver";
import * as verkit from "verkit";
import {
getBlogPostInfo,
getChangelogContent,
@@ -9,8 +9,7 @@ import {
const RELEASE_URL_BASE = "https://github.com/prettier/prettier/releases/new?";
export function getReleaseUrl(version, previousVersion) {
const semverDiff = semver.diff(version, previousVersion);
const isPatch = semverDiff === "patch";
const isPatch = verkit.difference(version, previousVersion) === "patch";
const tag = version;
let body;
if (isPatch) {
+2 -4
View File
@@ -1,7 +1,7 @@
import fs from "node:fs";
import spawn from "nano-spawn";
import styleText from "node-style-text";
import semver from "semver";
import * as verkit from "verkit";
import {
getBlogPostInfo,
getChangelogContent,
@@ -37,9 +37,7 @@ export default async function updateChangelog({
return;
}
const semverDiff = semver.diff(version, previousVersion);
if (semverDiff !== "patch") {
if (verkit.difference(version, previousVersion) !== "patch") {
const blogPost = getBlogPostInfo(version);
writeChangelog({
version,
@@ -1,24 +1,24 @@
import styleText from "node-style-text";
import semver from "semver";
import * as verkit from "verkit";
export default function validateNewVersion({ version, previousVersion, next }) {
if (!version) {
throw new Error("'--version' is required");
}
if (!semver.valid(version)) {
if (!verkit.isValid(version)) {
throw new Error(
`Invalid version '${styleText.red.underline(version)}' specified`,
);
}
if (!semver.gt(version, previousVersion)) {
if (!verkit.isGreaterThan(version, previousVersion)) {
throw new Error(
`Version '${styleText.yellow.underline(version)}' has already been published`,
);
}
if (next && semver.prerelease(version) === null) {
if (next && !verkit.isPrerelease(version)) {
throw new Error(
`Version '${styleText.yellow.underline(
version,
+5 -5
View File
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { URLSearchParams } from "node:url";
import getFormattedDate from "../get-formatted-date.js";
import { getReleaseUrl } from "../steps/show-instructions-after-npm-publish.js";
const RELEASE_URL_BASE = "https://github.com/prettier/prettier/releases/new?";
@@ -9,11 +10,10 @@ const getExpectedReleaseUrl = (parameters) => {
return `${RELEASE_URL_BASE}${parameters}`;
};
const getDateParts = () => [
new Date().getFullYear(),
String(new Date().getMonth() + 1).padStart(2, "0"),
String(new Date().getDate()).padStart(2, "0"),
];
const getDateParts = () => {
const { year, month, day } = getFormattedDate();
return [year, month, day];
};
describe("publish-to-npm", () => {
describe("getReleaseUrl", () => {
@@ -12,7 +12,7 @@ describe("validate-new-version", () => {
{ message: "'--version' is required" },
);
});
it("throws error for invalid semver", () => {
it("throws error for invalid version", () => {
assert.throws(
() => {
validateNewVersion({ version: "foo" });
+8 -10
View File
@@ -196,7 +196,7 @@ __metadata:
nano-spawn: "npm:2.1.0"
node-style-text: "npm:2.1.2"
outdent: "npm:0.8.0"
semver: "npm:7.8.5"
verkit: "npm:0.5.0"
languageName: unknown
linkType: soft
@@ -209,15 +209,6 @@ __metadata:
languageName: node
linkType: hard
"semver@npm:7.8.5":
version: 7.8.5
resolution: "semver@npm:7.8.5"
bin:
semver: bin/semver.js
checksum: 10/9b01d2ff11e6e4a4539b7ca3c5f280c8704cb397a28504469f2ed4f00ad2194748d756647362a9712fff30984d15772ab7f083108c2fb508e2096ae9e708f22c
languageName: node
linkType: hard
"strip-ansi@npm:^6.0.1":
version: 6.0.1
resolution: "strip-ansi@npm:6.0.1"
@@ -235,3 +226,10 @@ __metadata:
checksum: 10/10dda13571e1f5ad37546827e9b6d4252d2e0bc176c24a101252153ef435d83696e2557fe128c4678e4e78f5f01e83711c703eef9814eb12dab028580d45980a
languageName: node
linkType: hard
"verkit@npm:0.5.0":
version: 0.5.0
resolution: "verkit@npm:0.5.0"
checksum: 10/82efcb8da3d8e20d8745a51ab6500046651297ff6446ea83ca83ee4d1f610347a4d4553adf9c74d483814ad6752e3eec8250313c32912f853ea34fd31203dbec
languageName: node
linkType: hard