Skip to content

Commit

Permalink
Upgrade to babel-plugin-ember-template-compilation v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman committed Dec 21, 2022
1 parent 9f1882d commit 386e54f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
76 changes: 37 additions & 39 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,45 +196,43 @@ function setup(pluginInfo, options) {

let htmlbarsOptions = buildOptions(projectConfig, templateCompilerPath, pluginInfo);
let { templateCompiler } = htmlbarsOptions;

let templatePrecompile = templateCompiler.precompile;

let precompile = (template, _options) => {
// we have to reverse these for reasons that are a bit bonkers. the initial
// version of this system used `registeredPlugin` from
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
// only had `registerPlugin`, and there was no way to pass plugins directly
// to the call to `compile`/`precompile`). calling `registerPlugin`
// unfortunately **inverted** the order of plugins (it essentially did
// `PLUGINS = [plugin, ...PLUGINS]`).
//
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
let astPlugins = [...pluginInfo.plugins].reverse();

let options = {
plugins: {
ast: astPlugins,
},

..._options,
if (options.requiresModuleApiPolyfill) {
let templatePrecompile = templateCompiler.precompile;

let precompile = (template, _options) => {
// we have to reverse these for reasons that are a bit bonkers. the initial
// version of this system used `registeredPlugin` from
// `ember-template-compiler.js` to set up these plugins (because Ember ~ 1.13
// only had `registerPlugin`, and there was no way to pass plugins directly
// to the call to `compile`/`precompile`). calling `registerPlugin`
// unfortunately **inverted** the order of plugins (it essentially did
// `PLUGINS = [plugin, ...PLUGINS]`).
//
// sooooooo...... we are forced to maintain that **absolutely bonkers** ordering
let astPlugins = [...pluginInfo.plugins].reverse();

let options = {
plugins: {
ast: astPlugins,
},

..._options,
};

return templatePrecompile(template, options);
};

return templatePrecompile(template, options);
};

precompile.baseDir = () => path.resolve(__dirname, '..');
precompile.baseDir = () => path.resolve(__dirname, '..');

let cacheKey;
precompile.cacheKey = () => {
if (cacheKey === undefined) {
cacheKey = makeCacheKey(templateCompilerPath, pluginInfo);
}
cacheKey;
};
let cacheKey;
precompile.cacheKey = () => {
if (cacheKey === undefined) {
cacheKey = makeCacheKey(templateCompilerPath, pluginInfo);
}
cacheKey;
};

let plugin;
if (options.requiresModuleApiPolyfill) {
plugin = [
return [
require.resolve('babel-plugin-htmlbars-inline-precompile'),
{
precompile,
Expand All @@ -245,10 +243,12 @@ function setup(pluginInfo, options) {
'ember-cli-htmlbars:inline-precompile',
];
} else {
plugin = [
return [
require.resolve('babel-plugin-ember-template-compilation'),
{
precompile,
// As above, we present the AST transforms in reverse order
transforms: [...pluginInfo.plugins].reverse(),
compilerPath: require.resolve(templateCompilerPath),
enableLegacyModules: [
'ember-cli-htmlbars',
'ember-cli-htmlbars-inline-precompile',
Expand All @@ -258,8 +258,6 @@ function setup(pluginInfo, options) {
'ember-cli-htmlbars:inline-precompile',
];
}

return plugin;
}

function getTemplateCompilerCacheKey(templateCompilerPath) {
Expand Down
5 changes: 4 additions & 1 deletion node-tests/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ describe('utils', function () {

it('detects when the ember-template-compilation plugin exists', function () {
let plugins = [
utils.setup({}, { requiresModuleApiPolyfill: false, templateCompilerPath: '.' }),
utils.setup(
{ plugins: [] },
{ requiresModuleApiPolyfill: false, templateCompilerPath: '.' }
),
];

assert.strictEqual(utils.isInlinePrecompileBabelPluginRegistered(plugins), true);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@ember/edition-utils": "^1.2.0",
"babel-plugin-ember-template-compilation": "^1.0.0",
"babel-plugin-ember-template-compilation": "^2.0.0",
"babel-plugin-htmlbars-inline-precompile": "^5.3.0",
"broccoli-debug": "^0.6.5",
"broccoli-persistent-filter": "^3.1.2",
Expand Down
23 changes: 10 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3441,10 +3441,10 @@ babel-helpers@^6.24.1:
babel-runtime "^6.22.0"
babel-template "^6.24.1"

babel-import-util@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-0.2.0.tgz#b468bb679919601a3570f9e317536c54f2862e23"
integrity sha512-CtWYYHU/MgK88rxMrLfkD356dApswtR/kWZ/c6JifG1m10e7tBBrs/366dFzWMAoqYmG5/JSh+94tUSpIwh+ag==
babel-import-util@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/babel-import-util/-/babel-import-util-1.3.0.tgz#dc9251ea39a7747bd586c1c13b8d785a42797f8e"
integrity sha512-PPzUT17eAI18zn6ek1R3sB4Krc/MbnmT1MkZQFmyhjoaEGBVwNABhfVU9+EKcDSKrrOm9OIpGhjxukx1GCiy1g==

babel-loader@^8.0.6:
version "8.2.2"
Expand Down Expand Up @@ -3512,15 +3512,12 @@ babel-plugin-ember-modules-api-polyfill@^3.5.0:
dependencies:
ember-rfc176-data "^0.3.17"

babel-plugin-ember-template-compilation@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-1.0.0.tgz#984bc2ceb0bb864e878e25a9ca5c2a6153c96881"
integrity sha512-SvDQ+DbimZEq7XZztxiCKPNO3/HEwAOKBdJ9r4qtMpgmSuuhzO1elkixJTrnwnkLv1titAYAXNqLVD1fkE4Vgg==
babel-plugin-ember-template-compilation@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-ember-template-compilation/-/babel-plugin-ember-template-compilation-2.0.0.tgz#41d895874ba6119dd461f61993c16d1154bf8a57"
integrity sha512-d+4jaB2ik0rt9TH0K9kOlKJeRBHEb373FgFMcU9ZaJL2zYuVXe19bqy+cWlLpLf1tpOBcBG9QTlFBCoImlOt1g==
dependencies:
babel-import-util "^0.2.0"
line-column "^1.0.2"
magic-string "^0.25.7"
string.prototype.matchall "^4.0.5"
babel-import-util "^1.3.0"

babel-plugin-filter-imports@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -13583,7 +13580,7 @@ string-width@^3.0.0, string-width@^3.1.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"

string.prototype.matchall@^4.0.4, string.prototype.matchall@^4.0.5:
string.prototype.matchall@^4.0.4:
version "4.0.6"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.6.tgz#5abb5dabc94c7b0ea2380f65ba610b3a544b15fa"
integrity sha512-6WgDX8HmQqvEd7J+G6VtAahhsQIssiZ8zl7zKh1VDMFyL3hRTJP4FTNA3RbIp2TOQ9AYNDcc7e3fH0Qbup+DBg==
Expand Down

0 comments on commit 386e54f

Please sign in to comment.