Skip to content

v3.0.0

Compare
Choose a tag to compare
@wessberg wessberg released this 01 Aug 23:36
· 12 commits to master since this release

New Features

DI-Compiler is now based on ESM and requires Node v14.19.0 (BREAKING CHANGE)

Now that TypeScript v4.7 is out, it has finally received great support for ES modules in a Node.js environment that aligns with how it has been implemented across Node.js and browsers.

Because of this, now is a good time to make DI-Compiler a type: "module" package. However, it still provides a CommonJS fallback. If your codebase is still based on CommonJS, you should be fine. Please know however, that di-compiler requires an environment running Node v14.19.0 or newer going forward.

Node.js loader support (BREAKING CHANGE)

In the past, you could use DI-Compiler as a CommonJS loader, like so:

node -r @wessberg/di-compiler/register

However, this had a few issues:

  • It only worked in CommonJS projects
  • It internally wrapped ts-node in a way that wasn't transparent to the user.

Now, both a CommonJS and an ESM loader is exposed, both of which are documented in the README. They don't wrap ts-node, so they can be used in conjunction with not only ts-node, but other loaders for Node.js as well that teach Node.js to handle TypeScript syntax, such as tsx or esm-loader.

To ease migration, if you want to continue using DI-Compiler as you did before where it directly wraps ts-node, a legacy loader is provided for your convenience, and here's how you can use it:

node -r @wessberg/di-compiler/ts-node-loader

Usage without a TypeScript Program

In the past years, TypeScript tooling has moved towards much faster builds in part by treating emit as purely a matter of syntax transformation, whereas it is traditionally coupled with type checking and diagnostics reporting in TypeScript. This is how tools like babel, swc, and esbuild treat TypeScript.

To allow integration with these tools, as well as to allow integration with the new Node.js loader system, DI-Compiler can now work without access to a TypeScript Program or a Type checker. When a Program isn't given, it will attempt to statically infer whether or not identifiers are instances of DIContainer, and you can help it out by passing exactly which identifiers should be treated at such. See this section in the README for more details.

TypeScript v4.7 support

DI-Compiler now supports TypeScript v4.7 and its new features.

v2.2.6...v3.0.0