|
9 | 9 | rmSync, |
10 | 10 | writeFileSync, |
11 | 11 | } from "node:fs"; |
| 12 | +import { createRequire } from "node:module"; |
12 | 13 | import { tmpdir } from "node:os"; |
13 | 14 | import path from "node:path"; |
14 | 15 | import { performance } from "node:perf_hooks"; |
@@ -113,6 +114,7 @@ const SHRINK_RATCHET_OWNER_PATH = "scripts/lib/shrink-ratchet.mts"; |
113 | 114 | const CORE_OXLINT_TS_CONFIG = "config/tsconfig/oxlint.core.json"; |
114 | 115 | const EXTENSIONS_OXLINT_TS_CONFIG = "extensions/tsconfig.json"; |
115 | 116 | const SCRIPTS_OXLINT_TS_CONFIG = "config/tsconfig/oxlint.scripts.json"; |
| 117 | +const ROOT_TEST_TS_CONFIG = "test/tsconfig/tsconfig.test.root.json"; |
116 | 118 | const TARGETED_LINT_PATH_LIMIT = 8; |
117 | 119 | const LINTABLE_CORE_PATH_RE = /^(?:src|ui|packages)\/.+\.[cm]?[jt]sx?$/u; |
118 | 120 | const LINTABLE_EXTENSION_PATH_RE = /^extensions\/[^/]+\/.+\.[cm]?[jt]sx?$/u; |
@@ -495,6 +497,42 @@ export function createChangedCheckPlan( |
495 | 497 | const addTypecheck = (name: string, args: string[]) => |
496 | 498 | typechecks.add(add(name, args, createSparseTsgoSkipEnv(baseEnv))); |
497 | 499 | const finishPlan = (summary: string) => { |
| 500 | + // Full lint shards exclude test/. Keep changed root sources covered even |
| 501 | + // when another path selects the all-lane early return, without widening lint. |
| 502 | + let rootTestTargets = result.paths.filter( |
| 503 | + (file) => getChangedPathFacts(file).isRootTestSource && existsSync(file), |
| 504 | + ); |
| 505 | + if (rootTestTargets.length > 0) { |
| 506 | + // --tsconfig affects import resolution, not native semantic discovery or |
| 507 | + // target selection. Expand the canonical roots before passing explicit files. |
| 508 | + const ts = createRequire(import.meta.url)("typescript") as typeof import("typescript"); |
| 509 | + const config = ts.getParsedCommandLineOfConfigFile( |
| 510 | + path.resolve(ROOT_TEST_TS_CONFIG), |
| 511 | + {}, |
| 512 | + { |
| 513 | + ...ts.sys, |
| 514 | + onUnRecoverableConfigFileDiagnostic(diagnostic) { |
| 515 | + throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")); |
| 516 | + }, |
| 517 | + }, |
| 518 | + ); |
| 519 | + if (!config || config.errors.length > 0) { |
| 520 | + throw new Error( |
| 521 | + `Invalid ${ROOT_TEST_TS_CONFIG}: ${config?.errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n")}`, |
| 522 | + ); |
| 523 | + } |
| 524 | + const roots = new Set(config.fileNames.map((file) => path.resolve(file))); |
| 525 | + rootTestTargets = rootTestTargets.filter((file) => roots.has(path.resolve(file))); |
| 526 | + } |
| 527 | + for (let offset = 0; offset < rootTestTargets.length; offset += TARGETED_LINT_PATH_LIMIT) { |
| 528 | + const batch = rootTestTargets.slice(offset, offset + TARGETED_LINT_PATH_LIMIT); |
| 529 | + addCommand( |
| 530 | + batch.length === 1 ? "lint test root changed file" : "lint test root changed files", |
| 531 | + "node", |
| 532 | + ["scripts/run-oxlint.mjs", "--tsconfig", ROOT_TEST_TS_CONFIG, ...batch], |
| 533 | + baseEnv, |
| 534 | + ); |
| 535 | + } |
498 | 536 | const end = commands.findLastIndex((command) => typechecks.has(command)) + 1; |
499 | 537 | const prefix = commands.slice(0, end); |
500 | 538 | // These audits produce diagnostics, not compiler inputs. Defer them without |
@@ -1012,6 +1050,7 @@ function createTargetedOxlintCommand({ |
1012 | 1050 | !LINTABLE_CORE_PATH_RE.test(changedPath) && |
1013 | 1051 | !LINTABLE_EXTENSION_PATH_RE.test(changedPath) && |
1014 | 1052 | !LINTABLE_SCRIPT_PATH_RE.test(changedPath) && |
| 1053 | + !getChangedPathFacts(changedPath).isRootTestSource && |
1015 | 1054 | !neutralPathRe.test(changedPath) && |
1016 | 1055 | !MARKDOWN_LINT_OPTIMIZATION_NEUTRAL_PATH_RE.test(changedPath), |
1017 | 1056 | ) |
|
0 commit comments