1 | # broccoli-typescript-compiler
|
2 |
|
3 | ![Build Status](https://github.com/tildeio/broccoli-typescript-compiler/workflows/CI/badge.svg)
|
4 |
|
5 | A [Broccoli](https://github.com/broccolijs/broccoli) plugin which
|
6 | compiles [TypeScript](http://www.typescriptlang.org) files.
|
7 |
|
8 | ## How to install?
|
9 |
|
10 | ```sh
|
11 | $ npm install broccoli-typescript-compiler --save-dev
|
12 | ```
|
13 |
|
14 | ## How to use?
|
15 |
|
16 | ```js
|
17 | var typescript = require("broccoli-typescript-compiler").default;
|
18 | var cjsTree = typescript(inputTree, {
|
19 | tsconfig: {
|
20 | compilerOptions: {
|
21 | module: "commonjs",
|
22 | target: "es5",
|
23 | moduleResolution: "node",
|
24 | newLine: "LF",
|
25 | rootDir: "src",
|
26 | outDir: "dist",
|
27 | sourceMap: true,
|
28 | declaration: true,
|
29 | },
|
30 | files: ["src/index.ts", "src/tests/**"],
|
31 | },
|
32 | throwOnError: false,
|
33 | annotation: "compile program",
|
34 | });
|
35 | ```
|
36 |
|
37 | ### Config Options:
|
38 |
|
39 | `tsconfig:`
|
40 |
|
41 | - default (when ommited): will find the nearest `tsconfig` relative to where the BroccoliTypeScriptCompiler is invoked.
|
42 | - as string: a absolute path to a config tsconfig file
|
43 | - as config object: See: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
|
44 |
|
45 | `annotation:`
|
46 |
|
47 | An optional string, which when provide should be a descriptive annotation. Useful for debugging, to tell multiple instances of the same plugin apart.
|
48 |
|
49 | `throwOnError`
|
50 |
|
51 | An optional boolean, defaulting to `false`. If set to `true`, will cause the build to break on errors.
|
52 |
|
53 | *note: if `process.env.NODE_ENV === 'production'` is true, `throwOnError` will default to `true`.*
|
54 |
|
55 | ### Ways to use:
|
56 |
|
57 | ## via the broccoli plugin subclass
|
58 |
|
59 | This outputs only the emitted files from the compiled program.
|
60 |
|
61 | ```js
|
62 | const { TypescriptCompiler } = require("broccoli-typescript-compiler");
|
63 | let compiled = new TypescriptCompiler(input, options);
|
64 | ```
|
65 |
|
66 | ## via function
|
67 |
|
68 | This outputs only the emitted files from the compiled program.
|
69 |
|
70 | ```js
|
71 | const { default: typescript } = require("broccoli-typescript-compiler");
|
72 |
|
73 | let compiled = typescript(src, options);
|
74 | ```
|
75 |
|
76 | ## filter function (passthrough non .ts files)
|
77 |
|
78 | This selects only ts files from the input to compile and merges emitted files with the non ts files in the input.
|
79 |
|
80 | ```js
|
81 | const { filterTypescript } = require("broccoli-typescript-compiler");
|
82 | let output = filterTypescript(input, options);
|
83 | ```
|
84 |
|
85 | ## Development
|
86 |
|
87 | ### How to upgrade `typescript`
|
88 |
|
89 | 1. Initialize git submodules. `git submodule update --init`
|
90 | 2. Update `typescript` in `package.json`
|
91 | 3. Run `yarn run generate-tsconfig-interface`
|
92 | 4. Update `vendor/typescript`. `cd vendor/typescript && git fetch --tags && git checkout v[new-version-of-typescript]`
|
93 | 5. Commit all of the above changes
|
94 | 6. Run `yarn test`. There may be some changes needed to the tests to accomidate changes in TypeScript.
|