@expo/cli 56.1.5 → 56.1.7
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/api/rest/client.js +27 -12
- package/build/src/api/rest/client.js.map +1 -1
- package/build/src/api/user/UserSettings.js +17 -4
- package/build/src/api/user/UserSettings.js.map +1 -1
- package/build/src/events/index.js +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +3 -3
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/embed/exportServer.js +1 -1
- package/build/src/export/embed/exportServer.js.map +1 -1
- package/build/src/export/exportApp.js +1 -1
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/publicFolder.js +19 -1
- package/build/src/export/publicFolder.js.map +1 -1
- package/build/src/install/utils/checkPackagesCompatibility.js +32 -16
- package/build/src/install/utils/checkPackagesCompatibility.js.map +1 -1
- package/build/src/login/index.js +25 -5
- package/build/src/login/index.js.map +1 -1
- package/build/src/prebuild/resolveTemplate.js +10 -5
- package/build/src/prebuild/resolveTemplate.js.map +1 -1
- package/build/src/run/android/resolveLaunchProps.js +4 -1
- package/build/src/run/android/resolveLaunchProps.js.map +1 -1
- package/build/src/start/doctor/dependencies/reactNativeTv.js +149 -0
- package/build/src/start/doctor/dependencies/reactNativeTv.js.map +1 -0
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js +28 -3
- package/build/src/start/doctor/dependencies/validateDependenciesVersions.js.map +1 -1
- package/build/src/start/platforms/AppIdResolver.js +4 -0
- package/build/src/start/platforms/AppIdResolver.js.map +1 -1
- package/build/src/start/platforms/android/adb.js +16 -15
- package/build/src/start/platforms/android/adb.js.map +1 -1
- package/build/src/start/server/DevToolsPlugin.js +26 -1
- package/build/src/start/server/DevToolsPlugin.js.map +1 -1
- package/build/src/start/server/DevToolsPluginCliExtensionExecutor.js +57 -22
- package/build/src/start/server/DevToolsPluginCliExtensionExecutor.js.map +1 -1
- package/build/src/start/server/DevToolsPluginCliExtensionResults.js +29 -0
- package/build/src/start/server/DevToolsPluginCliExtensionResults.js.map +1 -1
- package/build/src/start/server/MCPDevToolsPluginCLIExtensions.js +15 -5
- package/build/src/start/server/MCPDevToolsPluginCLIExtensions.js.map +1 -1
- package/build/src/start/server/UrlCreator.js +14 -1
- package/build/src/start/server/UrlCreator.js.map +1 -1
- package/build/src/start/server/createMCPDevToolsExtensionSchema.js +13 -1
- package/build/src/start/server/createMCPDevToolsExtensionSchema.js.map +1 -1
- package/build/src/start/server/getStaticRenderFunctions.js +2 -1
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +44 -0
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/createServerComponentsMiddleware.js +13 -13
- package/build/src/start/server/metro/createServerComponentsMiddleware.js.map +1 -1
- package/build/src/start/server/metro/debugging/createDebugMiddleware.js +5 -4
- package/build/src/start/server/metro/debugging/createDebugMiddleware.js.map +1 -1
- package/build/src/start/server/metro/debugging/messageHandlers/NetworkResponse.js +17 -1
- package/build/src/start/server/metro/debugging/messageHandlers/NetworkResponse.js.map +1 -1
- package/build/src/start/server/metro/dev-server/createMessageSocket.js +13 -2
- package/build/src/start/server/metro/dev-server/createMessageSocket.js.map +1 -1
- package/build/src/start/server/metro/dev-server/createMetroMiddleware.js +9 -2
- package/build/src/start/server/metro/dev-server/createMetroMiddleware.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +8 -5
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +5 -2
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/router.js +10 -1
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +8 -0
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js +7 -4
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/OpenMiddleware.js +150 -0
- package/build/src/start/server/middleware/OpenMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js +13 -4
- package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/ServeStaticMiddleware.js +2 -9
- package/build/src/start/server/middleware/ServeStaticMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js +14 -24
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/openHandlers.js +157 -0
- package/build/src/start/server/middleware/openHandlers.js.map +1 -0
- package/build/src/start/server/webTemplate.js +3 -5
- package/build/src/start/server/webTemplate.js.map +1 -1
- package/build/src/utils/codesigning.js +6 -0
- package/build/src/utils/codesigning.js.map +1 -1
- package/build/src/utils/env.js +29 -6
- package/build/src/utils/env.js.map +1 -1
- package/build/src/utils/net.js +20 -1
- package/build/src/utils/net.js.map +1 -1
- package/build/src/utils/open.js +2 -5
- package/build/src/utils/open.js.map +1 -1
- package/build/src/utils/tar.js +2 -2
- package/build/src/utils/tar.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/build/src/utils/url.js +0 -12
- package/build/src/utils/url.js.map +1 -1
- package/package.json +22 -22
- package/static/loading-page/index.html +10 -2
package/build/bin/cli
CHANGED
|
@@ -84,20 +84,23 @@ function getResponseDataOrThrow(json) {
|
|
|
84
84
|
}
|
|
85
85
|
throw new UnexpectedServerData(!!json && typeof json === 'object' ? JSON.stringify(json) : 'Unknown data received from server.');
|
|
86
86
|
}
|
|
87
|
-
function wrapFetchWithCredentials(fetchFunction) {
|
|
87
|
+
function wrapFetchWithCredentials(fetchFunction, expoApiBaseUrl) {
|
|
88
|
+
const expoApiOrigin = new URL(expoApiBaseUrl).origin;
|
|
88
89
|
return async function fetchWithCredentials(url, options = {}) {
|
|
89
90
|
if (Array.isArray(options.headers)) {
|
|
90
91
|
throw new Error('request headers must be in object form');
|
|
91
92
|
}
|
|
92
93
|
const resolvedHeaders = options.headers ?? {};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
if (isExpoApiUrl(url, expoApiBaseUrl, expoApiOrigin)) {
|
|
95
|
+
const token = (0, _UserSettings.getAccessToken)();
|
|
96
|
+
if (token) {
|
|
97
|
+
resolvedHeaders.authorization = `Bearer ${token}`;
|
|
98
|
+
} else {
|
|
99
|
+
var _getSession;
|
|
100
|
+
const sessionSecret = (_getSession = (0, _UserSettings.getSession)()) == null ? void 0 : _getSession.sessionSecret;
|
|
101
|
+
if (sessionSecret) {
|
|
102
|
+
resolvedHeaders['expo-session'] = sessionSecret;
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
try {
|
|
@@ -133,6 +136,17 @@ function wrapFetchWithCredentials(fetchFunction) {
|
|
|
133
136
|
}
|
|
134
137
|
};
|
|
135
138
|
}
|
|
139
|
+
function isExpoApiUrl(url, expoApiBaseUrl, expoApiOrigin) {
|
|
140
|
+
if (typeof url !== 'string') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
// Relative URLs resolve against the Expo API base, so they always match the Expo origin.
|
|
145
|
+
return new URL(url, expoApiBaseUrl).origin === expoApiOrigin;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
136
150
|
/**
|
|
137
151
|
* Determine if the provided error is related to a network issue.
|
|
138
152
|
* When this returns true, offline mode should be enabled.
|
|
@@ -150,8 +164,9 @@ function wrapFetchWithCredentials(fetchFunction) {
|
|
|
150
164
|
].includes(error.code);
|
|
151
165
|
}
|
|
152
166
|
const fetchWithOffline = (0, _wrapFetchWithOffline.wrapFetchWithOffline)((0, _wrapFetchWithUserAgent.wrapFetchWithUserAgent)(_fetch.fetch));
|
|
153
|
-
const
|
|
154
|
-
const
|
|
167
|
+
const expoApiBaseUrl = (0, _endpoint.getExpoApiBaseUrl)() + '/v2/';
|
|
168
|
+
const fetchWithBaseUrl = (0, _wrapFetchWithBaseUrl.wrapFetchWithBaseUrl)(fetchWithOffline, expoApiBaseUrl);
|
|
169
|
+
const fetchWithCredentials = (0, _wrapFetchWithProgress.wrapFetchWithProgress)(wrapFetchWithCredentials(fetchWithBaseUrl, expoApiBaseUrl));
|
|
155
170
|
function createCachedFetch({ fetch = fetchWithCredentials, cacheDirectory, ttl, skipCache }) {
|
|
156
171
|
// Disable all caching in EXPO_BETA.
|
|
157
172
|
if (skipCache || _env.env.EXPO_BETA || _env.env.EXPO_NO_CACHE) {
|
|
@@ -163,6 +178,6 @@ function createCachedFetch({ fetch = fetchWithCredentials, cacheDirectory, ttl,
|
|
|
163
178
|
ttl
|
|
164
179
|
}));
|
|
165
180
|
}
|
|
166
|
-
const fetchAsync = (0, _wrapFetchWithProgress.wrapFetchWithProgress)(wrapFetchWithCredentials(fetchWithBaseUrl));
|
|
181
|
+
const fetchAsync = (0, _wrapFetchWithProgress.wrapFetchWithProgress)(wrapFetchWithCredentials(fetchWithBaseUrl, expoApiBaseUrl));
|
|
167
182
|
|
|
168
183
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/rest/client.ts"],"sourcesContent":["import type { JSONValue } from '@expo/json-file';\nimport path from 'path';\n\nimport { wrapFetchWithCache } from './cache/wrapFetchWithCache';\nimport type { FetchLike } from './client.types';\nimport { wrapFetchWithBaseUrl } from './wrapFetchWithBaseUrl';\nimport { wrapFetchWithOffline } from './wrapFetchWithOffline';\nimport { wrapFetchWithProgress } from './wrapFetchWithProgress';\nimport { wrapFetchWithUserAgent } from './wrapFetchWithUserAgent';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { fetch } from '../../utils/fetch';\nimport { getExpoApiBaseUrl } from '../endpoint';\nimport { disableNetwork } from '../settings';\nimport { getAccessToken, getExpoHomeDirectory, getSession } from '../user/UserSettings';\n\nexport class ApiV2Error extends Error {\n readonly name = 'ApiV2Error';\n readonly code: string;\n readonly expoApiV2ErrorCode: string;\n readonly expoApiV2ErrorDetails?: JSONValue;\n readonly expoApiV2ErrorServerStack?: string;\n readonly expoApiV2ErrorMetadata?: object;\n readonly expoApiV2RequestId?: string;\n\n constructor(response: {\n message: string;\n code: string;\n stack?: string;\n details?: JSONValue;\n metadata?: object;\n requestId: string;\n }) {\n super(response.message);\n this.code = response.code;\n this.expoApiV2ErrorCode = response.code;\n this.expoApiV2ErrorDetails = response.details;\n this.expoApiV2ErrorServerStack = response.stack;\n this.expoApiV2ErrorMetadata = response.metadata;\n this.expoApiV2RequestId = response.requestId;\n }\n\n toString() {\n return `${super.toString()}${env.EXPO_DEBUG && this.expoApiV2RequestId ? ` (Request Id: ${this.expoApiV2RequestId})` : ''}`;\n }\n}\n\n/**\n * An Expo server error that didn't return the expected error JSON information.\n * The only 'expected' place for this is in testing, all other cases are bugs with the server.\n */\nexport class UnexpectedServerError extends Error {\n readonly name = 'UnexpectedServerError';\n}\n\n/**\n * An error defining that the server didn't return the expected error JSON information.\n * The only 'expected' place for this is in testing, all other cases are bugs with the client.\n */\nexport class UnexpectedServerData extends Error {\n readonly name = 'UnexpectedServerData';\n}\n\n/** Validate the response json contains `.data` property, or throw an unexpected server data error */\nexport function getResponseDataOrThrow<T = any>(json: unknown): T {\n if (!!json && typeof json === 'object' && 'data' in json) {\n return json.data as T;\n }\n\n throw new UnexpectedServerData(\n !!json && typeof json === 'object' ? JSON.stringify(json) : 'Unknown data received from server.'\n );\n}\n\n/**\n * @returns a `fetch` function that will inject user authentication information and handle errors from the Expo API.\n */\nexport function wrapFetchWithCredentials(fetchFunction: FetchLike): FetchLike {\n return async function fetchWithCredentials(url, options = {}) {\n if (Array.isArray(options.headers)) {\n throw new Error('request headers must be in object form');\n }\n\n const resolvedHeaders = options.headers ?? ({} as any);\n\n const token = getAccessToken();\n if (token) {\n resolvedHeaders.authorization = `Bearer ${token}`;\n } else {\n const sessionSecret = getSession()?.sessionSecret;\n if (sessionSecret) {\n resolvedHeaders['expo-session'] = sessionSecret;\n }\n }\n\n try {\n const response = await fetchFunction(url, {\n ...options,\n headers: resolvedHeaders,\n });\n\n // Handle expected API errors (4xx)\n if (response.status >= 400 && response.status < 500) {\n const body = await response.text();\n try {\n const data = JSON.parse(body);\n if (data?.errors?.length) {\n throw new ApiV2Error(data.errors[0]);\n }\n } catch (error: any) {\n // Server returned non-json response.\n if (error.message.includes('in JSON at position')) {\n throw new UnexpectedServerError(body);\n }\n throw error;\n }\n }\n\n return response;\n } catch (error: any) {\n // When running `expo start`, but wifi or internet has issues\n if (isNetworkError(error) || ('cause' in error && isNetworkError(error.cause))) {\n disableNetwork();\n\n throw new CommandError(\n 'OFFLINE',\n 'Network connection is unreliable. Try again with the environment variable `EXPO_OFFLINE=1` to skip network requests.'\n );\n }\n\n throw error;\n }\n };\n}\n\n/**\n * Determine if the provided error is related to a network issue.\n * When this returns true, offline mode should be enabled.\n * - `ENOTFOUND` is thrown when the DNS lookup failed\n * - `EAI_AGAIN` is thrown when DNS lookup failed due to a server-side error\n * - `UND_ERR_CONNECT_TIMEOUT` is thrown after DNS is resolved, but server can't be reached\n *\n * @see https://nodejs.org/api/errors.html\n * @see https://github.com/nodejs/undici#network-address-family-autoselection\n */\nfunction isNetworkError(error: Error & { code?: string }) {\n return (\n 'code' in error &&\n error.code &&\n ['ENOTFOUND', 'EAI_AGAIN', 'UND_ERR_CONNECT_TIMEOUT'].includes(error.code)\n );\n}\n\nconst fetchWithOffline = wrapFetchWithOffline(wrapFetchWithUserAgent(fetch));\n\nconst fetchWithBaseUrl = wrapFetchWithBaseUrl(fetchWithOffline, getExpoApiBaseUrl() + '/v2/');\n\nconst fetchWithCredentials = wrapFetchWithProgress(wrapFetchWithCredentials(fetchWithBaseUrl));\n\n/**\n * Create an instance of the fully qualified fetch command (auto authentication and api) but with caching in the '~/.expo' directory.\n * Caching is disabled automatically if the EXPO_NO_CACHE or EXPO_BETA environment variables are enabled.\n */\nexport function createCachedFetch({\n fetch = fetchWithCredentials,\n cacheDirectory,\n ttl,\n skipCache,\n}: {\n fetch?: FetchLike;\n cacheDirectory: string;\n ttl?: number;\n skipCache?: boolean;\n}): FetchLike {\n // Disable all caching in EXPO_BETA.\n if (skipCache || env.EXPO_BETA || env.EXPO_NO_CACHE) {\n return fetch;\n }\n\n const { FileSystemResponseCache } =\n require('./cache/FileSystemResponseCache') as typeof import('./cache/FileSystemResponseCache');\n\n return wrapFetchWithCache(\n fetch,\n new FileSystemResponseCache({\n cacheDirectory: path.join(getExpoHomeDirectory(), cacheDirectory),\n ttl,\n })\n );\n}\n\n/** Instance of fetch with automatic base URL pointing to the Expo API, user credential injection, and API error handling. Caching not included. */\nexport const fetchAsync = wrapFetchWithProgress(wrapFetchWithCredentials(fetchWithBaseUrl));\n"],"names":["ApiV2Error","UnexpectedServerData","UnexpectedServerError","createCachedFetch","fetchAsync","getResponseDataOrThrow","wrapFetchWithCredentials","Error","response","message","name","code","expoApiV2ErrorCode","expoApiV2ErrorDetails","details","expoApiV2ErrorServerStack","stack","expoApiV2ErrorMetadata","metadata","expoApiV2RequestId","requestId","toString","env","EXPO_DEBUG","json","data","JSON","stringify","fetchFunction","fetchWithCredentials","url","options","Array","isArray","headers","resolvedHeaders","token","getAccessToken","authorization","getSession","sessionSecret","status","body","text","parse","errors","length","error","includes","isNetworkError","cause","disableNetwork","CommandError","fetchWithOffline","wrapFetchWithOffline","wrapFetchWithUserAgent","fetch","fetchWithBaseUrl","wrapFetchWithBaseUrl","getExpoApiBaseUrl","wrapFetchWithProgress","cacheDirectory","ttl","skipCache","EXPO_BETA","EXPO_NO_CACHE","FileSyst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;;;;CASC,GACD,SAASE,eAAeF,KAAgC;IACtD,OACE,UAAUA,SACVA,MAAMpC,IAAI,IACV;QAAC;QAAa;QAAa;KAA0B,CAACqC,QAAQ,CAACD,MAAMpC,IAAI;AAE7E;AAEA,MAAM0C,mBAAmBC,IAAAA,0CAAoB,EAACC,IAAAA,8CAAsB,EAACC,YAAK;AAE1E,MAAMC,mBAAmBC,IAAAA,0CAAoB,EAACL,kBAAkBM,IAAAA,2BAAiB,MAAK;AAEtF,MAAM9B,uBAAuB+B,IAAAA,4CAAqB,EAACtD,yBAAyBmD;AAMrE,SAAStD,kBAAkB,EAChCqD,QAAQ3B,oBAAoB,EAC5BgC,cAAc,EACdC,GAAG,EACHC,SAAS,EAMV;IACC,oCAAoC;IACpC,IAAIA,aAAazC,QAAG,CAAC0C,SAAS,IAAI1C,QAAG,CAAC2C,aAAa,EAAE;QACnD,OAAOT;IACT;IAEA,MAAM,EAAEU,uBAAuB,EAAE,GAC/BC,QAAQ;IAEV,OAAOC,IAAAA,sCAAkB,EACvBZ,OACA,IAAIU,wBAAwB;QAC1BL,gBAAgBQ,eAAI,CAACC,IAAI,CAACC,IAAAA,kCAAoB,KAAIV;QAClDC;IACF;AAEJ;AAGO,MAAM1D,aAAawD,IAAAA,4CAAqB,EAACtD,yBAAyBmD"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/rest/client.ts"],"sourcesContent":["import type { JSONValue } from '@expo/json-file';\nimport path from 'path';\n\nimport { wrapFetchWithCache } from './cache/wrapFetchWithCache';\nimport type { FetchLike } from './client.types';\nimport { wrapFetchWithBaseUrl } from './wrapFetchWithBaseUrl';\nimport { wrapFetchWithOffline } from './wrapFetchWithOffline';\nimport { wrapFetchWithProgress } from './wrapFetchWithProgress';\nimport { wrapFetchWithUserAgent } from './wrapFetchWithUserAgent';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { fetch } from '../../utils/fetch';\nimport { getExpoApiBaseUrl } from '../endpoint';\nimport { disableNetwork } from '../settings';\nimport { getAccessToken, getExpoHomeDirectory, getSession } from '../user/UserSettings';\n\nexport class ApiV2Error extends Error {\n readonly name = 'ApiV2Error';\n readonly code: string;\n readonly expoApiV2ErrorCode: string;\n readonly expoApiV2ErrorDetails?: JSONValue;\n readonly expoApiV2ErrorServerStack?: string;\n readonly expoApiV2ErrorMetadata?: object;\n readonly expoApiV2RequestId?: string;\n\n constructor(response: {\n message: string;\n code: string;\n stack?: string;\n details?: JSONValue;\n metadata?: object;\n requestId: string;\n }) {\n super(response.message);\n this.code = response.code;\n this.expoApiV2ErrorCode = response.code;\n this.expoApiV2ErrorDetails = response.details;\n this.expoApiV2ErrorServerStack = response.stack;\n this.expoApiV2ErrorMetadata = response.metadata;\n this.expoApiV2RequestId = response.requestId;\n }\n\n toString() {\n return `${super.toString()}${env.EXPO_DEBUG && this.expoApiV2RequestId ? ` (Request Id: ${this.expoApiV2RequestId})` : ''}`;\n }\n}\n\n/**\n * An Expo server error that didn't return the expected error JSON information.\n * The only 'expected' place for this is in testing, all other cases are bugs with the server.\n */\nexport class UnexpectedServerError extends Error {\n readonly name = 'UnexpectedServerError';\n}\n\n/**\n * An error defining that the server didn't return the expected error JSON information.\n * The only 'expected' place for this is in testing, all other cases are bugs with the client.\n */\nexport class UnexpectedServerData extends Error {\n readonly name = 'UnexpectedServerData';\n}\n\n/** Validate the response json contains `.data` property, or throw an unexpected server data error */\nexport function getResponseDataOrThrow<T = any>(json: unknown): T {\n if (!!json && typeof json === 'object' && 'data' in json) {\n return json.data as T;\n }\n\n throw new UnexpectedServerData(\n !!json && typeof json === 'object' ? JSON.stringify(json) : 'Unknown data received from server.'\n );\n}\n\n/**\n * @returns a `fetch` function that will inject user authentication information and handle errors from the Expo API.\n *\n * Credentials are only attached to requests targeting `expoApiBaseUrl`'s origin (including relative\n * URLs, which the downstream base-URL wrapper resolves against the Expo API). Absolute URLs to any\n * other host pass through without Expo credentials.\n */\nexport function wrapFetchWithCredentials(\n fetchFunction: FetchLike,\n expoApiBaseUrl: string\n): FetchLike {\n const expoApiOrigin = new URL(expoApiBaseUrl).origin;\n\n return async function fetchWithCredentials(url, options = {}) {\n if (Array.isArray(options.headers)) {\n throw new Error('request headers must be in object form');\n }\n\n const resolvedHeaders = options.headers ?? ({} as any);\n\n if (isExpoApiUrl(url, expoApiBaseUrl, expoApiOrigin)) {\n const token = getAccessToken();\n if (token) {\n resolvedHeaders.authorization = `Bearer ${token}`;\n } else {\n const sessionSecret = getSession()?.sessionSecret;\n if (sessionSecret) {\n resolvedHeaders['expo-session'] = sessionSecret;\n }\n }\n }\n\n try {\n const response = await fetchFunction(url, {\n ...options,\n headers: resolvedHeaders,\n });\n\n // Handle expected API errors (4xx)\n if (response.status >= 400 && response.status < 500) {\n const body = await response.text();\n try {\n const data = JSON.parse(body);\n if (data?.errors?.length) {\n throw new ApiV2Error(data.errors[0]);\n }\n } catch (error: any) {\n // Server returned non-json response.\n if (error.message.includes('in JSON at position')) {\n throw new UnexpectedServerError(body);\n }\n throw error;\n }\n }\n\n return response;\n } catch (error: any) {\n // When running `expo start`, but wifi or internet has issues\n if (isNetworkError(error) || ('cause' in error && isNetworkError(error.cause))) {\n disableNetwork();\n\n throw new CommandError(\n 'OFFLINE',\n 'Network connection is unreliable. Try again with the environment variable `EXPO_OFFLINE=1` to skip network requests.'\n );\n }\n\n throw error;\n }\n };\n}\n\nfunction isExpoApiUrl(url: unknown, expoApiBaseUrl: string, expoApiOrigin: string): boolean {\n if (typeof url !== 'string') {\n return false;\n }\n try {\n // Relative URLs resolve against the Expo API base, so they always match the Expo origin.\n return new URL(url, expoApiBaseUrl).origin === expoApiOrigin;\n } catch {\n return false;\n }\n}\n\n/**\n * Determine if the provided error is related to a network issue.\n * When this returns true, offline mode should be enabled.\n * - `ENOTFOUND` is thrown when the DNS lookup failed\n * - `EAI_AGAIN` is thrown when DNS lookup failed due to a server-side error\n * - `UND_ERR_CONNECT_TIMEOUT` is thrown after DNS is resolved, but server can't be reached\n *\n * @see https://nodejs.org/api/errors.html\n * @see https://github.com/nodejs/undici#network-address-family-autoselection\n */\nfunction isNetworkError(error: Error & { code?: string }) {\n return (\n 'code' in error &&\n error.code &&\n ['ENOTFOUND', 'EAI_AGAIN', 'UND_ERR_CONNECT_TIMEOUT'].includes(error.code)\n );\n}\n\nconst fetchWithOffline = wrapFetchWithOffline(wrapFetchWithUserAgent(fetch));\n\nconst expoApiBaseUrl = getExpoApiBaseUrl() + '/v2/';\n\nconst fetchWithBaseUrl = wrapFetchWithBaseUrl(fetchWithOffline, expoApiBaseUrl);\n\nconst fetchWithCredentials = wrapFetchWithProgress(\n wrapFetchWithCredentials(fetchWithBaseUrl, expoApiBaseUrl)\n);\n\n/**\n * Create an instance of the fully qualified fetch command (auto authentication and api) but with caching in the '~/.expo' directory.\n * Caching is disabled automatically if the EXPO_NO_CACHE or EXPO_BETA environment variables are enabled.\n */\nexport function createCachedFetch({\n fetch = fetchWithCredentials,\n cacheDirectory,\n ttl,\n skipCache,\n}: {\n fetch?: FetchLike;\n cacheDirectory: string;\n ttl?: number;\n skipCache?: boolean;\n}): FetchLike {\n // Disable all caching in EXPO_BETA.\n if (skipCache || env.EXPO_BETA || env.EXPO_NO_CACHE) {\n return fetch;\n }\n\n const { FileSystemResponseCache } =\n require('./cache/FileSystemResponseCache') as typeof import('./cache/FileSystemResponseCache');\n\n return wrapFetchWithCache(\n fetch,\n new FileSystemResponseCache({\n cacheDirectory: path.join(getExpoHomeDirectory(), cacheDirectory),\n ttl,\n })\n );\n}\n\n/** Instance of fetch with automatic base URL pointing to the Expo API, user credential injection, and API error handling. Caching not included. */\nexport const fetchAsync = wrapFetchWithProgress(\n wrapFetchWithCredentials(fetchWithBaseUrl, expoApiBaseUrl)\n);\n"],"names":["ApiV2Error","UnexpectedServerData","UnexpectedServerError","createCachedFetch","fetchAsync","getResponseDataOrThrow","wrapFetchWithCredentials","Error","response","message","name","code","expoApiV2ErrorCode","expoApiV2ErrorDetails","details","expoApiV2ErrorServerStack","stack","expoApiV2ErrorMetadata","metadata","expoApiV2RequestId","requestId","toString","env","EXPO_DEBUG","json","data","JSON","stringify","fetchFunction","expoApiBaseUrl","expoApiOrigin","URL","origin","fetchWithCredentials","url","options","Array","isArray","headers","resolvedHeaders","isExpoApiUrl","token","getAccessToken","authorization","getSession","sessionSecret","status","body","text","parse","errors","length","error","includes","isNetworkError","cause","disableNetwork","CommandError","fetchWithOffline","wrapFetchWithOffline","wrapFetchWithUserAgent","fetch","getExpoApiBaseUrl","fetchWithBaseUrl","wrapFetchWithBaseUrl","wrapFetchWithProgress","cacheDirectory","ttl","skipCache","EXPO_BETA","EXPO_NO_CACHE","FileSystemResponseCache","require","wrapFetchWithCache","path","join","getExpoHomeDirectory"],"mappings":";;;;;;;;;;;QAgBaA;eAAAA;;QA2CAC;eAAAA;;QARAC;eAAAA;;QA2IGC;eAAAA;;QA6BHC;eAAAA;;QA3JGC;eAAAA;;QAiBAC;eAAAA;;;;gEAhFC;;;;;;oCAEkB;sCAEE;sCACA;uCACC;wCACC;qBACnB;wBACS;uBACP;0BACY;0BACH;8BACkC;;;;;;AAE1D,MAAMN,mBAAmBO;IAS9B,YAAYC,QAOX,CAAE;QACD,KAAK,CAACA,SAASC,OAAO,QAhBfC,OAAO;QAiBd,IAAI,CAACC,IAAI,GAAGH,SAASG,IAAI;QACzB,IAAI,CAACC,kBAAkB,GAAGJ,SAASG,IAAI;QACvC,IAAI,CAACE,qBAAqB,GAAGL,SAASM,OAAO;QAC7C,IAAI,CAACC,yBAAyB,GAAGP,SAASQ,KAAK;QAC/C,IAAI,CAACC,sBAAsB,GAAGT,SAASU,QAAQ;QAC/C,IAAI,CAACC,kBAAkB,GAAGX,SAASY,SAAS;IAC9C;IAEAC,WAAW;QACT,OAAO,GAAG,KAAK,CAACA,aAAaC,QAAG,CAACC,UAAU,IAAI,IAAI,CAACJ,kBAAkB,GAAG,CAAC,cAAc,EAAE,IAAI,CAACA,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAA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HC,SAAS,EAMV;IACC,oCAAoC;IACpC,IAAIA,aAAa9C,QAAG,CAAC+C,SAAS,IAAI/C,QAAG,CAACgD,aAAa,EAAE;QACnD,OAAOT;IACT;IAEA,MAAM,EAAEU,uBAAuB,EAAE,GAC/BC,QAAQ;IAEV,OAAOC,IAAAA,sCAAkB,EACvBZ,OACA,IAAIU,wBAAwB;QAC1BL,gBAAgBQ,eAAI,CAACC,IAAI,CAACC,IAAAA,kCAAoB,KAAIV;QAClDC;IACF;AAEJ;AAGO,MAAM/D,aAAa6D,IAAAA,4CAAqB,EAC7C3D,yBAAyByD,kBAAkBlC"}
|
|
@@ -40,6 +40,13 @@ _export(exports, {
|
|
|
40
40
|
return setSessionAsync;
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
+
function _env() {
|
|
44
|
+
const data = require("@expo/env");
|
|
45
|
+
_env = function() {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
43
50
|
function _jsonfile() {
|
|
44
51
|
const data = /*#__PURE__*/ _interop_require_default(require("@expo/json-file"));
|
|
45
52
|
_jsonfile = function() {
|
|
@@ -123,8 +130,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
123
130
|
}
|
|
124
131
|
function getExpoHomeDirectory() {
|
|
125
132
|
const home = (0, _os().homedir)();
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
// Read from the pre-dotenv env — this redirects the directory used for the
|
|
134
|
+
// auth-token cache and other settings. The `__UNSAFE_` prefix marks it as a
|
|
135
|
+
// shell-only escape hatch; a project `.env` setting it would hijack credentials.
|
|
136
|
+
const unsafeHome = (0, _env().getOriginalEnvValue)('__UNSAFE_EXPO_HOME_DIRECTORY');
|
|
137
|
+
if (unsafeHome) {
|
|
138
|
+
return unsafeHome;
|
|
128
139
|
} else if ((0, _getenv().boolish)('EXPO_STAGING', false)) {
|
|
129
140
|
return _path().join(home, '.expo-staging');
|
|
130
141
|
} else if ((0, _getenv().boolish)('EXPO_LOCAL', false)) {
|
|
@@ -138,9 +149,12 @@ function getSettingsDirectory() {
|
|
|
138
149
|
function getSettingsFilePath() {
|
|
139
150
|
return _path().join(getExpoHomeDirectory(), 'state.json');
|
|
140
151
|
}
|
|
152
|
+
// state.json holds the auth session secret, so restrict it to the owner only.
|
|
153
|
+
const SETTINGS_FILE_MODE = 384;
|
|
141
154
|
function getSettings() {
|
|
142
155
|
return new (_jsonfile()).default(getSettingsFilePath(), {
|
|
143
156
|
ensureDir: true,
|
|
157
|
+
mode: SETTINGS_FILE_MODE,
|
|
144
158
|
jsonParseErrorDefault: {},
|
|
145
159
|
// This will ensure that an error isn't thrown if the file doesn't exist.
|
|
146
160
|
cantReadFileDefault: {}
|
|
@@ -154,8 +168,7 @@ function getSession() {
|
|
|
154
168
|
}
|
|
155
169
|
async function setSessionAsync(sessionData) {
|
|
156
170
|
await getSettings().setAsync('auth', sessionData, {
|
|
157
|
-
default: {}
|
|
158
|
-
ensureDir: true
|
|
171
|
+
default: {}
|
|
159
172
|
});
|
|
160
173
|
}
|
|
161
174
|
function hasCredentials() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/user/UserSettings.ts"],"sourcesContent":["import JsonFile from '@expo/json-file';\nimport crypto from 'crypto';\nimport { boolish } from 'getenv';\nimport { homedir } from 'os';\nimport * as path from 'path';\n\ntype SessionData = {\n sessionSecret?: string;\n userId?: string;\n username?: string;\n currentConnection?: 'Username-Password-Authentication' | 'Browser-Flow-Authentication';\n};\n\nexport type UserSettingsData = {\n auth?: SessionData | null;\n ignoreBundledBinaries?: string[];\n PATH?: string;\n /** Last development code signing ID used for `npx expo run:ios`. */\n developmentCodeSigningId?: string;\n /** Unique user ID which is generated anonymously and can be cleared locally. */\n uuid?: string;\n};\n\n// The ~/.expo directory is used to store authentication sessions,\n// which are shared between EAS CLI and Expo CLI.\nexport function getExpoHomeDirectory() {\n const home = homedir();\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/user/UserSettings.ts"],"sourcesContent":["import { getOriginalEnvValue } from '@expo/env';\nimport JsonFile from '@expo/json-file';\nimport crypto from 'crypto';\nimport { boolish } from 'getenv';\nimport { homedir } from 'os';\nimport * as path from 'path';\n\ntype SessionData = {\n sessionSecret?: string;\n userId?: string;\n username?: string;\n currentConnection?: 'Username-Password-Authentication' | 'Browser-Flow-Authentication';\n};\n\nexport type UserSettingsData = {\n auth?: SessionData | null;\n ignoreBundledBinaries?: string[];\n PATH?: string;\n /** Last development code signing ID used for `npx expo run:ios`. */\n developmentCodeSigningId?: string;\n /** Unique user ID which is generated anonymously and can be cleared locally. */\n uuid?: string;\n};\n\n// The ~/.expo directory is used to store authentication sessions,\n// which are shared between EAS CLI and Expo CLI.\nexport function getExpoHomeDirectory() {\n const home = homedir();\n\n // Read from the pre-dotenv env — this redirects the directory used for the\n // auth-token cache and other settings. The `__UNSAFE_` prefix marks it as a\n // shell-only escape hatch; a project `.env` setting it would hijack credentials.\n const unsafeHome = getOriginalEnvValue('__UNSAFE_EXPO_HOME_DIRECTORY');\n if (unsafeHome) {\n return unsafeHome;\n } else if (boolish('EXPO_STAGING', false)) {\n return path.join(home, '.expo-staging');\n } else if (boolish('EXPO_LOCAL', false)) {\n return path.join(home, '.expo-local');\n }\n return path.join(home, '.expo');\n}\n\n/** Return the user cache directory. */\nexport function getSettingsDirectory() {\n return getExpoHomeDirectory();\n}\n\n/** Return the file path of the settings file */\nexport function getSettingsFilePath(): string {\n return path.join(getExpoHomeDirectory(), 'state.json');\n}\n\n// state.json holds the auth session secret, so restrict it to the owner only.\nconst SETTINGS_FILE_MODE = 0o600;\n\n/** Get a new JsonFile instance pointed towards the settings file */\nexport function getSettings(): JsonFile<UserSettingsData> {\n return new JsonFile<UserSettingsData>(getSettingsFilePath(), {\n ensureDir: true,\n mode: SETTINGS_FILE_MODE,\n jsonParseErrorDefault: {},\n // This will ensure that an error isn't thrown if the file doesn't exist.\n cantReadFileDefault: {},\n });\n}\n\nexport function getAccessToken(): string | null {\n return process.env.EXPO_TOKEN ?? null;\n}\n\nexport function getSession() {\n return getSettings().get('auth', null);\n}\n\nexport async function setSessionAsync(sessionData?: SessionData) {\n await getSettings().setAsync('auth', sessionData, { default: {} });\n}\n\n/**\n * Check if there are credentials available, without fetching the user information.\n * This can be used as a faster check to see if users are authenticated.\n * Note, this isn't checking the validity of the credentials.\n */\nexport function hasCredentials() {\n return !!getAccessToken() || !!getSession();\n}\n\n/**\n * Get an anonymous and randomly generated identifier.\n * This is used to group telemetry event by unknown actor,\n * and cannot be used to identify a single user.\n */\nexport async function getAnonymousIdAsync(): Promise<string> {\n const settings = getSettings();\n let id = await settings.getAsync('uuid', null);\n\n if (!id) {\n id = crypto.randomUUID();\n await settings.setAsync('uuid', id);\n }\n\n return id;\n}\n\n/**\n * Get an anonymous and randomly generated identifier.\n * This is used to group telemetry event by unknown actor,\n * and cannot be used to identify a single user.\n */\nexport function getAnonymousId(): string {\n const settings = getSettings();\n let id = settings.get('uuid', null);\n\n if (!id) {\n id = crypto.randomUUID();\n settings.set('uuid', id);\n }\n\n return id;\n}\n"],"names":["getAccessToken","getAnonymousId","getAnonymousIdAsync","getExpoHomeDirectory","getSession","getSettings","getSettingsDirectory","getSettingsFilePath","hasCredentials","setSessionAsync","home","homedir","unsafeHome","getOriginalEnvValue","boolish","path","join","SETTINGS_FILE_MODE","JsonFile","ensureDir","mode","jsonParseErrorDefault","cantReadFileDefault","process","env","EXPO_TOKEN","get","sessionData","setAsync","default","settings","id","getAsync","crypto","randomUUID","set"],"mappings":";;;;;;;;;;;QAmEgBA;eAAAA;;QA2CAC;eAAAA;;QAjBMC;eAAAA;;QAnENC;eAAAA;;QA6CAC;eAAAA;;QAdAC;eAAAA;;QAbAC;eAAAA;;QAKAC;eAAAA;;QAmCAC;eAAAA;;QATMC;eAAAA;;;;yBA3Ec;;;;;;;gEACf;;;;;;;gEACF;;;;;;;yBACK;;;;;;;yBACA;;;;;;;iEACF;;;;;;;;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C;IAEA,OAAOA;AACT;AAOO,SAAS9B;IACd,MAAM6B,WAAWzB;IACjB,IAAI0B,KAAKD,SAASJ,GAAG,CAAC,QAAQ;IAE9B,IAAI,CAACK,IAAI;QACPA,KAAKE,iBAAM,CAACC,UAAU;QACtBJ,SAASK,GAAG,CAAC,QAAQJ;IACvB;IAEA,OAAOA;AACT"}
|
|
@@ -219,9 +219,9 @@ async function exportEmbedAsync(projectRoot, options) {
|
|
|
219
219
|
if (eagerBundleOptions.key === inputKey) {
|
|
220
220
|
// Copy the eager bundleOutput and assets to the new locations.
|
|
221
221
|
await (0, _dir.removeAsync)(options.bundleOutput);
|
|
222
|
-
(0, _dir.copyAsync)(eagerBundleOptions.options.bundleOutput, options.bundleOutput);
|
|
222
|
+
await (0, _dir.copyAsync)(eagerBundleOptions.options.bundleOutput, options.bundleOutput);
|
|
223
223
|
if (eagerBundleOptions.options.assetsDest && options.assetsDest) {
|
|
224
|
-
(0, _dir.copyAsync)(eagerBundleOptions.options.assetsDest, options.assetsDest);
|
|
224
|
+
await (0, _dir.copyAsync)(eagerBundleOptions.options.assetsDest, options.assetsDest);
|
|
225
225
|
}
|
|
226
226
|
console.log('info: Copied output to binary:', options.bundleOutput);
|
|
227
227
|
return;
|
|
@@ -263,7 +263,7 @@ async function exportEmbedInternalAsync(projectRoot, options) {
|
|
|
263
263
|
// Write dom components proxy files.
|
|
264
264
|
hasDomComponents ? (0, _saveAssets.persistMetroFilesAsync)(files, domComponentProxyOutputDir) : null,
|
|
265
265
|
// Copy public folder for dom components only if
|
|
266
|
-
hasDomComponents ? (0, _publicFolder.copyPublicFolderAsync)(
|
|
266
|
+
hasDomComponents ? (0, _publicFolder.copyPublicFolderAsync)((0, _publicFolder.getPublicFolderPath)(projectRoot), _path().default.join(domComponentProxyOutputDir, _DomComponentsMiddleware.DOM_COMPONENTS_BUNDLE_DIR)) : null,
|
|
267
267
|
// NOTE(EvanBacon): This may need to be adjusted in the future if want to support baseUrl on native
|
|
268
268
|
// platforms when doing production embeds (unlikely).
|
|
269
269
|
options.assetsDest ? (0, _persistMetroAssets.persistMetroAssetsAsync)(projectRoot, assets, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/export/embed/exportEmbedAsync.ts"],"sourcesContent":["/**\n * Copyright © 2023 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 { getConfig } from '@expo/config';\nimport { convertEntryPointToRelative } from '@expo/config/paths';\nimport Server from '@expo/metro/metro/Server';\nimport splitBundleOptions from '@expo/metro/metro/lib/splitBundleOptions';\nimport * as output from '@expo/metro/metro/shared/output/bundle';\nimport type { BundleOptions } from '@expo/metro/metro/shared/types';\nimport { patchTransformFileForPackedMaps } from '@expo/metro-config/build/serializer/packedMap';\nimport { patchMetroSourceMapStringForPackedMaps } from '@expo/metro-config/build/serializer/sourceMap';\nimport getMetroAssets from '@expo/metro-config/build/transform-worker/getAssets';\nimport assert from 'assert';\nimport fs from 'fs';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\nimport type { Options } from './resolveOptions';\nimport { deserializeEagerKey, getExportEmbedOptionsKey } from './resolveOptions';\nimport { isExecutingFromXcodebuild, logMetroErrorInXcode } from './xcodeCompilerLogger';\nimport { Log } from '../../log';\nimport { DevServerManager } from '../../start/server/DevServerManager';\nimport { MetroBundlerDevServer } from '../../start/server/metro/MetroBundlerDevServer';\nimport { replaceMetroFileMap } from '../../start/server/metro/createFileMap-fork';\nimport { loadMetroConfigAsync } from '../../start/server/metro/instantiateMetro';\nimport { DOM_COMPONENTS_BUNDLE_DIR } from '../../start/server/middleware/DomComponentsMiddleware';\nimport { getMetroDirectBundleOptionsForExpoConfig } from '../../start/server/middleware/metroOptions';\nimport { stripAnsi } from '../../utils/ansi';\nimport { copyAsync, removeAsync } from '../../utils/dir';\nimport { env } from '../../utils/env';\nimport { setNodeEnv, loadEnvFiles } from '../../utils/nodeEnv';\nimport { exportDomComponentAsync } from '../exportDomComponents';\nimport { isEnableHermesManaged } from '../exportHermes';\nimport { persistMetroAssetsAsync } from '../persistMetroAssets';\nimport { copyPublicFolderAsync } from '../publicFolder';\nimport type { BundleAssetWithFileHashes, ExportAssetMap } from '../saveAssets';\nimport { persistMetroFilesAsync } from '../saveAssets';\nimport { exportStandaloneServerAsync } from './exportServer';\nimport { ensureProcessExitsAfterDelay } from '../../utils/exit';\n\nconst debug = require('debug')('expo:export:embed');\n\nfunction guessCopiedAppleBundlePath(bundleOutput: string) {\n // Ensure the path is familiar before guessing.\n if (\n !bundleOutput.match(/\\/Xcode\\/DerivedData\\/.*\\/Build\\/Products\\//) &&\n !bundleOutput.match(/\\/CoreSimulator\\/Devices\\/.*\\/data\\/Containers\\/Bundle\\/Application\\//)\n ) {\n debug('Bundling to non-standard location:', bundleOutput);\n return false;\n }\n const bundleName = path.basename(bundleOutput);\n const bundleParent = path.dirname(bundleOutput);\n const possiblePath = globSync(`*.app/${bundleName}`, {\n cwd: bundleParent,\n absolute: true,\n // bundle identifiers can start with dots.\n dot: true,\n })[0];\n debug('Possible path for previous bundle:', possiblePath);\n return possiblePath;\n}\n\nexport async function exportEmbedAsync(projectRoot: string, options: Options) {\n // The React Native build scripts always enable the cache reset but we shouldn't need this in CI environments.\n // By disabling it, we can eagerly bundle code before the build and reuse the cached artifacts in subsequent builds.\n if (env.CI && options.resetCache) {\n debug('CI environment detected, disabling automatic cache reset');\n options.resetCache = false;\n }\n\n setNodeEnv(options.dev ? 'development' : 'production');\n loadEnvFiles(projectRoot);\n\n // This is an optimized codepath that can occur during `npx expo run` and does not occur during builds from Xcode or Android Studio.\n // Here we reconcile a bundle pass that was run before the native build process. This order can fail faster and is show better errors since the logs won't be obscured by Xcode and Android Studio.\n // This path is also used for automatically deploying server bundles to a remote host.\n const eagerBundleOptions = env.__EXPO_EAGER_BUNDLE_OPTIONS\n ? deserializeEagerKey(env.__EXPO_EAGER_BUNDLE_OPTIONS)\n : null;\n if (eagerBundleOptions) {\n // Get the cache key for the current process to compare against the eager key.\n const inputKey = getExportEmbedOptionsKey(options);\n\n // If the app was bundled previously in the same process, then we should reuse the Metro cache.\n options.resetCache = false;\n\n if (eagerBundleOptions.key === inputKey) {\n // Copy the eager bundleOutput and assets to the new locations.\n await removeAsync(options.bundleOutput);\n\n copyAsync(eagerBundleOptions.options.bundleOutput, options.bundleOutput);\n\n if (eagerBundleOptions.options.assetsDest && options.assetsDest) {\n copyAsync(eagerBundleOptions.options.assetsDest, options.assetsDest);\n }\n\n console.log('info: Copied output to binary:', options.bundleOutput);\n return;\n }\n // TODO: sourcemapOutput is set on Android but not during eager. This is tolerable since it doesn't invalidate the Metro cache.\n console.log(' Eager key:', eagerBundleOptions.key);\n console.log('Request key:', inputKey);\n\n // TODO: We may want an analytic event here in the future to understand when this happens.\n console.warn('warning: Eager bundle does not match new options, bundling again.');\n }\n\n await exportEmbedInternalAsync(projectRoot, options);\n\n // Ensure the process closes after bundling\n ensureProcessExitsAfterDelay();\n}\n\nexport async function exportEmbedInternalAsync(projectRoot: string, options: Options) {\n // Ensure we delete the old bundle to trigger a failure if the bundle cannot be created.\n await removeAsync(options.bundleOutput);\n\n // The iOS bundle is copied in to the Xcode project, so we need to remove the old one\n // to prevent Xcode from loading the old one after a build failure.\n if (options.platform === 'ios') {\n const previousPath = guessCopiedAppleBundlePath(options.bundleOutput);\n if (previousPath && fs.existsSync(previousPath)) {\n debug('Removing previous iOS bundle:', previousPath);\n await removeAsync(previousPath);\n }\n }\n\n const { bundle, assets, files } = await exportEmbedBundleAndAssetsAsync(projectRoot, options);\n\n fs.mkdirSync(path.dirname(options.bundleOutput), { recursive: true, mode: 0o755 });\n\n // On Android, dom components proxy files should write to the assets directory instead of the res directory.\n // We use the bundleOutput directory to get the assets directory.\n const domComponentProxyOutputDir =\n options.platform === 'android' ? path.dirname(options.bundleOutput) : options.assetsDest;\n const hasDomComponents = domComponentProxyOutputDir && files.size > 0;\n\n // Persist bundle and source maps.\n await Promise.all([\n output.save(bundle, options, Log.log),\n\n // Write dom components proxy files.\n hasDomComponents ? persistMetroFilesAsync(files, domComponentProxyOutputDir) : null,\n // Copy public folder for dom components only if\n hasDomComponents\n ? copyPublicFolderAsync(\n path.resolve(projectRoot, env.EXPO_PUBLIC_FOLDER),\n path.join(domComponentProxyOutputDir, DOM_COMPONENTS_BUNDLE_DIR)\n )\n : null,\n\n // NOTE(EvanBacon): This may need to be adjusted in the future if want to support baseUrl on native\n // platforms when doing production embeds (unlikely).\n options.assetsDest\n ? persistMetroAssetsAsync(projectRoot, assets, {\n platform: options.platform,\n outputDirectory: options.assetsDest,\n iosAssetCatalogDirectory: options.assetCatalogDest,\n })\n : null,\n ]);\n}\n\nexport async function exportEmbedBundleAndAssetsAsync(\n projectRoot: string,\n options: Options\n): Promise<{\n bundle: Awaited<ReturnType<Server['build']>>;\n assets: readonly BundleAssetWithFileHashes[];\n files: ExportAssetMap;\n}> {\n const devServerManager = await DevServerManager.startMetroAsync(projectRoot, {\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n port: 8081,\n isExporting: true,\n location: {},\n resetDevServer: options.resetCache,\n maxWorkers: options.maxWorkers,\n });\n\n const devServer = devServerManager.getDefaultDevServer();\n assert(devServer instanceof MetroBundlerDevServer);\n\n const { exp, pkg } = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n const isHermes = isEnableHermesManaged(exp, options.platform);\n\n let sourceMapUrl = options.sourcemapOutput;\n if (sourceMapUrl && !options.sourcemapUseAbsolutePath) {\n sourceMapUrl = path.basename(sourceMapUrl);\n }\n\n const files: ExportAssetMap = new Map();\n\n try {\n const bundles = await devServer.nativeExportBundleAsync(\n exp,\n {\n // TODO: Re-enable when we get bytecode chunk splitting working again.\n splitChunks: false, //devServer.isReactServerComponentsEnabled,\n mainModuleName: convertEntryPointToRelative(projectRoot, options.entryFile),\n platform: options.platform,\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n engine: isHermes ? 'hermes' : undefined,\n serializerIncludeMaps: !!sourceMapUrl,\n bytecode: options.bytecode ?? false,\n // source map inline\n reactCompiler: !!exp.experiments?.reactCompiler,\n },\n files,\n {\n sourceMapUrl,\n unstable_transformProfile: (options.unstableTransformProfile ||\n (isHermes ? 'hermes-stable' : 'default')) as BundleOptions['unstable_transformProfile'],\n }\n );\n\n // We optimistically build the server-side API routes code here, to ensure they're\n // valid or to enable parallel deployment in the future (TBD). This is disabled using\n // the explicit `--skip-server` flag.\n const apiRoutesEnabled =\n devServer.isReactServerComponentsEnabled || exp.web?.output === 'server';\n if (!options.skipServer && apiRoutesEnabled) {\n await exportStandaloneServerAsync(projectRoot, devServer, {\n exp,\n pkg,\n files,\n options,\n });\n }\n\n const expoDomComponentReferences = [\n ...new Set(\n bundles.artifacts\n .map((artifact) =>\n Array.isArray(artifact.metadata.expoDomComponentReferences)\n ? artifact.metadata.expoDomComponentReferences\n : []\n )\n .flat()\n ),\n ];\n if (expoDomComponentReferences.length > 0) {\n await Promise.all(\n // TODO: Make a version of this which uses `this.metro.getBundler().buildGraphForEntries([])` to bundle all the DOM components at once.\n expoDomComponentReferences.map(async (filePath) => {\n const { bundle } = await exportDomComponentAsync({\n filePath,\n projectRoot,\n dev: options.dev,\n devServer,\n isHermes,\n includeSourceMaps: !!sourceMapUrl,\n exp,\n files,\n });\n\n if (options.assetsDest) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // This is saving web-style inside of a native app's binary.\n await persistMetroAssetsAsync(\n projectRoot,\n bundle.assets.map((asset) => ({\n ...asset,\n httpServerLocation: path.join(DOM_COMPONENTS_BUNDLE_DIR, asset.httpServerLocation),\n })),\n {\n files,\n platform: 'web',\n outputDirectory: options.assetsDest,\n }\n );\n }\n })\n );\n }\n\n return {\n files,\n bundle: {\n code: bundles.artifacts.filter((a: any) => a.type === 'js')[0]?.source!,\n // Can be optional when source maps aren't enabled.\n map: bundles.artifacts.filter((a: any) => a.type === 'map')[0]?.source.toString()!,\n },\n assets: bundles.assets,\n };\n } catch (error: any) {\n if (isError(error)) {\n // Log using Xcode error format so the errors are picked up by xcodebuild.\n // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script\n if (options.platform === 'ios') {\n // If the error is about to be presented in Xcode, strip the ansi characters from the message.\n if ('message' in error && isExecutingFromXcodebuild()) {\n error.message = stripAnsi(error.message) as string;\n }\n logMetroErrorInXcode(projectRoot, error);\n }\n }\n throw error;\n } finally {\n devServerManager.stopAsync();\n }\n}\n\n// Exports for expo-updates\nexport async function createMetroServerAndBundleRequestAsync(\n projectRoot: string,\n options: Pick<\n Options,\n | 'maxWorkers'\n | 'config'\n | 'platform'\n | 'sourcemapOutput'\n | 'sourcemapUseAbsolutePath'\n | 'entryFile'\n | 'minify'\n | 'dev'\n | 'resetCache'\n | 'unstableTransformProfile'\n >\n): Promise<{ server: Server; bundleRequest: BundleOptions }> {\n const exp = getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp;\n\n // TODO: This is slow ~40ms\n const { config } = await loadMetroConfigAsync(\n projectRoot,\n {\n // TODO: This is always enabled in the native script and there's no way to disable it.\n resetCache: options.resetCache,\n maxWorkers: options.maxWorkers,\n },\n {\n exp,\n isExporting: true,\n getMetroBundler() {\n return metro.getBundler().getBundler();\n },\n }\n );\n\n const isHermes = isEnableHermesManaged(exp, options.platform);\n\n let sourceMapUrl = options.sourcemapOutput;\n if (sourceMapUrl && !options.sourcemapUseAbsolutePath) {\n sourceMapUrl = path.basename(sourceMapUrl);\n }\n\n const directBundleOptions = getMetroDirectBundleOptionsForExpoConfig(projectRoot, exp, {\n splitChunks: false,\n // TODO(@kitten): This currently has to match a filename exactly\n mainModuleName: convertEntryPointToRelative(projectRoot, options.entryFile, null),\n platform: options.platform,\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n engine: isHermes ? 'hermes' : undefined,\n isExporting: true,\n // Never output bytecode in the exported bundle since that is hardcoded in the native run script.\n bytecode: false,\n hosted: false,\n });\n\n // TODO(cedric): check if we can use the proper `bundleType=bundle` and `entryPoint=mainModuleName` properties\n const bundleRequest: BundleOptions = {\n ...Server.DEFAULT_BUNDLE_OPTIONS,\n ...directBundleOptions,\n\n // NOTE(@kitten): Cast non-optional defaults\n lazy: directBundleOptions.lazy ?? Server.DEFAULT_BUNDLE_OPTIONS.lazy,\n modulesOnly: directBundleOptions.modulesOnly ?? Server.DEFAULT_BUNDLE_OPTIONS.modulesOnly,\n runModule: directBundleOptions.runModule ?? Server.DEFAULT_BUNDLE_OPTIONS.runModule,\n\n sourceMapUrl,\n unstable_transformProfile: (options.unstableTransformProfile ||\n (isHermes ? 'hermes-stable' : 'default')) as BundleOptions['unstable_transformProfile'],\n };\n\n const { metro } = await replaceMetroFileMap(() => ({\n metro: new Server(config, {\n watch: false,\n }),\n }));\n\n // The dev server applies the same patch from `instantiateMetro.ts`;\n // this is the export-embed / `expo-updates` path, where `data.map`\n // would otherwise reach Metro's readers in the unwrapped wire shape.\n patchTransformFileForPackedMaps(metro.getBundler().getBundler());\n patchMetroSourceMapStringForPackedMaps();\n\n return { server: metro, bundleRequest };\n}\n\nexport async function exportEmbedAssetsAsync(\n server: Server,\n bundleRequest: BundleOptions,\n projectRoot: string,\n options: Pick<Options, 'platform'>\n) {\n try {\n const { entryFile, onProgress, resolverOptions, transformOptions } = splitBundleOptions({\n ...bundleRequest,\n // @ts-ignore-error TODO(@kitten): Very unclear why this is here. Remove?\n bundleType: 'todo',\n });\n\n const dependencies = await server._bundler.getDependencies(\n // NOTE(@kitten): This isn't an `entryFile`, but instead a `mainModuleName`, that's been renamed\n // in `getMetroDirectBundleOptions`, where we've passed the already converted name\n [entryFile],\n transformOptions,\n resolverOptions,\n { onProgress, shallow: false, lazy: false }\n );\n\n const config = server._config;\n\n return getMetroAssets(dependencies, {\n processModuleFilter: config.serializer.processModuleFilter,\n assetPlugins: config.transformer.assetPlugins,\n platform: transformOptions.platform!,\n // Forked out of Metro because the `this._getServerRootDir()` doesn't match the development\n // behavior.\n projectRoot: config.projectRoot, // this._getServerRootDir(),\n publicPath: config.transformer.publicPath,\n isHosted: false,\n });\n } catch (error: any) {\n if (isError(error)) {\n // Log using Xcode error format so the errors are picked up by xcodebuild.\n // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script\n if (options.platform === 'ios') {\n // If the error is about to be presented in Xcode, strip the ansi characters from the message.\n if ('message' in error && isExecutingFromXcodebuild()) {\n error.message = stripAnsi(error.message) as string;\n }\n logMetroErrorInXcode(projectRoot, error);\n }\n }\n throw error;\n }\n}\n\nfunction isError(error: any): error is Error {\n return error instanceof Error;\n}\n"],"names":["createMetroServerAndBundleRequestAsync","exportEmbedAssetsAsync","exportEmbedAsync","exportEmbedBundleAndAssetsAsync","exportEmbedInternalAsync","debug","require","guessCopiedAppleBundlePath","bundleOutput","match","bundleName","path","basename","bundleParent","dirname","possiblePath","globSync","cwd","absolute","dot","projectRoot","options","env","CI","resetCache","setNodeEnv","dev","loadEnvFiles","eagerBundleOptions","__EXPO_EAGER_BUNDLE_OPTIONS","deserializeEagerKey","inputKey","getExportEmbedOptionsKey","key","removeAsync","copyAsync","assetsDest","console","log","warn","ensureProcessExitsAfterDelay","platform","previousPath","fs","existsSync","bundle","assets","files","mkdirSync","recursive","mode","domComponentProxyOutputDir","hasDomComponents","size","Promise","all","output","save","Log","persistMetroFilesAsync","copyPublicFolderAsync","resolve","EXPO_PUBLIC_FOLDER","join","DOM_COMPONENTS_BUNDLE_DIR","persistMetroAssetsAsync","outputDirectory","iosAssetCatalogDirectory","assetCatalogDest","devServerManager","DevServerManager","startMetroAsync","minify","port","isExporting","location","resetDevServer","maxWorkers","devServer","getDefaultDevServer","assert","MetroBundlerDevServer","exp","pkg","getConfig","skipSDKVersionRequirement","isHermes","isEnableHermesManaged","sourceMapUrl","sourcemapOutput","sourcemapUseAbsolutePath","Map","bundles","nativeExportBundleAsync","splitChunks","mainModuleName","convertEntryPointToRelative","entryFile","engine","undefined","serializerIncludeMaps","bytecode","reactCompiler","experiments","unstable_transformProfile","unstableTransformProfile","apiRoutesEnabled","isReactServerComponentsEnabled","web","skipServer","exportStandaloneServerAsync","expoDomComponentReferences","Set","artifacts","map","artifact","Array","isArray","metadata","flat","length","filePath","exportDomComponentAsync","includeSourceMaps","asset","httpServerLocation","code","filter","a","type","source","toString","error","isError","isExecutingFromXcodebuild","message","stripAnsi","logMetroErrorInXcode","stopAsync","config","loadMetroConfigAsync","getMetroBundler","metro","getBundler","directBundleOptions","getMetroDirectBundleOptionsForExpoConfig","hosted","bundleRequest","Server","DEFAULT_BUNDLE_OPTIONS","lazy","modulesOnly","runModule","replaceMetroFileMap","watch","patchTransformFileForPackedMaps","patchMetroSourceMapStringForPackedMaps","server","onProgress","resolverOptions","transformOptions","splitBundleOptions","bundleType","dependencies","_bundler","getDependencies","shallow","_config","getMetroAssets","processModuleFilter","serializer","assetPlugins","transformer","publicPath","isHosted","Error"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAiTqBA;eAAAA;;QAsFAC;eAAAA;;QA1UAC;eAAAA;;QAqGAC;eAAAA;;QAlDAC;eAAAA;;;;yBA/GI;;;;;;;yBACkB;;;;;;;gEACzB;;;;;;;gEACY;;;;;;;iEACP;;;;;;;yBAEwB;;;;;;;yBACO;;;;;;;gEAC5B;;;;;;;gEACR;;;;;;;gEACJ;;;;;;;yBACkB;;;;;;;gEAChB;;;;;;gCAG6C;qCACE;qBAC5C;kCACa;uCACK;mCACF;kCACC;yCACK;8BACe;sBAC/B;qBACa;qBACnB;yBACqB;qCACD;8BACF;oCACE;8BACF;4BAEC;8BACK;sBACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,SAASC,2BAA2BC,YAAoB;IACtD,+CAA+C;IAC/C,IACE,CAACA,aAAaC,KAAK,CAAC,kDACpB,CAACD,aAAaC,KAAK,CAAC,0EACpB;QACAJ,MAAM,sCAAsCG;QAC5C,OAAO;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oBACrDF,MAAMG,OAAO,GAAGC,IAAAA,eAAS,EAACJ,MAAMG,OAAO;gBACzC;gBACAE,IAAAA,yCAAoB,EAACrH,aAAagH;YACpC;QACF;QACA,MAAMA;IACR;AACF;AAEA,SAASC,QAAQD,KAAU;IACzB,OAAOA,iBAAiB2C;AAC1B"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/export/embed/exportEmbedAsync.ts"],"sourcesContent":["/**\n * Copyright © 2023 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 { getConfig } from '@expo/config';\nimport { convertEntryPointToRelative } from '@expo/config/paths';\nimport Server from '@expo/metro/metro/Server';\nimport splitBundleOptions from '@expo/metro/metro/lib/splitBundleOptions';\nimport * as output from '@expo/metro/metro/shared/output/bundle';\nimport type { BundleOptions } from '@expo/metro/metro/shared/types';\nimport { patchTransformFileForPackedMaps } from '@expo/metro-config/build/serializer/packedMap';\nimport { patchMetroSourceMapStringForPackedMaps } from '@expo/metro-config/build/serializer/sourceMap';\nimport getMetroAssets from '@expo/metro-config/build/transform-worker/getAssets';\nimport assert from 'assert';\nimport fs from 'fs';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\nimport type { Options } from './resolveOptions';\nimport { deserializeEagerKey, getExportEmbedOptionsKey } from './resolveOptions';\nimport { isExecutingFromXcodebuild, logMetroErrorInXcode } from './xcodeCompilerLogger';\nimport { Log } from '../../log';\nimport { DevServerManager } from '../../start/server/DevServerManager';\nimport { MetroBundlerDevServer } from '../../start/server/metro/MetroBundlerDevServer';\nimport { replaceMetroFileMap } from '../../start/server/metro/createFileMap-fork';\nimport { loadMetroConfigAsync } from '../../start/server/metro/instantiateMetro';\nimport { DOM_COMPONENTS_BUNDLE_DIR } from '../../start/server/middleware/DomComponentsMiddleware';\nimport { getMetroDirectBundleOptionsForExpoConfig } from '../../start/server/middleware/metroOptions';\nimport { stripAnsi } from '../../utils/ansi';\nimport { copyAsync, removeAsync } from '../../utils/dir';\nimport { env } from '../../utils/env';\nimport { setNodeEnv, loadEnvFiles } from '../../utils/nodeEnv';\nimport { exportDomComponentAsync } from '../exportDomComponents';\nimport { isEnableHermesManaged } from '../exportHermes';\nimport { persistMetroAssetsAsync } from '../persistMetroAssets';\nimport { copyPublicFolderAsync, getPublicFolderPath } from '../publicFolder';\nimport type { BundleAssetWithFileHashes, ExportAssetMap } from '../saveAssets';\nimport { persistMetroFilesAsync } from '../saveAssets';\nimport { exportStandaloneServerAsync } from './exportServer';\nimport { ensureProcessExitsAfterDelay } from '../../utils/exit';\n\nconst debug = require('debug')('expo:export:embed');\n\nfunction guessCopiedAppleBundlePath(bundleOutput: string) {\n // Ensure the path is familiar before guessing.\n if (\n !bundleOutput.match(/\\/Xcode\\/DerivedData\\/.*\\/Build\\/Products\\//) &&\n !bundleOutput.match(/\\/CoreSimulator\\/Devices\\/.*\\/data\\/Containers\\/Bundle\\/Application\\//)\n ) {\n debug('Bundling to non-standard location:', bundleOutput);\n return false;\n }\n const bundleName = path.basename(bundleOutput);\n const bundleParent = path.dirname(bundleOutput);\n const possiblePath = globSync(`*.app/${bundleName}`, {\n cwd: bundleParent,\n absolute: true,\n // bundle identifiers can start with dots.\n dot: true,\n })[0];\n debug('Possible path for previous bundle:', possiblePath);\n return possiblePath;\n}\n\nexport async function exportEmbedAsync(projectRoot: string, options: Options) {\n // The React Native build scripts always enable the cache reset but we shouldn't need this in CI environments.\n // By disabling it, we can eagerly bundle code before the build and reuse the cached artifacts in subsequent builds.\n if (env.CI && options.resetCache) {\n debug('CI environment detected, disabling automatic cache reset');\n options.resetCache = false;\n }\n\n setNodeEnv(options.dev ? 'development' : 'production');\n loadEnvFiles(projectRoot);\n\n // This is an optimized codepath that can occur during `npx expo run` and does not occur during builds from Xcode or Android Studio.\n // Here we reconcile a bundle pass that was run before the native build process. This order can fail faster and is show better errors since the logs won't be obscured by Xcode and Android Studio.\n // This path is also used for automatically deploying server bundles to a remote host.\n const eagerBundleOptions = env.__EXPO_EAGER_BUNDLE_OPTIONS\n ? deserializeEagerKey(env.__EXPO_EAGER_BUNDLE_OPTIONS)\n : null;\n if (eagerBundleOptions) {\n // Get the cache key for the current process to compare against the eager key.\n const inputKey = getExportEmbedOptionsKey(options);\n\n // If the app was bundled previously in the same process, then we should reuse the Metro cache.\n options.resetCache = false;\n\n if (eagerBundleOptions.key === inputKey) {\n // Copy the eager bundleOutput and assets to the new locations.\n await removeAsync(options.bundleOutput);\n\n await copyAsync(eagerBundleOptions.options.bundleOutput, options.bundleOutput);\n\n if (eagerBundleOptions.options.assetsDest && options.assetsDest) {\n await copyAsync(eagerBundleOptions.options.assetsDest, options.assetsDest);\n }\n\n console.log('info: Copied output to binary:', options.bundleOutput);\n return;\n }\n // TODO: sourcemapOutput is set on Android but not during eager. This is tolerable since it doesn't invalidate the Metro cache.\n console.log(' Eager key:', eagerBundleOptions.key);\n console.log('Request key:', inputKey);\n\n // TODO: We may want an analytic event here in the future to understand when this happens.\n console.warn('warning: Eager bundle does not match new options, bundling again.');\n }\n\n await exportEmbedInternalAsync(projectRoot, options);\n\n // Ensure the process closes after bundling\n ensureProcessExitsAfterDelay();\n}\n\nexport async function exportEmbedInternalAsync(projectRoot: string, options: Options) {\n // Ensure we delete the old bundle to trigger a failure if the bundle cannot be created.\n await removeAsync(options.bundleOutput);\n\n // The iOS bundle is copied in to the Xcode project, so we need to remove the old one\n // to prevent Xcode from loading the old one after a build failure.\n if (options.platform === 'ios') {\n const previousPath = guessCopiedAppleBundlePath(options.bundleOutput);\n if (previousPath && fs.existsSync(previousPath)) {\n debug('Removing previous iOS bundle:', previousPath);\n await removeAsync(previousPath);\n }\n }\n\n const { bundle, assets, files } = await exportEmbedBundleAndAssetsAsync(projectRoot, options);\n\n fs.mkdirSync(path.dirname(options.bundleOutput), { recursive: true, mode: 0o755 });\n\n // On Android, dom components proxy files should write to the assets directory instead of the res directory.\n // We use the bundleOutput directory to get the assets directory.\n const domComponentProxyOutputDir =\n options.platform === 'android' ? path.dirname(options.bundleOutput) : options.assetsDest;\n const hasDomComponents = domComponentProxyOutputDir && files.size > 0;\n\n // Persist bundle and source maps.\n await Promise.all([\n output.save(bundle, options, Log.log),\n\n // Write dom components proxy files.\n hasDomComponents ? persistMetroFilesAsync(files, domComponentProxyOutputDir) : null,\n // Copy public folder for dom components only if\n hasDomComponents\n ? copyPublicFolderAsync(\n getPublicFolderPath(projectRoot),\n path.join(domComponentProxyOutputDir, DOM_COMPONENTS_BUNDLE_DIR)\n )\n : null,\n\n // NOTE(EvanBacon): This may need to be adjusted in the future if want to support baseUrl on native\n // platforms when doing production embeds (unlikely).\n options.assetsDest\n ? persistMetroAssetsAsync(projectRoot, assets, {\n platform: options.platform,\n outputDirectory: options.assetsDest,\n iosAssetCatalogDirectory: options.assetCatalogDest,\n })\n : null,\n ]);\n}\n\nexport async function exportEmbedBundleAndAssetsAsync(\n projectRoot: string,\n options: Options\n): Promise<{\n bundle: Awaited<ReturnType<Server['build']>>;\n assets: readonly BundleAssetWithFileHashes[];\n files: ExportAssetMap;\n}> {\n const devServerManager = await DevServerManager.startMetroAsync(projectRoot, {\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n port: 8081,\n isExporting: true,\n location: {},\n resetDevServer: options.resetCache,\n maxWorkers: options.maxWorkers,\n });\n\n const devServer = devServerManager.getDefaultDevServer();\n assert(devServer instanceof MetroBundlerDevServer);\n\n const { exp, pkg } = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n const isHermes = isEnableHermesManaged(exp, options.platform);\n\n let sourceMapUrl = options.sourcemapOutput;\n if (sourceMapUrl && !options.sourcemapUseAbsolutePath) {\n sourceMapUrl = path.basename(sourceMapUrl);\n }\n\n const files: ExportAssetMap = new Map();\n\n try {\n const bundles = await devServer.nativeExportBundleAsync(\n exp,\n {\n // TODO: Re-enable when we get bytecode chunk splitting working again.\n splitChunks: false, //devServer.isReactServerComponentsEnabled,\n mainModuleName: convertEntryPointToRelative(projectRoot, options.entryFile),\n platform: options.platform,\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n engine: isHermes ? 'hermes' : undefined,\n serializerIncludeMaps: !!sourceMapUrl,\n bytecode: options.bytecode ?? false,\n // source map inline\n reactCompiler: !!exp.experiments?.reactCompiler,\n },\n files,\n {\n sourceMapUrl,\n unstable_transformProfile: (options.unstableTransformProfile ||\n (isHermes ? 'hermes-stable' : 'default')) as BundleOptions['unstable_transformProfile'],\n }\n );\n\n // We optimistically build the server-side API routes code here, to ensure they're\n // valid or to enable parallel deployment in the future (TBD). This is disabled using\n // the explicit `--skip-server` flag.\n const apiRoutesEnabled =\n devServer.isReactServerComponentsEnabled || exp.web?.output === 'server';\n if (!options.skipServer && apiRoutesEnabled) {\n await exportStandaloneServerAsync(projectRoot, devServer, {\n exp,\n pkg,\n files,\n options,\n });\n }\n\n const expoDomComponentReferences = [\n ...new Set(\n bundles.artifacts\n .map((artifact) =>\n Array.isArray(artifact.metadata.expoDomComponentReferences)\n ? artifact.metadata.expoDomComponentReferences\n : []\n )\n .flat()\n ),\n ];\n if (expoDomComponentReferences.length > 0) {\n await Promise.all(\n // TODO: Make a version of this which uses `this.metro.getBundler().buildGraphForEntries([])` to bundle all the DOM components at once.\n expoDomComponentReferences.map(async (filePath) => {\n const { bundle } = await exportDomComponentAsync({\n filePath,\n projectRoot,\n dev: options.dev,\n devServer,\n isHermes,\n includeSourceMaps: !!sourceMapUrl,\n exp,\n files,\n });\n\n if (options.assetsDest) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // This is saving web-style inside of a native app's binary.\n await persistMetroAssetsAsync(\n projectRoot,\n bundle.assets.map((asset) => ({\n ...asset,\n httpServerLocation: path.join(DOM_COMPONENTS_BUNDLE_DIR, asset.httpServerLocation),\n })),\n {\n files,\n platform: 'web',\n outputDirectory: options.assetsDest,\n }\n );\n }\n })\n );\n }\n\n return {\n files,\n bundle: {\n code: bundles.artifacts.filter((a: any) => a.type === 'js')[0]?.source!,\n // Can be optional when source maps aren't enabled.\n map: bundles.artifacts.filter((a: any) => a.type === 'map')[0]?.source.toString()!,\n },\n assets: bundles.assets,\n };\n } catch (error: any) {\n if (isError(error)) {\n // Log using Xcode error format so the errors are picked up by xcodebuild.\n // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script\n if (options.platform === 'ios') {\n // If the error is about to be presented in Xcode, strip the ansi characters from the message.\n if ('message' in error && isExecutingFromXcodebuild()) {\n error.message = stripAnsi(error.message) as string;\n }\n logMetroErrorInXcode(projectRoot, error);\n }\n }\n throw error;\n } finally {\n devServerManager.stopAsync();\n }\n}\n\n// Exports for expo-updates\nexport async function createMetroServerAndBundleRequestAsync(\n projectRoot: string,\n options: Pick<\n Options,\n | 'maxWorkers'\n | 'config'\n | 'platform'\n | 'sourcemapOutput'\n | 'sourcemapUseAbsolutePath'\n | 'entryFile'\n | 'minify'\n | 'dev'\n | 'resetCache'\n | 'unstableTransformProfile'\n >\n): Promise<{ server: Server; bundleRequest: BundleOptions }> {\n const exp = getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp;\n\n // TODO: This is slow ~40ms\n const { config } = await loadMetroConfigAsync(\n projectRoot,\n {\n // TODO: This is always enabled in the native script and there's no way to disable it.\n resetCache: options.resetCache,\n maxWorkers: options.maxWorkers,\n },\n {\n exp,\n isExporting: true,\n getMetroBundler() {\n return metro.getBundler().getBundler();\n },\n }\n );\n\n const isHermes = isEnableHermesManaged(exp, options.platform);\n\n let sourceMapUrl = options.sourcemapOutput;\n if (sourceMapUrl && !options.sourcemapUseAbsolutePath) {\n sourceMapUrl = path.basename(sourceMapUrl);\n }\n\n const directBundleOptions = getMetroDirectBundleOptionsForExpoConfig(projectRoot, exp, {\n splitChunks: false,\n // TODO(@kitten): This currently has to match a filename exactly\n mainModuleName: convertEntryPointToRelative(projectRoot, options.entryFile, null),\n platform: options.platform,\n minify: options.minify,\n mode: options.dev ? 'development' : 'production',\n engine: isHermes ? 'hermes' : undefined,\n isExporting: true,\n // Never output bytecode in the exported bundle since that is hardcoded in the native run script.\n bytecode: false,\n hosted: false,\n });\n\n // TODO(cedric): check if we can use the proper `bundleType=bundle` and `entryPoint=mainModuleName` properties\n const bundleRequest: BundleOptions = {\n ...Server.DEFAULT_BUNDLE_OPTIONS,\n ...directBundleOptions,\n\n // NOTE(@kitten): Cast non-optional defaults\n lazy: directBundleOptions.lazy ?? Server.DEFAULT_BUNDLE_OPTIONS.lazy,\n modulesOnly: directBundleOptions.modulesOnly ?? Server.DEFAULT_BUNDLE_OPTIONS.modulesOnly,\n runModule: directBundleOptions.runModule ?? Server.DEFAULT_BUNDLE_OPTIONS.runModule,\n\n sourceMapUrl,\n unstable_transformProfile: (options.unstableTransformProfile ||\n (isHermes ? 'hermes-stable' : 'default')) as BundleOptions['unstable_transformProfile'],\n };\n\n const { metro } = await replaceMetroFileMap(() => ({\n metro: new Server(config, {\n watch: false,\n }),\n }));\n\n // The dev server applies the same patch from `instantiateMetro.ts`;\n // this is the export-embed / `expo-updates` path, where `data.map`\n // would otherwise reach Metro's readers in the unwrapped wire shape.\n patchTransformFileForPackedMaps(metro.getBundler().getBundler());\n patchMetroSourceMapStringForPackedMaps();\n\n return { server: metro, bundleRequest };\n}\n\nexport async function exportEmbedAssetsAsync(\n server: Server,\n bundleRequest: BundleOptions,\n projectRoot: string,\n options: Pick<Options, 'platform'>\n) {\n try {\n const { entryFile, onProgress, resolverOptions, transformOptions } = splitBundleOptions({\n ...bundleRequest,\n // @ts-ignore-error TODO(@kitten): Very unclear why this is here. Remove?\n bundleType: 'todo',\n });\n\n const dependencies = await server._bundler.getDependencies(\n // NOTE(@kitten): This isn't an `entryFile`, but instead a `mainModuleName`, that's been renamed\n // in `getMetroDirectBundleOptions`, where we've passed the already converted name\n [entryFile],\n transformOptions,\n resolverOptions,\n { onProgress, shallow: false, lazy: false }\n );\n\n const config = server._config;\n\n return getMetroAssets(dependencies, {\n processModuleFilter: config.serializer.processModuleFilter,\n assetPlugins: config.transformer.assetPlugins,\n platform: transformOptions.platform!,\n // Forked out of Metro because the `this._getServerRootDir()` doesn't match the development\n // behavior.\n projectRoot: config.projectRoot, // this._getServerRootDir(),\n publicPath: config.transformer.publicPath,\n isHosted: false,\n });\n } catch (error: any) {\n if (isError(error)) {\n // Log using Xcode error format so the errors are picked up by xcodebuild.\n // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script\n if (options.platform === 'ios') {\n // If the error is about to be presented in Xcode, strip the ansi characters from the message.\n if ('message' in error && isExecutingFromXcodebuild()) {\n error.message = stripAnsi(error.message) as string;\n }\n logMetroErrorInXcode(projectRoot, error);\n }\n }\n throw error;\n }\n}\n\nfunction isError(error: any): error is Error {\n return error instanceof Error;\n}\n"],"names":["createMetroServerAndBundleRequestAsync","exportEmbedAssetsAsync","exportEmbedAsync","exportEmbedBundleAndAssetsAsync","exportEmbedInternalAsync","debug","require","guessCopiedAppleBundlePath","bundleOutput","match","bundleName","path","basename","bundleParent","dirname","possiblePath","globSync","cwd","absolute","dot","projectRoot","options","env","CI","resetCache","setNodeEnv","dev","loadEnvFiles","eagerBundleOptions","__EXPO_EAGER_BUNDLE_OPTIONS","deserializeEagerKey","inputKey","getExportEmbedOptionsKey","key","removeAsync","copyAsync","assetsDest","console","log","warn","ensureProcessExitsAfterDelay","platform","previousPath","fs","existsSync","bundle","assets","files","mkdirSync","recursive","mode","domComponentProxyOutputDir","hasDomComponents","size","Promise","all","output","save","Log","persistMetroFilesAsync","copyPublicFolderAsync","getPublicFolderPath","join","DOM_COMPONENTS_BUNDLE_DIR","persistMetroAssetsAsync","outputDirectory","iosAssetCatalogDirectory","assetCatalogDest","devServerManager","DevServerManager","startMetroAsync","minify","port","isExporting","location","resetDevServer","maxWorkers","devServer","getDefaultDevServer","assert","MetroBundlerDevServer","exp","pkg","getConfig","skipSDKVersionRequirement","isHermes","isEnableHermesManaged","sourceMapUrl","sourcemapOutput","sourcemapUseAbsolutePath","Map","bundles","nativeExportBundleAsync","splitChunks","mainModuleName","convertEntryPointToRelative","entryFile","engine","undefined","serializerIncludeMaps","bytecode","reactCompiler","experiments","unstable_transformProfile","unstableTransformProfile","apiRoutesEnabled","isReactServerComponentsEnabled","web","skipServer","exportStandaloneServerAsync","expoDomComponentReferences","Set","artifacts","map","artifact","Array","isArray","metadata","flat","length","filePath","exportDomComponentAsync","includeSourceMaps","asset","httpServerLocation","code","filter","a","type","source","toString","error","isError","isExecutingFromXcodebuild","message","stripAnsi","logMetroErrorInXcode","stopAsync","config","loadMetroConfigAsync","getMetroBundler","metro","getBundler","directBundleOptions","getMetroDirectBundleOptionsForExpoConfig","hosted","bundleRequest","Server","DEFAULT_BUNDLE_OPTIONS","lazy","modulesOnly","runModule","replaceMetroFileMap","watch","patchTransformFileForPackedMaps","patchMetroSourceMapStringForPackedMaps","server","onProgress","resolverOptions","transformOptions","splitBundleOptions","bundleType","dependencies","_bundler","getDependencies","shallow","_config","getMetroAssets","processModuleFilter","serializer","assetPlugins","transformer","publicPath","isHosted","Error"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAiTqBA;eAAAA;;QAsFAC;eAAAA;;QA1UAC;eAAAA;;QAqGAC;eAAAA;;QAlDAC;eAAAA;;;;yBA/GI;;;;;;;yBACkB;;;;;;;gEACzB;;;;;;;gEACY;;;;;;;iEACP;;;;;;;yBAEwB;;;;;;;yBACO;;;;;;;gEAC5B;;;;;;;gEACR;;;;;;;gEACJ;;;;;;;yBACkB;;;;;;;gEAChB;;;;;;gCAG6C;qCACE;qBAC5C;kCACa;uCACK;mCACF;kCACC;yCACK;8BACe;sBAC/B;qBACa;qBACnB;yBACqB;qCACD;8BACF;oCACE;8BACmB;4BAEpB;8BACK;sBACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,SAASC,2BAA2BC,YAAoB;IACtD,+CAA+C;IAC/C,IACE,CAACA,aAAaC,KAAK,CAAC,kDAC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BAC9F,IAAI,aAAa0F,SAASE,IAAAA,8CAAyB,KAAI;oBACrDF,MAAMG,OAAO,GAAGC,IAAAA,eAAS,EAACJ,MAAMG,OAAO;gBACzC;gBACAE,IAAAA,yCAAoB,EAACpH,aAAa+G;YACpC;QACF;QACA,MAAMA;IACR;AACF;AAEA,SAASC,QAAQD,KAAU;IACzB,OAAOA,iBAAiB2C;AAC1B"}
|
|
@@ -87,7 +87,7 @@ async function exportStandaloneServerAsync(projectRoot, devServer, { exp, pkg, f
|
|
|
87
87
|
platform: 'web',
|
|
88
88
|
apiRoutesOnly: true
|
|
89
89
|
});
|
|
90
|
-
const publicPath =
|
|
90
|
+
const publicPath = (0, _publicFolder.getPublicFolderPath)(projectRoot);
|
|
91
91
|
// Copy over public folder items
|
|
92
92
|
await (0, _publicFolder.copyPublicFolderAsync)(publicPath, serverOutput);
|
|
93
93
|
// Copy over the server output on top of the public folder.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/export/embed/exportServer.ts"],"sourcesContent":["/**\n * Copyright © 2023 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 type { ExpoConfig, PackageJSONConfig } from '@expo/config';\nimport { modifyConfigAsync } from '@expo/config';\nimport spawnAsync from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport { execSync } from 'node:child_process';\nimport path from 'path';\n\nimport { disableNetwork } from '../../api/settings';\nimport { Log } from '../../log';\nimport { isSpawnResultError } from '../../start/platforms/ios/xcrun';\nimport type { MetroBundlerDevServer } from '../../start/server/metro/MetroBundlerDevServer';\nimport { removeAsync } from '../../utils/dir';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { exportApiRoutesStandaloneAsync } from '../exportStaticAsync';\nimport { copyPublicFolderAsync } from '../publicFolder';\nimport type { ExportAssetMap } from '../saveAssets';\nimport { persistMetroFilesAsync } from '../saveAssets';\nimport type { Options } from './resolveOptions';\nimport {\n isExecutingFromXcodebuild,\n logInXcode,\n logMetroErrorInXcode,\n warnInXcode,\n} from './xcodeCompilerLogger';\n\nconst debug = require('debug')('expo:export:server');\n\ntype ServerDeploymentResults = {\n url: string;\n dashboardUrl?: string;\n};\n\nexport async function exportStandaloneServerAsync(\n projectRoot: string,\n devServer: MetroBundlerDevServer,\n {\n exp,\n pkg,\n files,\n options,\n }: { exp: ExpoConfig; pkg: PackageJSONConfig; files: ExportAssetMap; options: Options }\n) {\n if (!options.eager) {\n await tryRemovingGeneratedOriginAsync(projectRoot, exp);\n }\n\n logInXcode('Exporting server');\n\n // Store the server output in the project's .expo directory.\n const serverOutput = path.join(projectRoot, '.expo/server', options.platform);\n\n // Remove the previous server output to prevent stale files.\n await removeAsync(serverOutput);\n\n // Export the API routes for server rendering the React Server Components.\n await exportApiRoutesStandaloneAsync(devServer, {\n files,\n platform: 'web',\n apiRoutesOnly: true,\n });\n\n const publicPath = path.resolve(projectRoot, env.EXPO_PUBLIC_FOLDER);\n\n // Copy over public folder items\n await copyPublicFolderAsync(publicPath, serverOutput);\n\n // Copy over the server output on top of the public folder.\n await persistMetroFilesAsync(files, serverOutput);\n\n [...files.entries()].forEach(([key, value]) => {\n if (value.targetDomain === 'server') {\n // Delete server resources to prevent them from being exposed in the binary.\n files.delete(key);\n }\n });\n\n // TODO: Deprecate this in favor of a built-in prop that users should avoid setting.\n const userDefinedServerUrl = exp.extra?.router?.origin;\n let serverUrl = userDefinedServerUrl;\n\n const shouldSkipServerDeployment = (() => {\n if (!options.eager) {\n logInXcode('Skipping server deployment because the script is not running in eager mode.');\n return true;\n }\n\n // Add an opaque flag to disable server deployment.\n if (env.EXPO_NO_DEPLOY) {\n warnInXcode('Skipping server deployment because environment variable EXPO_NO_DEPLOY is set.');\n return true;\n }\n\n // Can't safely deploy from Xcode since the PATH isn't set up correctly. We could amend this in the future and allow users who customize the PATH to deploy from Xcode.\n if (isExecutingFromXcodebuild()) {\n // TODO: Don't warn when the eager bundle has been run.\n warnInXcode(\n 'Skipping server deployment because the build is running from an Xcode run script. Build with Expo CLI or EAS Build to deploy the server automatically.'\n );\n return true;\n }\n\n return false;\n })();\n\n // Deploy the server output to a hosting provider.\n const deployedServerUrl = shouldSkipServerDeployment\n ? false\n : await runServerDeployCommandAsync(projectRoot, {\n distDirectory: serverOutput,\n deployScript: getServerDeploymentScript(pkg.scripts, options.platform),\n });\n\n if (!deployedServerUrl) {\n return;\n }\n\n if (serverUrl) {\n logInXcode(\n `Using custom server URL: ${serverUrl} (ignoring deployment URL: ${deployedServerUrl})`\n );\n }\n\n // If the user-defined server URL is not defined, use the deployed server URL.\n // This allows for overwriting the server URL in the project's native files.\n serverUrl ||= deployedServerUrl;\n\n // If the user hasn't manually defined the server URL, write the deployed server URL to the app.json.\n if (userDefinedServerUrl) {\n Log.log('Skip automatically linking server origin to native container');\n return;\n }\n Log.log('Writing generated server URL to app.json');\n\n // NOTE: Is is it possible to assert that the config needs to be modifiable before building the app?\n const modification = await modifyConfigAsync(\n projectRoot,\n {\n extra: {\n ...(exp.extra ?? {}),\n router: {\n ...(exp.extra?.router ?? {}),\n generatedOrigin: serverUrl,\n },\n },\n },\n {\n skipSDKVersionRequirement: true,\n }\n );\n\n if (modification.type !== 'success') {\n throw new CommandError(\n `Failed to write generated server origin to app.json because the file is dynamic and does not extend the static config. The client will not be able to make server requests to API routes or static files. You can disable server linking with EXPO_NO_DEPLOY=1 or by disabling server output in the app.json.`\n );\n }\n}\n\nasync function dumpDeploymentLogs(projectRoot: string, logs: string, name = 'deploy') {\n const outputPath = path.join(projectRoot, `.expo/logs/${name}.log`);\n await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });\n debug('Dumping server deployment logs to: ' + outputPath);\n await fs.promises.writeFile(outputPath, logs);\n return outputPath;\n}\n\nfunction getCommandBin(command: string) {\n try {\n return execSync(`command -v ${command}`, { stdio: 'pipe' }).toString().trim();\n } catch {\n return null;\n }\n}\n\nasync function runServerDeployCommandAsync(\n projectRoot: string,\n {\n distDirectory,\n deployScript,\n }: { distDirectory: string; deployScript: { scriptName: string; script: string } | null }\n): Promise<string | false> {\n const logOfflineError = () => {\n const manualScript = deployScript\n ? `npm run ${deployScript.scriptName}`\n : `npx eas deploy --export-dir ${distDirectory}`;\n\n logMetroErrorInXcode(\n projectRoot,\n chalk.red`Running CLI in offline mode, skipping server deployment. Deploy manually with: ${manualScript}`\n );\n };\n if (env.EXPO_OFFLINE) {\n logOfflineError();\n return false;\n }\n\n // TODO: Only allow EAS deployments when staging is enabled, this is because the feature is still staging-only.\n if (!env.EXPO_UNSTABLE_DEPLOY_SERVER) {\n return false;\n }\n\n if (!env.EAS_BUILD) {\n // This check helps avoid running EAS if the user isn't a user of EAS.\n // We only need to run it when building outside of EAS.\n const globalBin = getCommandBin('eas');\n if (!globalBin) {\n // This should never happen from EAS Builds.\n // Possible to happen when building locally with `npx expo run`\n logMetroErrorInXcode(\n projectRoot,\n `eas-cli is not installed globally, skipping server deployment. Install EAS CLI with 'npm install -g eas-cli'.`\n );\n return false;\n }\n debug('Found eas-cli:', globalBin);\n }\n\n let json: any;\n try {\n let results: spawnAsync.SpawnResult;\n\n const spawnOptions: spawnAsync.SpawnOptions = {\n cwd: projectRoot,\n // Ensures that errors can be caught.\n stdio: 'pipe',\n };\n // TODO: Support absolute paths in EAS CLI\n const exportDir = path.relative(projectRoot, distDirectory);\n if (deployScript) {\n logInXcode(`Using custom server deploy script: ${deployScript.scriptName}`);\n // Amend the path to try and make the custom scripts work.\n\n results = await spawnAsync(\n 'npm',\n ['run', deployScript.scriptName, `--export-dir=${exportDir}`],\n spawnOptions\n );\n } else {\n logInXcode('Deploying server to link with client');\n\n // results = DEPLOYMENT_SUCCESS_FIXTURE;\n results = await spawnAsync(\n 'npx',\n ['eas-cli', 'deploy', '--non-interactive', '--json', `--export-dir=${exportDir}`],\n spawnOptions\n );\n\n debug('Server deployment stdout:', results.stdout);\n\n // Send stderr to stderr. stdout is parsed as JSON.\n if (results.stderr) {\n process.stderr.write(results.stderr);\n }\n }\n\n const logPath = await dumpDeploymentLogs(projectRoot, results.output.join('\\n'));\n\n try {\n // {\n // \"dashboardUrl\": \"https://staging.expo.dev/projects/6460c11c-e1bc-4084-882a-fd9f57b825b1/hosting/deployments\",\n // \"identifier\": \"8a1pwbv6c5\",\n // \"url\": \"https://sep30--8a1pwbv6c5.staging.expo.app\"\n // }\n json = JSON.parse(results.stdout.trim());\n } catch {\n logMetroErrorInXcode(\n projectRoot,\n `Failed to parse server deployment JSON output. Check the logs for more information: ${logPath}`\n );\n return false;\n }\n } catch (error) {\n if (isSpawnResultError(error)) {\n const output = error.output.join('\\n').trim() || error.toString();\n Log.log(\n chalk.dim(\n 'An error occurred while deploying server. Logs stored at: ' +\n (await dumpDeploymentLogs(projectRoot, output, 'deploy-error'))\n )\n );\n\n // Likely a server offline or network error.\n if (output.match(/ENOTFOUND/)) {\n logOfflineError();\n // Print the raw error message to help provide more context.\n Log.log(chalk.dim(output));\n // Prevent any other network requests (unlikely for this command).\n disableNetwork();\n return false;\n }\n\n logInXcode(output);\n if (output.match(/spawn eas ENOENT/)) {\n // EAS not installed.\n logMetroErrorInXcode(\n projectRoot,\n `Server deployment failed because eas-cli cannot be accessed from the build script's environment (ENOENT). Install EAS CLI with 'npm install -g eas-cli'.`\n );\n return false;\n }\n\n if (error.stderr.match(/Must configure EAS project by running/)) {\n // EAS not configured, this can happen when building a project locally before building in EAS.\n // User must run `eas init`, `eas deploy`, or `eas build` first.\n\n // TODO: Should we fail the build here or just warn users?\n logMetroErrorInXcode(\n projectRoot,\n `Skipping server deployment because EAS is not configured. Run 'eas init' before trying again, or disable server output in the project.`\n );\n return false;\n }\n }\n\n // Throw unhandled server deployment errors.\n throw error;\n }\n\n // Assert json format\n assertDeploymentJsonOutput(json);\n\n // Warn about the URL not being valid. This should never happen, but might be possible with third-parties.\n if (!canParseURL(json.url)) {\n warnInXcode(`The server deployment URL is not a valid URL: ${json.url}`);\n }\n\n if (json.dashboardUrl) {\n logInXcode(`Server dashboard: ${json.dashboardUrl}`);\n }\n\n logInXcode(`Server deployed to: ${json.url}`);\n\n return json.url;\n}\n\nfunction canParseURL(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction assertDeploymentJsonOutput(json: any): asserts json is ServerDeploymentResults {\n if (!json || typeof json !== 'object' || typeof json.url !== 'string') {\n throw new Error(\n 'JSON output of server deployment command are not in the expected format: { url: \"https://...\" }'\n );\n }\n}\n\nfunction getServerDeploymentScript(\n scripts: Record<string, string> | undefined,\n platform: string\n): { scriptName: string; script: string } | null {\n // Users can overwrite the default deployment script with:\n // { scripts: { \"native:deploy\": \"eas deploy --json --non-interactive\" } }\n // A quick search on GitHub showed that `native:deploy` is not used in any public repos yet.\n // https://github.com/search?q=%22native%3Adeploy%22+path%3Apackage.json&type=code\n const DEFAULT_SCRIPT_NAME = 'native:deploy';\n\n const scriptNames = [\n // DEFAULT_SCRIPT_NAME + ':' + platform,\n DEFAULT_SCRIPT_NAME,\n ];\n\n for (const scriptName of scriptNames) {\n if (scripts?.[scriptName]) {\n return { scriptName, script: scripts[scriptName] };\n }\n }\n\n return null;\n}\n\n/** We can try to remove the generated origin from the manifest when running outside of eager mode. Bundling is the last operation to run so the config will already be embedded with the origin. */\nasync function tryRemovingGeneratedOriginAsync(projectRoot: string, exp: ExpoConfig) {\n if (env.CI) {\n // Skip in CI since nothing is committed.\n return;\n }\n if (exp.extra?.router?.generatedOrigin == null) {\n debug('No generated origin needs removing');\n return;\n }\n\n const modification = await modifyConfigAsync(\n projectRoot,\n {\n extra: {\n ...(exp.extra ?? {}),\n router: {\n ...(exp.extra?.router ?? {}),\n generatedOrigin: undefined,\n },\n },\n },\n {\n skipSDKVersionRequirement: true,\n }\n );\n\n if (modification.type !== 'success') {\n debug('Could not remove generated origin from manifest');\n } else {\n debug('Generated origin has been removed from manifest');\n }\n}\n"],"names":["exportStandaloneServerAsync","debug","require","projectRoot","devServer","exp","pkg","files","options","eager","tryRemovingGeneratedOriginAsync","logInXcode","serverOutput","path","join","platform","removeAsync","exportApiRoutesStandaloneAsync","apiRoutesOnly","publicPath","resolve","env","EXPO_PUBLIC_FOLDER","copyPublicFolderAsync","persistMetroFilesAsync","entries","forEach","key","value","targetDomain","delete","userDefinedServerUrl","extra","router","origin","serverUrl","shouldSkipServerDeployment","EXPO_NO_DEPLOY","warnInXcode","isExecutingFromXcodebuild","deployedServerUrl","runServerDeployCommandAsync","distDirectory","deployScript","getServerDeploymentScript","scripts","Log","log","modification","modifyConfigAsync","generatedOrigin","skipSDKVersionRequirement","type","CommandError","dumpDeploymentLogs","logs","name","outputPath","fs","promises","mkdir","dirname","recursive","writeFile","getCommandBin","command","execSync","stdio","toString","trim","logOfflineError","manualScript","scriptName","logMetroErrorInXcode","chalk","red","EXPO_OFFLINE","EXPO_UNSTABLE_DEPLOY_SERVER","EAS_BUILD","globalBin","json","results","spawnOptions","cwd","exportDir","relative","spawnAsync","stdout","stderr","process","write","logPath","output","JSON","parse","error","isSpawnResultError","dim","match","disableNetwork","assertDeploymentJsonOutput","canParseURL","url","dashboardUrl","URL","Error","DEFAULT_SCRIPT_NAME","scriptNames","script","CI","undefined"],"mappings":"AAAA;;;;;CAKC;;;;+BAmCqBA;;;eAAAA;;;;yBAjCY;;;;;;;gEACX;;;;;;;gEACL;;;;;;;gEACH;;;;;;;yBACU;;;;;;;gEACR;;;;;;0BAEc;qBACX;uBACe;qBAEP;qBACR;wBACS;mCACkB;8BACT;4BAEC;qCAOhC;;;;;;AAEP,MAAMC,QAAQC,QAAQ,SAAS;AAOxB,eAAeF,4BACpBG,WAAmB,EACnBC,SAAgC,EAChC,EACEC,GAAG,EACHC,GAAG,EACHC,KAAK,EACLC,OAAO,EAC8E;QAqC1DH,mBAAAA,YA+DjBA;IAlGZ,IAAI,CAACG,QAAQC,KAAK,EAAE;QAClB,MAAMC,gCAAgCP,aAAaE;IACrD;IAEAM,IAAAA,+BA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D,gCAAgCP,WAAmB,EAAEE,GAAe;QAK7EA,mBAAAA,YAWQA;IAfZ,IAAIgB,QAAG,CAACwF,EAAE,EAAE;QACV,yCAAyC;QACzC;IACF;IACA,IAAIxG,EAAAA,aAAAA,IAAI2B,KAAK,sBAAT3B,oBAAAA,WAAW4B,MAAM,qBAAjB5B,kBAAmB6C,eAAe,KAAI,MAAM;QAC9CjD,MAAM;QACN;IACF;IAEA,MAAM+C,eAAe,MAAMC,IAAAA,2BAAiB,EAC1C9C,aACA;QACE6B,OAAO;YACL,GAAI3B,IAAI2B,KAAK,IAAI,CAAC,CAAC;YACnBC,QAAQ;gBACN,GAAI5B,EAAAA,cAAAA,IAAI2B,KAAK,qBAAT3B,YAAW4B,MAAM,KAAI,CAAC,CAAC;gBAC3BiB,iBAAiB4D;YACnB;QACF;IACF,GACA;QACE3D,2BAA2B;IAC7B;IAGF,IAAIH,aAAaI,IAAI,KAAK,WAAW;QACnCnD,MAAM;IACR,OAAO;QACLA,MAAM;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/export/embed/exportServer.ts"],"sourcesContent":["/**\n * Copyright © 2023 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 type { ExpoConfig, PackageJSONConfig } from '@expo/config';\nimport { modifyConfigAsync } from '@expo/config';\nimport spawnAsync from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport { execSync } from 'node:child_process';\nimport path from 'path';\n\nimport { disableNetwork } from '../../api/settings';\nimport { Log } from '../../log';\nimport { isSpawnResultError } from '../../start/platforms/ios/xcrun';\nimport type { MetroBundlerDevServer } from '../../start/server/metro/MetroBundlerDevServer';\nimport { removeAsync } from '../../utils/dir';\nimport { env } from '../../utils/env';\nimport { CommandError } from '../../utils/errors';\nimport { exportApiRoutesStandaloneAsync } from '../exportStaticAsync';\nimport { copyPublicFolderAsync, getPublicFolderPath } from '../publicFolder';\nimport type { ExportAssetMap } from '../saveAssets';\nimport { persistMetroFilesAsync } from '../saveAssets';\nimport type { Options } from './resolveOptions';\nimport {\n isExecutingFromXcodebuild,\n logInXcode,\n logMetroErrorInXcode,\n warnInXcode,\n} from './xcodeCompilerLogger';\n\nconst debug = require('debug')('expo:export:server');\n\ntype ServerDeploymentResults = {\n url: string;\n dashboardUrl?: string;\n};\n\nexport async function exportStandaloneServerAsync(\n projectRoot: string,\n devServer: MetroBundlerDevServer,\n {\n exp,\n pkg,\n files,\n options,\n }: { exp: ExpoConfig; pkg: PackageJSONConfig; files: ExportAssetMap; options: Options }\n) {\n if (!options.eager) {\n await tryRemovingGeneratedOriginAsync(projectRoot, exp);\n }\n\n logInXcode('Exporting server');\n\n // Store the server output in the project's .expo directory.\n const serverOutput = path.join(projectRoot, '.expo/server', options.platform);\n\n // Remove the previous server output to prevent stale files.\n await removeAsync(serverOutput);\n\n // Export the API routes for server rendering the React Server Components.\n await exportApiRoutesStandaloneAsync(devServer, {\n files,\n platform: 'web',\n apiRoutesOnly: true,\n });\n\n const publicPath = getPublicFolderPath(projectRoot);\n\n // Copy over public folder items\n await copyPublicFolderAsync(publicPath, serverOutput);\n\n // Copy over the server output on top of the public folder.\n await persistMetroFilesAsync(files, serverOutput);\n\n [...files.entries()].forEach(([key, value]) => {\n if (value.targetDomain === 'server') {\n // Delete server resources to prevent them from being exposed in the binary.\n files.delete(key);\n }\n });\n\n // TODO: Deprecate this in favor of a built-in prop that users should avoid setting.\n const userDefinedServerUrl = exp.extra?.router?.origin;\n let serverUrl = userDefinedServerUrl;\n\n const shouldSkipServerDeployment = (() => {\n if (!options.eager) {\n logInXcode('Skipping server deployment because the script is not running in eager mode.');\n return true;\n }\n\n // Add an opaque flag to disable server deployment.\n if (env.EXPO_NO_DEPLOY) {\n warnInXcode('Skipping server deployment because environment variable EXPO_NO_DEPLOY is set.');\n return true;\n }\n\n // Can't safely deploy from Xcode since the PATH isn't set up correctly. We could amend this in the future and allow users who customize the PATH to deploy from Xcode.\n if (isExecutingFromXcodebuild()) {\n // TODO: Don't warn when the eager bundle has been run.\n warnInXcode(\n 'Skipping server deployment because the build is running from an Xcode run script. Build with Expo CLI or EAS Build to deploy the server automatically.'\n );\n return true;\n }\n\n return false;\n })();\n\n // Deploy the server output to a hosting provider.\n const deployedServerUrl = shouldSkipServerDeployment\n ? false\n : await runServerDeployCommandAsync(projectRoot, {\n distDirectory: serverOutput,\n deployScript: getServerDeploymentScript(pkg.scripts, options.platform),\n });\n\n if (!deployedServerUrl) {\n return;\n }\n\n if (serverUrl) {\n logInXcode(\n `Using custom server URL: ${serverUrl} (ignoring deployment URL: ${deployedServerUrl})`\n );\n }\n\n // If the user-defined server URL is not defined, use the deployed server URL.\n // This allows for overwriting the server URL in the project's native files.\n serverUrl ||= deployedServerUrl;\n\n // If the user hasn't manually defined the server URL, write the deployed server URL to the app.json.\n if (userDefinedServerUrl) {\n Log.log('Skip automatically linking server origin to native container');\n return;\n }\n Log.log('Writing generated server URL to app.json');\n\n // NOTE: Is is it possible to assert that the config needs to be modifiable before building the app?\n const modification = await modifyConfigAsync(\n projectRoot,\n {\n extra: {\n ...(exp.extra ?? {}),\n router: {\n ...(exp.extra?.router ?? {}),\n generatedOrigin: serverUrl,\n },\n },\n },\n {\n skipSDKVersionRequirement: true,\n }\n );\n\n if (modification.type !== 'success') {\n throw new CommandError(\n `Failed to write generated server origin to app.json because the file is dynamic and does not extend the static config. The client will not be able to make server requests to API routes or static files. You can disable server linking with EXPO_NO_DEPLOY=1 or by disabling server output in the app.json.`\n );\n }\n}\n\nasync function dumpDeploymentLogs(projectRoot: string, logs: string, name = 'deploy') {\n const outputPath = path.join(projectRoot, `.expo/logs/${name}.log`);\n await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });\n debug('Dumping server deployment logs to: ' + outputPath);\n await fs.promises.writeFile(outputPath, logs);\n return outputPath;\n}\n\nfunction getCommandBin(command: string) {\n try {\n return execSync(`command -v ${command}`, { stdio: 'pipe' }).toString().trim();\n } catch {\n return null;\n }\n}\n\nasync function runServerDeployCommandAsync(\n projectRoot: string,\n {\n distDirectory,\n deployScript,\n }: { distDirectory: string; deployScript: { scriptName: string; script: string } | null }\n): Promise<string | false> {\n const logOfflineError = () => {\n const manualScript = deployScript\n ? `npm run ${deployScript.scriptName}`\n : `npx eas deploy --export-dir ${distDirectory}`;\n\n logMetroErrorInXcode(\n projectRoot,\n chalk.red`Running CLI in offline mode, skipping server deployment. Deploy manually with: ${manualScript}`\n );\n };\n if (env.EXPO_OFFLINE) {\n logOfflineError();\n return false;\n }\n\n // TODO: Only allow EAS deployments when staging is enabled, this is because the feature is still staging-only.\n if (!env.EXPO_UNSTABLE_DEPLOY_SERVER) {\n return false;\n }\n\n if (!env.EAS_BUILD) {\n // This check helps avoid running EAS if the user isn't a user of EAS.\n // We only need to run it when building outside of EAS.\n const globalBin = getCommandBin('eas');\n if (!globalBin) {\n // This should never happen from EAS Builds.\n // Possible to happen when building locally with `npx expo run`\n logMetroErrorInXcode(\n projectRoot,\n `eas-cli is not installed globally, skipping server deployment. Install EAS CLI with 'npm install -g eas-cli'.`\n );\n return false;\n }\n debug('Found eas-cli:', globalBin);\n }\n\n let json: any;\n try {\n let results: spawnAsync.SpawnResult;\n\n const spawnOptions: spawnAsync.SpawnOptions = {\n cwd: projectRoot,\n // Ensures that errors can be caught.\n stdio: 'pipe',\n };\n // TODO: Support absolute paths in EAS CLI\n const exportDir = path.relative(projectRoot, distDirectory);\n if (deployScript) {\n logInXcode(`Using custom server deploy script: ${deployScript.scriptName}`);\n // Amend the path to try and make the custom scripts work.\n\n results = await spawnAsync(\n 'npm',\n ['run', deployScript.scriptName, `--export-dir=${exportDir}`],\n spawnOptions\n );\n } else {\n logInXcode('Deploying server to link with client');\n\n // results = DEPLOYMENT_SUCCESS_FIXTURE;\n results = await spawnAsync(\n 'npx',\n ['eas-cli', 'deploy', '--non-interactive', '--json', `--export-dir=${exportDir}`],\n spawnOptions\n );\n\n debug('Server deployment stdout:', results.stdout);\n\n // Send stderr to stderr. stdout is parsed as JSON.\n if (results.stderr) {\n process.stderr.write(results.stderr);\n }\n }\n\n const logPath = await dumpDeploymentLogs(projectRoot, results.output.join('\\n'));\n\n try {\n // {\n // \"dashboardUrl\": \"https://staging.expo.dev/projects/6460c11c-e1bc-4084-882a-fd9f57b825b1/hosting/deployments\",\n // \"identifier\": \"8a1pwbv6c5\",\n // \"url\": \"https://sep30--8a1pwbv6c5.staging.expo.app\"\n // }\n json = JSON.parse(results.stdout.trim());\n } catch {\n logMetroErrorInXcode(\n projectRoot,\n `Failed to parse server deployment JSON output. Check the logs for more information: ${logPath}`\n );\n return false;\n }\n } catch (error) {\n if (isSpawnResultError(error)) {\n const output = error.output.join('\\n').trim() || error.toString();\n Log.log(\n chalk.dim(\n 'An error occurred while deploying server. Logs stored at: ' +\n (await dumpDeploymentLogs(projectRoot, output, 'deploy-error'))\n )\n );\n\n // Likely a server offline or network error.\n if (output.match(/ENOTFOUND/)) {\n logOfflineError();\n // Print the raw error message to help provide more context.\n Log.log(chalk.dim(output));\n // Prevent any other network requests (unlikely for this command).\n disableNetwork();\n return false;\n }\n\n logInXcode(output);\n if (output.match(/spawn eas ENOENT/)) {\n // EAS not installed.\n logMetroErrorInXcode(\n projectRoot,\n `Server deployment failed because eas-cli cannot be accessed from the build script's environment (ENOENT). Install EAS CLI with 'npm install -g eas-cli'.`\n );\n return false;\n }\n\n if (error.stderr.match(/Must configure EAS project by running/)) {\n // EAS not configured, this can happen when building a project locally before building in EAS.\n // User must run `eas init`, `eas deploy`, or `eas build` first.\n\n // TODO: Should we fail the build here or just warn users?\n logMetroErrorInXcode(\n projectRoot,\n `Skipping server deployment because EAS is not configured. Run 'eas init' before trying again, or disable server output in the project.`\n );\n return false;\n }\n }\n\n // Throw unhandled server deployment errors.\n throw error;\n }\n\n // Assert json format\n assertDeploymentJsonOutput(json);\n\n // Warn about the URL not being valid. This should never happen, but might be possible with third-parties.\n if (!canParseURL(json.url)) {\n warnInXcode(`The server deployment URL is not a valid URL: ${json.url}`);\n }\n\n if (json.dashboardUrl) {\n logInXcode(`Server dashboard: ${json.dashboardUrl}`);\n }\n\n logInXcode(`Server deployed to: ${json.url}`);\n\n return json.url;\n}\n\nfunction canParseURL(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction assertDeploymentJsonOutput(json: any): asserts json is ServerDeploymentResults {\n if (!json || typeof json !== 'object' || typeof json.url !== 'string') {\n throw new Error(\n 'JSON output of server deployment command are not in the expected format: { url: \"https://...\" }'\n );\n }\n}\n\nfunction getServerDeploymentScript(\n scripts: Record<string, string> | undefined,\n platform: string\n): { scriptName: string; script: string } | null {\n // Users can overwrite the default deployment script with:\n // { scripts: { \"native:deploy\": \"eas deploy --json --non-interactive\" } }\n // A quick search on GitHub showed that `native:deploy` is not used in any public repos yet.\n // https://github.com/search?q=%22native%3Adeploy%22+path%3Apackage.json&type=code\n const DEFAULT_SCRIPT_NAME = 'native:deploy';\n\n const scriptNames = [\n // DEFAULT_SCRIPT_NAME + ':' + platform,\n DEFAULT_SCRIPT_NAME,\n ];\n\n for (const scriptName of scriptNames) {\n if (scripts?.[scriptName]) {\n return { scriptName, script: scripts[scriptName] };\n }\n }\n\n return null;\n}\n\n/** We can try to remove the generated origin from the manifest when running outside of eager mode. Bundling is the last operation to run so the config will already be embedded with the origin. */\nasync function tryRemovingGeneratedOriginAsync(projectRoot: string, exp: ExpoConfig) {\n if (env.CI) {\n // Skip in CI since nothing is committed.\n return;\n }\n if (exp.extra?.router?.generatedOrigin == null) {\n debug('No generated origin needs removing');\n return;\n }\n\n const modification = await modifyConfigAsync(\n projectRoot,\n {\n extra: {\n ...(exp.extra ?? {}),\n router: {\n ...(exp.extra?.router ?? {}),\n generatedOrigin: undefined,\n },\n },\n },\n {\n skipSDKVersionRequirement: true,\n }\n );\n\n if (modification.type !== 'success') {\n debug('Could not remove generated origin from manifest');\n } else {\n debug('Generated origin has been removed from manifest');\n }\n}\n"],"names":["exportStandaloneServerAsync","debug","require","projectRoot","devServer","exp","pkg","files","options","eager","tryRemovingGeneratedOriginAsync","logInXcode","serverOutput","path","join","platform","removeAsync","exportApiRoutesStandaloneAsync","apiRoutesOnly","publicPath","getPublicFolderPath","copyPublicFolderAsync","persistMetroFilesAsync","entries","forEach","key","value","targetDomain","delete","userDefinedServerUrl","extra","router","origin","serverUrl","shouldSkipServerDeployment","env","EXPO_NO_DEPLOY","warnInXcode","isExecutingFromXcodebuild","deployedServerUrl","runServerDeployCommandAsync","distDirectory","deployScript","getServerDeploymentScript","scripts","Log","log","modification","modifyConfigAsync","generatedOrigin","skipSDKVersionRequirement","type","CommandError","dumpDeploymentLogs","logs","name","outputPath","fs","promises","mkdir","dirname","recursive","writeFile","getCommandBin","command","execSync","stdio","toString","trim","logOfflineError","manualScript","scriptName","logMetroErrorInXcode","chalk","red","EXPO_OFFLINE","EXPO_UNSTABLE_DEPLOY_SERVER","EAS_BUILD","globalBin","json","results","spawnOptions","cwd","exportDir","relative","spawnAsync","stdout","stderr","process","write","logPath","output","JSON","parse","error","isSpawnResultError","dim","match","disableNetwork","assertDeploymentJsonOutput","canParseURL","url","dashboardUrl","URL","Error","DEFAULT_SCRIPT_NAME","scriptNames","script","CI","undefined"],"mappings":"AAAA;;;;;CAKC;;;;+BAmCqBA;;;eAAAA;;;;yBAjCY;;;;;;;gEACX;;;;;;;gEACL;;;;;;;gEACH;;;;;;;yBACU;;;;;;;gEACR;;;;;;0BAEc;qBACX;uBACe;qBAEP;qBACR;wBACS;mCACkB;8BACY;4BAEpB;qCAOhC;;;;;;AAEP,MAAMC,QAAQC,QAAQ,SAAS;AAOxB,eAAeF,4BACpBG,WAAmB,EACnBC,SAAgC,EAChC,EACEC,GAAG,EACHC,GAAG,EACHC,KAAK,EACLC,OAAO,EAC8E;QAqC1DH,mBAAAA,YA+DjBA;IAlGZ,IAAI,CAACG,QAAQC,KAAK,EAAE;QAClB,MAAMC,gCAAgCP,aAAaE;I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gCP,WAAmB,EAAEE,GAAe;QAK7EA,mBAAAA,YAWQA;IAfZ,IAAI8B,QAAG,CAACyE,EAAE,EAAE;QACV,yCAAyC;QACzC;IACF;IACA,IAAIvG,EAAAA,aAAAA,IAAIyB,KAAK,sBAATzB,oBAAAA,WAAW0B,MAAM,qBAAjB1B,kBAAmB4C,eAAe,KAAI,MAAM;QAC9ChD,MAAM;QACN;IACF;IAEA,MAAM8C,eAAe,MAAMC,IAAAA,2BAAiB,EAC1C7C,aACA;QACE2B,OAAO;YACL,GAAIzB,IAAIyB,KAAK,IAAI,CAAC,CAAC;YACnBC,QAAQ;gBACN,GAAI1B,EAAAA,cAAAA,IAAIyB,KAAK,qBAATzB,YAAW0B,MAAM,KAAI,CAAC,CAAC;gBAC3BkB,iBAAiB4D;YACnB;QACF;IACF,GACA;QACE3D,2BAA2B;IAC7B;IAGF,IAAIH,aAAaI,IAAI,KAAK,WAAW;QACnClD,MAAM;IACR,OAAO;QACLA,MAAM;IACR;AACF"}
|
|
@@ -153,7 +153,7 @@ async function exportAppAsync(projectRoot, { platforms, outputDir, clear, dev, d
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
const mode = dev ? 'development' : 'production';
|
|
156
|
-
const publicPath =
|
|
156
|
+
const publicPath = (0, _publicFolder.getPublicFolderPath)(projectRoot);
|
|
157
157
|
const outputPath = _path().default.resolve(projectRoot, outputDir);
|
|
158
158
|
// Write the JS bundles to disk, and get the bundle file names (this could change with async chunk loading support).
|
|
159
159
|
const files = new Map();
|