Files
openclaw/scripts/lib/package-root-args.mts
T
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

33 lines
1.2 KiB
TypeScript

// Parses package-root CLI/env overrides for package validation scripts.
import path from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
const defaultPackageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
function readPackageRootValue(value: string | undefined, optionName: string) {
if (value === undefined || value === "" || value.startsWith("-")) {
throw new Error(`${optionName} requires a value`);
}
return value;
}
/** Parse `--package-root` or an environment fallback into an absolute package root. */
export function parsePackageRootArg(argv: readonly string[], envName: string) {
let packageRoot = process.env[envName];
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === "--package-root") {
packageRoot = readPackageRootValue(argv[index + 1], arg);
index += 1;
continue;
}
if (arg?.startsWith("--package-root=")) {
packageRoot = readPackageRootValue(arg.slice("--package-root=".length), "--package-root");
continue;
}
throw new Error(`unknown argument: ${arg}`);
}
return { packageRoot: path.resolve(packageRoot ?? defaultPackageRoot) };
}