@expo/metro-runtime 3.1.1 → 3.1.3
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/HMRClient.d.ts.map +1 -1
- package/build/HMRClient.js +1 -0
- package/build/HMRClient.js.map +1 -1
- package/build/async-require/buildUrlForBundle.d.ts.map +1 -1
- package/build/async-require/buildUrlForBundle.js +3 -0
- package/build/async-require/buildUrlForBundle.js.map +1 -1
- package/build/async-require/buildUrlForBundle.native.d.ts.map +1 -1
- package/build/async-require/buildUrlForBundle.native.js +3 -0
- package/build/async-require/buildUrlForBundle.native.js.map +1 -1
- package/build/async-require/fetchAsync.d.ts +1 -0
- package/build/async-require/fetchAsync.d.ts.map +1 -1
- package/build/async-require/fetchAsync.js +1 -0
- package/build/async-require/fetchAsync.js.map +1 -1
- package/build/async-require/fetchAsync.native.d.ts +1 -0
- package/build/async-require/fetchAsync.native.d.ts.map +1 -1
- package/build/async-require/fetchAsync.native.js +3 -1
- package/build/async-require/fetchAsync.native.js.map +1 -1
- package/build/async-require/fetchThenEvalJs.d.ts.map +1 -1
- package/build/async-require/fetchThenEvalJs.js +37 -8
- package/build/async-require/fetchThenEvalJs.js.map +1 -1
- package/package.json +2 -2
- package/src/HMRClient.ts +1 -0
- package/src/async-require/buildUrlForBundle.native.ts +4 -0
- package/src/async-require/buildUrlForBundle.ts +3 -0
- package/src/async-require/fetchAsync.native.ts +46 -42
- package/src/async-require/fetchAsync.ts +4 -1
- package/src/async-require/fetchThenEvalJs.ts +41 -9
package/build/HMRClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HMRClient.d.ts","sourceRoot":"","sources":["../src/HMRClient.ts"],"names":[],"mappings":"AAiCA,KAAK,QAAQ,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,gBAAgB,GAChB,UAAU,GACV,OAAO,CAAC;AAEZ,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC5C,CAAC;AAMF;;;GAGG;AACH,QAAA,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"HMRClient.d.ts","sourceRoot":"","sources":["../src/HMRClient.ts"],"names":[],"mappings":"AAiCA,KAAK,QAAQ,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,gBAAgB,GAChB,UAAU,GACV,OAAO,CAAC;AAEZ,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC5C,CAAC;AAMF;;;GAGG;AACH,QAAA,MAAM,SAAS,EAAE,wBAyLhB,CAAC;AAuEF,eAAe,SAAS,CAAC"}
|
package/build/HMRClient.js
CHANGED
package/build/HMRClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HMRClient.js","sourceRoot":"","sources":["../src/HMRClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,+DAAsD;AAEtD,gEAAwC;AACxC,oEAA4C;AAC5C,k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AAuE;IACvE,uFAAuF;IACvF,aAAa,EAAE,CAAC;IAEhB,MAAM,OAAO,GAAG,0BAA0B,CAAC;IAC3C,0BAA0B,GAAG,IAAI,CAAC;IAElC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,0CAA0C;IAC1C,mBAAmB;IACnB,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAClC,MAAM,KAAK,CAAC;AACd,CAAC;AAED,kBAAe,SAAS,CAAC","sourcesContent":["/**\n * Copyright (c) 650 Industries.\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Based on this but with web support:\n * https://github.com/facebook/react-native/blob/086714b02b0fb838dee5a66c5bcefe73b53cf3df/Libraries/Utilities/HMRClient.js\n */\nimport prettyFormat, { plugins } from 'pretty-format';\n\nimport LoadingView from './LoadingView';\nimport LogBox from './error-overlay/LogBox';\nimport getDevServer from './getDevServer';\n\nconst MetroHMRClient = require('metro-runtime/src/modules/HMRClient');\nconst pendingEntryPoints: string[] = [];\n\ntype HMRClientType = {\n send: (msg: string) => void;\n isEnabled: () => boolean;\n disable: () => void;\n enable: () => void;\n hasPendingUpdates: () => boolean;\n};\n\nlet hmrClient: HMRClientType | null = null;\nlet hmrUnavailableReason: string | null = null;\nlet currentCompileErrorMessage: string | null = null;\nlet didConnect: boolean = false;\nconst pendingLogs: [LogLevel, any[]][] = [];\n\ntype LogLevel =\n | 'trace'\n | 'info'\n | 'warn'\n | 'error'\n | 'log'\n | 'group'\n | 'groupCollapsed'\n | 'groupEnd'\n | 'debug';\n\nexport type HMRClientNativeInterface = {\n enable(): void;\n disable(): void;\n registerBundle(requestUrl: string): void;\n log(level: LogLevel, data: any[]): void;\n setup(props: { isEnabled: boolean }): void;\n};\n\nfunction assert(foo: any, msg: string): asserts foo {\n if (!foo) throw new Error(msg);\n}\n\n/**\n * HMR Client that receives from the server HMR updates and propagates them\n * runtime to reflects those changes.\n */\nconst HMRClient: HMRClientNativeInterface = {\n enable() {\n if (hmrUnavailableReason !== null) {\n // If HMR became unavailable while you weren't using it,\n // explain why when you try to turn it on.\n // This is an error (and not a warning) because it is shown\n // in response to a direct user action.\n throw new Error(hmrUnavailableReason);\n }\n\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n\n // We use this for internal logging only.\n // It doesn't affect the logic.\n hmrClient.send(JSON.stringify({ type: 'log-opt-in' }));\n\n // When toggling Fast Refresh on, we might already have some stashed updates.\n // Since they'll get applied now, we'll show a banner.\n const hasUpdates = hmrClient!.hasPendingUpdates();\n\n if (hasUpdates) {\n LoadingView.showMessage('Refreshing...', 'refresh');\n }\n try {\n hmrClient.enable();\n } finally {\n if (hasUpdates) {\n LoadingView.hide();\n }\n }\n\n // There could be a compile error while Fast Refresh was off,\n // but we ignored it at the time. Show it now.\n showCompileError();\n },\n\n disable() {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n hmrClient.disable();\n },\n\n registerBundle(requestUrl: string) {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n pendingEntryPoints.push(requestUrl);\n registerBundleEntryPoints(hmrClient);\n },\n\n log(level: LogLevel, data: any[]) {\n if (!hmrClient) {\n // Catch a reasonable number of early logs\n // in case hmrClient gets initialized later.\n pendingLogs.push([level, data]);\n if (pendingLogs.length > 100) {\n pendingLogs.shift();\n }\n return;\n }\n try {\n hmrClient.send(\n JSON.stringify({\n type: 'log',\n level,\n mode: 'BRIDGE',\n data: data.map((item) =>\n typeof item === 'string'\n ? item\n : prettyFormat(item, {\n escapeString: true,\n highlight: true,\n maxDepth: 3,\n min: true,\n plugins: [plugins.ReactElement],\n })\n ),\n })\n );\n } catch {\n // If sending logs causes any failures we want to silently ignore them\n // to ensure we do not cause infinite-logging loops.\n }\n },\n\n // Called once by the bridge on startup, even if Fast Refresh is off.\n // It creates the HMR client but doesn't actually set up the socket yet.\n setup({ isEnabled }: { isEnabled: boolean }) {\n assert(!hmrClient, 'Cannot initialize hmrClient twice');\n\n const serverScheme = window.location.protocol === 'https:' ? 'wss' : 'ws';\n const client = new MetroHMRClient(`${serverScheme}://${window.location.host}/hot`);\n hmrClient = client;\n\n const { fullBundleUrl } = getDevServer();\n pendingEntryPoints.push(\n // HMRServer understands regular bundle URLs, so prefer that in case\n // there are any important URL parameters we can't reconstruct from\n // `setup()`'s arguments.\n fullBundleUrl\n );\n\n client.on('connection-error', (e: Error) => {\n let error = `Cannot connect to Metro.\n \n Try the following to fix the issue:\n - Ensure the Metro dev server is running and available on the same network as this device`;\n error += `\n \n URL: ${window.location.host}\n \n Error: ${e.message}`;\n\n setHMRUnavailableReason(error);\n });\n\n client.on('update-start', ({ isInitialUpdate }: { isInitialUpdate?: boolean }) => {\n currentCompileErrorMessage = null;\n didConnect = true;\n\n if (client.isEnabled() && !isInitialUpdate) {\n LoadingView.showMessage('Refreshing...', 'refresh');\n }\n });\n\n client.on('update', ({ isInitialUpdate }: { isInitialUpdate?: boolean }) => {\n if (client.isEnabled() && !isInitialUpdate) {\n dismissRedbox();\n LogBox.clearAllLogs();\n }\n });\n\n client.on('update-done', () => {\n LoadingView.hide();\n });\n\n client.on('error', (data: { type: string; message: string }) => {\n LoadingView.hide();\n\n if (data.type === 'GraphNotFoundError') {\n client.close();\n setHMRUnavailableReason('Metro has restarted since the last edit. Reload to reconnect.');\n } else if (data.type === 'RevisionNotFoundError') {\n client.close();\n setHMRUnavailableReason('Metro and the client are out of sync. Reload to reconnect.');\n } else {\n currentCompileErrorMessage = `${data.type} ${data.message}`;\n if (client.isEnabled()) {\n showCompileError();\n }\n }\n });\n\n client.on('close', (closeEvent: { code: number; reason: string }) => {\n LoadingView.hide();\n\n // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1\n // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5\n const isNormalOrUnsetCloseReason =\n closeEvent == null ||\n closeEvent.code === 1000 ||\n closeEvent.code === 1005 ||\n closeEvent.code == null;\n\n setHMRUnavailableReason(\n `${\n isNormalOrUnsetCloseReason\n ? 'Disconnected from Metro.'\n : `Disconnected from Metro (${closeEvent.code}: \"${closeEvent.reason}\").`\n }\n\nTo reconnect:\n- Ensure that Metro is running and available on the same network\n- Reload this app (will trigger further help if Metro cannot be connected to)\n `\n );\n });\n\n if (isEnabled) {\n HMRClient.enable();\n } else {\n HMRClient.disable();\n }\n\n registerBundleEntryPoints(hmrClient);\n flushEarlyLogs();\n },\n};\n\nfunction setHMRUnavailableReason(reason: string) {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n if (hmrUnavailableReason !== null) {\n // Don't show more than one warning.\n return;\n }\n hmrUnavailableReason = reason;\n\n // We only want to show a warning if Fast Refresh is on *and* if we ever\n // previously managed to connect successfully. We don't want to show\n // the warning to native engineers who use cached bundles without Metro.\n if (hmrClient.isEnabled() && didConnect) {\n console.warn(reason);\n // (Not using the `warning` module to prevent a Buck cycle.)\n }\n}\n\nfunction registerBundleEntryPoints(client: HMRClientType | null) {\n if (hmrUnavailableReason != null) {\n // \"Bundle Splitting – Metro disconnected\"\n window.location.reload();\n return;\n }\n\n if (pendingEntryPoints.length > 0) {\n client?.send(\n JSON.stringify({\n type: 'register-entrypoints',\n entryPoints: pendingEntryPoints,\n })\n );\n pendingEntryPoints.length = 0;\n }\n}\n\nfunction flushEarlyLogs() {\n try {\n pendingLogs.forEach(([level, data]) => {\n HMRClient.log(level, data);\n });\n } finally {\n pendingLogs.length = 0;\n }\n}\n\nfunction dismissRedbox() {\n // TODO(EvanBacon): Error overlay for web.\n}\n\nfunction showCompileError() {\n if (currentCompileErrorMessage === null) {\n return;\n }\n\n // Even if there is already a redbox, syntax errors are more important.\n // Otherwise you risk seeing a stale runtime error while a syntax error is more recent.\n dismissRedbox();\n\n const message = currentCompileErrorMessage;\n currentCompileErrorMessage = null;\n\n const error = new Error(message);\n // Symbolicating compile errors is wasted effort\n // because the stack trace is meaningless:\n // @ts-expect-error\n error.preventSymbolication = true;\n throw error;\n}\n\nexport default HMRClient;\n"]}
|
|
1
|
+
{"version":3,"file":"HMRClient.js","sourceRoot":"","sources":["../src/HMRClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,+DAAsD;AAEtD,gEAAwC;AACxC,oEAA4C;AAC5C,kEAA0C;AAE1C,MAAM,cAAc,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACtE,MAAM,kBAAkB,GAAa,EAAE,CAAC;AAUxC,IAAI,SAAS,GAAyB,IAAI,CAAC;AAC3C,IAAI,oBAAoB,GAAkB,IAAI,CAAC;AAC/C,IAAI,0BAA0B,GAAkB,IAAI,CAAC;AACrD,IAAI,UAAU,GAAY,KAAK,CAAC;AAChC,MAAM,WAAW,GAAwB,EAAE,CAAC;AAqB5C,SAAS,MAAM,CAAC,GAAQ,EAAE,GAAW;IACnC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,SAAS,GAA6B;IAC1C,MAAM;QACJ,IAAI,oBAAoB,KAAK,IAAI,EAAE;YACjC,wDAAwD;YACxD,0CAA0C;YAC1C,2DAA2D;YAC3D,uCAAuC;YACvC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACvC;QAED,MAAM,CAAC,SAAS,EAAE,6CAA6C,CAAC,CAAC;QAEjE,yCAAyC;QACzC,+BAA+B;QAC/B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;QAEvD,6EAA6E;QAC7E,sDAAsD;QACtD,MAAM,UAAU,GAAG,SAAU,CAAC,iBAAiB,EAAE,CAAC;QAElD,IAAI,UAAU,EAAE;YACd,qBAAW,CAAC,WAAW,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;SACrD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,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;KACJ;YAAS;QACR,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;KACxB;AACH,CAAC;AAED,SAAS,aAAa;IACpB,0CAA0C;AAC5C,CAAC;AAED,SAAS,gBAAgB;IACvB,IAAI,0BAA0B,KAAK,IAAI,EAAE;QACvC,OAAO;KACR;IAED,uEAAuE;IACvE,uFAAuF;IACvF,aAAa,EAAE,CAAC;IAEhB,MAAM,OAAO,GAAG,0BAA0B,CAAC;IAC3C,0BAA0B,GAAG,IAAI,CAAC;IAElC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,0CAA0C;IAC1C,mBAAmB;IACnB,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAClC,MAAM,KAAK,CAAC;AACd,CAAC;AAED,kBAAe,SAAS,CAAC","sourcesContent":["/**\n * Copyright (c) 650 Industries.\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Based on this but with web support:\n * https://github.com/facebook/react-native/blob/086714b02b0fb838dee5a66c5bcefe73b53cf3df/Libraries/Utilities/HMRClient.js\n */\nimport prettyFormat, { plugins } from 'pretty-format';\n\nimport LoadingView from './LoadingView';\nimport LogBox from './error-overlay/LogBox';\nimport getDevServer from './getDevServer';\n\nconst MetroHMRClient = require('metro-runtime/src/modules/HMRClient');\nconst pendingEntryPoints: string[] = [];\n\ntype HMRClientType = {\n send: (msg: string) => void;\n isEnabled: () => boolean;\n disable: () => void;\n enable: () => void;\n hasPendingUpdates: () => boolean;\n};\n\nlet hmrClient: HMRClientType | null = null;\nlet hmrUnavailableReason: string | null = null;\nlet currentCompileErrorMessage: string | null = null;\nlet didConnect: boolean = false;\nconst pendingLogs: [LogLevel, any[]][] = [];\n\ntype LogLevel =\n | 'trace'\n | 'info'\n | 'warn'\n | 'error'\n | 'log'\n | 'group'\n | 'groupCollapsed'\n | 'groupEnd'\n | 'debug';\n\nexport type HMRClientNativeInterface = {\n enable(): void;\n disable(): void;\n registerBundle(requestUrl: string): void;\n log(level: LogLevel, data: any[]): void;\n setup(props: { isEnabled: boolean }): void;\n};\n\nfunction assert(foo: any, msg: string): asserts foo {\n if (!foo) throw new Error(msg);\n}\n\n/**\n * HMR Client that receives from the server HMR updates and propagates them\n * runtime to reflects those changes.\n */\nconst HMRClient: HMRClientNativeInterface = {\n enable() {\n if (hmrUnavailableReason !== null) {\n // If HMR became unavailable while you weren't using it,\n // explain why when you try to turn it on.\n // This is an error (and not a warning) because it is shown\n // in response to a direct user action.\n throw new Error(hmrUnavailableReason);\n }\n\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n\n // We use this for internal logging only.\n // It doesn't affect the logic.\n hmrClient.send(JSON.stringify({ type: 'log-opt-in' }));\n\n // When toggling Fast Refresh on, we might already have some stashed updates.\n // Since they'll get applied now, we'll show a banner.\n const hasUpdates = hmrClient!.hasPendingUpdates();\n\n if (hasUpdates) {\n LoadingView.showMessage('Refreshing...', 'refresh');\n }\n try {\n hmrClient.enable();\n } finally {\n if (hasUpdates) {\n LoadingView.hide();\n }\n }\n\n // There could be a compile error while Fast Refresh was off,\n // but we ignored it at the time. Show it now.\n showCompileError();\n },\n\n disable() {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n hmrClient.disable();\n },\n\n registerBundle(requestUrl: string) {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n pendingEntryPoints.push(requestUrl);\n registerBundleEntryPoints(hmrClient);\n },\n\n log(level: LogLevel, data: any[]) {\n if (!hmrClient) {\n // Catch a reasonable number of early logs\n // in case hmrClient gets initialized later.\n pendingLogs.push([level, data]);\n if (pendingLogs.length > 100) {\n pendingLogs.shift();\n }\n return;\n }\n try {\n hmrClient.send(\n JSON.stringify({\n type: 'log',\n level,\n platform: 'web',\n mode: 'BRIDGE',\n data: data.map((item) =>\n typeof item === 'string'\n ? item\n : prettyFormat(item, {\n escapeString: true,\n highlight: true,\n maxDepth: 3,\n min: true,\n plugins: [plugins.ReactElement],\n })\n ),\n })\n );\n } catch {\n // If sending logs causes any failures we want to silently ignore them\n // to ensure we do not cause infinite-logging loops.\n }\n },\n\n // Called once by the bridge on startup, even if Fast Refresh is off.\n // It creates the HMR client but doesn't actually set up the socket yet.\n setup({ isEnabled }: { isEnabled: boolean }) {\n assert(!hmrClient, 'Cannot initialize hmrClient twice');\n\n const serverScheme = window.location.protocol === 'https:' ? 'wss' : 'ws';\n const client = new MetroHMRClient(`${serverScheme}://${window.location.host}/hot`);\n hmrClient = client;\n\n const { fullBundleUrl } = getDevServer();\n pendingEntryPoints.push(\n // HMRServer understands regular bundle URLs, so prefer that in case\n // there are any important URL parameters we can't reconstruct from\n // `setup()`'s arguments.\n fullBundleUrl\n );\n\n client.on('connection-error', (e: Error) => {\n let error = `Cannot connect to Metro.\n \n Try the following to fix the issue:\n - Ensure the Metro dev server is running and available on the same network as this device`;\n error += `\n \n URL: ${window.location.host}\n \n Error: ${e.message}`;\n\n setHMRUnavailableReason(error);\n });\n\n client.on('update-start', ({ isInitialUpdate }: { isInitialUpdate?: boolean }) => {\n currentCompileErrorMessage = null;\n didConnect = true;\n\n if (client.isEnabled() && !isInitialUpdate) {\n LoadingView.showMessage('Refreshing...', 'refresh');\n }\n });\n\n client.on('update', ({ isInitialUpdate }: { isInitialUpdate?: boolean }) => {\n if (client.isEnabled() && !isInitialUpdate) {\n dismissRedbox();\n LogBox.clearAllLogs();\n }\n });\n\n client.on('update-done', () => {\n LoadingView.hide();\n });\n\n client.on('error', (data: { type: string; message: string }) => {\n LoadingView.hide();\n\n if (data.type === 'GraphNotFoundError') {\n client.close();\n setHMRUnavailableReason('Metro has restarted since the last edit. Reload to reconnect.');\n } else if (data.type === 'RevisionNotFoundError') {\n client.close();\n setHMRUnavailableReason('Metro and the client are out of sync. Reload to reconnect.');\n } else {\n currentCompileErrorMessage = `${data.type} ${data.message}`;\n if (client.isEnabled()) {\n showCompileError();\n }\n }\n });\n\n client.on('close', (closeEvent: { code: number; reason: string }) => {\n LoadingView.hide();\n\n // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1\n // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5\n const isNormalOrUnsetCloseReason =\n closeEvent == null ||\n closeEvent.code === 1000 ||\n closeEvent.code === 1005 ||\n closeEvent.code == null;\n\n setHMRUnavailableReason(\n `${\n isNormalOrUnsetCloseReason\n ? 'Disconnected from Metro.'\n : `Disconnected from Metro (${closeEvent.code}: \"${closeEvent.reason}\").`\n }\n\nTo reconnect:\n- Ensure that Metro is running and available on the same network\n- Reload this app (will trigger further help if Metro cannot be connected to)\n `\n );\n });\n\n if (isEnabled) {\n HMRClient.enable();\n } else {\n HMRClient.disable();\n }\n\n registerBundleEntryPoints(hmrClient);\n flushEarlyLogs();\n },\n};\n\nfunction setHMRUnavailableReason(reason: string) {\n assert(hmrClient, 'Expected HMRClient.setup() call at startup.');\n if (hmrUnavailableReason !== null) {\n // Don't show more than one warning.\n return;\n }\n hmrUnavailableReason = reason;\n\n // We only want to show a warning if Fast Refresh is on *and* if we ever\n // previously managed to connect successfully. We don't want to show\n // the warning to native engineers who use cached bundles without Metro.\n if (hmrClient.isEnabled() && didConnect) {\n console.warn(reason);\n // (Not using the `warning` module to prevent a Buck cycle.)\n }\n}\n\nfunction registerBundleEntryPoints(client: HMRClientType | null) {\n if (hmrUnavailableReason != null) {\n // \"Bundle Splitting – Metro disconnected\"\n window.location.reload();\n return;\n }\n\n if (pendingEntryPoints.length > 0) {\n client?.send(\n JSON.stringify({\n type: 'register-entrypoints',\n entryPoints: pendingEntryPoints,\n })\n );\n pendingEntryPoints.length = 0;\n }\n}\n\nfunction flushEarlyLogs() {\n try {\n pendingLogs.forEach(([level, data]) => {\n HMRClient.log(level, data);\n });\n } finally {\n pendingLogs.length = 0;\n }\n}\n\nfunction dismissRedbox() {\n // TODO(EvanBacon): Error overlay for web.\n}\n\nfunction showCompileError() {\n if (currentCompileErrorMessage === null) {\n return;\n }\n\n // Even if there is already a redbox, syntax errors are more important.\n // Otherwise you risk seeing a stale runtime error while a syntax error is more recent.\n dismissRedbox();\n\n const message = currentCompileErrorMessage;\n currentCompileErrorMessage = null;\n\n const error = new Error(message);\n // Symbolicating compile errors is wasted effort\n // because the stack trace is meaningless:\n // @ts-expect-error\n error.preventSymbolication = true;\n throw error;\n}\n\nexport default HMRClient;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrlForBundle.d.ts","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"buildUrlForBundle.d.ts","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAO5D"}
|
|
@@ -14,6 +14,9 @@ exports.buildUrlForBundle = void 0;
|
|
|
14
14
|
* @returns a URL like "/foobar.bundle?platform=android&modulesOnly=true&runModule=false&runtimeBytecodeVersion=null"
|
|
15
15
|
*/
|
|
16
16
|
function buildUrlForBundle(bundlePath) {
|
|
17
|
+
if (bundlePath.match(/^https?:\/\//)) {
|
|
18
|
+
return bundlePath;
|
|
19
|
+
}
|
|
17
20
|
// NOTE(EvanBacon): This must come from the window origin (at least in dev mode).
|
|
18
21
|
// Otherwise Metro will crash from attempting to load a bundle that doesn't exist.
|
|
19
22
|
return '/' + bundlePath.replace(/^\/+/, '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrlForBundle.js","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,iFAAiF;IACjF,kFAAkF;IAClF,OAAO,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;
|
|
1
|
+
{"version":3,"file":"buildUrlForBundle.js","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,IAAI,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC;KACnB;IACD,iFAAiF;IACjF,kFAAkF;IAClF,OAAO,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAPD,8CAOC","sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Given a path and some optional additional query parameters, create the dev server bundle URL.\n * @param bundlePath like `/foobar`\n * @param params like `{ platform: \"web\" }`\n * @returns a URL like \"/foobar.bundle?platform=android&modulesOnly=true&runModule=false&runtimeBytecodeVersion=null\"\n */\nexport function buildUrlForBundle(bundlePath: string): string {\n if (bundlePath.match(/^https?:\\/\\//)) {\n return bundlePath;\n }\n // NOTE(EvanBacon): This must come from the window origin (at least in dev mode).\n // Otherwise Metro will crash from attempting to load a bundle that doesn't exist.\n return '/' + bundlePath.replace(/^\\/+/, '');\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrlForBundle.native.d.ts","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.native.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"buildUrlForBundle.native.d.ts","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.native.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAoB5D"}
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.buildUrlForBundle = void 0;
|
|
10
10
|
function buildUrlForBundle(bundlePath) {
|
|
11
|
+
if (bundlePath.match(/^https?:\/\//)) {
|
|
12
|
+
return bundlePath;
|
|
13
|
+
}
|
|
11
14
|
if (process.env.NODE_ENV === 'production') {
|
|
12
15
|
if (typeof location !== 'undefined') {
|
|
13
16
|
return joinComponents(location.origin, bundlePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrlForBundle.native.js","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.native.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,OAAO,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;SACpD;QACD,MAAM,IAAI,KAAK,CACb,6IAA6I,CAC9I,CAAC;KACH;SAAM;QACL,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC;aAC5C,OAAmD,CAAC;QAEvD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;QAE1C,OAAO,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;KAC9C;AACH,CAAC;
|
|
1
|
+
{"version":3,"file":"buildUrlForBundle.native.js","sourceRoot":"","sources":["../../src/async-require/buildUrlForBundle.native.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,IAAI,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC;KACnB;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,OAAO,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;SACpD;QACD,MAAM,IAAI,KAAK,CACb,6IAA6I,CAC9I,CAAC;KACH;SAAM;QACL,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC;aAC5C,OAAmD,CAAC;QAEvD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;QAE1C,OAAO,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;KAC9C;AACH,CAAC;AApBD,8CAoBC;AAED,SAAS,cAAc,CAAC,MAAc,EAAE,MAAc;IACpD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nexport function buildUrlForBundle(bundlePath: string): string {\n if (bundlePath.match(/^https?:\\/\\//)) {\n return bundlePath;\n }\n\n if (process.env.NODE_ENV === 'production') {\n if (typeof location !== 'undefined') {\n return joinComponents(location.origin, bundlePath);\n }\n throw new Error(\n 'Unable to determine the production URL where additional JavaScript chunks are hosted because the global \"location\" variable is not defined.'\n );\n } else {\n const getDevServer = require('../getDevServer')\n .default as typeof import('../getDevServer').default;\n\n const { url: serverUrl } = getDevServer();\n\n return joinComponents(serverUrl, bundlePath);\n }\n}\n\nfunction joinComponents(prefix: string, suffix: string): string {\n return prefix.replace(/\\/+$/, '') + '/' + suffix.replace(/^\\/+/, '');\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAsync.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchAsync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,UAAU,
|
|
1
|
+
{"version":3,"file":"fetchAsync.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchAsync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAa7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAsync.js","sourceRoot":"","sources":["../../src/async-require/fetchAsync.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,KAAK,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"fetchAsync.js","sourceRoot":"","sources":["../../src/async-require/fetchAsync.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,KAAK,UAAU,UAAU,CAC9B,GAAW;IAEX,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,wEAAwE;YACxE,eAAe,EAAE,KAAK;SACvB;KACF,CAAC,CAAC;IACH,OAAO;QACL,IAAI,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE;QAC3B,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC;AACJ,CAAC;AAfD,gCAeC","sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nexport async function fetchAsync(\n url: string\n): Promise<{ body: string; status: number; headers: Headers }> {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n // No real reason for this but we try to use this format for everything.\n 'expo-platform': 'web',\n },\n });\n return {\n body: await response.text(),\n status: response.status,\n headers: response.headers,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAsync.native.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchAsync.native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"fetchAsync.native.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchAsync.native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,CA2D5E"}
|
|
@@ -16,6 +16,7 @@ const react_native_1 = require("react-native");
|
|
|
16
16
|
const RCTNetworking_1 = __importDefault(require("react-native/Libraries/Network/RCTNetworking"));
|
|
17
17
|
function fetchAsync(url) {
|
|
18
18
|
let id = null;
|
|
19
|
+
let statusCode = null;
|
|
19
20
|
let responseText = null;
|
|
20
21
|
let headers = {};
|
|
21
22
|
let dataListener = null;
|
|
@@ -30,6 +31,7 @@ function fetchAsync(url) {
|
|
|
30
31
|
});
|
|
31
32
|
responseListener = addListener('didReceiveNetworkResponse', ([requestId, status, responseHeaders]) => {
|
|
32
33
|
if (requestId === id) {
|
|
34
|
+
statusCode = status;
|
|
33
35
|
headers = responseHeaders;
|
|
34
36
|
}
|
|
35
37
|
});
|
|
@@ -39,7 +41,7 @@ function fetchAsync(url) {
|
|
|
39
41
|
reject(error);
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
42
|
-
resolve({ body: responseText, headers });
|
|
44
|
+
resolve({ body: responseText, status: statusCode, headers });
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAsync.native.js","sourceRoot":"","sources":["../../src/async-require/fetchAsync.native.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,+CAAwC;AACxC,mBAAmB;AACnB,iGAAsE;AAItE,SAAgB,UAAU,CACxB,GAAW;IAEX,IAAI,EAAE,GAAkB,IAAI,CAAC;IAC7B,IAAI,YAAY,GAAkB,IAAI,CAAC;IACvC,IAAI,OAAO,GAA2B,EAAE,CAAC;IACzC,IAAI,YAAY,GAAsB,IAAI,CAAC;IAC3C,IAAI,gBAAgB,GAAsB,IAAI,CAAC;IAC/C,IAAI,gBAAgB,GAAsB,IAAI,CAAC;IAC/C,OAAO,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"fetchAsync.native.js","sourceRoot":"","sources":["../../src/async-require/fetchAsync.native.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,+CAAwC;AACxC,mBAAmB;AACnB,iGAAsE;AAItE,SAAgB,UAAU,CACxB,GAAW;IAEX,IAAI,EAAE,GAAkB,IAAI,CAAC;IAC7B,IAAI,UAAU,GAAkB,IAAI,CAAC;IACrC,IAAI,YAAY,GAAkB,IAAI,CAAC;IACvC,IAAI,OAAO,GAA2B,EAAE,CAAC;IACzC,IAAI,YAAY,GAAsB,IAAI,CAAC;IAC3C,IAAI,gBAAgB,GAAsB,IAAI,CAAC;IAC/C,IAAI,gBAAgB,GAAsB,IAAI,CAAC;IAC/C,OAAO,IAAI,OAAO,CAChB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAClB,MAAM,WAAW,GAAG,uBAAU,CA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CAAC,CAAC;AACL,CAAC;AA7DD,gCA6DC","sourcesContent":["/**\n * Copyright (c) 650 Industries.\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { Platform } from 'react-native';\n// @ts-expect-error\nimport Networking from 'react-native/Libraries/Network/RCTNetworking';\n\ntype Subscriber = { remove: () => void };\n\nexport function fetchAsync(\n url: string\n): Promise<{ body: string; status: number; headers: Record<string, string> }> {\n let id: string | null = null;\n let statusCode: number | null = null;\n let responseText: string | null = null;\n let headers: Record<string, string> = {};\n let dataListener: Subscriber | null = null;\n let completeListener: Subscriber | null = null;\n let responseListener: Subscriber | null = null;\n return new Promise<{ body: string; status: number; headers: Record<string, string> }>(\n (resolve, reject) => {\n const addListener = Networking.addListener.bind(Networking) as (\n event: string,\n callback: (props: [string, any, any]) => any\n ) => Subscriber;\n dataListener = addListener('didReceiveNetworkData', ([requestId, response]) => {\n if (requestId === id) {\n responseText = response;\n }\n });\n responseListener = addListener(\n 'didReceiveNetworkResponse',\n ([requestId, status, responseHeaders]) => {\n if (requestId === id) {\n statusCode = status;\n headers = responseHeaders;\n }\n }\n );\n completeListener = addListener('didCompleteNetworkResponse', ([requestId, error]) => {\n if (requestId === id) {\n if (error) {\n reject(error);\n } else {\n resolve({ body: responseText!, status: statusCode!, headers });\n }\n }\n });\n (Networking.sendRequest as any)(\n 'GET',\n 'asyncRequest',\n url,\n {\n 'expo-platform': Platform.OS,\n },\n '',\n 'text',\n false,\n 0,\n (requestId: string) => {\n id = requestId;\n },\n true\n );\n }\n ).finally(() => {\n dataListener?.remove();\n completeListener?.remove();\n responseListener?.remove();\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchThenEvalJs.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchThenEvalJs.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"fetchThenEvalJs.d.ts","sourceRoot":"","sources":["../../src/async-require/fetchThenEvalJs.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C7D"}
|
|
@@ -14,23 +14,52 @@ const fetchAsync_1 = require("./fetchAsync");
|
|
|
14
14
|
* @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`.
|
|
15
15
|
*/
|
|
16
16
|
function fetchThenEvalAsync(url) {
|
|
17
|
-
return (0, fetchAsync_1.fetchAsync)(url).then(({ body, headers }) => {
|
|
17
|
+
return (0, fetchAsync_1.fetchAsync)(url).then(({ body, status, headers }) => {
|
|
18
18
|
if (headers?.has?.('Content-Type') != null &&
|
|
19
19
|
headers.get('Content-Type').includes('application/json')) {
|
|
20
20
|
// Errors are returned as JSON.
|
|
21
21
|
throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (status === 200) {
|
|
24
|
+
// Some engines do not support `sourceURL` as a comment. We expose a
|
|
25
|
+
// `globalEvalWithSourceUrl` function to handle updates in that case.
|
|
26
|
+
if (global.globalEvalWithSourceUrl) {
|
|
27
|
+
return global.globalEvalWithSourceUrl(body, url);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// eslint-disable-next-line no-eval
|
|
31
|
+
return eval(body);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
else {
|
|
30
|
-
//
|
|
31
|
-
|
|
35
|
+
// Format Metro errors if possible.
|
|
36
|
+
if (process.env.NODE_ENV === 'development') {
|
|
37
|
+
// body can be an error from Metro if a module is missing.
|
|
38
|
+
// {"originModulePath":"/Users/evanbacon/Documents/GitHub/expo/.","targetModuleName":"./http://localhost:8081/node_modules/react-native/index.js","message":"..."}
|
|
39
|
+
const error = jsonParseOptional(body);
|
|
40
|
+
if (error) {
|
|
41
|
+
// TODO: This is essentially like the Metro native red box errors. We should do a better job formatting them so
|
|
42
|
+
// the user experience doesn't feel bad. This can be tested by loading a split bundle that results in a missing module error from Metro.
|
|
43
|
+
if ('message' in error) {
|
|
44
|
+
throw new Error('Failed to load split bundle from Metro ' +
|
|
45
|
+
url +
|
|
46
|
+
' (check terminal for more info).\n(load: ' +
|
|
47
|
+
error.message +
|
|
48
|
+
')');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Failed to load split bundle from Metro ${url} (check terminal for more info).\n${body}`);
|
|
32
53
|
}
|
|
33
54
|
});
|
|
34
55
|
}
|
|
35
56
|
exports.fetchThenEvalAsync = fetchThenEvalAsync;
|
|
57
|
+
function jsonParseOptional(json) {
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(json);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
36
65
|
//# sourceMappingURL=fetchThenEvalJs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchThenEvalJs.js","sourceRoot":"","sources":["../../src/async-require/fetchThenEvalJs.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6CAA0C;AAM1C;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,OAAO,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"fetchThenEvalJs.js","sourceRoot":"","sources":["../../src/async-require/fetchThenEvalJs.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6CAA0C;AAM1C;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,GAAW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QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACzB;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { fetchAsync } from './fetchAsync';\n\ndeclare let global: {\n globalEvalWithSourceUrl?: any;\n};\n\n/**\n * Load a bundle for a URL using fetch + eval on native and script tag injection on web.\n *\n * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`.\n */\nexport function fetchThenEvalAsync(url: string): Promise<void> {\n return fetchAsync(url).then(({ body, status, headers }) => {\n if (\n headers?.has?.('Content-Type') != null &&\n headers.get('Content-Type')!.includes('application/json')\n ) {\n // Errors are returned as JSON.\n throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`);\n }\n\n if (status === 200) {\n // Some engines do not support `sourceURL` as a comment. We expose a\n // `globalEvalWithSourceUrl` function to handle updates in that case.\n if (global.globalEvalWithSourceUrl) {\n return global.globalEvalWithSourceUrl(body, url);\n } else {\n // eslint-disable-next-line no-eval\n return eval(body);\n }\n } else {\n // Format Metro errors if possible.\n if (process.env.NODE_ENV === 'development') {\n // body can be an error from Metro if a module is missing.\n // {\"originModulePath\":\"/Users/evanbacon/Documents/GitHub/expo/.\",\"targetModuleName\":\"./http://localhost:8081/node_modules/react-native/index.js\",\"message\":\"...\"}\n const error = jsonParseOptional(body);\n if (error) {\n // TODO: This is essentially like the Metro native red box errors. We should do a better job formatting them so\n // the user experience doesn't feel bad. This can be tested by loading a split bundle that results in a missing module error from Metro.\n if ('message' in error) {\n throw new Error(\n 'Failed to load split bundle from Metro ' +\n url +\n ' (check terminal for more info).\\n(load: ' +\n error.message +\n ')'\n );\n }\n }\n }\n\n throw new Error(\n `Failed to load split bundle from Metro ${url} (check terminal for more info).\\n${body}`\n );\n }\n });\n}\n\nfunction jsonParseOptional(json: string): any {\n try {\n return JSON.parse(json);\n } catch {\n return null;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-runtime",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Tools for making advanced Metro bundler features work",
|
|
5
5
|
"sideEffects": true,
|
|
6
6
|
"types": "build",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react-native": "*"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4f3dcf3e23eae997f884117fdd34ad734efad9fd"
|
|
40
40
|
}
|
package/src/HMRClient.ts
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
export function buildUrlForBundle(bundlePath: string): string {
|
|
9
|
+
if (bundlePath.match(/^https?:\/\//)) {
|
|
10
|
+
return bundlePath;
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
if (process.env.NODE_ENV === 'production') {
|
|
10
14
|
if (typeof location !== 'undefined') {
|
|
11
15
|
return joinComponents(location.origin, bundlePath);
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* @returns a URL like "/foobar.bundle?platform=android&modulesOnly=true&runModule=false&runtimeBytecodeVersion=null"
|
|
13
13
|
*/
|
|
14
14
|
export function buildUrlForBundle(bundlePath: string): string {
|
|
15
|
+
if (bundlePath.match(/^https?:\/\//)) {
|
|
16
|
+
return bundlePath;
|
|
17
|
+
}
|
|
15
18
|
// NOTE(EvanBacon): This must come from the window origin (at least in dev mode).
|
|
16
19
|
// Otherwise Metro will crash from attempting to load a bundle that doesn't exist.
|
|
17
20
|
return '/' + bundlePath.replace(/^\/+/, '');
|
|
@@ -14,57 +14,61 @@ type Subscriber = { remove: () => void };
|
|
|
14
14
|
|
|
15
15
|
export function fetchAsync(
|
|
16
16
|
url: string
|
|
17
|
-
): Promise<{ body: string; headers: Record<string, string> }> {
|
|
17
|
+
): Promise<{ body: string; status: number; headers: Record<string, string> }> {
|
|
18
18
|
let id: string | null = null;
|
|
19
|
+
let statusCode: number | null = null;
|
|
19
20
|
let responseText: string | null = null;
|
|
20
21
|
let headers: Record<string, string> = {};
|
|
21
22
|
let dataListener: Subscriber | null = null;
|
|
22
23
|
let completeListener: Subscriber | null = null;
|
|
23
24
|
let responseListener: Subscriber | null = null;
|
|
24
|
-
return new Promise<{ body: string; headers: Record<string, string> }>(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
responseText = response;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
responseListener = addListener(
|
|
35
|
-
'didReceiveNetworkResponse',
|
|
36
|
-
([requestId, status, responseHeaders]) => {
|
|
25
|
+
return new Promise<{ body: string; status: number; headers: Record<string, string> }>(
|
|
26
|
+
(resolve, reject) => {
|
|
27
|
+
const addListener = Networking.addListener.bind(Networking) as (
|
|
28
|
+
event: string,
|
|
29
|
+
callback: (props: [string, any, any]) => any
|
|
30
|
+
) => Subscriber;
|
|
31
|
+
dataListener = addListener('didReceiveNetworkData', ([requestId, response]) => {
|
|
37
32
|
if (requestId === id) {
|
|
38
|
-
|
|
33
|
+
responseText = response;
|
|
39
34
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
});
|
|
36
|
+
responseListener = addListener(
|
|
37
|
+
'didReceiveNetworkResponse',
|
|
38
|
+
([requestId, status, responseHeaders]) => {
|
|
39
|
+
if (requestId === id) {
|
|
40
|
+
statusCode = status;
|
|
41
|
+
headers = responseHeaders;
|
|
42
|
+
}
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
44
|
+
);
|
|
45
|
+
completeListener = addListener('didCompleteNetworkResponse', ([requestId, error]) => {
|
|
46
|
+
if (requestId === id) {
|
|
47
|
+
if (error) {
|
|
48
|
+
reject(error);
|
|
49
|
+
} else {
|
|
50
|
+
resolve({ body: responseText!, status: statusCode!, headers });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
(Networking.sendRequest as any)(
|
|
55
|
+
'GET',
|
|
56
|
+
'asyncRequest',
|
|
57
|
+
url,
|
|
58
|
+
{
|
|
59
|
+
'expo-platform': Platform.OS,
|
|
60
|
+
},
|
|
61
|
+
'',
|
|
62
|
+
'text',
|
|
63
|
+
false,
|
|
64
|
+
0,
|
|
65
|
+
(requestId: string) => {
|
|
66
|
+
id = requestId;
|
|
67
|
+
},
|
|
68
|
+
true
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
).finally(() => {
|
|
68
72
|
dataListener?.remove();
|
|
69
73
|
completeListener?.remove();
|
|
70
74
|
responseListener?.remove();
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
export async function fetchAsync(
|
|
7
|
+
export async function fetchAsync(
|
|
8
|
+
url: string
|
|
9
|
+
): Promise<{ body: string; status: number; headers: Headers }> {
|
|
8
10
|
const response = await fetch(url, {
|
|
9
11
|
method: 'GET',
|
|
10
12
|
headers: {
|
|
@@ -14,6 +16,7 @@ export async function fetchAsync(url: string): Promise<{ body: string; headers:
|
|
|
14
16
|
});
|
|
15
17
|
return {
|
|
16
18
|
body: await response.text(),
|
|
19
|
+
status: response.status,
|
|
17
20
|
headers: response.headers,
|
|
18
21
|
};
|
|
19
22
|
}
|
|
@@ -16,7 +16,7 @@ declare let global: {
|
|
|
16
16
|
* @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`.
|
|
17
17
|
*/
|
|
18
18
|
export function fetchThenEvalAsync(url: string): Promise<void> {
|
|
19
|
-
return fetchAsync(url).then(({ body, headers }) => {
|
|
19
|
+
return fetchAsync(url).then(({ body, status, headers }) => {
|
|
20
20
|
if (
|
|
21
21
|
headers?.has?.('Content-Type') != null &&
|
|
22
22
|
headers.get('Content-Type')!.includes('application/json')
|
|
@@ -25,15 +25,47 @@ export function fetchThenEvalAsync(url: string): Promise<void> {
|
|
|
25
25
|
throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (status === 200) {
|
|
29
|
+
// Some engines do not support `sourceURL` as a comment. We expose a
|
|
30
|
+
// `globalEvalWithSourceUrl` function to handle updates in that case.
|
|
31
|
+
if (global.globalEvalWithSourceUrl) {
|
|
32
|
+
return global.globalEvalWithSourceUrl(body, url);
|
|
33
|
+
} else {
|
|
34
|
+
// eslint-disable-next-line no-eval
|
|
35
|
+
return eval(body);
|
|
36
|
+
}
|
|
34
37
|
} else {
|
|
35
|
-
//
|
|
36
|
-
|
|
38
|
+
// Format Metro errors if possible.
|
|
39
|
+
if (process.env.NODE_ENV === 'development') {
|
|
40
|
+
// body can be an error from Metro if a module is missing.
|
|
41
|
+
// {"originModulePath":"/Users/evanbacon/Documents/GitHub/expo/.","targetModuleName":"./http://localhost:8081/node_modules/react-native/index.js","message":"..."}
|
|
42
|
+
const error = jsonParseOptional(body);
|
|
43
|
+
if (error) {
|
|
44
|
+
// TODO: This is essentially like the Metro native red box errors. We should do a better job formatting them so
|
|
45
|
+
// the user experience doesn't feel bad. This can be tested by loading a split bundle that results in a missing module error from Metro.
|
|
46
|
+
if ('message' in error) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'Failed to load split bundle from Metro ' +
|
|
49
|
+
url +
|
|
50
|
+
' (check terminal for more info).\n(load: ' +
|
|
51
|
+
error.message +
|
|
52
|
+
')'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Failed to load split bundle from Metro ${url} (check terminal for more info).\n${body}`
|
|
60
|
+
);
|
|
37
61
|
}
|
|
38
62
|
});
|
|
39
63
|
}
|
|
64
|
+
|
|
65
|
+
function jsonParseOptional(json: string): any {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(json);
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|