expo-router 0.0.41 → 0.0.42

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/babel.js CHANGED
@@ -1,8 +1,21 @@
1
1
  const nodePath = require("path");
2
2
  const resolveFrom = require("resolve-from");
3
+ const { getExpoConstantsManifest } = require("./node/getExpoConstantsManifest");
3
4
 
4
5
  const debug = require("debug")("expo:router:babel");
5
6
 
7
+ function getExpoAppManifest(projectRoot) {
8
+ if (process.env.APP_MANIFEST) {
9
+ return process.env.APP_MANIFEST;
10
+ }
11
+
12
+ const exp = getExpoConstantsManifest(projectRoot);
13
+
14
+ debug("public manifest", exp);
15
+
16
+ return JSON.stringify(exp);
17
+ }
18
+
6
19
  function getExpoRouterAppRoot(projectRoot) {
7
20
  if (process.env.EXPO_ROUTER_APP_ROOT) {
8
21
  return process.env.EXPO_ROUTER_APP_ROOT;
@@ -35,7 +48,17 @@ module.exports = function (api) {
35
48
  // Add support for Node.js __filename
36
49
  Identifier(path, state) {
37
50
  if (path.node.name === "__filename") {
38
- path.replaceWith(t.stringLiteral(getRelPath(state)));
51
+ path.replaceWith(
52
+ t.stringLiteral(
53
+ // `/index.js` is the value used by Webpack.
54
+ getRelPath(state)
55
+ )
56
+ );
57
+ }
58
+ // Add support for Node.js `__dirname`.
59
+ // This static value comes from Webpack somewhere.
60
+ if (path.node.name === "__dirname") {
61
+ path.replaceWith(t.stringLiteral("/"));
39
62
  }
40
63
  },
41
64
 
@@ -53,6 +76,9 @@ module.exports = function (api) {
53
76
  return;
54
77
  }
55
78
 
79
+ const projectRoot =
80
+ process.env.EXPO_PROJECT_ROOT || state.file.opts.root || "";
81
+
56
82
  // Used for log box and stuff
57
83
  if (
58
84
  t.isIdentifier(parent.node.property, {
@@ -60,11 +86,20 @@ module.exports = function (api) {
60
86
  }) &&
61
87
  !parent.parentPath.isAssignmentExpression()
62
88
  ) {
63
- parent.replaceWith(
64
- t.stringLiteral(
65
- process.env.EXPO_PROJECT_ROOT || state.file.opts.root || ""
66
- )
67
- );
89
+ parent.replaceWith(t.stringLiteral(projectRoot));
90
+ return;
91
+ }
92
+
93
+ // Surfaces the `app.json` (config) as an environment variable which is then parsed by
94
+ // `expo-constants` https://docs.expo.dev/versions/latest/sdk/constants/
95
+ if (
96
+ t.isIdentifier(parent.node.property, {
97
+ name: "APP_MANIFEST",
98
+ }) &&
99
+ !parent.parentPath.isAssignmentExpression()
100
+ ) {
101
+ const manifest = getExpoAppManifest(projectRoot);
102
+ parent.replaceWith(t.stringLiteral(manifest));
68
103
  return;
69
104
  }
70
105
 
@@ -82,7 +117,7 @@ module.exports = function (api) {
82
117
 
83
118
  parent.replaceWith(
84
119
  // 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))
120
+ t.stringLiteral(getExpoRouterAppRoot(projectRoot))
86
121
  );
87
122
  },
88
123
  },
@@ -0,0 +1,179 @@
1
+ const { getConfig, getNameFromConfig } = require("expo/config");
2
+ // Use root to work better with create-react-app
3
+ const DEFAULT_LANGUAGE_ISO_CODE = `en`;
4
+ const DEFAULT_DISPLAY = "standalone";
5
+ const DEFAULT_STATUS_BAR = "black-translucent";
6
+ const DEFAULT_PREFER_RELATED_APPLICATIONS = true;
7
+ // Convert expo value to PWA value
8
+ function ensurePWAorientation(orientation) {
9
+ if (orientation && typeof orientation === "string") {
10
+ const webOrientation = orientation.toLowerCase();
11
+ if (webOrientation !== "default") {
12
+ return webOrientation;
13
+ }
14
+ }
15
+ return undefined;
16
+ }
17
+
18
+ const RESTRICTED_MANIFEST_FIELDS = [
19
+ // Omit app.json properties that get removed during the native build
20
+ "facebookScheme",
21
+ "facebookAppId",
22
+ "facebookDisplayName",
23
+ // Remove iOS and Android.
24
+ "ios",
25
+ "android",
26
+ // Hide internal / build values
27
+ "plugins",
28
+ "hooks",
29
+ "_internal",
30
+ // Remove metro-specific values
31
+ "assetBundlePatterns",
32
+ ];
33
+ function getExpoConstantsManifest(projectRoot) {
34
+ const { exp } = getConfig(projectRoot, {
35
+ isPublicConfig: true,
36
+ skipSDKVersionRequirement: true,
37
+ });
38
+ const manifest = ensurePWAConfig(exp);
39
+ for (const field of RESTRICTED_MANIFEST_FIELDS) {
40
+ delete manifest[field];
41
+ }
42
+ return manifest;
43
+ }
44
+ function applyWebDefaults(appJSON) {
45
+ // For RN CLI support
46
+ // @ts-ignore: expo object doesn't exist on ExpoConfig
47
+ const appManifest = appJSON.expo || appJSON || {};
48
+ const {
49
+ web: webManifest = {},
50
+ splash = {},
51
+ ios = {},
52
+ android = {},
53
+ } = appManifest;
54
+ // rn-cli apps use a displayName value as well.
55
+ const { appName, webName } = getNameFromConfig(appJSON);
56
+ const languageISOCode = webManifest.lang || DEFAULT_LANGUAGE_ISO_CODE;
57
+ const primaryColor = appManifest.primaryColor;
58
+ const description = appManifest.description;
59
+ // The theme_color sets the color of the tool bar, and may be reflected in the app's preview in task switchers.
60
+ const webThemeColor = webManifest.themeColor || primaryColor;
61
+ const dir = webManifest.dir;
62
+ const shortName = webManifest.shortName || webName;
63
+ const display = webManifest.display || DEFAULT_DISPLAY;
64
+ const startUrl = webManifest.startUrl;
65
+ const { scope, crossorigin } = webManifest;
66
+ const barStyle = webManifest.barStyle || DEFAULT_STATUS_BAR;
67
+ const orientation = ensurePWAorientation(
68
+ webManifest.orientation || appManifest.orientation
69
+ );
70
+ /**
71
+ * **Splash screen background color**
72
+ * `https://developers.google.com/web/fundamentals/web-app-manifest/#splash-screen`
73
+ * The background_color should be the same color as the load page,
74
+ * to provide a smooth transition from the splash screen to your app.
75
+ */
76
+ const backgroundColor = webManifest.backgroundColor || splash.backgroundColor; // No default background color
77
+ /**
78
+ *
79
+ * https://developer.mozilla.org/en-US/docs/Web/Manifest#prefer_related_applications
80
+ * Specifies a boolean value that hints for the user agent to indicate
81
+ * to the user that the specified native applications (see below) are recommended over the website.
82
+ * This should only be used if the related native apps really do offer something that the website can't... like Expo ;)
83
+ *
84
+ * >> The banner won't show up if the app is already installed:
85
+ * https://github.com/GoogleChrome/samples/issues/384#issuecomment-326387680
86
+ */
87
+ const preferRelatedApplications =
88
+ webManifest.preferRelatedApplications === undefined
89
+ ? DEFAULT_PREFER_RELATED_APPLICATIONS
90
+ : webManifest.preferRelatedApplications;
91
+ const relatedApplications =
92
+ inferWebRelatedApplicationsFromConfig(appManifest);
93
+ return {
94
+ ...appManifest,
95
+ name: appName,
96
+ description,
97
+ primaryColor,
98
+ // Ensure these objects exist
99
+ ios: {
100
+ ...ios,
101
+ },
102
+ android: {
103
+ ...android,
104
+ },
105
+ web: {
106
+ ...webManifest,
107
+ meta: undefined,
108
+ build: undefined,
109
+ scope,
110
+ crossorigin,
111
+ description,
112
+ preferRelatedApplications,
113
+ relatedApplications,
114
+ startUrl,
115
+ shortName,
116
+ display,
117
+ orientation,
118
+ dir,
119
+ barStyle,
120
+ backgroundColor,
121
+ themeColor: webThemeColor,
122
+ lang: languageISOCode,
123
+ name: webName,
124
+ },
125
+ };
126
+ }
127
+ /**
128
+ * https://developer.mozilla.org/en-US/docs/Web/Manifest#related_applications
129
+ * An array of native applications that are installable by, or accessible to, the underlying platform
130
+ * for example, a native Android application obtainable through the Google Play Store.
131
+ * Such applications are intended to be alternatives to the
132
+ * website that provides similar/equivalent functionality — like the native app version of the website.
133
+ */
134
+ function inferWebRelatedApplicationsFromConfig({
135
+ web = {},
136
+ ios = {},
137
+ android = {},
138
+ }) {
139
+ const relatedApplications = web.relatedApplications || [];
140
+ const { bundleIdentifier, appStoreUrl } = ios;
141
+ if (bundleIdentifier) {
142
+ const PLATFORM_ITUNES = "itunes";
143
+ const iosApp = relatedApplications.some(
144
+ ({ platform }) => platform === PLATFORM_ITUNES
145
+ );
146
+ if (!iosApp) {
147
+ relatedApplications.push({
148
+ platform: PLATFORM_ITUNES,
149
+ url: appStoreUrl,
150
+ id: bundleIdentifier,
151
+ });
152
+ }
153
+ }
154
+ const { package: androidPackage, playStoreUrl } = android;
155
+ if (androidPackage) {
156
+ const PLATFORM_PLAY = "play";
157
+ const alreadyHasAndroidApp = relatedApplications.some(
158
+ ({ platform }) => platform === PLATFORM_PLAY
159
+ );
160
+ if (!alreadyHasAndroidApp) {
161
+ relatedApplications.push({
162
+ platform: PLATFORM_PLAY,
163
+ url:
164
+ playStoreUrl ||
165
+ `http://play.google.com/store/apps/details?id=${androidPackage}`,
166
+ id: androidPackage,
167
+ });
168
+ }
169
+ }
170
+ return relatedApplications;
171
+ }
172
+ function ensurePWAConfig(appJSON) {
173
+ const config = applyWebDefaults(appJSON);
174
+ return config;
175
+ }
176
+
177
+ module.exports = {
178
+ getExpoConstantsManifest,
179
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "main": "build/index.js",
5
5
  "files": [
6
6
  "entry.js",
@@ -12,7 +12,8 @@
12
12
  "stack.js",
13
13
  "stack.d.ts",
14
14
  "tabs.js",
15
- "tabs.d.ts"
15
+ "tabs.d.ts",
16
+ "node"
16
17
  ],
17
18
  "repository": {
18
19
  "url": "https://github.com/expo/router.git",