| 20 | }; |
| 21 | |
| 22 | export default function compile( |
| 23 | input: string, |
| 24 | transformOpts: Opts, |
| 25 | options: ts.CompilerOptions = CJS_CONFIG |
| 26 | ) { |
| 27 | const files = globSync(input); |
| 28 | const compilerHost = ts.createCompilerHost(options); |
| 29 | const program = ts.createProgram(files, options, compilerHost); |
| 30 | |
| 31 | const msgs = {}; |
| 32 | |
| 33 | let emitResult = program.emit(undefined, undefined, undefined, undefined, { |
| 34 | before: [hoist(transformOpts)] |
| 35 | }); |
| 36 | |
| 37 | let allDiagnostics = ts |
| 38 | .getPreEmitDiagnostics(program) |
| 39 | .concat(emitResult.diagnostics); |
| 40 | |
| 41 | allDiagnostics.forEach(diagnostic => { |
| 42 | let { line, character } = diagnostic.file.getLineAndCharacterOfPosition( |
| 43 | diagnostic.start |
| 44 | ); |
| 45 | let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); |
| 46 | console.log( |
| 47 | `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}` |
| 48 | ); |
| 49 | }); |
| 50 | |
| 51 | return msgs; |
| 52 | } |