Commit 622b5e9
Babel preset: don't override
Summary:
Currently the RN Babel preset has this surprising bit of behaviour:
```js
module.exports = (options, babel) => {
if (options.withDevTools == null) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!env || env === 'development') {
return getPreset(null, {...options, dev: true}, babel);
}
}
return getPreset(null, options, babel);
};
```
If the (undocumented, otherwise unused) `withDevTools` option is set (to anything), we will override any given value of `dev` to `true` if `BABEL_ENV` || `NODE_ENV || 'development' === 'development'`.
To put that another way, with `NODE_ENV=development` and `BABEL_ENV` unset, we would always produce a dev bundle even if `{ dev: false }`
Expo sets `withDevTools: false` to stop this happening, and always set `dev` (so this diff means **no observable change under Expo**):
https://github.com/expo/expo/blob/4a46dbff7a5a77d9fe06d30a70d7fab38cfc7f9a/packages/babel-preset-expo/build/index.js#L235-L236
This odd-looking override was introduced in 2017 in bc22a4d / D5237158 as a way to gate `babel/plugin-transform-react-jsx-source`, *before the preset accepted any other options* - it was never intended to override `dev`. Now, we gate that same plugin under `options.dev`.
## Inferring `dev` when unspecified
The one potentially load-bearing piece of this is that, when a consumer specifies neither `withDevTools` nor `dev` (or maybe no options at all), this code serves to infer it from `process.env.BABEL_ENV || process.env.NODE_ENV`, which is reasonable and actually closer to the way typical plugins/presets work, but a better mechanism compatible with Babel's cache is to use the `env()` API (which defaults to `process.env.BABEL_ENV || process.env.NODE_ENV`, so preserves behaviour).
https://babeljs.io/docs/config-files#apienv
## This change
- Removes the obsolete use of `withDevToolss`, and never overrides the explicitly-passed `dev`
- Where `dev` is not specified, falls back to the Babel environment.
Changelog:
[General][Fixed] Babel-preset: Don't override explicitly-passed `dev` config if obsolete `withDevTools` is missing
Reviewed By: huntie
Differential Revision: D94660480dev based on omission of obsolete withDevTools, infer from env() instead. (#55805)1 parent 34779df commit 622b5e9
1 file changed
+5
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | | - | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
158 | | - | |
| 160 | + | |
159 | 161 | | |
160 | 162 | | |
161 | 163 | | |
162 | | - | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| |||
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | 267 | | |
272 | 268 | | |
273 | 269 | | |
| |||
0 commit comments