Skip to content

Commit ec4631a

Browse files
committed
Add new typescript-compiler package.
New TypeScript compiler uses internally TypeScript API from meteor-typescript NPM package. This part of the effort to create an official TypeScript compiler: Urigo/angular2-meteor#89 Urigo/angular2-meteor#90
1 parent 0ecd19e commit ec4631a

15 files changed

+247
-608
lines changed

README.md

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,8 @@
1-
## TypeScript compilers for Meteor.
1+
## TypeScript compiler for Meteor.
22

3-
Package exposes three TypeScript compilers: `TsBatchCompiler`, `TsCachingCompiler` and `TsCompiler` to be used in a Meteor compiler plugin.
3+
Exports two symbols:
4+
- `TypeScriptCompiler` - a compiler to be registered using `registerBuildPlugin`
5+
to compile TypeScript files.
46

5-
TypeScript is provided by this [package](https://github.com/barbatus/typescript), which is a wrapper package over the TypeScript NPM with API devised for the Meteor environment.
6-
7-
## Getting Started
8-
Add new package (into the packages folder) and register new Meteor plugin there:
9-
````js
10-
Package.registerBuildPlugin({
11-
name: 'TSBuilder',
12-
sources: [
13-
'ts_handler.js'
14-
],
15-
use: [
16-
'barbatus:[email protected]',
17-
18-
]
19-
});
20-
````
21-
In `ts_handler.js`, add one of two provided compilers as follows:
22-
23-
````js
24-
Plugin.registerCompiler({
25-
extensions: ['ts'],
26-
}, () => new TsCachingCompiler());
27-
````
28-
29-
Please, check out how everything works in the demo app.
30-
31-
## Compilers
32-
### TsBatchCompiler
33-
Compiles all passed `.ts`-files at once using [`TypeScript.transpileFiles`](https://github.com/barbatus/typescript/blob/master/typescript.js#L87) method internally.
34-
35-
TypeScript can potentially transpile all files together a bit more effiently using internal cache.
36-
37-
### TsCachingCompiler
38-
Extends Meteor's [`MultiFileCachingCompiler`](https://atmospherejs.com/meteor/caching-compiler) and compiles one file content at a time using [`TypeScript.transpile`](https://github.com/barbatus/typescript/blob/master/typescript.js#L96) internally.
39-
40-
This compiler smartely watches, not only for the .ts-files changes, but also for the declaration files as well.
41-
So, if a declaration file has been changed, all dependant .ts-files will be re-compiled. Hence, it makes sense to
42-
keep custom declaration files separated logically into smaller pieces.
43-
44-
### TsCompiler
45-
Main compiler that wraps two above compilers and use a particular one at a moment depending on the configuration provided.
46-
Currently, if `useCache` is set then `TsCachingCompiler` is used, otherwise - `TsBatchCompiler`.
47-
48-
## TypeScript Config
49-
Compilers can be configured via [`tsconfig.json`](https://github.com/Microsoft/TypeScript/wiki/tsconfig.json) in the app root folder.
50-
The structure of the file is exactly the same as the original one: `compilerOptions` and `files`.
51-
52-
`files` works only for the .d.ts-files in the _typings_ folder. These files are passed then to the TypeScript transpiler along with the TypeScript files, so you don't need to reference typigns directly.
53-
54-
Some of the TypeScript options are preset to be always turned on or off according to details of the Meteor environment. You can read about exceptions [here](https://github.com/barbatus/typescript#compiler-options).
55-
56-
There have been added additional section `meteorCompilerOptions` for Meteor environment needs.
57-
This sections accept two options: `alwaysThrow` and `useCache`.
58-
59-
When `alwaysThrow` is set, the compiler will always throw exceptions whenever syntactic or symantic error occurs. Otherwise, it throws by default only on syntactic errors, semantic ones (like module resolution errors, unknown variables etc) are just logged out in the terminal.
60-
61-
`useCache` simple says compiler to turn on/off caching results.
62-
63-
An example of the correct _tsconfig.json_ might look like this:
64-
65-
````
66-
{
67-
"compilerOptions": {
68-
"module": "system",
69-
"target": "es5"
70-
},
71-
"meteorCompilerOptions": {
72-
"alwaysThrow": true
73-
},
74-
"typings": ["typings/angular2.d.ts"]
75-
}
76-
````
77-
78-
## Package Development
79-
80-
To switch diagnostics on for the packages, you'll need to specify `pkgMode: true` in the config.
81-
Unfortunately, it can't compile package files relatively to the package folder, which require you to specify
82-
full file paths in the typings references if you want to avoid errors in the terminal. Though, I plan to add this feature (relative compilation) in the future versions.
83-
84-
Another feature, that one might consider useful, is an installation of the declaration files.
85-
If you want to add a specific declation file with API provided by your package to the user app, just
86-
add a `d.ts`-file in the package.js:
87-
88-
````js
89-
api.addFiles([
90-
'typings/path_to_file/foo.d.ts',
91-
], server);
92-
````
93-
94-
The package will recognize and copy added file to the user app at the same path as it is located in your package, i.e. `typings/path_to_file`.
95-
96-
## Compilation Speed-up
97-
`noResolve` is designated to turn on/off module resolution process. During that process TypeScript checks availability of each module and verify that API usage is correct as well, which can be quite time assuming especially
98-
for big apps because each imported module's file is being read and parsed.
99-
100-
Therefor, you might consider turning it off during intensive development when Meteor is running and changes applied just-in-time. TypeScript will skip resolving each module but will continue cursing on syntactic errors.
101-
From time to time you can switch `noResolve` back to false with the `useCache` set to false and re-start Meteor.
102-
You'll see all mistakes (if any) you have made including missing modules errors or incorrect API usage etc.
103-
104-
## Example of usage
105-
Please, check Angular2's demo called Socially [here](https://github.com/Urigo/Meteor-Angular2/tree/master/examples/parties). This demo is built fully in TypeScript and uses `tsconfig.json` as well. Angular2-Meteor package itself bases on the compilers of this package.
7+
- `TypeScript' - an object with `compile` method.
8+
Use `TypeScript.compile(source, options)` to compile with preset options.

0 commit comments

Comments
 (0)