From c9103c2e47dc2d46846b35a93abc2ccfd7be54dd Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 16 Apr 2026 13:50:23 -0700 Subject: [PATCH] fix(ci): prepare plugin sdk dts before lint --- scripts/run-oxlint.mjs | 98 +++++++++++++++++++++++++-------- test/scripts/run-oxlint.test.ts | 17 ++++++ 2 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 test/scripts/run-oxlint.test.ts diff --git a/scripts/run-oxlint.mjs b/scripts/run-oxlint.mjs index 2abe1b39a73..8de46f85d01 100644 --- a/scripts/run-oxlint.mjs +++ b/scripts/run-oxlint.mjs @@ -6,32 +6,86 @@ import { shouldAcquireLocalHeavyCheckLockForOxlint, } from "./lib/local-heavy-check-runtime.mjs"; -const { args: finalArgs, env } = applyLocalOxlintPolicy(process.argv.slice(2), process.env); - const oxlintPath = path.resolve("node_modules", ".bin", "oxlint"); -const releaseLock = shouldAcquireLocalHeavyCheckLockForOxlint(finalArgs, { - cwd: process.cwd(), - env, -}) - ? acquireLocalHeavyCheckLockSync({ - cwd: process.cwd(), - env, - toolName: "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)); +} -try { - const result = spawnSync(oxlintPath, finalArgs, { - stdio: "inherit", +function prepareExtensionPackageBoundaryArtifacts(env) { + const releaseArtifactsLock = acquireLocalHeavyCheckLockSync({ + cwd: process.cwd(), env, - shell: process.platform === "win32", + toolName: "extension-package-boundary-artifacts", + lockName: "extension-package-boundary-artifacts", }); - if (result.error) { - throw result.error; - } + try { + const result = spawnSync(process.execPath, PREPARE_EXTENSION_BOUNDARY_ARGS, { + stdio: "inherit", + env, + }); - process.exitCode = result.status ?? 1; -} finally { - releaseLock(); + if (result.error) { + throw result.error; + } + + if ((result.status ?? 1) !== 0) { + throw new Error( + `prepare-extension-package-boundary-artifacts failed with exit code ${result.status ?? 1}`, + ); + } + } finally { + releaseArtifactsLock(); + } +} + +export function main(argv = process.argv.slice(2), runtimeEnv = process.env) { + const { args: finalArgs, env } = applyLocalOxlintPolicy(argv, runtimeEnv); + const releaseLock = shouldAcquireLocalHeavyCheckLockForOxlint(finalArgs, { + cwd: process.cwd(), + env, + }) + ? acquireLocalHeavyCheckLockSync({ + cwd: process.cwd(), + env, + toolName: "oxlint", + }) + : () => {}; + + try { + if (shouldPrepareExtensionPackageBoundaryArtifacts(finalArgs)) { + prepareExtensionPackageBoundaryArtifacts(env); + } + + const result = spawnSync(oxlintPath, finalArgs, { + stdio: "inherit", + env, + shell: process.platform === "win32", + }); + + if (result.error) { + throw result.error; + } + + process.exitCode = result.status ?? 1; + } finally { + releaseLock(); + } +} + +if (import.meta.main) { + main(); } diff --git a/test/scripts/run-oxlint.test.ts b/test/scripts/run-oxlint.test.ts new file mode 100644 index 00000000000..461a3364e3c --- /dev/null +++ b/test/scripts/run-oxlint.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from "vitest"; +import { shouldPrepareExtensionPackageBoundaryArtifacts } from "../../scripts/run-oxlint.mjs"; + +describe("run-oxlint", () => { + it("prepares extension package boundary artifacts for normal lint runs", () => { + expect(shouldPrepareExtensionPackageBoundaryArtifacts([])).toBe(true); + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["src/index.ts"])).toBe(true); + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["--type-aware"])).toBe(true); + }); + + it("skips artifact preparation for metadata-only oxlint commands", () => { + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["--help"])).toBe(false); + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["--version"])).toBe(false); + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["--print-config"])).toBe(false); + expect(shouldPrepareExtensionPackageBoundaryArtifacts(["--rules"])).toBe(false); + }); +});