mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
fix(release): validate package dist check args
This commit is contained in:
parent
1a5d84d3fe
commit
80d3b132a5
3 changed files with 79 additions and 3 deletions
|
|
@ -13,11 +13,37 @@ function fail(message) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
const packageRoot = path.resolve(process.argv[2] ?? process.cwd());
|
||||
if (process.argv.length > 3) {
|
||||
fail(usage());
|
||||
function parseArgs(argv) {
|
||||
const args = argv[0] === "--" ? argv.slice(1) : argv;
|
||||
const packageRootArg = args[0]?.trim() ?? "";
|
||||
if (packageRootArg === "--help" || packageRootArg === "-h") {
|
||||
return { help: true, packageRoot: "" };
|
||||
}
|
||||
if (packageRootArg.startsWith("-")) {
|
||||
throw new Error(`Unknown package dist import check option: ${packageRootArg}`);
|
||||
}
|
||||
const extraArg = args[1]?.trim();
|
||||
if (extraArg) {
|
||||
throw new Error(`Unexpected package dist import check argument: ${extraArg}`);
|
||||
}
|
||||
return {
|
||||
help: false,
|
||||
packageRoot: path.resolve(packageRootArg || process.cwd()),
|
||||
};
|
||||
}
|
||||
|
||||
let cliArgs;
|
||||
try {
|
||||
cliArgs = parseArgs(process.argv.slice(2));
|
||||
} catch (error) {
|
||||
fail(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
if (cliArgs.help) {
|
||||
console.log(usage());
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const { packageRoot } = cliArgs;
|
||||
const distRoot = path.join(packageRoot, "dist");
|
||||
if (!fs.existsSync(distRoot)) {
|
||||
fail(`missing dist directory: ${distRoot}`);
|
||||
|
|
|
|||
|
|
@ -746,6 +746,7 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
|
|||
"scripts/check-openclaw-package-tarball.mjs",
|
||||
["test/scripts/check-openclaw-package-tarball.test.ts"],
|
||||
],
|
||||
["scripts/check-package-dist-imports.mjs", ["test/scripts/check-package-dist-imports.test.ts"]],
|
||||
["scripts/package-changelog.mjs", ["test/scripts/package-changelog.test.ts"]],
|
||||
["scripts/package-mac-app.sh", ["test/scripts/package-mac-app.test.ts"]],
|
||||
["scripts/package-mac-dist.sh", ["test/scripts/package-mac-dist.test.ts"]],
|
||||
|
|
|
|||
49
test/scripts/check-package-dist-imports.test.ts
Normal file
49
test/scripts/check-package-dist-imports.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { spawnSync } from "node:child_process";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
|
||||
|
||||
const CHECK_SCRIPT = "scripts/check-package-dist-imports.mjs";
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
cleanupTempDirs(tempDirs);
|
||||
});
|
||||
|
||||
describe("check-package-dist-imports", () => {
|
||||
it("prints help before reading package state", () => {
|
||||
const result = spawnSync("node", [CHECK_SCRIPT, "--help"], { encoding: "utf8" });
|
||||
|
||||
expect(result.status, result.stderr).toBe(0);
|
||||
expect(result.stdout).toContain(
|
||||
"Usage: node scripts/check-package-dist-imports.mjs [package-root]",
|
||||
);
|
||||
expect(result.stderr).toBe("");
|
||||
});
|
||||
|
||||
it("rejects option-like and extra arguments before dist scanning", () => {
|
||||
const unknown = spawnSync("node", [CHECK_SCRIPT, "--tag"], { encoding: "utf8" });
|
||||
|
||||
expect(unknown.status).not.toBe(0);
|
||||
expect(unknown.stderr).toContain("Unknown package dist import check option: --tag");
|
||||
expect(unknown.stderr).not.toContain("missing dist directory");
|
||||
|
||||
const extra = spawnSync("node", [CHECK_SCRIPT, ".", "extra"], { encoding: "utf8" });
|
||||
|
||||
expect(extra.status).not.toBe(0);
|
||||
expect(extra.stderr).toContain("Unexpected package dist import check argument: extra");
|
||||
expect(extra.stderr).not.toContain("missing dist directory");
|
||||
});
|
||||
|
||||
it("accepts a minimal package dist root", () => {
|
||||
const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-");
|
||||
mkdirSync(join(root, "dist"), { recursive: true });
|
||||
writeFileSync(join(root, "dist", "index.js"), "export {};\n", "utf8");
|
||||
|
||||
const result = spawnSync("node", [CHECK_SCRIPT, root], { encoding: "utf8" });
|
||||
|
||||
expect(result.status, result.stderr).toBe(0);
|
||||
expect(result.stdout).toContain("OpenClaw package dist import closure passed.");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue