@expo/cli 0.1.5 → 0.2.2

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.
Files changed (192) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/build/bin/cli +83 -4
  3. package/build/bin/cli.map +1 -1
  4. package/build/src/api/getNativeModuleVersions.js.map +1 -1
  5. package/build/src/api/rest/wrapFetchWithOffline.js +2 -23
  6. package/build/src/api/rest/wrapFetchWithOffline.js.map +1 -1
  7. package/build/src/customize/customizeAsync.js +40 -0
  8. package/build/src/customize/customizeAsync.js.map +1 -0
  9. package/build/src/customize/generate.js +77 -0
  10. package/build/src/customize/generate.js.map +1 -0
  11. package/build/src/customize/index.js +41 -0
  12. package/build/src/customize/index.js.map +1 -0
  13. package/build/src/customize/resolveOptions.js +18 -0
  14. package/build/src/customize/resolveOptions.js.map +1 -0
  15. package/build/src/customize/templates.js +118 -0
  16. package/build/src/customize/templates.js.map +1 -0
  17. package/build/src/export/createMetadataJson.js +10 -7
  18. package/build/src/export/createMetadataJson.js.map +1 -1
  19. package/build/src/export/exportApp.js +32 -0
  20. package/build/src/export/exportApp.js.map +1 -1
  21. package/build/src/export/exportAssets.js +2 -3
  22. package/build/src/export/exportAssets.js.map +1 -1
  23. package/build/src/export/fork-bundleAsync.js +52 -35
  24. package/build/src/export/fork-bundleAsync.js.map +1 -1
  25. package/build/src/export/index.js +14 -10
  26. package/build/src/export/index.js.map +1 -1
  27. package/build/src/export/printBundleSizes.js +27 -48
  28. package/build/src/export/printBundleSizes.js.map +1 -1
  29. package/build/src/export/resolveOptions.js +44 -5
  30. package/build/src/export/resolveOptions.js.map +1 -1
  31. package/build/src/export/saveAssets.js +2 -1
  32. package/build/src/export/saveAssets.js.map +1 -1
  33. package/build/src/export/web/exportWebAsync.js +37 -0
  34. package/build/src/export/web/exportWebAsync.js.map +1 -0
  35. package/build/src/export/web/index.js +66 -0
  36. package/build/src/export/web/index.js.map +1 -0
  37. package/build/src/export/web/resolveOptions.js +13 -0
  38. package/build/src/export/web/resolveOptions.js.map +1 -0
  39. package/build/src/export/writeContents.js.map +1 -1
  40. package/build/src/install/checkPackages.js +2 -1
  41. package/build/src/install/checkPackages.js.map +1 -1
  42. package/build/src/install/index.js +1 -0
  43. package/build/src/install/index.js.map +1 -1
  44. package/build/src/install/installAsync.js +13 -5
  45. package/build/src/install/installAsync.js.map +1 -1
  46. package/build/src/install/resolveOptions.js +12 -65
  47. package/build/src/install/resolveOptions.js.map +1 -1
  48. package/build/src/install/utils/autoAddConfigPlugins.js +5 -26
  49. package/build/src/install/utils/autoAddConfigPlugins.js.map +1 -1
  50. package/build/src/log.js.map +1 -1
  51. package/build/src/prebuild/copyTemplateFiles.js +5 -23
  52. package/build/src/prebuild/copyTemplateFiles.js.map +1 -1
  53. package/build/src/prebuild/index.js +18 -12
  54. package/build/src/prebuild/index.js.map +1 -1
  55. package/build/src/prebuild/prebuildAsync.js +11 -12
  56. package/build/src/prebuild/prebuildAsync.js.map +1 -1
  57. package/build/src/prebuild/resolveOptions.js +17 -0
  58. package/build/src/prebuild/resolveOptions.js.map +1 -1
  59. package/build/src/prebuild/resolveTemplate.js +2 -1
  60. package/build/src/prebuild/resolveTemplate.js.map +1 -1
  61. package/build/src/prebuild/updatePackageJson.js +5 -5
  62. package/build/src/prebuild/updatePackageJson.js.map +1 -1
  63. package/build/src/run/android/resolveInstallApkName.js +5 -26
  64. package/build/src/run/android/resolveInstallApkName.js.map +1 -1
  65. package/build/src/start/doctor/apple/SimulatorAppPrerequisite.js +2 -0
  66. package/build/src/start/doctor/apple/SimulatorAppPrerequisite.js.map +1 -1
  67. package/build/src/start/doctor/apple/XcodePrerequisite.js +2 -0
  68. package/build/src/start/doctor/apple/XcodePrerequisite.js.map +1 -1
  69. package/build/src/start/doctor/dependencies/bundledNativeModules.js +3 -2
  70. package/build/src/start/doctor/dependencies/bundledNativeModules.js.map +1 -1
  71. package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js +7 -13
  72. package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js.map +1 -1
  73. package/build/src/start/doctor/dependencies/getMissingPackages.js +3 -24
  74. package/build/src/start/doctor/dependencies/getMissingPackages.js.map +1 -1
  75. package/build/src/start/doctor/dependencies/getVersionedPackages.js +2 -23
  76. package/build/src/start/doctor/dependencies/getVersionedPackages.js.map +1 -1
  77. package/build/src/start/doctor/dependencies/validateDependenciesVersions.js +17 -9
  78. package/build/src/start/doctor/dependencies/validateDependenciesVersions.js.map +1 -1
  79. package/build/src/start/doctor/ngrok/ExternalModule.js +2 -1
  80. package/build/src/start/doctor/ngrok/ExternalModule.js.map +1 -1
  81. package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js +4 -3
  82. package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js.map +1 -1
  83. package/build/src/start/doctor/web/WebSupportProjectPrerequisite.js +29 -31
  84. package/build/src/start/doctor/web/WebSupportProjectPrerequisite.js.map +1 -1
  85. package/build/src/start/interface/KeyPressHandler.js +2 -0
  86. package/build/src/start/interface/KeyPressHandler.js.map +1 -1
  87. package/build/src/start/interface/interactiveActions.js +5 -5
  88. package/build/src/start/interface/interactiveActions.js.map +1 -1
  89. package/build/src/start/interface/startInterface.js +3 -2
  90. package/build/src/start/interface/startInterface.js.map +1 -1
  91. package/build/src/start/platforms/ExpoGoInstaller.js +2 -1
  92. package/build/src/start/platforms/ExpoGoInstaller.js.map +1 -1
  93. package/build/src/start/platforms/PlatformManager.js +4 -24
  94. package/build/src/start/platforms/PlatformManager.js.map +1 -1
  95. package/build/src/start/platforms/android/ADBServer.js +17 -32
  96. package/build/src/start/platforms/android/ADBServer.js.map +1 -1
  97. package/build/src/start/platforms/android/AndroidSdk.js +41 -0
  98. package/build/src/start/platforms/android/AndroidSdk.js.map +1 -0
  99. package/build/src/start/platforms/android/activateWindow.js +4 -4
  100. package/build/src/start/platforms/android/activateWindow.js.map +1 -1
  101. package/build/src/start/platforms/android/adb.js +8 -3
  102. package/build/src/start/platforms/android/adb.js.map +1 -1
  103. package/build/src/start/platforms/android/adbReverse.js +3 -2
  104. package/build/src/start/platforms/android/adbReverse.js.map +1 -1
  105. package/build/src/start/platforms/android/gradle.js +2 -2
  106. package/build/src/start/platforms/android/gradle.js.map +1 -1
  107. package/build/src/start/platforms/ios/getBestSimulator.js +4 -4
  108. package/build/src/start/platforms/ios/getBestSimulator.js.map +1 -1
  109. package/build/src/start/platforms/ios/xcrun.js +2 -23
  110. package/build/src/start/platforms/ios/xcrun.js.map +1 -1
  111. package/build/src/start/project/devices.js +2 -0
  112. package/build/src/start/project/devices.js.map +1 -1
  113. package/build/src/start/server/AsyncNgrok.js +6 -5
  114. package/build/src/start/server/AsyncNgrok.js.map +1 -1
  115. package/build/src/start/server/BundlerDevServer.js +15 -8
  116. package/build/src/start/server/BundlerDevServer.js.map +1 -1
  117. package/build/src/start/server/DevServerManager.js +15 -5
  118. package/build/src/start/server/DevServerManager.js.map +1 -1
  119. package/build/src/start/server/DevelopmentSession.js +4 -0
  120. package/build/src/start/server/DevelopmentSession.js.map +1 -1
  121. package/build/src/start/server/UrlCreator.js +10 -3
  122. package/build/src/start/server/UrlCreator.js.map +1 -1
  123. package/build/src/start/server/metro/MetroBundlerDevServer.js +9 -0
  124. package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
  125. package/build/src/start/server/metro/TerminalReporter.js +5 -0
  126. package/build/src/start/server/metro/TerminalReporter.js.map +1 -1
  127. package/build/src/start/server/metro/instantiateMetro.js +11 -2
  128. package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
  129. package/build/src/start/server/metro/resolveFromProject.js +8 -0
  130. package/build/src/start/server/metro/resolveFromProject.js.map +1 -1
  131. package/build/src/start/server/metro/withMetroMultiPlatform.js +115 -0
  132. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -0
  133. package/build/src/start/server/middleware/ClassicManifestMiddleware.js +1 -1
  134. package/build/src/start/server/middleware/ExpoMiddleware.js +9 -4
  135. package/build/src/start/server/middleware/ExpoMiddleware.js.map +1 -1
  136. package/build/src/start/server/middleware/HistoryFallbackMiddleware.js +24 -0
  137. package/build/src/start/server/middleware/HistoryFallbackMiddleware.js.map +1 -0
  138. package/build/src/start/server/middleware/InterstitialPageMiddleware.js +2 -0
  139. package/build/src/start/server/middleware/InterstitialPageMiddleware.js.map +1 -1
  140. package/build/src/start/server/middleware/ManifestMiddleware.js +57 -6
  141. package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
  142. package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js +6 -1
  143. package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js.map +1 -1
  144. package/build/src/start/server/middleware/ServeStaticMiddleware.js +62 -0
  145. package/build/src/start/server/middleware/ServeStaticMiddleware.js.map +1 -0
  146. package/build/src/start/server/platformBundlers.js +18 -0
  147. package/build/src/start/server/platformBundlers.js.map +1 -0
  148. package/build/src/start/server/webTemplate.js +68 -0
  149. package/build/src/start/server/webTemplate.js.map +1 -0
  150. package/build/src/start/server/webpack/WebpackBundlerDevServer.js +59 -19
  151. package/build/src/start/server/webpack/WebpackBundlerDevServer.js.map +1 -1
  152. package/build/src/start/server/webpack/compile.js +64 -0
  153. package/build/src/start/server/webpack/compile.js.map +1 -0
  154. package/build/src/start/startAsync.js +21 -17
  155. package/build/src/start/startAsync.js.map +1 -1
  156. package/build/src/utils/FileNotifier.js +5 -2
  157. package/build/src/utils/FileNotifier.js.map +1 -1
  158. package/build/src/utils/analytics/rudderstackClient.js +2 -2
  159. package/build/src/utils/downloadAppAsync.js +3 -2
  160. package/build/src/utils/downloadAppAsync.js.map +1 -1
  161. package/build/src/utils/downloadExpoGoAsync.js +7 -32
  162. package/build/src/utils/downloadExpoGoAsync.js.map +1 -1
  163. package/build/src/utils/editor.js +3 -2
  164. package/build/src/utils/editor.js.map +1 -1
  165. package/build/src/utils/env.js +3 -0
  166. package/build/src/utils/env.js.map +1 -1
  167. package/build/src/utils/exit.js +4 -25
  168. package/build/src/utils/exit.js.map +1 -1
  169. package/build/src/utils/getRunningProcess.js +6 -2
  170. package/build/src/utils/getRunningProcess.js.map +1 -1
  171. package/build/src/utils/nodeModules.js +13 -102
  172. package/build/src/utils/nodeModules.js.map +1 -1
  173. package/build/src/utils/npm.js +3 -24
  174. package/build/src/utils/npm.js.map +1 -1
  175. package/build/src/utils/ora.js +1 -13
  176. package/build/src/utils/ora.js.map +1 -1
  177. package/build/src/utils/progress.js +46 -0
  178. package/build/src/utils/progress.js.map +1 -1
  179. package/build/src/utils/prompts.js +4 -4
  180. package/build/src/utils/prompts.js.map +1 -1
  181. package/build/src/utils/tar.js +3 -0
  182. package/build/src/utils/tar.js.map +1 -1
  183. package/build/src/utils/validateApplicationId.js +9 -2
  184. package/build/src/utils/validateApplicationId.js.map +1 -1
  185. package/build/src/utils/variadic.js +47 -0
  186. package/build/src/utils/variadic.js.map +1 -0
  187. package/package.json +13 -8
  188. package/static/template/babel.config.js +6 -0
  189. package/static/template/index.html +117 -0
  190. package/static/template/metro.config.js +4 -0
  191. package/static/template/serve.json +13 -0
  192. package/static/template/webpack.config.js +7 -0
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _resolvePlatform = require("./resolvePlatform");
6
+ class HistoryFallbackMiddleware {
7
+ constructor(indexMiddleware){
8
+ this.indexMiddleware = indexMiddleware;
9
+ }
10
+ getHandler() {
11
+ return (req, res, next)=>{
12
+ const platform = (0, _resolvePlatform).parsePlatformHeader(req);
13
+ if (!platform || platform === "web") {
14
+ // Redirect unknown to the manifest handler while preserving the path.
15
+ // This implements the HTML5 history fallback API.
16
+ return this.indexMiddleware(req, res, next);
17
+ }
18
+ return next();
19
+ };
20
+ }
21
+ }
22
+ exports.HistoryFallbackMiddleware = HistoryFallbackMiddleware;
23
+
24
+ //# sourceMappingURL=HistoryFallbackMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/HistoryFallbackMiddleware.ts"],"sourcesContent":["import { parsePlatformHeader } from './resolvePlatform';\nimport { ServerNext, ServerRequest, ServerResponse } from './server.types';\n\n/**\n * Create a web-only middleware which redirects to the index middleware without losing the path component.\n * This is useful for things like React Navigation which need to render the index.html and then direct the user in-memory.\n */\nexport class HistoryFallbackMiddleware {\n constructor(\n private indexMiddleware: (\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ) => Promise<void>\n ) {}\n getHandler() {\n return (req: ServerRequest, res: ServerResponse, next: any) => {\n const platform = parsePlatformHeader(req);\n\n if (!platform || platform === 'web') {\n // Redirect unknown to the manifest handler while preserving the path.\n // This implements the HTML5 history fallback API.\n return this.indexMiddleware(req, res, next);\n }\n\n return next();\n };\n }\n}\n"],"names":["HistoryFallbackMiddleware","constructor","indexMiddleware","getHandler","req","res","next","platform","parsePlatformHeader"],"mappings":"AAAA;;;;AAAoC,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;AAOhD,MAAMA,yBAAyB;IACpCC,YACUC,eAIU,CAClB;aALQA,eAIU,GAJVA,eAIU;KAChB;IACJC,UAAU,GAAG;QACX,OAAO,CAACC,GAAkB,EAAEC,GAAmB,EAAEC,IAAS,GAAK;YAC7D,MAAMC,QAAQ,GAAGC,CAAAA,GAAAA,gBAAmB,AAAK,CAAA,oBAAL,CAACJ,GAAG,CAAC,AAAC;YAE1C,IAAI,CAACG,QAAQ,IAAIA,QAAQ,KAAK,KAAK,EAAE;gBACnC,sEAAsE;gBACtE,kDAAkD;gBAClD,OAAO,IAAI,CAACL,eAAe,CAACE,GAAG,EAAEC,GAAG,EAAEC,IAAI,CAAC,CAAC;aAC7C;YAED,OAAOA,IAAI,EAAE,CAAC;SACf,CAAC;KACH;CACF;QArBYN,yBAAyB,GAAzBA,yBAAyB"}
@@ -15,6 +15,7 @@ function _interopRequireDefault(obj) {
15
15
  default: obj
16
16
  };
17
17
  }
18
+ const debug = require("debug")("expo:start:server:middleware:interstitialPage");
18
19
  const LoadingEndpoint = "/_expo/loading";
19
20
  exports.LoadingEndpoint = LoadingEndpoint;
20
21
  function getRuntimeVersion(exp, platform) {
@@ -58,6 +59,7 @@ class InterstitialPageMiddleware extends _expoMiddleware.ExpoMiddleware {
58
59
  (0, _resolvePlatform).assertMissingRuntimePlatform(platform);
59
60
  (0, _resolvePlatform).assertRuntimePlatform(platform);
60
61
  const { appName , runtimeVersion } = this._getProjectOptions(platform);
62
+ debug(`Create loading page. (platform: ${platform}, appName: ${appName}, runtimeVersion: ${runtimeVersion})`);
61
63
  const content = await this._getPageAsync({
62
64
  appName,
63
65
  runtimeVersion
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/InterstitialPageMiddleware.ts"],"sourcesContent":["import { ExpoConfig, getConfig, getNameFromConfig } from '@expo/config';\nimport { getRuntimeVersionNullable } from '@expo/config-plugins/build/utils/Updates';\nimport { readFile } from 'fs/promises';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { disableResponseCache, ExpoMiddleware } from './ExpoMiddleware';\nimport {\n assertMissingRuntimePlatform,\n assertRuntimePlatform,\n parsePlatformHeader,\n RuntimePlatform,\n} from './resolvePlatform';\nimport { ServerRequest, ServerResponse } from './server.types';\n\nexport const LoadingEndpoint = '/_expo/loading';\n\nfunction getRuntimeVersion(exp: ExpoConfig, platform: 'android' | 'ios' | null): string {\n if (!platform) {\n return 'Undetected';\n }\n\n return getRuntimeVersionNullable(exp, platform) ?? 'Undetected';\n}\n\nexport class InterstitialPageMiddleware extends ExpoMiddleware {\n constructor(projectRoot: string) {\n super(projectRoot, [LoadingEndpoint]);\n }\n\n /** Get the template HTML page and inject values. */\n async _getPageAsync({\n appName,\n runtimeVersion,\n }: {\n appName: string;\n runtimeVersion: string | null;\n }): Promise<string> {\n const templatePath =\n // Production: This will resolve when installed in the project.\n resolveFrom.silent(this.projectRoot, 'expo/static/loading-page/index.html') ??\n // Development: This will resolve when testing locally.\n path.resolve(__dirname, '../../../../../static/loading-page/index.html');\n let content = (await readFile(templatePath)).toString('utf-8');\n\n content = content.replace(/{{\\s*AppName\\s*}}/, appName);\n content = content.replace(/{{\\s*RuntimeVersion\\s*}}/, runtimeVersion ?? '');\n content = content.replace(/{{\\s*Path\\s*}}/, this.projectRoot);\n\n return content;\n }\n\n /** Get settings for the page from the project config. */\n _getProjectOptions(platform: RuntimePlatform): {\n appName: string;\n runtimeVersion: string | null;\n } {\n assertRuntimePlatform(platform);\n\n const { exp } = getConfig(this.projectRoot);\n const { appName } = getNameFromConfig(exp);\n const runtimeVersion = getRuntimeVersion(exp, platform);\n\n return {\n appName: appName ?? 'App',\n runtimeVersion,\n };\n }\n\n async handleRequestAsync(req: ServerRequest, res: ServerResponse): Promise<void> {\n res = disableResponseCache(res);\n res.setHeader('Content-Type', 'text/html');\n\n const platform = parsePlatformHeader(req);\n assertMissingRuntimePlatform(platform);\n assertRuntimePlatform(platform);\n\n const { appName, runtimeVersion } = this._getProjectOptions(platform);\n const content = await this._getPageAsync({ appName, runtimeVersion });\n res.end(content);\n }\n}\n"],"names":["LoadingEndpoint","getRuntimeVersion","exp","platform","getRuntimeVersionNullable","InterstitialPageMiddleware","ExpoMiddleware","constructor","projectRoot","_getPageAsync","appName","runtimeVersion","resolveFrom","templatePath","silent","path","resolve","__dirname","content","readFile","toString","replace","_getProjectOptions","assertRuntimePlatform","getConfig","getNameFromConfig","handleRequestAsync","req","res","disableResponseCache","setHeader","parsePlatformHeader","assertMissingRuntimePlatform","end"],"mappings":"AAAA;;;;;AAAyD,IAAA,OAAc,WAAd,cAAc,CAAA;AAC7B,IAAA,QAA0C,WAA1C,0CAA0C,CAAA;AAC3D,IAAA,SAAa,WAAb,aAAa,CAAA;AACrB,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAEe,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAMhE,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;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AACf,OAAO,CAAC,CAAC;KAClB;CACF;QAxDYb,0BAA0B,GAA1BA,0BAA0B"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/InterstitialPageMiddleware.ts"],"sourcesContent":["import { ExpoConfig, getConfig, getNameFromConfig } from '@expo/config';\nimport { getRuntimeVersionNullable } from '@expo/config-plugins/build/utils/Updates';\nimport { readFile } from 'fs/promises';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { disableResponseCache, ExpoMiddleware } from './ExpoMiddleware';\nimport {\n assertMissingRuntimePlatform,\n assertRuntimePlatform,\n parsePlatformHeader,\n RuntimePlatform,\n} from './resolvePlatform';\nimport { ServerRequest, ServerResponse } from './server.types';\n\nconst debug = require('debug')(\n 'expo:start:server:middleware:interstitialPage'\n) as typeof console.log;\n\nexport const LoadingEndpoint = '/_expo/loading';\n\nfunction getRuntimeVersion(exp: ExpoConfig, platform: 'android' | 'ios' | null): string {\n if (!platform) {\n return 'Undetected';\n }\n\n return getRuntimeVersionNullable(exp, platform) ?? 'Undetected';\n}\n\nexport class InterstitialPageMiddleware extends ExpoMiddleware {\n constructor(projectRoot: string) {\n super(projectRoot, [LoadingEndpoint]);\n }\n\n /** Get the template HTML page and inject values. */\n async _getPageAsync({\n appName,\n runtimeVersion,\n }: {\n appName: string;\n runtimeVersion: string | null;\n }): Promise<string> {\n const templatePath =\n // Production: This will resolve when installed in the project.\n resolveFrom.silent(this.projectRoot, 'expo/static/loading-page/index.html') ??\n // Development: This will resolve when testing locally.\n path.resolve(__dirname, '../../../../../static/loading-page/index.html');\n let content = (await readFile(templatePath)).toString('utf-8');\n\n content = content.replace(/{{\\s*AppName\\s*}}/, appName);\n content = content.replace(/{{\\s*RuntimeVersion\\s*}}/, runtimeVersion ?? '');\n content = content.replace(/{{\\s*Path\\s*}}/, this.projectRoot);\n\n return content;\n }\n\n /** Get settings for the page from the project config. */\n _getProjectOptions(platform: RuntimePlatform): {\n appName: string;\n runtimeVersion: string | null;\n } {\n assertRuntimePlatform(platform);\n\n const { exp } = getConfig(this.projectRoot);\n const { appName } = getNameFromConfig(exp);\n const runtimeVersion = getRuntimeVersion(exp, platform);\n\n return {\n appName: appName ?? 'App',\n runtimeVersion,\n };\n }\n\n async handleRequestAsync(req: ServerRequest, res: ServerResponse): Promise<void> {\n res = disableResponseCache(res);\n res.setHeader('Content-Type', 'text/html');\n\n const platform = parsePlatformHeader(req);\n assertMissingRuntimePlatform(platform);\n assertRuntimePlatform(platform);\n\n const { appName, runtimeVersion } = this._getProjectOptions(platform);\n debug(\n `Create loading page. (platform: ${platform}, appName: ${appName}, runtimeVersion: ${runtimeVersion})`\n );\n const content = await this._getPageAsync({ appName, runtimeVersion });\n res.end(content);\n }\n}\n"],"names":["debug","require","LoadingEndpoint","getRuntimeVersion","exp","platform","getRuntimeVersionNullable","InterstitialPageMiddleware","ExpoMiddleware","constructor","projectRoot","_getPageAsync","appName","runtimeVersion","resolveFrom","templatePath","silent","path","resolve","__dirname","content","readFile","toString","replace","_getProjectOptions","assertRuntimePlatform","getConfig","getNameFromConfig","handleRequestAsync","req","res","disableResponseCache","setHeader","parsePlatformHeader","assertMissingRuntimePlatform","end"],"mappings":"AAAA;;;;;AAAyD,IAAA,OAAc,WAAd,cAAc,CAAA;AAC7B,IAAA,QAA0C,WAA1C,0CAA0C,CAAA;AAC3D,IAAA,SAAa,WAAb,aAAa,CAAA;AACrB,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAEe,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAMhE,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;;;;AAG1B,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAC5B,+CAA+C,CAChD,AAAsB,AAAC;AAEjB,MAAMC,eAAe,GAAG,gBAAgB,AAAC;QAAnCA,eAAe,GAAfA,eAAe;AAE5B,SAASC,iBAAiB,CAACC,GAAe,EAAEC,QAAkC,EAA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AG,CAACf,OAAO,CAAC,CAAC;KAClB;CACF;QA3DYb,0BAA0B,GAA1BA,0BAA0B"}
@@ -8,9 +8,12 @@ var _url = require("url");
8
8
  var Log = _interopRequireWildcard(require("../../../log"));
9
9
  var _url1 = require("../../../utils/url");
10
10
  var ProjectDevices = _interopRequireWildcard(require("../../project/devices"));
11
+ var _platformBundlers = require("../platformBundlers");
12
+ var _webTemplate = require("../webTemplate");
11
13
  var _expoMiddleware = require("./ExpoMiddleware");
12
14
  var _resolveAssets = require("./resolveAssets");
13
15
  var _resolveEntryPoint = require("./resolveEntryPoint");
16
+ var _resolvePlatform = require("./resolvePlatform");
14
17
  function _interopRequireWildcard(obj) {
15
18
  if (obj && obj.__esModule) {
16
19
  return obj;
@@ -45,6 +48,7 @@ class ManifestMiddleware extends _expoMiddleware.ExpoMiddleware {
45
48
  ]);
46
49
  this.projectRoot = projectRoot;
47
50
  this.options = options;
51
+ this.initialProjectConfig = (0, _config).getConfig(projectRoot);
48
52
  }
49
53
  /** Exposed for testing. */ async _resolveProjectSettingsAsync({ platform , hostname }) {
50
54
  // Read the config
@@ -96,6 +100,17 @@ class ManifestMiddleware extends _expoMiddleware.ExpoMiddleware {
96
100
  }
97
101
  }
98
102
  /** Create the bundle URL (points to the single JS entry file). Exposed for testing. */ _getBundleUrl({ platform , mainModuleName , hostname }) {
103
+ const path = this._getBundleUrlPath({
104
+ platform,
105
+ mainModuleName
106
+ });
107
+ return this.options.constructUrl({
108
+ scheme: "http",
109
+ // hostType: this.options.location.hostType,
110
+ hostname
111
+ }) + path;
112
+ }
113
+ _getBundleUrlPath({ platform , mainModuleName }) {
99
114
  const queryParams = new URLSearchParams({
100
115
  platform: encodeURIComponent(platform),
101
116
  dev: String(this.options.mode !== "production"),
@@ -105,12 +120,7 @@ class ManifestMiddleware extends _expoMiddleware.ExpoMiddleware {
105
120
  if (this.options.minify) {
106
121
  queryParams.append("minify", String(this.options.minify));
107
122
  }
108
- const path = `/${encodeURI(mainModuleName)}.bundle?${queryParams.toString()}`;
109
- return this.options.constructUrl({
110
- scheme: "http",
111
- // hostType: this.options.location.hostType,
112
- hostname
113
- }) + path;
123
+ return `/${encodeURI(mainModuleName)}.bundle?${queryParams.toString()}`;
114
124
  }
115
125
  getExpoGoConfig({ mainModuleName , hostname }) {
116
126
  return {
@@ -158,7 +168,48 @@ class ManifestMiddleware extends _expoMiddleware.ExpoMiddleware {
158
168
  // The server normally inserts this but if we're offline we'll do it here
159
169
  await (0, _resolveAssets).resolveGoogleServicesFile(this.projectRoot, manifest);
160
170
  }
171
+ /**
172
+ * Web platforms should create an index.html response using the same script resolution as native.
173
+ *
174
+ * Instead of adding a `bundleUrl` to a `manifest.json` (native) we'll add a `<script src="">`
175
+ * to an `index.html`, this enables the web platform to load JavaScript from the server.
176
+ */ async handleWebRequestAsync(req, res) {
177
+ const platform = "web";
178
+ // Read from headers
179
+ const mainModuleName = this.resolveMainModuleName(this.initialProjectConfig, platform);
180
+ const bundleUrl = this._getBundleUrlPath({
181
+ platform,
182
+ mainModuleName
183
+ });
184
+ res.setHeader("Content-Type", "text/html");
185
+ res.end(await (0, _webTemplate).createTemplateHtmlFromExpoConfigAsync(this.projectRoot, {
186
+ exp: this.initialProjectConfig.exp,
187
+ scripts: [
188
+ bundleUrl
189
+ ]
190
+ }));
191
+ }
192
+ /** Exposed for testing. */ async checkBrowserRequestAsync(req, res) {
193
+ // Read the config
194
+ const bundlers = (0, _platformBundlers).getPlatformBundlers(this.initialProjectConfig.exp);
195
+ if (bundlers.web === "metro") {
196
+ // NOTE(EvanBacon): This effectively disables the safety check we do on custom runtimes to ensure
197
+ // the `expo-platform` header is included. When `web.bundler=web`, if the user has non-standard Expo
198
+ // code loading then they'll get a web bundle without a clear assertion of platform support.
199
+ const platform = (0, _resolvePlatform).parsePlatformHeader(req);
200
+ // On web, serve the public folder
201
+ if (!platform || platform === "web") {
202
+ await this.handleWebRequestAsync(req, res);
203
+ return true;
204
+ }
205
+ }
206
+ return false;
207
+ }
161
208
  async handleRequestAsync(req, res, next) {
209
+ // First check for standard JavaScript runtimes (aka legacy browsers like Chrome).
210
+ if (await this.checkBrowserRequestAsync(req, res)) {
211
+ return;
212
+ }
162
213
  // Save device IDs for dev client.
163
214
  await this.saveDevicesAsync(req);
164
215
  // Read from headers
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/ManifestMiddleware.ts"],"sourcesContent":["import { ExpoConfig, ExpoGoConfig, getConfig, ProjectConfig } from '@expo/config';\nimport { resolve } from 'url';\n\nimport * as Log from '../../../log';\nimport { stripExtension } from '../../../utils/url';\nimport * as ProjectDevices from '../../project/devices';\nimport { UrlCreator } from '../UrlCreator';\nimport { ExpoMiddleware } from './ExpoMiddleware';\nimport { resolveGoogleServicesFile, resolveManifestAssets } from './resolveAssets';\nimport { resolveEntryPoint } from './resolveEntryPoint';\nimport { RuntimePlatform } from './resolvePlatform';\nimport { ServerHeaders, ServerNext, ServerRequest, ServerResponse } from './server.types';\n\n/** Info about the computer hosting the dev server. */\nexport interface HostInfo {\n host: string;\n server: 'expo';\n serverVersion: string;\n serverDriver: string | null;\n serverOS: NodeJS.Platform;\n serverOSVersion: string;\n}\n\n/** Parsed values from the supported request headers. */\nexport interface ManifestRequestInfo {\n /** Should return the signed manifest. */\n acceptSignature: boolean;\n /** Platform to serve. */\n platform: RuntimePlatform;\n /** Requested host name. */\n hostname?: string | null;\n}\n\n/** Project related info. */\nexport type ResponseProjectSettings = {\n expoGoConfig: ExpoGoConfig;\n hostUri: string;\n bundleUrl: string;\n exp: ExpoConfig;\n};\n\nexport const DEVELOPER_TOOL = 'expo-cli';\n\nexport type ManifestMiddlewareOptions = {\n /** Should start the dev servers in development mode (minify). */\n mode?: 'development' | 'production';\n /** Should instruct the bundler to create minified bundles. */\n minify?: boolean;\n constructUrl: UrlCreator['constructUrl'];\n isNativeWebpack?: boolean;\n privateKeyPath?: string;\n};\n\n/** Base middleware creator for serving the Expo manifest (like the index.html but for native runtimes). */\nexport abstract class ManifestMiddleware<\n TManifestRequestInfo extends ManifestRequestInfo\n> extends ExpoMiddleware {\n constructor(protected projectRoot: string, protected options: ManifestMiddlewareOptions) {\n super(\n projectRoot,\n /**\n * Only support `/`, `/manifest`, `/index.exp` for the manifest middleware.\n */\n ['/', '/manifest', '/index.exp']\n );\n }\n\n /** Exposed for testing. */\n public async _resolveProjectSettingsAsync({\n platform,\n hostname,\n }: Pick<TManifestRequestInfo, 'hostname' | 'platform'>): Promise<ResponseProjectSettings> {\n // Read the config\n const projectConfig = getConfig(this.projectRoot);\n\n // Read from headers\n const mainModuleName = this.resolveMainModuleName(projectConfig, platform);\n\n // Create the manifest and set fields within it\n const expoGoConfig = this.getExpoGoConfig({\n mainModuleName,\n hostname,\n });\n\n const hostUri = this.options.constructUrl({ scheme: '', hostname });\n\n const bundleUrl = this._getBundleUrl({\n platform,\n mainModuleName,\n hostname,\n });\n\n // Resolve all assets and set them on the manifest as URLs\n await this.mutateManifestWithAssetsAsync(projectConfig.exp, bundleUrl);\n\n return {\n expoGoConfig,\n hostUri,\n bundleUrl,\n exp: projectConfig.exp,\n };\n }\n\n /** Get the main entry module ID (file) relative to the project root. */\n private resolveMainModuleName(projectConfig: ProjectConfig, platform: string): string {\n let entryPoint = resolveEntryPoint(this.projectRoot, platform, projectConfig);\n // NOTE(Bacon): Webpack is currently hardcoded to index.bundle on native\n // in the future (TODO) we should move this logic into a Webpack plugin and use\n // a generated file name like we do on web.\n // const server = getDefaultDevServer();\n // // TODO: Move this into BundlerDevServer and read this info from self.\n // const isNativeWebpack = server instanceof WebpackBundlerDevServer && server.isTargetingNative();\n if (this.options.isNativeWebpack) {\n entryPoint = 'index.js';\n }\n\n return stripExtension(entryPoint, 'js');\n }\n\n /** Parse request headers into options. */\n public abstract getParsedHeaders(req: ServerRequest): TManifestRequestInfo;\n\n /** Store device IDs that were sent in the request headers. */\n private async saveDevicesAsync(req: ServerRequest) {\n const deviceIds = req.headers?.['expo-dev-client-id'];\n if (deviceIds) {\n await ProjectDevices.saveDevicesAsync(this.projectRoot, deviceIds).catch((e) =>\n Log.exception(e)\n );\n }\n }\n\n /** Create the bundle URL (points to the single JS entry file). Exposed for testing. */\n public _getBundleUrl({\n platform,\n mainModuleName,\n hostname,\n }: {\n platform: string;\n hostname?: string | null;\n mainModuleName: string;\n }): string {\n const queryParams = new URLSearchParams({\n platform: encodeURIComponent(platform),\n dev: String(this.options.mode !== 'production'),\n // TODO: Is this still needed?\n hot: String(false),\n });\n\n if (this.options.minify) {\n queryParams.append('minify', String(this.options.minify));\n }\n\n const path = `/${encodeURI(mainModuleName)}.bundle?${queryParams.toString()}`;\n\n return (\n this.options.constructUrl({\n scheme: 'http',\n // hostType: this.options.location.hostType,\n hostname,\n }) + path\n );\n }\n\n /** Log telemetry. */\n protected abstract trackManifest(version?: string): void;\n\n /** Get the manifest response to return to the runtime. This file contains info regarding where the assets can be loaded from. Exposed for testing. */\n public abstract _getManifestResponseAsync(options: TManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }>;\n\n private getExpoGoConfig({\n mainModuleName,\n hostname,\n }: {\n mainModuleName: string;\n hostname?: string | null;\n }): ExpoGoConfig {\n return {\n // localhost:19000\n debuggerHost: this.options.constructUrl({ scheme: '', hostname }),\n // http://localhost:19000/logs -- used to send logs to the CLI for displaying in the terminal.\n // This is deprecated in favor of the WebSocket connection setup in Metro.\n logUrl: this.options.constructUrl({ scheme: 'http', hostname }) + '/logs',\n // Required for Expo Go to function.\n developer: {\n tool: DEVELOPER_TOOL,\n projectRoot: this.projectRoot,\n },\n packagerOpts: {\n // Required for dev client.\n dev: this.options.mode !== 'production',\n },\n // Indicates the name of the main bundle.\n mainModuleName,\n // Add this string to make Flipper register React Native / Metro as \"running\".\n // Can be tested by running:\n // `METRO_SERVER_PORT=19000 open -a flipper.app`\n // Where 19000 is the port where the Expo project is being hosted.\n __flipperHack: 'React Native packager is running',\n };\n }\n\n /** Resolve all assets and set them on the manifest as URLs */\n private async mutateManifestWithAssetsAsync(manifest: ExpoConfig, bundleUrl: string) {\n await resolveManifestAssets(this.projectRoot, {\n manifest,\n resolver: async (path) => {\n if (this.options.isNativeWebpack) {\n // When using our custom dev server, just do assets normally\n // without the `assets/` subpath redirect.\n return resolve(bundleUrl!.match(/^https?:\\/\\/.*?\\//)![0], path);\n }\n return bundleUrl!.match(/^https?:\\/\\/.*?\\//)![0] + 'assets/' + path;\n },\n });\n // The server normally inserts this but if we're offline we'll do it here\n await resolveGoogleServicesFile(this.projectRoot, manifest);\n }\n\n async handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void> {\n // Save device IDs for dev client.\n await this.saveDevicesAsync(req);\n\n // Read from headers\n const options = this.getParsedHeaders(req);\n const { body, version, headers } = await this._getManifestResponseAsync(options);\n for (const [headerName, headerValue] of headers) {\n res.setHeader(headerName, headerValue);\n }\n res.end(body);\n\n // Log analytics\n this.trackManifest(version ?? null);\n }\n}\n"],"names":["Log","ProjectDevices","DEVELOPER_TOOL","ManifestMiddleware","ExpoMiddleware","constructor","projectRoot","options","_resolveProjectSettingsAsync","platform","hostname","projectConfig","getConfig","mainModuleName","resolveMainModuleName","expoGoConfig","getExpoGoConfig","hostUri","constructUrl","scheme","bundleUrl","_getBundleUrl","mutateManifestWithAssetsAsync","exp","entryPoint","resolveEntryPoint","isNativeWebpack","stripExtension","saveDevicesAsync","req","deviceIds","headers","catch","e","exception","queryParams","URLSearchParams","encodeURIComponent","dev","String","mode","hot","minify","append","path","encodeURI","toString","debuggerHost","logUrl","developer","tool","packagerOpts","__flipperHack","manifest","resolveManifestAssets","resolver","resolve","match","resolveGoogleServicesFile","handleRequestAsync","res","next","getParsedHeaders","body","version","_getManifestResponseAsync","headerName","headerValue","setHeader","end","trackManifest"],"mappings":"AAAA;;;;;AAAmE,IAAA,OAAc,WAAd,cAAc,CAAA;AACzD,IAAA,IAAK,WAAL,KAAK,CAAA;AAEjBA,IAAAA,GAAG,mCAAM,cAA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AM,CAAC2D,UAAU,EAAEC,WAAW,CAAC,IAAIpC,OAAO,CAAE;YAC/C6B,GAAG,CAACQ,SAAS,CAACF,UAAU,EAAEC,WAAW,CAAC,CAAC;SACxC;QACDP,GAAG,CAACS,GAAG,CAACN,IAAI,CAAC,CAAC;QAEd,gBAAgB;QAChB,IAAI,CAACO,aAAa,CAACN,OAAO,WAAPA,OAAO,GAAI,IAAI,CAAC,CAAC;KACrC;CACF;QA5LqB7D,kBAAkB,GAAlBA,kBAAkB"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/ManifestMiddleware.ts"],"sourcesContent":["import { ExpoConfig, ExpoGoConfig, getConfig, ProjectConfig } from '@expo/config';\nimport { resolve } from 'url';\n\nimport * as Log from '../../../log';\nimport { stripExtension } from '../../../utils/url';\nimport * as ProjectDevices from '../../project/devices';\nimport { UrlCreator } from '../UrlCreator';\nimport { getPlatformBundlers } from '../platformBundlers';\nimport { createTemplateHtmlFromExpoConfigAsync } from '../webTemplate';\nimport { ExpoMiddleware } from './ExpoMiddleware';\nimport { resolveGoogleServicesFile, resolveManifestAssets } from './resolveAssets';\nimport { resolveEntryPoint } from './resolveEntryPoint';\nimport { parsePlatformHeader, RuntimePlatform } from './resolvePlatform';\nimport { ServerHeaders, ServerNext, ServerRequest, ServerResponse } from './server.types';\n\n/** Info about the computer hosting the dev server. */\nexport interface HostInfo {\n host: string;\n server: 'expo';\n serverVersion: string;\n serverDriver: string | null;\n serverOS: NodeJS.Platform;\n serverOSVersion: string;\n}\n\n/** Parsed values from the supported request headers. */\nexport interface ManifestRequestInfo {\n /** Should return the signed manifest. */\n acceptSignature: boolean;\n /** Platform to serve. */\n platform: RuntimePlatform;\n /** Requested host name. */\n hostname?: string | null;\n}\n\n/** Project related info. */\nexport type ResponseProjectSettings = {\n expoGoConfig: ExpoGoConfig;\n hostUri: string;\n bundleUrl: string;\n exp: ExpoConfig;\n};\n\nexport const DEVELOPER_TOOL = 'expo-cli';\n\nexport type ManifestMiddlewareOptions = {\n /** Should start the dev servers in development mode (minify). */\n mode?: 'development' | 'production';\n /** Should instruct the bundler to create minified bundles. */\n minify?: boolean;\n constructUrl: UrlCreator['constructUrl'];\n isNativeWebpack?: boolean;\n privateKeyPath?: string;\n};\n\n/** Base middleware creator for serving the Expo manifest (like the index.html but for native runtimes). */\nexport abstract class ManifestMiddleware<\n TManifestRequestInfo extends ManifestRequestInfo\n> extends ExpoMiddleware {\n private initialProjectConfig: ProjectConfig;\n\n constructor(protected projectRoot: string, protected options: ManifestMiddlewareOptions) {\n super(\n projectRoot,\n /**\n * Only support `/`, `/manifest`, `/index.exp` for the manifest middleware.\n */\n ['/', '/manifest', '/index.exp']\n );\n this.initialProjectConfig = getConfig(projectRoot);\n }\n\n /** Exposed for testing. */\n public async _resolveProjectSettingsAsync({\n platform,\n hostname,\n }: Pick<TManifestRequestInfo, 'hostname' | 'platform'>): Promise<ResponseProjectSettings> {\n // Read the config\n const projectConfig = getConfig(this.projectRoot);\n\n // Read from headers\n const mainModuleName = this.resolveMainModuleName(projectConfig, platform);\n\n // Create the manifest and set fields within it\n const expoGoConfig = this.getExpoGoConfig({\n mainModuleName,\n hostname,\n });\n\n const hostUri = this.options.constructUrl({ scheme: '', hostname });\n\n const bundleUrl = this._getBundleUrl({\n platform,\n mainModuleName,\n hostname,\n });\n\n // Resolve all assets and set them on the manifest as URLs\n await this.mutateManifestWithAssetsAsync(projectConfig.exp, bundleUrl);\n\n return {\n expoGoConfig,\n hostUri,\n bundleUrl,\n exp: projectConfig.exp,\n };\n }\n\n /** Get the main entry module ID (file) relative to the project root. */\n private resolveMainModuleName(projectConfig: ProjectConfig, platform: string): string {\n let entryPoint = resolveEntryPoint(this.projectRoot, platform, projectConfig);\n // NOTE(Bacon): Webpack is currently hardcoded to index.bundle on native\n // in the future (TODO) we should move this logic into a Webpack plugin and use\n // a generated file name like we do on web.\n // const server = getDefaultDevServer();\n // // TODO: Move this into BundlerDevServer and read this info from self.\n // const isNativeWebpack = server instanceof WebpackBundlerDevServer && server.isTargetingNative();\n if (this.options.isNativeWebpack) {\n entryPoint = 'index.js';\n }\n\n return stripExtension(entryPoint, 'js');\n }\n\n /** Parse request headers into options. */\n public abstract getParsedHeaders(req: ServerRequest): TManifestRequestInfo;\n\n /** Store device IDs that were sent in the request headers. */\n private async saveDevicesAsync(req: ServerRequest) {\n const deviceIds = req.headers?.['expo-dev-client-id'];\n if (deviceIds) {\n await ProjectDevices.saveDevicesAsync(this.projectRoot, deviceIds).catch((e) =>\n Log.exception(e)\n );\n }\n }\n\n /** Create the bundle URL (points to the single JS entry file). Exposed for testing. */\n public _getBundleUrl({\n platform,\n mainModuleName,\n hostname,\n }: {\n platform: string;\n hostname?: string | null;\n mainModuleName: string;\n }): string {\n const path = this._getBundleUrlPath({ platform, mainModuleName });\n\n return (\n this.options.constructUrl({\n scheme: 'http',\n // hostType: this.options.location.hostType,\n hostname,\n }) + path\n );\n }\n\n public _getBundleUrlPath({\n platform,\n mainModuleName,\n }: {\n platform: string;\n mainModuleName: string;\n }): string {\n const queryParams = new URLSearchParams({\n platform: encodeURIComponent(platform),\n dev: String(this.options.mode !== 'production'),\n // TODO: Is this still needed?\n hot: String(false),\n });\n\n if (this.options.minify) {\n queryParams.append('minify', String(this.options.minify));\n }\n\n return `/${encodeURI(mainModuleName)}.bundle?${queryParams.toString()}`;\n }\n\n /** Log telemetry. */\n protected abstract trackManifest(version?: string): void;\n\n /** Get the manifest response to return to the runtime. This file contains info regarding where the assets can be loaded from. Exposed for testing. */\n public abstract _getManifestResponseAsync(options: TManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }>;\n\n private getExpoGoConfig({\n mainModuleName,\n hostname,\n }: {\n mainModuleName: string;\n hostname?: string | null;\n }): ExpoGoConfig {\n return {\n // localhost:19000\n debuggerHost: this.options.constructUrl({ scheme: '', hostname }),\n // http://localhost:19000/logs -- used to send logs to the CLI for displaying in the terminal.\n // This is deprecated in favor of the WebSocket connection setup in Metro.\n logUrl: this.options.constructUrl({ scheme: 'http', hostname }) + '/logs',\n // Required for Expo Go to function.\n developer: {\n tool: DEVELOPER_TOOL,\n projectRoot: this.projectRoot,\n },\n packagerOpts: {\n // Required for dev client.\n dev: this.options.mode !== 'production',\n },\n // Indicates the name of the main bundle.\n mainModuleName,\n // Add this string to make Flipper register React Native / Metro as \"running\".\n // Can be tested by running:\n // `METRO_SERVER_PORT=19000 open -a flipper.app`\n // Where 19000 is the port where the Expo project is being hosted.\n __flipperHack: 'React Native packager is running',\n };\n }\n\n /** Resolve all assets and set them on the manifest as URLs */\n private async mutateManifestWithAssetsAsync(manifest: ExpoConfig, bundleUrl: string) {\n await resolveManifestAssets(this.projectRoot, {\n manifest,\n resolver: async (path) => {\n if (this.options.isNativeWebpack) {\n // When using our custom dev server, just do assets normally\n // without the `assets/` subpath redirect.\n return resolve(bundleUrl!.match(/^https?:\\/\\/.*?\\//)![0], path);\n }\n return bundleUrl!.match(/^https?:\\/\\/.*?\\//)![0] + 'assets/' + path;\n },\n });\n // The server normally inserts this but if we're offline we'll do it here\n await resolveGoogleServicesFile(this.projectRoot, manifest);\n }\n\n /**\n * Web platforms should create an index.html response using the same script resolution as native.\n *\n * Instead of adding a `bundleUrl` to a `manifest.json` (native) we'll add a `<script src=\"\">`\n * to an `index.html`, this enables the web platform to load JavaScript from the server.\n */\n private async handleWebRequestAsync(req: ServerRequest, res: ServerResponse) {\n const platform = 'web';\n // Read from headers\n const mainModuleName = this.resolveMainModuleName(this.initialProjectConfig, platform);\n const bundleUrl = this._getBundleUrlPath({\n platform,\n mainModuleName,\n });\n\n res.setHeader('Content-Type', 'text/html');\n\n res.end(\n await createTemplateHtmlFromExpoConfigAsync(this.projectRoot, {\n exp: this.initialProjectConfig.exp,\n scripts: [bundleUrl],\n })\n );\n }\n\n /** Exposed for testing. */\n async checkBrowserRequestAsync(req: ServerRequest, res: ServerResponse) {\n // Read the config\n const bundlers = getPlatformBundlers(this.initialProjectConfig.exp);\n if (bundlers.web === 'metro') {\n // NOTE(EvanBacon): This effectively disables the safety check we do on custom runtimes to ensure\n // the `expo-platform` header is included. When `web.bundler=web`, if the user has non-standard Expo\n // code loading then they'll get a web bundle without a clear assertion of platform support.\n const platform = parsePlatformHeader(req);\n // On web, serve the public folder\n if (!platform || platform === 'web') {\n await this.handleWebRequestAsync(req, res);\n return true;\n }\n }\n return false;\n }\n\n async handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void> {\n // First check for standard JavaScript runtimes (aka legacy browsers like Chrome).\n if (await this.checkBrowserRequestAsync(req, res)) {\n return;\n }\n\n // Save device IDs for dev client.\n await this.saveDevicesAsync(req);\n\n // Read from headers\n const options = this.getParsedHeaders(req);\n const { body, version, headers } = await this._getManifestResponseAsync(options);\n for (const [headerName, headerValue] of headers) {\n res.setHeader(headerName, headerValue);\n }\n res.end(body);\n\n // Log analytics\n this.trackManifest(version ?? null);\n }\n}\n"],"names":["Log","ProjectDevices","DEVELOPER_TOOL","ManifestMiddleware","ExpoMiddleware","constructor","projectRoot","options","initialProjectConfig","getConfig","_resolveProjectSettingsAsync","platform","hostname","projectConfig","mainModuleName","resolveMainModuleName","expoGoConfig","getExpoGoConfig","hostUri","constructUrl","scheme","bundleUrl","_getBundleUrl","mutateManifestWithAssetsAsync","exp","entryPoint","resolveEntryPoint","isNativeWebpack","stripExtension","saveDevicesAsync","req","deviceIds","headers","catch","e","exception","path","_getBundleUrlPath","queryParams","URLSearchParams","encodeURIComponent","dev","String","mode","hot","minify","append","encodeURI","toString","debuggerHost","logUrl","developer","tool","packagerOpts","__flipperHack","manifest","resolveManifestAssets","resolver","resolve","match","resolveGoogleServicesFile","handleWebRequestAsync","res","setHeader","end","createTemplateHtmlFromExpoConfigAsync","scripts","checkBrowserRequestAsync","bundlers","getPlatformBundlers","web","parsePlatformHeader","handleRequestAsync","next","getParsedHeaders","body","version","_getManifestResponseAsync","headerName","headerValue","trackManifest"],"mappings":"AAAA;;;;;AAAmE,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CAACkD,qBAAqB,CAAC/B,GAAG,EAAEgC,GAAG,CAAC,CAAC;gBAC3C,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;KACd;IAED,MAAMU,kBAAkB,CACtB1C,GAAkB,EAClBgC,GAAmB,EACnBW,IAAgB,EACD;QACf,kFAAkF;QAClF,IAAI,MAAM,IAAI,CAACN,wBAAwB,CAACrC,GAAG,EAAEgC,GAAG,CAAC,EAAE;YACjD,OAAO;SACR;QAED,kCAAkC;QAClC,MAAM,IAAI,CAACjC,gBAAgB,CAACC,GAAG,CAAC,CAAC;QAEjC,oBAAoB;QACpB,MAAMvB,OAAO,GAAG,IAAI,CAACmE,gBAAgB,CAAC5C,GAAG,CAAC,AAAC;QAC3C,MAAM,EAAE6C,IAAI,CAAA,EAAEC,OAAO,CAAA,EAAE5C,OAAO,CAAA,EAAE,GAAG,MAAM,IAAI,CAAC6C,yBAAyB,CAACtE,OAAO,CAAC,AAAC;QACjF,KAAK,MAAM,CAACuE,UAAU,EAAEC,WAAW,CAAC,IAAI/C,OAAO,CAAE;YAC/C8B,GAAG,CAACC,SAAS,CAACe,UAAU,EAAEC,WAAW,CAAC,CAAC;SACxC;QACDjB,GAAG,CAACE,GAAG,CAACW,IAAI,CAAC,CAAC;QAEd,gBAAgB;QAChB,IAAI,CAACK,aAAa,CAACJ,OAAO,WAAPA,OAAO,GAAI,IAAI,CAAC,CAAC;KACrC;CACF;QAzPqBzE,kBAAkB,GAAlBA,kBAAkB"}
@@ -27,6 +27,7 @@ function _interopRequireWildcard(obj) {
27
27
  return newObj;
28
28
  }
29
29
  }
30
+ const debug = require("debug")("expo:start:server:middleware:runtimeRedirect");
30
31
  class RuntimeRedirectMiddleware extends _expoMiddleware.ExpoMiddleware {
31
32
  constructor(projectRoot, options){
32
33
  super(projectRoot, [
@@ -42,6 +43,10 @@ class RuntimeRedirectMiddleware extends _expoMiddleware.ExpoMiddleware {
42
43
  (0, _resolvePlatform).assertMissingRuntimePlatform(platform);
43
44
  (0, _resolvePlatform).assertRuntimePlatform(platform);
44
45
  const runtime = isDevClient ? "custom" : "expo";
46
+ debug(`props:`, {
47
+ platform,
48
+ runtime
49
+ });
45
50
  this.options.onDeepLink({
46
51
  runtime,
47
52
  platform
@@ -55,7 +60,7 @@ class RuntimeRedirectMiddleware extends _expoMiddleware.ExpoMiddleware {
55
60
  res.end();
56
61
  return;
57
62
  }
58
- Log.debug("Redirect ->", redirect);
63
+ debug("Redirect ->", redirect);
59
64
  res.setHeader("Location", redirect);
60
65
  // Disable caching
61
66
  (0, _expoMiddleware).disableResponseCache(res);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/RuntimeRedirectMiddleware.ts"],"sourcesContent":["import { parse } from 'url';\n\nimport * as Log from '../../../log';\nimport { disableResponseCache, ExpoMiddleware } from './ExpoMiddleware';\nimport {\n assertMissingRuntimePlatform,\n assertRuntimePlatform,\n parsePlatformHeader,\n RuntimePlatform,\n} from './resolvePlatform';\nimport { ServerRequest, ServerResponse } from './server.types';\n\n/** Runtime to target: expo = Expo Go, custom = Dev Client. */\ntype RuntimeTarget = 'expo' | 'custom';\n\nexport class RuntimeRedirectMiddleware extends ExpoMiddleware {\n constructor(\n protected projectRoot: string,\n protected options: {\n onDeepLink: (props: {\n runtime: RuntimeTarget;\n platform: RuntimePlatform;\n }) => void | Promise<void>;\n getLocation: (props: { runtime: RuntimeTarget }) => string | null | undefined;\n }\n ) {\n super(projectRoot, ['/_expo/link']);\n }\n\n async handleRequestAsync(req: ServerRequest, res: ServerResponse): Promise<void> {\n const { query } = parse(req.url!, true);\n const isDevClient = query['choice'] === 'expo-dev-client';\n const platform = parsePlatformHeader(req);\n assertMissingRuntimePlatform(platform);\n assertRuntimePlatform(platform);\n const runtime = isDevClient ? 'custom' : 'expo';\n\n this.options.onDeepLink({ runtime, platform });\n\n const redirect = this.options.getLocation({ runtime });\n if (!redirect) {\n Log.warn(\n `[redirect middleware]: Unable to determine redirect location for runtime '${runtime}' and platform '${platform}'`\n );\n res.statusCode = 404;\n res.end();\n return;\n }\n Log.debug('Redirect ->', redirect);\n res.setHeader('Location', redirect);\n\n // Disable caching\n disableResponseCache(res);\n\n // 'Temporary Redirect'\n res.statusCode = 307;\n res.end();\n }\n}\n"],"names":["Log","RuntimeRedirectMiddleware","ExpoMiddleware","constructor","projectRoot","options","handleRequestAsync","req","res","query","parse","url","isDevClient","platform","parsePlatformHeader","assertMissingRuntimePlatform","assertRuntimePlatform","runtime","onDeepLink","redirect","getLocation","warn","statusCode","end","debug","setHeader","disableResponseCache"],"mappings":"AAAA;;;;AAAsB,IAAA,IAAK,WAAL,KAAK,CAAA;AAEfA,IAAAA,GAAG,mCAAM,cAAc,EAApB;AACsC,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAMhE,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;;;;;;;;;;;;;;;;;;;;AAMnB,MAAMC,yBAAyB,SAASC,eAAc,eAAA;IAC3DC,YACYC,WAAmB,EACnBC,OAMT,CACD;QACA,KAAK,CAACD,WAAW,EAAE;YAAC,aAAa;SAAC,CAAC,CAAC;aAT1BA,WAAmB,GAAnBA,WAAmB;aACnBC,OAMT,GANSA,OAMT;KAGF;IAED,MAAMC,kBAAkB,CAACC,GAAkB,EAAEC,GAAmB,EAAiB;QAC/E,MAAM,EAAEC,KAAK,CAAA,EAAE,GAAGC,CAAAA,GAAAA,IAAK,AAAgB,CAAA,MAAhB,CAACH,GAAG,CAACI,GAAG,EAAG,IAAI,CAAC,AAAC;QACxC,MAAMC,WAAW,GAAGH,KAAK,CAAC,QAAQ,CAAC,KAAK,iBAAiB,AAAC;QAC1D,MAAMI,QAAQ,GAAGC,CAAAA,GAAAA,gBAAmB,AAAK,CAAA,oBAAL,CAACP,GAAG,CAAC,AAAC;QAC1CQ,CAAAA,GAAAA,gBAA4B,AAAU,CAAA,6BAAV,CAACF,QAAQ,CAAC,CAAC;QACvCG,CAAAA,GAAAA,gBAAqB,AAAU,CAAA,sBAAV,CAACH,QAAQ,CAAC,CAAC;QAChC,MAAMI,OAAO,GAAGL,WAAW,GAAG,QAAQ,GAAG,MAAM,AAAC;QAEhD,IAAI,CAACP,OAAO,CAACa,UAAU,CAAC;YAAED,OAAO;YAAEJ,QAAQ;SAAE,CAAC,CAAC;QAE/C,MAAMM,QAAQ,GAAG,IAAI,CAACd,OAAO,CAACe,WAAW,CAAC;YAAEH,OAAO;SAAE,CAAC,AAAC;QACvD,IAAI,CAACE,QAAQ,EAAE;YACbnB,GAAG,CAACqB,IAAI,CACN,CAAC,0EAA0E,EAAEJ,OAAO,CAAC,gBAAgB,EAAEJ,QAAQ,CAAC,CAAC,CAAC,CACnH,CAAC;YACFL,GAAG,CAACc,UAAU,GAAG,GAAG,CAAC;YACrBd,GAAG,CAACe,GAAG,EAAE,CAAC;YACV,OAAO;SACR;QACDvB,GAAG,CAACwB,KAAK,CAAC,aAAa,EAAEL,QAAQ,CAAC,CAAC;QACnCX,GAAG,CAACiB,SAAS,CAAC,UAAU,EAAEN,QAAQ,CAAC,CAAC;QAEpC,kBAAkB;QAClBO,CAAAA,GAAAA,eAAoB,AAAK,CAAA,qBAAL,CAAClB,GAAG,CAAC,CAAC;QAE1B,uBAAuB;QACvBA,GAAG,CAACc,UAAU,GAAG,GAAG,CAAC;QACrBd,GAAG,CAACe,GAAG,EAAE,CAAC;KACX;CACF;QA3CYtB,yBAAyB,GAAzBA,yBAAyB"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/RuntimeRedirectMiddleware.ts"],"sourcesContent":["import { parse } from 'url';\n\nimport * as Log from '../../../log';\nimport { disableResponseCache, ExpoMiddleware } from './ExpoMiddleware';\nimport {\n assertMissingRuntimePlatform,\n assertRuntimePlatform,\n parsePlatformHeader,\n RuntimePlatform,\n} from './resolvePlatform';\nimport { ServerRequest, ServerResponse } from './server.types';\n\nconst debug = require('debug')(\n 'expo:start:server:middleware:runtimeRedirect'\n) as typeof console.log;\n\n/** Runtime to target: expo = Expo Go, custom = Dev Client. */\ntype RuntimeTarget = 'expo' | 'custom';\n\nexport class RuntimeRedirectMiddleware extends ExpoMiddleware {\n constructor(\n protected projectRoot: string,\n protected options: {\n onDeepLink: (props: {\n runtime: RuntimeTarget;\n platform: RuntimePlatform;\n }) => void | Promise<void>;\n getLocation: (props: { runtime: RuntimeTarget }) => string | null | undefined;\n }\n ) {\n super(projectRoot, ['/_expo/link']);\n }\n\n async handleRequestAsync(req: ServerRequest, res: ServerResponse): Promise<void> {\n const { query } = parse(req.url!, true);\n const isDevClient = query['choice'] === 'expo-dev-client';\n const platform = parsePlatformHeader(req);\n assertMissingRuntimePlatform(platform);\n assertRuntimePlatform(platform);\n const runtime = isDevClient ? 'custom' : 'expo';\n\n debug(`props:`, { platform, runtime });\n\n this.options.onDeepLink({ runtime, platform });\n\n const redirect = this.options.getLocation({ runtime });\n if (!redirect) {\n Log.warn(\n `[redirect middleware]: Unable to determine redirect location for runtime '${runtime}' and platform '${platform}'`\n );\n res.statusCode = 404;\n res.end();\n return;\n }\n debug('Redirect ->', redirect);\n res.setHeader('Location', redirect);\n\n // Disable caching\n disableResponseCache(res);\n\n // 'Temporary Redirect'\n res.statusCode = 307;\n res.end();\n }\n}\n"],"names":["Log","debug","require","RuntimeRedirectMiddleware","ExpoMiddleware","constructor","projectRoot","options","handleRequestAsync","req","res","query","parse","url","isDevClient","platform","parsePlatformHeader","assertMissingRuntimePlatform","assertRuntimePlatform","runtime","onDeepLink","redirect","getLocation","warn","statusCode","end","setHeader","disableResponseCache"],"mappings":"AAAA;;;;AAAsB,IAAA,IAAK,WAAL,KAAK,CAAA;AAEfA,IAAAA,GAAG,mCAAM,cAAc,EAApB;AACsC,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAMhE,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;;;;;;;;;;;;;;;;;;;;AAG1B,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAC5B,8CAA8C,CAC/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ACc,UAAU,GAAG,GAAG,CAAC;YACrBd,GAAG,CAACe,GAAG,EAAE,CAAC;YACV,OAAO;SACR;QACDxB,KAAK,CAAC,aAAa,EAAEoB,QAAQ,CAAC,CAAC;QAC/BX,GAAG,CAACgB,SAAS,CAAC,UAAU,EAAEL,QAAQ,CAAC,CAAC;QAEpC,kBAAkB;QAClBM,CAAAA,GAAAA,eAAoB,AAAK,CAAA,qBAAL,CAACjB,GAAG,CAAC,CAAC;QAE1B,uBAAuB;QACvBA,GAAG,CAACc,UAAU,GAAG,GAAG,CAAC;QACrBd,GAAG,CAACe,GAAG,EAAE,CAAC;KACX;CACF;QA7CYtB,yBAAyB,GAAzBA,yBAAyB"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _path = _interopRequireDefault(require("path"));
6
+ var _send = _interopRequireDefault(require("send"));
7
+ var _url = require("url");
8
+ var _env = require("../../../utils/env");
9
+ var _resolvePlatform = require("./resolvePlatform");
10
+ function _interopRequireDefault(obj) {
11
+ return obj && obj.__esModule ? obj : {
12
+ default: obj
13
+ };
14
+ }
15
+ const debug = require("debug")("expo:start:server:middleware:serveStatic");
16
+ class ServeStaticMiddleware {
17
+ constructor(projectRoot){
18
+ this.projectRoot = projectRoot;
19
+ }
20
+ getHandler() {
21
+ const publicPath = _path.default.join(this.projectRoot, _env.env.EXPO_PUBLIC_FOLDER);
22
+ debug(`Serving static files from:`, publicPath);
23
+ const opts = {
24
+ root: publicPath
25
+ };
26
+ return (req, res, next)=>{
27
+ if (!(req == null ? void 0 : req.url) || req.method !== "GET" && req.method !== "HEAD") {
28
+ return next();
29
+ }
30
+ const platform = (0, _resolvePlatform).parsePlatformHeader(req);
31
+ // Currently this is web-only
32
+ if (platform && platform !== "web") {
33
+ return next();
34
+ }
35
+ const pathname = (0, _url).parse(req.url).pathname;
36
+ if (!pathname) {
37
+ return next();
38
+ }
39
+ debug(`Maybe serve static:`, pathname);
40
+ const stream = (0, _send).default(req, pathname, opts);
41
+ // add file listener for fallthrough
42
+ let forwardError = false;
43
+ stream.on("file", function onFile() {
44
+ // once file is determined, always forward error
45
+ forwardError = true;
46
+ });
47
+ // forward errors
48
+ stream.on("error", function error(err) {
49
+ if (forwardError || !(err.statusCode < 500)) {
50
+ next(err);
51
+ return;
52
+ }
53
+ next();
54
+ });
55
+ // pipe
56
+ stream.pipe(res);
57
+ };
58
+ }
59
+ }
60
+ exports.ServeStaticMiddleware = ServeStaticMiddleware;
61
+
62
+ //# sourceMappingURL=ServeStaticMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/ServeStaticMiddleware.ts"],"sourcesContent":["import path from 'path';\nimport send from 'send';\nimport { parse } from 'url';\n\nimport { env } from '../../../utils/env';\nimport { parsePlatformHeader } from './resolvePlatform';\nimport { ServerRequest, ServerResponse } from './server.types';\n\nconst debug = require('debug')('expo:start:server:middleware:serveStatic') as typeof console.log;\n\n/**\n * Adds support for serving the files in the static `public/` folder to web apps.\n */\nexport class ServeStaticMiddleware {\n constructor(private projectRoot: string) {}\n getHandler() {\n const publicPath = path.join(this.projectRoot, env.EXPO_PUBLIC_FOLDER);\n\n debug(`Serving static files from:`, publicPath);\n const opts = {\n root: publicPath,\n };\n return (req: ServerRequest, res: ServerResponse, next: any) => {\n if (!req?.url || (req.method !== 'GET' && req.method !== 'HEAD')) {\n return next();\n }\n\n const platform = parsePlatformHeader(req);\n // Currently this is web-only\n if (platform && platform !== 'web') {\n return next();\n }\n\n const pathname = parse(req.url).pathname;\n if (!pathname) {\n return next();\n }\n\n debug(`Maybe serve static:`, pathname);\n const stream = send(req, pathname, opts);\n\n // add file listener for fallthrough\n let forwardError = false;\n stream.on('file', function onFile() {\n // once file is determined, always forward error\n forwardError = true;\n });\n\n // forward errors\n stream.on('error', function error(err: any) {\n if (forwardError || !(err.statusCode < 500)) {\n next(err);\n return;\n }\n\n next();\n });\n\n // pipe\n stream.pipe(res);\n };\n }\n}\n"],"names":["debug","require","ServeStaticMiddleware","constructor","projectRoot","getHandler","publicPath","path","join","env","EXPO_PUBLIC_FOLDER","opts","root","req","res","next","url","method","platform","parsePlatformHeader","pathname","parse","stream","send","forwardError","on","onFile","error","err","statusCode","pipe"],"mappings":"AAAA;;;;AAAiB,IAAA,KAAM,kCAAN,MAAM,EAAA;AACN,IAAA,KAAM,kCAAN,MAAM,EAAA;AACD,IAAA,IAAK,WAAL,KAAK,CAAA;AAEP,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACJ,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;;;;AAGvD,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,0CAA0C,CAAC,AAAsB,AAAC;AAK1F,MAAMC,qBAAqB;IAChCC,YAAoBC,WAAmB,CAAE;aAArBA,WAAmB,GAAnBA,WAAmB;KAAI;IAC3CC,UAAU,GAAG;QACX,MAAMC,UAAU,GAAGC,KAAI,QAAA,CAACC,IAAI,CAAC,IAAI,CAACJ,WAAW,EAAEK,IAAG,IAAA,CAACC,kBAAkB,CAAC,AAAC;QAEvEV,KAAK,CAAC,CAAC,0BAA0B,CAAC,EAAEM,UAAU,CAAC,CAAC;QAChD,MAAMK,IAAI,GAAG;YACXC,IAAI,EAAEN,UAAU;SACjB,AAAC;QACF,OAAO,CAACO,GAAkB,EAAEC,GAAmB,EAAEC,IAAS,GAAK;YAC7D,IAAI,CAACF,CAAAA,GAAG,QAAK,GAARA,KAAAA,CAAQ,GAARA,GAAG,CAAEG,GAAG,CAAA,IAAKH,GAAG,CAACI,MAAM,KAAK,KAAK,IAAIJ,GAAG,CAACI,MAAM,KAAK,MAAM,AAAC,EAAE;gBAChE,OAAOF,IAAI,EAAE,CAAC;aACf;YAED,MAAMG,QAAQ,GAAGC,CAAAA,GAAAA,gBAAmB,AAAK,CAAA,oBAAL,CAACN,GAAG,CAAC,AAAC;YAC1C,6BAA6B;YAC7B,IAAIK,QAAQ,IAAIA,QAAQ,KAAK,KAAK,EAAE;gBAClC,OAAOH,IAAI,EAAE,CAAC;aACf;YAED,MAAMK,QAAQ,GAAGC,CAAAA,GAAAA,IAAK,AAAS,CAAA,MAAT,CAACR,GAAG,CAACG,GAAG,CAAC,CAACI,QAAQ,AAAC;YACzC,IAAI,CAACA,QAAQ,EAAE;gBACb,OAAOL,IAAI,EAAE,CAAC;aACf;YAEDf,KAAK,CAAC,CAAC,mBAAmB,CAAC,EAAEoB,QAAQ,CAAC,CAAC;YACvC,MAAME,MAAM,GAAGC,CAAAA,GAAAA,KAAI,AAAqB,CAAA,QAArB,CAACV,GAAG,EAAEO,QAAQ,EAAET,IAAI,CAAC,AAAC;YAEzC,oCAAoC;YACpC,IAAIa,YAAY,GAAG,KAAK,AAAC;YACzBF,MAAM,CAACG,EAAE,CAAC,MAAM,EAAE,SAASC,MAAM,GAAG;gBAClC,gDAAgD;gBAChDF,YAAY,GAAG,IAAI,CAAC;aACrB,CAAC,CAAC;YAEH,iBAAiB;YACjBF,MAAM,CAACG,EAAE,CAAC,OAAO,EAAE,SAASE,KAAK,CAACC,GAAQ,EAAE;gBAC1C,IAAIJ,YAAY,IAAI,CAAC,CAACI,GAAG,CAACC,UAAU,GAAG,GAAG,CAAC,EAAE;oBAC3Cd,IAAI,CAACa,GAAG,CAAC,CAAC;oBACV,OAAO;iBACR;gBAEDb,IAAI,EAAE,CAAC;aACR,CAAC,CAAC;YAEH,OAAO;YACPO,MAAM,CAACQ,IAAI,CAAChB,GAAG,CAAC,CAAC;SAClB,CAAC;KACH;CACF;QAjDYZ,qBAAqB,GAArBA,qBAAqB"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.getPlatformBundlers = getPlatformBundlers;
6
+ function getPlatformBundlers(exp) {
7
+ var ref, ref1, ref2;
8
+ var ref3, ref4, ref5;
9
+ return {
10
+ // @ts-expect-error: not on type yet
11
+ ios: (ref3 = (ref = exp.ios) == null ? void 0 : ref.bundler) != null ? ref3 : "metro",
12
+ // @ts-expect-error: not on type yet
13
+ android: (ref4 = (ref1 = exp.android) == null ? void 0 : ref1.bundler) != null ? ref4 : "metro",
14
+ web: (ref5 = (ref2 = exp.web) == null ? void 0 : ref2.bundler) != null ? ref5 : "webpack"
15
+ };
16
+ }
17
+
18
+ //# sourceMappingURL=platformBundlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/start/server/platformBundlers.ts"],"sourcesContent":["import { ExpoConfig, Platform } from '@expo/config';\n\n/** Which bundler each platform should use. */\nexport type PlatformBundlers = Record<Platform, 'metro' | 'webpack'>;\n\n/** Get the platform bundlers mapping. */\nexport function getPlatformBundlers(exp: Partial<ExpoConfig>): PlatformBundlers {\n return {\n // @ts-expect-error: not on type yet\n ios: exp.ios?.bundler ?? 'metro',\n // @ts-expect-error: not on type yet\n android: exp.android?.bundler ?? 'metro',\n web: exp.web?.bundler ?? 'webpack',\n };\n}\n"],"names":["getPlatformBundlers","exp","ios","bundler","android","web"],"mappings":"AAAA;;;;QAMgBA,mBAAmB,GAAnBA,mBAAmB;AAA5B,SAASA,mBAAmB,CAACC,GAAwB,EAAoB;QAGvEA,GAAO,EAEHA,IAAW,EACfA,IAAO;QAHPA,IAAgB,EAEZA,IAAoB,EACxBA,IAAgB;IALvB,OAAO;QACL,oCAAoC;QACpCC,GAAG,EAAED,CAAAA,IAAgB,GAAhBA,CAAAA,GAAO,GAAPA,GAAG,CAACC,GAAG,SAAS,GAAhBD,KAAAA,CAAgB,GAAhBA,GAAO,CAAEE,OAAO,YAAhBF,IAAgB,GAAI,OAAO;QAChC,oCAAoC;QACpCG,OAAO,EAAEH,CAAAA,IAAoB,GAApBA,CAAAA,IAAW,GAAXA,GAAG,CAACG,OAAO,SAAS,GAApBH,KAAAA,CAAoB,GAApBA,IAAW,CAAEE,OAAO,YAApBF,IAAoB,GAAI,OAAO;QACxCI,GAAG,EAAEJ,CAAAA,IAAgB,GAAhBA,CAAAA,IAAO,GAAPA,GAAG,CAACI,GAAG,SAAS,GAAhBJ,KAAAA,CAAgB,GAAhBA,IAAO,CAAEE,OAAO,YAAhBF,IAAgB,GAAI,SAAS;KACnC,CAAC;CACH"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.createTemplateHtmlFromExpoConfigAsync = createTemplateHtmlFromExpoConfigAsync;
6
+ exports.createTemplateHtmlAsync = createTemplateHtmlAsync;
7
+ var _config = require("@expo/config");
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _templates = require("../../customize/templates");
11
+ var _env = require("../../utils/env");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ async function createTemplateHtmlFromExpoConfigAsync(projectRoot, { scripts , exp =(0, _config).getConfig(projectRoot, {
18
+ skipSDKVersionRequirement: true
19
+ }).exp }) {
20
+ var ref, ref1, ref2;
21
+ var ref3, _webName;
22
+ return createTemplateHtmlAsync(projectRoot, {
23
+ langIsoCode: (ref3 = (ref = exp.web) == null ? void 0 : ref.lang) != null ? ref3 : "en",
24
+ scripts,
25
+ title: (_webName = (0, _config).getNameFromConfig(exp).webName) != null ? _webName : "Expo App",
26
+ description: (ref1 = exp.web) == null ? void 0 : ref1.description,
27
+ themeColor: (ref2 = exp.web) == null ? void 0 : ref2.themeColor
28
+ });
29
+ }
30
+ function getFileFromLocalPublicFolder(projectRoot, { publicFolder , filePath }) {
31
+ const localFilePath = _path.default.resolve(projectRoot, publicFolder, filePath);
32
+ if (!_fs.default.existsSync(localFilePath)) {
33
+ return null;
34
+ }
35
+ return localFilePath;
36
+ }
37
+ /** Attempt to read the `index.html` from the local project before falling back on the template `index.html`. */ async function getTemplateIndexHtmlAsync(projectRoot) {
38
+ let filePath = getFileFromLocalPublicFolder(projectRoot, {
39
+ // TODO: Maybe use the app.json override.
40
+ publicFolder: _env.env.EXPO_PUBLIC_FOLDER,
41
+ filePath: "index.html"
42
+ });
43
+ if (!filePath) {
44
+ filePath = _templates.TEMPLATES.find((value)=>value.id === "index.html"
45
+ ).file(projectRoot);
46
+ }
47
+ return _fs.default.promises.readFile(filePath, "utf8");
48
+ }
49
+ async function createTemplateHtmlAsync(projectRoot, { scripts , description , langIsoCode , title , themeColor }) {
50
+ // Resolve the best possible index.html template file.
51
+ let contents = await getTemplateIndexHtmlAsync(projectRoot);
52
+ contents = contents.replace("%LANG_ISO_CODE%", langIsoCode);
53
+ contents = contents.replace("%WEB_TITLE%", title);
54
+ contents = contents.replace("</body>", scripts.map((url)=>`<script src="${url}"></script>`
55
+ ).join("") + "</body>");
56
+ if (themeColor) {
57
+ contents = addMeta(contents, `name="theme-color" content="${themeColor}"`);
58
+ }
59
+ if (description) {
60
+ contents = addMeta(contents, `name="description" content="${description}"`);
61
+ }
62
+ return contents;
63
+ }
64
+ /** Add a `<meta />` tag to the `<head />` element. */ function addMeta(contents, meta) {
65
+ return contents.replace("</head>", `<meta ${meta}>\n</head>`);
66
+ }
67
+
68
+ //# sourceMappingURL=webTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/start/server/webTemplate.ts"],"sourcesContent":["import { ExpoConfig, getConfig, getNameFromConfig } from '@expo/config';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { TEMPLATES } from '../../customize/templates';\nimport { env } from '../../utils/env';\n\n/**\n * Create a static HTML for SPA styled websites.\n * This method attempts to reuse the same patterns as `@expo/webpack-config`.\n */\nexport async function createTemplateHtmlFromExpoConfigAsync(\n projectRoot: string,\n {\n scripts,\n exp = getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp,\n }: {\n scripts: string[];\n exp?: ExpoConfig;\n }\n) {\n return createTemplateHtmlAsync(projectRoot, {\n langIsoCode: exp.web?.lang ?? 'en',\n scripts,\n title: getNameFromConfig(exp).webName ?? 'Expo App',\n description: exp.web?.description,\n themeColor: exp.web?.themeColor,\n });\n}\n\nfunction getFileFromLocalPublicFolder(\n projectRoot: string,\n { publicFolder, filePath }: { publicFolder: string; filePath: string }\n): string | null {\n const localFilePath = path.resolve(projectRoot, publicFolder, filePath);\n if (!fs.existsSync(localFilePath)) {\n return null;\n }\n return localFilePath;\n}\n\n/** Attempt to read the `index.html` from the local project before falling back on the template `index.html`. */\nasync function getTemplateIndexHtmlAsync(projectRoot: string): Promise<string> {\n let filePath = getFileFromLocalPublicFolder(projectRoot, {\n // TODO: Maybe use the app.json override.\n publicFolder: env.EXPO_PUBLIC_FOLDER,\n filePath: 'index.html',\n });\n if (!filePath) {\n filePath = TEMPLATES.find((value) => value.id === 'index.html')!.file(projectRoot);\n }\n return fs.promises.readFile(filePath, 'utf8');\n}\n\n/** Return an `index.html` string with template values added. */\nexport async function createTemplateHtmlAsync(\n projectRoot: string,\n {\n scripts,\n description,\n langIsoCode,\n title,\n themeColor,\n }: {\n scripts: string[];\n description?: string;\n langIsoCode: string;\n title: string;\n themeColor?: string;\n }\n): Promise<string> {\n // Resolve the best possible index.html template file.\n let contents = await getTemplateIndexHtmlAsync(projectRoot);\n\n contents = contents.replace('%LANG_ISO_CODE%', langIsoCode);\n contents = contents.replace('%WEB_TITLE%', title);\n contents = contents.replace(\n '</body>',\n scripts.map((url) => `<script src=\"${url}\"></script>`).join('') + '</body>'\n );\n\n if (themeColor) {\n contents = addMeta(contents, `name=\"theme-color\" content=\"${themeColor}\"`);\n }\n\n if (description) {\n contents = addMeta(contents, `name=\"description\" content=\"${description}\"`);\n }\n\n return contents;\n}\n\n/** Add a `<meta />` tag to the `<head />` element. */\nfunction addMeta(contents: string, meta: string): string {\n return contents.replace('</head>', `<meta ${meta}>\\n</head>`);\n}\n"],"names":["createTemplateHtmlFromExpoConfigAsync","createTemplateHtmlAsync","projectRoot","scripts","exp","getConfig","skipSDKVersionRequirement","getNameFromConfig","langIsoCode","web","lang","title","webName","description","themeColor","getFileFromLocalPublicFolder","publicFolder","filePath","localFilePath","path","resolve","fs","existsSync","getTemplateIndexHtmlAsync","env","EXPO_PUBLIC_FOLDER","TEMPLATES","find","value","id","file","promises","readFile","contents","replace","map","url","join","addMeta","meta"],"mappings":"AAAA;;;;QAWsBA,qCAAqC,GAArCA,qCAAqC;QA4CrCC,uBAAuB,GAAvBA,uBAAuB;AAvDY,IAAA,OAAc,WAAd,cAAc,CAAA;AACxD,IAAA,GAAI,kCAAJ,IAAI,EAAA;AACF,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEG,IAAA,UAA2B,WAA3B,2BAA2B,CAAA;AACjC,IAAA,IAAiB,WAAjB,iBAAiB,CAAA;;;;;;AAM9B,eAAeD,qCAAqC,CACzDE,WAAmB,EACnB,EACEC,OAAO,CAAA,EACPC,GAAG,EAAGC,CAAAA,GAAAA,OAAS,AAAkD,CAAA,UAAlD,CAACH,WAAW,EAAE;IAAEI,yBAAyB,EAAE,IAAI;CAAE,CAAC,CAACF,GAAG,CAAA,EAItE,EACD;QAEeA,GAAO,EAGPA,IAAO,EACRA,IAAO;QAJNA,IAAa,EAEnBG,QAA8B;IAHvC,OAAON,uBAAuB,CAACC,WAAW,EAAE;QAC1CM,WAAW,EAAEJ,CAAAA,IAAa,GAAbA,CAAAA,GAAO,GAAPA,GAAG,CAACK,GAAG,SAAM,GAAbL,KAAAA,CAAa,GAAbA,GAAO,CAAEM,IAAI,YAAbN,IAAa,GAAI,IAAI;QAClCD,OAAO;QACPQ,KAAK,EAAEJ,CAAAA,QAA8B,GAA9BA,CAAAA,GAAAA,OAAiB,AAAK,CAAA,kBAAL,CAACH,GAAG,CAAC,CAACQ,OAAO,YAA9BL,QAA8B,GAAI,UAAU;QACnDM,WAAW,EAAET,CAAAA,IAAO,GAAPA,GAAG,CAACK,GAAG,SAAa,GAApBL,KAAAA,CAAoB,GAApBA,IAAO,CAAES,WAAW;QACjCC,UAAU,EAAEV,CAAAA,IAAO,GAAPA,GAAG,CA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yB,QAAQ,GAAGA,QAAQ,CAACC,OAAO,CAAC,aAAa,EAAEvB,KAAK,CAAC,CAAC;IAClDsB,QAAQ,GAAGA,QAAQ,CAACC,OAAO,CACzB,SAAS,EACT/B,OAAO,CAACgC,GAAG,CAAC,CAACC,GAAG,GAAK,CAAC,aAAa,EAAEA,GAAG,CAAC,WAAW,CAAC;IAAA,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAC5E,CAAC;IAEF,IAAIvB,UAAU,EAAE;QACdmB,QAAQ,GAAGK,OAAO,CAACL,QAAQ,EAAE,CAAC,4BAA4B,EAAEnB,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5E;IAED,IAAID,WAAW,EAAE;QACfoB,QAAQ,GAAGK,OAAO,CAACL,QAAQ,EAAE,CAAC,4BAA4B,EAAEpB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7E;IAED,OAAOoB,QAAQ,CAAC;CACjB;AAED,sDAAsD,CACtD,SAASK,OAAO,CAACL,QAAgB,EAAEM,IAAY,EAAU;IACvD,OAAON,QAAQ,CAACC,OAAO,CAAC,SAAS,EAAE,CAAC,MAAM,EAAEK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;CAC/D"}
@@ -13,8 +13,10 @@ var _env = require("../../../utils/env");
13
13
  var _errors = require("../../../utils/errors");
14
14
  var _ip = require("../../../utils/ip");
15
15
  var _port = require("../../../utils/port");
16
+ var _progress = require("../../../utils/progress");
16
17
  var _dotExpo = require("../../project/dotExpo");
17
18
  var _bundlerDevServer = require("../BundlerDevServer");
19
+ var _compile = require("./compile");
18
20
  var _resolveFromProject = require("./resolveFromProject");
19
21
  var _tls = require("./tls");
20
22
  function _interopRequireDefault(obj) {
@@ -43,6 +45,7 @@ function _interopRequireWildcard(obj) {
43
45
  return newObj;
44
46
  }
45
47
  }
48
+ const debug = require("debug")("expo:start:server:webpack:devServer");
46
49
  function assertIsWebpackDevServer(value) {
47
50
  if (!(value == null ? void 0 : value.sockWrite)) {
48
51
  var ref;
@@ -99,9 +102,6 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
99
102
  "android"
100
103
  ].includes(process.env.EXPO_WEBPACK_PLATFORM || "");
101
104
  }
102
- isTargetingWeb() {
103
- return true;
104
- }
105
105
  async createNativeDevServerMiddleware({ port , compiler , options }) {
106
106
  if (!this.isTargetingNative()) {
107
107
  return null;
@@ -141,6 +141,46 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
141
141
  throw new _errors.CommandError("NO_PORT_FOUND", error.message);
142
142
  }
143
143
  }
144
+ async bundleAsync({ mode , clear }) {
145
+ // Do this first to fail faster.
146
+ const webpack = (0, _resolveFromProject).importWebpackFromProject(this.projectRoot);
147
+ if (clear) {
148
+ await this.clearWebProjectCacheAsync(this.projectRoot, mode);
149
+ }
150
+ const config = await this.loadConfigAsync({
151
+ isImageEditingEnabled: true,
152
+ mode
153
+ });
154
+ if (!config.plugins) {
155
+ config.plugins = [];
156
+ }
157
+ const bar = (0, _progress).createProgressBar(_chalk.default`{bold Web} Bundling Javascript [:bar] :percent`, {
158
+ width: 64,
159
+ total: 100,
160
+ clear: true,
161
+ complete: "=",
162
+ incomplete: " "
163
+ });
164
+ // NOTE(EvanBacon): Add a progress bar to the webpack logger if defined (e.g. not in CI).
165
+ if (bar != null) {
166
+ config.plugins.push(new webpack.ProgressPlugin((percent)=>{
167
+ bar == null ? void 0 : bar.update(percent);
168
+ if (percent === 1) {
169
+ bar == null ? void 0 : bar.terminate();
170
+ }
171
+ }));
172
+ }
173
+ // Create a webpack compiler that is configured with custom messages.
174
+ const compiler = webpack(config);
175
+ try {
176
+ await (0, _compile).compileAsync(compiler);
177
+ } catch (error) {
178
+ Log.error(_chalk.default.red("Failed to compile"));
179
+ throw error;
180
+ } finally{
181
+ bar == null ? void 0 : bar.terminate();
182
+ }
183
+ }
144
184
  async startImplementationAsync(options) {
145
185
  var ref;
146
186
  // Do this first to fail faster.
@@ -157,12 +197,12 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
157
197
  scheme: https ? "https" : "http"
158
198
  }
159
199
  });
160
- Log.debug("Starting webpack on port: " + port);
200
+ debug("Starting webpack on port: " + port);
161
201
  if (resetDevServer) {
162
- await clearWebProjectCacheAsync(this.projectRoot, mode);
202
+ await this.clearWebProjectCacheAsync(this.projectRoot, mode);
163
203
  }
164
204
  if (https) {
165
- Log.debug("Configuring TLS to enable HTTPS support");
205
+ debug("Configuring TLS to enable HTTPS support");
166
206
  await (0, _tls).ensureEnvironmentSupportsTLSAsync(this.projectRoot).catch((error)=>{
167
207
  Log.error(`Error creating TLS certificates: ${error}`);
168
208
  });
@@ -273,6 +313,19 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
273
313
  "./webpack.config.js"
274
314
  ];
275
315
  }
316
+ async clearWebProjectCacheAsync(projectRoot, mode = "development") {
317
+ Log.log(_chalk.default.dim(`Clearing Webpack ${mode} cache directory...`));
318
+ const dir = await (0, _dotExpo).ensureDotExpoProjectDirectoryInitialized(projectRoot);
319
+ const cacheFolder = path.join(dir, "web/cache", mode);
320
+ try {
321
+ await _fs.default.promises.rm(cacheFolder, {
322
+ recursive: true,
323
+ force: true
324
+ });
325
+ } catch (error) {
326
+ Log.error(`Could not clear ${mode} web cache directory: ${error.message}`);
327
+ }
328
+ }
276
329
  }
277
330
  exports.WebpackBundlerDevServer = WebpackBundlerDevServer;
278
331
  function setMode(mode) {
@@ -282,18 +335,5 @@ function setMode(mode) {
282
335
  function getProjectWebpackConfigFilePath(projectRoot) {
283
336
  return _resolveFrom.default.silent(projectRoot, "./webpack.config.js");
284
337
  }
285
- async function clearWebProjectCacheAsync(projectRoot, mode = "development") {
286
- Log.log(_chalk.default.dim(`Clearing Webpack ${mode} cache directory...`));
287
- const dir = await (0, _dotExpo).ensureDotExpoProjectDirectoryInitialized(projectRoot);
288
- const cacheFolder = path.join(dir, "web/cache", mode);
289
- try {
290
- await _fs.default.promises.rm(cacheFolder, {
291
- recursive: true,
292
- force: true
293
- });
294
- } catch (error) {
295
- Log.error(`Could not clear ${mode} web cache directory: ${error.message}`);
296
- }
297
- }
298
338
 
299
339
  //# sourceMappingURL=WebpackBundlerDevServer.js.map