Skip to content

Commit

Permalink
Fix compatiblity with ember-cli-babel@7.26.0+.
Browse files Browse the repository at this point in the history
ember-cli-babel@7.24 fixed a bug where the `buildBabelOptions` result
included a number of non-babel specific properties. Unfortunately,
while we were explicitly working around that bug (the `delete`'s in the
snippet here) but we **also** ended up relying on it with the usage of
`filterExtensions` property.

In order to make it possible for ember-auto-import to have a path
forward, ember-cli-babel@7.26.0 introduces a new public API to get a
list of the supported extensions (`babelAddon.getSupportedExtensions`).

This PR uses the presence of the `getSupportedExtensions` function to
decide if it needs to clear the abnormal properties or not, and fixes
usage of ember-auto-import along with ember-cli-babel@7.26+.
  • Loading branch information
rwjblue committed Mar 18, 2021
1 parent 4b93532 commit b014e3f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/ember-auto-import/ts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,26 @@ export default class Package {
// is using. We will use these so we can configure our parser to
// match.
let babelAddon = instance.addons.find(addon => addon.name === 'ember-cli-babel') as any;
let babelOptions = babelAddon.buildBabelOptions(options);
let extensions = babelOptions.filterExtensions || ['js'];
let version = parseInt(babelAddon.pkg.version.split('.')[0], 10);
let babelOptions, extensions;

if (typeof babelAddon.getSupportedExtensions === 'function') {
babelOptions = babelAddon.buildBabelOptions('babel');
extensions = babelAddon.getSupportedExtensions();
} else {
babelOptions = babelAddon.buildBabelOptions(options);
extensions = babelOptions.filterExtensions || ['js'];

// https://github.com/babel/ember-cli-babel/issues/227
delete babelOptions.annotation;
delete babelOptions.throwUnlessParallelizable;
delete babelOptions.filterExtensions;
}

// https://github.com/babel/ember-cli-babel/issues/227
delete babelOptions.annotation;
delete babelOptions.throwUnlessParallelizable;
delete babelOptions.filterExtensions;
if (babelOptions.plugins) {
babelOptions.plugins = babelOptions.plugins.filter((p: any) => !p._parallelBabel);
}
let version = parseInt(babelAddon.pkg.version.split('.')[0], 10);

return { babelOptions, extensions, version };
}

Expand Down

0 comments on commit b014e3f

Please sign in to comment.