@expo/cli 0.19.7 → 0.19.9
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/bin/cli +1 -1
- package/build/src/install/utils/checkPackagesCompatibility.js +1 -1
- package/build/src/install/utils/checkPackagesCompatibility.js.map +1 -1
- package/build/src/start/server/AsyncNgrok.js +5 -2
- package/build/src/start/server/AsyncNgrok.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +32 -12
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/createServerComponentsMiddleware.js +12 -4
- package/build/src/start/server/metro/createServerComponentsMiddleware.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +20 -9
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/utils/env.js +3 -0
- package/build/src/utils/env.js.map +1 -1
- package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
- package/build/src/utils/telemetry/utils/context.js +1 -1
- package/package.json +2 -2
package/build/bin/cli
CHANGED
|
@@ -43,7 +43,7 @@ async function checkPackagesCompatibility(packages) {
|
|
|
43
43
|
return ((ref = packageMetadata[packageName]) == null ? void 0 : ref.newArchitecture) === "unsupported";
|
|
44
44
|
});
|
|
45
45
|
if (incompatiblePackages.length) {
|
|
46
|
-
_log.Log.warn(_chalk().default.yellow(`${_chalk().default.bold("Warning")}: ${formatPackageNames(incompatiblePackages)} do not support the New Architecture. ${(0, _link.learnMore)("https://docs.expo.dev/guides/new-architecture/")}`));
|
|
46
|
+
_log.Log.warn(_chalk().default.yellow(`${_chalk().default.bold("Warning")}: ${formatPackageNames(incompatiblePackages)} do${incompatiblePackages.length > 1 ? "" : "es"} not support the New Architecture. ${(0, _link.learnMore)("https://docs.expo.dev/guides/new-architecture/")}`));
|
|
47
47
|
}
|
|
48
48
|
} catch {
|
|
49
49
|
_log.Log.log(_chalk().default.gray(ERROR_MESSAGE));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/install/utils/checkPackagesCompatibility.ts"],"sourcesContent":["// note(Simek): https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts\nimport chalk from 'chalk';\n\nimport { Log } from '../../log';\nimport { fetch } from '../../utils/fetch';\nimport { learnMore } from '../../utils/link';\n\nexport type ReactNativeDirectoryCheckResult = {\n unmaintained: boolean;\n newArchitecture: 'supported' | 'unsupported' | 'untested';\n};\n\nconst ERROR_MESSAGE =\n 'Unable to fetch compatibility data from React Native Directory. Skipping check.';\n\nexport async function checkPackagesCompatibility(packages: string[]) {\n try {\n const response = await fetch('https://reactnative.directory/api/libraries/check', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ packages }),\n });\n\n if (!response.ok) {\n Log.log(chalk.gray(ERROR_MESSAGE));\n }\n\n const packageMetadata = (await response.json()) as Record<\n string,\n ReactNativeDirectoryCheckResult\n >;\n\n const incompatiblePackages = packages.filter(\n (packageName) => packageMetadata[packageName]?.newArchitecture === 'unsupported'\n );\n\n if (incompatiblePackages.length) {\n Log.warn(\n chalk.yellow(\n `${chalk.bold('Warning')}: ${formatPackageNames(incompatiblePackages)} do not support the New Architecture. ${learnMore('https://docs.expo.dev/guides/new-architecture/')}`\n )\n );\n }\n } catch {\n Log.log(chalk.gray(ERROR_MESSAGE));\n }\n}\n\nfunction formatPackageNames(incompatiblePackages: string[]) {\n if (incompatiblePackages.length === 1) {\n return incompatiblePackages.join();\n }\n\n const lastPackage = incompatiblePackages.pop();\n return `${incompatiblePackages.join(', ')} and ${lastPackage}`;\n}\n"],"names":["checkPackagesCompatibility","ERROR_MESSAGE","packages","response","fetch","method","headers","body","JSON","stringify","ok","Log","log","chalk","gray","packageMetadata","json","incompatiblePackages","filter","packageName","newArchitecture","length","warn","yellow","bold","formatPackageNames","learnMore","join","last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kPackagesCompatibility.ts"],"sourcesContent":["// note(Simek): https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts\nimport chalk from 'chalk';\n\nimport { Log } from '../../log';\nimport { fetch } from '../../utils/fetch';\nimport { learnMore } from '../../utils/link';\n\nexport type ReactNativeDirectoryCheckResult = {\n unmaintained: boolean;\n newArchitecture: 'supported' | 'unsupported' | 'untested';\n};\n\nconst ERROR_MESSAGE =\n 'Unable to fetch compatibility data from React Native Directory. Skipping check.';\n\nexport async function checkPackagesCompatibility(packages: string[]) {\n try {\n const response = await fetch('https://reactnative.directory/api/libraries/check', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ packages }),\n });\n\n if (!response.ok) {\n Log.log(chalk.gray(ERROR_MESSAGE));\n }\n\n const packageMetadata = (await response.json()) as Record<\n string,\n ReactNativeDirectoryCheckResult\n >;\n\n const incompatiblePackages = packages.filter(\n (packageName) => packageMetadata[packageName]?.newArchitecture === 'unsupported'\n );\n\n if (incompatiblePackages.length) {\n Log.warn(\n chalk.yellow(\n `${chalk.bold('Warning')}: ${formatPackageNames(incompatiblePackages)} do${incompatiblePackages.length > 1 ? '' : 'es'} not support the New Architecture. ${learnMore('https://docs.expo.dev/guides/new-architecture/')}`\n )\n );\n }\n } catch {\n Log.log(chalk.gray(ERROR_MESSAGE));\n }\n}\n\nfunction formatPackageNames(incompatiblePackages: string[]) {\n if (incompatiblePackages.length === 1) {\n return incompatiblePackages.join();\n }\n\n const lastPackage = incompatiblePackages.pop();\n return `${incompatiblePackages.join(', ')} and ${lastPackage}`;\n}\n"],"names":["checkPackagesCompatibility","ERROR_MESSAGE","packages","response","fetch","method","headers","body","JSON","stringify","ok","Log","log","chalk","gray","packageMetadata","json","incompatiblePackages","filter","packageName","newArchitecture","length","warn","yellow","bold","formatPackageNames","learnMore","join","lastPackage","pop"],"mappings":"AAAA,0GAA0G;AAC1G;;;;+BAcsBA,4BAA0B;;aAA1BA,0BAA0B;;;8DAd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AAC,CAAC,CAAC,CAC1N,CACF,CAAC;QACJ,CAAC;IACH,EAAE,OAAM;QACNf,IAAG,IAAA,CAACC,GAAG,CAACC,MAAK,EAAA,QAAA,CAACC,IAAI,CAACb,aAAa,CAAC,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED,SAASwB,kBAAkB,CAACR,oBAA8B,EAAE;IAC1D,IAAIA,oBAAoB,CAACI,MAAM,KAAK,CAAC,EAAE;QACrC,OAAOJ,oBAAoB,CAACU,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,MAAMC,WAAW,GAAGX,oBAAoB,CAACY,GAAG,EAAE,AAAC;IAC/C,OAAO,CAAC,EAAEZ,oBAAoB,CAACU,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAEC,WAAW,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -244,13 +244,16 @@ class AsyncNgrok {
|
|
|
244
244
|
}
|
|
245
245
|
async getProjectRandomnessAsync() {
|
|
246
246
|
const { urlRandomness: randomness } = await _settings.ProjectSettings.readAsync(this.projectRoot);
|
|
247
|
-
if (randomness) {
|
|
247
|
+
if (randomness && /^[A-Za-z0-9]/.test(randomness)) {
|
|
248
248
|
return randomness;
|
|
249
249
|
}
|
|
250
250
|
return await this._resetProjectRandomnessAsync();
|
|
251
251
|
}
|
|
252
252
|
async _resetProjectRandomnessAsync() {
|
|
253
|
-
|
|
253
|
+
let randomness;
|
|
254
|
+
do {
|
|
255
|
+
randomness = _crypto().default.randomBytes(5).toString("base64url");
|
|
256
|
+
}while (randomness.startsWith("_")); // _ is an invalid character for a hostname
|
|
254
257
|
await _settings.ProjectSettings.setAsync(this.projectRoot, {
|
|
255
258
|
urlRandomness: randomness
|
|
256
259
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/AsyncNgrok.ts"],"sourcesContent":["import chalk from 'chalk';\nimport crypto from 'crypto';\nimport * as path from 'path';\nimport slugify from 'slugify';\n\nimport { getSettingsDirectory } from '../../api/user/UserSettings';\nimport { getActorDisplayName, getUserAsync } from '../../api/user/user';\nimport * as Log from '../../log';\nimport { delayAsync, resolveWithTimeout } from '../../utils/delay';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { isNgrokClientError, NgrokInstance, NgrokResolver } from '../doctor/ngrok/NgrokResolver';\nimport { hasAdbReverseAsync, startAdbReverseAsync } from '../platforms/android/adbReverse';\nimport { ProjectSettings } from '../project/settings';\n\nconst debug = require('debug')('expo:start:server:ngrok') as typeof console.log;\n\nconst NGROK_CONFIG = {\n authToken: '5W1bR67GNbWcXqmxZzBG1_56GezNeaX6sSRvn8npeQ8',\n domain: 'exp.direct',\n};\n\nconst TUNNEL_TIMEOUT = 10 * 1000;\n\nexport class AsyncNgrok {\n /** Resolves the best instance of ngrok, exposed for testing. */\n resolver: NgrokResolver;\n\n /** Info about the currently running instance of ngrok. */\n private serverUrl: string | null = null;\n\n constructor(\n private projectRoot: string,\n private port: number\n ) {\n this.resolver = new NgrokResolver(projectRoot);\n }\n\n public getActiveUrl(): string | null {\n return this.serverUrl;\n }\n\n /** Exposed for testing. */\n async _getIdentifyingUrlSegmentsAsync(): Promise<string[]> {\n const user = await getUserAsync();\n if (user?.__typename === 'Robot') {\n throw new CommandError('NGROK_ROBOT', 'Cannot use ngrok with a robot user.');\n }\n const username = getActorDisplayName(user);\n\n return [\n // NOTE: https://github.com/expo/expo/pull/16556#discussion_r822944286\n await this.getProjectRandomnessAsync(),\n // Strip out periods from the username to avoid subdomain issues with SSL certificates.\n slugify(username, { remove: /\\./ }),\n // Use the port to distinguish between multiple tunnels (webpack, metro).\n String(this.port),\n ];\n }\n\n /** Exposed for testing. */\n async _getProjectHostnameAsync(): Promise<string> {\n return `${(await this._getIdentifyingUrlSegmentsAsync()).join('-')}.${NGROK_CONFIG.domain}`;\n }\n\n /** Exposed for testing. */\n async _getProjectSubdomainAsync(): Promise<string> {\n return (await this._getIdentifyingUrlSegmentsAsync()).join('-');\n }\n\n /** Start ngrok on the given port for the project. */\n async startAsync({ timeout }: { timeout?: number } = {}): Promise<void> {\n // Ensure the instance is loaded first, this can linger so we should run it before the timeout.\n await this.resolver.resolveAsync({\n // For now, prefer global install since the package has native code (harder to install) and doesn't change very often.\n prefersGlobalInstall: true,\n });\n\n // NOTE(EvanBacon): If the user doesn't have ADB installed,\n // then skip attempting to reverse the port.\n if (hasAdbReverseAsync()) {\n // Ensure ADB reverse is running.\n if (!(await startAdbReverseAsync([this.port]))) {\n // TODO: Better error message.\n throw new CommandError(\n 'NGROK_ADB',\n `Cannot start tunnel URL because \\`adb reverse\\` failed for the connected Android device(s).`\n );\n }\n }\n\n this.serverUrl = await this._connectToNgrokAsync({ timeout });\n\n debug('Tunnel URL:', this.serverUrl);\n Log.log('Tunnel ready.');\n }\n\n /** Stop the ngrok process if it's running. */\n public async stopAsync(): Promise<void> {\n debug('Stopping Tunnel');\n\n await this.resolver.get()?.kill?.();\n this.serverUrl = null;\n }\n\n /** Exposed for testing. */\n async _connectToNgrokAsync(\n options: { timeout?: number } = {},\n attempts: number = 0\n ): Promise<string> {\n // Attempt to stop any hanging processes, this increases the chances of a successful connection.\n await this.stopAsync();\n\n // Get the instance quietly or assert otherwise.\n const instance = await this.resolver.resolveAsync({\n shouldPrompt: false,\n autoInstall: false,\n });\n\n // TODO(Bacon): Consider dropping the timeout functionality:\n // https://github.com/expo/expo/pull/16556#discussion_r822307373\n const results = await resolveWithTimeout(\n () => this.connectToNgrokInternalAsync(instance, attempts),\n {\n timeout: options.timeout ?? TUNNEL_TIMEOUT,\n errorMessage: 'ngrok tunnel took too long to connect.',\n }\n );\n if (typeof results === 'string') {\n return results;\n }\n\n // Wait 100ms and then try again\n await delayAsync(100);\n\n return this._connectToNgrokAsync(options, attempts + 1);\n }\n\n private async _getConnectionPropsAsync(): Promise<{ hostname?: string; subdomain?: string }> {\n const userDefinedSubdomain = env.EXPO_TUNNEL_SUBDOMAIN;\n if (userDefinedSubdomain) {\n const subdomain =\n typeof userDefinedSubdomain === 'string'\n ? userDefinedSubdomain\n : await this._getProjectSubdomainAsync();\n debug('Subdomain:', subdomain);\n return { subdomain };\n } else {\n const hostname = await this._getProjectHostnameAsync();\n debug('Hostname:', hostname);\n return { hostname };\n }\n }\n\n private async connectToNgrokInternalAsync(\n instance: NgrokInstance,\n attempts: number = 0\n ): Promise<string | false> {\n try {\n // Global config path.\n const configPath = path.join(getSettingsDirectory(), 'ngrok.yml');\n debug('Global config path:', configPath);\n const urlProps = await this._getConnectionPropsAsync();\n\n const url = await instance.connect({\n ...urlProps,\n authtoken: NGROK_CONFIG.authToken,\n configPath,\n onStatusChange(status) {\n if (status === 'closed') {\n Log.error(\n chalk.red(\n 'Tunnel connection has been closed. This is often related to intermittent connection problems with the Ngrok servers. Restart the dev server to try connecting to Ngrok again.'\n ) + chalk.gray('\\nCheck the Ngrok status page for outages: https://status.ngrok.com/')\n );\n } else if (status === 'connected') {\n Log.log('Tunnel connected.');\n }\n },\n port: this.port,\n });\n return url;\n } catch (error: any) {\n const assertNgrok = () => {\n if (isNgrokClientError(error)) {\n throw new CommandError(\n 'NGROK_CONNECT',\n [\n error.body.msg,\n error.body.details?.err,\n chalk.gray('Check the Ngrok status page for outages: https://status.ngrok.com/'),\n ]\n .filter(Boolean)\n .join('\\n\\n')\n );\n }\n throw new CommandError(\n 'NGROK_CONNECT',\n error.toString() +\n chalk.gray('\\nCheck the Ngrok status page for outages: https://status.ngrok.com/')\n );\n };\n\n // Attempt to connect 3 times\n if (attempts >= 2) {\n assertNgrok();\n }\n\n // Attempt to fix the issue\n if (isNgrokClientError(error) && error.body.error_code === 103) {\n // Assert early if a custom subdomain is used since it cannot\n // be changed and retried. If the tunnel subdomain is a boolean\n // then we can reset the randomness and try again.\n if (typeof env.EXPO_TUNNEL_SUBDOMAIN === 'string') {\n assertNgrok();\n }\n // Change randomness to avoid conflict if killing ngrok doesn't help\n await this._resetProjectRandomnessAsync();\n }\n\n return false;\n }\n }\n\n private async getProjectRandomnessAsync() {\n const { urlRandomness: randomness } = await ProjectSettings.readAsync(this.projectRoot);\n if (randomness) {\n return randomness;\n }\n return await this._resetProjectRandomnessAsync();\n }\n\n async _resetProjectRandomnessAsync() {\n const randomness = crypto.randomBytes(5).toString('base64url');\n await ProjectSettings.setAsync(this.projectRoot, { urlRandomness: randomness });\n debug('Resetting project randomness:', randomness);\n return randomness;\n }\n}\n"],"names":["AsyncNgrok","debug","require","NGROK_CONFIG","authToken","domain","TUNNEL_TIMEOUT","constructor","projectRoot","port","serverUrl","resolver","NgrokResolver","getActiveUrl","_getIdentifyingUrlSegmentsAsync","user","getUserAsync","__typename","CommandError","username","getActorDisplayName","getProjectRandomnessAsync","slugify","remove","String","_getProjectHostnameAsync","join","_getProjectSubdomainAsync","startAsync","timeout","resolveAsync","prefersGlobalInstall","hasAdbReverseAsync","startAdbReverseAsync","_connectToNgrokAsync","Log","log","stopAsync","get","kill","options","attempts","instance","shouldPrompt","autoInstall","results","resolveWithTimeout","connectToNgrokInternalAsync","errorMessage","delayAsync","_getConnectionPropsAsync","userDefinedSubdomain","env","EXPO_TUNNEL_SUBDOMAIN","subdomain","hostname","configPath","path","getSettingsDirectory","urlProps","url","connect","authtoken","onStatusChange","status","error","chalk","red","gray","assertNgrok","isNgrokClientError","body","msg","details","err","filter","Boolean","toString","error_code","_resetProjectRandomnessAsync","urlRandomness","randomness","ProjectSettings","readAsync","crypto","randomBytes","setAsync"],"mappings":"AAAA;;;;+BAwBaA,YAAU;;aAAVA,UAAU;;;8DAxBL,OAAO;;;;;;;8DACN,QAAQ;;;;;;;+DACL,MAAM;;;;;;;8DACR,SAAS;;;;;;8BAEQ,6BAA6B;sBAChB,qBAAqB;2DAClD,WAAW;uBACe,mBAAmB;qBAC9C,iBAAiB;wBACR,oBAAoB;+BACgB,+BAA+B;4BACvC,iCAAiC;0BAC1D,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErD,MAAMC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,4BAA4B,GAAG;QACnC,MAAME,UAAU,GAAGG,OAAM,EAAA,QAAA,CAACC,WAAW,CAAC,CAAC,CAAC,CAACR,QAAQ,CAAC,WAAW,CAAC,AAAC;QAC/D,MAAMK,SAAe,gBAAA,CAACI,QAAQ,CAAC,IAAI,CAAC9E,WAAW,EAAE;YAAEwE,aAAa,EAAEC,UAAU;SAAE,CAAC,CAAC;QAChFhF,KAAK,CAAC,+BAA+B,EAAEgF,UAAU,CAAC,CAAC;QACnD,OAAOA,UAAU,CAAC;IACpB;CACD"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/AsyncNgrok.ts"],"sourcesContent":["import chalk from 'chalk';\nimport crypto from 'crypto';\nimport * as path from 'path';\nimport slugify from 'slugify';\n\nimport { getSettingsDirectory } from '../../api/user/UserSettings';\nimport { getActorDisplayName, getUserAsync } from '../../api/user/user';\nimport * as Log from '../../log';\nimport { delayAsync, resolveWithTimeout } from '../../utils/delay';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { isNgrokClientError, NgrokInstance, NgrokResolver } from '../doctor/ngrok/NgrokResolver';\nimport { hasAdbReverseAsync, startAdbReverseAsync } from '../platforms/android/adbReverse';\nimport { ProjectSettings } from '../project/settings';\n\nconst debug = require('debug')('expo:start:server:ngrok') as typeof console.log;\n\nconst NGROK_CONFIG = {\n authToken: '5W1bR67GNbWcXqmxZzBG1_56GezNeaX6sSRvn8npeQ8',\n domain: 'exp.direct',\n};\n\nconst TUNNEL_TIMEOUT = 10 * 1000;\n\nexport class AsyncNgrok {\n /** Resolves the best instance of ngrok, exposed for testing. */\n resolver: NgrokResolver;\n\n /** Info about the currently running instance of ngrok. */\n private serverUrl: string | null = null;\n\n constructor(\n private projectRoot: string,\n private port: number\n ) {\n this.resolver = new NgrokResolver(projectRoot);\n }\n\n public getActiveUrl(): string | null {\n return this.serverUrl;\n }\n\n /** Exposed for testing. */\n async _getIdentifyingUrlSegmentsAsync(): Promise<string[]> {\n const user = await getUserAsync();\n if (user?.__typename === 'Robot') {\n throw new CommandError('NGROK_ROBOT', 'Cannot use ngrok with a robot user.');\n }\n const username = getActorDisplayName(user);\n\n return [\n // NOTE: https://github.com/expo/expo/pull/16556#discussion_r822944286\n await this.getProjectRandomnessAsync(),\n // Strip out periods from the username to avoid subdomain issues with SSL certificates.\n slugify(username, { remove: /\\./ }),\n // Use the port to distinguish between multiple tunnels (webpack, metro).\n String(this.port),\n ];\n }\n\n /** Exposed for testing. */\n async _getProjectHostnameAsync(): Promise<string> {\n return `${(await this._getIdentifyingUrlSegmentsAsync()).join('-')}.${NGROK_CONFIG.domain}`;\n }\n\n /** Exposed for testing. */\n async _getProjectSubdomainAsync(): Promise<string> {\n return (await this._getIdentifyingUrlSegmentsAsync()).join('-');\n }\n\n /** Start ngrok on the given port for the project. */\n async startAsync({ timeout }: { timeout?: number } = {}): Promise<void> {\n // Ensure the instance is loaded first, this can linger so we should run it before the timeout.\n await this.resolver.resolveAsync({\n // For now, prefer global install since the package has native code (harder to install) and doesn't change very often.\n prefersGlobalInstall: true,\n });\n\n // NOTE(EvanBacon): If the user doesn't have ADB installed,\n // then skip attempting to reverse the port.\n if (hasAdbReverseAsync()) {\n // Ensure ADB reverse is running.\n if (!(await startAdbReverseAsync([this.port]))) {\n // TODO: Better error message.\n throw new CommandError(\n 'NGROK_ADB',\n `Cannot start tunnel URL because \\`adb reverse\\` failed for the connected Android device(s).`\n );\n }\n }\n\n this.serverUrl = await this._connectToNgrokAsync({ timeout });\n\n debug('Tunnel URL:', this.serverUrl);\n Log.log('Tunnel ready.');\n }\n\n /** Stop the ngrok process if it's running. */\n public async stopAsync(): Promise<void> {\n debug('Stopping Tunnel');\n\n await this.resolver.get()?.kill?.();\n this.serverUrl = null;\n }\n\n /** Exposed for testing. */\n async _connectToNgrokAsync(\n options: { timeout?: number } = {},\n attempts: number = 0\n ): Promise<string> {\n // Attempt to stop any hanging processes, this increases the chances of a successful connection.\n await this.stopAsync();\n\n // Get the instance quietly or assert otherwise.\n const instance = await this.resolver.resolveAsync({\n shouldPrompt: false,\n autoInstall: false,\n });\n\n // TODO(Bacon): Consider dropping the timeout functionality:\n // https://github.com/expo/expo/pull/16556#discussion_r822307373\n const results = await resolveWithTimeout(\n () => this.connectToNgrokInternalAsync(instance, attempts),\n {\n timeout: options.timeout ?? TUNNEL_TIMEOUT,\n errorMessage: 'ngrok tunnel took too long to connect.',\n }\n );\n if (typeof results === 'string') {\n return results;\n }\n\n // Wait 100ms and then try again\n await delayAsync(100);\n\n return this._connectToNgrokAsync(options, attempts + 1);\n }\n\n private async _getConnectionPropsAsync(): Promise<{ hostname?: string; subdomain?: string }> {\n const userDefinedSubdomain = env.EXPO_TUNNEL_SUBDOMAIN;\n if (userDefinedSubdomain) {\n const subdomain =\n typeof userDefinedSubdomain === 'string'\n ? userDefinedSubdomain\n : await this._getProjectSubdomainAsync();\n debug('Subdomain:', subdomain);\n return { subdomain };\n } else {\n const hostname = await this._getProjectHostnameAsync();\n debug('Hostname:', hostname);\n return { hostname };\n }\n }\n\n private async connectToNgrokInternalAsync(\n instance: NgrokInstance,\n attempts: number = 0\n ): Promise<string | false> {\n try {\n // Global config path.\n const configPath = path.join(getSettingsDirectory(), 'ngrok.yml');\n debug('Global config path:', configPath);\n const urlProps = await this._getConnectionPropsAsync();\n\n const url = await instance.connect({\n ...urlProps,\n authtoken: NGROK_CONFIG.authToken,\n configPath,\n onStatusChange(status) {\n if (status === 'closed') {\n Log.error(\n chalk.red(\n 'Tunnel connection has been closed. This is often related to intermittent connection problems with the Ngrok servers. Restart the dev server to try connecting to Ngrok again.'\n ) + chalk.gray('\\nCheck the Ngrok status page for outages: https://status.ngrok.com/')\n );\n } else if (status === 'connected') {\n Log.log('Tunnel connected.');\n }\n },\n port: this.port,\n });\n return url;\n } catch (error: any) {\n const assertNgrok = () => {\n if (isNgrokClientError(error)) {\n throw new CommandError(\n 'NGROK_CONNECT',\n [\n error.body.msg,\n error.body.details?.err,\n chalk.gray('Check the Ngrok status page for outages: https://status.ngrok.com/'),\n ]\n .filter(Boolean)\n .join('\\n\\n')\n );\n }\n throw new CommandError(\n 'NGROK_CONNECT',\n error.toString() +\n chalk.gray('\\nCheck the Ngrok status page for outages: https://status.ngrok.com/')\n );\n };\n\n // Attempt to connect 3 times\n if (attempts >= 2) {\n assertNgrok();\n }\n\n // Attempt to fix the issue\n if (isNgrokClientError(error) && error.body.error_code === 103) {\n // Assert early if a custom subdomain is used since it cannot\n // be changed and retried. If the tunnel subdomain is a boolean\n // then we can reset the randomness and try again.\n if (typeof env.EXPO_TUNNEL_SUBDOMAIN === 'string') {\n assertNgrok();\n }\n // Change randomness to avoid conflict if killing ngrok doesn't help\n await this._resetProjectRandomnessAsync();\n }\n\n return false;\n }\n }\n\n private async getProjectRandomnessAsync() {\n const { urlRandomness: randomness } = await ProjectSettings.readAsync(this.projectRoot);\n if (randomness && /^[A-Za-z0-9]/.test(randomness)) {\n return randomness;\n }\n return await this._resetProjectRandomnessAsync();\n }\n\n async _resetProjectRandomnessAsync() {\n let randomness: string;\n do {\n randomness = crypto.randomBytes(5).toString('base64url');\n } while (randomness.startsWith('_')); // _ is an invalid character for a hostname\n\n await ProjectSettings.setAsync(this.projectRoot, { urlRandomness: randomness });\n debug('Resetting project randomness:', randomness);\n return randomness;\n }\n}\n"],"names":["AsyncNgrok","debug","require","NGROK_CONFIG","authToken","domain","TUNNEL_TIMEOUT","constructor","projectRoot","port","serverUrl","resolver","NgrokResolver","getActiveUrl","_getIdentifyingUrlSegmentsAsync","user","getUserAsync","__typename","CommandError","username","getActorDisplayName","getProjectRandomnessAsync","slugify","remove","String","_getProjectHostnameAsync","join","_getProjectSubdomainAsync","startAsync","timeout","resolveAsync","prefersGlobalInstall","hasAdbReverseAsync","startAdbReverseAsync","_connectToNgrokAsync","Log","log","stopAsync","get","kill","options","attempts","instance","shouldPrompt","autoInstall","results","resolveWithTimeout","connectToNgrokInternalAsync","errorMessage","delayAsync","_getConnectionPropsAsync","userDefinedSubdomain","env","EXPO_TUNNEL_SUBDOMAIN","subdomain","hostname","configPath","path","getSettingsDirectory","urlProps","url","connect","authtoken","onStatusChange","status","error","chalk","red","gray","assertNgrok","isNgrokClientError","body","msg","details","err","filter","Boolean","toString","error_code","_resetProjectRandomnessAsync","urlRandomness","randomness","ProjectSettings","readAsync","test","crypto","randomBytes","startsWith","setAsync"],"mappings":"AAAA;;;;+BAwBaA,YAAU;;aAAVA,UAAU;;;8DAxBL,OAAO;;;;;;;8DACN,QAAQ;;;;;;;+DACL,MAAM;;;;;;;8DACR,SAAS;;;;;;8BAEQ,6BAA6B;sBAChB,qBAAqB;2DAClD,WAAW;uBACe,mBAAmB;qBAC9C,iBAAiB;wBACR,oBAAoB;+BACgB,+BAA+B;4BACvC,iCAAiC;0BAC1D,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErD,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,AAAsB,AAAC;AAEhF,MAAMC,YAAY,GAAG;IACnBC,SAAS,EAAE,6CAA6C;IACxDC,MAAM,EAAE,YAAY;CACrB,AAAC;AAEF,MAAMC,cAAc,GAAG,EAAE,GAAG,IAAI,AAAC;AAE1B,MAAMN,UAAU;IAOrBO,YACUC,WAAmB,EACnBC,IAAY,CACpB;QAFQD,mBAAAA,WAAmB,CAAA;QACnBC,YAAAA,IAAY,CAAA;aAJdC,SAAS,GAAkB,IAAI;QAMrC,IAAI,CAACC,QAAQ,GAAG,IAAIC,cAAa,cAAA,CAACJ,WAAW,CAAC,CAAC;IACjD;IAEOK,YAAY,GAAkB;QACnC,OAAO,IAAI,CAACH,SAAS,CAAC;IACxB;IAEA,yBAAyB,SACnBI,+BAA+B,GAAsB;QACzD,MAAMC,IAAI,GAAG,MAAMC,IAAAA,KAAY,aAAA,GAAE,AAAC;QAClC,IAAID,CAAAA,IAAI,QAAY,GAAhBA,KAAAA,CAAgB,GAAhBA,IAA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AAK,GAAG,EAAE;gBAC9D,6DAA6D;gBAC7D,+DAA+D;gBAC/D,kDAAkD;gBAClD,IAAI,OAAO1B,IAAG,IAAA,CAACC,qBAAqB,KAAK,QAAQ,EAAE;oBACjDgB,WAAW,EAAE,CAAC;gBAChB,CAAC;gBACD,oEAAoE;gBACpE,MAAM,IAAI,CAACU,4BAA4B,EAAE,CAAC;YAC5C,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;IACH;UAEc1D,yBAAyB,GAAG;QACxC,MAAM,EAAE2D,aAAa,EAAEC,UAAU,CAAA,EAAE,GAAG,MAAMC,SAAe,gBAAA,CAACC,SAAS,CAAC,IAAI,CAAC3E,WAAW,CAAC,AAAC;QACxF,IAAIyE,UAAU,IAAI,eAAeG,IAAI,CAACH,UAAU,CAAC,EAAE;YACjD,OAAOA,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,MAAM,IAAI,CAACF,4BAA4B,EAAE,CAAC;IACnD;UAEMA,4BAA4B,GAAG;QACnC,IAAIE,UAAU,AAAQ,AAAC;QACvB,GAAG;YACDA,UAAU,GAAGI,OAAM,EAAA,QAAA,CAACC,WAAW,CAAC,CAAC,CAAC,CAACT,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC3D,QAASI,UAAU,CAACM,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,2CAA2C;QAEjF,MAAML,SAAe,gBAAA,CAACM,QAAQ,CAAC,IAAI,CAAChF,WAAW,EAAE;YAAEwE,aAAa,EAAEC,UAAU;SAAE,CAAC,CAAC;QAChFhF,KAAK,CAAC,+BAA+B,EAAEgF,UAAU,CAAC,CAAC;QACnD,OAAOA,UAAU,CAAC;IACpB;CACD"}
|
|
@@ -523,13 +523,13 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
523
523
|
}
|
|
524
524
|
async singlePageReactServerComponentExportAsync(options, files, extraOptions = {}) {
|
|
525
525
|
// NOTE(EvanBacon): This will not support any code elimination since it's a static pass.
|
|
526
|
-
|
|
526
|
+
let { reactClientReferences: clientBoundaries , reactServerReferences: serverActionReferencesInServer , cssModules , } = await this.rscRenderer.getExpoRouterClientReferencesAsync({
|
|
527
527
|
platform: options.platform
|
|
528
528
|
}, files);
|
|
529
529
|
// TODO: The output keys should be in production format or use a lookup manifest.
|
|
530
530
|
debug("Evaluated client boundaries:", clientBoundaries);
|
|
531
531
|
// Run metro bundler and create the JS bundles/source maps.
|
|
532
|
-
|
|
532
|
+
let bundle = await this.legacySinglePageExportBundleAsync({
|
|
533
533
|
...options,
|
|
534
534
|
clientBoundaries
|
|
535
535
|
}, extraOptions);
|
|
@@ -544,13 +544,30 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
544
544
|
throw new Error("Static server action references were not returned from the Metro client bundle");
|
|
545
545
|
}
|
|
546
546
|
debug("React server action boundaries from client:", reactServerReferences);
|
|
547
|
-
|
|
547
|
+
// When we export the server actions that were imported from the client, we may need to re-bundle the client with the new client boundaries.
|
|
548
|
+
const { clientBoundaries: nestedClientBoundaries } = await this.rscRenderer.exportServerActionsAsync({
|
|
548
549
|
platform: options.platform,
|
|
549
550
|
entryPoints: [
|
|
550
551
|
...serverActionReferencesInServer,
|
|
551
552
|
...reactServerReferences
|
|
552
553
|
]
|
|
553
554
|
}, files);
|
|
555
|
+
const hasUniqueClientBoundaries = nestedClientBoundaries.some((boundary)=>!clientBoundaries.includes(boundary));
|
|
556
|
+
if (hasUniqueClientBoundaries) {
|
|
557
|
+
debug("Re-bundling client with nested client boundaries:", nestedClientBoundaries);
|
|
558
|
+
clientBoundaries = [
|
|
559
|
+
...new Set(clientBoundaries.concat(nestedClientBoundaries))
|
|
560
|
+
];
|
|
561
|
+
// Re-bundle the client with the new client boundaries that only exist in server actions that were imported from the client.
|
|
562
|
+
// Run metro bundler and create the JS bundles/source maps.
|
|
563
|
+
bundle = await this.legacySinglePageExportBundleAsync({
|
|
564
|
+
...options,
|
|
565
|
+
clientBoundaries: [
|
|
566
|
+
...clientBoundaries,
|
|
567
|
+
...nestedClientBoundaries
|
|
568
|
+
]
|
|
569
|
+
}, extraOptions);
|
|
570
|
+
}
|
|
554
571
|
// Inject the global CSS that was imported during the server render.
|
|
555
572
|
bundle.artifacts.push(...cssModules);
|
|
556
573
|
const serverRoot = (0, _paths().getMetroServerRoot)(this.projectRoot);
|
|
@@ -651,7 +668,7 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
651
668
|
}
|
|
652
669
|
rscRenderer = null;
|
|
653
670
|
async startImplementationAsync(options) {
|
|
654
|
-
var ref, ref1, ref2, ref3;
|
|
671
|
+
var ref, ref1, ref2, ref3, ref4, ref5, ref6;
|
|
655
672
|
options.port = await this.resolvePortAsync(options);
|
|
656
673
|
this.urlCreator = this.getUrlCreator(options);
|
|
657
674
|
const config = (0, _config().getConfig)(this.projectRoot, {
|
|
@@ -659,17 +676,18 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
659
676
|
});
|
|
660
677
|
const { exp } = config;
|
|
661
678
|
// NOTE: This will change in the future when it's less experimental, we enable React 19, and turn on more RSC flags by default.
|
|
662
|
-
const isReactServerComponentsEnabled = !!((ref = exp.experiments) == null ? void 0 : ref.reactServerComponents);
|
|
679
|
+
const isReactServerComponentsEnabled = !!((ref = exp.experiments) == null ? void 0 : ref.reactServerComponents) || !!((ref1 = exp.experiments) == null ? void 0 : ref1.reactServerActions);
|
|
680
|
+
const isReactServerActionsOnlyEnabled = !((ref2 = exp.experiments) == null ? void 0 : ref2.reactServerComponents) && !!((ref3 = exp.experiments) == null ? void 0 : ref3.reactServerActions);
|
|
663
681
|
this.isReactServerComponentsEnabled = isReactServerComponentsEnabled;
|
|
664
682
|
const useServerRendering = [
|
|
665
683
|
"static",
|
|
666
684
|
"server"
|
|
667
|
-
].includes(((
|
|
668
|
-
const hasApiRoutes = isReactServerComponentsEnabled || ((
|
|
685
|
+
].includes(((ref4 = exp.web) == null ? void 0 : ref4.output) ?? "");
|
|
686
|
+
const hasApiRoutes = isReactServerComponentsEnabled || ((ref5 = exp.web) == null ? void 0 : ref5.output) === "server";
|
|
669
687
|
const baseUrl = (0, _metroOptions.getBaseUrlFromExpoConfig)(exp);
|
|
670
688
|
const asyncRoutes = (0, _metroOptions.getAsyncRoutesFromExpoConfig)(exp, options.mode ?? "development", "web");
|
|
671
689
|
const routerRoot = (0, _router.getRouterDirectoryModuleIdWithManifest)(this.projectRoot, exp);
|
|
672
|
-
const reactCompiler = !!((
|
|
690
|
+
const reactCompiler = !!((ref6 = exp.experiments) == null ? void 0 : ref6.reactCompiler);
|
|
673
691
|
const appDir = _path().default.join(this.projectRoot, routerRoot);
|
|
674
692
|
const mode = options.mode ?? "development";
|
|
675
693
|
if (isReactServerComponentsEnabled && useServerRendering) {
|
|
@@ -775,7 +793,8 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
775
793
|
instanceMetroOptions: this.instanceMetroOptions,
|
|
776
794
|
rscPath: "/_flight",
|
|
777
795
|
ssrLoadModule: this.ssrLoadModule.bind(this),
|
|
778
|
-
ssrLoadModuleArtifacts: this.metroImportAsArtifactsAsync.bind(this)
|
|
796
|
+
ssrLoadModuleArtifacts: this.metroImportAsArtifactsAsync.bind(this),
|
|
797
|
+
useClientRouter: isReactServerActionsOnlyEnabled
|
|
779
798
|
});
|
|
780
799
|
this.rscRenderer = rscMiddleware;
|
|
781
800
|
middleware.use(rscMiddleware.middleware);
|
|
@@ -787,12 +806,12 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
787
806
|
// This MUST run last since it's the fallback.
|
|
788
807
|
middleware.use(new _historyFallbackMiddleware.HistoryFallbackMiddleware(manifestMiddleware.getHandler().internal).getHandler());
|
|
789
808
|
} else {
|
|
790
|
-
var
|
|
809
|
+
var ref7;
|
|
791
810
|
middleware.use((0, _createServerRouteMiddleware.createRouteHandlerMiddleware)(this.projectRoot, {
|
|
792
811
|
appDir,
|
|
793
812
|
routerRoot,
|
|
794
813
|
config,
|
|
795
|
-
...(
|
|
814
|
+
...(ref7 = config.exp.extra) == null ? void 0 : ref7.router,
|
|
796
815
|
bundleApiRoute: (functionFilePath)=>this.ssrImportApiRoute(functionFilePath, {
|
|
797
816
|
platform: "web"
|
|
798
817
|
}),
|
|
@@ -810,7 +829,8 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
810
829
|
instanceMetroOptions: this.instanceMetroOptions,
|
|
811
830
|
rscPath: "/_flight",
|
|
812
831
|
ssrLoadModule: this.ssrLoadModule.bind(this),
|
|
813
|
-
ssrLoadModuleArtifacts: this.metroImportAsArtifactsAsync.bind(this)
|
|
832
|
+
ssrLoadModuleArtifacts: this.metroImportAsArtifactsAsync.bind(this),
|
|
833
|
+
useClientRouter: isReactServerActionsOnlyEnabled
|
|
814
834
|
});
|
|
815
835
|
this.rscRenderer = rscMiddleware1;
|
|
816
836
|
}
|