Files
openclaw/scripts/run-oxlint.mjs
2026-04-23 08:44:58 -07:00

90 lines
2.3 KiB
JavaScript

import path from "node:path";
import {
acquireLocalHeavyCheckLockSync,
applyLocalOxlintPolicy,
shouldAcquireLocalHeavyCheckLockForOxlint,
} from "./lib/local-heavy-check-runtime.mjs";
import { runManagedCommand } from "./lib/managed-child-process.mjs";
const oxlintPath = path.resolve("node_modules", ".bin", "oxlint");
const PREPARE_EXTENSION_BOUNDARY_ARGS = [
path.resolve("scripts", "prepare-extension-package-boundary-artifacts.mjs"),
];
const OXLINT_PREPARE_SKIP_FLAGS = new Set([
"--help",
"-h",
"--version",
"-V",
"--print-config",
"--rules",
"--init",
"--lsp",
]);
export function shouldPrepareExtensionPackageBoundaryArtifacts(args) {
return !args.some((arg) => OXLINT_PREPARE_SKIP_FLAGS.has(arg));
}
async function prepareExtensionPackageBoundaryArtifacts(env) {
const releaseArtifactsLock = acquireLocalHeavyCheckLockSync({
cwd: process.cwd(),
env,
toolName: "extension-package-boundary-artifacts",
lockName: "extension-package-boundary-artifacts",
});
try {
const status = await runManagedCommand({
bin: process.execPath,
args: PREPARE_EXTENSION_BOUNDARY_ARGS,
env,
});
if (status !== 0) {
throw new Error(
`prepare-extension-package-boundary-artifacts failed with exit code ${status}`,
);
}
} finally {
releaseArtifactsLock();
}
}
export async function main(argv = process.argv.slice(2), runtimeEnv = process.env) {
const { args: finalArgs, env } = applyLocalOxlintPolicy(argv, runtimeEnv);
const releaseLock =
env.OPENCLAW_OXLINT_SKIP_LOCK === "1"
? () => {}
: shouldAcquireLocalHeavyCheckLockForOxlint(finalArgs, {
cwd: process.cwd(),
env,
})
? acquireLocalHeavyCheckLockSync({
cwd: process.cwd(),
env,
toolName: "oxlint",
})
: () => {};
try {
if (
env.OPENCLAW_OXLINT_SKIP_PREPARE !== "1" &&
shouldPrepareExtensionPackageBoundaryArtifacts(finalArgs)
) {
await prepareExtensionPackageBoundaryArtifacts(env);
}
const status = await runManagedCommand({
bin: oxlintPath,
args: finalArgs,
env,
});
process.exitCode = status;
} finally {
releaseLock();
}
}
if (import.meta.main) {
await main();
}