@ariestools/toolchain 9.0.2 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/xy.mjs CHANGED
@@ -24,7 +24,9 @@ import { performance as performance$1 } from "node:perf_hooks";
24
24
  import util, { promisify, stripVTControlCharacters } from "node:util";
25
25
  import ts from "typescript";
26
26
  import { createHash, randomBytes } from "node:crypto";
27
- import { applyRecommendedConfigTypeChecked, parseRecommendedConfigSource } from "@ariestools/eslint-config-flat";
27
+ import { ESLint } from "eslint";
28
+ import { applyRecommendedConfigTypeChecked, collectTypeCheckedRuleNames, getRuleSeverity, parseRecommendedConfigSource } from "@ariestools/eslint-config-flat";
29
+ import { includeIgnoreFile } from "eslint/config";
28
30
  import { pipeline } from "node:stream/promises";
29
31
  import zlib from "node:zlib";
30
32
  import { builtinRules } from "eslint/use-at-your-own-risk";
@@ -25691,21 +25693,16 @@ function isInPackageSubdirectory(pkg, fileName, directoryName) {
25691
25693
  return relative !== "" && !relative.startsWith("../") && relative !== "..";
25692
25694
  }
25693
25695
  /**
25694
- * Validates one package in-process, reproducing exactly the program that
25695
- * `package-compile --validate-only` runs via `tsc -p`: the package's own
25696
- * tsconfig (its `lib`, `jsx`, `types`, `paths` — every option is the
25697
- * package's own), the same file set (tsconfig includes minus nested
25698
- * workspace dirs), with `noEmit` and `rootDir` overridden the same way.
25699
- * Only the compiler *host* is shared, for SourceFile reuse across packages.
25696
+ Create one package-specific TypeScript Program while reusing immutable parsed
25697
+ SourceFiles from earlier packages in the same process. Compiler options and the
25698
+ semantic Program remain package-specific.
25700
25699
  */
25701
- function validateWorkspaceInProcess(workspaceDir, cache) {
25700
+ function createWorkspaceProgramInProcess(workspaceDir, cache) {
25702
25701
  const pkg = PATH.resolve(workspaceDir);
25703
25702
  const tsconfigPath = PATH.join(pkg, "tsconfig.json");
25704
25703
  if (!fs.existsSync(tsconfigPath)) return {
25705
- errorCount: 0,
25706
- fileCount: 0,
25707
- formatted: "",
25708
- skipped: "no-tsconfig"
25704
+ kind: "skipped",
25705
+ reason: "no-tsconfig"
25709
25706
  };
25710
25707
  const formatHost = {
25711
25708
  getCanonicalFileName: (fileName) => fileName,
@@ -25715,14 +25712,14 @@ function validateWorkspaceInProcess(workspaceDir, cache) {
25715
25712
  const configFile = ts.readConfigFile(tsconfigPath, (fileName) => ts.sys.readFile(fileName));
25716
25713
  if (configFile.error) return {
25717
25714
  errorCount: 1,
25718
- fileCount: 0,
25719
- formatted: ts.formatDiagnosticsWithColorAndContext([configFile.error], formatHost)
25715
+ formatted: ts.formatDiagnosticsWithColorAndContext([configFile.error], formatHost),
25716
+ kind: "error"
25720
25717
  };
25721
25718
  const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, pkg, void 0, tsconfigPath);
25722
25719
  if (parsed.errors.length > 0) return {
25723
25720
  errorCount: parsed.errors.length,
25724
- fileCount: 0,
25725
- formatted: ts.formatDiagnosticsWithColorAndContext(parsed.errors, formatHost)
25721
+ formatted: ts.formatDiagnosticsWithColorAndContext(parsed.errors, formatHost),
25722
+ kind: "error"
25726
25723
  };
25727
25724
  const rootNames = parsed.fileNames.filter((fileName) => !isInPackageSubdirectory(pkg, fileName, "packages"));
25728
25725
  const options = {
@@ -25730,16 +25727,46 @@ function validateWorkspaceInProcess(workspaceDir, cache) {
25730
25727
  noEmit: true,
25731
25728
  rootDir: pkg
25732
25729
  };
25733
- const program = ts.createProgram({
25734
- host: createSharedHost(options, cache),
25735
- options,
25730
+ return {
25731
+ kind: "ready",
25732
+ program: ts.createProgram({
25733
+ host: createSharedHost(options, cache),
25734
+ options,
25735
+ rootNames
25736
+ }),
25736
25737
  rootNames
25737
- });
25738
- const diagnostics = ts.getPreEmitDiagnostics(program);
25738
+ };
25739
+ }
25740
+ /**
25741
+ * Validates one package in-process, reproducing exactly the program that
25742
+ * `package-compile --validate-only` runs via `tsc -p`: the package's own
25743
+ * tsconfig (its `lib`, `jsx`, `types`, `paths` — every option is the
25744
+ * package's own), the same file set (tsconfig includes minus nested
25745
+ * workspace dirs), with `noEmit` and `rootDir` overridden the same way.
25746
+ * Only the compiler *host* is shared, for SourceFile reuse across packages.
25747
+ */
25748
+ function validateWorkspaceInProcess(workspaceDir, cache) {
25749
+ const result = createWorkspaceProgramInProcess(workspaceDir, cache);
25750
+ if (result.kind === "skipped") return {
25751
+ errorCount: 0,
25752
+ fileCount: 0,
25753
+ formatted: "",
25754
+ skipped: "no-tsconfig"
25755
+ };
25756
+ if (result.kind === "error") return {
25757
+ errorCount: result.errorCount,
25758
+ fileCount: 0,
25759
+ formatted: result.formatted
25760
+ };
25761
+ const diagnostics = ts.getPreEmitDiagnostics(result.program);
25739
25762
  return {
25740
25763
  errorCount: diagnostics.filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error).length,
25741
- fileCount: rootNames.length,
25742
- formatted: diagnostics.length > 0 ? ts.formatDiagnosticsWithColorAndContext(diagnostics, formatHost) : ""
25764
+ fileCount: result.rootNames.length,
25765
+ formatted: diagnostics.length > 0 ? ts.formatDiagnosticsWithColorAndContext(diagnostics, {
25766
+ getCanonicalFileName: (fileName) => fileName,
25767
+ getCurrentDirectory: () => PATH.resolve(workspaceDir),
25768
+ getNewLine: () => ts.sys.newLine
25769
+ }) : ""
25743
25770
  };
25744
25771
  }
25745
25772
  //#endregion
@@ -31249,6 +31276,32 @@ const deplintPick = async ({ classifier, jobs, pkg, verbose } = {}) => {
31249
31276
  return emptyPickResult(rows.length, decisions.length, changedFiles);
31250
31277
  };
31251
31278
  //#endregion
31279
+ //#region src/actions/lintMode.ts
31280
+ const lintModes = [
31281
+ "package-workers",
31282
+ "shared-typecheck",
31283
+ "workspace-eslint"
31284
+ ];
31285
+ const defaultLintMode = "package-workers";
31286
+ /**
31287
+ Resolve the named lint implementation while preserving the two historical
31288
+ boolean selectors as hidden transition aliases.
31289
+ */
31290
+ function resolveLintMode({ mode = defaultLintMode, next = false, prev = false }) {
31291
+ if (next && prev) throw new Error("--next and --prev cannot be combined; use --mode instead");
31292
+ const legacyMode = next ? "package-workers" : prev ? "workspace-eslint" : void 0;
31293
+ if (legacyMode !== void 0 && mode !== "package-workers" && mode !== legacyMode) throw new Error(`--mode ${mode} cannot be combined with ${next ? "--next" : "--prev"}`);
31294
+ if (next) return {
31295
+ legacyOption: "--next",
31296
+ mode: "package-workers"
31297
+ };
31298
+ if (prev) return {
31299
+ legacyOption: "--prev",
31300
+ mode: "workspace-eslint"
31301
+ };
31302
+ return { mode };
31303
+ }
31304
+ //#endregion
31252
31305
  //#region src/actions/lintNextWorker.ts
31253
31306
  const lintNextIgnorePatterns = ["packages/**"];
31254
31307
  const lintNextResultMarker = "__XY_LINT_NEXT_RESULT__";
@@ -31349,8 +31402,24 @@ function gitignoreOverrideBlock(options) {
31349
31402
  })
31350
31403
  }
31351
31404
 
31405
+ function structuralOverrideBlock(options) {
31406
+ if (options.phase !== 'structural') return undefined
31407
+ const rules = Object.fromEntries((options.typeCheckedRuleNames ?? []).map(ruleName => [ruleName, 'off']))
31408
+ return {
31409
+ files: cycleRuleFilePatterns,
31410
+ languageOptions: {
31411
+ parserOptions: {
31412
+ programs: null,
31413
+ project: false,
31414
+ projectService: false,
31415
+ },
31416
+ },
31417
+ rules,
31418
+ }
31419
+ }
31420
+
31352
31421
  function additionalOverrideBlocks(options) {
31353
- return [gitignoreOverrideBlock(options), cycleOverrideBlock(options)].filter(Boolean)
31422
+ return [gitignoreOverrideBlock(options), structuralOverrideBlock(options), cycleOverrideBlock(options)].filter(Boolean)
31354
31423
  }
31355
31424
 
31356
31425
  async function createLintEngine(cwd, options) {
@@ -31358,10 +31427,12 @@ async function createLintEngine(cwd, options) {
31358
31427
  const overrideSpec = options.configOverride ?? options.analyzeTier
31359
31428
  if (overrideSpec) {
31360
31429
  const gitignoreBlock = gitignoreOverrideBlock(options)
31430
+ const structuralBlock = structuralOverrideBlock(options)
31361
31431
  const cycleBlock = cycleOverrideBlock(options)
31362
31432
  const overrideConfig = [
31363
31433
  ...(gitignoreBlock === undefined ? [] : [gitignoreBlock]),
31364
31434
  ...await resolveAnalyzeOverrideConfig(cwd, overrideSpec),
31435
+ ...(structuralBlock === undefined ? [] : [structuralBlock]),
31365
31436
  ...(cycleBlock === undefined ? [] : [cycleBlock]),
31366
31437
  ]
31367
31438
  return new ESLint({
@@ -31821,7 +31892,7 @@ function emptyPackageResult(pkg) {
31821
31892
  * Classify packages, skip empty/meta as configured, then lint the rest via
31822
31893
  * the persistent ESLint worker pool.
31823
31894
  */
31824
- async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, gitignore, meta, onPackageResult, profile, rootDir, skipEmpty, tierContext, typeChecked, verbose, workspaces }) {
31895
+ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, cycleDepth, fix, gitignore, meta, onPackageResult, phase = "full", profile, rootDir, skipEmpty, tierContext, typeChecked, typeCheckedRuleNames, verbose, workspaces }) {
31825
31896
  const forceFull = workspaces.length === 1;
31826
31897
  const classified = workspaces.map((ws) => {
31827
31898
  return {
@@ -31874,7 +31945,9 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
31874
31945
  fix,
31875
31946
  gitignore,
31876
31947
  gitignorePath,
31948
+ phase,
31877
31949
  profile,
31950
+ typeCheckedRuleNames,
31878
31951
  verbose
31879
31952
  }
31880
31953
  });
@@ -31902,6 +31975,370 @@ async function runLintNextPackages({ analyze, analyzeTier, cache, concurrency, c
31902
31975
  return [...skippedResults, ...lintResults];
31903
31976
  }
31904
31977
  //#endregion
31978
+ //#region src/actions/lintSharedTypecheckRules.ts
31979
+ init_index_min();
31980
+ const sharedTypecheckScriptPatterns = [
31981
+ "**/*.ts",
31982
+ "**/*.tsx",
31983
+ "**/*.mts",
31984
+ "**/*.cts",
31985
+ "**/*.js",
31986
+ "**/*.jsx",
31987
+ "**/*.cjs",
31988
+ "**/*.mjs",
31989
+ "**/*.d.ts",
31990
+ "**/*.d.tsx",
31991
+ "**/*.d.jsx",
31992
+ "**/*.d.mts",
31993
+ "**/*.d.cts"
31994
+ ];
31995
+ const packageIgnorePatterns = [
31996
+ "packages/**",
31997
+ "**/build/**",
31998
+ "**/dist/**",
31999
+ "**/node_modules/**"
32000
+ ];
32001
+ function configPackageName(configOverride) {
32002
+ return configOverride.configPackageName ?? (configOverride.isReact ? "@ariestools/eslint-config-react-flat" : "@ariestools/eslint-config-flat");
32003
+ }
32004
+ function mergeRules(configs) {
32005
+ const rules = {};
32006
+ for (const config of configs) Object.assign(rules, config.rules);
32007
+ return rules;
32008
+ }
32009
+ function isEnabledRule(entry) {
32010
+ const severity = getRuleSeverity(entry);
32011
+ return severity !== void 0 && severity !== "off";
32012
+ }
32013
+ async function resolveManagedTypeCheckedRuleNames(rootDir, configOverride) {
32014
+ const result = new Set(collectTypeCheckedRuleNames());
32015
+ if (configOverride === void 0) return result;
32016
+ const resolved = createRequire(PATH.join(rootDir, "package.json")).resolve(configPackageName(configOverride));
32017
+ const configPackage = await import(pathToFileURL(resolved).href);
32018
+ if (configPackage.recommendedConfig === void 0) return result;
32019
+ const common = { tier: configOverride.tier };
32020
+ const checked = mergeRules(configPackage.recommendedConfig({
32021
+ ...common,
32022
+ isTypeChecked: true
32023
+ }));
32024
+ const unchecked = mergeRules(configPackage.recommendedConfig({
32025
+ ...common,
32026
+ isTypeChecked: false
32027
+ }));
32028
+ for (const [ruleName, entry] of Object.entries(checked)) if (isEnabledRule(entry) && !isEnabledRule(unchecked[ruleName])) result.add(ruleName);
32029
+ return result;
32030
+ }
32031
+ async function resolveConfigOverride(cwd, configOverride) {
32032
+ const resolved = createRequire(PATH.join(cwd, "package.json")).resolve(configPackageName(configOverride));
32033
+ const configPackage = await import(pathToFileURL(resolved).href);
32034
+ if (configPackage.recommendedConfig !== void 0) return configPackage.recommendedConfig({
32035
+ isTypeChecked: configOverride.isTypeChecked,
32036
+ tier: configOverride.tier
32037
+ });
32038
+ const configs = configPackage[configOverride.exportName];
32039
+ if (!Array.isArray(configs)) throw new TypeError(`Missing ESLint tier export "${configOverride.exportName}"`);
32040
+ return configs;
32041
+ }
32042
+ async function baseSharedTypecheckConfigs(cwd, configOverride, gitignorePath) {
32043
+ const ignored = gitignorePath === void 0 ? void 0 : includeIgnoreFile(gitignorePath, {
32044
+ gitignoreResolution: true,
32045
+ name: "XY repository .gitignore"
32046
+ });
32047
+ if (configOverride === void 0) return { configs: ignored === void 0 ? [] : [ignored] };
32048
+ return {
32049
+ configs: [...ignored === void 0 ? [] : [ignored], ...await resolveConfigOverride(cwd, configOverride)],
32050
+ overrideConfigFile: true
32051
+ };
32052
+ }
32053
+ function sharedTypecheckEslintOptions({ configs, cwd, fix, overrideConfigFile }) {
32054
+ return {
32055
+ cache: false,
32056
+ cwd,
32057
+ fix,
32058
+ ignorePatterns: ["packages/**"],
32059
+ overrideConfig: configs,
32060
+ ...overrideConfigFile !== void 0 && { overrideConfigFile },
32061
+ warnIgnored: false
32062
+ };
32063
+ }
32064
+ function ruleRequiresTypeChecking(config, ruleName) {
32065
+ const slash = ruleName.lastIndexOf("/");
32066
+ if (slash <= 0) return false;
32067
+ const pluginName = ruleName.slice(0, slash);
32068
+ const localRuleName = ruleName.slice(slash + 1);
32069
+ return ((config.plugins?.[pluginName])?.rules?.[localRuleName])?.meta?.docs?.requiresTypeChecking === true;
32070
+ }
32071
+ function collectActiveRules(config, plan) {
32072
+ const entries = Object.entries(config.rules ?? {});
32073
+ for (const [ruleName, entry] of entries) {
32074
+ if (!isEnabledRule(entry)) continue;
32075
+ plan.activeRuleNames.add(ruleName);
32076
+ if (ruleRequiresTypeChecking(config, ruleName)) plan.typeCheckedRuleNames.add(ruleName);
32077
+ }
32078
+ }
32079
+ async function inspectPackageRules({ configOverride, cwd, gitignorePath, knownTypeCheckedRuleNames }) {
32080
+ const base = await baseSharedTypecheckConfigs(cwd, configOverride, gitignorePath);
32081
+ const engine = new ESLint(sharedTypecheckEslintOptions({
32082
+ configs: base.configs,
32083
+ cwd,
32084
+ fix: false,
32085
+ overrideConfigFile: base.overrideConfigFile
32086
+ }));
32087
+ const candidates = ts$1(sharedTypecheckScriptPatterns, {
32088
+ absolute: true,
32089
+ cwd,
32090
+ ignore: packageIgnorePatterns,
32091
+ nodir: true
32092
+ });
32093
+ const plan = {
32094
+ activeRuleNames: /* @__PURE__ */ new Set(),
32095
+ typeCheckedRuleNames: new Set(knownTypeCheckedRuleNames)
32096
+ };
32097
+ for (const file of candidates) {
32098
+ const config = await engine.calculateConfigForFile(file);
32099
+ if (config !== void 0) collectActiveRules(config, plan);
32100
+ }
32101
+ return plan;
32102
+ }
32103
+ async function withSharedTypecheckGitignore(gitignore, action) {
32104
+ const previous = process.env.XY_LINT_GITIGNORE;
32105
+ process.env.XY_LINT_GITIGNORE = gitignore ? "true" : "false";
32106
+ try {
32107
+ return await action();
32108
+ } finally {
32109
+ if (previous === void 0) delete process.env.XY_LINT_GITIGNORE;
32110
+ else process.env.XY_LINT_GITIGNORE = previous;
32111
+ }
32112
+ }
32113
+ async function inspectSharedTypecheckRulePlans({ analyze, analyzeTier, gitignore, rootDir, tierContext, typeChecked, workspaces }) {
32114
+ const configOverride = resolvePackageConfigOverride(typeChecked, analyze ? void 0 : tierContext, analyzeTier);
32115
+ const known = await resolveManagedTypeCheckedRuleNames(rootDir, configOverride ?? (tierContext?.hasXylabsConfig === true ? buildForcedConfigOverride(tierContext, true) : void 0));
32116
+ const repositoryGitignore = PATH.resolve(rootDir, ".gitignore");
32117
+ const gitignorePath = gitignore && existsSync(repositoryGitignore) ? repositoryGitignore : void 0;
32118
+ const plans = /* @__PURE__ */ new Map();
32119
+ const allTypeCheckedRuleNames = new Set(known);
32120
+ await withSharedTypecheckGitignore(gitignore, async () => {
32121
+ for (const workspace of workspaces) {
32122
+ const plan = await inspectPackageRules({
32123
+ configOverride,
32124
+ cwd: PATH.resolve(rootDir, workspace.location),
32125
+ gitignorePath,
32126
+ knownTypeCheckedRuleNames: known
32127
+ });
32128
+ plans.set(workspace.name, plan);
32129
+ for (const ruleName of plan.typeCheckedRuleNames) allTypeCheckedRuleNames.add(ruleName);
32130
+ }
32131
+ });
32132
+ return {
32133
+ allTypeCheckedRuleNames: [...allTypeCheckedRuleNames],
32134
+ plans
32135
+ };
32136
+ }
32137
+ //#endregion
32138
+ //#region src/actions/lintSharedTypecheck.ts
32139
+ const scriptExtensionPattern = /\.(?:[cm]?[jt]s|[jt]sx)$/u;
32140
+ function lintableWorkspaces({ meta, rootDir, skipEmpty, workspaces }) {
32141
+ const forceFull = workspaces.length === 1;
32142
+ return workspaces.filter((workspace) => {
32143
+ return classifyLintPackage(rootDir, workspace, workspaces, {
32144
+ forceFull,
32145
+ meta,
32146
+ skipEmpty
32147
+ }).mode !== "skip";
32148
+ });
32149
+ }
32150
+ function emptySemanticResult(pkg) {
32151
+ return {
32152
+ errors: 0,
32153
+ files: 0,
32154
+ messages: [],
32155
+ output: "",
32156
+ pkg,
32157
+ timeMs: 0,
32158
+ warnings: 0
32159
+ };
32160
+ }
32161
+ function failedSemanticResult(pkg, output, timeMs) {
32162
+ return {
32163
+ errors: 1,
32164
+ files: 0,
32165
+ messages: [],
32166
+ output,
32167
+ pkg,
32168
+ timeMs,
32169
+ warnings: 0
32170
+ };
32171
+ }
32172
+ async function lintSemanticPackage({ analyze, configOverride, fix, gitignore, gitignorePath, profile, rulePlan, sharedCache, verbose, workspace }) {
32173
+ const started = performance$1.now();
32174
+ const programResult = createWorkspaceProgramInProcess(workspace.location, sharedCache);
32175
+ if (programResult.kind === "skipped") return failedSemanticResult(workspace.name, `Shared typecheck [${workspace.name}] requires ${PATH.join(workspace.location, "tsconfig.json")}\n`, Math.round(performance$1.now() - started));
32176
+ if (programResult.kind === "error") return failedSemanticResult(workspace.name, programResult.formatted, Math.round(performance$1.now() - started));
32177
+ const lintFiles = programResult.rootNames.filter((fileName) => scriptExtensionPattern.test(fileName));
32178
+ if (lintFiles.length === 0) return emptySemanticResult(workspace.name);
32179
+ const base = await baseSharedTypecheckConfigs(workspace.location, configOverride, gitignorePath);
32180
+ const disabledRules = Object.fromEntries([...rulePlan.activeRuleNames].filter((ruleName) => !rulePlan.typeCheckedRuleNames.has(ruleName)).map((ruleName) => [ruleName, "off"]));
32181
+ const semanticConfig = {
32182
+ files: sharedTypecheckScriptPatterns,
32183
+ languageOptions: { parserOptions: {
32184
+ programs: [programResult.program],
32185
+ project: false,
32186
+ projectService: false
32187
+ } },
32188
+ rules: disabledRules
32189
+ };
32190
+ const engine = new ESLint(sharedTypecheckEslintOptions({
32191
+ configs: [...base.configs, semanticConfig],
32192
+ cwd: workspace.location,
32193
+ fix: analyze ? false : fix,
32194
+ overrideConfigFile: base.overrideConfigFile
32195
+ }));
32196
+ const lintStarted = performance$1.now();
32197
+ const lintResults = await withSharedTypecheckGitignore(gitignore, async () => engine.lintFiles(lintFiles));
32198
+ const finished = performance$1.now();
32199
+ if (fix && !analyze) await ESLint.outputFixes(lintResults);
32200
+ let output = "";
32201
+ if (!analyze || verbose) output = await (await engine.loadFormatter("stylish")).format(lintResults);
32202
+ const result = {
32203
+ errors: lintResults.reduce((sum, entry) => sum + entry.errorCount, 0),
32204
+ files: lintResults.length,
32205
+ messages: analyze ? lintResults.flatMap((entry) => entry.messages.map((message) => ({
32206
+ ruleId: message.ruleId ?? null,
32207
+ severity: message.severity
32208
+ }))) : [],
32209
+ output,
32210
+ pkg: workspace.name,
32211
+ timeMs: Math.round(finished - started),
32212
+ warnings: lintResults.reduce((sum, entry) => sum + entry.warningCount, 0)
32213
+ };
32214
+ if (profile) result.profile = {
32215
+ configMs: Math.round(lintStarted - started),
32216
+ lintMs: Math.round(finished - lintStarted),
32217
+ spawnMs: 0,
32218
+ wallMs: result.timeMs,
32219
+ totalMs: Math.round(finished - started)
32220
+ };
32221
+ return result;
32222
+ }
32223
+ function mergeOutput(first, second) {
32224
+ if (first.length === 0) return second;
32225
+ if (second.length === 0) return first;
32226
+ return `${first.endsWith("\n") ? first : `${first}\n`}${second}`;
32227
+ }
32228
+ function mergePackageResults(structural, semantic) {
32229
+ if (semantic === void 0) return structural;
32230
+ const result = {
32231
+ errors: structural.errors + semantic.errors,
32232
+ files: structural.files,
32233
+ messages: [...structural.messages, ...semantic.messages],
32234
+ output: mergeOutput(structural.output, semantic.output),
32235
+ pkg: structural.pkg,
32236
+ timeMs: structural.timeMs + semantic.timeMs,
32237
+ warnings: structural.warnings + semantic.warnings
32238
+ };
32239
+ if (structural.profile !== void 0 || semantic.profile !== void 0) {
32240
+ const structuralProfile = structural.profile ?? {
32241
+ configMs: 0,
32242
+ lintMs: 0,
32243
+ spawnMs: 0,
32244
+ totalMs: 0,
32245
+ wallMs: structural.timeMs
32246
+ };
32247
+ const semanticProfile = semantic.profile ?? {
32248
+ configMs: 0,
32249
+ lintMs: 0,
32250
+ spawnMs: 0,
32251
+ totalMs: 0,
32252
+ wallMs: semantic.timeMs
32253
+ };
32254
+ result.profile = {
32255
+ configMs: structuralProfile.configMs + semanticProfile.configMs,
32256
+ lintMs: structuralProfile.lintMs + semanticProfile.lintMs,
32257
+ spawnMs: structuralProfile.spawnMs,
32258
+ totalMs: structuralProfile.totalMs + semanticProfile.totalMs,
32259
+ wallMs: structuralProfile.wallMs + semanticProfile.wallMs
32260
+ };
32261
+ }
32262
+ return result;
32263
+ }
32264
+ function isTypeCheckingEnabled({ analyzeTier, tierContext, typeChecked }) {
32265
+ if (analyzeTier !== void 0) return analyzeTier.isTypeChecked;
32266
+ if (typeChecked !== "auto") return typeChecked;
32267
+ return tierContext?.isTypeChecked ?? true;
32268
+ }
32269
+ function ignorePackageResult() {}
32270
+ /**
32271
+ Run syntax/structural rules in the existing package-worker pool while one
32272
+ process owns every package-specific TypeScript Program used by semantic rules.
32273
+ Only parsed SourceFiles are shared; compiler options and TypeCheckers remain
32274
+ isolated per package.
32275
+ */
32276
+ async function runLintSharedTypecheckPackages(params) {
32277
+ if (!isTypeCheckingEnabled(params)) {
32278
+ if (params.profile) console.log(chalk.gray(" shared typecheck: disabled by effective ESLint configuration"));
32279
+ return await runLintNextPackages(params);
32280
+ }
32281
+ const targets = lintableWorkspaces(params);
32282
+ const { allTypeCheckedRuleNames, plans } = await inspectSharedTypecheckRulePlans({
32283
+ ...params,
32284
+ workspaces: targets
32285
+ });
32286
+ if (params.profile) console.log(chalk.gray(` shared typecheck: 1 semantic owner · ${allTypeCheckedRuleNames.length} semantic rules · semantic cache off`));
32287
+ const structuralAction = async () => runLintNextPackages({
32288
+ ...params,
32289
+ onPackageResult: ignorePackageResult,
32290
+ phase: "structural",
32291
+ typeCheckedRuleNames: allTypeCheckedRuleNames
32292
+ });
32293
+ const semanticAction = async () => {
32294
+ const sharedCache = createSharedValidateCache();
32295
+ const configOverride = resolvePackageConfigOverride(params.typeChecked, params.analyze ? void 0 : params.tierContext, params.analyzeTier);
32296
+ const repositoryGitignore = PATH.resolve(params.rootDir, ".gitignore");
32297
+ const gitignorePath = params.gitignore && existsSync(repositoryGitignore) ? repositoryGitignore : void 0;
32298
+ const results = [];
32299
+ for (const workspace of targets) {
32300
+ const rulePlan = plans.get(workspace.name) ?? {
32301
+ activeRuleNames: /* @__PURE__ */ new Set(),
32302
+ typeCheckedRuleNames: new Set(allTypeCheckedRuleNames)
32303
+ };
32304
+ results.push(await lintSemanticPackage({
32305
+ analyze: params.analyze,
32306
+ configOverride,
32307
+ fix: params.fix,
32308
+ gitignore: params.gitignore,
32309
+ gitignorePath,
32310
+ profile: params.profile,
32311
+ rulePlan,
32312
+ sharedCache,
32313
+ verbose: params.verbose,
32314
+ workspace: {
32315
+ ...workspace,
32316
+ location: PATH.resolve(params.rootDir, workspace.location)
32317
+ }
32318
+ }));
32319
+ }
32320
+ if (params.profile) {
32321
+ const heapMiB = Math.round(process.memoryUsage().heapUsed / 1024 / 1024);
32322
+ console.log(chalk.gray(` shared TypeScript sources: ${sharedCache.sourceFiles.size} · semantic heap: ${heapMiB} MiB`));
32323
+ }
32324
+ return results;
32325
+ };
32326
+ let semanticResults;
32327
+ let structuralResults;
32328
+ if (params.fix) {
32329
+ structuralResults = await structuralAction();
32330
+ semanticResults = await semanticAction();
32331
+ } else [structuralResults, semanticResults] = await Promise.all([structuralAction(), semanticAction()]);
32332
+ const semanticByPackage = new Map(semanticResults.map((result) => [result.pkg, result]));
32333
+ const merged = structuralResults.map((result) => mergePackageResults(result, semanticByPackage.get(result.pkg)));
32334
+ const mergedByPackage = new Map(merged.map((result) => [result.pkg, result]));
32335
+ for (const [index, workspace] of targets.entries()) {
32336
+ const result = mergedByPackage.get(workspace.name);
32337
+ if (result !== void 0) params.onPackageResult(index, targets.length, result);
32338
+ }
32339
+ return merged;
32340
+ }
32341
+ //#endregion
31905
32342
  //#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
31906
32343
  var Node = class {
31907
32344
  value;
@@ -32579,7 +33016,10 @@ function logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, me
32579
33016
  console.log(chalk.gray(` type-checked: ${typeCheckedLabel}`));
32580
33017
  console.log(chalk.gray(` meta packages: ${meta} · skip empty: ${skipEmpty ? "on" : "off"}`));
32581
33018
  }
32582
- async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false, gitignore = true, jobs, meta = "full", pkg, profile = false, skipEmpty = true, typeChecked = "auto", verbose = false, workspaces: targetWorkspaces }) {
33019
+ function runLintModePackages(mode, params) {
33020
+ return mode === "shared-typecheck" ? runLintSharedTypecheckPackages(params) : runLintNextPackages(params);
33021
+ }
33022
+ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false, gitignore = true, jobs, meta = "full", mode = "package-workers", pkg, profile = false, skipEmpty = true, typeChecked = "auto", verbose = false, workspaces: targetWorkspaces }) {
32583
33023
  const rootDir = INIT_CWD();
32584
33024
  const { analyzeContext, detectedContext, tierContext } = resolveTierForLint(analyze, rootDir);
32585
33025
  if (analyzeContext.kind === "invalid") return resultFromExitCode(1);
@@ -32590,12 +33030,15 @@ async function lintNext({ analyze = false, cache = true, cycleDepth, fix = false
32590
33030
  const analyzeStarted = Date.now();
32591
33031
  const label = getLintLabel(analyze, fix, cycleDepth);
32592
33032
  if (analyze && tierContext !== void 0) printAnalyzeRunHeader(workspaces);
32593
- if (profile) logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty);
33033
+ if (profile) {
33034
+ console.log(chalk.gray(` lint mode: ${mode}`));
33035
+ logLintProfileHeader(cache, gitignore, typeChecked, detectedContext, meta, skipEmpty);
33036
+ }
32594
33037
  return finishLintNext({
32595
33038
  analyze,
32596
33039
  analyzeStarted,
32597
33040
  profile,
32598
- results: await runLintNextPackages({
33041
+ results: await runLintModePackages(mode, {
32599
33042
  analyze,
32600
33043
  analyzeTier,
32601
33044
  cache,
@@ -32634,11 +33077,12 @@ function shouldUseIncremental$2(incremental) {
32634
33077
  function shouldUseIncrementalLint({ analyze, fix, incremental, pkg }) {
32635
33078
  return pkg === void 0 && fix !== true && analyze !== true && shouldUseIncremental$2(incremental);
32636
33079
  }
32637
- function lintOptionsHash({ cycleDepth, gitignore }) {
33080
+ function lintOptionsHash({ cycleDepth, gitignore, mode = defaultLintMode }) {
32638
33081
  const gitignorePath = PATH.resolve(INIT_CWD(), ".gitignore");
32639
33082
  return {
32640
33083
  cycleDepth,
32641
33084
  gitignore: gitignore === false ? false : existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf8") : null,
33085
+ mode,
32642
33086
  strict: isStrictMode()
32643
33087
  };
32644
33088
  }
@@ -32646,7 +33090,7 @@ const lintPackage = ({ pkg, fix, verbose }) => {
32646
33090
  const pm = getPackageManager();
32647
33091
  return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
32648
33092
  };
32649
- async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
33093
+ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta, mode, profile, skipEmpty, typeChecked, verbose, workspaces: targetWorkspaces }) {
32650
33094
  const pm = getPackageManager();
32651
33095
  const allWorkspaces = targetWorkspaces ?? pm.listWorkspaces();
32652
33096
  if (allWorkspaces.length === 0) return await lintNext({
@@ -32656,6 +33100,7 @@ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta,
32656
33100
  gitignore,
32657
33101
  jobs,
32658
33102
  meta,
33103
+ mode,
32659
33104
  profile,
32660
33105
  skipEmpty,
32661
33106
  typeChecked,
@@ -32665,7 +33110,8 @@ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta,
32665
33110
  action: "lint",
32666
33111
  options: lintOptionsHash({
32667
33112
  cycleDepth,
32668
- gitignore
33113
+ gitignore,
33114
+ mode
32669
33115
  }),
32670
33116
  pm,
32671
33117
  isVerbose: verbose,
@@ -32678,7 +33124,8 @@ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta,
32678
33124
  action: "lint",
32679
33125
  options: lintOptionsHash({
32680
33126
  cycleDepth,
32681
- gitignore
33127
+ gitignore,
33128
+ mode
32682
33129
  }),
32683
33130
  pm,
32684
33131
  workspaces: allWorkspaces
@@ -32692,6 +33139,7 @@ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta,
32692
33139
  gitignore,
32693
33140
  jobs,
32694
33141
  meta,
33142
+ mode,
32695
33143
  profile,
32696
33144
  skipEmpty,
32697
33145
  typeChecked,
@@ -32702,19 +33150,25 @@ async function lintIncremental({ cache, cycleDepth, fix, gitignore, jobs, meta,
32702
33150
  action: "lint",
32703
33151
  options: lintOptionsHash({
32704
33152
  cycleDepth,
32705
- gitignore
33153
+ gitignore,
33154
+ mode
32706
33155
  }),
32707
33156
  pm,
32708
33157
  workspaces: allWorkspaces
32709
33158
  });
32710
33159
  return result;
32711
33160
  }
32712
- const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, meta, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
33161
+ const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, meta, mode, next, prev, pkg, profile, skipEmpty, typeChecked, verbose, workspaces }) => {
32713
33162
  if (analyze === true && fix === true) {
32714
33163
  console.error("The --analyze option cannot be combined with --fix");
32715
33164
  return 1;
32716
33165
  }
32717
- if (!(prev ?? false)) {
33166
+ const resolvedMode = resolveLintMode({
33167
+ mode,
33168
+ next,
33169
+ prev
33170
+ }).mode;
33171
+ if (resolvedMode !== "workspace-eslint") {
32718
33172
  if (shouldUseIncrementalLint({
32719
33173
  analyze,
32720
33174
  fix,
@@ -32727,6 +33181,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, m
32727
33181
  gitignore,
32728
33182
  jobs,
32729
33183
  meta,
33184
+ mode: resolvedMode,
32730
33185
  profile,
32731
33186
  skipEmpty,
32732
33187
  typeChecked,
@@ -32740,6 +33195,7 @@ const lint = ({ analyze, cache, cycleDepth, fix, gitignore, incremental, jobs, m
32740
33195
  gitignore,
32741
33196
  jobs,
32742
33197
  meta,
33198
+ mode: resolvedMode,
32743
33199
  pkg,
32744
33200
  profile,
32745
33201
  skipEmpty,
@@ -44251,8 +44707,13 @@ const relintPackage = ({ pkg, fix, verbose }) => {
44251
44707
  const pm = getPackageManager();
44252
44708
  return runSteps(`${fix ?? false ? "Fix" : "Lint"} [${pkg}]`, [pm.runInWorkspace(pkg, fix ?? false ? "package-fix" : verbose ?? false ? "package-lint-verbose" : "package-lint")]);
44253
44709
  };
44254
- const relint = ({ fix, gitignore, jobs, pkg, prev, verbose }) => {
44255
- if (!(prev ?? false)) {
44710
+ const relint = ({ fix, gitignore, jobs, mode, next, pkg, prev, verbose }) => {
44711
+ const resolvedMode = resolveLintMode({
44712
+ mode,
44713
+ next,
44714
+ prev
44715
+ }).mode;
44716
+ if (resolvedMode !== "workspace-eslint") {
44256
44717
  cleanLintCaches(pkg);
44257
44718
  clearIncrementalSnapshot("lint");
44258
44719
  return lint({
@@ -44261,6 +44722,7 @@ const relint = ({ fix, gitignore, jobs, pkg, prev, verbose }) => {
44261
44722
  gitignore,
44262
44723
  incremental: true,
44263
44724
  jobs,
44725
+ mode: resolvedMode,
44264
44726
  pkg,
44265
44727
  verbose
44266
44728
  });
@@ -55945,14 +56407,20 @@ const runCommand = {
55945
56407
  default: true,
55946
56408
  description: "Ignore files matched by the repository root .gitignore (disable with --no-gitignore)",
55947
56409
  type: "boolean"
56410
+ }).option("mode", {
56411
+ choices: lintModes,
56412
+ default: defaultLintMode,
56413
+ description: "Lint implementation: package workers, shared type-checking, or workspace ESLint",
56414
+ type: "string"
55948
56415
  }).option("next", {
55949
56416
  default: false,
55950
- description: "Deprecated: per-package lint is the default",
56417
+ description: "Deprecated: use --mode package-workers",
55951
56418
  hidden: true,
55952
56419
  type: "boolean"
55953
56420
  }).option("prev", {
55954
56421
  default: false,
55955
- description: "Use the previous all-packages lint runner",
56422
+ description: "Deprecated: use --mode workspace-eslint",
56423
+ hidden: true,
55956
56424
  type: "boolean"
55957
56425
  }).option("analyze", {
55958
56426
  default: false,
@@ -55985,12 +56453,18 @@ const runCommand = {
55985
56453
  await withEnvelope("lint rules", async () => ruleCatalogResult(await getEslintRuleCatalog("lint"), RULE_COMMANDS.lint.title));
55986
56454
  return;
55987
56455
  }
56456
+ const resolvedMode = resolveLintMode({
56457
+ mode: argv.mode,
56458
+ next: argv.next,
56459
+ prev: argv.prev
56460
+ });
56461
+ if (resolvedMode.legacyOption !== void 0) console.warn(chalk.yellow(`Deprecated: "${resolvedMode.legacyOption}" is deprecated; use "--mode ${resolvedMode.mode}" instead.`));
55988
56462
  if (Boolean(argv.fresh)) {
55989
56463
  await withEnvelope("lint", () => relint({
55990
56464
  gitignore: argv.gitignore,
55991
56465
  jobs: argv.jobs,
56466
+ mode: resolvedMode.mode,
55992
56467
  pkg: argv.package,
55993
- prev: argv.prev,
55994
56468
  verbose: !!Boolean(argv.verbose)
55995
56469
  }));
55996
56470
  return;
@@ -56004,7 +56478,7 @@ const runCommand = {
56004
56478
  incremental: argv.incremental !== false,
56005
56479
  jobs: argv.jobs,
56006
56480
  meta: argv.meta,
56007
- prev: argv.prev,
56481
+ mode: resolvedMode.mode,
56008
56482
  pkg: argv.package,
56009
56483
  profile: argv.profile,
56010
56484
  skipEmpty: argv["skip-empty"],
@@ -56150,15 +56624,21 @@ const relintCommand = {
56150
56624
  command: "relint [package]",
56151
56625
  describe: "Deprecated: use \"xy lint --fresh\"",
56152
56626
  builder: (yargs) => {
56153
- return packagePositionalParam(yargs).option("next", {
56627
+ return packagePositionalParam(yargs).option("mode", {
56628
+ choices: lintModes,
56629
+ default: defaultLintMode,
56630
+ description: "Lint implementation: package workers, shared type-checking, or workspace ESLint",
56631
+ type: "string"
56632
+ }).option("next", {
56154
56633
  alias: "n",
56155
56634
  default: false,
56156
- description: "Deprecated: per-package lint is the default",
56635
+ description: "Deprecated: use --mode package-workers",
56157
56636
  hidden: true,
56158
56637
  type: "boolean"
56159
56638
  }).option("prev", {
56160
56639
  default: false,
56161
- description: "Use the previous all-packages lint runner",
56640
+ description: "Deprecated: use --mode workspace-eslint",
56641
+ hidden: true,
56162
56642
  type: "boolean"
56163
56643
  }).option("rules", {
56164
56644
  default: false,
@@ -56173,10 +56653,16 @@ const relintCommand = {
56173
56653
  await withEnvelope("lint rules", async () => ruleCatalogResult(await getEslintRuleCatalog("lint"), RULE_COMMANDS.lint.title));
56174
56654
  return;
56175
56655
  }
56656
+ const resolvedMode = resolveLintMode({
56657
+ mode: argv.mode,
56658
+ next: argv.next,
56659
+ prev: argv.prev
56660
+ });
56661
+ if (resolvedMode.legacyOption !== void 0) console.warn(chalk.yellow(`Deprecated: "${resolvedMode.legacyOption}" is deprecated; use "--mode ${resolvedMode.mode}" instead.`));
56176
56662
  await withEnvelope("lint", () => relint({
56177
56663
  jobs: argv.jobs,
56664
+ mode: resolvedMode.mode,
56178
56665
  pkg: argv.package,
56179
- prev: argv.prev,
56180
56666
  verbose: !!Boolean(argv.verbose)
56181
56667
  }));
56182
56668
  }