Ember CLI Preprocessor Registry
Ember CLI Preprocessor Registry (npm: `ember-cli-preprocess-registry`) is an internal utility package within the Ember CLI ecosystem, providing a centralized registry for managing various preprocessors for `css`, `template`, and `js` assets. It is currently at version 5.0.1 and primarily maintained as needed for Ember CLI development, without a strict independent release cadence. Its key differentiator is its deep integration into Ember CLI's build pipeline, offering a standard way for addons to register and interact with asset transformations via hooks like `setupPreprocessorRegistry`. This package is not typically consumed directly by end-user applications but is a core component for Ember CLI addons wishing to extend asset compilation.
Common errors
-
Error: Node.js v14.x is not supported by ember-cli-preprocess-registry@5.x
cause Running an Ember CLI project with `ember-cli-preprocess-registry` version 5.x on an unsupported Node.js version (e.g., Node.js < 16).fixUpgrade your Node.js environment to version 16 or 18 and above. For example, use `nvm install 18 && nvm use 18`. -
TypeError: Cannot read properties of undefined (reading 'add') at setupPreprocessorRegistry
cause Attempting to call `registry.add` or other methods on an undefined `registry` object, often due to an incorrect `type` check or a misconfigured addon.fixVerify that your `setupPreprocessorRegistry` hook correctly receives the `registry` argument and that any conditional logic for `type` allows the `registry` object to be used when appropriate (e.g., `if (type === 'parent')`). -
Preprocessor plugin 'my-plugin' must define a `name` property.
cause A custom preprocessor plugin object passed to `registry.add` is missing the required `name` property.fixAdd a `name` getter to your plugin object, e.g., `get name() { return 'my-plugin'; }`.
Warnings
- breaking Version 5.0.0 dropped support for Node.js versions older than 16. Ensure your Node.js environment meets the '16.* || >= 18' requirement.
- breaking In version 5.0.0, the package was ES6ified, and support for legacy template plugins was entirely removed. Existing code relying on these deprecated template plugin types will break.
- breaking The `registry.remove()` method was broken in version 5.0.0, failing to remove plugins by name. This functionality was restored in v5.0.1. Addons relying on dynamically removing plugins by name would have experienced issues in v5.0.0.
- gotcha Plugins added to the registry must implement a `name` getter and a `toTree(tree)` method (for Broccoli-compatible plugins). Failing to provide these can lead to runtime errors within the Ember CLI build.
Install
-
npm install ember-cli-preprocess-registry -
yarn add ember-cli-preprocess-registry -
pnpm add ember-cli-preprocess-registry
Imports
- Registry
import { Registry } from 'ember-cli-preprocess-registry';const Registry = require('ember-cli-preprocess-registry'); - Registry
const { Registry } = require('ember-cli-preprocess-registry');import Registry from 'ember-cli-preprocess-registry';
- registry (parameter)
import { registry } from 'ember-cli-preprocess-registry'; // Incorrect way to obtain the registry instance for addon usagemodule.exports = { name: 'my-addon', setupPreprocessorRegistry(type, registry) { if (type === 'parent') { registry.add('js', { name: 'my-js-preprocessor', toTree(tree) { return tree; } }); } } };
Quickstart
module.exports = {
name: 'special-js-sauce',
setupPreprocessorRegistry(type, registry) {
if (type !== 'parent') { return; }
registry.add('js', {
name: 'special-js-sauce-preprocessor',
toTree(tree) {
console.log('Processing JavaScript tree with special-js-sauce-preprocessor');
// In a real scenario, 'tree' would be a Broccoli node and processing
// would return a new Broccoli node. For demonstration, we return it as is.
return tree;
}
});
console.log('Registered special-js-sauce-preprocessor for type "js"');
const jsPlugins = registry.load('js');
console.log(`Current JS plugins: ${jsPlugins.map(p => p.name).join(', ')}`);
}
};