-
Notifications
You must be signed in to change notification settings - Fork 137
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
New babel config #2016
New babel config #2016
Changes from all commits
195014e
e3a40c1
a5e28b3
fb442c6
6c5d77d
788e9d4
22e50e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { locateEmbroiderWorkingDir } from '@embroider/core'; | ||
import { existsSync, readJSONSync } from 'fs-extra'; | ||
import { join } from 'path'; | ||
|
||
export function loadLegacyPlugins() { | ||
const path = join(locateEmbroiderWorkingDir(process.cwd()), '_babel_config_.json'); | ||
if (!existsSync(path)) { | ||
throw new Error(`Could not load the Babel plugins required by classic addons from ${path}`); | ||
} | ||
|
||
const { plugins } = readJSONSync(path); | ||
_warnIfNoLegacyPlugins(plugins); | ||
return plugins ?? []; | ||
} | ||
|
||
export function loadPluginDebugMacros() { | ||
return [ | ||
[ | ||
'babel-plugin-debug-macros', | ||
{ | ||
flags: [ | ||
{ | ||
source: '@glimmer/env', | ||
flags: { | ||
DEBUG: true, | ||
CI: false, | ||
}, | ||
}, | ||
], | ||
debugTools: { | ||
isDebug: true, | ||
source: '@ember/debug', | ||
assertPredicateIndex: 1, | ||
}, | ||
externalizeHelpers: { | ||
module: '@ember/debug', | ||
}, | ||
}, | ||
'@ember/debug stripping', | ||
], | ||
[ | ||
'babel-plugin-debug-macros', | ||
{ | ||
externalizeHelpers: { | ||
module: '@ember/application/deprecations', | ||
}, | ||
debugTools: { | ||
isDebug: true, | ||
source: '@ember/application/deprecations', | ||
assertPredicateIndex: 1, | ||
}, | ||
}, | ||
'@ember/application/deprecations stripping', | ||
], | ||
]; | ||
} | ||
|
||
function _warnIfNoLegacyPlugins(legacyPlugins: any) { | ||
if (!legacyPlugins || !legacyPlugins.length) { | ||
console.warn(` | ||
Your Ember app doesn't use any classic addon that requires Babel plugins. | ||
In your babel.config.cjs, you can safely remove the usage of loadLegacyPlugins. | ||
|
||
Remove: | ||
- const { loadLegacyPlugins } = require('@embroider/compat'); | ||
- ...loadLegacyPlugins(), | ||
|
||
If you install a classic addon in your app afterward, make sure to add any Babel config it may require to babel.config.cjs. | ||
`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,6 +581,9 @@ export class CompatAppBuilder { | |
`module.exports = ${JSON.stringify(pconfig.config, null, 2)}`, | ||
'utf8' | ||
); | ||
outputJSONSync(join(locateEmbroiderWorkingDir(this.compatApp.root), '_babel_config_.json'), pconfig.config, { | ||
spaces: 2, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is adding a new output location without removing the previous one on the lines above? Also, similar to my comment in combat-app.ts, this value we're creating no longer needs to be a whole babel config. It's just a file that exports a |
||
writeFileSync( | ||
join(locateEmbroiderWorkingDir(this.compatApp.root), '_babel_filter_.js'), | ||
babelFilterTemplate({ skipBabel: this.options.skipBabel, appRoot: this.origAppPackage.root }), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,21 +225,8 @@ export default class CompatApp { | |
|
||
@Memoize() | ||
babelConfig(): TransformOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole method can change name and return type because its only remaining responsibility is to capture the plugins added by v1 addons. It could become |
||
// this finds all the built-in babel configuration that comes with ember-cli-babel | ||
const babelAddon = (this.legacyEmberAppInstance.project as any).findAddonByName('ember-cli-babel'); | ||
const babelConfig = babelAddon.buildBabelOptions({ | ||
'ember-cli-babel': { | ||
...this.legacyEmberAppInstance.options['ember-cli-babel'], | ||
includeExternalHelpers: true, | ||
compileModules: false, | ||
disableDebugTooling: false, | ||
disablePresetEnv: false, | ||
disableEmberModulesAPIPolyfill: false, | ||
}, | ||
}); | ||
BlueCutOfficial marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let plugins = babelConfig.plugins as any[]; | ||
let presets = babelConfig.presets; | ||
let plugins: any[] = []; | ||
let presets: any[] = []; | ||
|
||
// this finds any custom babel configuration that's on the app (either | ||
// because the app author explicitly added some, or because addons have | ||
|
@@ -250,7 +237,19 @@ export default class CompatApp { | |
plugins = appBabel.plugins.concat(plugins); | ||
} | ||
if (appBabel.presets) { | ||
presets = appBabel.presets.concat(presets); | ||
if (this.legacyEmberAppInstance.options.useCustomBabelPresets) { | ||
throw new Error(` | ||
The following Babel presets have been found on the app custom Babel configuration: | ||
|
||
${presets} | ||
|
||
Either these presets have been added explicitly to the app (e.g. through ember-cli-babel options in ember-cli-build.js), either classic addons have pushed these presets into the app. | ||
With Embroider, you have full control over the Babel config via babel.config.cjs, and babel.config.cjs should be the only source of truth regarding Babel configuration; so classic addons no longer have the ability to push Babel presets. | ||
|
||
1. Add the presets you want to use to the babel.config.cjs. | ||
2. Once babel.config.cjs has the presets you need, remove the present error by setting "useCustomBabelPresets" to false in the build options. | ||
`); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry that this is premature. Long after someone has seen this message and removed the legacy plugin support, someone on their team could add an addon that needs it and be puzzled why the addon doesn't work.
@mansona just suggested to me that perhaps it would be better to wait to tell people to remove the legacy plugin support until we can do a deprecation against any v1 addon trying to add babel plugins, and that sounds reasonable.