expo-router 0.0.18 → 0.0.19

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.
Files changed (2) hide show
  1. package/babel.js +30 -34
  2. package/package.json +1 -1
package/babel.js CHANGED
@@ -1,9 +1,33 @@
1
- const { relative } = require("path");
1
+ const nodePath = require("path");
2
+ const resolveFrom = require("resolve-from");
3
+
4
+ const debug = require("debug")("expo:router:babel");
5
+
6
+ function getExpoRouterAppRoot(projectRoot) {
7
+ if (process.env.EXPO_ROUTER_APP_ROOT) {
8
+ return process.env.EXPO_ROUTER_APP_ROOT;
9
+ }
10
+ const routerEntry = resolveFrom.silent(projectRoot, "expo-router/entry");
11
+
12
+ if (!routerEntry) {
13
+ console.warn(
14
+ `Required environment variable EXPO_ROUTER_APP_ROOT is not defined, bundle with Expo CLI (expo@^46.0.13) to fix.`
15
+ );
16
+ process.env.EXPO_ROUTER_APP_ROOT = "../../app";
17
+ return process.env.EXPO_ROUTER_APP_ROOT;
18
+ }
19
+ // It doesn't matter if the app folder exists.
20
+ const appFolder = nodePath.join(projectRoot, "app");
21
+ const appRoot = nodePath.relative(nodePath.dirname(routerEntry), appFolder);
22
+ debug("routerEntry", routerEntry, appFolder, appRoot);
23
+
24
+ return appRoot;
25
+ }
2
26
 
3
27
  module.exports = function (api) {
4
28
  const { types: t } = api;
5
29
  const getRelPath = (state) =>
6
- "./" + relative(state.file.opts.root, state.filename);
30
+ "./" + nodePath.relative(state.file.opts.root, state.filename);
7
31
 
8
32
  return {
9
33
  name: "expo-router",
@@ -15,35 +39,6 @@ module.exports = function (api) {
15
39
  }
16
40
  },
17
41
 
18
- // Auto add the React prop `context={require.context('./app')}` to a component named `Root` that's
19
- JSXOpeningElement(path, state) {
20
- if (!getRelPath(state).match(/^\.\/app\//)) {
21
- return;
22
- }
23
- if (path.node.name.name === "ExpoRoot") {
24
- // Check if the context prop already exists
25
- const contextProp = path.node.attributes.find(
26
- (attr) => attr.name.name === "context"
27
- );
28
- if (contextProp) {
29
- return;
30
- }
31
-
32
- path.node.attributes.push(
33
- t.jsxAttribute(
34
- t.jsxIdentifier("context"),
35
- t.jsxExpressionContainer(
36
- t.callExpression(t.identifier("require"), [
37
- t.callExpression(t.identifier("context"), [
38
- t.stringLiteral("./app"),
39
- ]),
40
- ])
41
- )
42
- )
43
- );
44
- }
45
- },
46
-
47
42
  // Convert `process.env.EXPO_ROUTER_APP_ROOT` to a string literal
48
43
  MemberExpression(path, state) {
49
44
  if (
@@ -85,9 +80,10 @@ module.exports = function (api) {
85
80
  return;
86
81
  }
87
82
 
88
- if (process.env.EXPO_ROUTER_APP_ROOT != null) {
89
- parent.replaceWith(t.stringLiteral(process.env.EXPO_ROUTER_APP_ROOT));
90
- }
83
+ parent.replaceWith(
84
+ // This is defined in Expo CLI when using Metro. It points to the relative path for the project app directory.
85
+ t.stringLiteral(getExpoRouterAppRoot(state.file.opts.root))
86
+ );
91
87
  },
92
88
  },
93
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "main": "build/index.js",
5
5
  "files": [
6
6
  "entry.js",