( ts: TypeScript, config: ts.ParsedCommandLine, result: EmittedModules, request: ReturnType<typeof createSyncPrecompiler>, rewrites: (specifier: string) => boolean )
| 92 | config.options.configFilePath as string |
| 93 | |
| 94 | const emitProject = ( |
| 95 | ts: TypeScript, |
| 96 | config: ts.ParsedCommandLine, |
| 97 | result: EmittedModules, |
| 98 | request: ReturnType<typeof createSyncPrecompiler>, |
| 99 | rewrites: (specifier: string) => boolean |
| 100 | ) => { |
| 101 | if (!config.fileNames.length) return |
| 102 | const { options } = config |
| 103 | if (options.noEmit || options.emitDeclarationOnly) |
| 104 | throwError(writeUnemittedMessage(resolve(configPathOf(config)))) |
| 105 | const emitOptions = emitOptionsOf(options) |
| 106 | const host = ts.createCompilerHost(emitOptions) |
| 107 | const { getSourceFile } = host |
| 108 | const precompiled: Record<string, TransformedModule> = {} |
| 109 | // the program precompiled modules are emitted from reuses the others |
| 110 | const sourceFiles: Record<string, ts.SourceFile | undefined> = {} |
| 111 | host.getSourceFile = (fileName, languageVersion, ...rest) => |
| 112 | fileName in precompiled ? |
| 113 | ts.createSourceFile( |
| 114 | fileName, |
| 115 | precompiled[fileName].code!, |
| 116 | languageVersion, |
| 117 | true |
| 118 | ) |
| 119 | : (sourceFiles[fileName] ??= getSourceFile( |
| 120 | fileName, |
| 121 | languageVersion, |
| 122 | ...rest |
| 123 | )) |
| 124 | const programOptions: ts.CreateProgramOptions = { |
| 125 | rootNames: config.fileNames, |
| 126 | options: emitOptions, |
| 127 | host, |
| 128 | ...(config.projectReferences && { |
| 129 | projectReferences: config.projectReferences |
| 130 | }) |
| 131 | } |
| 132 | const program = ts.createProgram(programOptions) |
| 133 | const emitted: ts.SourceFile[] = [] |
| 134 | const { rootDir } = options |
| 135 | // tsc fails on a module outside rootDir, as one resolved to its source |
| 136 | const files = emittedFilesOf(program).filter( |
| 137 | file => !rootDir || isInside(rootDir, file.fileName) |
| 138 | ) |
| 139 | // the project is the whole program, so a site another module may write a |
| 140 | // value of is refused |
| 141 | request("program", { |
| 142 | modules: Object.fromEntries( |
| 143 | files.map(file => [realPathOf(file.fileName), { source: file.text }]) |
| 144 | ) |
| 145 | } satisfies ReadProgram) |
| 146 | for (const file of files) { |
| 147 | const transformed = request( |
| 148 | "transform", |
| 149 | file.text, |
| 150 | realPathOf(file.fileName) |
| 151 | ) as TransformedModule | undefined |
no test coverage detected