{"version":3,"file":"tscUtils.js","names":[],"sources":["../../src/checkers/tscUtils.ts"],"sourcesContent":["import type ts from 'typescript'\n\n/**\n * Wrap a `SolutionBuilderWithWatchHost` so that when a referenced project's\n * tsconfig fails to parse, we force `compilerOptions.noEmit` to `true` instead\n * of letting TS fall back to defaults (which include `noEmit: false`).\n *\n * `createSolutionBuilderWithWatch` takes its emit decisions from each referenced\n * project's own `compilerOptions`. If a referenced tsconfig is truncated or\n * mid-write at the moment TS reads it (which can happen e.g. when a dev tool\n * rewrites tsconfigs at runtime), TS falls back to default options — and the\n * default is `noEmit: false`, so the build host writes `.js` files next to\n * sources. See https://github.com/nuxt/nuxt/issues/32872.\n *\n * We deliberately only override when parsing produced errors: forcing\n * `noEmit: true` on every parsed project would break valid `tsc --build`\n * graphs, since composite referenced projects must emit declarations.\n */\nexport function forceNoEmitOnSolutionBuilderHost<\n H extends {\n getParsedCommandLine?: ts.SolutionBuilderHostBase['getParsedCommandLine']\n },\n>(ts: typeof import('typescript'), host: H): H {\n const parseConfigHost: ts.ParseConfigFileHost = {\n useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,\n readDirectory: ts.sys.readDirectory,\n fileExists: ts.sys.fileExists,\n readFile: ts.sys.readFile,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n onUnRecoverableConfigFileDiagnostic: () => {},\n }\n\n const original = host.getParsedCommandLine?.bind(host)\n\n host.getParsedCommandLine = (fileName: string) => {\n const parsed = original\n ? original(fileName)\n : ts.getParsedCommandLineOfConfigFile(\n fileName,\n // `tscBuild` is the internal flag the solution builder sets on every\n // referenced project's parsed options. Without it `canEmitTsBuildInfo`\n // returns false, so a `noEmit: true` referenced project whose\n // `include` resolves to only `.d.ts` files has no output path at all\n // and `getFirstProjectOutput` crashes.\n { tscBuild: true } as ts.CompilerOptions,\n parseConfigHost,\n )\n if (parsed && parsed.errors.length > 0) {\n parsed.options.noEmit = true\n }\n return parsed\n }\n\n return host\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,iCAId,IAAiC,MAAY;CAC7C,MAAM,kBAA0C;EAC9C,2BAA2B,GAAG,IAAI;EAClC,eAAe,GAAG,IAAI;EACtB,YAAY,GAAG,IAAI;EACnB,UAAU,GAAG,IAAI;EACjB,qBAAqB,GAAG,IAAI;EAC5B,2CAA2C,CAAC;CAC9C;CAEA,MAAM,WAAW,KAAK,sBAAsB,KAAK,IAAI;CAErD,KAAK,wBAAwB,aAAqB;EAChD,MAAM,SAAS,WACX,SAAS,QAAQ,IACjB,GAAG,iCACD,UAMA,EAAE,UAAU,KAAK,GACjB,eACF;EACJ,IAAI,UAAU,OAAO,OAAO,SAAS,GACnC,OAAO,QAAQ,SAAS;EAE1B,OAAO;CACT;CAEA,OAAO;AACT"}