@expo/cli 1.0.0-canary-20250729-d8899ae → 54.0.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 (101) hide show
  1. package/build/bin/cli +1 -1
  2. package/build/metro-require/require.js +24 -13
  3. package/build/src/api/getExpoSchema.js +8 -7
  4. package/build/src/api/getExpoSchema.js.map +1 -1
  5. package/build/src/expoUpdatesExports.js +28 -0
  6. package/build/src/expoUpdatesExports.js.map +1 -0
  7. package/build/src/export/embed/exportEmbedAsync.js +4 -2
  8. package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
  9. package/build/src/export/exportApp.js +7 -4
  10. package/build/src/export/exportApp.js.map +1 -1
  11. package/build/src/export/exportAssets.js +20 -4
  12. package/build/src/export/exportAssets.js.map +1 -1
  13. package/build/src/export/exportHermes.js +34 -9
  14. package/build/src/export/exportHermes.js.map +1 -1
  15. package/build/src/export/exportStaticAsync.js +19 -2
  16. package/build/src/export/exportStaticAsync.js.map +1 -1
  17. package/build/src/export/index.js +1 -0
  18. package/build/src/export/index.js.map +1 -1
  19. package/build/src/export/resolveOptions.js +1 -0
  20. package/build/src/export/resolveOptions.js.map +1 -1
  21. package/build/src/export/saveAssets.js +12 -0
  22. package/build/src/export/saveAssets.js.map +1 -1
  23. package/build/src/install/checkPackages.js +9 -1
  24. package/build/src/install/checkPackages.js.map +1 -1
  25. package/build/src/lint/lintAsync.js +2 -0
  26. package/build/src/lint/lintAsync.js.map +1 -1
  27. package/build/src/prebuild/prebuildAsync.js +18 -0
  28. package/build/src/prebuild/prebuildAsync.js.map +1 -1
  29. package/build/src/prebuild/resolveLocalTemplate.js +42 -0
  30. package/build/src/prebuild/resolveLocalTemplate.js.map +1 -0
  31. package/build/src/prebuild/resolveTemplate.js +17 -7
  32. package/build/src/prebuild/resolveTemplate.js.map +1 -1
  33. package/build/src/prebuild/updateFromTemplate.js +1 -0
  34. package/build/src/prebuild/updateFromTemplate.js.map +1 -1
  35. package/build/src/prebuild/updatePackageJson.js +5 -3
  36. package/build/src/prebuild/updatePackageJson.js.map +1 -1
  37. package/build/src/run/android/resolveOptions.js +2 -2
  38. package/build/src/run/android/resolveOptions.js.map +1 -1
  39. package/build/src/run/ios/options/resolveOptions.js +2 -2
  40. package/build/src/run/ios/options/resolveOptions.js.map +1 -1
  41. package/build/src/run/ios/runIosAsync.js +3 -0
  42. package/build/src/run/ios/runIosAsync.js.map +1 -1
  43. package/build/src/serve/serveAsync.js +5 -2
  44. package/build/src/serve/serveAsync.js.map +1 -1
  45. package/build/src/start/platforms/ExpoGoInstaller.js +1 -1
  46. package/build/src/start/platforms/ExpoGoInstaller.js.map +1 -1
  47. package/build/src/start/server/DevToolsPluginManager.js +7 -35
  48. package/build/src/start/server/DevToolsPluginManager.js.map +1 -1
  49. package/build/src/start/server/metro/MetroBundlerDevServer.js +68 -29
  50. package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
  51. package/build/src/start/server/metro/MetroTerminalReporter.js +63 -18
  52. package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
  53. package/build/src/start/server/metro/createExpoAutolinkingResolver.js +121 -0
  54. package/build/src/start/server/metro/createExpoAutolinkingResolver.js.map +1 -0
  55. package/build/src/start/server/metro/createServerComponentsMiddleware.js +4 -4
  56. package/build/src/start/server/metro/createServerComponentsMiddleware.js.map +1 -1
  57. package/build/src/start/server/metro/createServerRouteMiddleware.js +54 -8
  58. package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -1
  59. package/build/src/start/server/metro/dev-server/createMetroMiddleware.js +1 -1
  60. package/build/src/start/server/metro/dev-server/createMetroMiddleware.js.map +1 -1
  61. package/build/src/start/server/metro/fetchRouterManifest.js +1 -0
  62. package/build/src/start/server/metro/fetchRouterManifest.js.map +1 -1
  63. package/build/src/start/server/metro/instantiateMetro.js +20 -18
  64. package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
  65. package/build/src/start/server/metro/metroErrorInterface.js +20 -13
  66. package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
  67. package/build/src/start/server/metro/router.js +75 -0
  68. package/build/src/start/server/metro/router.js.map +1 -1
  69. package/build/src/start/server/metro/serializeHtml.js +45 -5
  70. package/build/src/start/server/metro/serializeHtml.js.map +1 -1
  71. package/build/src/start/server/metro/withMetroErrorReportingResolver.js +267 -0
  72. package/build/src/start/server/metro/withMetroErrorReportingResolver.js.map +1 -0
  73. package/build/src/start/server/metro/withMetroMultiPlatform.js +50 -35
  74. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
  75. package/build/src/start/server/metro/withMetroResolvers.js +0 -176
  76. package/build/src/start/server/metro/withMetroResolvers.js.map +1 -1
  77. package/build/src/start/server/metro/withMetroSupervisingTransformWorker.js +63 -0
  78. package/build/src/start/server/metro/withMetroSupervisingTransformWorker.js.map +1 -0
  79. package/build/src/start/server/middleware/createBuiltinAPIRequestHandler.js +1 -1
  80. package/build/src/start/server/middleware/createBuiltinAPIRequestHandler.js.map +1 -1
  81. package/build/src/start/server/middleware/metroOptions.js +7 -2
  82. package/build/src/start/server/middleware/metroOptions.js.map +1 -1
  83. package/build/src/start/server/serverLogLikeMetro.js +13 -11
  84. package/build/src/start/server/serverLogLikeMetro.js.map +1 -1
  85. package/build/src/utils/build-cache-providers/index.js.map +1 -1
  86. package/build/src/utils/dir.js +7 -0
  87. package/build/src/utils/dir.js.map +1 -1
  88. package/build/src/utils/env.js +3 -1
  89. package/build/src/utils/env.js.map +1 -1
  90. package/build/src/utils/errors.js +1 -1
  91. package/build/src/utils/errors.js.map +1 -1
  92. package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
  93. package/build/src/utils/telemetry/utils/context.js +1 -1
  94. package/internal/unstable-expo-updates-exports.d.ts +31 -0
  95. package/internal/unstable-expo-updates-exports.js +3 -0
  96. package/package.json +33 -18
  97. package/static/template/[...rsc]+api.ts +1 -1
  98. package/build/src/start/server/metro/createExpoStickyResolver.js +0 -137
  99. package/build/src/start/server/metro/createExpoStickyResolver.js.map +0 -1
  100. package/build/src/utils/jsonSchemaDeref.js +0 -150
  101. package/build/src/utils/jsonSchemaDeref.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/metroErrorInterface.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 { getMetroServerRoot } from '@expo/config/paths';\nimport chalk from 'chalk';\nimport { stripVTControlCharacters } from 'node:util';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\nimport { parse, StackFrame } from 'stacktrace-parser';\nimport terminalLink from 'terminal-link';\n\nimport { LogBoxLog } from './log-box/LogBoxLog';\nimport type { CodeFrame, StackFrame as MetroStackFrame } from './log-box/LogBoxSymbolication';\nimport { getStackFormattedLocation } from './log-box/formatProjectFilePath';\nimport { Log } from '../../../log';\nimport { stripAnsi } from '../../../utils/ansi';\nimport { env } from '../../../utils/env';\nimport { CommandError, SilentError } from '../../../utils/errors';\nimport { createMetroEndpointAsync } from '../getStaticRenderFunctions';\n\nconst isDebug = require('debug').enabled('expo:start:server:metro');\n\nfunction fill(width: number): string {\n return Array(width).join(' ');\n}\n\nfunction formatPaths(config: { filePath: string | null; line?: number; col?: number }) {\n const filePath = chalk.reset(config.filePath);\n return (\n chalk.dim('(') +\n filePath +\n chalk.dim(`:${[config.line, config.col].filter(Boolean).join(':')})`)\n );\n}\n\nexport async function logMetroErrorWithStack(\n projectRoot: string,\n {\n stack,\n codeFrame,\n error,\n }: {\n stack: MetroStackFrame[];\n codeFrame?: CodeFrame;\n error: Error;\n }\n) {\n if (error instanceof SilentError) {\n return;\n }\n\n // process.stdout.write('\\u001b[0m'); // Reset attributes\n // process.stdout.write('\\u001bc'); // Reset the terminal\n\n Log.log();\n Log.log(chalk.red('Metro error: ') + error.message);\n Log.log();\n\n if (error instanceof CommandError) {\n return;\n }\n\n Log.log(\n getStackAsFormattedLog(projectRoot, { stack, codeFrame, error, showCollapsedFrames: true })\n );\n}\n\nexport function getStackAsFormattedLog(\n projectRoot: string,\n {\n stack,\n codeFrame,\n error,\n showCollapsedFrames = env.EXPO_DEBUG,\n }: {\n stack: MetroStackFrame[];\n codeFrame?: CodeFrame;\n error?: Error;\n showCollapsedFrames?: boolean;\n }\n): string {\n const logs: string[] = [];\n let hasCodeFramePresented = false;\n const containsCodeFrame = likelyContainsCodeFrame(error?.message);\n\n if (containsCodeFrame) {\n // Some transformation errors will have a code frame embedded in the error message\n // from Babel and we should not duplicate it as message is already printed before this call.\n hasCodeFramePresented = true;\n } else if (codeFrame) {\n const maxWarningLineLength = Math.max(800, process.stdout.columns);\n\n const lineText = codeFrame.content;\n const isPreviewTooLong = codeFrame.content\n .split('\\n')\n .some((line) => line.length > maxWarningLineLength);\n const column = codeFrame.location?.column;\n // When the preview is too long, we skip reading the file and attempting to apply\n // code coloring, this is because it can get very slow.\n if (isPreviewTooLong) {\n let previewLine = '';\n let cursorLine = '';\n\n const formattedPath = formatPaths({\n filePath: codeFrame.fileName,\n line: codeFrame.location?.row,\n col: codeFrame.location?.column,\n });\n // Create a curtailed preview line like:\n // `...transition:'fade'},k._updatePropsStack=function(){clearImmediate(k._updateImmediate),k._updateImmediate...`\n // If there is no text preview or column number, we can't do anything.\n if (lineText && column != null) {\n const rangeWindow = Math.round(\n Math.max(codeFrame.fileName?.length ?? 0, Math.max(80, process.stdout.columns)) / 2\n );\n let minBounds = Math.max(0, column - rangeWindow);\n const maxBounds = Math.min(minBounds + rangeWindow * 2, lineText.length);\n previewLine = lineText.slice(minBounds, maxBounds);\n\n // If we splice content off the start, then we should append `...`.\n // This is unlikely to happen since we limit the activation size.\n if (minBounds > 0) {\n // Adjust the min bounds so the cursor is aligned after we add the \"...\"\n minBounds -= 3;\n previewLine = chalk.dim('...') + previewLine;\n }\n if (maxBounds < lineText.length) {\n previewLine += chalk.dim('...');\n }\n\n // If the column property could be found, then use that to fix the cursor location which is often broken in regex.\n cursorLine = (column == null ? '' : fill(column) + chalk.reset('^')).slice(minBounds);\n\n logs.push(formattedPath, '', previewLine, cursorLine, chalk.dim('(error truncated)'));\n hasCodeFramePresented = true;\n }\n } else {\n logs.push(codeFrame.content);\n hasCodeFramePresented = true;\n }\n }\n\n if (stack?.length) {\n const stackProps = stack.map((frame) => {\n return {\n title: frame.methodName,\n subtitle: getStackFormattedLocation(projectRoot, frame),\n collapse: frame.collapse,\n };\n });\n\n const stackLines: string[] = [];\n const backupStackLines: string[] = [];\n\n stackProps.forEach((frame) => {\n const shouldShow = !frame.collapse || showCollapsedFrames;\n\n const position = terminalLink.isSupported\n ? terminalLink(frame.subtitle, frame.subtitle)\n : frame.subtitle;\n let lineItem = chalk.gray(` ${frame.title} (${position})`);\n\n if (frame.collapse) {\n lineItem = chalk.dim(lineItem);\n }\n // Never show the internal module system.\n const isMetroRuntime =\n /\\/metro-runtime\\/src\\/polyfills\\/require\\.js/.test(frame.subtitle) ||\n /\\/metro-require\\/require\\.js/.test(frame.subtitle);\n if (!isMetroRuntime) {\n if (shouldShow) {\n stackLines.push(lineItem);\n }\n backupStackLines.push(lineItem);\n }\n });\n\n if (hasCodeFramePresented) {\n logs.push('');\n }\n logs.push(chalk.bold`Call Stack`);\n\n if (!backupStackLines.length) {\n logs.push(chalk.gray(' No stack trace available.'));\n } else {\n // If there are not stack lines then it means the error likely happened in the node modules, in this case we should fallback to showing all the\n // the stacks to give the user whatever help we can.\n const displayStack = stackLines.length ? stackLines : backupStackLines;\n logs.push(displayStack.join('\\n'));\n }\n } else if (error && error.stack) {\n logs.push(chalk.gray(` ${error.stack}`));\n }\n return logs.join('\\n');\n}\n\nexport const IS_METRO_BUNDLE_ERROR_SYMBOL = Symbol('_isMetroBundleError');\nconst HAS_LOGGED_SYMBOL = Symbol('_hasLoggedInCLI');\n\nexport async function logMetroError(\n projectRoot: string,\n {\n error,\n }: {\n error: Error & {\n [HAS_LOGGED_SYMBOL]?: boolean;\n };\n }\n) {\n if (error instanceof SilentError || error[HAS_LOGGED_SYMBOL]) {\n return;\n }\n error[HAS_LOGGED_SYMBOL] = true;\n\n const stack = parseErrorStack(projectRoot, error.stack);\n\n const log = new LogBoxLog({\n level: 'static',\n message: {\n content: error.message,\n substitutions: [],\n },\n isComponentError: false,\n stack,\n category: 'static',\n componentStack: [],\n });\n\n await new Promise((res) => log.symbolicate('stack', res));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n}\n\nfunction isTransformError(\n error: any\n): error is { type: 'TransformError'; filename: string; lineNumber: number; column: number } {\n return error.type === 'TransformError';\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nfunction logFromError({ error, projectRoot }: { error: Error; projectRoot: string }) {\n // Remap direct Metro Node.js errors to a format that will appear more client-friendly in the logbox UI.\n let stack: MetroStackFrame[] | undefined;\n if (isTransformError(error) && error.filename) {\n // Syntax errors in static rendering.\n stack = [\n {\n file: path.join(projectRoot, error.filename),\n methodName: '<unknown>',\n arguments: [],\n // TODO: Import stack\n lineNumber: error.lineNumber,\n column: error.column,\n },\n ];\n } else if ('originModulePath' in error && typeof error.originModulePath === 'string') {\n // TODO: Use import stack here when the error is resolution based.\n stack = [\n {\n file: error.originModulePath,\n methodName: '<unknown>',\n arguments: [],\n // TODO: Import stack\n lineNumber: 0,\n column: 0,\n },\n ];\n } else {\n stack = parseErrorStack(projectRoot, error.stack);\n }\n\n return new LogBoxLog({\n level: 'static',\n message: {\n content: error.message,\n substitutions: [],\n },\n isComponentError: false,\n stack,\n category: 'static',\n componentStack: [],\n });\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nexport async function logMetroErrorAsync({\n error,\n projectRoot,\n}: {\n error: Error;\n projectRoot: string;\n}) {\n const log = logFromError({ projectRoot, error });\n\n await new Promise<void>((res) => log.symbolicate('stack', () => res()));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nexport async function getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot,\n}: {\n error: Error;\n projectRoot: string;\n routerRoot: string;\n}) {\n const log = logFromError({ projectRoot, error });\n\n await new Promise<void>((res) => log.symbolicate('stack', () => res()));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n\n if ('message' in log && 'content' in log.message && typeof log.message.content === 'string') {\n log.message.content = stripAnsi(log.message.content)!;\n }\n\n const logBoxContext = {\n selectedLogIndex: 0,\n isDisabled: false,\n logs: [log],\n };\n const html = `<html><head><style>#root,body,html{height:100%}body{overflow:hidden}#root{display:flex}</style></head><body><div id=\"root\"></div><script id=\"_expo-static-error\" type=\"application/json\">${JSON.stringify(\n logBoxContext\n )}</script></body></html>`;\n\n const errorOverlayEntry = await createMetroEndpointAsync(\n projectRoot,\n // Keep the URL relative\n '',\n resolveFrom(projectRoot, 'expo-router/_error'),\n {\n mode: 'development',\n platform: 'web',\n minify: false,\n optimize: false,\n usedExports: false,\n baseUrl: '',\n routerRoot,\n isExporting: false,\n reactCompiler: false,\n }\n );\n\n const htmlWithJs = html.replace('</body>', `<script src=${errorOverlayEntry}></script></body>`);\n return htmlWithJs;\n}\n\nfunction parseErrorStack(\n projectRoot: string,\n stack?: string\n): (StackFrame & { collapse?: boolean })[] {\n if (stack == null) {\n return [];\n }\n if (Array.isArray(stack)) {\n return stack;\n }\n\n const serverRoot = getMetroServerRoot(projectRoot);\n\n return parse(stack)\n .map((frame) => {\n // frame.file will mostly look like `http://localhost:8081/index.bundle?platform=web&dev=true&hot=false`\n\n if (frame.file) {\n // SSR will sometimes have absolute paths followed by `.bundle?...`, we need to try and make them relative paths and append a dev server URL.\n if (frame.file.startsWith('/') && frame.file.includes('bundle?') && !canParse(frame.file)) {\n // Malformed stack file from SSR. Attempt to repair.\n frame.file = 'https://localhost:8081/' + path.relative(serverRoot, frame.file);\n }\n }\n\n return {\n ...frame,\n column: frame.column != null ? frame.column - 1 : null,\n };\n })\n .filter((frame) => frame.file && !frame.file.includes('node_modules'));\n}\n\nfunction canParse(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function dropStackIfContainsCodeFrame(err: unknown) {\n if (!(err instanceof Error)) return;\n\n if (likelyContainsCodeFrame(err.message)) {\n // If the error message contains a code frame, we should drop the stack to avoid cluttering the output.\n delete err.stack;\n }\n}\n\n/**\n * Tests given string on presence of ` [num] |` at the start of any line.\n * Returns `false` for undefined or empty strings.\n */\nexport function likelyContainsCodeFrame(message: string | undefined): boolean {\n if (!message) return false;\n\n const clean = stripVTControlCharacters(message);\n if (!clean) return false;\n\n return /^\\s*\\d+\\s+\\|/m.test(clean);\n}\n\n/**\n * Walks thru the error cause chain and attaches the import stack to the root error message.\n * Removes the error stack for import and syntax errors.\n */\nexport const attachImportStackToRootMessage = (err: unknown) => {\n if (!(err instanceof Error)) return;\n\n // Space out build failures.\n const nearestImportStackValue = nearestImportStack(err);\n if (nearestImportStackValue) {\n err.message += '\\n\\n' + nearestImportStackValue;\n\n if (!isDebug) {\n // When not debugging remove the stack to avoid cluttering the output and confusing users,\n // the import stack is the guide to fixing the error.\n delete err.stack;\n }\n }\n};\n\n/**\n * Walks thru the error cause chain and returns the nearest import stack.\n * If the import stack is not found, it returns `undefined`.\n */\nexport const nearestImportStack = (err: unknown, root: unknown = err): string | undefined => {\n if (!(err instanceof Error) || !(root instanceof Error)) return undefined;\n\n if ('_expoImportStack' in err && typeof err._expoImportStack === 'string') {\n // Space out build failures.\n return err._expoImportStack;\n } else {\n return nearestImportStack(err.cause, root);\n }\n};\n"],"names":["IS_METRO_BUNDLE_ERROR_SYMBOL","attachImportStackToRootMessage","dropStackIfContainsCodeFrame","getErrorOverlayHtmlAsync","getStackAsFormattedLog","likelyContainsCodeFrame","logMetroError","logMetroErrorAsync","logMetroErrorWithStack","nearestImportStack","isDebug","require","enabled","fill","width","Array","join","formatPaths","config","filePath","chalk","reset","dim","line","col","filter","Boolean","projectRoot","stack","codeFrame","error","SilentError","Log","log","red","message","CommandError","showCollapsedFrames","env","EXPO_DEBUG","logs","hasCodeFramePresented","containsCodeFrame","maxWarningLineLength","Math","max","process","stdout","columns","lineText","content","isPreviewTooLong","split","some","length","column","location","previewLine","cursorLine","formattedPath","fileName","row","rangeWindow","round","minBounds","maxBounds","min","slice","push","stackProps","map","frame","title","methodName","subtitle","getStackFormattedLocation","collapse","stackLines","backupStackLines","forEach","shouldShow","position","terminalLink","isSupported","lineItem","gray","isMetroRuntime","test","bold","displayStack","Symbol","HAS_LOGGED_SYMBOL","parseErrorStack","LogBoxLog","level","substitutions","isComponentError","category","componentStack","Promise","res","symbolicate","symbolicated","isTransformError","type","logFromError","filename","file","path","arguments","lineNumber","originModulePath","routerRoot","stripAnsi","logBoxContext","selectedLogIndex","isDisabled","html","JSON","stringify","errorOverlayEntry","createMetroEndpointAsync","resolveFrom","mode","platform","minify","optimize","usedExports","baseUrl","isExporting","reactCompiler","htmlWithJs","replace","isArray","serverRoot","getMetroServerRoot","parse","startsWith","includes","canParse","relative","url","URL","err","Error","clean","stripVTControlCharacters","nearestImportStackValue","root","undefined","_expoImportStack","cause"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;IAkMYA,4BAA4B;eAA5BA;;IA2OAC,8BAA8B;eAA9BA;;IA1BGC,4BAA4B;eAA5BA;;IAjGMC,wBAAwB;eAAxBA;;IAjPNC,sBAAsB;eAAtBA;;IA+VAC,uBAAuB;eAAvBA;;IA3NMC,aAAa;eAAbA;;IA0FAC,kBAAkB;eAAlBA;;IA9PAC,sBAAsB;eAAtBA;;IAgaTC,kBAAkB;eAAlBA;;;;yBAhcsB;;;;;;;gEACjB;;;;;;;yBACuB;;;;;;;gEACxB;;;;;;;gEACO;;;;;;;yBACU;;;;;;;gEACT;;;;;;2BAEC;uCA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AAAA,oCAAwB,EAAC/G;IACvC,IAAI,CAAC8G,OAAO,OAAO;IAEnB,OAAO,gBAAgB1D,IAAI,CAAC0D;AAC9B;AAMO,MAAMhJ,iCAAiC,CAAC8I;IAC7C,IAAI,CAAEA,CAAAA,eAAeC,KAAI,GAAI;IAE7B,4BAA4B;IAC5B,MAAMG,0BAA0B1I,mBAAmBsI;IACnD,IAAII,yBAAyB;QAC3BJ,IAAI5G,OAAO,IAAI,SAASgH;QAExB,IAAI,CAACzI,SAAS;YACZ,0FAA0F;YAC1F,qDAAqD;YACrD,OAAOqI,IAAInH,KAAK;QAClB;IACF;AACF;AAMO,MAAMnB,qBAAqB,CAACsI,KAAcK,OAAgBL,GAAG;IAClE,IAAI,CAAEA,CAAAA,eAAeC,KAAI,KAAM,CAAEI,CAAAA,gBAAgBJ,KAAI,GAAI,OAAOK;IAEhE,IAAI,sBAAsBN,OAAO,OAAOA,IAAIO,gBAAgB,KAAK,UAAU;QACzE,4BAA4B;QAC5B,OAAOP,IAAIO,gBAAgB;IAC7B,OAAO;QACL,OAAO7I,mBAAmBsI,IAAIQ,KAAK,EAAEH;IACvC;AACF"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/metroErrorInterface.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 { getMetroServerRoot } from '@expo/config/paths';\nimport chalk from 'chalk';\nimport { stripVTControlCharacters } from 'node:util';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\nimport { parse, StackFrame } from 'stacktrace-parser';\nimport terminalLink from 'terminal-link';\n\nimport { LogBoxLog } from './log-box/LogBoxLog';\nimport type { CodeFrame, StackFrame as MetroStackFrame } from './log-box/LogBoxSymbolication';\nimport { getStackFormattedLocation } from './log-box/formatProjectFilePath';\nimport { Log } from '../../../log';\nimport { stripAnsi } from '../../../utils/ansi';\nimport { env } from '../../../utils/env';\nimport { CommandError, SilentError } from '../../../utils/errors';\nimport { createMetroEndpointAsync } from '../getStaticRenderFunctions';\n\nconst isDebug = require('debug').enabled('expo:start:server:metro');\n\nfunction fill(width: number): string {\n return Array(width).join(' ');\n}\n\nfunction formatPaths(config: { filePath: string | null; line?: number; col?: number }) {\n const filePath = chalk.reset(config.filePath);\n return (\n chalk.dim('(') +\n filePath +\n chalk.dim(`:${[config.line, config.col].filter(Boolean).join(':')})`)\n );\n}\n\nexport async function logMetroErrorWithStack(\n projectRoot: string,\n {\n stack,\n codeFrame,\n error,\n }: {\n stack: MetroStackFrame[];\n codeFrame?: CodeFrame;\n error: Error;\n }\n) {\n if (error instanceof SilentError) {\n return;\n }\n\n // process.stdout.write('\\u001b[0m'); // Reset attributes\n // process.stdout.write('\\u001bc'); // Reset the terminal\n\n Log.log();\n Log.log(chalk.red('Metro error: ') + error.message);\n Log.log();\n\n if (error instanceof CommandError) {\n return;\n }\n\n Log.log(\n getStackAsFormattedLog(projectRoot, { stack, codeFrame, error, showCollapsedFrames: true })\n .stack\n );\n}\n\nexport function getStackAsFormattedLog(\n projectRoot: string,\n {\n stack,\n codeFrame,\n error,\n showCollapsedFrames = env.EXPO_DEBUG,\n }: {\n stack: MetroStackFrame[];\n codeFrame?: CodeFrame;\n error?: Error;\n showCollapsedFrames?: boolean;\n }\n): {\n isFallback: boolean;\n stack: string;\n} {\n const logs: string[] = [];\n const containsCodeFrame = likelyContainsCodeFrame(error?.message);\n\n if (containsCodeFrame) {\n // Some transformation errors will have a code frame embedded in the error message\n // from Babel and we should not duplicate it as message is already printed before this call.\n } else if (codeFrame) {\n const maxWarningLineLength = Math.max(800, process.stdout.columns);\n\n const lineText = codeFrame.content;\n const lines = codeFrame.content.split('\\n');\n\n // ---- index.tsx ------------------------------------------------------\n // 32 | This is example code which will be under the title.\n const title = path.basename(codeFrame.fileName);\n logs.push(chalk.bold`Code: ${title}`);\n\n const isPreviewTooLong = lines.some((line) => line.length > maxWarningLineLength);\n const column = codeFrame.location?.column;\n // When the preview is too long, we skip reading the file and attempting to apply\n // code coloring, this is because it can get very slow.\n if (isPreviewTooLong) {\n let previewLine = '';\n let cursorLine = '';\n\n const formattedPath = formatPaths({\n filePath: codeFrame.fileName,\n line: codeFrame.location?.row,\n col: codeFrame.location?.column,\n });\n // Create a curtailed preview line like:\n // `...transition:'fade'},k._updatePropsStack=function(){clearImmediate(k._updateImmediate),k._updateImmediate...`\n // If there is no text preview or column number, we can't do anything.\n if (lineText && column != null) {\n const rangeWindow = Math.round(\n Math.max(codeFrame.fileName?.length ?? 0, Math.max(80, process.stdout.columns)) / 2\n );\n let minBounds = Math.max(0, column - rangeWindow);\n const maxBounds = Math.min(minBounds + rangeWindow * 2, lineText.length);\n previewLine = lineText.slice(minBounds, maxBounds);\n\n // If we splice content off the start, then we should append `...`.\n // This is unlikely to happen since we limit the activation size.\n if (minBounds > 0) {\n // Adjust the min bounds so the cursor is aligned after we add the \"...\"\n minBounds -= 3;\n previewLine = chalk.dim('...') + previewLine;\n }\n if (maxBounds < lineText.length) {\n previewLine += chalk.dim('...');\n }\n\n // If the column property could be found, then use that to fix the cursor location which is often broken in regex.\n cursorLine = (column == null ? '' : fill(column) + chalk.reset('^')).slice(minBounds);\n\n logs.push(formattedPath, '', previewLine, cursorLine, chalk.dim('(error truncated)'));\n }\n } else {\n logs.push(codeFrame.content);\n }\n }\n\n let isFallback = false;\n if (stack?.length) {\n const stackProps = stack.map((frame) => {\n return {\n title: frame.methodName,\n subtitle: getStackFormattedLocation(projectRoot, frame),\n collapse: frame.collapse || isInternalBytecode(frame),\n };\n });\n\n const stackLines: string[] = [];\n const backupStackLines: string[] = [];\n\n stackProps.forEach((frame) => {\n const shouldShow = !frame.collapse || showCollapsedFrames;\n\n const position = terminalLink.isSupported\n ? terminalLink(frame.subtitle, frame.subtitle)\n : frame.subtitle;\n let lineItem = chalk.gray(` ${frame.title} (${position})`);\n\n if (frame.collapse) {\n lineItem = chalk.dim(lineItem);\n }\n // Never show the internal module system.\n const isMetroRuntime =\n /\\/metro-runtime\\/src\\/polyfills\\/require\\.js/.test(frame.subtitle) ||\n /\\/metro-require\\/require\\.js/.test(frame.subtitle);\n if (!isMetroRuntime) {\n if (shouldShow) {\n stackLines.push(lineItem);\n }\n backupStackLines.push(lineItem);\n }\n });\n\n logs.push(chalk.bold`Call Stack`);\n\n if (!backupStackLines.length) {\n logs.push(chalk.gray(' No stack trace available.'));\n } else {\n isFallback = stackLines.length === 0;\n // If there are not stack lines then it means the error likely happened in the node modules, in this case we should fallback to showing all the\n // the stacks to give the user whatever help we can.\n const displayStack = stackLines.length ? stackLines : backupStackLines;\n logs.push(displayStack.join('\\n'));\n }\n } else if (error && error.stack) {\n logs.push(chalk.gray(` ${error.stack}`));\n }\n\n return {\n isFallback,\n stack: logs.join('\\n'),\n };\n}\n\nexport const IS_METRO_BUNDLE_ERROR_SYMBOL = Symbol('_isMetroBundleError');\nconst HAS_LOGGED_SYMBOL = Symbol('_hasLoggedInCLI');\n\nexport async function logMetroError(\n projectRoot: string,\n {\n error,\n }: {\n error: Error & {\n [HAS_LOGGED_SYMBOL]?: boolean;\n };\n }\n) {\n if (error instanceof SilentError || error[HAS_LOGGED_SYMBOL]) {\n return;\n }\n error[HAS_LOGGED_SYMBOL] = true;\n\n const stack = parseErrorStack(projectRoot, error.stack);\n\n const log = new LogBoxLog({\n level: 'static',\n message: {\n content: error.message,\n substitutions: [],\n },\n isComponentError: false,\n stack,\n category: 'static',\n componentStack: [],\n });\n\n await new Promise((res) => log.symbolicate('stack', res));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n}\n\nfunction isTransformError(\n error: any\n): error is { type: 'TransformError'; filename: string; lineNumber: number; column: number } {\n return error.type === 'TransformError';\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nfunction logFromError({ error, projectRoot }: { error: Error; projectRoot: string }) {\n // Remap direct Metro Node.js errors to a format that will appear more client-friendly in the logbox UI.\n let stack: MetroStackFrame[] | undefined;\n if (isTransformError(error) && error.filename) {\n // Syntax errors in static rendering.\n stack = [\n {\n file: path.join(projectRoot, error.filename),\n methodName: '<unknown>',\n arguments: [],\n // TODO: Import stack\n lineNumber: error.lineNumber,\n column: error.column,\n },\n ];\n } else if ('originModulePath' in error && typeof error.originModulePath === 'string') {\n // TODO: Use import stack here when the error is resolution based.\n stack = [\n {\n file: error.originModulePath,\n methodName: '<unknown>',\n arguments: [],\n // TODO: Import stack\n lineNumber: 0,\n column: 0,\n },\n ];\n } else {\n stack = parseErrorStack(projectRoot, error.stack);\n }\n\n return new LogBoxLog({\n level: 'static',\n message: {\n content: error.message,\n substitutions: [],\n },\n isComponentError: false,\n stack,\n category: 'static',\n componentStack: [],\n });\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nexport async function logMetroErrorAsync({\n error,\n projectRoot,\n}: {\n error: Error;\n projectRoot: string;\n}) {\n const log = logFromError({ projectRoot, error });\n\n await new Promise<void>((res) => log.symbolicate('stack', () => res()));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n}\n\n/** @returns the html required to render the static metro error as an SPA. */\nexport async function getErrorOverlayHtmlAsync({\n error,\n projectRoot,\n routerRoot,\n}: {\n error: Error;\n projectRoot: string;\n routerRoot: string;\n}) {\n const log = logFromError({ projectRoot, error });\n\n await new Promise<void>((res) => log.symbolicate('stack', () => res()));\n\n logMetroErrorWithStack(projectRoot, {\n stack: log.symbolicated?.stack?.stack ?? [],\n codeFrame: log.codeFrame,\n error,\n });\n\n if ('message' in log && 'content' in log.message && typeof log.message.content === 'string') {\n log.message.content = stripAnsi(log.message.content)!;\n }\n\n const logBoxContext = {\n selectedLogIndex: 0,\n isDisabled: false,\n logs: [log],\n };\n const html = `<html><head><style>#root,body,html{height:100%}body{overflow:hidden}#root{display:flex}</style></head><body><div id=\"root\"></div><script id=\"_expo-static-error\" type=\"application/json\">${JSON.stringify(\n logBoxContext\n )}</script></body></html>`;\n\n const errorOverlayEntry = await createMetroEndpointAsync(\n projectRoot,\n // Keep the URL relative\n '',\n resolveFrom(projectRoot, 'expo-router/_error'),\n {\n mode: 'development',\n platform: 'web',\n minify: false,\n optimize: false,\n usedExports: false,\n baseUrl: '',\n routerRoot,\n isExporting: false,\n reactCompiler: false,\n }\n );\n\n const htmlWithJs = html.replace('</body>', `<script src=${errorOverlayEntry}></script></body>`);\n return htmlWithJs;\n}\n\nfunction parseErrorStack(\n projectRoot: string,\n stack?: string\n): (StackFrame & { collapse?: boolean })[] {\n if (stack == null) {\n return [];\n }\n if (Array.isArray(stack)) {\n return stack;\n }\n\n const serverRoot = getMetroServerRoot(projectRoot);\n\n return parse(stack)\n .map((frame) => {\n // frame.file will mostly look like `http://localhost:8081/index.bundle?platform=web&dev=true&hot=false`\n\n if (frame.file) {\n // SSR will sometimes have absolute paths followed by `.bundle?...`, we need to try and make them relative paths and append a dev server URL.\n if (frame.file.startsWith('/') && frame.file.includes('bundle?') && !canParse(frame.file)) {\n // Malformed stack file from SSR. Attempt to repair.\n frame.file = 'https://localhost:8081/' + path.relative(serverRoot, frame.file);\n }\n }\n\n return {\n ...frame,\n column: frame.column != null ? frame.column - 1 : null,\n };\n })\n .filter((frame) => frame.file && !frame.file.includes('node_modules'));\n}\n\nfunction canParse(url: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function dropStackIfContainsCodeFrame(err: unknown) {\n if (!(err instanceof Error)) return;\n\n if (likelyContainsCodeFrame(err.message)) {\n // If the error message contains a code frame, we should drop the stack to avoid cluttering the output.\n delete err.stack;\n }\n}\n\n/**\n * Tests given string on presence of ` [num] |` at the start of any line.\n * Returns `false` for undefined or empty strings.\n */\nexport function likelyContainsCodeFrame(message: string | undefined): boolean {\n if (!message) return false;\n\n const clean = stripVTControlCharacters(message);\n if (!clean) return false;\n\n return /^\\s*\\d+\\s+\\|/m.test(clean);\n}\n\n/**\n * Walks thru the error cause chain and attaches the import stack to the root error message.\n * Removes the error stack for import and syntax errors.\n */\nexport const attachImportStackToRootMessage = (err: unknown) => {\n if (!(err instanceof Error)) return;\n\n // Space out build failures.\n const nearestImportStackValue = nearestImportStack(err);\n if (nearestImportStackValue) {\n err.message += '\\n\\n' + nearestImportStackValue;\n\n if (!isDebug) {\n // When not debugging remove the stack to avoid cluttering the output and confusing users,\n // the import stack is the guide to fixing the error.\n delete err.stack;\n }\n }\n};\n\n/**\n * Walks thru the error cause chain and returns the nearest import stack.\n * If the import stack is not found, it returns `undefined`.\n */\nexport const nearestImportStack = (err: unknown, root: unknown = err): string | undefined => {\n if (!(err instanceof Error) || !(root instanceof Error)) return undefined;\n\n if ('_expoImportStack' in err && typeof err._expoImportStack === 'string') {\n // Space out build failures.\n return err._expoImportStack;\n } else {\n return nearestImportStack(err.cause, root);\n }\n};\n\nfunction isInternalBytecode(frame: StackFrame): boolean {\n return frame.file?.includes('InternalBytecode.js') ?? false;\n}\n"],"names":["IS_METRO_BUNDLE_ERROR_SYMBOL","attachImportStackToRootMessage","dropStackIfContainsCodeFrame","getErrorOverlayHtmlAsync","getStackAsFormattedLog","likelyContainsCodeFrame","logMetroError","logMetroErrorAsync","logMetroErrorWithStack","nearestImportStack","isDebug","require","enabled","fill","width","Array","join","formatPaths","config","filePath","chalk","reset","dim","line","col","filter","Boolean","projectRoot","stack","codeFrame","error","SilentError","Log","log","red","message","CommandError","showCollapsedFrames","env","EXPO_DEBUG","logs","containsCodeFrame","maxWarningLineLength","Math","max","process","stdout","columns","lineText","content","lines","split","title","path","basename","fileName","push","bold","isPreviewTooLong","some","length","column","location","previewLine","cursorLine","formattedPath","row","rangeWindow","round","minBounds","maxBounds","min","slice","isFallback","stackProps","map","frame","methodName","subtitle","getStackFormattedLocation","collapse","isInternalBytecode","stackLines","backupStackLines","forEach","shouldShow","position","terminalLink","isSupported","lineItem","gray","isMetroRuntime","test","displayStack","Symbol","HAS_LOGGED_SYMBOL","parseErrorStack","LogBoxLog","level","substitutions","isComponentError","category","componentStack","Promise","res","symbolicate","symbolicated","isTransformError","type","logFromError","filename","file","arguments","lineNumber","originModulePath","routerRoot","stripAnsi","logBoxContext","selectedLogIndex","isDisabled","html","JSON","stringify","errorOverlayEntry","createMetroEndpointAsync","resolveFrom","mode","platform","minify","optimize","usedExports","baseUrl","isExporting","reactCompiler","htmlWithJs","replace","isArray","serverRoot","getMetroServerRoot","parse","startsWith","includes","canParse","relative","url","URL","err","Error","clean","stripVTControlCharacters","nearestImportStackValue","root","undefined","_expoImportStack","cause"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;IA0MYA,4BAA4B;eAA5BA;;IA2OAC,8BAA8B;eAA9BA;;IA1BGC,4BAA4B;eAA5BA;;IAjGMC,wBAAwB;eAAxBA;;IAxPNC,sBAAsB;eAAtBA;;IAsWAC,uBAAuB;eAAvBA;;IA3NMC,aAAa;eAAbA;;IA0FAC,kBAAkB;eAAlBA;;IAtQAC,sBAAsB;eAAtBA;;IAwaTC,kBAAkB;eAAlBA;;;;yBAxcsB;;;;;;;gEACjB;;;;;;;yBACuB;;;;;;;gEACxB;;;;;;;gEACO;;;;;;;yBACU;;;;;;;gEACT;;;;;;2BAEC;uCAEgB;qBACtB;sBACM;qBACN;wBACsB;0CACD;;;;;;AAEzC,MAAMC,UAAUC,QAAQ,SAASC,OAAO,CAAC;AAEzC,SAASC,KAAKC,KAAa;IACzB,OAAOC,MAAMD,OAAOE,IAAI,CAAC;AAC3B;AAEA,SAASC,YAAYC,MAAgE;IACnF,MAAMC,WAAWC,gBAAK,CAACC,KAAK,CAACH,OAAOC,QAAQ;IAC5C,OACEC,gBAAK,CAACE,GAAG,CAAC,OACVH,WACAC,gBAAK,CAACE,GAAG,CAAC,CAAC,CAAC,EAAE;QAACJ,OAAOK,IAAI;QAAEL,OAAOM,GAAG;KAAC,CAACC,MAAM,CAACC,SAASV,IAAI,CAAC,KAAK,CAAC,CAAC;AAExE;A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G,OAAO,IAAI,SAASmH;QAExB,IAAI,CAAC5I,SAAS;YACZ,0FAA0F;YAC1F,qDAAqD;YACrD,OAAOwI,IAAItH,KAAK;QAClB;IACF;AACF;AAMO,MAAMnB,qBAAqB,CAACyI,KAAcK,OAAgBL,GAAG;IAClE,IAAI,CAAEA,CAAAA,eAAeC,KAAI,KAAM,CAAEI,CAAAA,gBAAgBJ,KAAI,GAAI,OAAOK;IAEhE,IAAI,sBAAsBN,OAAO,OAAOA,IAAIO,gBAAgB,KAAK,UAAU;QACzE,4BAA4B;QAC5B,OAAOP,IAAIO,gBAAgB;IAC7B,OAAO;QACL,OAAOhJ,mBAAmByI,IAAIQ,KAAK,EAAEH;IACvC;AACF;AAEA,SAAStE,mBAAmBL,KAAiB;QACpCA;IAAP,OAAOA,EAAAA,cAAAA,MAAMmC,IAAI,qBAAVnC,YAAYiE,QAAQ,CAAC,2BAA0B;AACxD"}
@@ -15,6 +15,9 @@ _export(exports, {
15
15
  getAppRouterRelativeEntryPath: function() {
16
16
  return getAppRouterRelativeEntryPath;
17
17
  },
18
+ getMiddlewareForDirectory: function() {
19
+ return getMiddlewareForDirectory;
20
+ },
18
21
  getRoutePaths: function() {
19
22
  return getRoutePaths;
20
23
  },
@@ -27,9 +30,18 @@ _export(exports, {
27
30
  hasWarnedAboutApiRoutes: function() {
28
31
  return hasWarnedAboutApiRoutes;
29
32
  },
33
+ hasWarnedAboutMiddleware: function() {
34
+ return hasWarnedAboutMiddleware;
35
+ },
30
36
  isApiRouteConvention: function() {
31
37
  return isApiRouteConvention;
32
38
  },
39
+ warnInvalidMiddlewareMatcherSettings: function() {
40
+ return warnInvalidMiddlewareMatcherSettings;
41
+ },
42
+ warnInvalidMiddlewareOutput: function() {
43
+ return warnInvalidMiddlewareOutput;
44
+ },
33
45
  warnInvalidWebOutput: function() {
34
46
  return warnInvalidWebOutput;
35
47
  }
@@ -120,6 +132,22 @@ function getApiRoutesForDirectory(cwd) {
120
132
  dot: true
121
133
  });
122
134
  }
135
+ function getMiddlewareForDirectory(cwd) {
136
+ const files = (0, _glob().sync)('+middleware.@(ts|tsx|js|jsx)', {
137
+ cwd,
138
+ absolute: true,
139
+ dot: true
140
+ });
141
+ if (files.length === 0) return null;
142
+ if (files.length > 1) {
143
+ // In development, throw an error if there are multiple root-level middleware files
144
+ if (process.env.NODE_ENV !== 'production') {
145
+ const relativePaths = files.map((f)=>'./' + _path().default.relative(cwd, f)).sort();
146
+ throw new Error(`Only one middleware file is allowed. Keep one of the conflicting files: ${relativePaths.map((p)=>`"${p}"`).join(' or ')}`);
147
+ }
148
+ }
149
+ return files[0];
150
+ }
123
151
  function getRoutePaths(cwd) {
124
152
  return (0, _glob().sync)('**/*.@(ts|tsx|js|jsx)', {
125
153
  cwd,
@@ -130,14 +158,61 @@ function normalizePaths(p) {
130
158
  return p.replace(/\\/g, '/');
131
159
  }
132
160
  let hasWarnedAboutApiRouteOutput = false;
161
+ let hasWarnedAboutMiddlewareOutput = false;
133
162
  function hasWarnedAboutApiRoutes() {
134
163
  return hasWarnedAboutApiRouteOutput;
135
164
  }
165
+ function hasWarnedAboutMiddleware() {
166
+ return hasWarnedAboutMiddlewareOutput;
167
+ }
136
168
  function warnInvalidWebOutput() {
137
169
  if (!hasWarnedAboutApiRouteOutput) {
138
170
  _log.Log.warn(_chalk().default.yellow`Using API routes requires the {bold web.output} to be set to {bold "server"} in the project {bold app.json}. ${(0, _link.learnMore)('https://docs.expo.dev/router/reference/api-routes/')}`);
139
171
  }
140
172
  hasWarnedAboutApiRouteOutput = true;
141
173
  }
174
+ function warnInvalidMiddlewareOutput() {
175
+ if (!hasWarnedAboutMiddlewareOutput) {
176
+ _log.Log.warn(_chalk().default.yellow`Using middleware requires the {bold web.output} to be set to {bold "server"} in the project {bold app.json}. ${(0, _link.learnMore)('https://docs.expo.dev/router/reference/api-routes/')}`);
177
+ }
178
+ hasWarnedAboutMiddlewareOutput = true;
179
+ }
180
+ function warnInvalidMiddlewareMatcherSettings(matcher) {
181
+ const validMethods = [
182
+ 'GET',
183
+ 'POST',
184
+ 'PUT',
185
+ 'PATCH',
186
+ 'DELETE',
187
+ 'OPTIONS',
188
+ 'HEAD'
189
+ ];
190
+ // Ensure methods are valid HTTP methods
191
+ if (matcher.methods) {
192
+ if (!Array.isArray(matcher.methods)) {
193
+ _log.Log.error(_chalk().default.red`Middleware matcher methods must be an array of valid HTTP methods. Supported methods are: ${validMethods.join(', ')}`);
194
+ } else {
195
+ for (const method of matcher.methods){
196
+ if (!validMethods.includes(method)) {
197
+ _log.Log.error(_chalk().default.red`Invalid middleware HTTP method: ${method}. Supported methods are: ${validMethods.join(', ')}`);
198
+ }
199
+ }
200
+ }
201
+ }
202
+ // Ensure patterns are either a string or RegExp
203
+ if (matcher.patterns) {
204
+ const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [
205
+ matcher.patterns
206
+ ];
207
+ for (const pattern of patterns){
208
+ if (typeof pattern !== 'string' && !(pattern instanceof RegExp)) {
209
+ _log.Log.error(_chalk().default.red`Middleware matcher patterns must be strings or regular expressions. Received: ${String(pattern)}`);
210
+ }
211
+ if (typeof pattern === 'string' && !pattern.startsWith('/')) {
212
+ _log.Log.error(_chalk().default.red`String patterns in middleware matcher must start with '/'. Received: ${pattern}`);
213
+ }
214
+ }
215
+ }
216
+ }
142
217
 
143
218
  //# sourceMappingURL=router.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/router.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport chalk from 'chalk';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { Log } from '../../../log';\nimport { directoryExistsSync } from '../../../utils/dir';\nimport { toPosixPath } from '../../../utils/filePath';\nimport { learnMore } from '../../../utils/link';\n\nconst debug = require('debug')('expo:start:server:metro:router') as typeof console.log;\n\n/**\n * Get the relative path for requiring the `/app` folder relative to the `expo-router/entry` file.\n * This mechanism does require the server to restart after the `expo-router` package is installed.\n */\nexport function getAppRouterRelativeEntryPath(\n projectRoot: string,\n routerDirectory: string = getRouterDirectory(projectRoot)\n): string | undefined {\n // Auto pick App entry\n const routerEntry =\n resolveFrom.silent(projectRoot, 'expo-router/entry') ?? getFallbackEntryRoot(projectRoot);\n if (!routerEntry) {\n return undefined;\n }\n // It doesn't matter if the app folder exists.\n const appFolder = path.join(projectRoot, routerDirectory);\n const appRoot = path.relative(path.dirname(routerEntry), appFolder);\n debug('expo-router entry', routerEntry, appFolder, appRoot);\n return appRoot;\n}\n\n/** If the `expo-router` package is not installed, then use the `expo` package to determine where the node modules are relative to the project. */\nfunction getFallbackEntryRoot(projectRoot: string): string {\n const expoRoot = resolveFrom.silent(projectRoot, 'expo/package.json');\n if (expoRoot) {\n return path.join(path.dirname(path.dirname(expoRoot)), 'expo-router/entry');\n }\n return path.join(projectRoot, 'node_modules/expo-router/entry');\n}\n\nexport function getRouterDirectoryModuleIdWithManifest(\n projectRoot: string,\n exp: ExpoConfig\n): string {\n return toPosixPath(exp.extra?.router?.root ?? getRouterDirectory(projectRoot));\n}\n\nlet hasWarnedAboutSrcDir = false;\nconst logSrcDir = () => {\n if (hasWarnedAboutSrcDir) return;\n hasWarnedAboutSrcDir = true;\n Log.log(chalk.gray('Using src/app as the root directory for Expo Router.'));\n};\n\nexport function getRouterDirectory(projectRoot: string): string {\n // more specific directories first\n if (directoryExistsSync(path.join(projectRoot, 'src', 'app'))) {\n logSrcDir();\n return path.join('src', 'app');\n }\n\n debug('Using app as the root directory for Expo Router.');\n return 'app';\n}\n\nexport function isApiRouteConvention(name: string): boolean {\n return /\\+api\\.[tj]sx?$/.test(name);\n}\n\nexport function getApiRoutesForDirectory(cwd: string) {\n return globSync('**/*+api.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n}\n\n// Used to emulate a context module, but way faster. TODO: May need to adjust the extensions to stay in sync with Metro.\nexport function getRoutePaths(cwd: string) {\n return globSync('**/*.@(ts|tsx|js|jsx)', {\n cwd,\n dot: true,\n }).map((p) => './' + normalizePaths(p));\n}\n\nfunction normalizePaths(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\nlet hasWarnedAboutApiRouteOutput = false;\n\nexport function hasWarnedAboutApiRoutes() {\n return hasWarnedAboutApiRouteOutput;\n}\n\nexport function warnInvalidWebOutput() {\n if (!hasWarnedAboutApiRouteOutput) {\n Log.warn(\n chalk.yellow`Using API routes requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutApiRouteOutput = true;\n}\n"],"names":["getApiRoutesForDirectory","getAppRouterRelativeEntryPath","getRoutePaths","getRouterDirectory","getRouterDirectoryModuleIdWithManifest","hasWarnedAboutApiRoutes","isApiRouteConvention","warnInvalidWebOutput","debug","require","projectRoot","routerDirectory","routerEntry","resolveFrom","silent","getFallbackEntryRoot","undefined","appFolder","path","join","appRoot","relative","dirname","expoRoot","exp","toPosixPath","extra","router","root","hasWarnedAboutSrcDir","logSrcDir","Log","log","chalk","gray","directoryExistsSync","name","test","cwd","globSync","absolute","dot","map","p","normalizePaths","replace","hasWarnedAboutApiRouteOutput","warn","yellow","learnMore"],"mappings":";;;;;;;;;;;IAwEgBA,wBAAwB;eAAxBA;;IAvDAC,6BAA6B;eAA7BA;;IAgEAC,aAAa;eAAbA;;IAxBAC,kBAAkB;eAAlBA;;IAdAC,sCAAsC;eAAtCA;;IAmDAC,uBAAuB;eAAvBA;;IA1BAC,oBAAoB;eAApBA;;IA8BAC,oBAAoB;eAApBA;;;;gEAjGE;;;;;;;yBACe;;;;;;;gEAChB;;;;;;;gEACO;;;;;;qBAEJ;qBACgB;0BACR;sBACF;;;;;;AAE1B,MAAMC,QAAQC,QAAQ,SAAS;AAMxB,SAASR,8BACdS,WAAmB,EACnBC,kBAA0BR,mBAAmBO,YAAY;IAEzD,sBAAsB;IACtB,MAAME,cACJC,sBAAW,CAACC,MAAM,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B;QAC3CD;QACAE,UAAU;QACVC,KAAK;IACP;AACF;AAGO,SAASvC,cAAcoC,GAAW;IACvC,OAAOC,IAAAA,YAAQ,EAAC,yBAAyB;QACvCD;QACAG,KAAK;IACP,GAAGC,GAAG,CAAC,CAACC,IAAM,OAAOC,eAAeD;AACtC;AAEA,SAASC,eAAeD,CAAS;IAC/B,OAAOA,EAAEE,OAAO,CAAC,OAAO;AAC1B;AAEA,IAAIC,+BAA+B;AAE5B,SAASzC;IACd,OAAOyC;AACT;AAEO,SAASvC;IACd,IAAI,CAACuC,8BAA8B;QACjCf,QAAG,CAACgB,IAAI,CACNd,gBAAK,CAACe,MAAM,CAAC,6GAA6G,EAAEC,IAAAA,eAAS,EACnI,sDACA,CAAC;IAEP;IAEAH,+BAA+B;AACjC"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/router.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport type { MiddlewareMatcher } from '@expo/server/build/types';\nimport chalk from 'chalk';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { Log } from '../../../log';\nimport { directoryExistsSync } from '../../../utils/dir';\nimport { toPosixPath } from '../../../utils/filePath';\nimport { learnMore } from '../../../utils/link';\n\nconst debug = require('debug')('expo:start:server:metro:router') as typeof console.log;\n\n/**\n * Get the relative path for requiring the `/app` folder relative to the `expo-router/entry` file.\n * This mechanism does require the server to restart after the `expo-router` package is installed.\n */\nexport function getAppRouterRelativeEntryPath(\n projectRoot: string,\n routerDirectory: string = getRouterDirectory(projectRoot)\n): string | undefined {\n // Auto pick App entry\n const routerEntry =\n resolveFrom.silent(projectRoot, 'expo-router/entry') ?? getFallbackEntryRoot(projectRoot);\n if (!routerEntry) {\n return undefined;\n }\n // It doesn't matter if the app folder exists.\n const appFolder = path.join(projectRoot, routerDirectory);\n const appRoot = path.relative(path.dirname(routerEntry), appFolder);\n debug('expo-router entry', routerEntry, appFolder, appRoot);\n return appRoot;\n}\n\n/** If the `expo-router` package is not installed, then use the `expo` package to determine where the node modules are relative to the project. */\nfunction getFallbackEntryRoot(projectRoot: string): string {\n const expoRoot = resolveFrom.silent(projectRoot, 'expo/package.json');\n if (expoRoot) {\n return path.join(path.dirname(path.dirname(expoRoot)), 'expo-router/entry');\n }\n return path.join(projectRoot, 'node_modules/expo-router/entry');\n}\n\nexport function getRouterDirectoryModuleIdWithManifest(\n projectRoot: string,\n exp: ExpoConfig\n): string {\n return toPosixPath(exp.extra?.router?.root ?? getRouterDirectory(projectRoot));\n}\n\nlet hasWarnedAboutSrcDir = false;\nconst logSrcDir = () => {\n if (hasWarnedAboutSrcDir) return;\n hasWarnedAboutSrcDir = true;\n Log.log(chalk.gray('Using src/app as the root directory for Expo Router.'));\n};\n\nexport function getRouterDirectory(projectRoot: string): string {\n // more specific directories first\n if (directoryExistsSync(path.join(projectRoot, 'src', 'app'))) {\n logSrcDir();\n return path.join('src', 'app');\n }\n\n debug('Using app as the root directory for Expo Router.');\n return 'app';\n}\n\nexport function isApiRouteConvention(name: string): boolean {\n return /\\+api\\.[tj]sx?$/.test(name);\n}\n\nexport function getApiRoutesForDirectory(cwd: string) {\n return globSync('**/*+api.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n}\n\n/**\n * Gets the +middleware file for a given directory. In\n * @param cwd\n */\nexport function getMiddlewareForDirectory(cwd: string): string | null {\n const files = globSync('+middleware.@(ts|tsx|js|jsx)', {\n cwd,\n absolute: true,\n dot: true,\n });\n\n if (files.length === 0) return null;\n\n if (files.length > 1) {\n // In development, throw an error if there are multiple root-level middleware files\n if (process.env.NODE_ENV !== 'production') {\n const relativePaths = files.map((f) => './' + path.relative(cwd, f)).sort();\n throw new Error(\n `Only one middleware file is allowed. Keep one of the conflicting files: ${relativePaths.map((p) => `\"${p}\"`).join(' or ')}`\n );\n }\n }\n\n return files[0];\n}\n\n// Used to emulate a context module, but way faster. TODO: May need to adjust the extensions to stay in sync with Metro.\nexport function getRoutePaths(cwd: string) {\n return globSync('**/*.@(ts|tsx|js|jsx)', {\n cwd,\n dot: true,\n }).map((p) => './' + normalizePaths(p));\n}\n\nfunction normalizePaths(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\nlet hasWarnedAboutApiRouteOutput = false;\nlet hasWarnedAboutMiddlewareOutput = false;\n\nexport function hasWarnedAboutApiRoutes() {\n return hasWarnedAboutApiRouteOutput;\n}\n\nexport function hasWarnedAboutMiddleware() {\n return hasWarnedAboutMiddlewareOutput;\n}\n\nexport function warnInvalidWebOutput() {\n if (!hasWarnedAboutApiRouteOutput) {\n Log.warn(\n chalk.yellow`Using API routes requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutApiRouteOutput = true;\n}\n\nexport function warnInvalidMiddlewareOutput() {\n if (!hasWarnedAboutMiddlewareOutput) {\n Log.warn(\n chalk.yellow`Using middleware requires the {bold web.output} to be set to {bold \"server\"} in the project {bold app.json}. ${learnMore(\n 'https://docs.expo.dev/router/reference/api-routes/'\n )}`\n );\n }\n\n hasWarnedAboutMiddlewareOutput = true;\n}\n\nexport function warnInvalidMiddlewareMatcherSettings(matcher: MiddlewareMatcher) {\n const validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];\n\n // Ensure methods are valid HTTP methods\n if (matcher.methods) {\n if (!Array.isArray(matcher.methods)) {\n Log.error(\n chalk.red`Middleware matcher methods must be an array of valid HTTP methods. Supported methods are: ${validMethods.join(', ')}`\n );\n } else {\n for (const method of matcher.methods) {\n if (!validMethods.includes(method)) {\n Log.error(\n chalk.red`Invalid middleware HTTP method: ${method}. Supported methods are: ${validMethods.join(', ')}`\n );\n }\n }\n }\n }\n\n // Ensure patterns are either a string or RegExp\n if (matcher.patterns) {\n const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [matcher.patterns];\n for (const pattern of patterns) {\n if (typeof pattern !== 'string' && !(pattern instanceof RegExp)) {\n Log.error(\n chalk.red`Middleware matcher patterns must be strings or regular expressions. Received: ${String(\n pattern\n )}`\n );\n }\n\n if (typeof pattern === 'string' && !pattern.startsWith('/')) {\n Log.error(\n chalk.red`String patterns in middleware matcher must start with '/'. Received: ${pattern}`\n );\n }\n }\n }\n}\n"],"names":["getApiRoutesForDirectory","getAppRouterRelativeEntryPath","getMiddlewareForDirectory","getRoutePaths","getRouterDirectory","getRouterDirectoryModuleIdWithManifest","hasWarnedAboutApiRoutes","hasWarnedAboutMiddleware","isApiRouteConvention","warnInvalidMiddlewareMatcherSettings","warnInvalidMiddlewareOutput","warnInvalidWebOutput","debug","require","projectRoot","routerDirectory","routerEntry","resolveFrom","silent","getFallbackEntryRoot","undefined","appFolder","path","join","appRoot","relative","dirname","expoRoot","exp","toPosixPath","extra","router","root","hasWarnedAboutSrcDir","logSrcDir","Log","log","chalk","gray","directoryExistsSync","name","test","cwd","globSync","absolute","dot","files","length","process","env","NODE_ENV","relativePaths","map","f","sort","Error","p","normalizePaths","replace","hasWarnedAboutApiRouteOutput","hasWarnedAboutMiddlewareOutput","warn","yellow","learnMore","matcher","validMethods","methods","Array","isArray","error","red","method","includes","patterns","pattern","RegExp","String","startsWith"],"mappings":";;;;;;;;;;;IAyEgBA,wBAAwB;eAAxBA;;IAvDAC,6BAA6B;eAA7BA;;IAmEAC,yBAAyB;eAAzBA;;IAuBAC,aAAa;eAAbA;;IAlDAC,kBAAkB;eAAlBA;;IAdAC,sCAAsC;eAAtCA;;IA8EAC,uBAAuB;eAAvBA;;IAIAC,wBAAwB;eAAxBA;;IAzDAC,oBAAoB;eAApBA;;IAqFAC,oCAAoC;eAApCA;;IAZAC,2BAA2B;eAA3BA;;IAZAC,oBAAoB;eAApBA;;;;gEAhIE;;;;;;;yBACe;;;;;;;gEAChB;;;;;;;gEACO;;;;;;qBAEJ;qBACgB;0BACR;sBACF;;;;;;AAE1B,MAAMC,QAAQC,QAA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ACiC,GAAG,CAAC,qEAAqE,EAAEI,QAAQ,CAAC;YAE9F;QACF;IACF;AACF"}
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "serializeHtmlWithAssets", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ assetsRequiresSort: function() {
13
+ return assetsRequiresSort;
14
+ },
15
+ serializeHtmlWithAssets: function() {
8
16
  return serializeHtmlWithAssets;
9
17
  }
10
18
  });
@@ -52,8 +60,8 @@ function htmlFromSerialAssets(assets, { isExporting, template, baseUrl, bundleUr
52
60
  // External link tags will be passed through as-is.
53
61
  return source;
54
62
  }).join('');
55
- const jsAssets = assets.filter((asset)=>asset.type === 'js');
56
- const scripts = bundleUrl ? `<script src="${bundleUrl}" defer></script>` : jsAssets.map(({ filename, metadata })=>{
63
+ const orderedJsAssets = assetsRequiresSort(assets.filter((asset)=>asset.type === 'js'));
64
+ const scripts = bundleUrl ? `<script src="${bundleUrl}" defer></script>` : orderedJsAssets.map(({ filename, metadata })=>{
57
65
  // TODO: Mark dependencies of the HTML and include them to prevent waterfalls.
58
66
  if (metadata.isAsync) {
59
67
  // We have the data required to match async chunks to the route's HTML file.
@@ -79,5 +87,37 @@ function htmlFromSerialAssets(assets, { isExporting, template, baseUrl, bundleUr
79
87
  }
80
88
  return template.replace('</head>', `${styleString}</head>`).replace('</body>', `${scripts}\n</body>`);
81
89
  }
90
+ function assetsRequiresSort(assets) {
91
+ const lookup = new Map();
92
+ const visited = new Set();
93
+ const visiting = new Set();
94
+ const result = [];
95
+ assets.forEach((a)=>{
96
+ lookup.set(a.filename, a);
97
+ });
98
+ function visit(name) {
99
+ var _module_metadata_requires;
100
+ if (visited.has(name)) return;
101
+ if (visiting.has(name)) throw new Error(`Circular dependencies in assets are not allowed. Found cycle: ${[
102
+ ...visiting,
103
+ name
104
+ ].join(' -> ')}`);
105
+ visiting.add(name);
106
+ const module = lookup.get(name);
107
+ if (!module) throw new Error(`Asset not found: ${name}`);
108
+ (_module_metadata_requires = module.metadata.requires) == null ? void 0 : _module_metadata_requires.forEach((dependency)=>{
109
+ visit(dependency);
110
+ });
111
+ visiting.delete(name);
112
+ visited.add(name);
113
+ result.push(module);
114
+ }
115
+ assets.forEach((a)=>{
116
+ if (!visited.has(a.filename)) {
117
+ visit(a.filename);
118
+ }
119
+ });
120
+ return result;
121
+ }
82
122
 
83
123
  //# sourceMappingURL=serializeHtml.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/serializeHtml.ts"],"sourcesContent":["import { SerialAsset } from '@expo/metro-config/build/serializer/serializerAssets';\nimport { RouteNode } from 'expo-router/build/Route';\n\nconst debug = require('debug')('expo:metro:html') as typeof console.log;\n\nexport function serializeHtmlWithAssets({\n resources,\n template,\n devBundleUrl,\n baseUrl,\n route,\n isExporting,\n hydrate,\n}: {\n resources: SerialAsset[];\n template: string;\n /** asset prefix used for deploying to non-standard origins like GitHub pages. */\n baseUrl: string;\n devBundleUrl?: string;\n route?: RouteNode;\n isExporting: boolean;\n hydrate?: boolean;\n}): string {\n if (!resources) {\n return '';\n }\n return htmlFromSerialAssets(resources, {\n isExporting,\n template,\n baseUrl,\n bundleUrl: isExporting ? undefined : devBundleUrl,\n route,\n hydrate,\n });\n}\n\n/**\n * Combine the path segments of a URL.\n * This filters out empty segments and avoids duplicate slashes when joining.\n * If base url is empty, it will be treated as a root path, adding `/` to the beginning.\n */\nfunction combineUrlPath(baseUrl: string, ...segments: string[]) {\n return [baseUrl || '/', ...segments]\n .filter(Boolean)\n .map((segment, index) => {\n const segmentIsBaseUrl = index === 0;\n // Do not remove leading slashes from baseUrl\n return segment.replace(segmentIsBaseUrl ? /\\/+$/g : /^\\/+|\\/+$/g, '');\n })\n .join('/');\n}\n\nfunction htmlFromSerialAssets(\n assets: SerialAsset[],\n {\n isExporting,\n template,\n baseUrl,\n bundleUrl,\n route,\n hydrate,\n }: {\n isExporting: boolean;\n template: string;\n baseUrl: string;\n /** This is dev-only. */\n bundleUrl?: string;\n route?: RouteNode;\n hydrate?: boolean;\n }\n) {\n // Combine the CSS modules into tags that have hot refresh data attributes.\n const styleString = assets\n .filter((asset) => asset.type.startsWith('css'))\n .map(({ type, metadata, filename, source }) => {\n if (type === 'css') {\n if (isExporting) {\n return [\n `<link rel=\"preload\" href=\"${combineUrlPath(baseUrl, filename)}\" as=\"style\">`,\n `<link rel=\"stylesheet\" href=\"${combineUrlPath(baseUrl, filename)}\">`,\n ].join('');\n } else {\n return `<style data-expo-css-hmr=\"${metadata.hmrId}\">` + source + '\\n</style>';\n }\n }\n // External link tags will be passed through as-is.\n return source;\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, metadata }) => {\n // TODO: Mark dependencies of the HTML and include them to prevent waterfalls.\n if (metadata.isAsync) {\n // We have the data required to match async chunks to the route's HTML file.\n if (\n route?.entryPoints &&\n metadata.modulePaths &&\n Array.isArray(route.entryPoints) &&\n Array.isArray(metadata.modulePaths)\n ) {\n // TODO: Handle module IDs like `expo-router/build/views/Unmatched.js`\n const doesAsyncChunkContainRouteEntryPoint = route.entryPoints.some((entryPoint) =>\n (metadata.modulePaths as string[]).includes(entryPoint)\n );\n if (!doesAsyncChunkContainRouteEntryPoint) {\n return '';\n }\n debug('Linking async chunk %s to HTML for route %s', filename, route.contextKey);\n // Pass through to the next condition.\n } else {\n return '';\n }\n // Mark async chunks as defer so they don't block the page load.\n // return `<script src=\"${combineUrlPath(baseUrl, filename)\" defer></script>`;\n }\n\n return `<script src=\"${combineUrlPath(baseUrl, filename)}\" defer></script>`;\n })\n .join('');\n\n if (hydrate) {\n const hydrateScript = `<script type=\"module\">globalThis.__EXPO_ROUTER_HYDRATE__=true;</script>`;\n template = template.replace('</head>', `${hydrateScript}</head>`);\n }\n\n return template\n .replace('</head>', `${styleString}</head>`)\n .replace('</body>', `${scripts}\\n</body>`);\n}\n"],"names":["serializeHtmlWithAssets","debug","require","resources","template","devBundleUrl","baseUrl","route","isExporting","hydrate","htmlFromSerialAssets","bundleUrl","undefined","combineUrlPath","segments","filter","Boolean","map","segment","index","segmentIsBaseUrl","replace","join","assets","styleString","asset","type","startsWith","metadata","filename","source","hmrId","jsAssets","scripts","isAsync","entryPoints","modulePaths","Array","isArray","doesAsyncChunkContainRouteEntryPoint","some","entryPoint","includes","contextKey","hydrateScript"],"mappings":";;;;+BAKgBA;;;eAAAA;;;AAFhB,MAAMC,QAAQC,QAAQ,SAAS;AAExB,SAASF,wBAAwB,EACtCG,SAAS,EACTC,QAAQ,EACRC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,OAAO,EAUR;IACC,IAAI,CAACN,WAAW;QACd,OAAO;IACT;IACA,OAAOO,qBAAqBP,WAAW;QACrCK;QACAJ;QACAE;QACAK,WAAWH,cAAcI,YAAYP;QACrCE;QACAE;IACF;AACF;AAEA;;;;CAIC,GACD,SAASI,eAAeP,OAAe,EAAE,GAAGQ,QAAkB;IAC5D,OAAO;QAACR,WAAW;WAAQQ;KAAS,CACjCC,MAAM,CAACC,SACPC,GAAG,CAAC,CAACC,SAASC;QACb,MAAMC,mBAAmBD,UAAU;QACnC,6CAA6C;QAC7C,OAAOD,QAAQG,OAAO,CAACD,mBAAmB,UAAU,cAAc;IACpE,GACCE,IAAI,CAAC;AACV;AAEA,SAASZ,qBACPa,MAAqB,EACrB,EACEf,WAAW,EACXJ,QAAQ,EACRE,OAAO,EACPK,SAAS,EACTJ,KAAK,EACLE,OAAO,EASR;IAED,2EAA2E;IAC3E,MAAMe,cAAcD,OACjBR,MAAM,CAAC,CAACU,QAAUA,MAAMC,IAAI,CAACC,UAAU,CAAC,QACxCV,GAAG,CAA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,CAAC;IAEZ,IAAIb,SAAS;QACX,MAAMmC,gBAAgB,CAAC,uEAAuE,CAAC;QAC/FxC,WAAWA,SAASiB,OAAO,CAAC,WAAW,GAAGuB,cAAc,OAAO,CAAC;IAClE;IAEA,OAAOxC,SACJiB,OAAO,CAAC,WAAW,GAAGG,YAAY,OAAO,CAAC,EAC1CH,OAAO,CAAC,WAAW,GAAGY,QAAQ,SAAS,CAAC;AAC7C"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/serializeHtml.ts"],"sourcesContent":["import type { SerialAsset } from '@expo/metro-config/build/serializer/serializerAssets';\nimport type { RouteNode } from 'expo-router/build/Route';\n\nconst debug = require('debug')('expo:metro:html') as typeof console.log;\n\nexport function serializeHtmlWithAssets({\n resources,\n template,\n devBundleUrl,\n baseUrl,\n route,\n isExporting,\n hydrate,\n}: {\n resources: SerialAsset[];\n template: string;\n /** asset prefix used for deploying to non-standard origins like GitHub pages. */\n baseUrl: string;\n devBundleUrl?: string;\n route?: RouteNode;\n isExporting: boolean;\n hydrate?: boolean;\n}): string {\n if (!resources) {\n return '';\n }\n return htmlFromSerialAssets(resources, {\n isExporting,\n template,\n baseUrl,\n bundleUrl: isExporting ? undefined : devBundleUrl,\n route,\n hydrate,\n });\n}\n\n/**\n * Combine the path segments of a URL.\n * This filters out empty segments and avoids duplicate slashes when joining.\n * If base url is empty, it will be treated as a root path, adding `/` to the beginning.\n */\nfunction combineUrlPath(baseUrl: string, ...segments: string[]) {\n return [baseUrl || '/', ...segments]\n .filter(Boolean)\n .map((segment, index) => {\n const segmentIsBaseUrl = index === 0;\n // Do not remove leading slashes from baseUrl\n return segment.replace(segmentIsBaseUrl ? /\\/+$/g : /^\\/+|\\/+$/g, '');\n })\n .join('/');\n}\n\nfunction htmlFromSerialAssets(\n assets: SerialAsset[],\n {\n isExporting,\n template,\n baseUrl,\n bundleUrl,\n route,\n hydrate,\n }: {\n isExporting: boolean;\n template: string;\n baseUrl: string;\n /** This is dev-only. */\n bundleUrl?: string;\n route?: RouteNode;\n hydrate?: boolean;\n }\n) {\n // Combine the CSS modules into tags that have hot refresh data attributes.\n const styleString = assets\n .filter((asset) => asset.type.startsWith('css'))\n .map(({ type, metadata, filename, source }) => {\n if (type === 'css') {\n if (isExporting) {\n return [\n `<link rel=\"preload\" href=\"${combineUrlPath(baseUrl, filename)}\" as=\"style\">`,\n `<link rel=\"stylesheet\" href=\"${combineUrlPath(baseUrl, filename)}\">`,\n ].join('');\n } else {\n return `<style data-expo-css-hmr=\"${metadata.hmrId}\">` + source + '\\n</style>';\n }\n }\n // External link tags will be passed through as-is.\n return source;\n })\n .join('');\n\n const orderedJsAssets = assetsRequiresSort(assets.filter((asset) => asset.type === 'js'));\n\n const scripts = bundleUrl\n ? `<script src=\"${bundleUrl}\" defer></script>`\n : orderedJsAssets\n .map(({ filename, metadata }) => {\n // TODO: Mark dependencies of the HTML and include them to prevent waterfalls.\n if (metadata.isAsync) {\n // We have the data required to match async chunks to the route's HTML file.\n if (\n route?.entryPoints &&\n metadata.modulePaths &&\n Array.isArray(route.entryPoints) &&\n Array.isArray(metadata.modulePaths)\n ) {\n // TODO: Handle module IDs like `expo-router/build/views/Unmatched.js`\n const doesAsyncChunkContainRouteEntryPoint = route.entryPoints.some((entryPoint) =>\n (metadata.modulePaths as string[]).includes(entryPoint)\n );\n if (!doesAsyncChunkContainRouteEntryPoint) {\n return '';\n }\n debug('Linking async chunk %s to HTML for route %s', filename, route.contextKey);\n // Pass through to the next condition.\n } else {\n return '';\n }\n // Mark async chunks as defer so they don't block the page load.\n // return `<script src=\"${combineUrlPath(baseUrl, filename)\" defer></script>`;\n }\n\n return `<script src=\"${combineUrlPath(baseUrl, filename)}\" defer></script>`;\n })\n .join('');\n\n if (hydrate) {\n const hydrateScript = `<script type=\"module\">globalThis.__EXPO_ROUTER_HYDRATE__=true;</script>`;\n template = template.replace('</head>', `${hydrateScript}</head>`);\n }\n\n return template\n .replace('</head>', `${styleString}</head>`)\n .replace('</body>', `${scripts}\\n</body>`);\n}\n\n/**\n * Sorts assets based on the requires tree. DFS order.\n */\nexport function assetsRequiresSort(assets: SerialAsset[]): SerialAsset[] {\n const lookup = new Map<string, SerialAsset>();\n const visited = new Set();\n const visiting = new Set();\n const result: SerialAsset[] = [];\n\n assets.forEach((a) => {\n lookup.set(a.filename, a);\n });\n\n function visit(name: string) {\n if (visited.has(name)) return;\n if (visiting.has(name))\n throw new Error(\n `Circular dependencies in assets are not allowed. Found cycle: ${[...visiting, name].join(' -> ')}`\n );\n\n visiting.add(name);\n\n const module = lookup.get(name);\n if (!module) throw new Error(`Asset not found: ${name}`);\n\n module.metadata.requires?.forEach((dependency) => {\n visit(dependency);\n });\n\n visiting.delete(name);\n visited.add(name);\n result.push(module);\n }\n\n assets.forEach((a) => {\n if (!visited.has(a.filename)) {\n visit(a.filename);\n }\n });\n\n return result;\n}\n"],"names":["assetsRequiresSort","serializeHtmlWithAssets","debug","require","resources","template","devBundleUrl","baseUrl","route","isExporting","hydrate","htmlFromSerialAssets","bundleUrl","undefined","combineUrlPath","segments","filter","Boolean","map","segment","index","segmentIsBaseUrl","replace","join","assets","styleString","asset","type","startsWith","metadata","filename","source","hmrId","orderedJsAssets","scripts","isAsync","entryPoints","modulePaths","Array","isArray","doesAsyncChunkContainRouteEntryPoint","some","entryPoint","includes","contextKey","hydrateScript","lookup","Map","visited","Set","visiting","result","forEach","a","set","visit","name","module","has","Error","add","get","requires","dependency","delete","push"],"mappings":";;;;;;;;;;;IA0IgBA,kBAAkB;eAAlBA;;IArIAC,uBAAuB;eAAvBA;;;AAFhB,MAAMC,QAAQC,QAAQ,SAAS;AAExB,SAASF,wBAAwB,EACtCG,SAAS,EACTC,QAAQ,EACRC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,OAAO,EAUR;IACC,IAAI,CAACN,WAAW;QACd,OAAO;IACT;IACA,OAAOO,qBAAqBP,WAAW;QACrCK;QACAJ;QACAE;QACAK,WAAWH,cAAcI,YAAYP;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