UNPKG

2.71 kBMarkdownView Raw
1# broccoli-typescript-compiler
2
3![Build Status](https://github.com/tildeio/broccoli-typescript-compiler/workflows/CI/badge.svg)
4
5A [Broccoli](https://github.com/broccolijs/broccoli) plugin which
6compiles [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
17var typescript = require("broccoli-typescript-compiler").default;
18var 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
47An 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
51An 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
59This outputs only the emitted files from the compiled program.
60
61```js
62const { TypescriptCompiler } = require("broccoli-typescript-compiler");
63let compiled = new TypescriptCompiler(input, options);
64```
65
66## via function
67
68This outputs only the emitted files from the compiled program.
69
70```js
71const { default: typescript } = require("broccoli-typescript-compiler");
72
73let compiled = typescript(src, options);
74```
75
76## filter function (passthrough non .ts files)
77
78This selects only ts files from the input to compile and merges emitted files with the non ts files in the input.
79
80```js
81const { filterTypescript } = require("broccoli-typescript-compiler");
82let output = filterTypescript(input, options);
83```
84
85## Development
86
87### How to upgrade `typescript`
88
891. Initialize git submodules. `git submodule update --init`
902. Update `typescript` in `package.json`
913. Run `yarn run generate-tsconfig-interface`
924. Update `vendor/typescript`. `cd vendor/typescript && git fetch --tags && git checkout v[new-version-of-typescript]`
935. Commit all of the above changes
946. Run `yarn test`. There may be some changes needed to the tests to accomidate changes in TypeScript.