* Compiles a TypeScript project. * @param {typeof ts} compiler The TypeScript compiler to use. * @param {string} configFileName The file name of the TypeScript config file. * @returns {Promise } The diagnostics produced.
(compiler, configFileName)
| 104 | * @returns {Promise<ts.Diagnostic[]>} The diagnostics produced. |
| 105 | */ |
| 106 | async function compile(compiler, configFileName) { |
| 107 | let jsonParseResult = compiler.parseConfigFileTextToJson( |
| 108 | configFileName, |
| 109 | await fs.readFile(configFileName, { encoding: 'utf8' }) |
| 110 | ); |
| 111 | |
| 112 | if (!jsonParseResult.config && jsonParseResult.error) { |
| 113 | return [jsonParseResult.error]; |
| 114 | } |
| 115 | |
| 116 | let config = compiler.parseJsonConfigFileContent( |
| 117 | jsonParseResult.config, |
| 118 | compiler.sys, |
| 119 | path.dirname(configFileName) |
| 120 | ); |
| 121 | if (config.errors.length > 0) { |
| 122 | return config.errors; |
| 123 | } |
| 124 | |
| 125 | let program = compiler.createProgram(config.fileNames, config.options); |
| 126 | let emitResult = program.emit( |
| 127 | undefined, |
| 128 | // Do not emit anything. |
| 129 | () => undefined |
| 130 | ); |
| 131 | |
| 132 | return compiler.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Prints the diagnostics to stdout. |