@expo/cli 56.1.6 → 56.1.8
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 +2 -2
- package/build/src/export/embed/exportEmbedAsync.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/prebuild/resolveTemplate.js +10 -5
- package/build/src/prebuild/resolveTemplate.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/UrlCreator.js +10 -1
- package/build/src/start/server/UrlCreator.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/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/createMetroMiddleware.js +7 -1
- package/build/src/start/server/metro/dev-server/createMetroMiddleware.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +3 -1
- 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/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/inspector/createJsInspectorMiddleware.js +14 -24
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.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 +13 -0
- 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/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","FileSystemResponseCache","require","wrapFetchWithCache","path","join","getExpoHomeDirectory"],"mappings":";;;;;;;;;;;QAgBaA;eAAAA;;QA2CAC;eAAAA;;QARAC;eAAAA;;QAgHGC;eAAAA;;QA6BHC;eAAAA;;QAhIGC;eAAAA;;QAaAC;eAAAA;;;;gEA5EC;;;;;;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,IAA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AQ3B,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,IAAI;IAC7H;AACF;AAMO,MAAMjB,8BAA8BK;;QAApC,qBACIG,OAAO;;AAClB;AAMO,MAAMT,6BAA6BM;;QAAnC,qBACIG,OAAO;;AAClB;AAGO,SAASL,uBAAgCmB,IAAa;IAC3D,IAAI,CAAC,CAACA,QAAQ,OAAOA,SAAS,YAAY,UAAUA,MAAM;QACxD,OAAOA,KAAKC,IAAI;IAClB;IAEA,MAAM,IAAIxB,qBACR,CAAC,CAACuB,QAAQ,OAAOA,SAAS,WAAWE,KAAKC,SAAS,CAACH,QAAQ;AAEhE;AASO,SAASlB,yBACdsB,aAAwB,EACxBC,cAAsB;IA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
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBf,SAASN;IACd,MAAMO,OAAOC,IAAAA,aAAO;IAEpB,2EAA2E;IAC3E,4EAA4E;IAC5E,iFAAiF;IACjF,MAAMC,aAAaC,IAAAA,0BAAmB,EAAC;IACvC,IAAID,YAAY;QACd,OAAOA;IACT,OAAO,IAAIE,IAAAA,iBAAO,EAAC,gBAAgB,QAAQ;QACzC,OAAOC,QAAKC,IAAI,CAACN,MAAM;IACzB,OAAO,IAAII,IAAAA,iBAAO,EAAC,cAAc,QAAQ;QACvC,OAAOC,QAAKC,IAAI,CAACN,MAAM;IACzB;IACA,OAAOK,QAAKC,IAAI,CAACN,MAAM;AACzB;AAGO,SAASJ;IACd,OAAOH;AACT;AAGO,SAASI;IACd,OAAOQ,QAAKC,IAAI,CAACb,wBAAwB;AAC3C;AAEA,8EAA8E;AAC9E,MAAMc,qBAAqB;AAGpB,SAASZ;IACd,OAAO,IAAIa,CAAAA,WAAO,SAAC,CAAmBX,uBAAuB;QAC3DY,WAAW;QACXC,MAAMH;QACNI,uBAAuB,CAAC;QACxB,yEAAyE;QACzEC,qBAAqB,CAAC;IACxB;AACF;AAEO,SAAStB;IACd,OAAOuB,QAAQC,GAAG,CAACC,UAAU,IAAI;AACnC;AAEO,SAASrB;IACd,OAAOC,cAAcqB,GAAG,CAAC,QAAQ;AACnC;AAEO,eAAejB,gBAAgBkB,WAAyB;IAC7D,MAAMtB,cAAcuB,QAAQ,CAAC,QAAQD,aAAa;QAAEE,SAAS,CAAC;IAAE;AAClE;AAOO,SAASrB;IACd,OAAO,CAAC,CAACR,oBAAoB,CAAC,CAACI;AACjC;AAOO,eAAeF;IACpB,MAAM4B,WAAWzB;IACjB,IAAI0B,KAAK,MAAMD,SAASE,QAAQ,CAAC,QAAQ;IAEzC,IAAI,CAACD,IAAI;QACPA,KAAKE,iBAAM,CAACC,UAAU;QACtB,MAAMJ,SAASF,QAAQ,CAAC,QAAQG;IAClC;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;
|
|
@@ -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, 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 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 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;8BAC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AOiC,WAAW,CAACC,UAAU;YACzCC,UAAU;QACZ;IACF,EAAE,OAAO1C,OAAY;QACnB,IAAIC,QAAQD,QAAQ;YAClB,0EAA0E;YAC1E,iIAAiI;YACjI,IAAI9G,QAAQoB,QAAQ,KAAK,OAAO;gBAC9B,8FAA8F;gBAC9F,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"}
|
|
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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YACZrB,aAAasH,OAAOtH,WAAW;YAC/BwJ,YAAYlC,OAAOiC,WAAW,CAACC,UAAU;YACzCC,UAAU;QACZ;IACF,EAAE,OAAO1C,OAAY;QACnB,IAAIC,QAAQD,QAAQ;YAClB,0EAA0E;YAC1E,iIAAiI;YACjI,IAAI9G,QAAQoB,QAAQ,KAAK,OAAO;gBAC9B,8FAA8F;gBAC9F,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"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
// note(Simek): https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts
|
|
1
|
+
// note(Simek): reference https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
get MAX_PACKAGES_PER_QUERY () {
|
|
14
|
+
return MAX_PACKAGES_PER_QUERY;
|
|
15
|
+
},
|
|
16
|
+
get checkPackagesCompatibility () {
|
|
9
17
|
return checkPackagesCompatibility;
|
|
10
18
|
}
|
|
11
19
|
});
|
|
@@ -17,6 +25,7 @@ function _chalk() {
|
|
|
17
25
|
return data;
|
|
18
26
|
}
|
|
19
27
|
const _log = require("../../log");
|
|
28
|
+
const _array = require("../../utils/array");
|
|
20
29
|
const _fetch = require("../../utils/fetch");
|
|
21
30
|
const _link = require("../../utils/link");
|
|
22
31
|
function _interop_require_default(obj) {
|
|
@@ -24,6 +33,7 @@ function _interop_require_default(obj) {
|
|
|
24
33
|
default: obj
|
|
25
34
|
};
|
|
26
35
|
}
|
|
36
|
+
const MAX_PACKAGES_PER_QUERY = 50;
|
|
27
37
|
const ERROR_MESSAGE = 'Unable to fetch compatibility data from React Native Directory. Skipping check.';
|
|
28
38
|
async function checkPackagesCompatibility(packages) {
|
|
29
39
|
try {
|
|
@@ -31,19 +41,25 @@ async function checkPackagesCompatibility(packages) {
|
|
|
31
41
|
if (!packagesToCheck.length) {
|
|
32
42
|
return;
|
|
33
43
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
const chunkedPackages = (0, _array.chunk)(packagesToCheck, MAX_PACKAGES_PER_QUERY);
|
|
45
|
+
const results = await Promise.allSettled(chunkedPackages.map((packageChunk)=>(0, _fetch.fetch)(`https://reactnative.directory/api/libraries/check?${new URLSearchParams({
|
|
46
|
+
packages: packageChunk.join(',')
|
|
47
|
+
})}`).then((response)=>{
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(ERROR_MESSAGE);
|
|
50
|
+
}
|
|
51
|
+
return response.json();
|
|
52
|
+
})));
|
|
53
|
+
const packageMetadata = results.reduce((acc, result)=>{
|
|
54
|
+
if (result.status === 'fulfilled') {
|
|
55
|
+
return {
|
|
56
|
+
...acc,
|
|
57
|
+
...result.value
|
|
58
|
+
};
|
|
59
|
+
}
|
|
44
60
|
_log.Log.log(_chalk().default.gray(ERROR_MESSAGE));
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
47
63
|
const incompatiblePackages = packagesToCheck.filter((packageName)=>{
|
|
48
64
|
var _packageMetadata_packageName;
|
|
49
65
|
return ((_packageMetadata_packageName = packageMetadata[packageName]) == null ? void 0 : _packageMetadata_packageName.newArchitecture) === 'unsupported';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/install/utils/checkPackagesCompatibility.ts"],"sourcesContent":["// note(Simek): https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts\nimport chalk from 'chalk';\n\nimport { Log } from '../../log';\nimport { fetch } from '../../utils/fetch';\nimport { learnMore } from '../../utils/link';\n\nexport type ReactNativeDirectoryCheckResult = {\n unmaintained: boolean;\n newArchitecture: 'supported' | 'unsupported' | 'untested';\n};\n\nconst ERROR_MESSAGE =\n 'Unable to fetch compatibility data from React Native Directory. Skipping check.';\n\nexport async function checkPackagesCompatibility(packages: string[]) {\n try {\n const packagesToCheck = packages.filter(\n (packageName) =>\n !packageName.startsWith('@expo/') && !packageName.startsWith('@expo-google-fonts/')\n );\n\n if (!packagesToCheck.length) {\n return;\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../../src/install/utils/checkPackagesCompatibility.ts"],"sourcesContent":["// note(Simek): reference https://github.com/react-native-community/directory/blob/main/pages/api/libraries/check.ts\nimport chalk from 'chalk';\n\nimport { Log } from '../../log';\nimport { chunk } from '../../utils/array';\nimport { fetch } from '../../utils/fetch';\nimport { learnMore } from '../../utils/link';\n\nexport type ReactNativeDirectoryCheckResult = {\n unmaintained: boolean;\n newArchitecture: 'supported' | 'unsupported' | 'untested';\n};\n\nexport type DirectoryCheckResponse = Record<string, ReactNativeDirectoryCheckResult>;\n\nexport const MAX_PACKAGES_PER_QUERY = 50;\nconst ERROR_MESSAGE =\n 'Unable to fetch compatibility data from React Native Directory. Skipping check.';\n\nexport async function checkPackagesCompatibility(packages: string[]) {\n try {\n const packagesToCheck = packages.filter(\n (packageName) =>\n !packageName.startsWith('@expo/') && !packageName.startsWith('@expo-google-fonts/')\n );\n\n if (!packagesToCheck.length) {\n return;\n }\n\n const chunkedPackages = chunk(packagesToCheck, MAX_PACKAGES_PER_QUERY);\n\n const results = await Promise.allSettled<DirectoryCheckResponse>(\n chunkedPackages.map((packageChunk) =>\n fetch(\n `https://reactnative.directory/api/libraries/check?${new URLSearchParams({ packages: packageChunk.join(',') })}`\n ).then((response) => {\n if (!response.ok) {\n throw new Error(ERROR_MESSAGE);\n }\n return response.json();\n })\n )\n );\n\n const packageMetadata = results.reduce<DirectoryCheckResponse>((acc, result) => {\n if (result.status === 'fulfilled') {\n return { ...acc, ...result.value };\n }\n Log.log(chalk.gray(ERROR_MESSAGE));\n return acc;\n }, {});\n\n const incompatiblePackages = packagesToCheck.filter(\n (packageName) => packageMetadata[packageName]?.newArchitecture === 'unsupported'\n );\n\n if (incompatiblePackages.length) {\n Log.warn(\n chalk.yellow(\n `${chalk.bold('Warning')}: ${formatPackageNames(incompatiblePackages)} do${incompatiblePackages.length > 1 ? '' : 'es'} not support the New Architecture. ${learnMore('https://docs.expo.dev/guides/new-architecture/')}`\n )\n );\n }\n } catch {\n Log.log(chalk.gray(ERROR_MESSAGE));\n }\n}\n\nfunction formatPackageNames(incompatiblePackages: string[]) {\n if (incompatiblePackages.length === 1) {\n return incompatiblePackages.join();\n }\n\n const lastPackage = incompatiblePackages.pop();\n return `${incompatiblePackages.join(', ')} and ${lastPackage}`;\n}\n"],"names":["MAX_PACKAGES_PER_QUERY","checkPackagesCompatibility","ERROR_MESSAGE","packages","packagesToCheck","filter","packageName","startsWith","length","chunkedPackages","chunk","results","Promise","allSettled","map","packageChunk","fetch","URLSearchParams","join","then","response","ok","Error","json","packageMetadata","reduce","acc","result","status","value","Log","log","chalk","gray","incompatiblePackages","newArchitecture","warn","yellow","bold","formatPackageNames","learnMore","lastPackage","pop"],"mappings":"AAAA,oHAAoH;;;;;;;;;;;;QAevGA;eAAAA;;QAISC;eAAAA;;;;gEAlBJ;;;;;;qBAEE;uBACE;uBACA;sBACI;;;;;;AASnB,MAAMD,yBAAyB;AACtC,MAAME,gBACJ;AA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;QAG/N;IACF,EAAE,OAAM;QACNV,QAAG,CAACC,GAAG,CAACC,gBAAK,CAACC,IAAI,CAAC/B;IACrB;AACF;AAEA,SAASqC,mBAAmBL,oBAA8B;IACxD,IAAIA,qBAAqB1B,MAAM,KAAK,GAAG;QACrC,OAAO0B,qBAAqBhB,IAAI;IAClC;IAEA,MAAMuB,cAAcP,qBAAqBQ,GAAG;IAC5C,OAAO,GAAGR,qBAAqBhB,IAAI,CAAC,MAAM,KAAK,EAAEuB,aAAa;AAChE"}
|
|
@@ -22,13 +22,12 @@ function _semver() {
|
|
|
22
22
|
};
|
|
23
23
|
return data;
|
|
24
24
|
}
|
|
25
|
-
const _client = require("../api/rest/client");
|
|
26
25
|
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../log"));
|
|
27
26
|
const _resolveLocalTemplate = require("./resolveLocalTemplate");
|
|
28
27
|
const _createFileTransform = require("../utils/createFileTransform");
|
|
29
28
|
const _errors = require("../utils/errors");
|
|
29
|
+
const _fetch = require("../utils/fetch");
|
|
30
30
|
const _npm = require("../utils/npm");
|
|
31
|
-
const _url = require("../utils/url");
|
|
32
31
|
function _interop_require_default(obj) {
|
|
33
32
|
return obj && obj.__esModule ? obj : {
|
|
34
33
|
default: obj
|
|
@@ -122,8 +121,9 @@ async function getRepoInfo(url, examplePath) {
|
|
|
122
121
|
const filePath = examplePath ? examplePath.replace(/^\//, '') : file.join('/');
|
|
123
122
|
// Support repos whose entire purpose is to be an example, e.g.
|
|
124
123
|
// https://github.com/:username/:my-cool-example-repo-name.
|
|
124
|
+
// Use the plain unauthenticated `fetch` so Expo credentials aren't forwarded to GitHub.
|
|
125
125
|
if (t === undefined) {
|
|
126
|
-
const infoResponse = await (0,
|
|
126
|
+
const infoResponse = await (0, _fetch.fetch)(`https://api.github.com/repos/${username}/${name}`);
|
|
127
127
|
if (infoResponse.status !== 200) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
@@ -147,10 +147,15 @@ async function getRepoInfo(url, examplePath) {
|
|
|
147
147
|
}
|
|
148
148
|
return undefined;
|
|
149
149
|
}
|
|
150
|
-
function hasRepo({ username, name, branch, filePath }) {
|
|
150
|
+
async function hasRepo({ username, name, branch, filePath }) {
|
|
151
151
|
const contentsUrl = `https://api.github.com/repos/${username}/${name}/contents`;
|
|
152
152
|
const packagePath = `${filePath ? `/${filePath}` : ''}/package.json`;
|
|
153
|
-
|
|
153
|
+
try {
|
|
154
|
+
const response = await (0, _fetch.fetch)(contentsUrl + packagePath + `?ref=${branch}`);
|
|
155
|
+
return response.ok;
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
154
159
|
}
|
|
155
160
|
async function downloadAndExtractRepoAsync({ username, name, branch, filePath }, output, props) {
|
|
156
161
|
const url = `https://codeload.github.com/${username}/${name}/tar.gz/${branch}`;
|