test: 增加发布包运行时预检
This commit is contained in:
1 parent
16fd827634
commit
ea81c754ed
3 files changed
+63
-2
No files matched your search
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createRequire } from "node:module";
|
||||
import { checkPackage } from "./check-package.mjs";
|
||||
import { verifyRuntimePreflight } from "./runtime-preflight.mjs";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { findLeaks, loadConfig } = require("../../apps/taro/config/mask-taro.cjs");
|
||||
@@ -173,6 +174,8 @@ async function buildTemplateCatalog() {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (Number(process.versions.node.split(".")[0]) !== 24)
|
||||
throw new Error("Node.js 24 is required to build the release");
|
||||
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,100}$/.test(version))
|
||||
throw new Error("Invalid release version");
|
||||
const adminDist = path.join(root, "apps/admin/dist");
|
||||
@@ -245,6 +248,7 @@ async function main() {
|
||||
}
|
||||
await writeFile(path.join(output, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
|
||||
await checkPackage(output);
|
||||
await verifyRuntimePreflight(output);
|
||||
run("tar", ["-czf", archive, "-C", output, "."]);
|
||||
const checksum = createHash("sha256")
|
||||
.update(await readFile(archive))
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { cp, mkdtemp, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
/**
|
||||
* 在临时目录中验证发布包的运行时依赖闭包。
|
||||
* 冻结安装只能证明锁文件一致,不能证明打包时没有遗漏 workspace package。
|
||||
*/
|
||||
export async function verifyRuntimePreflight(releaseDirectory) {
|
||||
const temporary = await mkdtemp(path.join(os.tmpdir(), "personal-brand-runtime-"));
|
||||
const apiDirectory = path.join(temporary, "apps/api");
|
||||
try {
|
||||
await cp(releaseDirectory, temporary, { recursive: true });
|
||||
run(
|
||||
"pnpm",
|
||||
[
|
||||
"--filter",
|
||||
"@personal-brand/api...",
|
||||
"--filter",
|
||||
"@personal-brand/taro...",
|
||||
"--filter",
|
||||
"@personal-brand/template-acheng-campus-food",
|
||||
"--filter",
|
||||
"@personal-brand/template-linjing-editorial",
|
||||
"--filter",
|
||||
"@personal-brand/template-atelier-solopreneur",
|
||||
"install",
|
||||
"--frozen-lockfile",
|
||||
"--prefer-offline",
|
||||
"--ignore-scripts",
|
||||
],
|
||||
temporary,
|
||||
);
|
||||
run("pnpm", ["--filter", "@personal-brand/api", "exec", "prisma", "generate"], temporary);
|
||||
run(
|
||||
process.execPath,
|
||||
["--input-type=module", "-e", "await import('./dist/main.js')"],
|
||||
apiDirectory,
|
||||
{ NODE_ENV: "test" },
|
||||
);
|
||||
} finally {
|
||||
await rm(temporary, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
function run(command, args, cwd, extraEnvironment = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
cwd,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, ...extraEnvironment },
|
||||
});
|
||||
if (result.status !== 0)
|
||||
throw new Error(
|
||||
`${command} failed during release runtime preflight with exit ${result.status}`,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user