* Compiles a TypeScript project. * @param {string} configFileName The file name of the TypeScript config file. * @returns {Promise } The diagnostics produced.
(configFileName)
| 68 | * @returns {Promise<ts.Diagnostic[]>} The diagnostics produced. |
| 69 | */ |
| 70 | async function compile(configFileName) { |
| 71 | let jsonParseResult = ts.parseConfigFileTextToJson( |
| 72 | configFileName, |
| 73 | await fs.readFile(configFileName, { encoding: 'utf8' }) |
| 74 | ); |
| 75 | |
| 76 | if (!jsonParseResult.config && jsonParseResult.error) { |
| 77 | return [jsonParseResult.error]; |
| 78 | } |
| 79 | |
| 80 | let config = ts.parseJsonConfigFileContent( |
| 81 | jsonParseResult.config, |
| 82 | ts.sys, |
| 83 | path.dirname(configFileName) |
| 84 | ); |
| 85 | if (config.errors.length > 0) { |
| 86 | return config.errors; |
| 87 | } |
| 88 | |
| 89 | let program = ts.createProgram(config.fileNames, config.options); |
| 90 | let emitResult = program.emit( |
| 91 | undefined, |
| 92 | // Do not emit anything. |
| 93 | () => undefined |
| 94 | ); |
| 95 | |
| 96 | return ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Prints the diagnostics to stdout. |