@expo/cli 0.4.10 → 0.5.0
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 +2 -2
- package/build/src/api/user/UserSettings.js +2 -2
- package/build/src/api/user/UserSettings.js.map +1 -1
- package/build/src/export/fork-bundleAsync.js +4 -2
- package/build/src/export/fork-bundleAsync.js.map +1 -1
- package/build/src/prebuild/writeMetroConfig.js +1 -1
- package/build/src/prebuild/writeMetroConfig.js.map +1 -1
- package/build/src/run/ios/appleDevice/AppleDevice.js +12 -17
- package/build/src/run/ios/appleDevice/AppleDevice.js.map +1 -1
- package/build/src/run/ios/appleDevice/client/LockdowndClient.js.map +1 -1
- package/build/src/run/ios/appleDevice/client/UsbmuxdClient.js.map +1 -1
- package/build/src/run/ios/options/promptDevice.js +1 -1
- package/build/src/run/ios/options/promptDevice.js.map +1 -1
- package/build/src/start/doctor/apple/XcodePrerequisite.js +3 -3
- package/build/src/start/doctor/apple/XcodePrerequisite.js.map +1 -1
- package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js +0 -4
- package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js.map +1 -1
- package/build/src/start/platforms/ExpoGoInstaller.js +5 -0
- package/build/src/start/platforms/ExpoGoInstaller.js.map +1 -1
- package/build/src/start/platforms/android/adb.js +2 -1
- package/build/src/start/platforms/android/adb.js.map +1 -1
- package/build/src/start/server/AsyncNgrok.js +2 -1
- package/build/src/start/server/AsyncNgrok.js.map +1 -1
- package/build/src/start/server/UrlCreator.js +3 -9
- package/build/src/start/server/UrlCreator.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +18 -1
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrors.js +14 -0
- package/build/src/start/server/metro/metroErrors.js.map +1 -0
- package/build/src/start/server/metro/withMetroMultiPlatform.js +25 -26
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/metro/withMetroResolvers.js +47 -0
- package/build/src/start/server/metro/withMetroResolvers.js.map +1 -0
- package/build/src/start/server/middleware/ClassicManifestMiddleware.js +2 -2
- package/build/src/start/server/middleware/ClassicManifestMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js +2 -2
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js.map +1 -1
- package/build/src/utils/analytics/rudderstackClient.js +2 -2
- package/build/src/utils/downloadExpoGoAsync.js +35 -10
- package/build/src/utils/downloadExpoGoAsync.js.map +1 -1
- package/build/src/utils/env.js +0 -10
- package/build/src/utils/env.js.map +1 -1
- package/build/src/utils/errors.js +3 -2
- package/build/src/utils/errors.js.map +1 -1
- package/build/src/utils/scheme.js +11 -2
- package/build/src/utils/scheme.js.map +1 -1
- package/package.json +14 -13
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.withWebResolvers = withWebResolvers;
|
|
6
|
+
exports.shouldAliasAssetRegistryForWeb = shouldAliasAssetRegistryForWeb;
|
|
6
7
|
exports.withMetroMultiPlatformAsync = withMetroMultiPlatformAsync;
|
|
7
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
9
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -11,6 +12,7 @@ var _env = require("../../../utils/env");
|
|
|
11
12
|
var _webSupportProjectPrerequisite = require("../../doctor/web/WebSupportProjectPrerequisite");
|
|
12
13
|
var _resolveFromProject = require("./resolveFromProject");
|
|
13
14
|
var _router = require("./router");
|
|
15
|
+
var _withMetroResolvers = require("./withMetroResolvers");
|
|
14
16
|
function _interopRequireDefault(obj) {
|
|
15
17
|
return obj && obj.__esModule ? obj : {
|
|
16
18
|
default: obj
|
|
@@ -34,29 +36,8 @@ function withWebPolyfills(config) {
|
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
return (context, moduleName, platform)=>{
|
|
40
|
-
return resolve(context, moduleName, platform);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/** Extend the `resolver.resolveRequest` method with custom methods that can exit early by returning a `Resolution`. */ function withCustomResolvers(config, projectRoot, resolvers) {
|
|
44
|
-
const originalResolveRequest = config.resolver.resolveRequest || getDefaultResolveRequest(projectRoot);
|
|
45
|
-
return {
|
|
46
|
-
...config,
|
|
47
|
-
resolver: {
|
|
48
|
-
...config.resolver,
|
|
49
|
-
resolveRequest (...args) {
|
|
50
|
-
for (const resolver of resolvers){
|
|
51
|
-
const resolution = resolver(...args);
|
|
52
|
-
if (resolution) {
|
|
53
|
-
return resolution;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return originalResolveRequest(...args);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
39
|
+
function normalizeSlashes(p) {
|
|
40
|
+
return p.replace(/\\/g, "/");
|
|
60
41
|
}
|
|
61
42
|
function withWebResolvers(config, projectRoot) {
|
|
62
43
|
// Get the `transformer.assetRegistryPath`
|
|
@@ -72,6 +53,11 @@ function withWebResolvers(config, projectRoot) {
|
|
|
72
53
|
"react-native": _path.default.resolve(require.resolve("react-native-web/package.json"), "..")
|
|
73
54
|
}
|
|
74
55
|
};
|
|
56
|
+
const aliases = {
|
|
57
|
+
web: {
|
|
58
|
+
"react-native": "react-native-web"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
75
61
|
const preferredMainFields = {
|
|
76
62
|
// Defaults from Expo Webpack. Most packages using `react-native` don't support web
|
|
77
63
|
// in the `react-native` field, so we should prefer the `browser` field.
|
|
@@ -82,15 +68,25 @@ function withWebResolvers(config, projectRoot) {
|
|
|
82
68
|
"main"
|
|
83
69
|
]
|
|
84
70
|
};
|
|
85
|
-
return
|
|
71
|
+
return (0, _withMetroResolvers).withMetroResolvers(config, projectRoot, [
|
|
86
72
|
// Add a resolver to alias the web asset resolver.
|
|
87
73
|
(immutableContext, moduleName, platform)=>{
|
|
88
74
|
const context = {
|
|
89
75
|
...immutableContext
|
|
90
76
|
};
|
|
77
|
+
// Conditionally remap `react-native` to `react-native-web` on web in
|
|
78
|
+
// a way that doesn't require Babel to resolve the alias.
|
|
79
|
+
if (platform && platform in aliases && aliases[platform][moduleName]) {
|
|
80
|
+
moduleName = aliases[platform][moduleName];
|
|
81
|
+
}
|
|
82
|
+
// TODO: We may be able to remove this in the future, it's doing no harm
|
|
83
|
+
// by staying here.
|
|
91
84
|
// Conditionally remap `react-native` to `react-native-web`
|
|
92
85
|
if (platform && platform in extraNodeModules) {
|
|
93
|
-
context.extraNodeModules =
|
|
86
|
+
context.extraNodeModules = {
|
|
87
|
+
...extraNodeModules[platform],
|
|
88
|
+
...context.extraNodeModules
|
|
89
|
+
};
|
|
94
90
|
}
|
|
95
91
|
const mainFields = _env.env.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE ? context.mainFields : platform && platform in preferredMainFields ? preferredMainFields[platform] : context.mainFields;
|
|
96
92
|
const result = resolve({
|
|
@@ -108,7 +104,7 @@ function withWebResolvers(config, projectRoot) {
|
|
|
108
104
|
}, moduleName, platform);
|
|
109
105
|
// Replace the web resolver with the original one.
|
|
110
106
|
// This is basically an alias for web-only.
|
|
111
|
-
if (platform
|
|
107
|
+
if (shouldAliasAssetRegistryForWeb(platform, result)) {
|
|
112
108
|
// @ts-expect-error: `readonly` for some reason.
|
|
113
109
|
result.filePath = assetRegistryPath;
|
|
114
110
|
}
|
|
@@ -116,6 +112,9 @@ function withWebResolvers(config, projectRoot) {
|
|
|
116
112
|
},
|
|
117
113
|
]);
|
|
118
114
|
}
|
|
115
|
+
function shouldAliasAssetRegistryForWeb(platform, result) {
|
|
116
|
+
return platform === "web" && (result == null ? void 0 : result.type) === "sourceFile" && typeof (result == null ? void 0 : result.filePath) === "string" && normalizeSlashes(result.filePath).endsWith("react-native-web/dist/modules/AssetRegistry/index.js");
|
|
117
|
+
}
|
|
119
118
|
async function withMetroMultiPlatformAsync(projectRoot, config, platformBundlers) {
|
|
120
119
|
// Auto pick App entry: this is injected with Babel.
|
|
121
120
|
process.env.EXPO_ROUTER_APP_ROOT = (0, _router).getAppRouterRelativeEntryPath(projectRoot);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/metro/withMetroMultiPlatform.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport { ConfigT } from 'metro-config';\nimport { ResolutionContext } from 'metro-resolver';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { env } from '../../../utils/env';\nimport { WebSupportProjectPrerequisite } from '../../doctor/web/WebSupportProjectPrerequisite';\nimport { PlatformBundlers } from '../platformBundlers';\nimport { importMetroResolverFromProject } from './resolveFromProject';\nimport { getAppRouterRelativeEntryPath } from './router';\n\nfunction withWebPolyfills(config: ConfigT): ConfigT {\n const originalGetPolyfills = config.serializer.getPolyfills\n ? config.serializer.getPolyfills.bind(config.serializer)\n : () => [];\n\n const getPolyfills = (ctx: { platform: string | null | undefined }): readonly string[] => {\n if (ctx.platform === 'web') {\n return [\n // TODO: runtime polyfills, i.e. Fast Refresh, error overlay, React Dev Tools...\n ];\n }\n // Generally uses `rn-get-polyfills`\n return originalGetPolyfills(ctx);\n };\n\n return {\n ...config,\n serializer: {\n ...config.serializer,\n getPolyfills,\n },\n };\n}\n\nfunction getDefaultResolveRequest(projectRoot: string) {\n const { resolve } = importMetroResolverFromProject(projectRoot);\n return (context: ResolutionContext, moduleName: string, platform: string | null) => {\n return resolve(context, moduleName, platform);\n };\n}\n\nexport type ExpoCustomMetroResolver = (\n ...args: Parameters<import('metro-resolver').CustomResolver>\n) => import('metro-resolver').Resolution | null;\n\n/** Extend the `resolver.resolveRequest` method with custom methods that can exit early by returning a `Resolution`. */\nfunction withCustomResolvers(\n config: ConfigT,\n projectRoot: string,\n resolvers: ExpoCustomMetroResolver[]\n): ConfigT {\n const originalResolveRequest =\n config.resolver.resolveRequest || getDefaultResolveRequest(projectRoot);\n\n return {\n ...config,\n resolver: {\n ...config.resolver,\n resolveRequest(...args: Parameters<import('metro-resolver').CustomResolver>) {\n for (const resolver of resolvers) {\n const resolution = resolver(...args);\n if (resolution) {\n return resolution;\n }\n }\n return originalResolveRequest(...args);\n },\n },\n };\n}\n\n/**\n * Apply custom resolvers to do the following:\n * - Disable `.native.js` extensions on web.\n * - Alias `react-native` to `react-native-web` on web.\n * - Redirect `react-native-web/dist/modules/AssetRegistry/index.js` to `@react-native/assets/registry.js` on web.\n */\nexport function withWebResolvers(config: ConfigT, projectRoot: string) {\n // Get the `transformer.assetRegistryPath`\n // this needs to be unified since you can't dynamically\n // swap out the transformer based on platform.\n const assetRegistryPath = fs.realpathSync(\n // This is the native asset registry alias for native.\n path.resolve(resolveFrom(projectRoot, 'react-native/Libraries/Image/AssetRegistry'))\n // NOTE(EvanBacon): This is the newer import but it doesn't work in the expo/expo monorepo.\n // path.resolve(resolveFrom(projectRoot, '@react-native/assets/registry.js'))\n );\n\n // Create a resolver which dynamically disables support for\n // `*.native.*` extensions on web.\n\n const { resolve } = importMetroResolverFromProject(projectRoot);\n\n const extraNodeModules: { [key: string]: Record<string, string> } = {\n web: {\n 'react-native': path.resolve(require.resolve('react-native-web/package.json'), '..'),\n },\n };\n\n const preferredMainFields: { [key: string]: string[] } = {\n // Defaults from Expo Webpack. Most packages using `react-native` don't support web\n // in the `react-native` field, so we should prefer the `browser` field.\n // https://github.com/expo/router/issues/37\n web: ['browser', 'module', 'main'],\n };\n\n return withCustomResolvers(config, projectRoot, [\n // Add a resolver to alias the web asset resolver.\n (immutableContext: ResolutionContext, moduleName: string, platform: string | null) => {\n const context = { ...immutableContext } as ResolutionContext & { mainFields: string[] };\n\n // Conditionally remap `react-native` to `react-native-web`\n if (platform && platform in extraNodeModules) {\n context.extraNodeModules = extraNodeModules[platform];\n }\n\n const mainFields = env.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE\n ? context.mainFields\n : platform && platform in preferredMainFields\n ? preferredMainFields[platform]\n : context.mainFields;\n\n const result = resolve(\n {\n ...context,\n preferNativePlatform: platform !== 'web',\n resolveRequest: undefined,\n\n // Passing `mainFields` directly won't be considered\n // we need to extend the `getPackageMainPath` directly to\n // use platform specific `mainFields`.\n getPackageMainPath(packageJsonPath) {\n // @ts-expect-error: mainFields is not on type\n const package_ = context.moduleCache.getPackage(packageJsonPath);\n return package_.getMain(mainFields);\n },\n },\n moduleName,\n platform\n );\n\n // Replace the web resolver with the original one.\n // This is basically an alias for web-only.\n if (\n platform === 'web' &&\n result?.type === 'sourceFile' &&\n typeof result?.filePath === 'string' &&\n result.filePath.endsWith('react-native-web/dist/modules/AssetRegistry/index.js')\n ) {\n // @ts-expect-error: `readonly` for some reason.\n result.filePath = assetRegistryPath;\n }\n\n return result;\n },\n ]);\n}\n\n/** Add support for `react-native-web` and the Web platform. */\nexport async function withMetroMultiPlatformAsync(\n projectRoot: string,\n config: ConfigT,\n platformBundlers: PlatformBundlers\n) {\n // Auto pick App entry: this is injected with Babel.\n process.env.EXPO_ROUTER_APP_ROOT = getAppRouterRelativeEntryPath(projectRoot);\n process.env.EXPO_PROJECT_ROOT = process.env.EXPO_PROJECT_ROOT ?? projectRoot;\n\n if (platformBundlers.web === 'metro') {\n await new WebSupportProjectPrerequisite(projectRoot).assertAsync();\n } else {\n // Bail out early for performance enhancements if web is not enabled.\n return config;\n }\n\n return withMetroMultiPlatform(projectRoot, config, platformBundlers);\n}\n\nfunction withMetroMultiPlatform(\n projectRoot: string,\n config: ConfigT,\n platformBundlers: PlatformBundlers\n) {\n let expoConfigPlatforms = Object.entries(platformBundlers)\n .filter(([, bundler]) => bundler === 'metro')\n .map(([platform]) => platform);\n\n if (Array.isArray(config.resolver.platforms)) {\n expoConfigPlatforms = [...new Set(expoConfigPlatforms.concat(config.resolver.platforms))];\n }\n\n // @ts-expect-error: typed as `readonly`.\n config.resolver.platforms = expoConfigPlatforms;\n\n config = withWebPolyfills(config);\n\n return withWebResolvers(config, projectRoot);\n}\n"],"names":["withWebResolvers","withMetroMultiPlatformAsync","withWebPolyfills","config","originalGetPolyfills","serializer","getPolyfills","bind","ctx","platform","getDefaultResolveRequest","projectRoot","resolve","importMetroResolverFromProject","context","moduleName","withCustomResolvers","resolvers","originalResolveRequest","resolver","resolveRequest","args","resolution","assetRegistryPath","fs","realpathSync","path","resolveFrom","extraNodeModules","web","require","preferredMainFields","immutableContext","mainFields","env","EXPO_METRO_NO_MAIN_FIELD_OVERRIDE","result","preferNativePlatform","undefined","getPackageMainPath","packageJsonPath","package_","moduleCache","getPackage","getMain","type","filePath","endsWith","platformBundlers","process","EXPO_ROUTER_APP_ROOT","getAppRouterRelativeEntryPath","EXPO_PROJECT_ROOT","WebSupportProjectPrerequisite","assertAsync","withMetroMultiPlatform","expoConfigPlatforms","Object","entries","filter","bundler","map","Array","isArray","platforms","Set","concat"],"mappings":"AAMA;;;;QA+EgBA,gBAAgB,GAAhBA,gBAAgB;QAkFVC,2BAA2B,GAA3BA,2BAA2B;AAjKlC,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAGF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAElB,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACM,IAAA,8BAAgD,WAAhD,gDAAgD,CAAA;AAE/C,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACvB,IAAA,OAAU,WAAV,UAAU,CAAA;;;;;;AAExD,SAASC,gBAAgB,CAACC,MAAe,EAAW;IAClD,MAAMC,oBAAoB,GAAGD,MAAM,CAACE,UAAU,CAACC,YAAY,GACvDH,MAAM,CAACE,UAAU,CAACC,YAAY,CAACC,IAAI,CAACJ,MAAM,CAACE,UAAU,CAAC,GACtD,IAAM,EAAE;IAAC;IAEb,MAAMC,YAAY,GAAG,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IAE7E,IAAIqC,gBAAgB,CAACnB,GAAG,KAAK,OAAO,EAAE;QACpC,MAAM,IAAIwB,8BAA6B,8BAAA,CAAC1C,WAAW,CAAC,CAAC2C,WAAW,EAAE,CAAC;KACpE,MAAM;QACL,qEAAqE;QACrE,OAAOnD,MAAM,CAAC;KACf;IAED,OAAOoD,sBAAsB,CAAC5C,WAAW,EAAER,MAAM,EAAE6C,gBAAgB,CAAC,CAAC;CACtE;AAED,SAASO,sBAAsB,CAC7B5C,WAAmB,EACnBR,MAAe,EACf6C,gBAAkC,EAClC;IACA,IAAIQ,mBAAmB,GAAGC,MAAM,CAACC,OAAO,CAACV,gBAAgB,CAAC,CACvDW,MAAM,CAAC,CAAC,GAAGC,OAAO,CAAC,GAAKA,OAAO,KAAK,OAAO;IAAA,CAAC,CAC5CC,GAAG,CAAC,CAAC,CAACpD,QAAQ,CAAC,GAAKA,QAAQ;IAAA,CAAC,AAAC;IAEjC,IAAIqD,KAAK,CAACC,OAAO,CAAC5D,MAAM,CAACgB,QAAQ,CAAC6C,SAAS,CAAC,EAAE;QAC5CR,mBAAmB,GAAG;eAAI,IAAIS,GAAG,CAACT,mBAAmB,CAACU,MAAM,CAAC/D,MAAM,CAACgB,QAAQ,CAAC6C,SAAS,CAAC,CAAC;SAAC,CAAC;KAC3F;IAED,yCAAyC;IACzC7D,MAAM,CAACgB,QAAQ,CAAC6C,SAAS,GAAGR,mBAAmB,CAAC;IAEhDrD,MAAM,GAAGD,gBAAgB,CAACC,MAAM,CAAC,CAAC;IAElC,OAAOH,gBAAgB,CAACG,MAAM,EAAEQ,WAAW,CAAC,CAAC;CAC9C"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/withMetroMultiPlatform.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport fs from 'fs';\nimport { ConfigT } from 'metro-config';\nimport { Resolution, ResolutionContext } from 'metro-resolver';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { env } from '../../../utils/env';\nimport { WebSupportProjectPrerequisite } from '../../doctor/web/WebSupportProjectPrerequisite';\nimport { PlatformBundlers } from '../platformBundlers';\nimport { importMetroResolverFromProject } from './resolveFromProject';\nimport { getAppRouterRelativeEntryPath } from './router';\nimport { withMetroResolvers } from './withMetroResolvers';\n\nfunction withWebPolyfills(config: ConfigT): ConfigT {\n const originalGetPolyfills = config.serializer.getPolyfills\n ? config.serializer.getPolyfills.bind(config.serializer)\n : () => [];\n\n const getPolyfills = (ctx: { platform: string | null | undefined }): readonly string[] => {\n if (ctx.platform === 'web') {\n return [\n // TODO: runtime polyfills, i.e. Fast Refresh, error overlay, React Dev Tools...\n ];\n }\n // Generally uses `rn-get-polyfills`\n return originalGetPolyfills(ctx);\n };\n\n return {\n ...config,\n serializer: {\n ...config.serializer,\n getPolyfills,\n },\n };\n}\n\nfunction normalizeSlashes(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\n/**\n * Apply custom resolvers to do the following:\n * - Disable `.native.js` extensions on web.\n * - Alias `react-native` to `react-native-web` on web.\n * - Redirect `react-native-web/dist/modules/AssetRegistry/index.js` to `@react-native/assets/registry.js` on web.\n */\nexport function withWebResolvers(config: ConfigT, projectRoot: string) {\n // Get the `transformer.assetRegistryPath`\n // this needs to be unified since you can't dynamically\n // swap out the transformer based on platform.\n const assetRegistryPath = fs.realpathSync(\n // This is the native asset registry alias for native.\n path.resolve(resolveFrom(projectRoot, 'react-native/Libraries/Image/AssetRegistry'))\n // NOTE(EvanBacon): This is the newer import but it doesn't work in the expo/expo monorepo.\n // path.resolve(resolveFrom(projectRoot, '@react-native/assets/registry.js'))\n );\n\n // Create a resolver which dynamically disables support for\n // `*.native.*` extensions on web.\n\n const { resolve } = importMetroResolverFromProject(projectRoot);\n\n const extraNodeModules: { [key: string]: Record<string, string> } = {\n web: {\n 'react-native': path.resolve(require.resolve('react-native-web/package.json'), '..'),\n },\n };\n\n const aliases: { [key: string]: Record<string, string> } = {\n web: {\n 'react-native': 'react-native-web',\n },\n };\n\n const preferredMainFields: { [key: string]: string[] } = {\n // Defaults from Expo Webpack. Most packages using `react-native` don't support web\n // in the `react-native` field, so we should prefer the `browser` field.\n // https://github.com/expo/router/issues/37\n web: ['browser', 'module', 'main'],\n };\n\n return withMetroResolvers(config, projectRoot, [\n // Add a resolver to alias the web asset resolver.\n (immutableContext: ResolutionContext, moduleName: string, platform: string | null) => {\n const context = { ...immutableContext } as ResolutionContext & { mainFields: string[] };\n\n // Conditionally remap `react-native` to `react-native-web` on web in\n // a way that doesn't require Babel to resolve the alias.\n if (platform && platform in aliases && aliases[platform][moduleName]) {\n moduleName = aliases[platform][moduleName];\n }\n\n // TODO: We may be able to remove this in the future, it's doing no harm\n // by staying here.\n // Conditionally remap `react-native` to `react-native-web`\n if (platform && platform in extraNodeModules) {\n context.extraNodeModules = {\n ...extraNodeModules[platform],\n ...context.extraNodeModules,\n };\n }\n\n const mainFields = env.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE\n ? context.mainFields\n : platform && platform in preferredMainFields\n ? preferredMainFields[platform]\n : context.mainFields;\n\n const result = resolve(\n {\n ...context,\n preferNativePlatform: platform !== 'web',\n resolveRequest: undefined,\n\n // Passing `mainFields` directly won't be considered\n // we need to extend the `getPackageMainPath` directly to\n // use platform specific `mainFields`.\n getPackageMainPath(packageJsonPath) {\n // @ts-expect-error: mainFields is not on type\n const package_ = context.moduleCache.getPackage(packageJsonPath);\n return package_.getMain(mainFields);\n },\n },\n moduleName,\n platform\n );\n\n // Replace the web resolver with the original one.\n // This is basically an alias for web-only.\n if (shouldAliasAssetRegistryForWeb(platform, result)) {\n // @ts-expect-error: `readonly` for some reason.\n result.filePath = assetRegistryPath;\n }\n\n return result;\n },\n ]);\n}\n\n/** @returns `true` if the incoming resolution should be swapped on web. */\nexport function shouldAliasAssetRegistryForWeb(\n platform: string | null,\n result: Resolution\n): boolean {\n return (\n platform === 'web' &&\n result?.type === 'sourceFile' &&\n typeof result?.filePath === 'string' &&\n normalizeSlashes(result.filePath).endsWith(\n 'react-native-web/dist/modules/AssetRegistry/index.js'\n )\n );\n}\n\n/** Add support for `react-native-web` and the Web platform. */\nexport async function withMetroMultiPlatformAsync(\n projectRoot: string,\n config: ConfigT,\n platformBundlers: PlatformBundlers\n) {\n // Auto pick App entry: this is injected with Babel.\n process.env.EXPO_ROUTER_APP_ROOT = getAppRouterRelativeEntryPath(projectRoot);\n process.env.EXPO_PROJECT_ROOT = process.env.EXPO_PROJECT_ROOT ?? projectRoot;\n\n if (platformBundlers.web === 'metro') {\n await new WebSupportProjectPrerequisite(projectRoot).assertAsync();\n } else {\n // Bail out early for performance enhancements if web is not enabled.\n return config;\n }\n\n return withMetroMultiPlatform(projectRoot, config, platformBundlers);\n}\n\nfunction withMetroMultiPlatform(\n projectRoot: string,\n config: ConfigT,\n platformBundlers: PlatformBundlers\n) {\n let expoConfigPlatforms = Object.entries(platformBundlers)\n .filter(([, bundler]) => bundler === 'metro')\n .map(([platform]) => platform);\n\n if (Array.isArray(config.resolver.platforms)) {\n expoConfigPlatforms = [...new Set(expoConfigPlatforms.concat(config.resolver.platforms))];\n }\n\n // @ts-expect-error: typed as `readonly`.\n config.resolver.platforms = expoConfigPlatforms;\n\n config = withWebPolyfills(config);\n\n return withWebResolvers(config, projectRoot);\n}\n"],"names":["withWebResolvers","shouldAliasAssetRegistryForWeb","withMetroMultiPlatformAsync","withWebPolyfills","config","originalGetPolyfills","serializer","getPolyfills","bind","ctx","platform","normalizeSlashes","p","replace","projectRoot","assetRegistryPath","fs","realpathSync","path","resolve","resolveFrom","importMetroResolverFromProject","extraNodeModules","web","require","aliases","preferredMainFields","withMetroResolvers","immutableContext","moduleName","context","mainFields","env","EXPO_METRO_NO_MAIN_FIELD_OVERRIDE","result","preferNativePlatform","resolveRequest","undefined","getPackageMainPath","packageJsonPath","package_","moduleCache","getPackage","getMain","filePath","type","endsWith","platformBundlers","process","EXPO_ROUTER_APP_ROOT","getAppRouterRelativeEntryPath","EXPO_PROJECT_ROOT","WebSupportProjectPrerequisite","assertAsync","withMetroMultiPlatform","expoConfigPlatforms","Object","entries","filter","bundler","map","Array","isArray","resolver","platforms","Set","concat"],"mappings":"AAMA;;;;QA+CgBA,gBAAgB,GAAhBA,gBAAgB;QA8FhBC,8BAA8B,GAA9BA,8BAA8B;QAexBC,2BAA2B,GAA3BA,2BAA2B;AA5JlC,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAGF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAElB,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACM,IAAA,8BAAgD,WAAhD,gDAAgD,CAAA;AAE/C,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACvB,IAAA,OAAU,WAAV,UAAU,CAAA;AACrB,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;;;;;;AAEzD,SAASC,gBAAgB,CAACC,MAAe,EAAW;IAClD,MAAMC,oBAAoB,GAAGD,MAAM,CAACE,UAAU,CAACC,YAAY,GACvDH,MAAM,CAACE,UAAU,CAACC,YAAY,CAACC,IAAI,CAACJ,MAAM,CAACE,UAAU,CAAC,GACtD,IAAM,EAAE;IAAC;IAEb,MAAMC,YAAY,GAAG,CAACE,GAA4C,GAAwB;QACxF,IAAIA,GAAG,CAACC,QAAQ,KAAK,KAAK,EAAE;YAC1B,OAAO,EAEN,CAAC;SACH;QACD,oCAAoC;QACpC,OAAOL,oBAAoB,CAACI,GAAG,CAAC,CAAC;KAClC,AAAC;IAEF,OAAO;QACL,GAAGL,MAAM;QACTE,UAAU,EAAE;YACV,GAAGF,MAAM,CAACE,UAAU;YACpBC,YAAY;SACb;KACF,CAAC;CACH;AAED,SAASI,gBAAgB,CAACC,CAAS,EAAE;IACnC,OAAOA,CAAC,CAACC,OAAO,QAAQ,GAAG,CAAC,CAAC;CAC9B;AAQM,SAASb,gBAAgB,CAAC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AC1D,MAAM,CAAC2D,QAAQ,CAACC,SAAS,CAAC,EAAE;QAC5CT,mBAAmB,GAAG;eAAI,IAAIU,GAAG,CAACV,mBAAmB,CAACW,MAAM,CAAC9D,MAAM,CAAC2D,QAAQ,CAACC,SAAS,CAAC,CAAC;SAAC,CAAC;KAC3F;IAED,yCAAyC;IACzC5D,MAAM,CAAC2D,QAAQ,CAACC,SAAS,GAAGT,mBAAmB,CAAC;IAEhDnD,MAAM,GAAGD,gBAAgB,CAACC,MAAM,CAAC,CAAC;IAElC,OAAOJ,gBAAgB,CAACI,MAAM,EAAEU,WAAW,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.getDefaultMetroResolver = getDefaultMetroResolver;
|
|
6
|
+
exports.withMetroResolvers = withMetroResolvers;
|
|
7
|
+
var _metroErrors = require("./metroErrors");
|
|
8
|
+
var _resolveFromProject = require("./resolveFromProject");
|
|
9
|
+
const debug = require("debug")("expo:metro:withMetroResolvers");
|
|
10
|
+
function getDefaultMetroResolver(projectRoot) {
|
|
11
|
+
const { resolve } = (0, _resolveFromProject).importMetroResolverFromProject(projectRoot);
|
|
12
|
+
return (context, moduleName, platform)=>{
|
|
13
|
+
return resolve(context, moduleName, platform);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function withMetroResolvers(config, projectRoot, resolvers) {
|
|
17
|
+
debug(`Appending ${resolvers.length} custom resolvers to Metro config. (has custom resolver: ${!!config.resolver.resolveRequest})`);
|
|
18
|
+
const originalResolveRequest = config.resolver.resolveRequest || getDefaultMetroResolver(projectRoot);
|
|
19
|
+
return {
|
|
20
|
+
...config,
|
|
21
|
+
resolver: {
|
|
22
|
+
...config.resolver,
|
|
23
|
+
resolveRequest (...args) {
|
|
24
|
+
for (const resolver of resolvers){
|
|
25
|
+
try {
|
|
26
|
+
const resolution = resolver(...args);
|
|
27
|
+
if (resolution) {
|
|
28
|
+
return resolution;
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// If the error is directly related to a resolver not being able to resolve a module, then
|
|
32
|
+
// we can ignore the error and try the next resolver. Otherwise, we should throw the error.
|
|
33
|
+
const isResolutionError = (0, _metroErrors).isFailedToResolveNameError(error) || (0, _metroErrors).isFailedToResolvePathError(error);
|
|
34
|
+
if (!isResolutionError) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
debug(`Custom resolver threw: ${error.constructor.name}. (module: ${args[1]}, platform: ${args[2]})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// If we haven't returned by now, use the original resolver or upstream resolver.
|
|
41
|
+
return originalResolveRequest(...args);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=withMetroResolvers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/metro/withMetroResolvers.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { ConfigT as MetroConfig } from 'metro-config';\nimport { ResolutionContext } from 'metro-resolver';\n\nimport { isFailedToResolveNameError, isFailedToResolvePathError } from './metroErrors';\nimport { importMetroResolverFromProject } from './resolveFromProject';\n\nconst debug = require('debug')('expo:metro:withMetroResolvers') as typeof console.log;\n\nexport type MetroResolver = NonNullable<MetroConfig['resolver']['resolveRequest']>;\n\n/** Expo Metro Resolvers can return `null` to skip without throwing an error. Metro Resolvers will throw either a `FailedToResolveNameError` or `FailedToResolvePathError`. */\nexport type ExpoCustomMetroResolver = (\n ...args: Parameters<MetroResolver>\n) => ReturnType<MetroResolver> | null;\n\n/** @returns `MetroResolver` utilizing the upstream `resolve` method. */\nexport function getDefaultMetroResolver(projectRoot: string): MetroResolver {\n const { resolve } = importMetroResolverFromProject(projectRoot);\n return (context: ResolutionContext, moduleName: string, platform: string | null) => {\n return resolve(context, moduleName, platform);\n };\n}\n\n/**\n * Extend the Metro config `resolver.resolveRequest` method with additional resolvers that can\n * exit early by returning a `Resolution` or skip to the next resolver by returning `null`.\n *\n * @param config Metro config.\n * @param projectRoot path to the project root used to resolve the default Metro resolver.\n * @param resolvers custom MetroResolver to chain.\n * @returns a new `MetroConfig` with the `resolver.resolveRequest` method chained.\n */\nexport function withMetroResolvers(\n config: MetroConfig,\n projectRoot: string,\n resolvers: ExpoCustomMetroResolver[]\n): MetroConfig {\n debug(\n `Appending ${\n resolvers.length\n } custom resolvers to Metro config. (has custom resolver: ${!!config.resolver.resolveRequest})`\n );\n const originalResolveRequest =\n config.resolver.resolveRequest || getDefaultMetroResolver(projectRoot);\n\n return {\n ...config,\n resolver: {\n ...config.resolver,\n resolveRequest(...args: Parameters<MetroResolver>) {\n for (const resolver of resolvers) {\n try {\n const resolution = resolver(...args);\n if (resolution) {\n return resolution;\n }\n } catch (error: any) {\n // If the error is directly related to a resolver not being able to resolve a module, then\n // we can ignore the error and try the next resolver. Otherwise, we should throw the error.\n const isResolutionError =\n isFailedToResolveNameError(error) || isFailedToResolvePathError(error);\n if (!isResolutionError) {\n throw error;\n }\n debug(\n `Custom resolver threw: ${error.constructor.name}. (module: ${args[1]}, platform: ${args[2]})`\n );\n }\n }\n // If we haven't returned by now, use the original resolver or upstream resolver.\n return originalResolveRequest(...args);\n },\n },\n };\n}\n"],"names":["getDefaultMetroResolver","withMetroResolvers","debug","require","projectRoot","resolve","importMetroResolverFromProject","context","moduleName","platform","config","resolvers","length","resolver","resolveRequest","originalResolveRequest","args","resolution","error","isResolutionError","isFailedToResolveNameError","isFailedToResolvePathError","constructor","name"],"mappings":"AAMA;;;;QAgBgBA,uBAAuB,GAAvBA,uBAAuB;QAgBvBC,kBAAkB,GAAlBA,kBAAkB;AA7BqC,IAAA,YAAe,WA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AAA,GAAAA,YAA0B,AAAO,CAAA,2BAAP,CAACH,KAAK,CAAC,AAAC;wBACzE,IAAI,CAACC,iBAAiB,EAAE;4BACtB,MAAMD,KAAK,CAAC;yBACb;wBACDhB,KAAK,CACH,CAAC,uBAAuB,EAAEgB,KAAK,CAACI,WAAW,CAACC,IAAI,CAAC,WAAW,EAAEP,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,EAAEA,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC/F,CAAC;qBACH;iBACF;gBACD,iFAAiF;gBACjF,OAAOD,sBAAsB,IAAIC,IAAI,CAAC,CAAC;aACxC;SACF;KACF,CAAC;CACH"}
|
|
@@ -63,7 +63,7 @@ class ClassicManifestMiddleware extends _manifestMiddleware.ManifestMiddleware {
|
|
|
63
63
|
// Gather packager and host info
|
|
64
64
|
const hostInfo = await createHostInfoAsync();
|
|
65
65
|
const headers = new Map();
|
|
66
|
-
headers.set("Exponent-Server", hostInfo);
|
|
66
|
+
headers.set("Exponent-Server", JSON.stringify(hostInfo));
|
|
67
67
|
// Create the final string
|
|
68
68
|
const body = await this._fetchComputedManifestStringAsync({
|
|
69
69
|
manifest,
|
|
@@ -130,7 +130,7 @@ async function createHostInfoAsync() {
|
|
|
130
130
|
host: await _userSettings.default.getAnonymousIdentifierAsync(),
|
|
131
131
|
server: "expo",
|
|
132
132
|
// Defined in the build step
|
|
133
|
-
serverVersion: "0.
|
|
133
|
+
serverVersion: "0.5.0",
|
|
134
134
|
serverDriver: _manifestMiddleware.DEVELOPER_TOOL,
|
|
135
135
|
serverOS: _os.default.platform(),
|
|
136
136
|
serverOSVersion: _os.default.release()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/middleware/ClassicManifestMiddleware.ts"],"sourcesContent":["import { ExpoAppManifest, ExpoConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport os from 'os';\n\nimport { APISettings } from '../../../api/settings';\nimport { signClassicExpoGoManifestAsync } from '../../../api/signManifest';\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME, getUserAsync } from '../../../api/user/user';\nimport * as Log from '../../../log';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport { memoize } from '../../../utils/fn';\nimport { learnMore } from '../../../utils/link';\nimport { stripPort } from '../../../utils/url';\nimport {\n DEVELOPER_TOOL,\n HostInfo,\n ManifestMiddleware,\n ManifestRequestInfo,\n} from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\n\ntype SignManifestProps = {\n manifest: ExpoAppManifest;\n hostId: string;\n acceptSignature: boolean;\n};\n\ninterface ClassicManifestRequestInfo extends ManifestRequestInfo {}\n\nconst debug = require('debug')(\n 'expo:start:server:middleware:ClassicManifestMiddleware'\n) as typeof console.log;\n\nexport class ClassicManifestMiddleware extends ManifestMiddleware<ClassicManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ClassicManifestRequestInfo {\n const platform = parsePlatformHeader(req) || 'ios';\n assertRuntimePlatform(platform);\n return {\n platform,\n acceptSignature: Boolean(req.headers['exponent-accept-signature']),\n hostname: stripPort(req.headers['host']),\n };\n }\n\n public async _getManifestResponseAsync({\n acceptSignature,\n ...requestOptions\n }: ClassicManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const manifest: ExpoAppManifest = {\n ...(exp as ExpoAppManifest),\n ...expoGoConfig,\n hostUri,\n bundleUrl,\n };\n\n // Gather packager and host info\n const hostInfo = await createHostInfoAsync();\n\n const headers = new Map<string, any>();\n headers.set('Exponent-Server', hostInfo);\n\n // Create the final string\n const body = await this._fetchComputedManifestStringAsync({\n manifest,\n hostId: hostInfo.host,\n acceptSignature,\n });\n\n return {\n body,\n version: manifest.sdkVersion,\n headers,\n };\n }\n\n protected trackManifest(version?: string) {\n // Log analytics\n logEventAsync('Serve Manifest', {\n sdkVersion: version ?? null,\n });\n }\n\n /** Exposed for testing. */\n async _getManifestStringAsync({\n manifest,\n hostId,\n acceptSignature,\n }: SignManifestProps): Promise<string> {\n const currentSession = await getUserAsync();\n if (!currentSession || APISettings.isOffline) {\n manifest.id = `@${ANONYMOUS_USERNAME}/${manifest.slug}-${hostId}`;\n }\n if (!acceptSignature) {\n return JSON.stringify(manifest);\n } else if (!currentSession || APISettings.isOffline) {\n return getUnsignedManifestString(manifest);\n } else {\n return this.getSignedManifestStringAsync(manifest);\n }\n }\n\n private getSignedManifestStringAsync = memoize(signClassicExpoGoManifestAsync);\n\n /** Exposed for testing. */\n async _fetchComputedManifestStringAsync(props: SignManifestProps): Promise<string> {\n try {\n return await this._getManifestStringAsync(props);\n } catch (error: any) {\n debug(`Error getting manifest:`, error);\n if (error.code === 'UNAUTHORIZED' && props.manifest.owner) {\n // Don't have permissions for siging, warn and enable offline mode.\n this.addSigningDisabledWarning(\n `This project belongs to ${chalk.bold(\n `@${props.manifest.owner}`\n )} and you have not been granted the appropriate permissions.\\n` +\n `Please request access from an admin of @${props.manifest.owner} or change the \"owner\" field to an account you belong to.\\n` +\n learnMore('https://docs.expo.dev/versions/latest/config/app/#owner')\n );\n APISettings.isOffline = true;\n return await this._getManifestStringAsync(props);\n } else if (error.code === 'ENOTFOUND') {\n // Got a DNS error, i.e. can't access exp.host, warn and enable offline mode.\n this.addSigningDisabledWarning(\n `Could not reach Expo servers, please check if you can access ${\n error.hostname || 'exp.host'\n }.`\n );\n APISettings.isOffline = true;\n return await this._getManifestStringAsync(props);\n } else {\n throw error;\n }\n }\n }\n\n private addSigningDisabledWarning = memoize((reason: string) => {\n Log.warn(`${reason}\\nFalling back to offline mode.`);\n // For the memo\n return reason;\n });\n}\n\n// Passed to Expo Go and registered as telemetry.\n// TODO: it's unclear why we don't just send it from the CLI.\nasync function createHostInfoAsync(): Promise<HostInfo> {\n return {\n host: await UserSettings.getAnonymousIdentifierAsync(),\n server: 'expo',\n // Defined in the build step\n serverVersion: process.env.__EXPO_VERSION!,\n serverDriver: DEVELOPER_TOOL,\n serverOS: os.platform(),\n serverOSVersion: os.release(),\n };\n}\n\nfunction getUnsignedManifestString(manifest: ExpoConfig) {\n const unsignedManifest = {\n manifestString: JSON.stringify(manifest),\n signature: 'UNSIGNED',\n };\n return JSON.stringify(unsignedManifest);\n}\n"],"names":["Log","debug","require","ClassicManifestMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","acceptSignature","Boolean","headers","hostname","stripPort","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","manifest","hostInfo","createHostInfoAsync","Map","set","body","_fetchComputedManifestStringAsync","hostId","host","version","sdkVersion","trackManifest","logEventAsync","_getManifestStringAsync","currentSession","getUserAsync","APISettings","isOffline","id","ANONYMOUS_USERNAME","slug","JSON","stringify","getUnsignedManifestString","getSignedManifestStringAsync","memoize","signClassicExpoGoManifestAsync","props","error","code","owner","addSigningDisabledWarning","chalk","bold","learnMore","reason","warn","UserSettings","getAnonymousIdentifierAsync","server","serverVersion","process","env","__EXPO_VERSION","serverDriver","DEVELOPER_TOOL","serverOS","os","serverOSVersion","release","unsignedManifest","manifestString","signature"],"mappings":"AAAA;;;;AACkB,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAES,IAAA,SAAuB,WAAvB,uBAAuB,CAAA;AACJ,IAAA,aAA2B,WAA3B,2BAA2B,CAAA;AACjD,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACR,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC7DA,IAAAA,GAAG,mCAAM,cAAc,EAApB;AACe,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAClD,IAAA,GAAmB,WAAnB,mBAAmB,CAAA;AACjB,IAAA,KAA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ACb;SACF;KACF;IAED,AAAQG,yBAAyB,GAAGN,CAAAA,GAAAA,GAAO,AAIzC,CAAA,QAJyC,CAAC,CAACU,MAAc,GAAK;QAC9DzD,GAAG,CAAC0D,IAAI,CAAC,CAAC,EAAED,MAAM,CAAC,+BAA+B,CAAC,CAAC,CAAC;QACrD,eAAe;QACf,OAAOA,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;QAnHYtD,yBAAyB,GAAzBA,yBAAyB;AAqHtC,iDAAiD;AACjD,6DAA6D;AAC7D,eAAeqB,mBAAmB,GAAsB;IACtD,OAAO;QACLM,IAAI,EAAE,MAAM6B,aAAY,QAAA,CAACC,2BAA2B,EAAE;QACtDC,MAAM,EAAE,MAAM;QACd,4BAA4B;QAC5BC,aAAa,EAAEC,OAAO,CAACC,GAAG,CAACC,cAAc;QACzCC,YAAY,EAAEC,mBAAc,eAAA;QAC5BC,QAAQ,EAAEC,GAAE,QAAA,CAAC9D,QAAQ,EAAE;QACvB+D,eAAe,EAAED,GAAE,QAAA,CAACE,OAAO,EAAE;KAC9B,CAAC;CACH;AAED,SAAS1B,yBAAyB,CAACvB,QAAoB,EAAE;IACvD,MAAMkD,gBAAgB,GAAG;QACvBC,cAAc,EAAE9B,IAAI,CAACC,SAAS,CAACtB,QAAQ,CAAC;QACxCoD,SAAS,EAAE,UAAU;KACtB,AAAC;IACF,OAAO/B,IAAI,CAACC,SAAS,CAAC4B,gBAAgB,CAAC,CAAC;CACzC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/ClassicManifestMiddleware.ts"],"sourcesContent":["import { ExpoAppManifest, ExpoConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport os from 'os';\n\nimport { APISettings } from '../../../api/settings';\nimport { signClassicExpoGoManifestAsync } from '../../../api/signManifest';\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME, getUserAsync } from '../../../api/user/user';\nimport * as Log from '../../../log';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport { memoize } from '../../../utils/fn';\nimport { learnMore } from '../../../utils/link';\nimport { stripPort } from '../../../utils/url';\nimport {\n DEVELOPER_TOOL,\n HostInfo,\n ManifestMiddleware,\n ManifestRequestInfo,\n} from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\n\ntype SignManifestProps = {\n manifest: ExpoAppManifest;\n hostId: string;\n acceptSignature: boolean;\n};\n\ninterface ClassicManifestRequestInfo extends ManifestRequestInfo {}\n\nconst debug = require('debug')(\n 'expo:start:server:middleware:ClassicManifestMiddleware'\n) as typeof console.log;\n\nexport class ClassicManifestMiddleware extends ManifestMiddleware<ClassicManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ClassicManifestRequestInfo {\n const platform = parsePlatformHeader(req) || 'ios';\n assertRuntimePlatform(platform);\n return {\n platform,\n acceptSignature: Boolean(req.headers['exponent-accept-signature']),\n hostname: stripPort(req.headers['host']),\n };\n }\n\n public async _getManifestResponseAsync({\n acceptSignature,\n ...requestOptions\n }: ClassicManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const manifest: ExpoAppManifest = {\n ...(exp as ExpoAppManifest),\n ...expoGoConfig,\n hostUri,\n bundleUrl,\n };\n\n // Gather packager and host info\n const hostInfo = await createHostInfoAsync();\n\n const headers = new Map<string, any>();\n headers.set('Exponent-Server', JSON.stringify(hostInfo));\n\n // Create the final string\n const body = await this._fetchComputedManifestStringAsync({\n manifest,\n hostId: hostInfo.host,\n acceptSignature,\n });\n\n return {\n body,\n version: manifest.sdkVersion,\n headers,\n };\n }\n\n protected trackManifest(version?: string) {\n // Log analytics\n logEventAsync('Serve Manifest', {\n sdkVersion: version ?? null,\n });\n }\n\n /** Exposed for testing. */\n async _getManifestStringAsync({\n manifest,\n hostId,\n acceptSignature,\n }: SignManifestProps): Promise<string> {\n const currentSession = await getUserAsync();\n if (!currentSession || APISettings.isOffline) {\n manifest.id = `@${ANONYMOUS_USERNAME}/${manifest.slug}-${hostId}`;\n }\n if (!acceptSignature) {\n return JSON.stringify(manifest);\n } else if (!currentSession || APISettings.isOffline) {\n return getUnsignedManifestString(manifest);\n } else {\n return this.getSignedManifestStringAsync(manifest);\n }\n }\n\n private getSignedManifestStringAsync = memoize(signClassicExpoGoManifestAsync);\n\n /** Exposed for testing. */\n async _fetchComputedManifestStringAsync(props: SignManifestProps): Promise<string> {\n try {\n return await this._getManifestStringAsync(props);\n } catch (error: any) {\n debug(`Error getting manifest:`, error);\n if (error.code === 'UNAUTHORIZED' && props.manifest.owner) {\n // Don't have permissions for siging, warn and enable offline mode.\n this.addSigningDisabledWarning(\n `This project belongs to ${chalk.bold(\n `@${props.manifest.owner}`\n )} and you have not been granted the appropriate permissions.\\n` +\n `Please request access from an admin of @${props.manifest.owner} or change the \"owner\" field to an account you belong to.\\n` +\n learnMore('https://docs.expo.dev/versions/latest/config/app/#owner')\n );\n APISettings.isOffline = true;\n return await this._getManifestStringAsync(props);\n } else if (error.code === 'ENOTFOUND') {\n // Got a DNS error, i.e. can't access exp.host, warn and enable offline mode.\n this.addSigningDisabledWarning(\n `Could not reach Expo servers, please check if you can access ${\n error.hostname || 'exp.host'\n }.`\n );\n APISettings.isOffline = true;\n return await this._getManifestStringAsync(props);\n } else {\n throw error;\n }\n }\n }\n\n private addSigningDisabledWarning = memoize((reason: string) => {\n Log.warn(`${reason}\\nFalling back to offline mode.`);\n // For the memo\n return reason;\n });\n}\n\n// Passed to Expo Go and registered as telemetry.\n// TODO: it's unclear why we don't just send it from the CLI.\nasync function createHostInfoAsync(): Promise<HostInfo> {\n return {\n host: await UserSettings.getAnonymousIdentifierAsync(),\n server: 'expo',\n // Defined in the build step\n serverVersion: process.env.__EXPO_VERSION!,\n serverDriver: DEVELOPER_TOOL,\n serverOS: os.platform(),\n serverOSVersion: os.release(),\n };\n}\n\nfunction getUnsignedManifestString(manifest: ExpoConfig) {\n const unsignedManifest = {\n manifestString: JSON.stringify(manifest),\n signature: 'UNSIGNED',\n };\n return JSON.stringify(unsignedManifest);\n}\n"],"names":["Log","debug","require","ClassicManifestMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","acceptSignature","Boolean","headers","hostname","stripPort","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","manifest","hostInfo","createHostInfoAsync","Map","set","JSON","stringify","body","_fetchComputedManifestStringAsync","hostId","host","version","sdkVersion","trackManifest","logEventAsync","_getManifestStringAsync","currentSession","getUserAsync","APISettings","isOffline","id","ANONYMOUS_USERNAME","slug","getUnsignedManifestString","getSignedManifestStringAsync","memoize","signClassicExpoGoManifestAsync","props","error","code","owner","addSigningDisabledWarning","chalk","bold","learnMore","reason","warn","UserSettings","getAnonymousIdentifierAsync","server","serverVersion","process","env","__EXPO_VERSION","serverDriver","DEVELOPER_TOOL","serverOS","os","serverOSVersion","release","unsignedManifest","manifestString","signature"],"mappings":"AAAA;;;;AACkB,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAES,IAAA,SAAuB,WAAvB,uBAAuB,CAAA;AACJ,IAAA,aAA2B,WAA3B,2BAA2B,CAAA;AACjD,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACR,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC7DA,IAAAA,GAAG,mCAAM,cAAc,EAApB;AACe,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAClD,IAAA,GAAmB,WAAnB,mBAAmB,CAAA;AACjB,IAAA,KAAqB,WAArB,qBAAqB,CAAA;AACrB,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AAMvC,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AAC8B,IAAA,gBAAmB,WAA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AK;QAC9DzD,GAAG,CAAC0D,IAAI,CAAC,CAAC,EAAED,MAAM,CAAC,+BAA+B,CAAC,CAAC,CAAC;QACrD,eAAe;QACf,OAAOA,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;QAnHYtD,yBAAyB,GAAzBA,yBAAyB;AAqHtC,iDAAiD;AACjD,6DAA6D;AAC7D,eAAeqB,mBAAmB,GAAsB;IACtD,OAAO;QACLQ,IAAI,EAAE,MAAM2B,aAAY,QAAA,CAACC,2BAA2B,EAAE;QACtDC,MAAM,EAAE,MAAM;QACd,4BAA4B;QAC5BC,aAAa,EAAEC,OAAO,CAACC,GAAG,CAACC,cAAc;QACzCC,YAAY,EAAEC,mBAAc,eAAA;QAC5BC,QAAQ,EAAEC,GAAE,QAAA,CAAC9D,QAAQ,EAAE;QACvB+D,eAAe,EAAED,GAAE,QAAA,CAACE,OAAO,EAAE;KAC9B,CAAC;CACH;AAED,SAAS1B,yBAAyB,CAACvB,QAAoB,EAAE;IACvD,MAAMkD,gBAAgB,GAAG;QACvBC,cAAc,EAAE9C,IAAI,CAACC,SAAS,CAACN,QAAQ,CAAC;QACxCoD,SAAS,EAAE,UAAU;KACtB,AAAC;IACF,OAAO/C,IAAI,CAACC,SAAS,CAAC4C,gBAAgB,CAAC,CAAC;CACzC"}
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
var _configPlugins = require("@expo/config-plugins");
|
|
6
6
|
var _accepts = _interopRequireDefault(require("accepts"));
|
|
7
7
|
var _assert = _interopRequireDefault(require("assert"));
|
|
8
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
8
9
|
var _formData = _interopRequireDefault(require("form-data"));
|
|
9
10
|
var _structuredHeaders = require("structured-headers");
|
|
10
|
-
var _uuid = require("uuid");
|
|
11
11
|
var _getProject = require("../../../api/getProject");
|
|
12
12
|
var _settings = require("../../../api/settings");
|
|
13
13
|
var _signManifest = require("../../../api/signManifest");
|
|
@@ -82,7 +82,7 @@ class ExpoGoManifestHandlerMiddleware extends _manifestMiddleware.ManifestMiddle
|
|
|
82
82
|
}
|
|
83
83
|
const scopeKey = shouldUseAnonymousManifest ? `@${_user.ANONYMOUS_USERNAME}/${exp.slug}-${userAnonymousIdentifier}` : await this.getScopeKeyForProjectIdAsync(easProjectId);
|
|
84
84
|
const expoUpdatesManifest = {
|
|
85
|
-
id:
|
|
85
|
+
id: _crypto.default.randomUUID(),
|
|
86
86
|
createdAt: new Date().toISOString(),
|
|
87
87
|
runtimeVersion,
|
|
88
88
|
launchAsset: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/middleware/ExpoGoManifestHandlerMiddleware.ts"],"sourcesContent":["import { ExpoUpdatesManifest } from '@expo/config';\nimport { Updates } from '@expo/config-plugins';\nimport accepts from 'accepts';\nimport assert from 'assert';\nimport FormData from 'form-data';\nimport { serializeDictionary, Dictionary } from 'structured-headers';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { getProjectAsync } from '../../../api/getProject';\nimport { APISettings } from '../../../api/settings';\nimport { signExpoGoManifestAsync } from '../../../api/signManifest';\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME, getUserAsync } from '../../../api/user/user';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport {\n CodeSigningInfo,\n getCodeSigningInfoAsync,\n signManifestString,\n} from '../../../utils/codesigning';\nimport { CommandError } from '../../../utils/errors';\nimport { memoize } from '../../../utils/fn';\nimport { stripPort } from '../../../utils/url';\nimport { ManifestMiddleware, ManifestRequestInfo } from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\n\nconst debug = require('debug')('expo:start:server:middleware:ExpoGoManifestHandlerMiddleware');\n\ninterface ExpoGoManifestRequestInfo extends ManifestRequestInfo {\n explicitlyPrefersMultipartMixed: boolean;\n expectSignature: string | null;\n}\n\nexport class ExpoGoManifestHandlerMiddleware extends ManifestMiddleware<ExpoGoManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ExpoGoManifestRequestInfo {\n let platform = parsePlatformHeader(req);\n\n if (!platform) {\n debug(\n `No \"expo-platform\" header or \"platform\" query parameter specified. Falling back to \"none\".`\n );\n platform = 'none';\n }\n\n assertRuntimePlatform(platform);\n\n // Expo Updates clients explicitly accept \"multipart/mixed\" responses while browsers implicitly\n // accept them with \"accept: */*\". To make it easier to debug manifest responses by visiting their\n // URLs in a browser, we denote the response as \"text/plain\" if the user agent appears not to be\n // an Expo Updates client.\n const accept = accepts(req);\n const explicitlyPrefersMultipartMixed =\n accept.types(['unknown/unknown', 'multipart/mixed']) === 'multipart/mixed';\n\n const expectSignature = req.headers['expo-expect-signature'];\n\n return {\n explicitlyPrefersMultipartMixed,\n platform,\n acceptSignature: !!req.headers['expo-accept-signature'],\n expectSignature: expectSignature ? String(expectSignature) : null,\n hostname: stripPort(req.headers['host']),\n };\n }\n\n private getDefaultResponseHeaders(): ServerHeaders {\n const headers = new Map<string, number | string | readonly string[]>();\n // set required headers for Expo Updates manifest specification\n headers.set('expo-protocol-version', 0);\n headers.set('expo-sfv-version', 0);\n headers.set('cache-control', 'private, max-age=0');\n return headers;\n }\n\n public async _getManifestResponseAsync(requestOptions: ExpoGoManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const runtimeVersion = Updates.getRuntimeVersion(\n { ...exp, runtimeVersion: exp.runtimeVersion ?? { policy: 'sdkVersion' } },\n requestOptions.platform\n );\n if (!runtimeVersion) {\n throw new CommandError(\n 'MANIFEST_MIDDLEWARE',\n `Unable to determine runtime version for platform '${requestOptions.platform}'`\n );\n }\n\n const codeSigningInfo = await getCodeSigningInfoAsync(\n exp,\n requestOptions.expectSignature,\n this.options.privateKeyPath\n );\n\n const easProjectId = exp.extra?.eas?.projectId;\n const shouldUseAnonymousManifest = await shouldUseAnonymousManifestAsync(\n easProjectId,\n codeSigningInfo\n );\n const userAnonymousIdentifier = await UserSettings.getAnonymousIdentifierAsync();\n if (!shouldUseAnonymousManifest) {\n assert(easProjectId);\n }\n const scopeKey = shouldUseAnonymousManifest\n ? `@${ANONYMOUS_USERNAME}/${exp.slug}-${userAnonymousIdentifier}`\n : await this.getScopeKeyForProjectIdAsync(easProjectId);\n\n const expoUpdatesManifest: ExpoUpdatesManifest = {\n id: uuidv4(),\n createdAt: new Date().toISOString(),\n runtimeVersion,\n launchAsset: {\n key: 'bundle',\n contentType: 'application/javascript',\n url: bundleUrl,\n },\n assets: [], // assets are not used in development\n metadata: {}, // required for the client to detect that this is an expo-updates manifest\n extra: {\n eas: {\n projectId: easProjectId ?? undefined,\n },\n expoClient: {\n ...exp,\n hostUri,\n },\n expoGo: expoGoConfig,\n scopeKey,\n },\n };\n\n const headers = this.getDefaultResponseHeaders();\n if (requestOptions.acceptSignature && !shouldUseAnonymousManifest) {\n const manifestSignature = await this.getSignedManifestStringAsync(expoUpdatesManifest);\n headers.set('expo-manifest-signature', manifestSignature);\n }\n\n const stringifiedManifest = JSON.stringify(expoUpdatesManifest);\n\n let manifestPartHeaders: { 'expo-signature': string } | null = null;\n let certificateChainBody: string | null = null;\n if (codeSigningInfo) {\n const signature = signManifestString(stringifiedManifest, codeSigningInfo);\n manifestPartHeaders = {\n 'expo-signature': serializeDictionary(\n convertToDictionaryItemsRepresentation({\n keyid: codeSigningInfo.keyId,\n sig: signature,\n alg: 'rsa-v1_5-sha256',\n })\n ),\n };\n certificateChainBody = codeSigningInfo.certificateChainForResponse.join('\\n');\n }\n\n const form = this.getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n });\n\n headers.set(\n 'content-type',\n requestOptions.explicitlyPrefersMultipartMixed\n ? `multipart/mixed; boundary=${form.getBoundary()}`\n : 'text/plain'\n );\n\n return {\n body: form.getBuffer().toString(),\n version: runtimeVersion,\n headers,\n };\n }\n\n private getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n }: {\n stringifiedManifest: string;\n manifestPartHeaders: { 'expo-signature': string } | null;\n certificateChainBody: string | null;\n }): FormData {\n const form = new FormData();\n form.append('manifest', stringifiedManifest, {\n contentType: 'application/json',\n header: {\n ...manifestPartHeaders,\n },\n });\n if (certificateChainBody && certificateChainBody.length > 0) {\n form.append('certificate_chain', certificateChainBody, {\n contentType: 'application/x-pem-file',\n });\n }\n return form;\n }\n\n protected trackManifest(version?: string) {\n logEventAsync('Serve Expo Updates Manifest', {\n runtimeVersion: version,\n });\n }\n\n private getSignedManifestStringAsync = memoize(signExpoGoManifestAsync);\n\n private getScopeKeyForProjectIdAsync = memoize(getScopeKeyForProjectIdAsync);\n}\n\n/**\n * 1. No EAS project ID in config, then use anonymous scope key\n * 2. When offline or not logged in\n * a. If code signing not accepted by client (only legacy manifest signing is supported), then use anonymous scope key\n * b. If code signing accepted by client and no development code signing certificate is cached, then use anonymous scope key\n */\nasync function shouldUseAnonymousManifestAsync(\n easProjectId: string | undefined | null,\n codeSigningInfo: CodeSigningInfo | null\n): Promise<boolean> {\n if (!easProjectId || (APISettings.isOffline && codeSigningInfo === null)) {\n return true;\n }\n\n return !(await getUserAsync());\n}\n\nasync function getScopeKeyForProjectIdAsync(projectId: string): Promise<string> {\n const project = await getProjectAsync(projectId);\n return project.scopeKey;\n}\n\nfunction convertToDictionaryItemsRepresentation(obj: { [key: string]: string }): Dictionary {\n return new Map(\n Object.entries(obj).map(([k, v]) => {\n return [k, [v, new Map()]];\n })\n );\n}\n"],"names":["debug","require","ExpoGoManifestHandlerMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","accept","accepts","explicitlyPrefersMultipartMixed","types","expectSignature","headers","acceptSignature","String","hostname","stripPort","getDefaultResponseHeaders","Map","set","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","runtimeVersion","Updates","getRuntimeVersion","policy","CommandError","codeSigningInfo","getCodeSigningInfoAsync","options","privateKeyPath","easProjectId","extra","eas","projectId","shouldUseAnonymousManifest","shouldUseAnonymousManifestAsync","userAnonymousIdentifier","UserSettings","getAnonymousIdentifierAsync","assert","scopeKey","ANONYMOUS_USERNAME","slug","getScopeKeyForProjectIdAsync","expoUpdatesManifest","id","uuidv4","createdAt","Date","toISOString","launchAsset","key","contentType","url","assets","metadata","undefined","expoClient","expoGo","manifestSignature","getSignedManifestStringAsync","stringifiedManifest","JSON","stringify","manifestPartHeaders","certificateChainBody","signature","signManifestString","serializeDictionary","convertToDictionaryItemsRepresentation","keyid","keyId","sig","alg","certificateChainForResponse","join","form","getFormData","getBoundary","body","getBuffer","toString","version","FormData","append","header","length","trackManifest","logEventAsync","memoize","signExpoGoManifestAsync","APISettings","isOffline","getUserAsync","project","getProjectAsync","obj","Object","entries","map","k","v"],"mappings":"AAAA;;;;AACwB,IAAA,cAAsB,WAAtB,sBAAsB,CAAA;AAC1B,IAAA,QAAS,kCAAT,SAAS,EAAA;AACV,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACN,IAAA,SAAW,kCAAX,WAAW,EAAA;AACgB,IAAA,kBAAoB,WAApB,oBAAoB,CAAA;AACvC,IAAA,KAAM,WAAN,MAAM,CAAA;AAEH,IAAA,WAAyB,WAAzB,yBAAyB,CAAA;AAC7B,IAAA,SAAuB,WAAvB,uBAAuB,CAAA;AACX,IAAA,aAA2B,WAA3B,2BAA2B,CAAA;AAC1C,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACR,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC3C,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAKnE,IAAA,YAA4B,WAA5B,4BAA4B,CAAA;AACN,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AAC5B,IAAA,GAAmB,WAAnB,mBAAmB,CAAA;AACjB,IAA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AW,CAAA,gBAAX,CAAC9D,SAAS,CAAC,AAAC;IACjD,OAAO6D,OAAO,CAACtD,QAAQ,CAAC;CACzB;AAED,SAAS6B,sCAAsC,CAAC2B,GAA8B,EAAc;IAC1F,OAAO,IAAIpF,GAAG,CACZqF,MAAM,CAACC,OAAO,CAACF,GAAG,CAAC,CAACG,GAAG,CAAC,CAAC,CAACC,CAAC,EAAEC,CAAC,CAAC,GAAK;QAClC,OAAO;YAACD,CAAC;YAAE;gBAACC,CAAC;gBAAE,IAAIzF,GAAG,EAAE;aAAC;SAAC,CAAC;KAC5B,CAAC,CACH,CAAC;CACH"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/ExpoGoManifestHandlerMiddleware.ts"],"sourcesContent":["import { ExpoUpdatesManifest } from '@expo/config';\nimport { Updates } from '@expo/config-plugins';\nimport accepts from 'accepts';\nimport assert from 'assert';\nimport crypto from 'crypto';\nimport FormData from 'form-data';\nimport { serializeDictionary, Dictionary } from 'structured-headers';\n\nimport { getProjectAsync } from '../../../api/getProject';\nimport { APISettings } from '../../../api/settings';\nimport { signExpoGoManifestAsync } from '../../../api/signManifest';\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME, getUserAsync } from '../../../api/user/user';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport {\n CodeSigningInfo,\n getCodeSigningInfoAsync,\n signManifestString,\n} from '../../../utils/codesigning';\nimport { CommandError } from '../../../utils/errors';\nimport { memoize } from '../../../utils/fn';\nimport { stripPort } from '../../../utils/url';\nimport { ManifestMiddleware, ManifestRequestInfo } from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\n\nconst debug = require('debug')('expo:start:server:middleware:ExpoGoManifestHandlerMiddleware');\n\ninterface ExpoGoManifestRequestInfo extends ManifestRequestInfo {\n explicitlyPrefersMultipartMixed: boolean;\n expectSignature: string | null;\n}\n\nexport class ExpoGoManifestHandlerMiddleware extends ManifestMiddleware<ExpoGoManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ExpoGoManifestRequestInfo {\n let platform = parsePlatformHeader(req);\n\n if (!platform) {\n debug(\n `No \"expo-platform\" header or \"platform\" query parameter specified. Falling back to \"none\".`\n );\n platform = 'none';\n }\n\n assertRuntimePlatform(platform);\n\n // Expo Updates clients explicitly accept \"multipart/mixed\" responses while browsers implicitly\n // accept them with \"accept: */*\". To make it easier to debug manifest responses by visiting their\n // URLs in a browser, we denote the response as \"text/plain\" if the user agent appears not to be\n // an Expo Updates client.\n const accept = accepts(req);\n const explicitlyPrefersMultipartMixed =\n accept.types(['unknown/unknown', 'multipart/mixed']) === 'multipart/mixed';\n\n const expectSignature = req.headers['expo-expect-signature'];\n\n return {\n explicitlyPrefersMultipartMixed,\n platform,\n acceptSignature: !!req.headers['expo-accept-signature'],\n expectSignature: expectSignature ? String(expectSignature) : null,\n hostname: stripPort(req.headers['host']),\n };\n }\n\n private getDefaultResponseHeaders(): ServerHeaders {\n const headers = new Map<string, number | string | readonly string[]>();\n // set required headers for Expo Updates manifest specification\n headers.set('expo-protocol-version', 0);\n headers.set('expo-sfv-version', 0);\n headers.set('cache-control', 'private, max-age=0');\n return headers;\n }\n\n public async _getManifestResponseAsync(requestOptions: ExpoGoManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const runtimeVersion = Updates.getRuntimeVersion(\n { ...exp, runtimeVersion: exp.runtimeVersion ?? { policy: 'sdkVersion' } },\n requestOptions.platform\n );\n if (!runtimeVersion) {\n throw new CommandError(\n 'MANIFEST_MIDDLEWARE',\n `Unable to determine runtime version for platform '${requestOptions.platform}'`\n );\n }\n\n const codeSigningInfo = await getCodeSigningInfoAsync(\n exp,\n requestOptions.expectSignature,\n this.options.privateKeyPath\n );\n\n const easProjectId = exp.extra?.eas?.projectId;\n const shouldUseAnonymousManifest = await shouldUseAnonymousManifestAsync(\n easProjectId,\n codeSigningInfo\n );\n const userAnonymousIdentifier = await UserSettings.getAnonymousIdentifierAsync();\n if (!shouldUseAnonymousManifest) {\n assert(easProjectId);\n }\n const scopeKey = shouldUseAnonymousManifest\n ? `@${ANONYMOUS_USERNAME}/${exp.slug}-${userAnonymousIdentifier}`\n : await this.getScopeKeyForProjectIdAsync(easProjectId);\n\n const expoUpdatesManifest: ExpoUpdatesManifest = {\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n runtimeVersion,\n launchAsset: {\n key: 'bundle',\n contentType: 'application/javascript',\n url: bundleUrl,\n },\n assets: [], // assets are not used in development\n metadata: {}, // required for the client to detect that this is an expo-updates manifest\n extra: {\n eas: {\n projectId: easProjectId ?? undefined,\n },\n expoClient: {\n ...exp,\n hostUri,\n },\n expoGo: expoGoConfig,\n scopeKey,\n },\n };\n\n const headers = this.getDefaultResponseHeaders();\n if (requestOptions.acceptSignature && !shouldUseAnonymousManifest) {\n const manifestSignature = await this.getSignedManifestStringAsync(expoUpdatesManifest);\n headers.set('expo-manifest-signature', manifestSignature);\n }\n\n const stringifiedManifest = JSON.stringify(expoUpdatesManifest);\n\n let manifestPartHeaders: { 'expo-signature': string } | null = null;\n let certificateChainBody: string | null = null;\n if (codeSigningInfo) {\n const signature = signManifestString(stringifiedManifest, codeSigningInfo);\n manifestPartHeaders = {\n 'expo-signature': serializeDictionary(\n convertToDictionaryItemsRepresentation({\n keyid: codeSigningInfo.keyId,\n sig: signature,\n alg: 'rsa-v1_5-sha256',\n })\n ),\n };\n certificateChainBody = codeSigningInfo.certificateChainForResponse.join('\\n');\n }\n\n const form = this.getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n });\n\n headers.set(\n 'content-type',\n requestOptions.explicitlyPrefersMultipartMixed\n ? `multipart/mixed; boundary=${form.getBoundary()}`\n : 'text/plain'\n );\n\n return {\n body: form.getBuffer().toString(),\n version: runtimeVersion,\n headers,\n };\n }\n\n private getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n }: {\n stringifiedManifest: string;\n manifestPartHeaders: { 'expo-signature': string } | null;\n certificateChainBody: string | null;\n }): FormData {\n const form = new FormData();\n form.append('manifest', stringifiedManifest, {\n contentType: 'application/json',\n header: {\n ...manifestPartHeaders,\n },\n });\n if (certificateChainBody && certificateChainBody.length > 0) {\n form.append('certificate_chain', certificateChainBody, {\n contentType: 'application/x-pem-file',\n });\n }\n return form;\n }\n\n protected trackManifest(version?: string) {\n logEventAsync('Serve Expo Updates Manifest', {\n runtimeVersion: version,\n });\n }\n\n private getSignedManifestStringAsync = memoize(signExpoGoManifestAsync);\n\n private getScopeKeyForProjectIdAsync = memoize(getScopeKeyForProjectIdAsync);\n}\n\n/**\n * 1. No EAS project ID in config, then use anonymous scope key\n * 2. When offline or not logged in\n * a. If code signing not accepted by client (only legacy manifest signing is supported), then use anonymous scope key\n * b. If code signing accepted by client and no development code signing certificate is cached, then use anonymous scope key\n */\nasync function shouldUseAnonymousManifestAsync(\n easProjectId: string | undefined | null,\n codeSigningInfo: CodeSigningInfo | null\n): Promise<boolean> {\n if (!easProjectId || (APISettings.isOffline && codeSigningInfo === null)) {\n return true;\n }\n\n return !(await getUserAsync());\n}\n\nasync function getScopeKeyForProjectIdAsync(projectId: string): Promise<string> {\n const project = await getProjectAsync(projectId);\n return project.scopeKey;\n}\n\nfunction convertToDictionaryItemsRepresentation(obj: { [key: string]: string }): Dictionary {\n return new Map(\n Object.entries(obj).map(([k, v]) => {\n return [k, [v, new Map()]];\n })\n );\n}\n"],"names":["debug","require","ExpoGoManifestHandlerMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","accept","accepts","explicitlyPrefersMultipartMixed","types","expectSignature","headers","acceptSignature","String","hostname","stripPort","getDefaultResponseHeaders","Map","set","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","runtimeVersion","Updates","getRuntimeVersion","policy","CommandError","codeSigningInfo","getCodeSigningInfoAsync","options","privateKeyPath","easProjectId","extra","eas","projectId","shouldUseAnonymousManifest","shouldUseAnonymousManifestAsync","userAnonymousIdentifier","UserSettings","getAnonymousIdentifierAsync","assert","scopeKey","ANONYMOUS_USERNAME","slug","getScopeKeyForProjectIdAsync","expoUpdatesManifest","id","crypto","randomUUID","createdAt","Date","toISOString","launchAsset","key","contentType","url","assets","metadata","undefined","expoClient","expoGo","manifestSignature","getSignedManifestStringAsync","stringifiedManifest","JSON","stringify","manifestPartHeaders","certificateChainBody","signature","signManifestString","serializeDictionary","convertToDictionaryItemsRepresentation","keyid","keyId","sig","alg","certificateChainForResponse","join","form","getFormData","getBoundary","body","getBuffer","toString","version","FormData","append","header","length","trackManifest","logEventAsync","memoize","signExpoGoManifestAsync","APISettings","isOffline","getUserAsync","project","getProjectAsync","obj","Object","entries","map","k","v"],"mappings":"AAAA;;;;AACwB,IAAA,cAAsB,WAAtB,sBAAsB,CAAA;AAC1B,IAAA,QAAS,kCAAT,SAAS,EAAA;AACV,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACR,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACN,IAAA,SAAW,kCAAX,WAAW,EAAA;AACgB,IAAA,kBAAoB,WAApB,oBAAoB,CAAA;AAEpC,IAAA,WAAyB,WAAzB,yBAAyB,CAAA;AAC7B,IAAA,SAAuB,WAAvB,uBAAuB,CAAA;AACX,IAAA,aAA2B,WAA3B,2BAA2B,CAAA;AAC1C,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACR,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC3C,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAKnE,IAAA,YAA4B,WAA5B,4BAA4B,CAAA;AACN,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AAC5B,IAAA,GAAmB,WAAnB,mBAAmB,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AAAW,CAAA,gBAAX,CAAC/D,SAAS,CAAC,AAAC;IACjD,OAAO8D,OAAO,CAACvD,QAAQ,CAAC;CACzB;AAED,SAAS8B,sCAAsC,CAAC2B,GAA8B,EAAc;IAC1F,OAAO,IAAIrF,GAAG,CACZsF,MAAM,CAACC,OAAO,CAACF,GAAG,CAAC,CAACG,GAAG,CAAC,CAAC,CAACC,CAAC,EAAEC,CAAC,CAAC,GAAK;QAClC,OAAO;YAACD,CAAC;YAAE;gBAACC,CAAC;gBAAE,IAAI1F,GAAG,EAAE;aAAC;SAAC,CAAC;KAC5B,CAAC,CACH,CAAC;CACH"}
|
|
@@ -94,7 +94,7 @@ async function logEventAsync(event, properties = {}) {
|
|
|
94
94
|
}
|
|
95
95
|
const { userId , deviceId } = identifyData;
|
|
96
96
|
const commonEventProperties = {
|
|
97
|
-
source_version: "0.
|
|
97
|
+
source_version: "0.5.0",
|
|
98
98
|
source: "expo"
|
|
99
99
|
};
|
|
100
100
|
const identity = {
|
|
@@ -135,7 +135,7 @@ function getContext() {
|
|
|
135
135
|
},
|
|
136
136
|
app: {
|
|
137
137
|
name: "expo",
|
|
138
|
-
version: "0.
|
|
138
|
+
version: "0.5.0"
|
|
139
139
|
},
|
|
140
140
|
ci: ciInfo.isCI ? {
|
|
141
141
|
name: ciInfo.name,
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
exports.getExpoGoVersionEntryAsync = getExpoGoVersionEntryAsync;
|
|
5
6
|
exports.downloadExpoGoAsync = downloadExpoGoAsync;
|
|
6
7
|
var _getUserState = require("@expo/config/build/getUserState");
|
|
7
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _semver = require("semver");
|
|
8
10
|
var _getVersions = require("../api/getVersions");
|
|
11
|
+
var _log = require("../log");
|
|
9
12
|
var _downloadAppAsync = require("./downloadAppAsync");
|
|
10
13
|
var _errors = require("./errors");
|
|
11
14
|
var _ora = require("./ora");
|
|
@@ -31,6 +34,27 @@ const platformSettings = {
|
|
|
31
34
|
shouldExtractResults: false
|
|
32
35
|
}
|
|
33
36
|
};
|
|
37
|
+
async function getExpoGoVersionEntryAsync(sdkVersion) {
|
|
38
|
+
const { sdkVersions: versions } = await (0, _getVersions).getVersionsAsync();
|
|
39
|
+
let version;
|
|
40
|
+
if (sdkVersion.toUpperCase() === "UNVERSIONED") {
|
|
41
|
+
// find the latest version
|
|
42
|
+
const latestVersionKey = Object.keys(versions).reduce((a, b)=>{
|
|
43
|
+
if ((0, _semver).gt(b, a)) {
|
|
44
|
+
return b;
|
|
45
|
+
}
|
|
46
|
+
return a;
|
|
47
|
+
}, "0.0.0");
|
|
48
|
+
_log.Log.warn(`Downloading the latest Expo Go client (${latestVersionKey}). This will not fully conform to UNVERSIONED.`);
|
|
49
|
+
version = versions[latestVersionKey];
|
|
50
|
+
} else {
|
|
51
|
+
version = versions[sdkVersion];
|
|
52
|
+
}
|
|
53
|
+
if (!version) {
|
|
54
|
+
throw new _errors.CommandError(`Unable to find a version of Expo Go for SDK ${sdkVersion}`);
|
|
55
|
+
}
|
|
56
|
+
return version;
|
|
57
|
+
}
|
|
34
58
|
async function downloadExpoGoAsync(platform, { url , sdkVersion }) {
|
|
35
59
|
const { getFilePath , versionsKey , shouldExtractResults } = platformSettings[platform];
|
|
36
60
|
const spinner = (0, _ora).ora({
|
|
@@ -38,17 +62,18 @@ async function downloadExpoGoAsync(platform, { url , sdkVersion }) {
|
|
|
38
62
|
color: "white"
|
|
39
63
|
}).start();
|
|
40
64
|
let bar = null;
|
|
41
|
-
|
|
42
|
-
if (!
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
try {
|
|
66
|
+
if (!url) {
|
|
67
|
+
if (!sdkVersion) {
|
|
68
|
+
throw new _errors.CommandError(`Unable to determine which Expo Go version to install (platform: ${platform})`);
|
|
69
|
+
}
|
|
70
|
+
const version = await getExpoGoVersionEntryAsync(sdkVersion);
|
|
71
|
+
debug(`Installing Expo Go version for SDK ${sdkVersion} at URL: ${version[versionsKey]}`);
|
|
72
|
+
url = version[versionsKey];
|
|
49
73
|
}
|
|
50
|
-
|
|
51
|
-
|
|
74
|
+
} catch (error) {
|
|
75
|
+
spinner.fail();
|
|
76
|
+
throw error;
|
|
52
77
|
}
|
|
53
78
|
const filename = _path.default.parse(url).name;
|
|
54
79
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/downloadExpoGoAsync.ts"],"sourcesContent":["import { getExpoHomeDirectory } from '@expo/config/build/getUserState';\nimport path from 'path';\nimport ProgressBar from 'progress';\n\nimport { getVersionsAsync, SDKVersion } from '../api/getVersions';\nimport { downloadAppAsync } from './downloadAppAsync';\nimport { CommandError } from './errors';\nimport { ora } from './ora';\nimport { profile } from './profile';\nimport { createProgressBar } from './progress';\n\nconst debug = require('debug')('expo:utils:downloadExpoGo') as typeof console.log;\n\nconst platformSettings: Record<\n string,\n {\n shouldExtractResults: boolean;\n versionsKey: keyof SDKVersion;\n getFilePath: (filename: string) => string;\n }\n> = {\n ios: {\n versionsKey: 'iosClientUrl',\n getFilePath: (filename) =>\n path.join(getExpoHomeDirectory(), 'ios-simulator-app-cache', `${filename}.app`),\n shouldExtractResults: true,\n },\n android: {\n versionsKey: 'androidClientUrl',\n getFilePath: (filename) =>\n path.join(getExpoHomeDirectory(), 'android-apk-cache', `${filename}.apk`),\n shouldExtractResults: false,\n },\n};\n\n/** Download the Expo Go app from the Expo servers (if only it was this easy for every app). */\nexport async function downloadExpoGoAsync(\n platform: keyof typeof platformSettings,\n {\n url,\n sdkVersion,\n }: {\n url?: string;\n sdkVersion?: string;\n }\n): Promise<string> {\n const { getFilePath, versionsKey, shouldExtractResults } = platformSettings[platform];\n\n const spinner = ora({ text: 'Fetching Expo Go', color: 'white' }).start();\n\n let bar: ProgressBar | null = null;\n\n if (!url) {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/downloadExpoGoAsync.ts"],"sourcesContent":["import { getExpoHomeDirectory } from '@expo/config/build/getUserState';\nimport path from 'path';\nimport ProgressBar from 'progress';\nimport { gt } from 'semver';\n\nimport { getVersionsAsync, SDKVersion } from '../api/getVersions';\nimport { Log } from '../log';\nimport { downloadAppAsync } from './downloadAppAsync';\nimport { CommandError } from './errors';\nimport { ora } from './ora';\nimport { profile } from './profile';\nimport { createProgressBar } from './progress';\n\nconst debug = require('debug')('expo:utils:downloadExpoGo') as typeof console.log;\n\nconst platformSettings: Record<\n string,\n {\n shouldExtractResults: boolean;\n versionsKey: keyof SDKVersion;\n getFilePath: (filename: string) => string;\n }\n> = {\n ios: {\n versionsKey: 'iosClientUrl',\n getFilePath: (filename) =>\n path.join(getExpoHomeDirectory(), 'ios-simulator-app-cache', `${filename}.app`),\n shouldExtractResults: true,\n },\n android: {\n versionsKey: 'androidClientUrl',\n getFilePath: (filename) =>\n path.join(getExpoHomeDirectory(), 'android-apk-cache', `${filename}.apk`),\n shouldExtractResults: false,\n },\n};\n\n/**\n * @internal exposed for testing.\n * @returns the matching `SDKVersion` object from the Expo API.\n */\nexport async function getExpoGoVersionEntryAsync(sdkVersion: string): Promise<SDKVersion> {\n const { sdkVersions: versions } = await getVersionsAsync();\n let version: SDKVersion;\n\n if (sdkVersion.toUpperCase() === 'UNVERSIONED') {\n // find the latest version\n const latestVersionKey = Object.keys(versions).reduce((a, b) => {\n if (gt(b, a)) {\n return b;\n }\n return a;\n }, '0.0.0');\n\n Log.warn(\n `Downloading the latest Expo Go client (${latestVersionKey}). This will not fully conform to UNVERSIONED.`\n );\n version = versions[latestVersionKey];\n } else {\n version = versions[sdkVersion];\n }\n\n if (!version) {\n throw new CommandError(`Unable to find a version of Expo Go for SDK ${sdkVersion}`);\n }\n return version;\n}\n\n/** Download the Expo Go app from the Expo servers (if only it was this easy for every app). */\nexport async function downloadExpoGoAsync(\n platform: keyof typeof platformSettings,\n {\n url,\n sdkVersion,\n }: {\n url?: string;\n sdkVersion?: string;\n }\n): Promise<string> {\n const { getFilePath, versionsKey, shouldExtractResults } = platformSettings[platform];\n\n const spinner = ora({ text: 'Fetching Expo Go', color: 'white' }).start();\n\n let bar: ProgressBar | null = null;\n\n try {\n if (!url) {\n if (!sdkVersion) {\n throw new CommandError(\n `Unable to determine which Expo Go version to install (platform: ${platform})`\n );\n }\n\n const version = await getExpoGoVersionEntryAsync(sdkVersion);\n\n debug(`Installing Expo Go version for SDK ${sdkVersion} at URL: ${version[versionsKey]}`);\n url = version[versionsKey] as string;\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n const filename = path.parse(url).name;\n\n try {\n const outputPath = getFilePath(filename);\n debug(`Downloading Expo Go from \"${url}\" to \"${outputPath}\".`);\n debug(\n `The requested copy of Expo Go might already be cached in: \"${getExpoHomeDirectory()}\". You can disable the cache with EXPO_NO_CACHE=1`\n );\n await profile(downloadAppAsync)({\n url,\n // Save all encrypted cache data to `~/.expo/expo-go`\n cacheDirectory: 'expo-go',\n outputPath,\n extract: shouldExtractResults,\n onProgress({ progress, total }) {\n if (progress && total) {\n if (!bar) {\n if (spinner.isSpinning) {\n spinner.stop();\n }\n bar = createProgressBar('Downloading the Expo Go app [:bar] :percent :etas', {\n width: 64,\n total: 100,\n // clear: true,\n complete: '=',\n incomplete: ' ',\n });\n }\n bar!.update(progress, total);\n }\n },\n });\n return outputPath;\n } finally {\n spinner.stop();\n // @ts-expect-error\n bar?.terminate();\n }\n}\n"],"names":["getExpoGoVersionEntryAsync","downloadExpoGoAsync","debug","require","platformSettings","ios","versionsKey","getFilePath","filename","path","join","getExpoHomeDirectory","shouldExtractResults","android","sdkVersion","sdkVersions","versions","getVersionsAsync","version","toUpperCase","latestVersionKey","Object","keys","reduce","a","b","gt","Log","warn","CommandError","platform","url","spinner","ora","text","color","start","bar","error","fail","parse","name","outputPath","profile","downloadAppAsync","cacheDirectory","extract","onProgress","progress","total","is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QAAQ,IAAIC,KAAK,EAAE;oBACrB,IAAI,CAACZ,GAAG,EAAE;wBACR,IAAIL,OAAO,CAACkB,UAAU,EAAE;4BACtBlB,OAAO,CAACmB,IAAI,EAAE,CAAC;yBAChB;wBACDd,GAAG,GAAGe,CAAAA,GAAAA,SAAiB,AAMrB,CAAA,kBANqB,CAAC,mDAAmD,EAAE;4BAC3EC,KAAK,EAAE,EAAE;4BACTJ,KAAK,EAAE,GAAG;4BACV,eAAe;4BACfK,QAAQ,EAAE,GAAG;4BACbC,UAAU,EAAE,GAAG;yBAChB,CAAC,CAAC;qBACJ;oBACDlB,GAAG,CAAEmB,MAAM,CAACR,QAAQ,EAAEC,KAAK,CAAC,CAAC;iBAC9B;aACF;SACF,CAAC,CAAC;QACH,OAAOP,UAAU,CAAC;KACnB,QAAS;QACRV,OAAO,CAACmB,IAAI,EAAE,CAAC;QACf,mBAAmB;QACnBd,GAAG,QAAW,GAAdA,KAAAA,CAAc,GAAdA,GAAG,CAAEoB,SAAS,EAAE,AA3IpB,CA2IqB;KAClB;CACF"}
|
package/build/src/utils/env.js
CHANGED
|
@@ -64,20 +64,10 @@ class Env {
|
|
|
64
64
|
/**
|
|
65
65
|
* Overwrite the dev server URL, disregarding the `--port`, `--host`, `--tunnel`, `--lan`, `--localhost` arguments.
|
|
66
66
|
* This is useful for browser editors that require custom proxy URLs.
|
|
67
|
-
*
|
|
68
|
-
* The URL will not be used verbatim unless `EXPO_NO_DEFAULT_PORT=true` is also set,
|
|
69
|
-
* otherwise a `:80` port will be added for Android support.
|
|
70
67
|
*/ get EXPO_PACKAGER_PROXY_URL() {
|
|
71
68
|
return (0, _getenv).string("EXPO_PACKAGER_PROXY_URL", "");
|
|
72
69
|
}
|
|
73
70
|
/**
|
|
74
|
-
* Disable the enforced `:80` port when using custom dev server URLs.
|
|
75
|
-
* This can break the incomplete Android WebSocket implementation but allows
|
|
76
|
-
* `EXPO_PACKAGER_PROXY_URL` to work as expected.
|
|
77
|
-
*/ get EXPO_NO_DEFAULT_PORT() {
|
|
78
|
-
return (0, _getenv).boolish("EXPO_NO_DEFAULT_PORT", false);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
71
|
* **Experimental** - Disable using `exp.direct` as the hostname for
|
|
82
72
|
* `--tunnel` connections. This enables **https://** forwarding which
|
|
83
73
|
* can be used to test universal links on iOS.
|