Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #214] User ember-cli-babel’s public API to discover config (pl… #218

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 31 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,48 @@ 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)
stefanpenner marked this conversation as resolved.
Show resolved Hide resolved
);
});
}
const babelAddon = (this.app.project as any).findAddonByName('ember-cli-babel');
const babelConfig = babelAddon.buildBabelOptions({
'ember-cli-babel': {
includeExternalHelpers: true,
compileModules: false,
disableDebugTooling: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we needed this to be false not true...

disablePresetEnv: false,
disableEmberModulesAPIPolyfill: false,
disableDecoratorTransforms: false,
},
});

let plugins = babelConfig.plugins as any[];
let presets = babelConfig.presets;

// 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.
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)
);
});
// install debug 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