From 1b9e0193c23c4d8d9f44b355023502411da146a5 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Thu, 8 Sep 2022 15:55:45 -0400 Subject: [PATCH] manually apply babel in older ember-cli versions --- lib/ember-addon-main.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ember-addon-main.js b/lib/ember-addon-main.js index d3b20b07..06696105 100644 --- a/lib/ember-addon-main.js +++ b/lib/ember-addon-main.js @@ -96,13 +96,36 @@ module.exports = { } this._addon.logger.debug(`setup *.hbs compiler with ${htmlbarsOptions.pluginNames}`); - return debugTree( + let output = debugTree( this._addon.transpileTree(inputTree, { isProduction, ...htmlbarsOptions, }), '03-output' ); + + let checker = new VersionChecker(this._addon.project).for('ember-cli', 'npm'); + let requiresBabelTree = checker.lt('3.13.0'); + let isAddon = this._addon.parent !== this._addon.project; + + // as a result of https://github.com/ember-cli/ember-cli-htmlbars/pull/749 we are relying + // on babel for all template comilation. This works fine since ember-cli@3.13 but before + // that there was a different path for **addon** templates and they would not be compiled + // correctly. This change wraps the output of addons in a babel tree since ember-cli + // isn't doing that properly. + if (requiresBabelTree && isAddon) { + let babelAddon = this._addon.parent.addons.find( + (addon) => addon.name === 'ember-cli-babel' + ); + output = babelAddon.transpileTree(output, { + babel: this._addon.parent.options.babel, + 'ember-cli-babel': { + compileModules: false, + }, + }); + } + + return output; }, precompile(string, _options) {