Skip to content

Commit

Permalink
Remove runtime alias hack (#5142)
Browse files Browse the repository at this point in the history
* Remove runtime alias hack

* Pass absolute path to preset

* Change comment

* Give a relative path to absolute runtime

* Clean up config

* Tweak again

* Make absolute runtime the default

* Remove runtime package from error overlay
  • Loading branch information
Timer committed Sep 27, 2018
1 parent a73829f commit 27ac52a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
19 changes: 19 additions & 0 deletions packages/babel-preset-react-app/create.js
Expand Up @@ -6,6 +6,8 @@
*/
'use strict';

const path = require('path');

const validateBoolOption = (name, value, defaultValue) => {
if (typeof value === 'undefined') {
value = defaultValue;
Expand All @@ -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(
Expand Down Expand Up @@ -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 && [
Expand Down
20 changes: 20 additions & 0 deletions packages/babel-preset-react-app/dependencies.js
Expand Up @@ -6,6 +6,8 @@
*/
'use strict';

const path = require('path');

const validateBoolOption = (name, value, defaultValue) => {
if (typeof value === 'undefined') {
value = defaultValue;
Expand Down Expand Up @@ -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 ' +
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-react-app/package.json
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/react-error-overlay/package.json
Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions packages/react-scripts/config/webpack.config.dev.js
Expand Up @@ -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',
Expand Down
9 changes: 0 additions & 9 deletions packages/react-scripts/config/webpack.config.prod.js
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion packages/react-scripts/package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 27ac52a

Please sign in to comment.