UNPKG

3.79 kBMarkdownView Raw
1# Making a new release
2
3Write release notes in `README.md`. Then,
4
5```
6npm version <major|minor|patch>
7git push --follow-tags
8npm publish
9```
10
11Enjoy life :heart: :rose:
12
13
14# Debugging
15
16Debug logging is enabled using the built in node `util`. We setup the `log` function as
17
18```
19var log = require('util').debuglog(require('./package').name);
20```
21
22If you want this function to actually do something just set the environment variable `NODE_DEBUG=tsify` e.g.
23
24```
25NODE_DEBUG=tsify browserify ... etc.
26```
27
28
29# Internals and processing flow
30
31`tsify` is a implemented as a Browserify [plugin](https://github.com/substack/browserify-handbook#plugins) - not as a [transform](https://github.com/substack/browserify-handbook#writing-your-own) - because it needs access to the Browserify bundler - which is passed to plugins, but not to transforms. Access to the bundler is required so that `tsify` can include the TypeScript extensions in the `_extensions` array used by Browserify when resolving modules and so that `tsify` can listen to events associated with the Browserify pipeline. That's not possible with a transform, as a transform receives only a file path and a stream of content.
32
33However, `tsify` does implement a transform that is wired up internally.
34
35## `index.js` - the plugin
36
37* It wires up internal transform.
38* It wires up the `file` and `reset` events. (Note that the `file` is [informational nicety](https://github.com/substack/node-browserify#events); it's not a core part of the Browserify process.)
39* It places `.ts(x)` extensions at the *head* of Browserify's extensions array.
40* It gathers the Browserify entry point files.
41
42## `lib/Tsifier.js` - the transform
43
44* The `Tsifer` is a Browserify transform.
45* It returns compiled content to Browserify.
46* It parses the `tsconfig.json` for options and files.
47* It configures the TypeScipt `rootDir` and `outDir` options to use an imaginary `/__tsify__` directory.
48* It creates the `Host`, passing it to the TypeScript Compiler API to compile the program and check the syntax, semantics and output.
49
50## `lib/Host.js` - the TypeScript host
51
52* The `Host` is a TypeScript Compiler API host.
53* It abstracts the reading and writing of files, etc.
54* It parses and caches the parsed source files, reading them from disk.
55* It caches the compiled files when the TypeScript Compiler API writes compiled content.
56
57## Processing flow
58
59* When Browserify's pipeline is prepared, the initial list of files to be compiled is obtained from the `tsconfig.json` and from the Browserify entry points.
60* With the pipeline prepared, Browserify starts processing its entry points, passing their content through the `Tsifier` transform.
61* To obtain the transformed content, the `Tsifier` transform looks in a cache for the compiled content.
62* If the cache look up results in a miss, the transformed file is added to the list of files (if it's missing from the list) and a compilation of the list of files is performed.
63* Note that with TypeScript using the same module resolution mechanism as Browserify (`"moduleResolution": "node"`) only a single compilation is required.
64* Browserify then locates any `require` calls in the transformed content and passes the content for these dependencies through the `Tsifier` transform.
65* This continues until all dependencies have been processed.
66
67## Caveats
68
69* The `Host` reads the source from disk; the content passed into the `Tsifier` transform is ignored. That means that any transforms added before the `tsify` plugin will be ineffectual.
70* If `grunt-browserify` is used, declarative configurations will see transforms will be loaded before plugins. To avoid that, an imperative configuration that uses the [configure](https://github.com/jmreidy/grunt-browserify#configure) function would be necessary.