Skip to content

Commit

Permalink
Avoid conflicts with ember-cli-htmlbars-inline-precompile (#317)
Browse files Browse the repository at this point in the history
Avoid conflicts with ember-cli-htmlbars-inline-precompile
  • Loading branch information
rwjblue committed Oct 1, 2019
2 parents a645f9d + 71314df commit 15ca4ea
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = function() {
name: 'with-ember-cli-htmlbars-inline-precompile',
npm: {
devDependencies: {
'ember-cli-htmlbars-inline-precompile': '^2.1.0',
'ember-cli-htmlbars-inline-precompile': '^3.0.0',
},
},
},
Expand Down
63 changes: 52 additions & 11 deletions lib/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,43 @@ dBabelVersion: ${hasValidBabelVersion};`
if (type === 'parent') {
this.parentRegistry = registry;
}

let legacyInlinePrecompileAddon = this.parent.addons.find(
a => a.name === 'ember-cli-htmlbars-inline-precompile'
);
if (legacyInlinePrecompileAddon !== undefined) {
let heirarchy = ['ember-cli-htmlbars-inline-precompile'];
let pointer = this;
while (pointer.parent) {
heirarchy.push(pointer.pkg.name);
pointer = pointer.parent;
}

this.ui.writeDeprecateLine(
`${heirarchy
.reverse()
.join(
' > '
)} is no longer needed with ember-cli-htmlbars versions 4.0.0 and higher, please remove it from \`${
this.parent.root
}/package.json\``
);

// overwrite the `included` method on the
// ember-cli-htmlbars-inline-precompile instance this prevents issues
// when using ember-cli-htmlbars-inline-precompile < 3.0.1 (where both
// this addon and ember-cli-htmlbars-inline-precompile use the same
// babel-plugin-htmlbars-inline-precompile version and get confused about
// whether or not it registers its replacements)
//
// this only mutates the local addon _instance_ (not **all** instances of
// the addon) because we _know_ that this instance of ember-cli-htmlbars
// will take care of the precompilation of:
//
// import hbs from 'htmlbars-inline-precompile';
// import hbs from 'ember-cli-htmlbars-inline-precompile';
legacyInlinePrecompileAddon.included = function() {};
}
},

included() {
Expand All @@ -104,16 +141,10 @@ dBabelVersion: ${hasValidBabelVersion};`

let modules = {
'ember-cli-htmlbars': 'hbs',
'ember-cli-htmlbars-inline-precompile': 'default',
'htmlbars-inline-precompile': 'default',
};

// TODO: add deprecation to migrate import paths to use
// ember-cli-htmlbars instead of htmlbars-inline-precompile or
// ember-cli-htmlbars-inline-precompile
if (!this.parent.addons.find(a => a.name === 'ember-cli-htmlbars-inline-precompile')) {
modules['ember-cli-htmlbars-inline-precompile'] = 'default';
modules['htmlbars-inline-precompile'] = 'default';
}

if (pluginInfo.canParallelize) {
logger.debug('using parallel API with for babel inline precompilation plugin');

Expand Down Expand Up @@ -164,7 +195,7 @@ dBabelVersion: ${hasValidBabelVersion};`
},

/**
* This function checks if 'ember-cli-htmlbars-inline-precompile' is already present in babelPlugins.
* This function checks if 'babel-plugin-htmlbars-inline-precompile' is already present in babelPlugins.
* The plugin object will be different for non parallel API and parallel API.
* For parallel api, check the `baseDir` of a plugin to see if it has current dirname
* For non parallel api, check the 'modules' to see if it contains the babel plugin
Expand All @@ -173,14 +204,24 @@ dBabelVersion: ${hasValidBabelVersion};`
_isInlinePrecompileBabelPluginRegistered(plugins) {
return plugins.some(plugin => {
if (Array.isArray(plugin)) {
return plugin[0] === require.resolve('babel-plugin-htmlbars-inline-precompile');
let [pluginPathOrInstance, options] = plugin;

return (
pluginPathOrInstance === require.resolve('babel-plugin-htmlbars-inline-precompile') &&
typeof options.modules === 'object' &&
options.modules['ember-cli-htmlbars'] === 'hbs'
);
} else if (
plugin !== null &&
typeof plugin === 'object' &&
plugin._parallelBabel !== undefined
) {
return (
plugin._parallelBabel.requireFile === path.resolve(__dirname, 'lib/require-from-worker')
plugin._parallelBabel.requireFile ===
path.resolve(__dirname, 'lib/require-from-worker') &&
typeof plugin._parallelBabel.params === 'object' &&
typeof plugin._parallelBabel.params.modules === 'object' &&
plugin._parallelBabel.params.modules['ember-cli-htmlbars'] === 'hbs'
);
} else {
return false;
Expand Down

0 comments on commit 15ca4ea

Please sign in to comment.