Ember CLI TypeScript Blueprint Polyfill
This package `ember-cli-typescript-blueprint-polyfill` provides a utility function to enable TypeScript blueprint functionality in Ember applications and addons running on older versions of Ember CLI that predate native support for TypeScript blueprints. Its current stable version is 0.1.0, suggesting it reached its intended feature set early and is not actively developed for new capabilities. The package essentially polyfills RFC 0776, allowing `*.ts` files within a blueprint's `files` directory to be transformed into JavaScript during blueprint generation. It is primarily differentiated by its purpose of bridging this compatibility gap for legacy Ember CLI environments, as modern Ember CLI (typically v4.x and newer, following RFC 0776's merger in December 2021) includes this functionality natively. Consequently, this polyfill is largely redundant for new projects or those on recent Ember CLI versions, making its utility specific to maintaining older Ember ecosystems. Its release cadence is effectively stable, with no new versions anticipated given the widespread native support now available in the target environment.
Common errors
-
TypeError: typescriptBlueprintPolyfill is not a function
cause This usually indicates that the `require()` statement failed to correctly import the function, perhaps due to a typo in the package name or an issue with the package's export.fixVerify the package is installed (`npm list ember-cli-typescript-blueprint-polyfill`) and the `require()` path/syntax is correct: `const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill');`. -
Blueprint does not transform TypeScript files into JavaScript.
cause The `shouldTransformTypeScript: true` flag is missing or incorrectly set in the blueprint's `index.js`, or the polyfill's `init` call is missing/incorrect.fixEnsure `shouldTransformTypeScript: true,` is present and `typescriptBlueprintPolyfill(this);` is called within the `init()` method.
Warnings
- deprecated This polyfill is generally no longer needed for Ember CLI versions that natively support TypeScript blueprints (Ember CLI v4.x and above). Using it in modern projects is redundant and could potentially lead to unexpected behavior if not carefully managed alongside native features.
- gotcha For the polyfill to work, the `shouldTransformTypeScript: true` property must be explicitly set in the blueprint's `module.exports` object. Forgetting this flag will prevent TypeScript files from being processed.
- gotcha The `typescriptBlueprintPolyfill` function must be called within the blueprint's `init` method, and the blueprint instance (`this`) must be passed as its argument. Incorrect invocation or passing the wrong context will prevent the polyfill from applying transformations.
Install
-
npm install ember-cli-typescript-blueprint-polyfill -
yarn add ember-cli-typescript-blueprint-polyfill -
pnpm add ember-cli-typescript-blueprint-polyfill
Imports
- typescriptBlueprintPolyfill
import typescriptBlueprintPolyfill from 'ember-cli-typescript-blueprint-polyfill';
const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill');
Quickstart
// my-app/blueprints/foo/index.js
const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill');
module.exports = {
// Required flag to indicate that the blueprint contains TypeScript files
shouldTransformTypeScript: true,
init() {
// Ensure the super class's init method is called if it exists
this._super && this._super.init.apply(this, arguments);
// Call the polyfill with 'this' (the blueprint instance) as the argument
typescriptBlueprintPolyfill(this);
},
// Other blueprint methods like locals, fileMapTokens, etc.
// ...
};