Skip to content

Commit 27ac52a

Browse files
authored
Remove runtime alias hack (#5142)
* 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
1 parent a73829f commit 27ac52a

File tree

7 files changed

+40
-20
lines changed

7 files changed

+40
-20
lines changed

packages/babel-preset-react-app/create.js

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
'use strict';
88

9+
const path = require('path');
10+
911
const validateBoolOption = (name, value, defaultValue) => {
1012
if (typeof value === 'undefined') {
1113
value = defaultValue;
@@ -26,8 +28,21 @@ module.exports = function(api, opts, env) {
2628
var isEnvDevelopment = env === 'development';
2729
var isEnvProduction = env === 'production';
2830
var isEnvTest = env === 'test';
31+
2932
var isFlowEnabled = validateBoolOption('flow', opts.flow, true);
3033
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true);
34+
var useAbsoluteRuntime = validateBoolOption(
35+
'absoluteRuntime',
36+
opts.absoluteRuntime,
37+
true
38+
);
39+
40+
var absoluteRuntimePath = undefined;
41+
if (useAbsoluteRuntime) {
42+
absoluteRuntimePath = path.dirname(
43+
require.resolve('@babel/runtime/package.json')
44+
);
45+
}
3146

3247
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
3348
throw new Error(
@@ -120,6 +135,10 @@ module.exports = function(api, opts, env) {
120135
// We should turn this on once the lowest version of Node LTS
121136
// supports ES Modules.
122137
useESModules: isEnvDevelopment || isEnvProduction,
138+
// Undocumented option that lets us encapsulate our runtime, ensuring
139+
// the correct version is used
140+
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
141+
absoluteRuntime: absoluteRuntimePath,
123142
},
124143
],
125144
isEnvProduction && [

packages/babel-preset-react-app/dependencies.js

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
'use strict';
88

9+
const path = require('path');
10+
911
const validateBoolOption = (name, value, defaultValue) => {
1012
if (typeof value === 'undefined') {
1113
value = defaultValue;
@@ -33,7 +35,21 @@ module.exports = function(api, opts) {
3335
var isEnvDevelopment = env === 'development';
3436
var isEnvProduction = env === 'production';
3537
var isEnvTest = env === 'test';
38+
3639
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, false);
40+
var useAbsoluteRuntime = validateBoolOption(
41+
'absoluteRuntime',
42+
opts.absoluteRuntime,
43+
true
44+
);
45+
46+
var absoluteRuntimePath = undefined;
47+
if (useAbsoluteRuntime) {
48+
absoluteRuntimePath = path.dirname(
49+
require.resolve('@babel/runtime/package.json')
50+
);
51+
}
52+
3753
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
3854
throw new Error(
3955
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -95,6 +111,10 @@ module.exports = function(api, opts) {
95111
// We should turn this on once the lowest version of Node LTS
96112
// supports ES Modules.
97113
useESModules: isEnvDevelopment || isEnvProduction,
114+
// Undocumented option that lets us encapsulate our runtime, ensuring
115+
// the correct version is used
116+
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
117+
absoluteRuntime: absoluteRuntimePath,
98118
},
99119
],
100120
// Adds syntax support for import()

packages/babel-preset-react-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@babel/preset-env": "7.1.0",
3131
"@babel/preset-flow": "7.0.0",
3232
"@babel/preset-react": "7.0.0",
33+
"@babel/runtime": "7.0.0",
3334
"babel-loader": "8.0.2",
3435
"babel-plugin-macros": "2.4.2",
3536
"babel-plugin-transform-dynamic-import": "2.1.0",

packages/react-error-overlay/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"devDependencies": {
3333
"@babel/code-frame": "7.0.0",
3434
"@babel/core": "7.1.0",
35-
"@babel/runtime": "7.0.0",
3635
"anser": "1.4.7",
3736
"babel-core": "7.0.0-bridge.0",
3837
"babel-eslint": "9.0.0",

packages/react-scripts/config/webpack.config.dev.js

-9
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,6 @@ module.exports = {
144144
// for React Native Web.
145145
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
146146
alias: {
147-
// @remove-on-eject-begin
148-
// Resolve Babel runtime relative to react-scripts.
149-
// It usually still works on npm 3 without this but it would be
150-
// unfortunate to rely on, as react-scripts could be symlinked,
151-
// and thus @babel/runtime might not be resolvable from the source.
152-
'@babel/runtime': path.dirname(
153-
require.resolve('@babel/runtime/package.json')
154-
),
155-
// @remove-on-eject-end
156147
// Support React Native Web
157148
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
158149
'react-native': 'react-native-web',

packages/react-scripts/config/webpack.config.prod.js

-9
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,6 @@ module.exports = {
199199
// for React Native Web.
200200
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
201201
alias: {
202-
// @remove-on-eject-begin
203-
// Resolve Babel runtime relative to react-scripts.
204-
// It usually still works on npm 3 without this but it would be
205-
// unfortunate to rely on, as react-scripts could be symlinked,
206-
// and thus @babel/runtime might not be resolvable from the source.
207-
'@babel/runtime': path.dirname(
208-
require.resolve('@babel/runtime/package.json')
209-
),
210-
// @remove-on-eject-end
211202
// Support React Native Web
212203
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
213204
'react-native': 'react-native-web',

packages/react-scripts/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
},
2323
"dependencies": {
2424
"@babel/core": "7.1.0",
25-
"@babel/runtime": "7.0.0",
2625
"@svgr/webpack": "2.4.1",
2726
"babel-core": "7.0.0-bridge.0",
2827
"babel-eslint": "9.0.0",

0 commit comments

Comments
 (0)