@expo/metro-runtime 2.0.1 → 2.0.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.
@@ -28,23 +28,27 @@ function getBaseUrl() {
28
28
  var _a, _b, _c;
29
29
  // TODO: Make it official by moving out of `extra`
30
30
  let productionBaseUrl = (_c = (_b = (_a = expo_constants_1.default.manifest) === null || _a === void 0 ? void 0 : _a.extra) === null || _b === void 0 ? void 0 : _b.router) === null || _c === void 0 ? void 0 : _c.origin;
31
+ if (!productionBaseUrl) {
32
+ return null;
33
+ }
31
34
  if (process.env.NODE_ENV !== "production") {
32
35
  // e.g. http://localhost:19006
33
36
  productionBaseUrl = (0, getDevServer_1.default)().url;
34
37
  }
35
38
  // Ensure no trailing slash
36
- return productionBaseUrl.replace(/\/$/, "");
39
+ return productionBaseUrl === null || productionBaseUrl === void 0 ? void 0 : productionBaseUrl.replace(/\/$/, "");
37
40
  }
38
41
  function wrapFetchWithWindowLocation(fetch) {
39
42
  if (fetch.__EXPO_BASE_URL_POLYFILLED) {
40
43
  return fetch;
41
44
  }
42
45
  const _fetch = (...props) => {
46
+ var _a, _b;
43
47
  if (props[0] && typeof props[0] === "string" && props[0].startsWith("/")) {
44
48
  if (process.env.NODE_ENV !== "production") {
45
49
  warnProductionOriginNotConfigured(props[0]);
46
50
  }
47
- props[0] = new url_parse_1.default(props[0], window.location.origin).toString();
51
+ props[0] = new url_parse_1.default(props[0], (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin).toString();
48
52
  }
49
53
  else if (props[0] && typeof props[0] === "object") {
50
54
  if (props[0].url &&
@@ -53,7 +57,7 @@ function wrapFetchWithWindowLocation(fetch) {
53
57
  if (process.env.NODE_ENV !== "production") {
54
58
  warnProductionOriginNotConfigured(props[0]);
55
59
  }
56
- props[0].url = new url_parse_1.default(props[0].url, window.location.origin).toString();
60
+ props[0].url = new url_parse_1.default(props[0].url, (_b = window.location) === null || _b === void 0 ? void 0 : _b.origin).toString();
57
61
  }
58
62
  }
59
63
  return fetch(...props);
@@ -64,8 +68,11 @@ function wrapFetchWithWindowLocation(fetch) {
64
68
  if (((_c = (_b = (_a = expo_constants_1.default.manifest) === null || _a === void 0 ? void 0 : _a.extra) === null || _b === void 0 ? void 0 : _b.router) === null || _c === void 0 ? void 0 : _c.origin) !== false) {
65
69
  // Polyfill window.location in native runtimes.
66
70
  if (typeof window !== "undefined" && !window.location) {
67
- (0, Location_1.setLocationHref)(getBaseUrl());
68
- (0, Location_1.install)();
71
+ const url = getBaseUrl();
72
+ if (url) {
73
+ (0, Location_1.setLocationHref)(url);
74
+ (0, Location_1.install)();
75
+ }
69
76
  }
70
77
  // Polyfill native fetch to support relative URLs
71
78
  Object.defineProperty(global, "fetch", {
@@ -1 +1 @@
1
- {"version":3,"file":"install.native.js","sourceRoot":"","sources":["../../src/location/install.native.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAuC;AACvC,0DAA4B;AAE5B,yCAAsD;AACtD,mEAA2C;AAE3C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,mEAAmE;AACnE,uEAAuE;AACvE,2EAA2E;AAC3E,SAAS,iCAAiC,CAAC,UAAkB;;IAC3D,IAAI,SAAS,EAAE;QACb,OAAO;KACR;IACD,SAAS,GAAG,IAAI,CAAC;IACjB,IAAI,CAAC,CAAA,MAAA,MAAA,MAAA,wBAAS,CAAC,QAAQ,0CAAE,KAAK,0CAAE,MAAM,0CAAE,MAAM,CAAA,EAAE;QAC9C,OAAO,CAAC,IAAI,CACV,+BAA+B,UAAU,oNAAoN,CAC9P,CAAC;KACH;AACH,CAAC;AAED,sGAAsG;AACtG,+DAA+D;AAC/D,SAAS,UAAU;;IACjB,kDAAkD;IAClD,IAAI,iBAAiB,GAAG,MAAA,MAAA,MAAA,wBAAS,CAAC,QAAQ,0CAAE,KAAK,0CAAE,MAAM,0CAAE,MAAM,CAAC;IAElE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,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AAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;aACzE;SACF;QACD,OAAO,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC;IAEF,MAAM,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAEzC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAI,CAAA,MAAA,MAAA,MAAA,wBAAS,CAAC,QAAQ,0CAAE,KAAK,0CAAE,MAAM,0CAAE,MAAM,MAAK,KAAK,EAAE;IACvD,+CAA+C;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrD,IAAA,0BAAe,EAAC,UAAU,EAAE,CAAC,CAAC;QAC9B,IAAA,kBAAO,GAAE,CAAC;KACX;IAED,iDAAiD;IACjD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE;QACrC,KAAK,EAAE,2BAA2B,CAAC,KAAK,CAAC;KAC1C,CAAC,CAAC;CACJ","sourcesContent":["import Constants from \"expo-constants\";\nimport URL from \"url-parse\";\n\nimport { install, setLocationHref } from \"./Location\";\nimport getDevServer from \"../getDevServer\";\n\nlet hasWarned = false;\n\n// Add a development warning for fetch requests with relative paths\n// to ensure developers are aware of the need to configure a production\n// base URL in the Expo config (app.json) under `expo.extra.router.origin`.\nfunction warnProductionOriginNotConfigured(requestUrl: string) {\n if (hasWarned) {\n return;\n }\n hasWarned = true;\n if (!Constants.manifest?.extra?.router?.origin) {\n console.warn(\n `The relative fetch request \"${requestUrl}\" will not work in production until the Expo config (app.json) \\`expo.extra.router.origin\\` field is set to the base URL of your web server. [Learn more](https://expo.github.io/router/docs/lab/runtime-location)`\n );\n }\n}\n\n// TODO: This would be better if native and tied as close to the JS engine as possible, i.e. it should\n// reflect the exact location of the JS file that was executed.\nfunction getBaseUrl() {\n // TODO: Make it official by moving out of `extra`\n let productionBaseUrl = Constants.manifest?.extra?.router?.origin;\n\n if (process.env.NODE_ENV !== \"production\") {\n // e.g. http://localhost:19006\n productionBaseUrl = getDevServer().url;\n }\n\n // Ensure no trailing slash\n return productionBaseUrl.replace(/\\/$/, \"\");\n}\n\nfunction wrapFetchWithWindowLocation(\n fetch: Function & { __EXPO_BASE_URL_POLYFILLED?: boolean }\n) {\n if (fetch.__EXPO_BASE_URL_POLYFILLED) {\n return fetch;\n }\n\n const _fetch = (...props: any[]) => {\n if (props[0] && typeof props[0] === \"string\" && props[0].startsWith(\"/\")) {\n if (process.env.NODE_ENV !== \"production\") {\n warnProductionOriginNotConfigured(props[0]);\n }\n\n props[0] = new URL(props[0], window.location.origin).toString();\n } else if (props[0] && typeof props[0] === \"object\") {\n if (\n props[0].url &&\n typeof props[0].url === \"string\" &&\n props[0].url.startsWith(\"/\")\n ) {\n if (process.env.NODE_ENV !== \"production\") {\n warnProductionOriginNotConfigured(props[0]);\n }\n\n props[0].url = new URL(props[0].url, window.location.origin).toString();\n }\n }\n return fetch(...props);\n };\n\n _fetch.__EXPO_BASE_URL_POLYFILLED = true;\n\n return _fetch;\n}\n\nif (Constants.manifest?.extra?.router?.origin !== false) {\n // Polyfill window.location in native runtimes.\n if (typeof window !== \"undefined\" && !window.location) {\n setLocationHref(getBaseUrl());\n install();\n }\n\n // Polyfill native fetch to support relative URLs\n Object.defineProperty(global, \"fetch\", {\n value: wrapFetchWithWindowLocation(fetch),\n });\n}\n"]}
1
+ {"version":3,"file":"install.native.js","sourceRoot":"","sources":["../../src/location/install.native.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAuC;AACvC,0DAA4B;AAE5B,yCAAsD;AACtD,mEAA2C;AAE3C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,mEAAmE;AACnE,uEAAuE;AACvE,2EAA2E;AAC3E,SAAS,iCAAiC,CAAC,UAAkB;;IAC3D,IAAI,SAAS,EAAE;QACb,OAAO;KACR;IACD,S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E,OAAO,EAAE;QACrC,KAAK,EAAE,2BAA2B,CAAC,KAAK,CAAC;KAC1C,CAAC,CAAC;CACJ","sourcesContent":["import Constants from \"expo-constants\";\nimport URL from \"url-parse\";\n\nimport { install, setLocationHref } from \"./Location\";\nimport getDevServer from \"../getDevServer\";\n\nlet hasWarned = false;\n\n// Add a development warning for fetch requests with relative paths\n// to ensure developers are aware of the need to configure a production\n// base URL in the Expo config (app.json) under `expo.extra.router.origin`.\nfunction warnProductionOriginNotConfigured(requestUrl: string) {\n if (hasWarned) {\n return;\n }\n hasWarned = true;\n if (!Constants.manifest?.extra?.router?.origin) {\n console.warn(\n `The relative fetch request \"${requestUrl}\" will not work in production until the Expo config (app.json) \\`expo.extra.router.origin\\` field is set to the base URL of your web server. [Learn more](https://expo.github.io/router/docs/lab/runtime-location)`\n );\n }\n}\n\n// TODO: This would be better if native and tied as close to the JS engine as possible, i.e. it should\n// reflect the exact location of the JS file that was executed.\nfunction getBaseUrl() {\n // TODO: Make it official by moving out of `extra`\n let productionBaseUrl = Constants.manifest?.extra?.router?.origin;\n\n if (!productionBaseUrl) {\n return null;\n }\n\n if (process.env.NODE_ENV !== \"production\") {\n // e.g. http://localhost:19006\n productionBaseUrl = getDevServer().url;\n }\n\n // Ensure no trailing slash\n return productionBaseUrl?.replace(/\\/$/, \"\");\n}\n\nfunction wrapFetchWithWindowLocation(\n fetch: Function & { __EXPO_BASE_URL_POLYFILLED?: boolean }\n) {\n if (fetch.__EXPO_BASE_URL_POLYFILLED) {\n return fetch;\n }\n\n const _fetch = (...props: any[]) => {\n if (props[0] && typeof props[0] === \"string\" && props[0].startsWith(\"/\")) {\n if (process.env.NODE_ENV !== \"production\") {\n warnProductionOriginNotConfigured(props[0]);\n }\n\n props[0] = new URL(props[0], window.location?.origin).toString();\n } else if (props[0] && typeof props[0] === \"object\") {\n if (\n props[0].url &&\n typeof props[0].url === \"string\" &&\n props[0].url.startsWith(\"/\")\n ) {\n if (process.env.NODE_ENV !== \"production\") {\n warnProductionOriginNotConfigured(props[0]);\n }\n\n props[0].url = new URL(\n props[0].url,\n window.location?.origin\n ).toString();\n }\n }\n return fetch(...props);\n };\n\n _fetch.__EXPO_BASE_URL_POLYFILLED = true;\n\n return _fetch;\n}\n\nif (Constants.manifest?.extra?.router?.origin !== false) {\n // Polyfill window.location in native runtimes.\n if (typeof window !== \"undefined\" && !window.location) {\n const url = getBaseUrl();\n if (url) {\n setLocationHref(url);\n install();\n }\n }\n // Polyfill native fetch to support relative URLs\n Object.defineProperty(global, \"fetch\", {\n value: wrapFetchWithWindowLocation(fetch),\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/metro-runtime",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Tools for making experimental Metro bundler features work",
5
5
  "main": "build",
6
6
  "homepage": "https://github.com/expo/router/tree/main/packages/expo-metro-runtime",