Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline stage1 template compilation #1242

Merged
merged 12 commits into from
Nov 7, 2022
Merged
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Embroider Changelog

# main

## `@embroider/core`, `@embroider/compat`, `@embroidre/webpack`

- BREAKING: drop support for Ember < 3.28.

## `@ember/addon-dev`

- BREAKING: `@embroider/addon-template/template-transform-plugin` is removed
because `babel-plugin-ember-template-compilation >= 2.0.0-alpha.2` directly
supports source-to-source transformation (and it offers new capabilities to
AST transform authors that we would like to be available everywhere).

# Release 2022-10-06.0

## `@embroider/core` 1.8.3 -> 1.9.0 minor
Expand Down
2 changes: 1 addition & 1 deletion PORTING-ADDONS-TO-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Now that we've separated the test-app and docs app concerns from the addon, we c
`yarn add --dev @embroider/addon-dev rollup @rollup/plugin-babel @babel/core @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators`

6. Grab the [example babel config](https://github.com/embroider-build/embroider/blob/main/packages/addon-dev/sample-babel.config.json) and save it as `addon/babel.config.json`
- If you addon requires template transforms in order to publish to a shareable format. Apply transforms using the `@embroider/addon-dev/template-transform-plugin`. View how to use this in the [example babel.config.js](https://github.com/embroider-build/embroider/blob/main/packages/addon-dev/sample-babel.config.js)
- If you addon requires template transforms in order to publish to a shareable format. Apply transforms using the `babel-plugin-ember-template-compilation`. View how to use this in the [example babel.config.js](https://github.com/embroider-build/embroider/blob/main/packages/addon-dev/sample-babel.config.js)
7. Grab the [example rollup config](https://github.com/embroider-build/embroider/blob/main/packages/addon-dev/sample-rollup.config.js) and save it as `addon/rollup.config.js`.
8. Identify your **app reexports**. This is the list of modules from your addon that get reexported by files in the `addon/app` directory.
9. Delete the `addon/app` directory. You aren't going to need it anymore.
Expand Down
6 changes: 0 additions & 6 deletions packages/addon-dev/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/addon-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"exports": {
"./template-colocation-plugin": "./src/template-colocation-plugin.js",
"./template-transform-plugin": "./src/template-transform-plugin.js",
"./rollup": "./src/rollup.js"
},
"files": [
Expand Down
10 changes: 4 additions & 6 deletions packages/addon-dev/sample-babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
// be done during the addon build.
const someAstTransformPlugin = require('./some-ast-transform-plugin');

// The `@embroider/addon-dev/template-transform-plugin` has the following options:
// `options.astTransforms` - an array of functions or paths to preprocess the GlimmerAST
// `options.compilerPath` - Optional: Defaults to `ember-source/dist/ember-template-compiler`

module.exports = {
plugins: [
'@embroider/addon-dev/template-colocation-plugin',
[
'@embroider/addon-dev/template-transform-plugin',
'babel-plugin-ember-template-compilation',
{
astTransforms: [
targetFormat: 'hbs',
compilerPath: 'ember-source/dist/ember-template-compiler',
transforms: [
someAstTransformPlugin,
'./path/to/another-template-transform-plugin',
],
Expand Down
42 changes: 0 additions & 42 deletions packages/addon-dev/src/template-transform-plugin.ts

This file was deleted.

150 changes: 0 additions & 150 deletions packages/addon-dev/tests/template-transform-plugin.test.ts

This file was deleted.

36 changes: 36 additions & 0 deletions packages/compat/src/hbs-to-js-broccoli-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Node } from 'broccoli-node-api';
import Filter from 'broccoli-persistent-filter';
import { hbsToJS } from '@embroider/core';
import { join } from 'path';

export default class TemplateCompileTree extends Filter {
constructor(inputTree: Node) {
super(inputTree, {
name: `embroider-template-compile-stage1`,
persist: true,
extensions: ['hbs', 'handlebars'],
});
}

getDestFilePath(relativePath: string, entry: Parameters<Filter['getDestFilePath']>[1]) {
if (this.isDirectory(relativePath, entry)) {
return null;
}
for (let ext of ['hbs', 'handlebars']) {
if (relativePath.slice(-ext.length - 1) === '.' + ext) {
// we deliberately don't chop off the .hbs before appending .js, because if
// the user has both .js` and .hbs` side-by-side we don't want our new file
// to collide with theirs.
return relativePath + '.js';
}
}
return null;
}

processString(source: string, relativePath: string) {
return hbsToJS(source, relativePath);
}
baseDir() {
return join(__dirname, '..');
}
}
24 changes: 0 additions & 24 deletions packages/compat/src/template-compiler-broccoli-plugin.ts

This file was deleted.

Loading