UNPKG

1.95 kBJavaScriptView Raw
1import Compiler from "./compiler";
2import DiagnosticsHandler from "./diagnostics-handler";
3import { toAbsolutePath } from "./fs/path-utils";
4import { BroccoliPlugin, heimdall } from "./helpers";
5import normalizeOptions from "./normalize-options";
6/**
7 * Returns a Broccoli plugin instance that compiles
8 * the files in the tsconfig.
9 *
10 * It is rooted to the inputNode's outputPath, all
11 * files it imports must be resolvable from its input
12 * except for the default library file.
13 *
14 * Errors are logged and it will try to emit whatever
15 * it could successfully compile.
16 *
17 * It will only emit based on the root source files
18 * you give it, by default it will look for all .ts
19 * files, but if you specify a files or filesGlob
20 * it will these as entry points and only compile
21 * the files and files they reference from the input.
22 */
23export function typescript(inputNode, options) {
24 return new TypescriptCompiler(inputNode, options);
25}
26/**
27 * TypeScript Broccoli plugin class.
28 */
29export class TypescriptCompiler extends BroccoliPlugin {
30 constructor(inputNode, options) {
31 super([inputNode], {
32 annotation: options && options.annotation,
33 name: "broccoli-typescript-compiler",
34 persistentOutput: true,
35 });
36 const normalizedOptions = normalizeOptions(options || {});
37 this.options = normalizedOptions;
38 this.diagnosticHandler = new DiagnosticsHandler(normalizedOptions);
39 }
40 build() {
41 const token = heimdall.start("TypeScript:compile");
42 let compiler = this.compiler;
43 if (!compiler) {
44 compiler = this.compiler = new Compiler(toAbsolutePath(this.inputPaths[0]), toAbsolutePath(this.outputPath), this.options, this.diagnosticHandler);
45 }
46 compiler.compile();
47 heimdall.stop(token);
48 }
49 setDiagnosticWriter(write) {
50 this.diagnosticHandler.setWrite(write);
51 }
52}
53//# sourceMappingURL=plugin.js.map
\No newline at end of file