babel-preset-expo 13.1.7 → 13.1.9
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 +1 -1
- package/build/client-module-proxy-plugin.js +10 -3
- package/build/common.d.ts +5 -0
- package/build/common.js +13 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +8 -1
- package/build/server-actions-plugin.js +5 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -150,7 +150,7 @@ Changes the engine preset in `@react-native/babel-preset` based on the JavaScrip
|
|
|
150
150
|
|
|
151
151
|
### `unstable_transformImportMeta`
|
|
152
152
|
|
|
153
|
-
Enable that transform that converts `import.meta` to `globalThis.__ExpoImportMetaRegistry`, defaults to `false
|
|
153
|
+
Enable that transform that converts `import.meta` to `globalThis.__ExpoImportMetaRegistry`, defaults to `false` in client bundles and `true` for server bundles.
|
|
154
154
|
|
|
155
155
|
> **Note:** Use this option at your own risk. If the JavaScript engine supports `import.meta` natively, this transformation may interfere with the native implementation.
|
|
156
156
|
|
|
@@ -8,10 +8,12 @@ exports.reactClientReferencesPlugin = reactClientReferencesPlugin;
|
|
|
8
8
|
* Copyright © 2024 650 Industries.
|
|
9
9
|
*/
|
|
10
10
|
const core_1 = require("@babel/core");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
11
12
|
const node_url_1 = __importDefault(require("node:url"));
|
|
12
13
|
const common_1 = require("./common");
|
|
13
14
|
function reactClientReferencesPlugin(api) {
|
|
14
15
|
const isReactServer = api.caller(common_1.getIsReactServer);
|
|
16
|
+
const possibleProjectRoot = api.caller(common_1.getPossibleProjectRoot);
|
|
15
17
|
return {
|
|
16
18
|
name: 'expo-client-references',
|
|
17
19
|
visitor: {
|
|
@@ -32,7 +34,12 @@ function reactClientReferencesPlugin(api) {
|
|
|
32
34
|
// This can happen in tests or systems that use Babel standalone.
|
|
33
35
|
throw new Error('[Babel] Expected a filename to be set in the state');
|
|
34
36
|
}
|
|
35
|
-
const
|
|
37
|
+
const projectRoot = possibleProjectRoot || state.file.opts.root || '';
|
|
38
|
+
// TODO: Replace with opaque paths in production.
|
|
39
|
+
const outputKey = './' + (0, common_1.toPosixPath)((0, node_path_1.relative)(projectRoot, filePath));
|
|
40
|
+
// const outputKey = isProd
|
|
41
|
+
// ? './' + getRelativePath(projectRoot, filePath)
|
|
42
|
+
// : url.pathToFileURL(filePath).href;
|
|
36
43
|
function iterateExports(callback, type) {
|
|
37
44
|
const exportNames = new Set();
|
|
38
45
|
// Collect all of the exports
|
|
@@ -157,7 +164,7 @@ function reactClientReferencesPlugin(api) {
|
|
|
157
164
|
// Store the proxy export names for testing purposes.
|
|
158
165
|
state.file.metadata.proxyExports = [...proxyExports];
|
|
159
166
|
// Save the server action reference in the metadata.
|
|
160
|
-
state.file.metadata.reactServerReference =
|
|
167
|
+
state.file.metadata.reactServerReference = node_url_1.default.pathToFileURL(filePath).href;
|
|
161
168
|
}
|
|
162
169
|
else if (isUseClient) {
|
|
163
170
|
if (!isReactServer) {
|
|
@@ -208,7 +215,7 @@ function reactClientReferencesPlugin(api) {
|
|
|
208
215
|
// Store the proxy export names for testing purposes.
|
|
209
216
|
state.file.metadata.proxyExports = [...proxyExports];
|
|
210
217
|
// Save the client reference in the metadata.
|
|
211
|
-
state.file.metadata.reactClientReference =
|
|
218
|
+
state.file.metadata.reactClientReference = node_url_1.default.pathToFileURL(filePath).href;
|
|
212
219
|
}
|
|
213
220
|
},
|
|
214
221
|
},
|
package/build/common.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ export declare function getIsNodeModule(caller?: any): boolean;
|
|
|
14
14
|
export declare function getBaseUrl(caller?: any): string;
|
|
15
15
|
export declare function getReactCompiler(caller?: any): boolean;
|
|
16
16
|
export declare function getIsServer(caller?: any): boolean;
|
|
17
|
+
export declare function getMetroSourceType(caller?: any): "script" | "module" | "asset" | undefined;
|
|
17
18
|
export declare function getExpoRouterAbsoluteAppRoot(caller?: any): string;
|
|
18
19
|
export declare function getInlineEnvVarsEnabled(caller?: any): boolean;
|
|
19
20
|
export declare function getAsyncRoutes(caller?: any): boolean;
|
|
20
21
|
export declare function createAddNamedImportOnce(t: typeof import('@babel/types')): (path: NodePath<t.Node>, name: string, source: string) => any;
|
|
22
|
+
/**
|
|
23
|
+
* Convert any platform-specific path to a POSIX path.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toPosixPath(filePath: string): string;
|
package/build/common.js
CHANGED
|
@@ -15,10 +15,12 @@ exports.getIsNodeModule = getIsNodeModule;
|
|
|
15
15
|
exports.getBaseUrl = getBaseUrl;
|
|
16
16
|
exports.getReactCompiler = getReactCompiler;
|
|
17
17
|
exports.getIsServer = getIsServer;
|
|
18
|
+
exports.getMetroSourceType = getMetroSourceType;
|
|
18
19
|
exports.getExpoRouterAbsoluteAppRoot = getExpoRouterAbsoluteAppRoot;
|
|
19
20
|
exports.getInlineEnvVarsEnabled = getInlineEnvVarsEnabled;
|
|
20
21
|
exports.getAsyncRoutes = getAsyncRoutes;
|
|
21
22
|
exports.createAddNamedImportOnce = createAddNamedImportOnce;
|
|
23
|
+
exports.toPosixPath = toPosixPath;
|
|
22
24
|
// @ts-expect-error: missing types
|
|
23
25
|
const helper_module_imports_1 = require("@babel/helper-module-imports");
|
|
24
26
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -113,6 +115,10 @@ function getIsServer(caller) {
|
|
|
113
115
|
assertExpoBabelCaller(caller);
|
|
114
116
|
return caller?.isServer ?? false;
|
|
115
117
|
}
|
|
118
|
+
function getMetroSourceType(caller) {
|
|
119
|
+
assertExpoBabelCaller(caller);
|
|
120
|
+
return caller?.metroSourceType;
|
|
121
|
+
}
|
|
116
122
|
function getExpoRouterAbsoluteAppRoot(caller) {
|
|
117
123
|
assertExpoBabelCaller(caller);
|
|
118
124
|
const rootModuleId = caller?.routerRoot ?? './app';
|
|
@@ -164,3 +170,10 @@ function createAddNamedImportOnce(t) {
|
|
|
164
170
|
return didCreate ? identifier : t.cloneNode(identifier);
|
|
165
171
|
};
|
|
166
172
|
}
|
|
173
|
+
const REGEXP_REPLACE_SLASHES = /\\/g;
|
|
174
|
+
/**
|
|
175
|
+
* Convert any platform-specific path to a POSIX path.
|
|
176
|
+
*/
|
|
177
|
+
function toPosixPath(filePath) {
|
|
178
|
+
return filePath.replace(REGEXP_REPLACE_SLASHES, '/');
|
|
179
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ type BabelPresetExpoPlatformOptions = {
|
|
|
72
72
|
*
|
|
73
73
|
* > **Note:** Use this option at your own risk. If the JavaScript engine supports `import.meta` natively, this transformation may interfere with the native implementation.
|
|
74
74
|
*
|
|
75
|
-
* @default `false`
|
|
75
|
+
* @default `false` on client and `true` on server.
|
|
76
76
|
*/
|
|
77
77
|
unstable_transformImportMeta?: boolean;
|
|
78
78
|
};
|
package/build/index.js
CHANGED
|
@@ -29,6 +29,7 @@ function babelPresetExpo(api, options = {}) {
|
|
|
29
29
|
const isReactServer = api.caller(common_1.getIsReactServer);
|
|
30
30
|
const isFastRefreshEnabled = api.caller(common_1.getIsFastRefreshEnabled);
|
|
31
31
|
const isReactCompilerEnabled = api.caller(common_1.getReactCompiler);
|
|
32
|
+
const metroSourceType = api.caller(common_1.getMetroSourceType);
|
|
32
33
|
const baseUrl = api.caller(common_1.getBaseUrl);
|
|
33
34
|
const supportsStaticESM = api.caller((caller) => caller?.supportsStaticESM);
|
|
34
35
|
const isServerEnv = isServer || isReactServer;
|
|
@@ -44,6 +45,11 @@ function babelPresetExpo(api, options = {}) {
|
|
|
44
45
|
// Use the simpler babel preset for web and server environments (both web and native SSR).
|
|
45
46
|
const isModernEngine = platform === 'web' || isServerEnv;
|
|
46
47
|
const platformOptions = getOptions(options, platform);
|
|
48
|
+
// If the input is a script, we're unable to add any dependencies. Since the @babel/runtime transformer
|
|
49
|
+
// adds extra dependencies (requires/imports) we need to disable it
|
|
50
|
+
if (metroSourceType === 'script') {
|
|
51
|
+
platformOptions.enableBabelRuntime = false;
|
|
52
|
+
}
|
|
47
53
|
if (platformOptions.useTransformReactJSXExperimental != null) {
|
|
48
54
|
throw new Error(`babel-preset-expo: The option 'useTransformReactJSXExperimental' has been removed in favor of { jsxRuntime: 'classic' }.`);
|
|
49
55
|
}
|
|
@@ -181,7 +187,8 @@ function babelPresetExpo(api, options = {}) {
|
|
|
181
187
|
if (platformOptions.disableImportExportTransform) {
|
|
182
188
|
extraPlugins.push([require('./detect-dynamic-exports').detectDynamicExports]);
|
|
183
189
|
}
|
|
184
|
-
|
|
190
|
+
const polyfillImportMeta = platformOptions.unstable_transformImportMeta ?? isServerEnv;
|
|
191
|
+
extraPlugins.push((0, import_meta_transform_plugin_1.expoImportMetaTransformPluginFactory)(polyfillImportMeta === true));
|
|
185
192
|
return {
|
|
186
193
|
presets: [
|
|
187
194
|
(() => {
|
|
@@ -41,12 +41,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
41
41
|
return result;
|
|
42
42
|
};
|
|
43
43
|
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
44
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
48
|
exports.reactServerActionsPlugin = reactServerActionsPlugin;
|
|
46
49
|
const core_1 = require("@babel/core");
|
|
47
50
|
const t = __importStar(require("@babel/types"));
|
|
48
51
|
const node_path_1 = require("node:path");
|
|
49
|
-
const node_url_1 =
|
|
52
|
+
const node_url_1 = __importDefault(require("node:url"));
|
|
50
53
|
const common_1 = require("./common");
|
|
51
54
|
const debug = require('debug')('expo:babel:server-actions');
|
|
52
55
|
const LAZY_WRAPPER_VALUE_KEY = 'value';
|
|
@@ -193,7 +196,7 @@ function reactServerActionsPlugin(api) {
|
|
|
193
196
|
};
|
|
194
197
|
getActionModuleId = once(() => {
|
|
195
198
|
// Create relative file path hash.
|
|
196
|
-
return (0,
|
|
199
|
+
return './' + (0, common_1.toPosixPath)((0, node_path_1.relative)(projectRoot, file.opts.filename));
|
|
197
200
|
});
|
|
198
201
|
const defineBoundArgsWrapperHelper = once(() => {
|
|
199
202
|
const id = this.file.path.scope.generateUidIdentifier('wrapBoundArgs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "13.1.
|
|
3
|
+
"version": "13.1.9",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"expo-module-scripts": "^4.1.5",
|
|
80
80
|
"jest": "^29.2.1"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "bb2cf89d99a9d7f70b07419cc36cdf80c2764217"
|
|
83
83
|
}
|