


























@@ -1,3 +1,5 @@
1+import { spawnSync } from "node:child_process";
2+import fs from "node:fs";
13import path from "node:path";
24import {
35acquireLocalHeavyCheckLockSync,
@@ -20,10 +22,105 @@ const OXLINT_PREPARE_SKIP_FLAGS = new Set([
2022"--init",
2123"--lsp",
2224]);
25+const OXLINT_VALUE_FLAGS = new Set([
26+"--config",
27+"--deny",
28+"--env",
29+"--format",
30+"--globals",
31+"--ignore-path",
32+"--max-warnings",
33+"--output-file",
34+"--plugin",
35+"--rules",
36+"--tsconfig",
37+"--warn",
38+]);
39+2340export function shouldPrepareExtensionPackageBoundaryArtifacts(args) {
2441return !args.some((arg) => OXLINT_PREPARE_SKIP_FLAGS.has(arg));
2542}
264344+export function filterSparseMissingOxlintTargets(
45+args,
46+{
47+ cwd = process.cwd(),
48+ fileExists = fs.existsSync,
49+ isSparseCheckoutEnabled = getSparseCheckoutEnabled,
50+ isTrackedPath = hasTrackedPath,
51+} = {},
52+) {
53+if (!isSparseCheckoutEnabled({ cwd })) {
54+return { args, hadExplicitTargets: false, remainingExplicitTargets: 0, skippedTargets: [] };
55+}
56+57+const filteredArgs = [];
58+const skippedTargets = [];
59+let hadExplicitTargets = false;
60+let remainingExplicitTargets = 0;
61+let consumeNextValue = false;
62+63+for (const arg of args) {
64+if (consumeNextValue) {
65+filteredArgs.push(arg);
66+consumeNextValue = false;
67+continue;
68+}
69+70+if (arg === "--") {
71+filteredArgs.push(arg);
72+continue;
73+}
74+75+if (arg.startsWith("--")) {
76+filteredArgs.push(arg);
77+if (!arg.includes("=") && OXLINT_VALUE_FLAGS.has(arg)) {
78+consumeNextValue = true;
79+}
80+continue;
81+}
82+83+if (arg.startsWith("-")) {
84+filteredArgs.push(arg);
85+continue;
86+}
87+88+hadExplicitTargets = true;
89+const absoluteTarget = path.resolve(cwd, arg);
90+if (!fileExists(absoluteTarget) && isTrackedPath({ cwd, target: arg })) {
91+skippedTargets.push(arg);
92+continue;
93+}
94+95+remainingExplicitTargets += 1;
96+filteredArgs.push(arg);
97+}
98+99+return { args: filteredArgs, hadExplicitTargets, remainingExplicitTargets, skippedTargets };
100+}
101+102+function getSparseCheckoutEnabled({ cwd }) {
103+const result = spawnSync("git", ["config", "--get", "--bool", "core.sparseCheckout"], {
104+ cwd,
105+encoding: "utf8",
106+stdio: ["ignore", "pipe", "pipe"],
107+shell: process.platform === "win32",
108+});
109+110+return result.status === 0 && result.stdout.trim() === "true";
111+}
112+113+function hasTrackedPath({ cwd, target }) {
114+const result = spawnSync("git", ["ls-files", "--", target], {
115+ cwd,
116+encoding: "utf8",
117+stdio: ["ignore", "pipe", "pipe"],
118+shell: process.platform === "win32",
119+});
120+121+return result.status === 0 && result.stdout.trim().length > 0;
122+}
123+27124async function prepareExtensionPackageBoundaryArtifacts(env) {
28125const releaseArtifactsLock = acquireLocalHeavyCheckLockSync({
29126cwd: process.cwd(),
@@ -50,7 +147,19 @@ async function prepareExtensionPackageBoundaryArtifacts(env) {
50147}
5114852149export async function main(argv = process.argv.slice(2), runtimeEnv = process.env) {
53-const { args: finalArgs, env } = applyLocalOxlintPolicy(argv, runtimeEnv);
150+const { args: policyArgs, env } = applyLocalOxlintPolicy(argv, runtimeEnv);
151+const sparseTargets = filterSparseMissingOxlintTargets(policyArgs);
152+const finalArgs = sparseTargets.args;
153+if (sparseTargets.skippedTargets.length > 0) {
154+console.error(
155+`[oxlint] sparse checkout is missing tracked target(s); skipping ${sparseTargets.skippedTargets.join(", ")}`,
156+);
157+}
158+if (sparseTargets.hadExplicitTargets && sparseTargets.remainingExplicitTargets === 0) {
159+console.error("[oxlint] no present sparse-checkout targets remain; skipping oxlint.");
160+return;
161+}
162+54163const releaseLock =
55164env.OPENCLAW_OXLINT_SKIP_LOCK === "1"
56165 ? () => {}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。