mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-23 03:58:08 +00:00
fix(plugin): require runtime build package targets
This commit is contained in:
@@ -11,16 +11,20 @@ import {
|
||||
resolvePluginNpmRuntimeBuildPlan,
|
||||
} from "./lib/plugin-npm-runtime-build.mjs";
|
||||
|
||||
function parseArgs(argv) {
|
||||
function readPackageArgValue(argv, index) {
|
||||
const value = argv[index + 1];
|
||||
if (value === undefined || value === "" || value.startsWith("--")) {
|
||||
throw new Error("missing value for --package");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseArgs(argv) {
|
||||
const packageDirs = [];
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--package") {
|
||||
const packageDir = argv[index + 1];
|
||||
if (!packageDir) {
|
||||
throw new Error("missing value for --package");
|
||||
}
|
||||
packageDirs.push(packageDir);
|
||||
packageDirs.push(readPackageArgValue(argv, index));
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -294,11 +294,16 @@ export async function buildPluginNpmRuntime(params) {
|
||||
};
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
function readPackageDirArg(argv) {
|
||||
const packageDir = argv[0];
|
||||
if (!packageDir) {
|
||||
if (!packageDir || packageDir.startsWith("--")) {
|
||||
throw new Error("usage: node scripts/lib/plugin-npm-runtime-build.mjs <package-dir>");
|
||||
}
|
||||
return packageDir;
|
||||
}
|
||||
|
||||
export function parseArgs(argv) {
|
||||
const packageDir = readPackageDirArg(argv);
|
||||
return { packageDir };
|
||||
}
|
||||
|
||||
|
||||
26
test/scripts/plugin-npm-runtime-build-args.test.ts
Normal file
26
test/scripts/plugin-npm-runtime-build-args.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseArgs as parseBulkBuildArgs } from "../../scripts/check-plugin-npm-runtime-builds.mjs";
|
||||
import { parseArgs as parseSingleBuildArgs } from "../../scripts/lib/plugin-npm-runtime-build.mjs";
|
||||
|
||||
describe("plugin npm runtime build args", () => {
|
||||
it("parses explicit plugin package build targets", () => {
|
||||
expect(
|
||||
parseBulkBuildArgs(["--package", "extensions/slack", "--package", "extensions/telegram"]),
|
||||
).toEqual({
|
||||
packageDirs: ["extensions/slack", "extensions/telegram"],
|
||||
});
|
||||
expect(parseSingleBuildArgs(["extensions/slack"])).toEqual({
|
||||
packageDir: "extensions/slack",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects missing or option-looking package targets", () => {
|
||||
expect(() => parseBulkBuildArgs(["--package"])).toThrow("missing value for --package");
|
||||
expect(() => parseBulkBuildArgs(["--package", "--package", "extensions/slack"])).toThrow(
|
||||
"missing value for --package",
|
||||
);
|
||||
expect(() => parseSingleBuildArgs(["--package"])).toThrow(
|
||||
"usage: node scripts/lib/plugin-npm-runtime-build.mjs <package-dir>",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user