mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
// 检查 workspace 子包的根版本镜像
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { listWorkspacePackagePaths, readRootPackageVersion } from "./package-version.mjs";
|
|
|
|
const workspaceDir = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
|
|
|
|
const readPackageVersion = (packagePath) => {
|
|
let manifest;
|
|
try {
|
|
manifest = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
} catch (error) {
|
|
throw new Error(`Unable to read workspace package ${packagePath}`, { cause: error });
|
|
}
|
|
return manifest?.version;
|
|
};
|
|
|
|
/** 确认所有 workspace package metadata 都是根版本的镜像。 */
|
|
export const checkPackageVersions = (rootDir = workspaceDir) => {
|
|
const rootVersion = readRootPackageVersion(rootDir);
|
|
|
|
for (const packagePath of listWorkspacePackagePaths(rootDir)) {
|
|
const packageVersion = readPackageVersion(packagePath);
|
|
if (packageVersion !== rootVersion) {
|
|
throw new Error(
|
|
`Workspace package ${packagePath} version must equal root version ${rootVersion}`,
|
|
);
|
|
}
|
|
}
|
|
|
|
console.log(`All workspace package versions match ${rootVersion}`);
|
|
};
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) checkPackageVersions();
|