babel-preset-expo 11.1.0-canary-20240719-83ee47b → 11.1.0-canary-20240814-ce0f7d5
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/build/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const expo_router_plugin_1 = require("./expo-router-plugin");
|
|
|
8
8
|
const inline_env_vars_1 = require("./inline-env-vars");
|
|
9
9
|
const lazyImports_1 = require("./lazyImports");
|
|
10
10
|
const restricted_react_api_plugin_1 = require("./restricted-react-api-plugin");
|
|
11
|
+
const use_dom_directive_plugin_1 = require("./use-dom-directive-plugin");
|
|
11
12
|
function getOptions(options, platform) {
|
|
12
13
|
const tag = platform === 'web' ? 'web' : 'native';
|
|
13
14
|
return {
|
|
@@ -68,6 +69,9 @@ function babelPresetExpo(api, options = {}) {
|
|
|
68
69
|
!isServerEnv &&
|
|
69
70
|
// Give users the ability to opt-out of the feature, per-platform.
|
|
70
71
|
platformOptions['react-compiler'] !== false) {
|
|
72
|
+
if (!(0, common_1.hasModule)('babel-plugin-react-compiler')) {
|
|
73
|
+
throw new Error('The `babel-plugin-react-compiler` must be installed before you can use React Compiler.');
|
|
74
|
+
}
|
|
71
75
|
extraPlugins.push([
|
|
72
76
|
require('babel-plugin-react-compiler'),
|
|
73
77
|
{
|
|
@@ -87,7 +91,11 @@ function babelPresetExpo(api, options = {}) {
|
|
|
87
91
|
// `@react-native/babel-preset` configures this plugin with `{ loose: true }`, which breaks all
|
|
88
92
|
// getters and setters in spread objects. We need to add this plugin ourself without that option.
|
|
89
93
|
// @see https://github.com/expo/expo/pull/11960#issuecomment-887796455
|
|
90
|
-
extraPlugins.push([
|
|
94
|
+
extraPlugins.push([
|
|
95
|
+
require('@babel/plugin-transform-object-rest-spread'),
|
|
96
|
+
// Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
|
|
97
|
+
{ loose: true, useBuiltIns: true },
|
|
98
|
+
]);
|
|
91
99
|
}
|
|
92
100
|
else {
|
|
93
101
|
if (platform !== 'web' && !isServerEnv) {
|
|
@@ -117,6 +125,7 @@ function babelPresetExpo(api, options = {}) {
|
|
|
117
125
|
inlines['process.env.EXPO_BASE_URL'] = baseUrl;
|
|
118
126
|
}
|
|
119
127
|
extraPlugins.push([require('./define-plugin'), inlines]);
|
|
128
|
+
extraPlugins.push(use_dom_directive_plugin_1.expoUseDomDirectivePlugin);
|
|
120
129
|
if (isProduction) {
|
|
121
130
|
// Metro applies a version of this plugin too but it does it after the Platform modules have been transformed to CJS, this breaks the transform.
|
|
122
131
|
// Here, we'll apply it before the commonjs transform, in production only, to ensure `Platform.OS` is replaced with a string literal.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.expoUseDomDirectivePlugin = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright © 2024 650 Industries.
|
|
9
|
+
*/
|
|
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"));
|
|
14
|
+
const common_1 = require("./common");
|
|
15
|
+
function expoUseDomDirectivePlugin(api) {
|
|
16
|
+
// TODO: Is exporting
|
|
17
|
+
const isProduction = api.caller(common_1.getIsProd);
|
|
18
|
+
const platform = api.caller((caller) => caller?.platform);
|
|
19
|
+
return {
|
|
20
|
+
name: 'expo-use-dom-directive',
|
|
21
|
+
visitor: {
|
|
22
|
+
Program(path, state) {
|
|
23
|
+
// Native only feature.
|
|
24
|
+
if (platform === 'web') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const hasUseDomDirective = path.node.directives.some((directive) => directive.value.value === 'use dom');
|
|
28
|
+
const filePath = state.file.opts.filename;
|
|
29
|
+
if (!filePath) {
|
|
30
|
+
// This can happen in tests or systems that use Babel standalone.
|
|
31
|
+
throw new Error('[Babel] Expected a filename to be set in the state');
|
|
32
|
+
}
|
|
33
|
+
// File starts with "use dom" directive.
|
|
34
|
+
if (!hasUseDomDirective) {
|
|
35
|
+
// Do nothing for code that isn't marked as a dom component.
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Assert that a default export must exist and that no other exports should be present.
|
|
39
|
+
// NOTE: In the future we could support other exports with extraction.
|
|
40
|
+
let hasDefaultExport = false;
|
|
41
|
+
// Collect all of the exports
|
|
42
|
+
path.traverse({
|
|
43
|
+
ExportNamedDeclaration(path) {
|
|
44
|
+
throw path.buildCodeFrameError('Modules with the "use dom" directive only support a single default export.');
|
|
45
|
+
},
|
|
46
|
+
ExportDefaultDeclaration() {
|
|
47
|
+
hasDefaultExport = true;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (!hasDefaultExport) {
|
|
51
|
+
throw path.buildCodeFrameError('The "use dom" directive requires a default export to be present in the file.');
|
|
52
|
+
}
|
|
53
|
+
const outputKey = url_1.default.pathToFileURL(filePath).href;
|
|
54
|
+
const proxyModule = [
|
|
55
|
+
`import React from 'react';
|
|
56
|
+
import { WebView } from 'expo/dom/internal';`,
|
|
57
|
+
];
|
|
58
|
+
if (isProduction) {
|
|
59
|
+
// MUST MATCH THE EXPORT COMMAND!
|
|
60
|
+
const hash = crypto_1.default.createHash('sha1').update(outputKey).digest('hex');
|
|
61
|
+
const outputName = `www.bundle/${hash}.html`;
|
|
62
|
+
if (platform === 'ios') {
|
|
63
|
+
proxyModule.push(`const source = { uri: "${outputName}" };`);
|
|
64
|
+
}
|
|
65
|
+
else if (platform === 'android') {
|
|
66
|
+
proxyModule.push(`const source = { uri: "file:///android_asset/${outputName}" };`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error('production "use dom" directive is not supported yet for platform: ' + platform);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
proxyModule.push(
|
|
74
|
+
// Add the basename to improve the Safari debug preview option.
|
|
75
|
+
`const source = { uri: new URL("/_expo/@dom/${(0, path_1.basename)(filePath)}?file=" + ${JSON.stringify(outputKey)}, require("react-native/Libraries/Core/Devtools/getDevServer")().url).toString() };`);
|
|
76
|
+
}
|
|
77
|
+
proxyModule.push(`
|
|
78
|
+
export default React.forwardRef((props, ref) => {
|
|
79
|
+
return React.createElement(WebView, { ref, ...props, source });
|
|
80
|
+
});`);
|
|
81
|
+
// Clear the body
|
|
82
|
+
path.node.body = [];
|
|
83
|
+
path.node.directives = [];
|
|
84
|
+
path.pushContainer('body', core_1.template.ast(proxyModule.join('\n')));
|
|
85
|
+
assertExpoMetadata(state.file.metadata);
|
|
86
|
+
// Save the client reference in the metadata.
|
|
87
|
+
state.file.metadata.expoDomComponentReference = outputKey;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.expoUseDomDirectivePlugin = expoUseDomDirectivePlugin;
|
|
93
|
+
function assertExpoMetadata(metadata) {
|
|
94
|
+
if (metadata && typeof metadata === 'object') {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
throw new Error('Expected Babel state.file.metadata to be an object');
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "11.1.0-canary-
|
|
3
|
+
"version": "11.1.0-canary-20240814-ce0f7d5",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -46,17 +46,25 @@
|
|
|
46
46
|
"@babel/plugin-transform-export-namespace-from": "^7.22.11",
|
|
47
47
|
"@babel/plugin-transform-object-rest-spread": "^7.12.13",
|
|
48
48
|
"@babel/plugin-transform-parameters": "^7.22.15",
|
|
49
|
-
"@babel/preset-typescript": "^7.23.0",
|
|
50
49
|
"@babel/preset-react": "^7.22.15",
|
|
51
|
-
"@
|
|
52
|
-
"babel-
|
|
50
|
+
"@babel/preset-typescript": "^7.23.0",
|
|
51
|
+
"@react-native/babel-preset": "0.75.0-rc.7",
|
|
53
52
|
"babel-plugin-react-native-web": "~0.19.10",
|
|
54
53
|
"react-refresh": "^0.14.2"
|
|
55
54
|
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"babel-plugin-react-compiler": "0.0.0-experimental-334f00b-20240725"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"babel-plugin-react-compiler": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
56
63
|
"devDependencies": {
|
|
57
64
|
"@babel/core": "^7.20.0",
|
|
58
|
-
"
|
|
65
|
+
"babel-plugin-react-compiler": "0.0.0-experimental-334f00b-20240725",
|
|
66
|
+
"expo-module-scripts": "3.6.0-canary-20240814-ce0f7d5",
|
|
59
67
|
"jest": "^29.2.1"
|
|
60
68
|
},
|
|
61
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "ce0f7d5c7eaec2c8d06ee4e0dc0e58cd6c1612ed"
|
|
62
70
|
}
|