@expo/cli 0.13.0 → 0.13.1

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 (39) hide show
  1. package/build/bin/cli +2 -2
  2. package/build/src/export/createMetadataJson.js +1 -0
  3. package/build/src/export/createMetadataJson.js.map +1 -1
  4. package/build/src/export/exportApp.js +15 -6
  5. package/build/src/export/exportApp.js.map +1 -1
  6. package/build/src/export/exportStaticAsync.js +54 -3
  7. package/build/src/export/exportStaticAsync.js.map +1 -1
  8. package/build/src/export/writeContents.js +2 -2
  9. package/build/src/export/writeContents.js.map +1 -1
  10. package/build/src/start/server/getStaticRenderFunctions.js +6 -2
  11. package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
  12. package/build/src/start/server/metro/MetroBundlerDevServer.js +66 -46
  13. package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
  14. package/build/src/start/server/metro/bundleApiRoutes.js +67 -0
  15. package/build/src/start/server/metro/bundleApiRoutes.js.map +1 -0
  16. package/build/src/start/server/metro/createServerRouteMiddleware.js +112 -0
  17. package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -0
  18. package/build/src/start/server/metro/fetchRouterManifest.js +60 -0
  19. package/build/src/start/server/metro/fetchRouterManifest.js.map +1 -0
  20. package/build/src/start/server/metro/instantiateMetro.js +12 -12
  21. package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
  22. package/build/src/start/server/metro/metroErrorInterface.js +70 -10
  23. package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
  24. package/build/src/start/server/metro/router.js +32 -0
  25. package/build/src/start/server/metro/router.js.map +1 -1
  26. package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js +22 -0
  27. package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js.map +1 -1
  28. package/build/src/start/server/metro/withMetroMultiPlatform.js +4 -1
  29. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
  30. package/build/src/start/server/middleware/ManifestMiddleware.js +5 -1
  31. package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
  32. package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js +2 -0
  33. package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js.map +1 -1
  34. package/build/src/start/server/type-generation/routes.js +3 -4
  35. package/build/src/start/server/type-generation/routes.js.map +1 -1
  36. package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js +1 -3
  37. package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js.map +1 -1
  38. package/build/src/utils/analytics/rudderstackClient.js +2 -2
  39. package/package.json +7 -4
@@ -8,9 +8,12 @@ var runtimeEnv = _interopRequireWildcard(require("@expo/env"));
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
9
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
+ var _bundleApiRoutes = require("./bundleApiRoutes");
12
+ var _createServerRouteMiddleware = require("./createServerRouteMiddleware");
13
+ var _fetchRouterManifest = require("./fetchRouterManifest");
11
14
  var _instantiateMetro = require("./instantiateMetro");
12
- var _metroErrorInterface = require("./metroErrorInterface");
13
15
  var _metroWatchTypeScriptFiles = require("./metroWatchTypeScriptFiles");
16
+ var _router = require("./router");
14
17
  var _waitForMetroToObserveTypeScriptFile = require("./waitForMetroToObserveTypeScriptFile");
15
18
  var _log = require("../../../log");
16
19
  var _getDevClientProperties = _interopRequireDefault(require("../../../utils/analytics/getDevClientProperties"));
@@ -63,6 +66,7 @@ class ForwardHtmlError extends _errors.CommandError {
63
66
  this.statusCode = statusCode;
64
67
  }
65
68
  }
69
+ exports.ForwardHtmlError = ForwardHtmlError;
66
70
  const debug = require("debug")("expo:start:server:metro");
67
71
  /** Default port to use for apps running in Expo Go. */ const EXPO_GO_METRO_PORT = 8081;
68
72
  /** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */ const DEV_CLIENT_METRO_PORT = 8081;
@@ -78,6 +82,25 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
78
82
  (options.devClient ? Number(process.env.RCT_METRO_PORT) || DEV_CLIENT_METRO_PORT : await (0, _port).getFreePortAsync(EXPO_GO_METRO_PORT));
79
83
  return port;
80
84
  }
85
+ async getExpoRouterRoutesManifestAsync({ appDir }) {
86
+ const manifest = await (0, _fetchRouterManifest).fetchManifest(this.projectRoot, {
87
+ asJson: true,
88
+ appDir
89
+ });
90
+ if (!manifest) {
91
+ throw new _errors.CommandError("EXPO_ROUTER_SERVER_MANIFEST", "Unexpected error: server manifest could not be fetched.");
92
+ }
93
+ return manifest;
94
+ }
95
+ async exportExpoRouterApiRoutesAsync({ mode , appDir }) {
96
+ var ref;
97
+ return (0, _bundleApiRoutes).exportAllApiRoutesAsync(this.projectRoot, {
98
+ mode,
99
+ appDir,
100
+ port: (ref = this.getInstance()) == null ? void 0 : ref.location.port,
101
+ shouldThrow: true
102
+ });
103
+ }
81
104
  async composeResourcesWithHtml({ mode , resources , template , devBundleUrl , basePath }) {
82
105
  if (!resources) {
83
106
  return "";
@@ -101,7 +124,8 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
101
124
  return {
102
125
  // Get routes from Expo Router.
103
126
  manifest: await getManifest({
104
- fetchData: true
127
+ fetchData: true,
128
+ preserveApiRoutes: false
105
129
  }),
106
130
  // Get route generating function
107
131
  async renderAsync (path) {
@@ -164,12 +188,6 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
164
188
  }
165
189
  throw new Error("Invalid resources returned from the Metro serializer. Expected array, found: " + data);
166
190
  }
167
- async renderStaticErrorAsync(error) {
168
- return (0, _metroErrorInterface).getErrorOverlayHtmlAsync({
169
- error,
170
- projectRoot: this.projectRoot
171
- });
172
- }
173
191
  async getStaticPageAsync(pathname, { mode , minify =mode !== "development" , basePath }) {
174
192
  const devBundleUrlPathname = (0, _manifestMiddleware).createBundleUrlPath({
175
193
  platform: "web",
@@ -269,8 +287,8 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
269
287
  var ref;
270
288
  return (ref = this.urlCreator) == null ? void 0 : ref.constructDevClientUrl();
271
289
  } else {
272
- var ref1;
273
- return (ref1 = this.urlCreator) == null ? void 0 : ref1.constructUrl({
290
+ var ref3;
291
+ return (ref3 = this.urlCreator) == null ? void 0 : ref3.constructUrl({
274
292
  scheme: "exp"
275
293
  });
276
294
  }
@@ -280,55 +298,57 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
280
298
  middleware.use(new _createFileMiddleware.CreateFileMiddleware(this.projectRoot).getHandler());
281
299
  // Append support for redirecting unhandled requests to the index.html page on web.
282
300
  if (this.isTargetingWeb()) {
283
- var ref2;
301
+ var ref4, ref1;
284
302
  const { exp } = (0, _config).getConfig(this.projectRoot, {
285
303
  skipSDKVersionRequirement: true
286
304
  });
287
- const useWebSSG = ((ref2 = exp.web) == null ? void 0 : ref2.output) === "static";
305
+ var ref2;
306
+ const useServerRendering = [
307
+ "static",
308
+ "server"
309
+ ].includes((ref2 = (ref4 = exp.web) == null ? void 0 : ref4.output) != null ? ref2 : "");
288
310
  // This MUST be after the manifest middleware so it doesn't have a chance to serve the template `public/index.html`.
289
311
  middleware.use(new _serveStaticMiddleware.ServeStaticMiddleware(this.projectRoot).getHandler());
290
312
  // This should come after the static middleware so it doesn't serve the favicon from `public/favicon.ico`.
291
313
  middleware.use(new _faviconMiddleware.FaviconMiddleware(this.projectRoot).getHandler());
292
- if (useWebSSG) {
293
- middleware.use(async (req, res, next)=>{
294
- if (!(req == null ? void 0 : req.url)) {
295
- return next();
296
- }
297
- // TODO: Formal manifest for allowed paths
298
- if (req.url.endsWith(".ico")) {
299
- return next();
300
- }
301
- if (req.url.includes("serializer.output=static")) {
302
- return next();
303
- }
304
- try {
305
- var _mode;
306
- const { content } = await this.getStaticPageAsync(req.url, {
307
- mode: (_mode = options.mode) != null ? _mode : "development",
308
- // Asset prefix is not supported in development.
309
- basePath: ""
310
- });
311
- res.setHeader("Content-Type", "text/html");
312
- res.end(content);
313
- } catch (error) {
314
- res.setHeader("Content-Type", "text/html");
315
- // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.
316
- if (error instanceof ForwardHtmlError) {
317
- res.statusCode = error.statusCode;
318
- res.end(error.html);
319
- return;
314
+ const appDir = (0, _router).getRouterDirectoryWithManifest(this.projectRoot, exp);
315
+ middleware.use((0, _createServerRouteMiddleware).createRouteHandlerMiddleware(this.projectRoot, {
316
+ ...options,
317
+ appDir,
318
+ getWebBundleUrl: manifestMiddleware.getWebBundleUrl.bind(manifestMiddleware),
319
+ getStaticPageAsync: (pathname)=>{
320
+ var _mode;
321
+ return this.getStaticPageAsync(pathname, {
322
+ mode: (_mode = options.mode) != null ? _mode : "development",
323
+ minify: options.minify,
324
+ // No base path in development
325
+ basePath: ""
326
+ });
327
+ }
328
+ }));
329
+ // @ts-expect-error: TODO
330
+ if (((ref1 = exp.web) == null ? void 0 : ref1.output) === "server") {
331
+ // Cache observation for API Routes...
332
+ (0, _waitForMetroToObserveTypeScriptFile).observeApiRouteChanges(this.projectRoot, {
333
+ metro,
334
+ server
335
+ }, async (filepath, op)=>{
336
+ if ((0, _router).isApiRouteConvention(filepath)) {
337
+ debug(`[expo-cli] ${op} ${filepath}`);
338
+ if (op === "change" || op === "add") {
339
+ (0, _bundleApiRoutes).rebundleApiRoute(this.projectRoot, filepath, {
340
+ ...options,
341
+ appDir
342
+ });
320
343
  }
321
- try {
322
- res.end(await this.renderStaticErrorAsync(error));
323
- } catch (staticError) {
324
- // Fallback error for when Expo Router is misconfigured in the project.
325
- res.end("<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>" + error.message + "<br/><br/>" + staticError.message + "</span>");
344
+ if (op === "delete") {
345
+ // TODO: Cancel the bundling of the deleted route.
326
346
  }
327
347
  }
328
348
  });
329
349
  }
330
350
  // This MUST run last since it's the fallback.
331
- if (!useWebSSG) {
351
+ if (!useServerRendering) {
332
352
  middleware.use(new _historyFallbackMiddleware.HistoryFallbackMiddleware(manifestMiddleware.getHandler().internal).getHandler());
333
353
  }
334
354
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/MetroBundlerDevServer.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 { getConfig } from '@expo/config';\nimport * as runtimeEnv from '@expo/env';\nimport { SerialAsset } from '@expo/metro-config/build/serializer/serializerAssets';\nimport chalk from 'chalk';\nimport fetch from 'node-fetch';\nimport path from 'path';\n\nimport { instantiateMetroAsync } from './instantiateMetro';\nimport { getErrorOverlayHtmlAsync } from './metroErrorInterface';\nimport { metroWatchTypeScriptFiles } from './metroWatchTypeScriptFiles';\nimport { observeFileChanges } from './waitForMetroToObserveTypeScriptFile';\nimport { Log } from '../../../log';\nimport getDevClientProperties from '../../../utils/analytics/getDevClientProperties';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport { CommandError } from '../../../utils/errors';\nimport { getFreePortAsync } from '../../../utils/port';\nimport { BundlerDevServer, BundlerStartOptions, DevServerInstance } from '../BundlerDevServer';\nimport { getStaticRenderFunctions } from '../getStaticRenderFunctions';\nimport { ContextModuleSourceMapsMiddleware } from '../middleware/ContextModuleSourceMapsMiddleware';\nimport { CreateFileMiddleware } from '../middleware/CreateFileMiddleware';\nimport { FaviconMiddleware } from '../middleware/FaviconMiddleware';\nimport { HistoryFallbackMiddleware } from '../middleware/HistoryFallbackMiddleware';\nimport { InterstitialPageMiddleware } from '../middleware/InterstitialPageMiddleware';\nimport {\n createBundleUrlPath,\n resolveMainModuleName,\n shouldEnableAsyncImports,\n} from '../middleware/ManifestMiddleware';\nimport { ReactDevToolsPageMiddleware } from '../middleware/ReactDevToolsPageMiddleware';\nimport {\n DeepLinkHandler,\n RuntimeRedirectMiddleware,\n} from '../middleware/RuntimeRedirectMiddleware';\nimport { ServeStaticMiddleware } from '../middleware/ServeStaticMiddleware';\nimport { prependMiddleware } from '../middleware/mutations';\nimport { ServerNext, ServerRequest, ServerResponse } from '../middleware/server.types';\nimport { startTypescriptTypeGenerationAsync } from '../type-generation/startTypescriptTypeGeneration';\n\nclass ForwardHtmlError extends CommandError {\n constructor(\n message: string,\n public html: string,\n public statusCode: number\n ) {\n super(message);\n }\n}\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\n/** Default port to use for apps running in Expo Go. */\nconst EXPO_GO_METRO_PORT = 8081;\n\n/** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */\nconst DEV_CLIENT_METRO_PORT = 8081;\n\nexport class MetroBundlerDevServer extends BundlerDevServer {\n private metro: import('metro').Server | null = null;\n\n get name(): string {\n return 'metro';\n }\n\n async resolvePortAsync(options: Partial<BundlerStartOptions> = {}): Promise<number> {\n const port =\n // If the manually defined port is busy then an error should be thrown...\n options.port ??\n // Otherwise use the default port based on the runtime target.\n (options.devClient\n ? // Don't check if the port is busy if we're using the dev client since most clients are hardcoded to 8081.\n Number(process.env.RCT_METRO_PORT) || DEV_CLIENT_METRO_PORT\n : // Otherwise (running in Expo Go) use a free port that falls back on the classic 8081 port.\n await getFreePortAsync(EXPO_GO_METRO_PORT));\n\n return port;\n }\n\n async composeResourcesWithHtml({\n mode,\n resources,\n template,\n devBundleUrl,\n basePath,\n }: {\n mode: 'development' | 'production';\n resources: SerialAsset[];\n template: string;\n /** asset prefix used for deploying to non-standard origins like GitHub pages. */\n basePath: string;\n devBundleUrl?: string;\n }): Promise<string> {\n if (!resources) {\n return '';\n }\n const isDev = mode === 'development';\n return htmlFromSerialAssets(resources, {\n dev: isDev,\n template,\n basePath,\n bundleUrl: isDev ? devBundleUrl : undefined,\n });\n }\n\n async getStaticRenderFunctionAsync({\n mode,\n minify = mode !== 'development',\n }: {\n mode: 'development' | 'production';\n minify?: boolean;\n }) {\n const url = this.getDevServerUrl()!;\n\n const { getStaticContent, getManifest } = await getStaticRenderFunctions(\n this.projectRoot,\n url,\n {\n minify,\n dev: mode !== 'production',\n // Ensure the API Routes are included\n environment: 'node',\n }\n );\n return {\n // Get routes from Expo Router.\n manifest: await getManifest({ fetchData: true }),\n // Get route generating function\n async renderAsync(path: string) {\n return await getStaticContent(new URL(path, url));\n },\n };\n }\n\n async getStaticResourcesAsync({\n mode,\n minify = mode !== 'development',\n includeMaps,\n }: {\n mode: string;\n minify?: boolean;\n includeMaps?: boolean;\n }): Promise<SerialAsset[]> {\n const devBundleUrlPathname = createBundleUrlPath({\n platform: 'web',\n mode,\n minify,\n environment: 'client',\n serializerOutput: 'static',\n serializerIncludeMaps: includeMaps,\n mainModuleName: resolveMainModuleName(this.projectRoot, getConfig(this.projectRoot), 'web'),\n lazy: shouldEnableAsyncImports(this.projectRoot),\n });\n\n const bundleUrl = new URL(devBundleUrlPathname, this.getDevServerUrl()!);\n\n // Fetch the generated HTML from our custom Metro serializer\n const results = await fetch(bundleUrl.toString());\n\n const txt = await results.text();\n\n // console.log('STAT:', results.status, results.statusText);\n let data: any;\n try {\n data = JSON.parse(txt);\n } catch (error: any) {\n debug(txt);\n\n // Metro can throw this error when the initial module id cannot be resolved.\n if (!results.ok && txt.startsWith('<!DOCTYPE html>')) {\n throw new ForwardHtmlError(\n `Metro failed to bundle the project. Check the console for more information.`,\n txt,\n results.status\n );\n }\n\n Log.error(\n 'Failed to generate resources with Metro, the Metro config may not be using the correct serializer. Ensure the metro.config.js is extending the expo/metro-config and is not overriding the serializer.'\n );\n throw error;\n }\n\n // NOTE: This could potentially need more validation in the future.\n if (Array.isArray(data)) {\n return data;\n }\n\n if (data != null && (data.errors || data.type?.match(/.*Error$/))) {\n // {\n // type: 'InternalError',\n // errors: [],\n // message: 'Metro has encountered an error: While trying to resolve module `stylis` from file `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/@emotion/cache/dist/emotion-cache.browser.esm.js`, the package `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs`. Indeed, none of these files exist:\\n' +\n // '\\n' +\n // ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css)\\n' +\n // ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs/index(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css): /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/metro/src/node-haste/DependencyGraph.js (289:17)\\n' +\n // '\\n' +\n // '\\x1B[0m \\x1B[90m 287 |\\x1B[39m }\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 288 |\\x1B[39m \\x1B[36mif\\x1B[39m (error \\x1B[36minstanceof\\x1B[39m \\x1B[33mInvalidPackageError\\x1B[39m) {\\x1B[0m\\n' +\n // '\\x1B[0m\\x1B[31m\\x1B[1m>\\x1B[22m\\x1B[39m\\x1B[90m 289 |\\x1B[39m \\x1B[36mthrow\\x1B[39m \\x1B[36mnew\\x1B[39m \\x1B[33mPackageResolutionError\\x1B[39m({\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m |\\x1B[39m \\x1B[31m\\x1B[1m^\\x1B[22m\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 290 |\\x1B[39m packageError\\x1B[33m:\\x1B[39m error\\x1B[33m,\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 291 |\\x1B[39m originModulePath\\x1B[33m:\\x1B[39m \\x1B[36mfrom\\x1B[39m\\x1B[33m,\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 292 |\\x1B[39m targetModuleName\\x1B[33m:\\x1B[39m to\\x1B[33m,\\x1B[39m\\x1B[0m'\n // }\n // The Metro logger already showed this error.\n throw new Error(data.message);\n }\n\n throw new Error(\n 'Invalid resources returned from the Metro serializer. Expected array, found: ' + data\n );\n }\n\n private async renderStaticErrorAsync(error: Error) {\n return getErrorOverlayHtmlAsync({\n error,\n projectRoot: this.projectRoot,\n });\n }\n\n async getStaticPageAsync(\n pathname: string,\n {\n mode,\n minify = mode !== 'development',\n basePath,\n }: {\n mode: 'development' | 'production';\n minify?: boolean;\n basePath: string;\n }\n ) {\n const devBundleUrlPathname = createBundleUrlPath({\n platform: 'web',\n mode,\n environment: 'client',\n mainModuleName: resolveMainModuleName(this.projectRoot, getConfig(this.projectRoot), 'web'),\n lazy: shouldEnableAsyncImports(this.projectRoot),\n });\n\n const bundleStaticHtml = async (): Promise<string> => {\n const { getStaticContent } = await getStaticRenderFunctions(\n this.projectRoot,\n this.getDevServerUrl()!,\n {\n minify: false,\n dev: mode !== 'production',\n // Ensure the API Routes are included\n environment: 'node',\n }\n );\n\n const location = new URL(pathname, this.getDevServerUrl()!);\n return await getStaticContent(location);\n };\n\n const [resources, staticHtml] = await Promise.all([\n this.getStaticResourcesAsync({ mode, minify }),\n bundleStaticHtml(),\n ]);\n const content = await this.composeResourcesWithHtml({\n mode,\n resources,\n template: staticHtml,\n devBundleUrl: devBundleUrlPathname,\n basePath,\n });\n return {\n content,\n resources,\n };\n }\n\n async watchEnvironmentVariables() {\n if (!this.instance) {\n throw new Error(\n 'Cannot observe environment variable changes without a running Metro instance.'\n );\n }\n if (!this.metro) {\n // This can happen when the run command is used and the server is already running in another\n // process.\n debug('Skipping Environment Variable observation because Metro is not running (headless).');\n return;\n }\n\n const envFiles = runtimeEnv\n .getFiles(process.env.NODE_ENV)\n .map((fileName) => path.join(this.projectRoot, fileName));\n\n observeFileChanges(\n {\n metro: this.metro,\n server: this.instance.server,\n },\n envFiles,\n () => {\n debug('Reloading environment variables...');\n // Force reload the environment variables.\n runtimeEnv.load(this.projectRoot, { force: true });\n }\n );\n }\n\n protected async startImplementationAsync(\n options: BundlerStartOptions\n ): Promise<DevServerInstance> {\n options.port = await this.resolvePortAsync(options);\n this.urlCreator = this.getUrlCreator(options);\n\n const parsedOptions = {\n port: options.port,\n maxWorkers: options.maxWorkers,\n resetCache: options.resetDevServer,\n\n // Use the unversioned metro config.\n // TODO: Deprecate this property when expo-cli goes away.\n unversioned: false,\n };\n\n // Required for symbolication:\n process.env.EXPO_DEV_SERVER_ORIGIN = `http://localhost:${options.port}`;\n\n const { metro, server, middleware, messageSocket } = await instantiateMetroAsync(\n this,\n parsedOptions,\n {\n isExporting: !!options.isExporting,\n }\n );\n\n const manifestMiddleware = await this.getManifestMiddlewareAsync(options);\n\n // Important that we noop source maps for context modules as soon as possible.\n prependMiddleware(middleware, new ContextModuleSourceMapsMiddleware().getHandler());\n\n // We need the manifest handler to be the first middleware to run so our\n // routes take precedence over static files. For example, the manifest is\n // served from '/' and if the user has an index.html file in their project\n // then the manifest handler will never run, the static middleware will run\n // and serve index.html instead of the manifest.\n // https://github.com/expo/expo/issues/13114\n prependMiddleware(middleware, manifestMiddleware.getHandler());\n\n middleware.use(\n new InterstitialPageMiddleware(this.projectRoot, {\n // TODO: Prevent this from becoming stale.\n scheme: options.location.scheme ?? null,\n }).getHandler()\n );\n middleware.use(new ReactDevToolsPageMiddleware(this.projectRoot).getHandler());\n\n const deepLinkMiddleware = new RuntimeRedirectMiddleware(this.projectRoot, {\n onDeepLink: getDeepLinkHandler(this.projectRoot),\n getLocation: ({ runtime }) => {\n if (runtime === 'custom') {\n return this.urlCreator?.constructDevClientUrl();\n } else {\n return this.urlCreator?.constructUrl({\n scheme: 'exp',\n });\n }\n },\n });\n middleware.use(deepLinkMiddleware.getHandler());\n\n middleware.use(new CreateFileMiddleware(this.projectRoot).getHandler());\n\n // Append support for redirecting unhandled requests to the index.html page on web.\n if (this.isTargetingWeb()) {\n const { exp } = getConfig(this.projectRoot, { skipSDKVersionRequirement: true });\n const useWebSSG = exp.web?.output === 'static';\n\n // This MUST be after the manifest middleware so it doesn't have a chance to serve the template `public/index.html`.\n middleware.use(new ServeStaticMiddleware(this.projectRoot).getHandler());\n\n // This should come after the static middleware so it doesn't serve the favicon from `public/favicon.ico`.\n middleware.use(new FaviconMiddleware(this.projectRoot).getHandler());\n\n if (useWebSSG) {\n middleware.use(async (req: ServerRequest, res: ServerResponse, next: ServerNext) => {\n if (!req?.url) {\n return next();\n }\n\n // TODO: Formal manifest for allowed paths\n if (req.url.endsWith('.ico')) {\n return next();\n }\n if (req.url.includes('serializer.output=static')) {\n return next();\n }\n\n try {\n const { content } = await this.getStaticPageAsync(req.url, {\n mode: options.mode ?? 'development',\n // Asset prefix is not supported in development.\n basePath: '',\n });\n\n res.setHeader('Content-Type', 'text/html');\n res.end(content);\n } catch (error: any) {\n res.setHeader('Content-Type', 'text/html');\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n if (error instanceof ForwardHtmlError) {\n res.statusCode = error.statusCode;\n res.end(error.html);\n return;\n }\n try {\n res.end(await this.renderStaticErrorAsync(error));\n } catch (staticError: any) {\n // Fallback error for when Expo Router is misconfigured in the project.\n res.end(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>'\n );\n }\n }\n });\n }\n\n // This MUST run last since it's the fallback.\n if (!useWebSSG) {\n middleware.use(\n new HistoryFallbackMiddleware(manifestMiddleware.getHandler().internal).getHandler()\n );\n }\n }\n // Extend the close method to ensure that we clean up the local info.\n const originalClose = server.close.bind(server);\n\n server.close = (callback?: (err?: Error) => void) => {\n return originalClose((err?: Error) => {\n this.instance = null;\n this.metro = null;\n callback?.(err);\n });\n };\n\n this.metro = metro;\n return {\n server,\n location: {\n // The port is the main thing we want to send back.\n port: options.port,\n // localhost isn't always correct.\n host: 'localhost',\n // http is the only supported protocol on native.\n url: `http://localhost:${options.port}`,\n protocol: 'http',\n },\n middleware,\n messageSocket,\n };\n }\n\n public async waitForTypeScriptAsync(): Promise<boolean> {\n if (!this.instance) {\n throw new Error('Cannot wait for TypeScript without a running server.');\n }\n\n return new Promise<boolean>((resolve) => {\n if (!this.metro) {\n // This can happen when the run command is used and the server is already running in another\n // process. In this case we can't wait for the TypeScript check to complete because we don't\n // have access to the Metro server.\n debug('Skipping TypeScript check because Metro is not running (headless).');\n return resolve(false);\n }\n\n const off = metroWatchTypeScriptFiles({\n projectRoot: this.projectRoot,\n server: this.instance!.server,\n metro: this.metro,\n tsconfig: true,\n throttle: true,\n eventTypes: ['change', 'add'],\n callback: async () => {\n // Run once, this prevents the TypeScript project prerequisite from running on every file change.\n off();\n const { TypeScriptProjectPrerequisite } = await import(\n '../../doctor/typescript/TypeScriptProjectPrerequisite'\n );\n\n try {\n const req = new TypeScriptProjectPrerequisite(this.projectRoot);\n await req.bootstrapAsync();\n resolve(true);\n } catch (error: any) {\n // Ensure the process doesn't fail if the TypeScript check fails.\n // This could happen during the install.\n Log.log();\n Log.error(\n chalk.red`Failed to automatically setup TypeScript for your project. Try restarting the dev server to fix.`\n );\n Log.exception(error);\n resolve(false);\n }\n },\n });\n });\n }\n\n public async startTypeScriptServices() {\n return startTypescriptTypeGenerationAsync({\n server: this.instance?.server,\n metro: this.metro,\n projectRoot: this.projectRoot,\n });\n }\n\n protected getConfigModuleIds(): string[] {\n return ['./metro.config.js', './metro.config.json', './rn-cli.config.js'];\n }\n}\n\nexport function getDeepLinkHandler(projectRoot: string): DeepLinkHandler {\n return async ({ runtime }) => {\n if (runtime === 'expo') return;\n const { exp } = getConfig(projectRoot);\n await logEventAsync('dev client start command', {\n status: 'started',\n ...getDevClientProperties(projectRoot, exp),\n });\n };\n}\n\nfunction htmlFromSerialAssets(\n assets: SerialAsset[],\n {\n dev,\n template,\n basePath,\n bundleUrl,\n }: {\n dev: boolean;\n template: string;\n basePath: string;\n /** This is dev-only. */\n bundleUrl?: string;\n }\n) {\n // Combine the CSS modules into tags that have hot refresh data attributes.\n const styleString = assets\n .filter((asset) => asset.type === 'css')\n .map(({ metadata, filename, source }) => {\n if (dev) {\n return `<style data-expo-css-hmr=\"${metadata.hmrId}\">` + source + '\\n</style>';\n } else {\n return [\n `<link rel=\"preload\" href=\"${basePath}/${filename}\" as=\"style\">`,\n `<link rel=\"stylesheet\" href=\"${basePath}/${filename}\">`,\n ].join('');\n }\n })\n .join('');\n\n const jsAssets = assets.filter((asset) => asset.type === 'js');\n\n const scripts = bundleUrl\n ? `<script src=\"${bundleUrl}\" defer></script>`\n : jsAssets\n .map(({ filename }) => {\n return `<script src=\"${basePath}/${filename}\" defer></script>`;\n })\n .join('');\n\n return template\n .replace('</head>', `${styleString}</head>`)\n .replace('</body>', `${scripts}\\n</body>`);\n}\n"],"names":["getDeepLinkHandler","runtimeEnv","ForwardHtmlError","CommandError","constructor","message","html","statusCode","debug","require","EXPO_GO_METRO_PORT","DEV_CLIENT_METRO_PORT","MetroBundlerDevServer","BundlerDevServer","metro","name","resolvePortAsync","options","port","devClient","Number","process","env","RCT_METRO_PORT","getFreePortAsync","composeResourcesWithHtml","mode","resources","template","devBundleUrl","basePath","isDev","htmlFromSerialAssets","dev","bundleUrl","undefined","getStaticRenderFunctionAsync","minify","url","getDevServerUrl","getStaticContent","getManifest","getStaticRenderFunctions","projectRoot","environment","manifest","fetchData","renderAsync","path","URL","getStaticResourcesAsync","includeMaps","data","devBundleUrlPathname","createBundleUrlPath","platform","serializerOutput","serializerIncludeMaps","mainModuleName","resolveMainModuleName","getConfig","lazy","shouldEnableAsyncImports","results","fetch","toString","txt","text","JSON","parse","error","ok","startsWith","status","Log","Array","isArray","errors","type","match","Error","renderStaticErrorAsync","getErrorOverlayHtmlAsync","getStaticPageAsync","pathname","bundleStaticHtml","location","staticHtml","Promise","all","content","watchEnvironmentVariables","instance","envFiles","getFiles","NODE_ENV","map","fileName","join","observeFileChanges","server","load","force","startImplementationAsync","urlCreator","getUrlCreator","parsedOptions","maxWorkers","resetCache","resetDevServer","unversioned","EXPO_DEV_SERVER_ORIGIN","middleware","messageSocket","instantiateMetroAsync","isExporting","manifestMiddleware","getManifestMiddlewareAsync","prependMiddleware","ContextModuleSourceMapsMiddleware","getHandler","use","InterstitialPageMiddleware","scheme","ReactDevToolsPageMiddleware","deepLinkMiddleware","RuntimeRedirectMiddleware","onDeepLink","getLocation","runtime","constructDevClientUrl","constructUrl","CreateFileMiddleware","isTargetingWeb","exp","skipSDKVersionRequirement","useWebSSG","web","output","ServeStaticMiddleware","FaviconMiddleware","req","res","next","endsWith","includes","setHeader","end","staticError","HistoryFallbackMiddleware","internal","originalClose","close","bind","callback","err","host","protocol","waitForTypeScriptAsync","resolve","off","metroWatchTypeScriptFiles","tsconfig","throttle","eventTypes","TypeScriptProjectPrerequisite","bootstrapAsync","log","chalk","red","exception","startTypeScriptServices","startTypescriptTypeGenerationAsync","getConfigModuleIds","logEventAsync","getDevClientProperties","assets","styleString","filter","asset","metadata","filename","source","hmrId","jsAssets","scripts","replace"],"mappings":"AAMA;;;;QAwgBgBA,kBAAkB,GAAlBA,kBAAkB;AAxgBR,IAAA,OAAc,WAAd,cAAc,CAAA;AAC5BC,IAAAA,UAAU,mCAAM,WAAW,EAAjB;AAEJ,IAAA,MAAO,kCAAP,OAAO,EAAA;AACP,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEe,IAAA,iBAAoB,WAApB,oBAAoB,CAAA;AACjB,IAAA,oBAAuB,WAAvB,uBAAuB,CAAA;AACtB,IAAA,0BAA6B,WAA7B,6BAA6B,CAAA;AACpC,IAAA,oCAAuC,WAAvC,uCAAuC,CAAA;AACtD,IAAA,IAAc,WAAd,cAAc,CAAA;AACC,IAAA,uBAAiD,kCAAjD,iDAAiD,EAAA;AACtD,IAAA,kBAA4C,WAA5C,4CA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IAEZ,MAAMsF,QAAQ,GAAGR,MAAM,CAACE,MAAM,CAAC,CAACC,KAAK,GAAKA,KAAK,CAACrG,IAAI,KAAK,IAAI;IAAA,CAAC,AAAC;IAE/D,MAAM2G,OAAO,GAAGvJ,SAAS,GACrB,CAAC,aAAa,EAAEA,SAAS,CAAC,iBAAiB,CAAC,GAC5CsJ,QAAQ,CACLxF,GAAG,CAAC,CAAC,EAAEqF,QAAQ,CAAA,EAAE,GAAK;QACrB,OAAO,CAAC,aAAa,EAAEvJ,QAAQ,CAAC,CAAC,EAAEuJ,QAAQ,CAAC,iBAAiB,CAAC,CAAC;KAChE,CAAC,CACDnF,IAAI,CAAC,EAAE,CAAC,AAAC;IAEhB,OAAOtE,QAAQ,CACZ8J,OAAO,CAAC,SAAS,EAAE,CAAC,EAAET,WAAW,CAAC,OAAO,CAAC,CAAC,CAC3CS,OAAO,CAAC,SAAS,EAAE,CAAC,EAAED,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;CAC9C"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/MetroBundlerDevServer.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 { getConfig } from '@expo/config';\nimport * as runtimeEnv from '@expo/env';\nimport { SerialAsset } from '@expo/metro-config/build/serializer/serializerAssets';\nimport chalk from 'chalk';\nimport fetch from 'node-fetch';\nimport path from 'path';\n\nimport { exportAllApiRoutesAsync, rebundleApiRoute } from './bundleApiRoutes';\nimport { createRouteHandlerMiddleware } from './createServerRouteMiddleware';\nimport { fetchManifest } from './fetchRouterManifest';\nimport { instantiateMetroAsync } from './instantiateMetro';\nimport { metroWatchTypeScriptFiles } from './metroWatchTypeScriptFiles';\nimport { getRouterDirectoryWithManifest, isApiRouteConvention } from './router';\nimport { observeApiRouteChanges, observeFileChanges } from './waitForMetroToObserveTypeScriptFile';\nimport { Log } from '../../../log';\nimport getDevClientProperties from '../../../utils/analytics/getDevClientProperties';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport { CommandError } from '../../../utils/errors';\nimport { getFreePortAsync } from '../../../utils/port';\nimport { BundlerDevServer, BundlerStartOptions, DevServerInstance } from '../BundlerDevServer';\nimport { getStaticRenderFunctions } from '../getStaticRenderFunctions';\nimport { ContextModuleSourceMapsMiddleware } from '../middleware/ContextModuleSourceMapsMiddleware';\nimport { CreateFileMiddleware } from '../middleware/CreateFileMiddleware';\nimport { FaviconMiddleware } from '../middleware/FaviconMiddleware';\nimport { HistoryFallbackMiddleware } from '../middleware/HistoryFallbackMiddleware';\nimport { InterstitialPageMiddleware } from '../middleware/InterstitialPageMiddleware';\nimport {\n createBundleUrlPath,\n resolveMainModuleName,\n shouldEnableAsyncImports,\n} from '../middleware/ManifestMiddleware';\nimport { ReactDevToolsPageMiddleware } from '../middleware/ReactDevToolsPageMiddleware';\nimport {\n DeepLinkHandler,\n RuntimeRedirectMiddleware,\n} from '../middleware/RuntimeRedirectMiddleware';\nimport { ServeStaticMiddleware } from '../middleware/ServeStaticMiddleware';\nimport { prependMiddleware } from '../middleware/mutations';\nimport { startTypescriptTypeGenerationAsync } from '../type-generation/startTypescriptTypeGeneration';\n\nexport class ForwardHtmlError extends CommandError {\n constructor(\n message: string,\n public html: string,\n public statusCode: number\n ) {\n super(message);\n }\n}\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\n/** Default port to use for apps running in Expo Go. */\nconst EXPO_GO_METRO_PORT = 8081;\n\n/** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */\nconst DEV_CLIENT_METRO_PORT = 8081;\n\nexport class MetroBundlerDevServer extends BundlerDevServer {\n private metro: import('metro').Server | null = null;\n\n get name(): string {\n return 'metro';\n }\n\n async resolvePortAsync(options: Partial<BundlerStartOptions> = {}): Promise<number> {\n const port =\n // If the manually defined port is busy then an error should be thrown...\n options.port ??\n // Otherwise use the default port based on the runtime target.\n (options.devClient\n ? // Don't check if the port is busy if we're using the dev client since most clients are hardcoded to 8081.\n Number(process.env.RCT_METRO_PORT) || DEV_CLIENT_METRO_PORT\n : // Otherwise (running in Expo Go) use a free port that falls back on the classic 8081 port.\n await getFreePortAsync(EXPO_GO_METRO_PORT));\n\n return port;\n }\n\n async getExpoRouterRoutesManifestAsync({ appDir }: { appDir: string }) {\n const manifest = await fetchManifest(this.projectRoot, {\n asJson: true,\n appDir,\n });\n\n if (!manifest) {\n throw new CommandError(\n 'EXPO_ROUTER_SERVER_MANIFEST',\n 'Unexpected error: server manifest could not be fetched.'\n );\n }\n\n return manifest;\n }\n\n async exportExpoRouterApiRoutesAsync({\n mode,\n appDir,\n }: {\n mode: 'development' | 'production';\n appDir: string;\n }) {\n return exportAllApiRoutesAsync(this.projectRoot, {\n mode,\n appDir,\n port: this.getInstance()?.location.port,\n shouldThrow: true,\n });\n }\n\n async composeResourcesWithHtml({\n mode,\n resources,\n template,\n devBundleUrl,\n basePath,\n }: {\n mode: 'development' | 'production';\n resources: SerialAsset[];\n template: string;\n /** asset prefix used for deploying to non-standard origins like GitHub pages. */\n basePath: string;\n devBundleUrl?: string;\n }): Promise<string> {\n if (!resources) {\n return '';\n }\n const isDev = mode === 'development';\n return htmlFromSerialAssets(resources, {\n dev: isDev,\n template,\n basePath,\n bundleUrl: isDev ? devBundleUrl : undefined,\n });\n }\n\n async getStaticRenderFunctionAsync({\n mode,\n minify = mode !== 'development',\n }: {\n mode: 'development' | 'production';\n minify?: boolean;\n }) {\n const url = this.getDevServerUrl()!;\n\n const { getStaticContent, getManifest } = await getStaticRenderFunctions(\n this.projectRoot,\n url,\n {\n minify,\n dev: mode !== 'production',\n // Ensure the API Routes are included\n environment: 'node',\n }\n );\n return {\n // Get routes from Expo Router.\n manifest: await getManifest({ fetchData: true, preserveApiRoutes: false }),\n // Get route generating function\n async renderAsync(path: string) {\n return await getStaticContent(new URL(path, url));\n },\n };\n }\n\n async getStaticResourcesAsync({\n mode,\n minify = mode !== 'development',\n includeMaps,\n }: {\n mode: string;\n minify?: boolean;\n includeMaps?: boolean;\n }): Promise<SerialAsset[]> {\n const devBundleUrlPathname = createBundleUrlPath({\n platform: 'web',\n mode,\n minify,\n environment: 'client',\n serializerOutput: 'static',\n serializerIncludeMaps: includeMaps,\n mainModuleName: resolveMainModuleName(this.projectRoot, getConfig(this.projectRoot), 'web'),\n lazy: shouldEnableAsyncImports(this.projectRoot),\n });\n\n const bundleUrl = new URL(devBundleUrlPathname, this.getDevServerUrl()!);\n\n // Fetch the generated HTML from our custom Metro serializer\n const results = await fetch(bundleUrl.toString());\n\n const txt = await results.text();\n\n // console.log('STAT:', results.status, results.statusText);\n let data: any;\n try {\n data = JSON.parse(txt);\n } catch (error: any) {\n debug(txt);\n\n // Metro can throw this error when the initial module id cannot be resolved.\n if (!results.ok && txt.startsWith('<!DOCTYPE html>')) {\n throw new ForwardHtmlError(\n `Metro failed to bundle the project. Check the console for more information.`,\n txt,\n results.status\n );\n }\n\n Log.error(\n 'Failed to generate resources with Metro, the Metro config may not be using the correct serializer. Ensure the metro.config.js is extending the expo/metro-config and is not overriding the serializer.'\n );\n throw error;\n }\n\n // NOTE: This could potentially need more validation in the future.\n if (Array.isArray(data)) {\n return data;\n }\n\n if (data != null && (data.errors || data.type?.match(/.*Error$/))) {\n // {\n // type: 'InternalError',\n // errors: [],\n // message: 'Metro has encountered an error: While trying to resolve module `stylis` from file `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/@emotion/cache/dist/emotion-cache.browser.esm.js`, the package `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs`. Indeed, none of these files exist:\\n' +\n // '\\n' +\n // ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css)\\n' +\n // ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs/index(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css): /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/metro/src/node-haste/DependencyGraph.js (289:17)\\n' +\n // '\\n' +\n // '\\x1B[0m \\x1B[90m 287 |\\x1B[39m }\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 288 |\\x1B[39m \\x1B[36mif\\x1B[39m (error \\x1B[36minstanceof\\x1B[39m \\x1B[33mInvalidPackageError\\x1B[39m) {\\x1B[0m\\n' +\n // '\\x1B[0m\\x1B[31m\\x1B[1m>\\x1B[22m\\x1B[39m\\x1B[90m 289 |\\x1B[39m \\x1B[36mthrow\\x1B[39m \\x1B[36mnew\\x1B[39m \\x1B[33mPackageResolutionError\\x1B[39m({\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m |\\x1B[39m \\x1B[31m\\x1B[1m^\\x1B[22m\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 290 |\\x1B[39m packageError\\x1B[33m:\\x1B[39m error\\x1B[33m,\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 291 |\\x1B[39m originModulePath\\x1B[33m:\\x1B[39m \\x1B[36mfrom\\x1B[39m\\x1B[33m,\\x1B[39m\\x1B[0m\\n' +\n // '\\x1B[0m \\x1B[90m 292 |\\x1B[39m targetModuleName\\x1B[33m:\\x1B[39m to\\x1B[33m,\\x1B[39m\\x1B[0m'\n // }\n // The Metro logger already showed this error.\n throw new Error(data.message);\n }\n\n throw new Error(\n 'Invalid resources returned from the Metro serializer. Expected array, found: ' + data\n );\n }\n\n async getStaticPageAsync(\n pathname: string,\n {\n mode,\n minify = mode !== 'development',\n basePath,\n }: {\n mode: 'development' | 'production';\n minify?: boolean;\n basePath: string;\n }\n ) {\n const devBundleUrlPathname = createBundleUrlPath({\n platform: 'web',\n mode,\n environment: 'client',\n mainModuleName: resolveMainModuleName(this.projectRoot, getConfig(this.projectRoot), 'web'),\n lazy: shouldEnableAsyncImports(this.projectRoot),\n });\n\n const bundleStaticHtml = async (): Promise<string> => {\n const { getStaticContent } = await getStaticRenderFunctions(\n this.projectRoot,\n this.getDevServerUrl()!,\n {\n minify: false,\n dev: mode !== 'production',\n // Ensure the API Routes are included\n environment: 'node',\n }\n );\n\n const location = new URL(pathname, this.getDevServerUrl()!);\n return await getStaticContent(location);\n };\n\n const [resources, staticHtml] = await Promise.all([\n this.getStaticResourcesAsync({ mode, minify }),\n bundleStaticHtml(),\n ]);\n const content = await this.composeResourcesWithHtml({\n mode,\n resources,\n template: staticHtml,\n devBundleUrl: devBundleUrlPathname,\n basePath,\n });\n return {\n content,\n resources,\n };\n }\n\n async watchEnvironmentVariables() {\n if (!this.instance) {\n throw new Error(\n 'Cannot observe environment variable changes without a running Metro instance.'\n );\n }\n if (!this.metro) {\n // This can happen when the run command is used and the server is already running in another\n // process.\n debug('Skipping Environment Variable observation because Metro is not running (headless).');\n return;\n }\n\n const envFiles = runtimeEnv\n .getFiles(process.env.NODE_ENV)\n .map((fileName) => path.join(this.projectRoot, fileName));\n\n observeFileChanges(\n {\n metro: this.metro,\n server: this.instance.server,\n },\n envFiles,\n () => {\n debug('Reloading environment variables...');\n // Force reload the environment variables.\n runtimeEnv.load(this.projectRoot, { force: true });\n }\n );\n }\n\n protected async startImplementationAsync(\n options: BundlerStartOptions\n ): Promise<DevServerInstance> {\n options.port = await this.resolvePortAsync(options);\n this.urlCreator = this.getUrlCreator(options);\n\n const parsedOptions = {\n port: options.port,\n maxWorkers: options.maxWorkers,\n resetCache: options.resetDevServer,\n\n // Use the unversioned metro config.\n // TODO: Deprecate this property when expo-cli goes away.\n unversioned: false,\n };\n\n // Required for symbolication:\n process.env.EXPO_DEV_SERVER_ORIGIN = `http://localhost:${options.port}`;\n\n const { metro, server, middleware, messageSocket } = await instantiateMetroAsync(\n this,\n parsedOptions,\n {\n isExporting: !!options.isExporting,\n }\n );\n\n const manifestMiddleware = await this.getManifestMiddlewareAsync(options);\n\n // Important that we noop source maps for context modules as soon as possible.\n prependMiddleware(middleware, new ContextModuleSourceMapsMiddleware().getHandler());\n\n // We need the manifest handler to be the first middleware to run so our\n // routes take precedence over static files. For example, the manifest is\n // served from '/' and if the user has an index.html file in their project\n // then the manifest handler will never run, the static middleware will run\n // and serve index.html instead of the manifest.\n // https://github.com/expo/expo/issues/13114\n prependMiddleware(middleware, manifestMiddleware.getHandler());\n\n middleware.use(\n new InterstitialPageMiddleware(this.projectRoot, {\n // TODO: Prevent this from becoming stale.\n scheme: options.location.scheme ?? null,\n }).getHandler()\n );\n middleware.use(new ReactDevToolsPageMiddleware(this.projectRoot).getHandler());\n\n const deepLinkMiddleware = new RuntimeRedirectMiddleware(this.projectRoot, {\n onDeepLink: getDeepLinkHandler(this.projectRoot),\n getLocation: ({ runtime }) => {\n if (runtime === 'custom') {\n return this.urlCreator?.constructDevClientUrl();\n } else {\n return this.urlCreator?.constructUrl({\n scheme: 'exp',\n });\n }\n },\n });\n middleware.use(deepLinkMiddleware.getHandler());\n\n middleware.use(new CreateFileMiddleware(this.projectRoot).getHandler());\n\n // Append support for redirecting unhandled requests to the index.html page on web.\n if (this.isTargetingWeb()) {\n const { exp } = getConfig(this.projectRoot, { skipSDKVersionRequirement: true });\n const useServerRendering = ['static', 'server'].includes(exp.web?.output ?? '');\n\n // This MUST be after the manifest middleware so it doesn't have a chance to serve the template `public/index.html`.\n middleware.use(new ServeStaticMiddleware(this.projectRoot).getHandler());\n\n // This should come after the static middleware so it doesn't serve the favicon from `public/favicon.ico`.\n middleware.use(new FaviconMiddleware(this.projectRoot).getHandler());\n\n const appDir = getRouterDirectoryWithManifest(this.projectRoot, exp);\n\n middleware.use(\n createRouteHandlerMiddleware(this.projectRoot, {\n ...options,\n appDir,\n getWebBundleUrl: manifestMiddleware.getWebBundleUrl.bind(manifestMiddleware),\n getStaticPageAsync: (pathname) => {\n return this.getStaticPageAsync(pathname, {\n mode: options.mode ?? 'development',\n minify: options.minify,\n // No base path in development\n basePath: '',\n });\n },\n })\n );\n\n // @ts-expect-error: TODO\n if (exp.web?.output === 'server') {\n // Cache observation for API Routes...\n observeApiRouteChanges(\n this.projectRoot,\n {\n metro,\n server,\n },\n async (filepath, op) => {\n if (isApiRouteConvention(filepath)) {\n debug(`[expo-cli] ${op} ${filepath}`);\n if (op === 'change' || op === 'add') {\n rebundleApiRoute(this.projectRoot, filepath, {\n ...options,\n appDir,\n });\n }\n\n if (op === 'delete') {\n // TODO: Cancel the bundling of the deleted route.\n }\n }\n }\n );\n }\n\n // This MUST run last since it's the fallback.\n if (!useServerRendering) {\n middleware.use(\n new HistoryFallbackMiddleware(manifestMiddleware.getHandler().internal).getHandler()\n );\n }\n }\n // Extend the close method to ensure that we clean up the local info.\n const originalClose = server.close.bind(server);\n\n server.close = (callback?: (err?: Error) => void) => {\n return originalClose((err?: Error) => {\n this.instance = null;\n this.metro = null;\n callback?.(err);\n });\n };\n\n this.metro = metro;\n return {\n server,\n location: {\n // The port is the main thing we want to send back.\n port: options.port,\n // localhost isn't always correct.\n host: 'localhost',\n // http is the only supported protocol on native.\n url: `http://localhost:${options.port}`,\n protocol: 'http',\n },\n middleware,\n messageSocket,\n };\n }\n\n public async waitForTypeScriptAsync(): Promise<boolean> {\n if (!this.instance) {\n throw new Error('Cannot wait for TypeScript without a running server.');\n }\n\n return new Promise<boolean>((resolve) => {\n if (!this.metro) {\n // This can happen when the run command is used and the server is already running in another\n // process. In this case we can't wait for the TypeScript check to complete because we don't\n // have access to the Metro server.\n debug('Skipping TypeScript check because Metro is not running (headless).');\n return resolve(false);\n }\n\n const off = metroWatchTypeScriptFiles({\n projectRoot: this.projectRoot,\n server: this.instance!.server,\n metro: this.metro,\n tsconfig: true,\n throttle: true,\n eventTypes: ['change', 'add'],\n callback: async () => {\n // Run once, this prevents the TypeScript project prerequisite from running on every file change.\n off();\n const { TypeScriptProjectPrerequisite } = await import(\n '../../doctor/typescript/TypeScriptProjectPrerequisite'\n );\n\n try {\n const req = new TypeScriptProjectPrerequisite(this.projectRoot);\n await req.bootstrapAsync();\n resolve(true);\n } catch (error: any) {\n // Ensure the process doesn't fail if the TypeScript check fails.\n // This could happen during the install.\n Log.log();\n Log.error(\n chalk.red`Failed to automatically setup TypeScript for your project. Try restarting the dev server to fix.`\n );\n Log.exception(error);\n resolve(false);\n }\n },\n });\n });\n }\n\n public async startTypeScriptServices() {\n return startTypescriptTypeGenerationAsync({\n server: this.instance?.server,\n metro: this.metro,\n projectRoot: this.projectRoot,\n });\n }\n\n protected getConfigModuleIds(): string[] {\n return ['./metro.config.js', './metro.config.json', './rn-cli.config.js'];\n }\n}\n\nexport function getDeepLinkHandler(projectRoot: string): DeepLinkHandler {\n return async ({ runtime }) => {\n if (runtime === 'expo') return;\n const { exp } = getConfig(projectRoot);\n await logEventAsync('dev client start command', {\n status: 'started',\n ...getDevClientProperties(projectRoot, exp),\n });\n };\n}\n\nfunction htmlFromSerialAssets(\n assets: SerialAsset[],\n {\n dev,\n template,\n basePath,\n bundleUrl,\n }: {\n dev: boolean;\n template: string;\n basePath: string;\n /** This is dev-only. */\n bundleUrl?: string;\n }\n) {\n // Combine the CSS modules into tags that have hot refresh data attributes.\n const styleString = assets\n .filter((asset) => asset.type === 'css')\n .map(({ metadata, filename, source }) => {\n if (dev) {\n return `<style data-expo-css-hmr=\"${metadata.hmrId}\">` + source + '\\n</style>';\n } else {\n return [\n `<link rel=\"preload\" href=\"${basePath}/${filename}\" as=\"style\">`,\n `<link rel=\"stylesheet\" href=\"${basePath}/${filename}\">`,\n ].join('');\n }\n })\n .join('');\n\n const jsAssets = assets.filter((asset) => asset.type === 'js');\n\n const scripts = bundleUrl\n ? `<script src=\"${bundleUrl}\" defer></script>`\n : jsAssets\n .map(({ filename }) => {\n return `<script src=\"${basePath}/${filename}\" defer></script>`;\n })\n .join('');\n\n return template\n .replace('</head>', `${styleString}</head>`)\n .replace('</body>', `${scripts}\\n</body>`);\n}\n"],"names":["getDeepLinkHandler","runtimeEnv","ForwardHtmlError","CommandError","constructor","message","html","statusCode","debug","require","EXPO_GO_METRO_PORT","DEV_CLIENT_METRO_PORT","MetroBundlerDevServer","BundlerDevServer","metro","name","resolvePortAsync","options","port","devClient","Number","process","env","RCT_METRO_PORT","getFreePortAsync","getExpoRouterRoutesManifestAsync","appDir","manifest","fetchManifest","projectRoot","asJson","exportExpoRouterApiRoutesAsync","mode","exportAllApiRoutesAsync","getInstance","location","shouldThrow","composeResourcesWithHtml","resources","template","devBundleUrl","basePath","isDev","htmlFromSerialAssets","dev","bundleUrl","undefined","getStaticRenderFunctionAsync","minify","url","getDevServerUrl","getStaticContent","getManifest","getStaticRenderFunctions","environment","fetchData","preserveApiRoutes","renderAsync","path","URL","getStaticResourcesAsync","includeMaps","data","devBundleUrlPathname","createBundleUrlPath","platform","serializerOutput","serializerIncludeMaps","mainModuleName","resolveMainModuleName","getConfig","lazy","shouldEnableAsyncImports","results","fetch","toString","txt","text","JSON","parse","error","ok","startsWith","status","Log","Array","isArray","errors","type","match","Error","getStaticPageAsync","pathname","bundleStaticHtml","staticHtml","Promise","all","content","watchEnvironmentVariables","instance","envFiles","getFiles","NODE_ENV","map","fileName","join","observeFileChanges","server","load","force","startImplementationAsync","urlCreator","getUrlCreator","parsedOptions","maxWorkers","resetCache","resetDevServer","unversioned","EXPO_DEV_SERVER_ORIGIN","middleware","messageSocket","instantiateMetroAsync","isExporting","manifestMiddleware","getManifestMiddlewareAsync","prependMiddleware","ContextModuleSourceMapsMiddleware","getHandler","use","InterstitialPageMiddleware","scheme","ReactDevToolsPageMiddleware","deepLinkMiddleware","RuntimeRedirectMiddleware","onDeepLink","getLocation","runtime","constructDevClientUrl","constructUrl","CreateFileMiddleware","isTargetingWeb","exp","skipSDKVersionRequirement","useServerRendering","includes","web","output","ServeStaticMiddleware","FaviconMiddleware","getRouterDirectoryWithManifest","createRouteHandlerMiddleware","getWebBundleUrl","bind","observeApiRouteChanges","filepath","op","isApiRouteConvention","rebundleApiRoute","HistoryFallbackMiddleware","internal","originalClose","close","callback","err","host","protocol","waitForTypeScriptAsync","resolve","off","metroWatchTypeScriptFiles","tsconfig","throttle","eventTypes","TypeScriptProjectPrerequisite","req","bootstrapAsync","log","chalk","red","exception","startTypeScriptServices","startTypescriptTypeGenerationAsync","getConfigModuleIds","logEventAsync","getDevClientProperties","assets","styleString","filter","asset","metadata","filename","source","hmrId","jsAssets","scripts","replace"],"mappings":"AAMA;;;;QAgiBgBA,kBAAkB,GAAlBA,kBAAkB;AAhiBR,IAAA,OAAc,WAAd,cAAc,CAAA;AAC5BC,IAAAA,UAAU,mCAAM,WAAW,EAAjB;AAEJ,IAAA,MAAO,kCAAP,OAAO,EAAA;AACP,IAAA,UAAY,kCAAZ,YAAY,EAAA;AACb,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEmC,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;AAChC,IAAA,4BAA+B,WAA/B,+BAA+B,CAAA;AAC9C,IAAA,oBAAuB,WAAvB,uBAAuB,CAAA;AACf,IAAA,iBAAoB,WAApB,oBAAoB,CAAA;AAChB,IAAA,0BAA6B,WAA7B,6BAA6B,CAAA;AACF,IAAA,OAAU,WAAV,UAAU,CAAA;AACpB,IAAA,oCAAuC,WAAvC,uCAAuC,CAAA;AAC9E,IAAA,IAAc,WAAd,cAAc,CAAA;AACC,IAAA,uBAAiD,kCAAjD,iDAAiD,EAAA;AACtD,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAC7C,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AACnB,IAAA,KAAqB,WAArB,qBAAqB,CAAA;AACmB,IAAA,iBAAqB,WAArB,qBAAqB,CAAA;AACrD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CAAC;CAC9C"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.bundleApiRoute = bundleApiRoute;
6
+ exports.rebundleApiRoute = rebundleApiRoute;
7
+ exports.exportAllApiRoutesAsync = exportAllApiRoutesAsync;
8
+ var _nodePath = _interopRequireDefault(require("node:path"));
9
+ var _metroErrorInterface = require("./metroErrorInterface");
10
+ var _router = require("./router");
11
+ var _getStaticRenderFunctions = require("../getStaticRenderFunctions");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const debug = require("debug")("expo:server-routes");
18
+ const pendingRouteOperations = new Map();
19
+ async function bundleApiRoute(projectRoot, filepath, options) {
20
+ if (pendingRouteOperations.has(filepath)) {
21
+ return pendingRouteOperations.get(filepath);
22
+ }
23
+ const devServerUrl = `http://localhost:${options.port}`;
24
+ async function bundleAsync() {
25
+ try {
26
+ debug("Check API route:", options.appDir, filepath);
27
+ const middleware = await (0, _getStaticRenderFunctions).requireFileContentsWithMetro(projectRoot, devServerUrl, filepath, {
28
+ minify: options.mode === "production",
29
+ dev: options.mode !== "production",
30
+ // Ensure Node.js
31
+ environment: "node"
32
+ });
33
+ return middleware;
34
+ } catch (error) {
35
+ if (error instanceof Error) {
36
+ await (0, _metroErrorInterface).logMetroErrorAsync({
37
+ error,
38
+ projectRoot
39
+ });
40
+ }
41
+ if (options.shouldThrow) {
42
+ throw error;
43
+ }
44
+ // TODO: improve error handling, maybe have this be a mock function which returns the static error html
45
+ return null;
46
+ } finally{
47
+ // pendingRouteOperations.delete(filepath);
48
+ }
49
+ }
50
+ const route = bundleAsync();
51
+ pendingRouteOperations.set(filepath, route);
52
+ return route;
53
+ }
54
+ async function rebundleApiRoute(projectRoot, filepath, options) {
55
+ pendingRouteOperations.delete(filepath);
56
+ return bundleApiRoute(projectRoot, filepath, options);
57
+ }
58
+ async function exportAllApiRoutesAsync(projectRoot, options) {
59
+ const files = new Map();
60
+ await Promise.all((0, _router).getApiRoutesForDirectory(options.appDir).map(async (filepath)=>{
61
+ const contents = await bundleApiRoute(projectRoot, filepath, options);
62
+ files.set(_nodePath.default.relative(options.appDir, filepath.replace(/\.[tj]sx?$/, ".js")), contents);
63
+ }));
64
+ return files;
65
+ }
66
+
67
+ //# sourceMappingURL=bundleApiRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/bundleApiRoutes.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 path from 'node:path';\n\nimport { logMetroErrorAsync } from './metroErrorInterface';\nimport { getApiRoutesForDirectory } from './router';\nimport { requireFileContentsWithMetro } from '../getStaticRenderFunctions';\n\nconst debug = require('debug')('expo:server-routes') as typeof console.log;\n\nconst pendingRouteOperations = new Map<string, Promise<string | null>>();\n\nexport type ApiRouteOptions = {\n mode?: string;\n appDir: string;\n port?: number;\n shouldThrow?: boolean;\n};\n\n// Bundle the API Route with Metro and return the string contents to be evaluated in the server.\nexport async function bundleApiRoute(\n projectRoot: string,\n filepath: string,\n options: ApiRouteOptions\n): Promise<string | null | undefined> {\n if (pendingRouteOperations.has(filepath)) {\n return pendingRouteOperations.get(filepath);\n }\n\n const devServerUrl = `http://localhost:${options.port}`;\n\n async function bundleAsync() {\n try {\n debug('Check API route:', options.appDir, filepath);\n\n const middleware = await requireFileContentsWithMetro(projectRoot, devServerUrl, filepath, {\n minify: options.mode === 'production',\n dev: options.mode !== 'production',\n // Ensure Node.js\n environment: 'node',\n });\n\n return middleware;\n } catch (error: any) {\n if (error instanceof Error) {\n await logMetroErrorAsync({ error, projectRoot });\n }\n if (options.shouldThrow) {\n throw error;\n }\n // TODO: improve error handling, maybe have this be a mock function which returns the static error html\n return null;\n } finally {\n // pendingRouteOperations.delete(filepath);\n }\n }\n const route = bundleAsync();\n\n pendingRouteOperations.set(filepath, route);\n return route;\n}\n\nexport async function rebundleApiRoute(\n projectRoot: string,\n filepath: string,\n options: ApiRouteOptions\n) {\n pendingRouteOperations.delete(filepath);\n return bundleApiRoute(projectRoot, filepath, options);\n}\n\nexport async function exportAllApiRoutesAsync(projectRoot: string, options: ApiRouteOptions) {\n const files: Map<string, string> = new Map();\n\n await Promise.all(\n getApiRoutesForDirectory(options.appDir).map(async (filepath) => {\n const contents = await bundleApiRoute(projectRoot, filepath, options);\n files.set(path.relative(options.appDir, filepath.replace(/\\.[tj]sx?$/, '.js')), contents!);\n })\n );\n\n return files;\n}\n"],"names":["bundleApiRoute","rebundleApiRoute","exportAllApiRoutesAsync","debug","require","pendingRouteOperations","Map","projectRoot","filepath","options","has","get","devServerUrl","port","bundleAsync","appDir","middleware","requireFileContentsWithMetro","minify","mode","dev","environment","error","Error","logMetroErrorAsync","shouldThrow","route","set","delete","files","Promise","all","getApiRoutesForDirectory","map","contents","path","relative","replace"],"mappings":"AAMA;;;;QAkBsBA,cAAc,GAAdA,cAAc;QA0CdC,gBAAgB,GAAhBA,gBAAgB;QAShBC,uBAAuB,GAAvBA,uBAAuB;AArE5B,IAAA,SAAW,kCAAX,WAAW,EAAA;AAEO,IAAA,oBAAuB,WAAvB,uBAAuB,CAAA;AACjB,IAAA,OAAU,WAAV,UAAU,CAAA;AACN,IAAA,yBAA6B,WAA7B,6BAA6B,CAAA;;;;;;AAE1E,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,AAAsB,AAAC;AAE3E,MAAMC,sBAAsB,GAAG,IAAIC,GAAG,EAAkC,AAAC;AAUlE,eAAeN,cAAc,CAClCO,WAAmB,EACnBC,QAAgB,EAChBC,OAAwB,EACY;IACpC,IAAIJ,sBAAsB,CAACK,GAAG,CAACF,QAAQ,CAAC,EAAE;QACxC,OAAOH,sBAAsB,CAACM,GAAG,CAACH,QAAQ,CAAC,CAAC;KAC7C;IAED,MAAMI,YAA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;IAC3F,MAAMoB,KAAK,GAAwB,IAAIvB,GAAG,EAAE,AAAC;IAE7C,MAAMwB,OAAO,CAACC,GAAG,CACfC,CAAAA,GAAAA,OAAwB,AAAgB,CAAA,yBAAhB,CAACvB,OAAO,CAACM,MAAM,CAAC,CAACkB,GAAG,CAAC,OAAOzB,QAAQ,GAAK;QAC/D,MAAM0B,QAAQ,GAAG,MAAMlC,cAAc,CAACO,WAAW,EAAEC,QAAQ,EAAEC,OAAO,CAAC,AAAC;QACtEoB,KAAK,CAACF,GAAG,CAACQ,SAAI,QAAA,CAACC,QAAQ,CAAC3B,OAAO,CAACM,MAAM,EAAEP,QAAQ,CAAC6B,OAAO,eAAe,KAAK,CAAC,CAAC,EAAEH,QAAQ,CAAE,CAAC;KAC5F,CAAC,CACH,CAAC;IAEF,OAAOL,KAAK,CAAC;CACd"}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.createRouteHandlerMiddleware = createRouteHandlerMiddleware;
6
+ var _server = require("@expo/server");
7
+ var _http = require("@expo/server/build/vendor/http");
8
+ var _requireFromString = _interopRequireDefault(require("require-from-string"));
9
+ var _resolve = _interopRequireDefault(require("resolve"));
10
+ var _util = require("util");
11
+ var _metroBundlerDevServer = require("./MetroBundlerDevServer");
12
+ var _bundleApiRoutes = require("./bundleApiRoutes");
13
+ var _fetchRouterManifest = require("./fetchRouterManifest");
14
+ var _metroErrorInterface = require("./metroErrorInterface");
15
+ var _log = require("../../../log");
16
+ function _interopRequireDefault(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ const debug = require("debug")("expo:start:server:metro");
22
+ const resolveAsync = (0, _util).promisify(_resolve.default);
23
+ function createRouteHandlerMiddleware(projectRoot, options) {
24
+ return (0, _http).createRequestHandler({
25
+ build: ""
26
+ }, {
27
+ async getRoutesManifest () {
28
+ const manifest = await (0, _fetchRouterManifest).fetchManifest(projectRoot, options);
29
+ debug("manifest", manifest);
30
+ // NOTE: no app dir if null
31
+ // TODO: Redirect to 404 page
32
+ return manifest;
33
+ },
34
+ async getHtml (request) {
35
+ try {
36
+ const { content } = await options.getStaticPageAsync(request.url);
37
+ return content;
38
+ } catch (error) {
39
+ // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.
40
+ if (error instanceof _metroBundlerDevServer.ForwardHtmlError) {
41
+ return new _server.ExpoResponse(error.html, {
42
+ status: error.statusCode,
43
+ headers: {
44
+ "Content-Type": "text/html"
45
+ }
46
+ });
47
+ }
48
+ try {
49
+ return new _server.ExpoResponse(await (0, _metroErrorInterface).getErrorOverlayHtmlAsync({
50
+ error,
51
+ projectRoot
52
+ }), {
53
+ status: 500,
54
+ headers: {
55
+ "Content-Type": "text/html"
56
+ }
57
+ });
58
+ } catch (staticError) {
59
+ // Fallback error for when Expo Router is misconfigured in the project.
60
+ return new _server.ExpoResponse("<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>" + error.message + "<br/><br/>" + staticError.message + "</span>", {
61
+ status: 500,
62
+ headers: {
63
+ "Content-Type": "text/html"
64
+ }
65
+ });
66
+ }
67
+ }
68
+ },
69
+ logApiRouteExecutionError (error) {
70
+ (0, _metroErrorInterface).logMetroError(projectRoot, {
71
+ error
72
+ });
73
+ },
74
+ async getApiRoute (route) {
75
+ const resolvedFunctionPath = await resolveAsync(route.page, {
76
+ extensions: [
77
+ ".js",
78
+ ".jsx",
79
+ ".ts",
80
+ ".tsx"
81
+ ],
82
+ basedir: options.appDir
83
+ });
84
+ const middlewareContents = await (0, _bundleApiRoutes).bundleApiRoute(projectRoot, resolvedFunctionPath, options);
85
+ if (!middlewareContents) {
86
+ // TODO: Error handling
87
+ return null;
88
+ }
89
+ try {
90
+ debug(`Bundling middleware at: ${resolvedFunctionPath}`);
91
+ return (0, _requireFromString).default(middlewareContents);
92
+ } catch (error) {
93
+ if (error instanceof Error) {
94
+ await (0, _metroErrorInterface).logMetroErrorAsync({
95
+ projectRoot,
96
+ error
97
+ });
98
+ } else {
99
+ _log.Log.error("Failed to load middleware: " + error);
100
+ }
101
+ return new _server.ExpoResponse("Failed to load middleware: " + resolvedFunctionPath + "\n\n" + error.message, {
102
+ status: 500,
103
+ headers: {
104
+ "Content-Type": "text/html"
105
+ }
106
+ });
107
+ }
108
+ }
109
+ });
110
+ }
111
+
112
+ //# sourceMappingURL=createServerRouteMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/createServerRouteMiddleware.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 { ExpoResponse } from '@expo/server';\nimport { createRequestHandler } from '@expo/server/build/vendor/http';\nimport requireString from 'require-from-string';\nimport resolve from 'resolve';\nimport { promisify } from 'util';\n\nimport { ForwardHtmlError } from './MetroBundlerDevServer';\nimport { bundleApiRoute } from './bundleApiRoutes';\nimport { fetchManifest } from './fetchRouterManifest';\nimport { getErrorOverlayHtmlAsync, logMetroError, logMetroErrorAsync } from './metroErrorInterface';\nimport { Log } from '../../../log';\n\nconst debug = require('debug')('expo:start:server:metro') as typeof console.log;\n\nconst resolveAsync = promisify(resolve) as any as (\n id: string,\n opts: resolve.AsyncOpts\n) => Promise<string | null>;\n\nexport function createRouteHandlerMiddleware(\n projectRoot: string,\n options: {\n mode?: string;\n appDir: string;\n port?: number;\n getWebBundleUrl: () => string;\n getStaticPageAsync: (pathname: string) => Promise<{ content: string }>;\n }\n) {\n return createRequestHandler(\n { build: '' },\n {\n async getRoutesManifest() {\n const manifest = await fetchManifest<RegExp>(projectRoot, options);\n debug('manifest', manifest);\n // NOTE: no app dir if null\n // TODO: Redirect to 404 page\n return manifest;\n },\n async getHtml(request) {\n try {\n const { content } = await options.getStaticPageAsync(request.url);\n return content;\n } catch (error: any) {\n // Forward the Metro server response as-is. It won't be pretty, but at least it will be accurate.\n if (error instanceof ForwardHtmlError) {\n return new ExpoResponse(error.html, {\n status: error.statusCode,\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n }\n\n try {\n return new ExpoResponse(\n await getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n }),\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n } catch (staticError: any) {\n // Fallback error for when Expo Router is misconfigured in the project.\n return new ExpoResponse(\n '<span><h3>Internal Error:</h3><b>Project is not setup correctly for static rendering (check terminal for more info):</b><br/>' +\n error.message +\n '<br/><br/>' +\n staticError.message +\n '</span>',\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n }\n },\n logApiRouteExecutionError(error) {\n logMetroError(projectRoot, { error });\n },\n async getApiRoute(route) {\n const resolvedFunctionPath = await resolveAsync(route.page, {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n basedir: options.appDir,\n });\n\n const middlewareContents = await bundleApiRoute(\n projectRoot,\n resolvedFunctionPath!,\n options\n );\n if (!middlewareContents) {\n // TODO: Error handling\n return null;\n }\n\n try {\n debug(`Bundling middleware at: ${resolvedFunctionPath}`);\n return requireString(middlewareContents);\n } catch (error: any) {\n if (error instanceof Error) {\n await logMetroErrorAsync({ projectRoot, error });\n } else {\n Log.error('Failed to load middleware: ' + error);\n }\n return new ExpoResponse(\n 'Failed to load middleware: ' + resolvedFunctionPath + '\\n\\n' + error.message,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n }\n );\n }\n },\n }\n );\n}\n"],"names":["createRouteHandlerMiddleware","debug","require","resolveAsync","promisify","resolve","projectRoot","options","createRequestHandler","build","getRoutesManifest","manifest","fetchManifest","getHtml","request","content","getStaticPageAsync","url","error","ForwardHtmlError","ExpoResponse","html","status","statusCode","headers","getErrorOverlayHtmlAsync","staticError","message","logApiRouteExecutionError","logMetroError","getApiRoute","route","resolvedFunctionPath","page","extensions","basedir","appDir","middlewareContents","bundleApiRoute","requireString","Error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