From d614005913a2399db60b68090e8e86fd740e9653 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Tue, 25 Jun 2024 15:52:53 +0800 Subject: [PATCH] chore: update --- scripts/debug/overrides-rspack.mjs | 5 ++- scripts/debug/update-rspack.mjs | 65 ------------------------------ scripts/release/version.mjs | 8 +--- x.mjs | 8 ---- 4 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 scripts/debug/update-rspack.mjs diff --git a/scripts/debug/overrides-rspack.mjs b/scripts/debug/overrides-rspack.mjs index 5babe71b4d5..833f4d58ed5 100644 --- a/scripts/debug/overrides-rspack.mjs +++ b/scripts/debug/overrides-rspack.mjs @@ -41,8 +41,9 @@ export async function overrides_rspack_handler(version, options) { for (const name of workspaceNames) { if (name.startsWith("@rspack/")) { - pkgJson["pnpm"]["overrides"][isSnapshot ? getNextName(name) : name] = - version; + pkgJson["pnpm"]["overrides"][name] = isSnapshot + ? `npm:${getNextName(name)}@${version}` + : version; } } diff --git a/scripts/debug/update-rspack.mjs b/scripts/debug/update-rspack.mjs deleted file mode 100644 index 76923692c07..00000000000 --- a/scripts/debug/update-rspack.mjs +++ /dev/null @@ -1,65 +0,0 @@ -import { getNextName } from "../release/version.mjs"; -import fs from "node:fs"; -import path from "node:path"; - -const depFields = [ - "dependencies", - "devDependencies", - "peerDependencies", - "optionalDependencies" -]; - -export function getNextPkgJson(pkgJson, version, isSnapshotVersion) { - const newPkgJson = { ...pkgJson }; - for (let field of depFields) { - if (!newPkgJson[field]) { - continue; - } - for (let [depName, _v] of Object.entries(newPkgJson[field])) { - if (depName.startsWith("@rspack/")) { - if (isSnapshotVersion) { - delete newPkgJson[field][depName]; - newPkgJson[field][getNextName(depName)] = version; - } else { - newPkgJson[field][depName] = version; - } - } - } - } - return newPkgJson; -} - -export async function update_rspack_handler(version, options) { - const root = process.cwd(); - const { path: pathOpts } = options; - - let pkgPath = pathOpts; - if (typeof pkgPath !== "string") { - pkgPath = path.resolve(process.cwd(), "package.json"); - } - - if (!path.isAbsolute(pkgPath)) { - pkgPath = path.resolve(root, pkgPath); - } - - if (path.basename(pkgPath) !== "package.json") { - pkgPath = path.resolve(pkgPath, "package.json"); - } - - const pkgJson = ( - await import(pkgPath, { - assert: { - type: "json" - } - }) - )["default"]; - - const newPkgJson = await getNextPkgJson( - pkgJson, - version, - version.includes("-canary") - ); - fs.writeFileSync(pkgPath, JSON.stringify(newPkgJson, null, 2), "utf8"); - - console.log(`Updated rspack related package to ${version} in ${pkgPath}`); -} diff --git a/scripts/release/version.mjs b/scripts/release/version.mjs index e15e2bf0fe6..be61a3eff5f 100644 --- a/scripts/release/version.mjs +++ b/scripts/release/version.mjs @@ -1,7 +1,6 @@ import path from "path"; import { findWorkspacePackagesNoCheck } from "@pnpm/find-workspace-packages"; import semver from "semver"; -import { getNextPkgJson } from "../debug/update-rspack.mjs"; async function getCommitId() { const result = await $`git rev-parse --short HEAD`; @@ -63,13 +62,8 @@ export async function version_handler(version) { if (version === "snapshot") { const nextName = getNextName(workspace.manifest.name); - const nextPkgJson = getNextPkgJson( - workspace.manifest, - "workspace:*", - true - ); newManifest = { - ...nextPkgJson, + ...workspace.manifest, name: nextName, version: nextVersion }; diff --git a/x.mjs b/x.mjs index ca221d4744a..5260678962d 100755 --- a/x.mjs +++ b/x.mjs @@ -9,7 +9,6 @@ import { launchRspackCli } from "./scripts/debug/launch.mjs"; import { overrides_rspack_handler } from "./scripts/debug/overrides-rspack.mjs"; -import { update_rspack_handler } from "./scripts/debug/update-rspack.mjs"; import { publish_handler } from "./scripts/release/publish.mjs"; import { version_handler } from "./scripts/release/version.mjs"; @@ -245,13 +244,6 @@ program await launchJestWithArgs(getVariadicArgs()); }); -program - .command("update-rspack") - .argument("", "version field") - .option("--path ", "path to package.json") - .description("update rspack related packages in package.json") - .action(update_rspack_handler); - program .command("overrides-rspack") .argument("", "version field")