(
args: { entrypoint: string; workPath: string },
ts: TypeScriptModule
)
| 58 | }; |
| 59 | |
| 60 | async function doTypeCheck( |
| 61 | args: { entrypoint: string; workPath: string }, |
| 62 | ts: TypeScriptModule |
| 63 | ): Promise<void> { |
| 64 | const entryAbsolute = resolve(args.workPath, args.entrypoint); |
| 65 | const tsconfig = await findNearestTsconfig(args.workPath); |
| 66 | |
| 67 | const formatDiagnostics = process.stdout.isTTY |
| 68 | ? ts.formatDiagnosticsWithColorAndContext |
| 69 | : ts.formatDiagnostics; |
| 70 | const diagnosticHost: FormatDiagnosticsHost = { |
| 71 | getNewLine: () => ts.sys.newLine, |
| 72 | getCanonicalFileName: (fileName: string) => |
| 73 | ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(), |
| 74 | getCurrentDirectory: () => args.workPath, |
| 75 | }; |
| 76 | |
| 77 | let options: CompilerOptions; |
| 78 | let parseDiagnostics: readonly Diagnostic[] = []; |
| 79 | |
| 80 | if (tsconfig) { |
| 81 | const configRead = ts.readConfigFile(tsconfig, ts.sys.readFile); |
| 82 | if (configRead.error) { |
| 83 | const message = formatDiagnostics([configRead.error], diagnosticHost); |
| 84 | console.error('\nTypeScript type check failed:\n'); |
| 85 | console.error(message); |
| 86 | throw new Error('TypeScript type check failed'); |
| 87 | } |
| 88 | const parsed = ts.parseJsonConfigFileContent( |
| 89 | configRead.config, |
| 90 | ts.sys, |
| 91 | dirname(tsconfig), |
| 92 | undefined, |
| 93 | tsconfig |
| 94 | ); |
| 95 | parseDiagnostics = parsed.errors; |
| 96 | options = { |
| 97 | ...parsed.options, |
| 98 | noEmit: true, |
| 99 | skipLibCheck: true, |
| 100 | allowJs: true, |
| 101 | esModuleInterop: true, |
| 102 | }; |
| 103 | } else { |
| 104 | options = { |
| 105 | noEmit: true, |
| 106 | skipLibCheck: true, |
| 107 | allowJs: true, |
| 108 | esModuleInterop: true, |
| 109 | target: ts.ScriptTarget.ES2022, |
| 110 | module: ts.ModuleKind.NodeNext, |
| 111 | moduleResolution: ts.ModuleResolutionKind.NodeNext, |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | const compilerHost = ts.createCompilerHost(options); |
| 116 | compilerHost.getCurrentDirectory = () => args.workPath; |
| 117 |
no test coverage detected