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

migrate @babel/preset-env to babel-preset-modules #24780

Merged
merged 3 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ const noModuleTarget = {
: ['Last 2 versions'],
};

const moduleTarget = {
'esmodules': true,
};

// eslint-disable-next-line local/no-module-exports
module.exports = function(api) {
api.cache(true);
Expand All @@ -51,14 +47,21 @@ module.exports = function(api) {
}
return {
'presets': [
[
'@babel/preset-env',
{
'modules': isDist ? false : 'commonjs',
'loose': true,
'targets': esm ? moduleTarget : noModuleTarget,
},
],
esm
? [
'babel-preset-modules',
{
'loose': true,
},
]
: [
'@babel/preset-env',
{
'modules': isDist ? false : 'commonjs',
'loose': true,
'targets': noModuleTarget,
},
],
],
'compact': false,
'sourceType': 'module',
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function compile(entryModuleFilenames, outputDir, outputFilename, options) {
assume_function_wrapper: true,
// Transpile from ES6 to ES5 if not running with `--esm`
// otherwise transpilation is done by Babel
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this comment need to be updated?

language_in: 'ECMASCRIPT6',
language_in: argv.esm ? 'ECMASCRIPT_2017' : 'ECMASCRIPT6',
language_out: argv.esm ? 'NO_TRANSPILE' : 'ECMASCRIPT5',
// We do not use the polyfills provided by closure compiler.
// If you need a polyfill. Manually include them in the
Expand Down
7 changes: 5 additions & 2 deletions build-system/compile/single-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ exports.getFlags = function(config) {
source_map_include_content: !!argv.full_sourcemaps,
source_map_location_mapping: ['|/'],
//new_type_inf: true,
language_in: 'ES6',
// By default closure puts all of the public exports on the global, but
// because of the wrapper modules (to mitigate async loading of scripts)
// that we add to the js binaries this prevents other js binaries from
// accessing the symbol, we remedy this by attaching all public exports
// to `_` and everything imported across modules is is accessed through `_`.
rename_prefix_namespace: '_',
language_out: config.language_out || 'ES5',
language_in: config.esm ? 'ECMASCRIPT_2017' : 'ECMASCRIPT6',
language_out: config.esm
? 'NO_TRANSPILE'
: config.language_out || 'ECMASCRIPT5',
chunk_output_path_prefix: config.writeTo || 'out/',
module_resolution: 'NODE',
process_common_js_modules: true,
Expand Down Expand Up @@ -551,6 +553,7 @@ exports.singlePassCompile = async function(entryModule, options) {
.getFlags({
modules: [entryModule].concat(extensions),
writeTo: singlePassDest,
esm: options.esm,
define: options.define,
externs: options.externs,
hideWarningsFor: options.hideWarningsFor,
Expand Down
4 changes: 2 additions & 2 deletions build-system/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ exports.transpileTs = function(srcDir, srcFilename) {
const tsEntry = path.join(srcDir, srcFilename).replace(/\.js$/, '.ts');
const tsConfig = ts.convertCompilerOptionsFromJson(
{
'module': 'ES6',
'target': 'ES6',
'module': 'esnext',
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

'target': 'esnext',
},
srcDir
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@ampproject/animations": "0.2.0",
"@ampproject/worker-dom": "0.19.0",
"babel-preset-modules": "0.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should @babel/preset-env have been removed from package.json?

"document-register-element": "1.5.0",
"dompurify": "2.0.2",
"moment": "2.24.0",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,16 @@ babel-preset-jest@^24.9.0:
"@babel/plugin-syntax-object-rest-spread" "^7.0.0"
babel-plugin-jest-hoist "^24.9.0"

babel-preset-modules@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/babel-preset-modules/-/babel-preset-modules-0.0.2.tgz#3ece9871bb022784a76749114e7b8bb109a6ec1e"
integrity sha512-YWjLfgPRGrQNPEZITnyIgsMITrPjA4ZvLS6hVyTCYgqymR0+l2P1jTd3lMHZ+hBDqAHDSGGKD20oxUmQvvvubg==
dependencies:
"@babel/plugin-proposal-unicode-property-regex" "^7.4.4"
"@babel/plugin-transform-dotall-regex" "^7.4.4"
"@babel/types" "^7.4.4"
esutils "^2.0.2"

babel-runtime@^6.22.0, babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
Expand Down