babel-preset-expo 12.1.0-canary-20250131-5c4e588 → 12.1.0-canary-20250207-8bc5146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,45 +1,16 @@
1
1
  # babel-preset-expo
2
2
 
3
- This preset extends the default React Native preset (`@react-native/babel-preset`) and adds support for decorators, tree-shaking web packages, and loading font icons with optional native dependencies if they're installed.
3
+ This preset extends the default React Native preset (`@react-native/babel-preset`) and adds support for tree shaking, bundle splitting, React Server Components, Hermes compilation, advanced dead-code elimination, reanimated, Expo DOM components, server-side rendering, and more...
4
4
 
5
- You can use this preset in any React Native project as a drop-in replacement for `@react-native/babel-preset`. If your project isn't using native font loading or web support then this preset will only add support for decorators with `@babel/plugin-proposal-decorators` - this is mostly used for supporting legacy community libraries.
6
-
7
- If you start your **web** project with `@expo/webpack-config` or `npx expo start` and your project doesn't contain a `babel.config.js` or a `.babelrc` then it will default to using `babel-preset-expo` for loading.
5
+ You can use this preset in any React Native project as a drop-in replacement for `@react-native/babel-preset`.
8
6
 
9
7
  If you have problems with the code in this repository, please file issues & bug reports
10
- at https://github.com/expo/expo. Thanks!
8
+ at https://github.com/expo/expo.
11
9
 
12
10
  ## Expo Bundler Spec Compliance
13
11
 
14
12
  A bundler must follow these requirements if they are to be considered spec compliant for use with a **universal React** (Expo) project.
15
13
 
16
- ### Babel Loader
17
-
18
- The babel loading mechanism must include the following properties on its `caller`.
19
-
20
- #### platform
21
-
22
- A `platform` property denoting the target platform. If the `platform` is not defined, it will default to using `web` when the `bundler` is `webpack` -- this is temporary and will throw an error in the future.
23
-
24
- | Value | Description |
25
- | --------- | ----------------------- |
26
- | `ios` | Runs on iOS devices |
27
- | `android` | Runs on Android devices |
28
- | `web` | Runs in web browsers |
29
-
30
- #### bundler
31
-
32
- A `bundler` property denoting the name of the bundler that is being used to create the JavaScript bundle.
33
- If the `bundler` is not defined, it will default to checking if a `babel-loader` is used, if so then `webpack` will be used, otherwise it will default to `metro`.
34
-
35
- | Value | Description |
36
- | --------- | -------------------------------- |
37
- | `metro` | Bundling with [Metro][metro] |
38
- | `webpack` | Bundling with [Webpack][webpack] |
39
-
40
- [metro]: https://facebook.github.io/metro/
41
- [webpack]: https://webpack.js.org/
42
-
43
14
  ## Options
44
15
 
45
16
  ### `react-compiler`
@@ -205,3 +176,30 @@ All options can be passed in the platform-specific objects `native` and `web` to
205
176
  ```
206
177
 
207
178
  Platform-specific options have higher priority over top-level options.
179
+
180
+ ### Babel Loader
181
+
182
+ The Babel loading mechanism must include the following properties on its `caller`.
183
+
184
+ #### platform
185
+
186
+ A `platform` property denoting the target platform. If the `platform` is not defined, it will default to using `web` when the `bundler` is `webpack` -- this is temporary and will throw an error in the future.
187
+
188
+ | Value | Description |
189
+ | --------- | ----------------------- |
190
+ | `ios` | Runs on iOS devices |
191
+ | `android` | Runs on Android devices |
192
+ | `web` | Runs in web browsers |
193
+
194
+ #### bundler
195
+
196
+ A `bundler` property denoting the name of the bundler that is being used to create the JavaScript bundle.
197
+ If the `bundler` is not defined, it will default to checking if a `babel-loader` is used, if so then `webpack` will be used, otherwise it will default to `metro`.
198
+
199
+ | Value | Description |
200
+ | --------- | -------------------------------- |
201
+ | `metro` | Bundling with [Metro][metro] |
202
+ | `webpack` | Bundling with [Webpack][webpack] |
203
+
204
+ [metro]: https://facebook.github.io/metro/
205
+ [webpack]: https://webpack.js.org/
@@ -8,7 +8,7 @@ exports.reactClientReferencesPlugin = void 0;
8
8
  * Copyright © 2024 650 Industries.
9
9
  */
10
10
  const core_1 = require("@babel/core");
11
- const url_1 = __importDefault(require("url"));
11
+ const node_url_1 = __importDefault(require("node:url"));
12
12
  const common_1 = require("./common");
13
13
  function reactClientReferencesPlugin(api) {
14
14
  const isReactServer = api.caller(common_1.getIsReactServer);
@@ -32,7 +32,7 @@ function reactClientReferencesPlugin(api) {
32
32
  // This can happen in tests or systems that use Babel standalone.
33
33
  throw new Error('[Babel] Expected a filename to be set in the state');
34
34
  }
35
- const outputKey = url_1.default.pathToFileURL(filePath).href;
35
+ const outputKey = node_url_1.default.pathToFileURL(filePath).href;
36
36
  function iterateExports(callback, type) {
37
37
  const exportNames = new Set();
38
38
  // Collect all of the exports
package/build/common.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getAsyncRoutes = exports.getInlineEnvVarsEnabled = exports.getExpoRouterAbsoluteAppRoot = exports.getIsServer = exports.getReactCompiler = exports.getBaseUrl = exports.getIsNodeModule = exports.getIsProd = exports.getIsFastRefreshEnabled = exports.getIsDev = exports.getIsReactServer = exports.getPossibleProjectRoot = exports.getPlatform = exports.getBundler = exports.hasModule = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  function hasModule(name) {
9
9
  try {
10
10
  return !!require.resolve(name);
@@ -111,11 +111,11 @@ exports.getIsServer = getIsServer;
111
111
  function getExpoRouterAbsoluteAppRoot(caller) {
112
112
  assertExpoBabelCaller(caller);
113
113
  const rootModuleId = caller?.routerRoot ?? './app';
114
- if (path_1.default.isAbsolute(rootModuleId)) {
114
+ if (node_path_1.default.isAbsolute(rootModuleId)) {
115
115
  return rootModuleId;
116
116
  }
117
117
  const projectRoot = getPossibleProjectRoot(caller) || '/';
118
- return path_1.default.join(projectRoot, rootModuleId);
118
+ return node_path_1.default.join(projectRoot, rootModuleId);
119
119
  }
120
120
  exports.getExpoRouterAbsoluteAppRoot = getExpoRouterAbsoluteAppRoot;
121
121
  function getInlineEnvVarsEnabled(caller) {
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  import * as t from '@babel/types';
9
- declare const plugin: ({ types }: {
9
+ declare const plugin: (_: {
10
10
  types: typeof t;
11
11
  }) => babel.PluginObj;
12
12
  export default plugin;
@@ -69,7 +69,7 @@ const unaryExpressionComparator = (nodePath, value) => {
69
69
  };
70
70
  const isLeftHandSideOfAssignmentExpression = (node, parent) => t.isAssignmentExpression(parent) && parent.left === node;
71
71
  const TYPEOF_PREFIX = 'typeof ';
72
- const plugin = ({ types }) => {
72
+ const plugin = (_) => {
73
73
  const processNode = (replacements, nodePath, comparator) => {
74
74
  const replacementKey = Object.keys(replacements).find((value) => comparator(nodePath, value));
75
75
  if (typeof replacementKey === 'string' &&
@@ -8,14 +8,14 @@ exports.expoRouterBabelPlugin = void 0;
8
8
  * Copyright © 2024 650 Industries.
9
9
  */
10
10
  const core_1 = require("@babel/core");
11
- const path_1 = __importDefault(require("path"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
12
  const resolve_from_1 = __importDefault(require("resolve-from"));
13
13
  const common_1 = require("./common");
14
14
  const debug = require('debug')('expo:babel:router');
15
15
  function getExpoRouterAppRoot(projectRoot, appFolder) {
16
16
  // TODO: We should have cache invalidation if the expo-router/entry file location changes.
17
17
  const routerEntry = (0, resolve_from_1.default)(projectRoot, 'expo-router/entry');
18
- const appRoot = path_1.default.relative(path_1.default.dirname(routerEntry), appFolder);
18
+ const appRoot = node_path_1.default.relative(node_path_1.default.dirname(routerEntry), appFolder);
19
19
  debug('routerEntry', routerEntry, appFolder, appRoot);
20
20
  return appRoot;
21
21
  }
package/build/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { ConfigAPI, TransformOptions } from '@babel/core';
2
2
  type BabelPresetExpoPlatformOptions = {
3
+ /** Disable or configure the `@babel/plugin-proposal-decorators` plugin. */
4
+ decorators?: false | {
5
+ legacy?: boolean;
6
+ version?: number;
7
+ };
3
8
  /** Enable or disable adding the Reanimated plugin by default. @default `true` */
4
9
  reanimated?: boolean;
5
10
  /** @deprecated Set `jsxRuntime: 'classic'` to disable automatic JSX handling. */
package/build/index.js CHANGED
@@ -247,7 +247,10 @@ function babelPresetExpo(api, options = {}) {
247
247
  plugins: [
248
248
  ...extraPlugins,
249
249
  // TODO: Remove
250
- [require('@babel/plugin-proposal-decorators'), { legacy: true }],
250
+ platformOptions.decorators !== false && [
251
+ require('@babel/plugin-proposal-decorators'),
252
+ platformOptions.decorators ?? { legacy: true },
253
+ ],
251
254
  require('@babel/plugin-transform-export-namespace-from'),
252
255
  // Automatically add `react-native-reanimated/plugin` when the package is installed.
253
256
  // TODO: Move to be a customTransformOption.
@@ -31,9 +31,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
31
31
  __setModuleDefault(result, mod);
32
32
  return result;
33
33
  };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
34
  Object.defineProperty(exports, "__esModule", { value: true });
38
35
  exports.reactServerActionsPlugin = void 0;
39
36
  const core_1 = require("@babel/core");
@@ -41,8 +38,7 @@ const core_1 = require("@babel/core");
41
38
  const helper_module_imports_1 = require("@babel/helper-module-imports");
42
39
  const t = __importStar(require("@babel/types"));
43
40
  const node_path_1 = require("node:path");
44
- const node_url_1 = require("node:url");
45
- const url_1 = __importDefault(require("url"));
41
+ const node_url_1 = __importStar(require("node:url"));
46
42
  const common_1 = require("./common");
47
43
  const debug = require('debug')('expo:babel:server-actions');
48
44
  const LAZY_WRAPPER_VALUE_KEY = 'value';
@@ -499,7 +495,7 @@ function reactServerActionsPlugin(api) {
499
495
  // This can happen in tests or systems that use Babel standalone.
500
496
  throw new Error('[Babel] Expected a filename to be set in the state');
501
497
  }
502
- const outputKey = url_1.default.pathToFileURL(filePath).href;
498
+ const outputKey = node_url_1.default.pathToFileURL(filePath).href;
503
499
  file.metadata.reactServerActions = payload;
504
500
  file.metadata.reactServerReference = outputKey;
505
501
  },
@@ -8,9 +8,9 @@ exports.expoUseDomDirectivePlugin = void 0;
8
8
  * Copyright © 2024 650 Industries.
9
9
  */
10
10
  const core_1 = require("@babel/core");
11
- const crypto_1 = __importDefault(require("crypto"));
12
- const path_1 = require("path");
13
- const url_1 = __importDefault(require("url"));
11
+ const node_crypto_1 = __importDefault(require("node:crypto"));
12
+ const node_path_1 = require("node:path");
13
+ const node_url_1 = __importDefault(require("node:url"));
14
14
  const common_1 = require("./common");
15
15
  function expoUseDomDirectivePlugin(api) {
16
16
  const { types: t } = api;
@@ -64,7 +64,7 @@ function expoUseDomDirectivePlugin(api) {
64
64
  throw path.buildCodeFrameError('The "use dom" directive requires a default export to be present in the file.');
65
65
  }
66
66
  // Assert that _layout routes cannot be used in DOM components.
67
- const fileBasename = (0, path_1.basename)(filePath);
67
+ const fileBasename = (0, node_path_1.basename)(filePath);
68
68
  if (projectRoot &&
69
69
  // Detecting if the file is in the router root would be extensive as it would cause a more complex
70
70
  // cache key for each file. Instead, let's just check if the file is in the project root and is not a node_module,
@@ -80,7 +80,7 @@ function expoUseDomDirectivePlugin(api) {
80
80
  throw path.buildCodeFrameError('API routes cannot be marked as DOM components.');
81
81
  }
82
82
  }
83
- const outputKey = url_1.default.pathToFileURL(filePath).href;
83
+ const outputKey = node_url_1.default.pathToFileURL(filePath).href;
84
84
  // Removes all imports using babel API, that will disconnect import bindings from the program.
85
85
  // plugin-transform-typescript TSX uses the bindings to remove type imports.
86
86
  // If the DOM component has `import React from 'react';`,
@@ -98,7 +98,7 @@ function expoUseDomDirectivePlugin(api) {
98
98
  import React from 'react';
99
99
  import { WebView } from 'expo/dom/internal';
100
100
  ${isProduction
101
- ? `const filePath = "${crypto_1.default.createHash('sha1').update(outputKey).digest('hex')}.html";`
101
+ ? `const filePath = "${node_crypto_1.default.createHash('sha1').update(outputKey).digest('hex')}.html";`
102
102
  : `const filePath = "${fileBasename}?file=" + ${JSON.stringify(outputKey)};`}
103
103
  const _Expo_DOMProxyComponent = React.forwardRef((props, ref) => {
104
104
  return React.createElement(WebView, { ref, ...props, filePath });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-expo",
3
- "version": "12.1.0-canary-20250131-5c4e588",
3
+ "version": "12.1.0-canary-20250207-8bc5146",
4
4
  "description": "The Babel preset for Expo projects",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -41,16 +41,27 @@
41
41
  "extends": "universe/node"
42
42
  },
43
43
  "dependencies": {
44
+ "@babel/helper-module-imports": "^7.25.9",
44
45
  "@babel/plugin-proposal-decorators": "^7.12.9",
46
+ "@babel/plugin-syntax-export-default-from": "^7.24.7",
47
+ "@babel/plugin-proposal-export-default-from": "^7.24.7",
45
48
  "@babel/plugin-transform-export-namespace-from": "^7.22.11",
46
- "@babel/plugin-transform-object-rest-spread": "^7.12.13",
47
- "@babel/plugin-transform-parameters": "^7.22.15",
49
+ "@babel/plugin-transform-flow-strip-types": "^7.25.2",
50
+ "@babel/plugin-transform-private-methods": "^7.24.7",
51
+ "@babel/plugin-transform-private-property-in-object": "^7.24.7",
52
+ "@babel/plugin-transform-runtime": "^7.24.7",
53
+ "@babel/plugin-transform-modules-commonjs": "^7.24.8",
54
+ "@babel/plugin-transform-object-rest-spread": "^7.24.7",
55
+ "@babel/plugin-transform-parameters": "^7.24.7",
48
56
  "@babel/preset-react": "^7.22.15",
49
57
  "@babel/preset-typescript": "^7.23.0",
50
58
  "@react-native/babel-preset": "0.76.3",
51
59
  "babel-plugin-react-native-web": "~0.19.13",
52
- "babel-plugin-syntax-hermes-parser": "0.25.1",
53
- "react-refresh": "^0.14.2"
60
+ "babel-plugin-transform-flow-enums": "^0.0.2",
61
+ "babel-plugin-syntax-hermes-parser": "^0.25.1",
62
+ "debug": "^4.3.4",
63
+ "react-refresh": "^0.14.2",
64
+ "resolve-from": "^5.0.0"
54
65
  },
55
66
  "peerDependencies": {
56
67
  "babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017",
@@ -66,9 +77,12 @@
66
77
  },
67
78
  "devDependencies": {
68
79
  "@babel/core": "^7.20.0",
80
+ "@babel/traverse": "^7.9.0",
81
+ "@babel/types": "^7.9.0",
69
82
  "babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017",
70
- "expo-module-scripts": "4.0.4-canary-20250131-5c4e588",
83
+ "expo-module-scripts": "4.0.4-canary-20250207-8bc5146",
71
84
  "jest": "^29.2.1",
72
85
  "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
73
- }
86
+ },
87
+ "gitHead": "8bc5146852ccd7033138bac9ef8d3c41ae85a211"
74
88
  }