diff --git a/packages/babel-preset-react-app/create.js b/packages/babel-preset-react-app/create.js index dbc9ea98eac..b53dd0aab23 100644 --- a/packages/babel-preset-react-app/create.js +++ b/packages/babel-preset-react-app/create.js @@ -6,6 +6,8 @@ */ 'use strict'; +const path = require('path'); + const validateBoolOption = (name, value, defaultValue) => { if (typeof value === 'undefined') { value = defaultValue; @@ -26,8 +28,21 @@ module.exports = function(api, opts, env) { var isEnvDevelopment = env === 'development'; var isEnvProduction = env === 'production'; var isEnvTest = env === 'test'; + var isFlowEnabled = validateBoolOption('flow', opts.flow, true); var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true); + var useAbsoluteRuntime = validateBoolOption( + 'absoluteRuntime', + opts.absoluteRuntime, + true + ); + + var absoluteRuntimePath = undefined; + if (useAbsoluteRuntime) { + absoluteRuntimePath = path.dirname( + require.resolve('@babel/runtime/package.json') + ); + } if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) { throw new Error( @@ -120,6 +135,10 @@ module.exports = function(api, opts, env) { // We should turn this on once the lowest version of Node LTS // supports ES Modules. useESModules: isEnvDevelopment || isEnvProduction, + // Undocumented option that lets us encapsulate our runtime, ensuring + // the correct version is used + // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42 + absoluteRuntime: absoluteRuntimePath, }, ], isEnvProduction && [ diff --git a/packages/babel-preset-react-app/dependencies.js b/packages/babel-preset-react-app/dependencies.js index 6872488e80a..19a6e74557b 100644 --- a/packages/babel-preset-react-app/dependencies.js +++ b/packages/babel-preset-react-app/dependencies.js @@ -6,6 +6,8 @@ */ 'use strict'; +const path = require('path'); + const validateBoolOption = (name, value, defaultValue) => { if (typeof value === 'undefined') { value = defaultValue; @@ -33,7 +35,21 @@ module.exports = function(api, opts) { var isEnvDevelopment = env === 'development'; var isEnvProduction = env === 'production'; var isEnvTest = env === 'test'; + var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, false); + var useAbsoluteRuntime = validateBoolOption( + 'absoluteRuntime', + opts.absoluteRuntime, + true + ); + + var absoluteRuntimePath = undefined; + if (useAbsoluteRuntime) { + absoluteRuntimePath = path.dirname( + require.resolve('@babel/runtime/package.json') + ); + } + if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) { throw new Error( 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' + @@ -95,6 +111,10 @@ module.exports = function(api, opts) { // We should turn this on once the lowest version of Node LTS // supports ES Modules. useESModules: isEnvDevelopment || isEnvProduction, + // Undocumented option that lets us encapsulate our runtime, ensuring + // the correct version is used + // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42 + absoluteRuntime: absoluteRuntimePath, }, ], // Adds syntax support for import() diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index 8a75a537586..4bb3240a90c 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -30,6 +30,7 @@ "@babel/preset-env": "7.1.0", "@babel/preset-flow": "7.0.0", "@babel/preset-react": "7.0.0", + "@babel/runtime": "7.0.0", "babel-loader": "8.0.2", "babel-plugin-macros": "2.4.2", "babel-plugin-transform-dynamic-import": "2.1.0", diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index 88c2c9d06b2..c08a2cfb41f 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -32,7 +32,6 @@ "devDependencies": { "@babel/code-frame": "7.0.0", "@babel/core": "7.1.0", - "@babel/runtime": "7.0.0", "anser": "1.4.7", "babel-core": "7.0.0-bridge.0", "babel-eslint": "9.0.0", diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index fb9dba5568f..ab54cc33cf2 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -144,15 +144,6 @@ module.exports = { // for React Native Web. extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'], alias: { - // @remove-on-eject-begin - // Resolve Babel runtime relative to react-scripts. - // It usually still works on npm 3 without this but it would be - // unfortunate to rely on, as react-scripts could be symlinked, - // and thus @babel/runtime might not be resolvable from the source. - '@babel/runtime': path.dirname( - require.resolve('@babel/runtime/package.json') - ), - // @remove-on-eject-end // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 43322611f17..fe92a483883 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -199,15 +199,6 @@ module.exports = { // for React Native Web. extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'], alias: { - // @remove-on-eject-begin - // Resolve Babel runtime relative to react-scripts. - // It usually still works on npm 3 without this but it would be - // unfortunate to rely on, as react-scripts could be symlinked, - // and thus @babel/runtime might not be resolvable from the source. - '@babel/runtime': path.dirname( - require.resolve('@babel/runtime/package.json') - ), - // @remove-on-eject-end // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 0738b4b74ab..d05871696de 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -22,7 +22,6 @@ }, "dependencies": { "@babel/core": "7.1.0", - "@babel/runtime": "7.0.0", "@svgr/webpack": "2.4.1", "babel-core": "7.0.0-bridge.0", "babel-eslint": "9.0.0",