Skip to content

Commit

Permalink
[Fixes #214] User ember-cli-babel’s public API to discover config (pl…
Browse files Browse the repository at this point in the history
…ugins/preset)
  • Loading branch information
stefanpenner committed Jun 12, 2019
1 parent a4f04d9 commit 55d6e93
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions packages/compat/src/v1-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { WatchedDir } from 'broccoli-source';
import resolve from 'resolve';
import V1Package from './v1-package';
import { Tree } from 'broccoli-plugin';
import get from 'lodash/get';
import { V1Config, WriteV1Config } from './v1-config';
import { PackageCache, TemplateCompiler, TemplateCompilerPlugins, AddonMeta, Package } from '@embroider/core';
import { writeJSONSync, ensureDirSync, copySync, readdirSync, pathExistsSync } from 'fs-extra';
Expand Down Expand Up @@ -184,55 +183,35 @@ export default class V1App implements V1Package {

@Memoize()
babelConfig(): TransformOptions {
let plugins = get(this.app.options, 'babel.plugins') as any[];
if (!plugins) {
plugins = [];
} else {
plugins = plugins.filter(p => {
// even if the app was using @embroider/macros, we drop it from the config
// here in favor of our globally-configured one.
return (
!isEmbroiderMacrosPlugin(p) &&
// similarly, if the app was already using
// ember-cli-htmlbars-inline-precompile, we remove it here because we
// have our own always-installed version of that (v2 addons are
// allowed to assume it will be present in the final app build, the
// app doesn't get to turn that off or configure it.).
!TemplateCompiler.isInlinePrecompilePlugin(p)
);
});
}
const babelAddon = (this.app.project as any).findAddonByName('ember-cli-babel');
const babelConfig = babelAddon.buildBabelOptions({
'ember-cli-babel': {
includeExternalHelpers: true,
compileModules: false,
disableDebugTooling: true,
disablePresetEnv: false,
disableEmberModulesAPIPolyfill: false,
disableDecoratorTransforms: false,
},
});

// this is reproducing what ember-cli-babel does. It would be nicer to just
// call it, but it require()s all the plugins up front, so not serializable.
// In its case, it's mostly doing it to set basedir so that broccoli caching
// will be happy, but that's irrelevant to us here.
let plugins = babelConfig.plugins as any[];
let presets = babelConfig.presets;

// install embroider macros
plugins.push(this.debugMacrosPlugin());
let babelInstance = (this.app.project.addons as any[]).find(a => a.name === 'ember-cli-babel');
if (babelInstance._emberVersionRequiresModulesAPIPolyfill()) {
let ModulesAPIPolyfill = require.resolve('babel-plugin-ember-modules-api-polyfill');
let blacklist = babelInstance._getEmberModulesAPIBlacklist();
plugins.push([ModulesAPIPolyfill, { blacklist }]);
}

let config: TransformOptions = {
const config: TransformOptions = {
babelrc: false,
plugins,
presets: [
[
this.babelMajorVersion() === 6 ? require.resolve('babel-preset-env') : require.resolve('@babel/preset-env'),
{
targets: babelInstance._getTargets(),
modules: false,
},
],
],
presets,
// this is here because broccoli-middleware can't render a codeFrame full
// of terminal codes. It would be nice to add something like
// https://github.com/mmalecki/ansispan to broccoli-middleware so we can
// leave color enabled.
highlightCode: false,
};

return config;
}

Expand Down

0 comments on commit 55d6e93

Please sign in to comment.