babel-preset-expo 12.0.0-preview.0 → 12.0.0-preview.2

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.
@@ -17,6 +17,7 @@ function expoUseDomDirectivePlugin(api) {
17
17
  // TODO: Is exporting
18
18
  const isProduction = api.caller(common_1.getIsProd);
19
19
  const platform = api.caller((caller) => caller?.platform);
20
+ const projectRoot = api.caller(common_1.getPossibleProjectRoot);
20
21
  return {
21
22
  name: 'expo-use-dom-directive',
22
23
  visitor: {
@@ -59,6 +60,23 @@ function expoUseDomDirectivePlugin(api) {
59
60
  if (!hasDefaultExport) {
60
61
  throw path.buildCodeFrameError('The "use dom" directive requires a default export to be present in the file.');
61
62
  }
63
+ // Assert that _layout routes cannot be used in DOM components.
64
+ const fileBasename = (0, path_1.basename)(filePath);
65
+ if (projectRoot &&
66
+ // Detecting if the file is in the router root would be extensive as it would cause a more complex
67
+ // cache key for each file. Instead, let's just check if the file is in the project root and is not a node_module,
68
+ // then we can assert that users should not use `_layout` or `+api` with "use dom".
69
+ filePath.includes(projectRoot) &&
70
+ !filePath.match(/node_modules/)) {
71
+ if (fileBasename.match(/^_layout\.[jt]sx?$/)) {
72
+ throw path.buildCodeFrameError('Layout routes cannot be marked as DOM components because they cannot render native views.');
73
+ }
74
+ else if (
75
+ // No API routes
76
+ fileBasename.match(/\+api\.[jt]sx?$/)) {
77
+ throw path.buildCodeFrameError('API routes cannot be marked as DOM components.');
78
+ }
79
+ }
62
80
  const outputKey = url_1.default.pathToFileURL(filePath).href;
63
81
  const proxyModule = [
64
82
  `import React from 'react';`,
@@ -81,7 +99,7 @@ function expoUseDomDirectivePlugin(api) {
81
99
  else {
82
100
  proxyModule.push(
83
101
  // Add the basename to improve the Safari debug preview option.
84
- `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() };`);
102
+ `const source = { uri: new URL("/_expo/@dom/${fileBasename}?file=" + ${JSON.stringify(outputKey)}, require("react-native/Libraries/Core/Devtools/getDevServer")().url).toString() };`);
85
103
  }
86
104
  proxyModule.push(`
87
105
  export default React.forwardRef((props, ref) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-expo",
3
- "version": "12.0.0-preview.0",
3
+ "version": "12.0.0-preview.2",
4
4
  "description": "The Babel preset for Expo projects",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -47,7 +47,7 @@
47
47
  "@babel/plugin-transform-parameters": "^7.22.15",
48
48
  "@babel/preset-react": "^7.22.15",
49
49
  "@babel/preset-typescript": "^7.23.0",
50
- "@react-native/babel-preset": "0.76.0-rc.6",
50
+ "@react-native/babel-preset": "0.76.1",
51
51
  "babel-plugin-react-native-web": "~0.19.13",
52
52
  "react-refresh": "^0.14.2"
53
53
  },
@@ -70,5 +70,5 @@
70
70
  "jest": "^29.2.1",
71
71
  "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
72
72
  },
73
- "gitHead": "7c7d2362fff23bec26cd145ed34edd9c403551bd"
73
+ "gitHead": "71f25de1d8fe12c0b91242fd6e882ccfb4698e17"
74
74
  }