@ngrok/app-server 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +610 -76
  2. package/dist/build-id-C6sYO9Yp.js +126 -0
  3. package/dist/build-id-C6sYO9Yp.js.map +1 -0
  4. package/dist/{build-manifest-8NfD1wnO.js → build-manifest-UDNk81Ce.js} +24 -6
  5. package/dist/build-manifest-UDNk81Ce.js.map +1 -0
  6. package/dist/cli.js +45 -25
  7. package/dist/cli.js.map +1 -1
  8. package/dist/client.d.ts +141 -0
  9. package/dist/client.js +326 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/compression-7_gToa8R.js +97 -0
  12. package/dist/compression-7_gToa8R.js.map +1 -0
  13. package/dist/create-server-iE1-s6Bi.js +1409 -0
  14. package/dist/create-server-iE1-s6Bi.js.map +1 -0
  15. package/dist/{deno-DNRgzHrk.js → deno-aqhikNMG.js} +2 -2
  16. package/dist/deno-aqhikNMG.js.map +1 -0
  17. package/dist/entry-DZ3qo7qF.js +116 -0
  18. package/dist/entry-DZ3qo7qF.js.map +1 -0
  19. package/dist/entry-DmJEqVfd.d.ts +622 -0
  20. package/dist/gzip-Doi4wqjX.js +294 -0
  21. package/dist/gzip-Doi4wqjX.js.map +1 -0
  22. package/dist/header-hook-Vzw9J9BY.js +159 -0
  23. package/dist/header-hook-Vzw9J9BY.js.map +1 -0
  24. package/dist/{index-oSE-tYRW.d.ts → index-Bo5G9LuQ.d.ts} +53 -14
  25. package/dist/index.d.ts +99 -269
  26. package/dist/index.js +47 -59
  27. package/dist/index.js.map +1 -1
  28. package/dist/listen-options-7TaXjyrk.js.map +1 -1
  29. package/dist/{load-entry-C03qqmhr.js → load-entry-AfYS_zS9.js} +8 -4
  30. package/dist/{load-entry-C03qqmhr.js.map → load-entry-AfYS_zS9.js.map} +1 -1
  31. package/dist/log-BP6xXXZl.js +122 -0
  32. package/dist/log-BP6xXXZl.js.map +1 -0
  33. package/dist/node-BFH82eeL.js +333 -0
  34. package/dist/node-BFH82eeL.js.map +1 -0
  35. package/dist/node-tBVQPjQv.js +41 -0
  36. package/dist/node-tBVQPjQv.js.map +1 -0
  37. package/dist/node-vite.d.ts +5 -4
  38. package/dist/node-vite.js +2 -17
  39. package/dist/node.d.ts +23 -4
  40. package/dist/node.js +2 -2
  41. package/dist/react-router-vite.d.ts +4 -3
  42. package/dist/react-router-vite.js +2 -20
  43. package/dist/react-router.d.ts +1 -1
  44. package/dist/react-router.js +8 -7
  45. package/dist/react-router.js.map +1 -1
  46. package/dist/request-context-BtQ87VYb.js +40 -0
  47. package/dist/request-context-BtQ87VYb.js.map +1 -0
  48. package/dist/response-edge-Bc1-C_Cx.js +327 -0
  49. package/dist/response-edge-Bc1-C_Cx.js.map +1 -0
  50. package/dist/response-writer-B7FoJjEE.js +289 -0
  51. package/dist/response-writer-B7FoJjEE.js.map +1 -0
  52. package/dist/script-hashes-hqUk6kG7.js +53 -0
  53. package/dist/script-hashes-hqUk6kG7.js.map +1 -0
  54. package/dist/{serve-Cleo8RMO.js → serve-CDNgThjk.js} +3 -3
  55. package/dist/{serve-Cleo8RMO.js.map → serve-CDNgThjk.js.map} +1 -1
  56. package/dist/{start-CINALHxy.js → start-TLIprD74.js} +14 -19
  57. package/dist/start-TLIprD74.js.map +1 -0
  58. package/dist/static-files-Beju9riB.js +302 -0
  59. package/dist/static-files-Beju9riB.js.map +1 -0
  60. package/dist/tanstack-start-vite.d.ts +6 -5
  61. package/dist/tanstack-start-vite.js +2 -23
  62. package/dist/tanstack-start.d.ts +19 -2
  63. package/dist/tanstack-start.js +5 -14
  64. package/dist/tanstack-start.js.map +1 -1
  65. package/dist/{tcp-C-9AmFuM.js → tcp-Dd1Mt6sN.js} +6 -5
  66. package/dist/{tcp-C-9AmFuM.js.map → tcp-Dd1Mt6sN.js.map} +1 -1
  67. package/dist/trailing-slash-DX7NB88H.d.ts +36 -0
  68. package/dist/types-DLYxYS6M.d.ts +392 -0
  69. package/dist/vercel-vite.d.ts +35 -0
  70. package/dist/vercel-vite.js +142 -0
  71. package/dist/vercel-vite.js.map +1 -0
  72. package/dist/vercel.d.ts +35 -0
  73. package/dist/vercel.js +89 -0
  74. package/dist/vercel.js.map +1 -0
  75. package/dist/vite-B-GfswoH.js +22 -0
  76. package/dist/vite-B-GfswoH.js.map +1 -0
  77. package/dist/vite-D4hfj3ph.js +19 -0
  78. package/dist/vite-D4hfj3ph.js.map +1 -0
  79. package/dist/vite-DyrhyKEr.js +25 -0
  80. package/dist/vite-DyrhyKEr.js.map +1 -0
  81. package/dist/vite-iioAoxSt.js +752 -0
  82. package/dist/vite-iioAoxSt.js.map +1 -0
  83. package/dist/vite.d.ts +2 -2
  84. package/dist/vite.js +1 -1
  85. package/package.json +24 -4
  86. package/dist/build-manifest-8NfD1wnO.js.map +0 -1
  87. package/dist/deno-DNRgzHrk.js.map +0 -1
  88. package/dist/entry-BkdUub2S.js +0 -638
  89. package/dist/entry-BkdUub2S.js.map +0 -1
  90. package/dist/log-CsjaKM8U.js +0 -59
  91. package/dist/log-CsjaKM8U.js.map +0 -1
  92. package/dist/node-CG7qXuWZ.js +0 -58
  93. package/dist/node-CG7qXuWZ.js.map +0 -1
  94. package/dist/node-YWPGmzAk.js +0 -215
  95. package/dist/node-YWPGmzAk.js.map +0 -1
  96. package/dist/node-ZMowKZDB.js +0 -3
  97. package/dist/node-vite.js.map +0 -1
  98. package/dist/react-router-vite.js.map +0 -1
  99. package/dist/start-CINALHxy.js.map +0 -1
  100. package/dist/tanstack-start-vite.js.map +0 -1
  101. package/dist/types-BfCkS7kQ.d.ts +0 -203
  102. package/dist/vite-mYZ2Y69u.js +0 -144
  103. package/dist/vite-mYZ2Y69u.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-iioAoxSt.js","names":["constants"],"sources":["../src/vite/standalone.ts","../src/vite/index.ts"],"sourcesContent":["import { cpSync, existsSync, readdirSync, readFileSync, realpathSync } from \"node:fs\";\nimport { basename, dirname, join, sep } from \"node:path\";\n\n/**\n * A package name: an optional scope and a name, each with no `/` or `\\` and\n * no `.` at the start. Why: a name such as `..` or `../x` in a manifest must\n * not move a copy out of `node_modules`.\n */\nconst PACKAGE_NAME = /^(?:@[^./\\\\][^/\\\\]*\\/)?[^./\\\\][^/\\\\]*$/u;\n\n/**\n * The package names in the dependency `fields` of the `package.json` in\n * `directory`. It skips a key that is not a package name.\n *\n * @example\n * dependencyNames(\"/app/node_modules/react-dom\", [\"peerDependencies\"]); // => [\"react\"]\n */\nexport function dependencyNames(directory: string, fields: readonly string[]): string[] {\n\tconst manifest: unknown = JSON.parse(readFileSync(join(directory, \"package.json\"), \"utf8\"));\n\tconst names = fields.flatMap((field) => {\n\t\tconst value: unknown =\n\t\t\ttypeof manifest === \"object\" && manifest != null ? Reflect.get(manifest, field) : undefined;\n\t\treturn typeof value === \"object\" && value != null\n\t\t\t? Object.keys(value).filter((name) => PACKAGE_NAME.test(name))\n\t\t\t: [];\n\t});\n\treturn [...new Set(names)];\n}\n\n/**\n * The package name of a bare import.\n *\n * @example\n * packageName(\"@scope/name/sub/path\"); // => \"@scope/name\"\n */\nexport function packageName(specifier: string): string {\n\tconst parts = specifier.split(\"/\");\n\treturn parts.slice(0, specifier.startsWith(\"@\") ? 2 : 1).join(\"/\");\n}\n\n/**\n * Code that finds a file next to its own module: a relative `new URL()` on\n * `import.meta.url`, `fileURLToPath(import.meta.url)`, or\n * `import.meta.dirname`.\n */\nconst OWN_FILE =\n\t/new\\s+URL\\(\\s*(?<quote>[\"'`])\\.{1,2}\\/[^\"'`]*\\k<quote>\\s*,\\s*import\\.meta\\.url\\s*\\)|fileURLToPath\\(\\s*import\\.meta\\.url\\s*\\)|import\\.meta\\.(?:dirname|filename)\\b/u;\n\n/**\n * Whether the module `file` finds a file next to itself, such as\n * `@vercel/og`, which reads `resvg.wasm` through\n * `new URL(\"./resvg.wasm\", import.meta.url)`. Why: in the bundle,\n * `import.meta.url` is the URL of the bundle, so the file is not there.\n *\n * @example\n * readsOwnFiles(\"/app/node_modules/@vercel/og/dist/index.node.js\"); // => true\n */\nexport function readsOwnFiles(file: string): boolean {\n\treturn OWN_FILE.test(readFileSync(file, \"utf8\"));\n}\n\n/**\n * The real path of the directory of package `name`, as Node finds it from the\n * directory `from`: in each `node_modules` directory above `from`. Else\n * `undefined`. The real path follows the symbolic links of pnpm's layout.\n *\n * @example\n * findPackage(\"react\", \"/app/build/server\"); // => \"/app/node_modules/.pnpm/react@19.3.1/node_modules/react\"\n */\nexport function findPackage(name: string, from: string): string | undefined {\n\tfor (let directory = from; ; directory = dirname(directory)) {\n\t\tconst candidate = join(directory, \"node_modules\", name);\n\t\tif (basename(directory) !== \"node_modules\" && existsSync(join(candidate, \"package.json\"))) {\n\t\t\treturn realpathSync(candidate);\n\t\t}\n\t\tif (dirname(directory) === directory) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n}\n\n/**\n * The directory of package `name` that holds `file`: the nearest directory\n * above `file` at `node_modules/<name>`. Else `undefined`, such as for a file\n * of a linked workspace package.\n *\n * @example\n * packageDirectoryOf(\"/app/node_modules/react/cjs/react.js\", \"react\"); // => \"/app/node_modules/react\"\n */\nexport function packageDirectoryOf(file: string, name: string): string | undefined {\n\tfor (\n\t\tlet directory = dirname(file);\n\t\tdirectory !== dirname(directory);\n\t\tdirectory = dirname(directory)\n\t) {\n\t\tif (directory.endsWith(`${sep}${join(\"node_modules\", name)}`)) {\n\t\t\t// Why the real path: `findPackage` gives real paths, and the two must compare equal.\n\t\t\treturn realpathSync(directory);\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** Whether a `.node` file is in `directory`, outside its `node_modules`. */\nfunction hasNodeFile(directory: string): boolean {\n\treturn readdirSync(directory, { withFileTypes: true }).some((entry) =>\n\t\tentry.isDirectory()\n\t\t\t? entry.name !== \"node_modules\" && hasNodeFile(join(entry.parentPath, entry.name))\n\t\t\t: entry.name.endsWith(\".node\"),\n\t);\n}\n\n/**\n * Whether the package in `directory` loads a native addon: a `.node` file is\n * in the package, or in a package of its `dependencies` or\n * `optionalDependencies`. The second case finds a package that gets its addon\n * from a package for each platform, such as `oxc-parser` from\n * `@oxc-parser/binding-darwin-arm64`. Only the installed platform package is\n * there. `scans` keeps the result for each directory that the function\n * searched, so a call with the same map does not search a directory again.\n *\n * @example\n * isNativePackage(\"/app/node_modules/better-sqlite3\"); // => true\n */\nexport function isNativePackage(directory: string, scans = new Map<string, boolean>()): boolean {\n\tconst scan = (path: string): boolean => {\n\t\tconst found = scans.get(path) ?? hasNodeFile(path);\n\t\tscans.set(path, found);\n\t\treturn found;\n\t};\n\treturn (\n\t\tscan(directory) ||\n\t\tdependencyNames(directory, [\"dependencies\", \"optionalDependencies\"]).some((name) => {\n\t\t\tconst dependency = findPackage(name, directory);\n\t\t\treturn dependency != null && scan(dependency);\n\t\t})\n\t);\n}\n\n/**\n * The `node_modules` directories where Node looks for a package that the\n * package at `destination` imports, nearest first, down to `target`.\n */\nfunction lookupDirectories(destination: string, target: string): string[] {\n\tconst directories: string[] = [];\n\tfor (let directory = destination; ; directory = dirname(directory)) {\n\t\tif (basename(directory) !== \"node_modules\") {\n\t\t\tdirectories.push(join(directory, \"node_modules\"));\n\t\t}\n\t\tif (directory === dirname(target)) {\n\t\t\treturn directories;\n\t\t}\n\t}\n}\n\n/**\n * Copies each package, whole, with the installed packages of its\n * `dependencies`, `optionalDependencies`, and `peerDependencies`, into the\n * `node_modules` directory `target`. Node then finds each package from a file\n * next to `target`, with no install. The copy follows symbolic links. A\n * dependency goes to the top of `target`. If another copy of that package is\n * nearer in the lookup path of the package that needs it, the dependency goes\n * into that package's own `node_modules`.\n *\n * @example\n * copyPackages(new Map([[\"oxc-parser\", \"/app/node_modules/oxc-parser\"]]), \"/app/build/server/node_modules\");\n */\nexport function copyPackages(packages: ReadonlyMap<string, string>, target: string): void {\n\t// Why a map of destinations: a later lookup must know which copy is at each path.\n\tconst sources = new Map<string, string>();\n\tconst queue: string[] = [];\n\tconst add = (destination: string, source: string) => {\n\t\tsources.set(destination, source);\n\t\tqueue.push(destination);\n\t};\n\tfor (const [name, source] of packages) {\n\t\tadd(join(target, name), source);\n\t}\n\t// Why breadth first: a package places all its own dependencies before a dependency looks up\n\t// its own, so a later copy never hides an earlier lookup.\n\tfor (const destination of queue) {\n\t\tconst source = sources.get(destination) ?? \"\";\n\t\tcpSync(source, destination, {\n\t\t\trecursive: true,\n\t\t\tdereference: true,\n\t\t\tfilter: (path) => path !== join(source, \"node_modules\"),\n\t\t});\n\t\tfor (const name of dependencyNames(source, [\n\t\t\t\"dependencies\",\n\t\t\t\"optionalDependencies\",\n\t\t\t\"peerDependencies\",\n\t\t])) {\n\t\t\tconst dependency = findPackage(name, source);\n\t\t\tconst found = lookupDirectories(destination, target)\n\t\t\t\t.map((directory) => join(directory, name))\n\t\t\t\t.find((path) => sources.has(path));\n\t\t\tif (dependency != null && (found == null || sources.get(found) !== dependency)) {\n\t\t\t\tadd(join(found == null ? target : join(destination, \"node_modules\"), name), dependency);\n\t\t\t}\n\t\t}\n\t}\n}\n","import { createHash } from \"node:crypto\";\nimport {\n\texistsSync,\n\tmkdirSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { isBuiltin } from \"node:module\";\nimport { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { brotliCompressSync, constants, gzipSync } from \"node:zlib\";\nimport { getPath } from \"hono/utils/url\";\nimport type { Environment, Plugin, PreviewServer, ResolvedConfig, Rolldown } from \"vite\";\nimport { BUILD_MANIFEST_FILE, manifestKey } from \"../core/build-manifest.js\";\nimport type { BuildManifest } from \"../core/build-manifest.js\";\nimport { copyName, isCompressible, MIN_COMPRESS_BYTES } from \"../core/compression.js\";\nimport type { Encoding } from \"../core/compression.js\";\nimport { contentType } from \"../core/static-files.js\";\nimport { inlineScriptHashes } from \"../node/script-hashes.js\";\nimport { node } from \"../node/vite.js\";\nimport { reactRouterAdapter } from \"../react-router/vite.js\";\nimport { tanstackStartAdapter } from \"../tanstack-start/vite.js\";\nimport {\n\tcopyPackages,\n\tdependencyNames,\n\tfindPackage,\n\tisNativePackage,\n\tpackageDirectoryOf,\n\tpackageName,\n\treadsOwnFiles,\n} from \"./standalone.js\";\n\n/** The module ID of the server entry that {@link appServer} generates. */\nexport const SERVER_ENTRY_ID = \"virtual:@ngrok/app-server/entry\";\nconst RESOLVED_SERVER_ENTRY_ID = `\\0${SERVER_ENTRY_ID}`;\n\n/** The Vite environment that builds the server. */\nconst SERVER_ENVIRONMENT = \"ssr\";\n\n/** A bare import, such as `react` or `@scope/name/path`: not a path, a `\\0` ID, or a `node:` or `virtual:` ID. */\nconst BARE_IMPORT = /^[\\w@][^:]*$/u;\n\n/** The file extensions of a module that Node imports as it is, with no transform by Vite. */\nconst JAVASCRIPT_EXTENSIONS = new Set([\"\", \".js\", \".mjs\", \".cjs\"]);\n\n/** The header that turns on Node's header store for a response, so `finish` can read every header. */\nconst CAPTURE_MARKER = \"x-app-server-capture\";\n\n/**\n * Headers that describe one transfer, not the resource. The server sets its\n * own, and a cookie must never replay to every visitor. `Vary` is left out\n * because the preview server adds `Vary: Origin` to every response.\n */\nconst UNCAPTURED_HEADERS = new Set([\n\tCAPTURE_MARKER,\n\t\"connection\",\n\t\"content-encoding\",\n\t\"content-length\",\n\t\"date\",\n\t\"etag\",\n\t\"keep-alive\",\n\t\"last-modified\",\n\t\"set-cookie\",\n\t\"transfer-encoding\",\n\t\"vary\",\n]);\n\n/**\n * The build side of a framework adapter. The Vite config imports it, such as\n * `reactRouterAdapter()` from `@ngrok/app-server/react-router/vite`.\n */\nexport type FrameworkBuild = {\n\t/** A name for logs and errors. */\n\tname: string;\n\t/** The Vite ID of the framework's server module, such as `virtual:react-router/server-build`. */\n\tserverModule: string;\n\t/**\n\t * The module whose `runtime` export makes the run side from the server\n\t * module. It has the type `FrameworkRuntimeFactory`.\n\t */\n\truntimeModule: string;\n\t/**\n\t * The source of an object literal with more options for `runtime`, such as\n\t * a build constant of the framework. The bundler replaces the constants in\n\t * it, because the source is part of the server entry.\n\t */\n\truntimeOptions?: string;\n\t/** Whether a preview server runs the framework's prerender pass. */\n\tisPrerenderPass: (server: PreviewServer) => boolean;\n\t/** Throws for a config that the adapter does not support, so the build fails, not the first request. */\n\tvalidate?: (config: ResolvedConfig) => void;\n};\n\n/**\n * The build side of a host adapter. The Vite config imports it, such as\n * `node()` from `@ngrok/app-server/node/vite`.\n */\nexport type HostBuild = {\n\t/** A name for logs and errors. */\n\tname: string;\n\t/** The module whose `host` export is the run side, a `HostRuntime`. */\n\truntimeModule: string;\n\t/** The file name of the server entry in the server build, such as `app-server.js`. */\n\tentryFileName: string;\n\t/**\n\t * Writes the host's deploy output, such as Vercel's `.vercel/output`. It\n\t * runs after each prerender pass and after the build, so it can run two\n\t * times. Why after the pass too: when `appServer` comes before the\n\t * framework's plugin, the pass runs after the build. Why sync: Vite does\n\t * not wait for the end of that pass.\n\t */\n\toutput?: (build: HostOutput) => void;\n};\n\n/** What a host's `output` gets: the absolute paths of the build. */\nexport type HostOutput = {\n\t/** The Vite root. */\n\troot: string;\n\t/** The client build, such as `build/client`. */\n\tclientDirectory: string;\n\t/** The server entry, such as `build/server/app-server.js`. */\n\tentryFile: string;\n};\n\n/** Options for {@link appServer}. */\nexport type AppServerOptions = {\n\t/**\n\t * The framework adapter. When omitted, the plugin finds the React Router or\n\t * TanStack Start plugin in the Vite config. It throws when it finds neither\n\t * or both.\n\t */\n\tframework?: FrameworkBuild;\n\t/** The host adapter. Default `node()`. */\n\thost?: HostBuild;\n\t/**\n\t * The module whose default export is the app from `createServer`, relative\n\t * to the Vite root. When omitted, the plugin uses `server.ts`, else\n\t * `server.js`, in the Vite root. When neither exists, the server uses its\n\t * default plugins.\n\t */\n\tapp?: string;\n};\n\n/** The built-in framework adapters, each with the name of the Vite plugin that marks its framework. */\nconst FRAMEWORKS = [\n\t// Why not the `react-router` plugin: React Router's child compiler drops that plugin and keeps\n\t// this one, which serves the server module.\n\t{ plugin: \"react-router:virtual-modules\", adapter: reactRouterAdapter },\n\t{ plugin: \"tanstack-react-start:config\", adapter: tanstackStartAdapter },\n];\n\n/** The adapter of the one built-in framework whose plugin is in the Vite config. */\nfunction detectFramework(plugins: readonly Plugin[]): FrameworkBuild {\n\tconst names = new Set(plugins.map((plugin) => plugin.name));\n\tconst [found, ...others] = FRAMEWORKS.filter(({ plugin }) => names.has(plugin));\n\tif (found == null) {\n\t\tthrow new Error(\n\t\t\t\"@ngrok/app-server found no React Router or TanStack Start plugin in the Vite config. Add the framework's plugin, or pass `framework` to `appServer`.\",\n\t\t);\n\t}\n\tif (others.length > 0) {\n\t\tthrow new Error(\n\t\t\t\"@ngrok/app-server found the React Router and the TanStack Start plugins in the Vite config. Pass `framework` to `appServer`.\",\n\t\t);\n\t}\n\treturn found.adapter();\n}\n\n/** The absolute path of `server.ts` or `server.js` in `root`, else `undefined` for the default app. */\nfunction defaultApp(root: string): string | undefined {\n\treturn [\"server.ts\", \"server.js\"]\n\t\t.map((name) => join(root, name))\n\t\t.find((path) => existsSync(path));\n}\n\n/** What {@link serverEntrySource} needs. */\ntype EntrySource = {\n\tframework: Pick<FrameworkBuild, \"serverModule\" | \"runtimeModule\" | \"runtimeOptions\">;\n\thost: Pick<HostBuild, \"runtimeModule\">;\n\t/** The absolute path of the app module, else `undefined` for the default app. */\n\tappModule: string | undefined;\n\t/** The source of an expression that gives the client build: a path or a `file:` URL. */\n\tclientDirectory: string;\n};\n\n/**\n * The source of the server entry. When a runtime runs the file as its main\n * module, such as `node build/server/app-server.js`, the entry starts the\n * server. When the CLI imports it, the CLI starts the server.\n */\nexport function serverEntrySource({\n\tframework,\n\thost,\n\tappModule,\n\tclientDirectory,\n}: EntrySource): string {\n\tconst modules = [\n\t\tframework.serverModule,\n\t\t// Why from the bundle: the CLI calls this export, so the server runs on the bundle's copy of\n\t\t// this package and of the framework, the same copies as the app and the routes.\n\t\t\"@ngrok/app-server\",\n\t\tframework.runtimeModule,\n\t\thost.runtimeModule,\n\t\t...(appModule == null ? [] : [appModule]),\n\t];\n\treturn [\n\t\t// Why before the imports: React reads `NODE_ENV` when it loads. Why dynamic imports: a static\n\t\t// import loads before this line.\n\t\t\"if (import.meta.main) {\",\n\t\t'\\tprocess.env.NODE_ENV ??= \"production\";',\n\t\t'\\tif (typeof process.setSourceMapsEnabled === \"function\") {',\n\t\t\"\\t\\tprocess.setSourceMapsEnabled(true);\",\n\t\t\"\\t}\",\n\t\t\"}\",\n\t\t`const [serverModule, { createEntry, createServer }, { runtime }, hostModule${appModule == null ? \"\" : \", { default: app }\"}] = await Promise.all([`,\n\t\t...modules.map((module) => `\\timport(${JSON.stringify(module)}),`),\n\t\t\"]);\",\n\t\t...(appModule == null\n\t\t\t? [\n\t\t\t\t\t`const app = createServer({ trustForwardedProto: process.env.TRUST_FORWARDED_PROTO === \"1\", trustedProxyHops: Number(process.env.TRUSTED_PROXY_HOPS ?? 0) });`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t`export const appServer = createEntry({`,\n\t\t`\\tapp,`,\n\t\t`\\thost: hostModule.host,`,\n\t\t`\\tclientDirectory: ${clientDirectory},`,\n\t\t`\\tframework: (mode) => runtime(serverModule, { ${framework.runtimeOptions == null ? \"\" : `...${framework.runtimeOptions}, `}mode }),`,\n\t\t`});`,\n\t\t// Why: a serverless host's function file calls the run side through the bundle's copy.\n\t\t\"export { hostModule };\",\n\t\t\"if (import.meta.main) {\",\n\t\t\"\\tawait appServer.start();\",\n\t\t\"}\",\n\t].join(\"\\n\");\n}\n\n/** The paths of the build that a host's `output` gets. */\nfunction hostOutput(config: ResolvedConfig, host: HostBuild): HostOutput {\n\treturn {\n\t\troot: config.root,\n\t\tclientDirectory: outDir(config, \"client\"),\n\t\tentryFile: join(outDir(config, SERVER_ENVIRONMENT), host.entryFileName),\n\t};\n}\n\n/** The absolute path of an environment's build output. */\nfunction outDir(config: ResolvedConfig, environment: string): string {\n\treturn resolve(\n\t\tconfig.root,\n\t\tconfig.environments[environment]?.build.outDir ?? config.build.outDir,\n\t);\n}\n\n/**\n * Whether `id` is a JavaScript file, which Node imports from `node_modules`\n * as it is. Why: a plugin can resolve a bare import to a virtual module, and\n * Vite transforms a JSON file or an asset, such as `?raw` on a file with no\n * extension.\n */\nfunction isJavaScriptFile(id: string): boolean {\n\treturn isAbsolute(id) && !id.includes(\"?\") && JAVASCRIPT_EXTENSIONS.has(extname(id));\n}\n\n/**\n * A `require.resolve()` or an `import.meta.resolve()` of a string literal.\n * The `source` group is the string.\n */\nconst RESOLVE_CALL =\n\t/\\b(?:require|import\\.meta)\\.resolve\\(\\s*(?<quote>[\"'`])(?<source>[^\"'`$]+)\\k<quote>/gu;\n\n/** The dependency fields of the app's `package.json` that can name a package the server imports. */\nconst APP_DEPENDENCY_FIELDS = [\"dependencies\", \"optionalDependencies\", \"devDependencies\"];\n\n/** Whether `environment` builds the server. */\nfunction isServerBuild(environment: Pick<Environment, \"name\" | \"mode\">): boolean {\n\treturn environment.name === SERVER_ENVIRONMENT && environment.mode === \"build\";\n}\n\n/**\n * Makes the server build run with no install. The build bundles each\n * dependency, except the packages that the app keeps external (`ssr.external`\n * or the bundler's `external`), each native package (see `isNativePackage`),\n * each package that reads a file next to its own module (see `readsOwnFiles`),\n * and each package that the bundle shares with a package that the app keeps\n * external: the whole package of an external subpath, and each peer, at each\n * level. Those stay external, so the plugin copies each one, whole, with its\n * dependencies, into `node_modules` in the server build. It also writes a `package.json` there, so\n * Node, Bun, and Deno load the build as ES modules and find that `node_modules`.\n */\nfunction standalone(): Plugin {\n\t// Why a value for each name: two copies of one external package cannot share one `node_modules`.\n\tconst externals = new Map<string, string | undefined>();\n\t// Why: the bundle and an external package must share one copy of a package, such as `react`.\n\tconst shared = new Set<string>();\n\tconst natives = new Map<string, boolean>();\n\t// Why: many packages share one dependency, and each search reads its whole directory.\n\tconst scans = new Map<string, boolean>();\n\tconst isNative = (directory: string): boolean => {\n\t\tconst native = natives.get(directory) ?? isNativePackage(directory, scans);\n\t\tnatives.set(directory, native);\n\t\treturn native;\n\t};\n\t// Why: many modules import one package, and each check reads the file.\n\tconst ownFiles = new Map<string, boolean>();\n\t// Why `existsSync`: another plugin can give a module that is not on disk.\n\tconst readsOwnFile = (file: string): boolean => {\n\t\tconst reads = ownFiles.get(file) ?? (existsSync(file) && readsOwnFiles(file));\n\t\townFiles.set(file, reads);\n\t\treturn reads;\n\t};\n\t// Why: a package that stays external after the bundle holds one of its peers gets a second copy.\n\tconst inBundle = new Set<string>();\n\t/**\n\t * Whether the bundled module `file` of package `name` must stay external:\n\t * the package is native, or `file` reads a file next to it. Then the\n\t * package and each of its peers stay external, so the bundle shares them.\n\t */\n\tconst staysExternal = (\n\t\t{ name, file, directory }: { name: string; file: string; directory: string | undefined },\n\t\tlogger: Environment[\"logger\"],\n\t): boolean => {\n\t\tconst native = directory != null && isNative(directory);\n\t\tif (directory == null || (!native && !readsOwnFile(file))) {\n\t\t\tinBundle.add(name);\n\t\t\treturn false;\n\t\t}\n\t\tconst group = withPeers([{ name, from: directory }]);\n\t\tconst held = [...group].find((peer) => inBundle.has(peer));\n\t\t// Why bundle it: a second copy of a peer, such as `react`, breaks more than a lost file.\n\t\tif (held != null && !native) {\n\t\t\tlogger.warn(\n\t\t\t\t`@ngrok/app-server bundles \"${name}\", but it reads a file next to its own module, so the server can fail when it reads that file. The bundle already holds \"${held}\", so \"${name}\" cannot stay external alone. Add \"${name}\" to \\`ssr.external\\`.`,\n\t\t\t);\n\t\t\tinBundle.add(name);\n\t\t\treturn false;\n\t\t}\n\t\tfor (const peer of group) {\n\t\t\tshared.add(peer);\n\t\t}\n\t\treturn true;\n\t};\n\treturn {\n\t\tname: \"@ngrok/app-server:standalone\",\n\t\t// Why `pre`: Vite's resolver runs before a plugin with no `enforce`, so that plugin cannot keep\n\t\t// a native package out of the bundle.\n\t\tenforce: \"pre\",\n\t\tconfig: (config, { command }) => {\n\t\t\tconst ssr = config.environments?.[SERVER_ENVIRONMENT]?.resolve;\n\t\t\t// Why a build only: in development, Vite loads each dependency from `node_modules`. Why not\n\t\t\t// with the app's value: Vite merges `true` over a list, and `noExternal: true` wins over\n\t\t\t// `external: true`, so the app's value then has no effect.\n\t\t\treturn command === \"build\" &&\n\t\t\t\tconfig.ssr?.noExternal == null &&\n\t\t\t\tssr?.noExternal == null &&\n\t\t\t\tconfig.ssr?.external !== true &&\n\t\t\t\tssr?.external !== true\n\t\t\t\t? { ssr: { noExternal: true } }\n\t\t\t\t: undefined;\n\t\t},\n\t\tbuildStart() {\n\t\t\tif (!isServerBuild(this.environment)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texternals.clear();\n\t\t\tshared.clear();\n\t\t\tnatives.clear();\n\t\t\tscans.clear();\n\t\t\townFiles.clear();\n\t\t\tinBundle.clear();\n\t\t\tconst { resolve: resolveOptions, build, root } = this.environment.config;\n\t\t\tconst kept = [\n\t\t\t\t...(resolveOptions.external === true ? [] : resolveOptions.external),\n\t\t\t\t...[build.rolldownOptions.external].flat(),\n\t\t\t];\n\t\t\tconst names = kept.flatMap((id) =>\n\t\t\t\ttypeof id === \"string\" && BARE_IMPORT.test(id) ? [packageName(id)] : [],\n\t\t\t);\n\t\t\tconst patterns = kept.filter(\n\t\t\t\t(id): id is Exclude<typeof id, string | undefined> => id != null && typeof id !== \"string\",\n\t\t\t);\n\t\t\t// Why the app's dependencies: the bundler never shows the plugin an import that a `RegExp` or\n\t\t\t// a function keeps external, so the build must find their peers before it bundles.\n\t\t\tconst matched =\n\t\t\t\tpatterns.length === 0 || !existsSync(join(root, \"package.json\"))\n\t\t\t\t\t? []\n\t\t\t\t\t: dependencyNames(root, APP_DEPENDENCY_FIELDS).filter((name) =>\n\t\t\t\t\t\t\tpatterns.some((pattern) => matchesExternal(pattern, name)),\n\t\t\t\t\t\t);\n\t\t\t// Why with no import: the app can read a file of a package at run time, such as through\n\t\t\t// `require.resolve`.\n\t\t\tfor (const name of names) {\n\t\t\t\tconst directory = findPackage(name, root);\n\t\t\t\tif (directory != null) {\n\t\t\t\t\texternals.set(name, directory);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const name of withPeers(\n\t\t\t\t[...names, ...matched].map((dependency) => ({ name: dependency, from: root })),\n\t\t\t)) {\n\t\t\t\tshared.add(name);\n\t\t\t}\n\t\t},\n\t\tresolveId: {\n\t\t\tfilter: { id: BARE_IMPORT },\n\t\t\tasync handler(source, importer, options) {\n\t\t\t\tif (!isServerBuild(this.environment) || isBuiltin(source)) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tconst resolved = await this.resolve(source, importer, { ...options, skipSelf: true });\n\t\t\t\tconst bundled = resolved?.external === false;\n\t\t\t\tif (resolved == null || (bundled && !isJavaScriptFile(resolved.id))) {\n\t\t\t\t\treturn resolved;\n\t\t\t\t}\n\t\t\t\tconst name = packageName(source);\n\t\t\t\t// Why the resolved file first: Vite can pick another copy than Node, such as for\n\t\t\t\t// `resolve.dedupe`.\n\t\t\t\tconst directory =\n\t\t\t\t\t(bundled ? packageDirectoryOf(resolved.id, name) : undefined) ??\n\t\t\t\t\tfindPackage(\n\t\t\t\t\t\tname,\n\t\t\t\t\t\timporter != null && isAbsolute(importer)\n\t\t\t\t\t\t\t? dirname(importer)\n\t\t\t\t\t\t\t: this.environment.config.root,\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tbundled &&\n\t\t\t\t\t!shared.has(name) &&\n\t\t\t\t\t!staysExternal({ name, file: resolved.id, directory }, this.environment.logger)\n\t\t\t\t) {\n\t\t\t\t\treturn resolved;\n\t\t\t\t}\n\t\t\t\tconst known = externals.get(name);\n\t\t\t\tif (known != null && directory != null && known !== directory) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`@ngrok/app-server found two copies of \"${name}\" that stay external, and the server build can hold one: ${known} and ${directory}. Install one version of \"${name}\".`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\texternals.set(name, known ?? directory);\n\t\t\t\treturn bundled ? { id: source, external: true } : resolved;\n\t\t\t},\n\t\t},\n\t\ttransform: {\n\t\t\t// Why only the app's code: a package that resolves a file of another package at run time,\n\t\t\t// such as an optional binary, would copy a large package that the server never reads.\n\t\t\tfilter: {\n\t\t\t\tid: { exclude: /[\\\\/]node_modules[\\\\/]/u },\n\t\t\t\tcode: /\\b(?:require|import\\.meta)\\.resolve\\(/u,\n\t\t\t},\n\t\t\thandler(code, id) {\n\t\t\t\tif (!isServerBuild(this.environment)) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\t// Why: the server reads a file of the package at run time, so the build must hold the package.\n\t\t\t\tfor (const { groups } of code.matchAll(RESOLVE_CALL)) {\n\t\t\t\t\tconst source = groups?.source ?? \"\";\n\t\t\t\t\tconst name = packageName(source);\n\t\t\t\t\tconst directory =\n\t\t\t\t\t\tBARE_IMPORT.test(source) && !isBuiltin(source) && !externals.has(name)\n\t\t\t\t\t\t\t? findPackage(name, isAbsolute(id) ? dirname(id) : this.environment.config.root)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t// Why only a package it finds: the module-graph pass in `writeBundle` can find it from another importer.\n\t\t\t\t\tif (directory != null) {\n\t\t\t\t\t\texternals.set(name, directory);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t},\n\t\t},\n\t\twriteBundle() {\n\t\t\tif (!isServerBuild(this.environment)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Why: the bundler does not call `resolveId` for a package in its own `external` option. Why\n\t\t\t// from the importer: with pnpm, only the importer's `node_modules` holds its dependencies.\n\t\t\tfor (const importer of this.getModuleIds()) {\n\t\t\t\tconst info = this.getModuleInfo(importer);\n\t\t\t\tfor (const id of [...(info?.importedIds ?? []), ...(info?.dynamicallyImportedIds ?? [])]) {\n\t\t\t\t\tconst name = packageName(id);\n\t\t\t\t\tif (BARE_IMPORT.test(id) && !isBuiltin(id) && !externals.has(name)) {\n\t\t\t\t\t\texternals.set(\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tfindPackage(\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tisAbsolute(importer) ? dirname(importer) : this.environment.config.root,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst directory = outDir(this.environment.getTopLevelConfig(), SERVER_ENVIRONMENT);\n\t\t\tconst found = new Map<string, string>();\n\t\t\tfor (const [name, source] of externals) {\n\t\t\t\tif (source == null) {\n\t\t\t\t\tthis.environment.logger.warn(\n\t\t\t\t\t\t`@ngrok/app-server cannot find \"${name}\", which stays external, so the server build does not hold it. The server fails if it imports \"${name}\".`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tfound.set(name, source);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst target = join(directory, \"node_modules\");\n\t\t\trmSync(target, { recursive: true, force: true });\n\t\t\tcopyPackages(found, target);\n\t\t\twriteFileSync(join(directory, \"package.json\"), `${JSON.stringify({ type: \"module\" })}\\n`);\n\t\t\tif (found.size > 0) {\n\t\t\t\tthis.environment.logger.info(\n\t\t\t\t\t`@ngrok/app-server copied the external packages ${[...found.keys()].join(\", \")}, with their dependencies, into ${target}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Whether the app's `RegExp` or function external keeps the package `name`\n * external. Why `false` when the function throws: the build calls it with no\n * importer, and a function that reads the importer can throw.\n */\nfunction matchesExternal(\n\tpattern: RegExp | ((id: string, importer: string | undefined, isResolved: boolean) => unknown),\n\tname: string,\n): boolean {\n\tif (typeof pattern !== \"function\") {\n\t\treturn name.search(pattern) !== -1;\n\t}\n\ttry {\n\t\treturn pattern(name, undefined, false) === true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Each package of `start` and each of its peers, at each level. Why each\n * level: a peer can have peers, such as `react` for `react-router`.\n */\nfunction withPeers(start: { name: string; from: string }[]): Set<string> {\n\tconst names = new Set<string>();\n\tconst queue = [...start];\n\tfor (const { name, from } of queue) {\n\t\tconst directory = names.has(name) ? undefined : findPackage(name, from);\n\t\tnames.add(name);\n\t\tif (directory != null) {\n\t\t\tfor (const peer of dependencyNames(directory, [\"peerDependencies\"])) {\n\t\t\t\tqueue.push({ name: peer, from: directory });\n\t\t\t}\n\t\t}\n\t}\n\treturn names;\n}\n\n/** The {@link inlineScriptHashes} of each HTML file in the client build, by its URL path. */\nfunction scriptHashesOf(clientDirectory: string): BuildManifest[\"scriptHashes\"] {\n\tconst hashes: BuildManifest[\"scriptHashes\"] = {};\n\tfor (const entry of readdirSync(clientDirectory, { recursive: true, withFileTypes: true })) {\n\t\t// Why `contentType`: the static stages send each file of an HTML type, such as `.htm`, as a document.\n\t\tif (entry.isFile() && contentType(entry.name, {}).startsWith(\"text/html\")) {\n\t\t\tconst path = join(entry.parentPath, entry.name);\n\t\t\tconst urlPath = `/${relative(clientDirectory, path).split(sep).join(\"/\")}`;\n\t\t\thashes[urlPath] = inlineScriptHashes(readFileSync(path, \"utf8\"));\n\t\t}\n\t}\n\treturn Object.fromEntries(\n\t\tObject.entries(hashes).toSorted(([first], [second]) => first.localeCompare(second)),\n\t);\n}\n\n/** Writes `.app-server.json` into the client build. */\nfunction writeBuildManifest(clientDirectory: string, manifest: BuildManifest): void {\n\tmkdirSync(clientDirectory, { recursive: true });\n\twriteFileSync(\n\t\tjoin(clientDirectory, BUILD_MANIFEST_FILE),\n\t\t`${JSON.stringify(manifest, null, \"\\t\")}\\n`,\n\t);\n}\n\n/**\n * Writes the build ID and the script hashes of the client build\n * ({@link scriptHashesOf}) into `.app-server.json`, and keeps the rest of the\n * file. Why after the build too: a build with no prerender pass can have HTML\n * files, such as `public/offline.html`.\n */\nfunction completeBuildManifest(clientDirectory: string, buildId: string | undefined): void {\n\tif (!existsSync(clientDirectory)) {\n\t\treturn;\n\t}\n\tconst path = join(clientDirectory, BUILD_MANIFEST_FILE);\n\tconst recorded: unknown = existsSync(path) ? JSON.parse(readFileSync(path, \"utf8\")) : undefined;\n\twriteBuildManifest(clientDirectory, {\n\t\tprerendered: [],\n\t\theaders: {},\n\t\t...(typeof recorded === \"object\" && recorded != null ? recorded : {}),\n\t\t...(buildId == null ? {} : { buildId }),\n\t\tscriptHashes: scriptHashesOf(clientDirectory),\n\t});\n}\n\n/**\n * The ID of a client build: a hash of the name and the content of each file\n * in its bundle. Why the bundle: it is the code that an open tab runs, so the\n * ID changes when that code changes, and not for a change to the server, a\n * `public/` file, or a prerendered page. Why the content, not the file\n * names: a name has a content hash only when the output names ask for one.\n */\nfunction bundleBuildId(bundle: Rolldown.OutputBundle): string {\n\tconst hash = createHash(\"sha256\");\n\t// Why `<`, not `localeCompare`: the order of `localeCompare` changes with the locale of the\n\t// machine, so two machines would give one bundle two IDs.\n\tfor (const file of Object.values(bundle).toSorted((first, second) =>\n\t\tfirst.fileName < second.fileName ? -1 : 1,\n\t)) {\n\t\thash.update(`${file.fileName}\\0`);\n\t\thash.update(file.type === \"chunk\" ? file.code : file.source);\n\t\thash.update(\"\\0\");\n\t}\n\t// Why 16 hex digits: 64 bits keep two builds apart, and the ID goes in each document's headers.\n\treturn hash.digest(\"hex\").slice(0, 16);\n}\n\n/** The path of each file under `directory` that is not a dotfile, in code unit order. */\nfunction filesIn(directory: string): string[] {\n\tif (!existsSync(directory)) {\n\t\treturn [];\n\t}\n\treturn readdirSync(directory, { recursive: true, withFileTypes: true })\n\t\t.filter((entry) => entry.isFile() && !entry.name.startsWith(\".\"))\n\t\t.map((entry) => relative(directory, join(entry.parentPath, entry.name)).split(sep).join(\"/\"))\n\t\t.toSorted();\n}\n\n/** The client build, as its `writeBundle` hook saw it. */\ntype ClientBuild = {\n\t/** The {@link bundleBuildId} of the client bundle. */\n\tbundleId: string;\n\t/** The assets directory of the client build, such as `build/client/assets`. */\n\tassetsDirectory: string;\n\t/** The files in the assets directory ({@link filesIn}) after the client build wrote its bundle. */\n\tassets: ReadonlySet<string>;\n};\n\n/**\n * The ID of the whole build: the {@link bundleBuildId} of the client bundle,\n * with the name and the content of each file that a later build step added to\n * the assets directory. Why: React Router writes its route manifest\n * (`assets/manifest-*.js`) during the server build, and a route change, such\n * as a new path for one module, can keep the client bundle the same.\n */\nfunction appBuildId({ bundleId, assetsDirectory, assets }: ClientBuild): string {\n\tconst added = filesIn(assetsDirectory).filter((file) => !assets.has(file));\n\tif (added.length === 0) {\n\t\treturn bundleId;\n\t}\n\tconst hash = createHash(\"sha256\").update(bundleId);\n\tfor (const file of added) {\n\t\thash.update(`\\0${file}\\0`);\n\t\thash.update(readFileSync(join(assetsDirectory, file)));\n\t}\n\treturn hash.digest(\"hex\").slice(0, 16);\n}\n\n/** The `buildId` of the build manifest that the client build wrote, if any. */\nfunction writtenBuildId(clientDirectory: string): string | undefined {\n\tconst path = join(clientDirectory, BUILD_MANIFEST_FILE);\n\tif (!existsSync(path)) {\n\t\treturn undefined;\n\t}\n\tconst manifest: unknown = JSON.parse(readFileSync(path, \"utf8\"));\n\treturn typeof manifest === \"object\" &&\n\t\tmanifest != null &&\n\t\t\"buildId\" in manifest &&\n\t\ttypeof manifest.buildId === \"string\"\n\t\t? manifest.buildId\n\t\t: undefined;\n}\n\n/**\n * Records each 2xx path and the headers of each non-document response while\n * the framework's prerender pass runs. It writes them to `.app-server.json` in\n * the client build when the preview server closes, with the script hashes of\n * each HTML file.\n */\nfunction capture(server: PreviewServer, afterPass: () => void): void {\n\tconst clientDirectory = outDir(server.config, \"client\");\n\tconst started = Date.now();\n\tconst paths = new Set<string>();\n\tconst headers: BuildManifest[\"headers\"] = {};\n\tserver.middlewares.use((request, response, next) => {\n\t\t// Why `getPath`: the static stages look a file up by Hono's decoded path, such as `/café.json`.\n\t\tconst pathname = getPath(new Request(new URL(request.url ?? \"/\", \"http://localhost\")));\n\t\t// Why: Node keeps the headers that `writeHead` gets readable only when a header was set first.\n\t\tresponse.setHeader(CAPTURE_MARKER, \"1\");\n\t\tresponse.once(\"finish\", () => {\n\t\t\tif (response.statusCode < 200 || response.statusCode >= 300) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst key = manifestKey(pathname);\n\t\t\tpaths.add(key);\n\t\t\t// Why skip documents: the framework sets their headers for each request (a nonce, the\n\t\t\t// host), so the headers of the build's request are wrong for every other one.\n\t\t\tif (String(response.getHeader(\"content-type\") ?? \"\").startsWith(\"text/html\")) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst recorded: Record<string, string> = {};\n\t\t\tfor (const [name, value] of Object.entries(response.getHeaders())) {\n\t\t\t\t// Why skip index names: after a `setHeader`, Node stores a flat header array from\n\t\t\t\t// `writeHead`, as TanStack Start's preview server sends, under its indexes too.\n\t\t\t\tif (!UNCAPTURED_HEADERS.has(name) && !/^\\d+$/u.test(name) && value != null) {\n\t\t\t\t\trecorded[name] = Array.isArray(value) ? value.join(\", \") : String(value);\n\t\t\t\t}\n\t\t\t}\n\t\t\theaders[key] = recorded;\n\t\t});\n\t\tnext();\n\t});\n\tserver.httpServer.once(\"close\", () => {\n\t\tconst buildId = writtenBuildId(clientDirectory);\n\t\twriteBuildManifest(clientDirectory, {\n\t\t\t// Why keep it: the prerender pass runs after the client build, which derived it.\n\t\t\t...(buildId == null ? {} : { buildId }),\n\t\t\tprerendered: [...paths].toSorted(),\n\t\t\theaders: Object.fromEntries(\n\t\t\t\tObject.entries(headers).toSorted(([first], [second]) => first.localeCompare(second)),\n\t\t\t),\n\t\t\tscriptHashes: scriptHashesOf(clientDirectory),\n\t\t});\n\t\t// Why here too: the copy step of `buildApp` runs before this pass when `appServer` comes\n\t\t// before the framework's plugin. Why sync: Vite does not wait for this listener.\n\t\t// Why each file that the pass changed, not each path: a path does not name its file, as\n\t\t// TanStack Start can write `/page` to `page.html`. Why 2 s early: a file system can keep the\n\t\t// modification time in steps of 1 or 2 s.\n\t\twriteAllCopies(clientDirectory, { changedSince: started - 2000 });\n\t\tafterPass();\n\t});\n}\n\n/**\n * The brotli quality of the copies. Why 9, not the highest (11): on a docs\n * build with 70 MB of text, 11 adds 46 s to the build and 9 adds 0.6 s. The\n * copies of 9 are 9% larger, and still 25% smaller than the gzip copies.\n */\nconst BROTLI_QUALITY = 9;\n\n/**\n * Writes the compressed copies (`.<file>.gz` and `.<file>.br`) of the file at\n * `path` when the server compresses the file: a compressible type of 1 KiB\n * or more. It writes a copy only when it is smaller: the gzip copy than the\n * file, and the brotli copy than the gzip copy. Else it removes an old copy,\n * so a copy from an earlier build never replaces a changed file.\n */\nfunction writeCopies(path: string): void {\n\tconst bytes =\n\t\tisCompressible(contentType(path, {})) &&\n\t\tstatSync(path, { throwIfNoEntry: false })?.isFile() === true\n\t\t\t? readFileSync(path)\n\t\t\t: undefined;\n\t// Why the highest gzip level: the build compresses each file once, and each response sends fewer bytes.\n\tconst gzip =\n\t\tbytes == null || bytes.byteLength < MIN_COMPRESS_BYTES\n\t\t\t? undefined\n\t\t\t: gzipSync(bytes, { level: constants.Z_BEST_COMPRESSION });\n\tconst gzipCopy =\n\t\tgzip != null && bytes != null && gzip.byteLength < bytes.byteLength ? gzip : undefined;\n\tconst brotli =\n\t\tgzipCopy == null || bytes == null\n\t\t\t? undefined\n\t\t\t: brotliCompressSync(bytes, {\n\t\t\t\t\tparams: {\n\t\t\t\t\t\t[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,\n\t\t\t\t\t\t[constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY,\n\t\t\t\t\t\t[constants.BROTLI_PARAM_SIZE_HINT]: bytes.byteLength,\n\t\t\t\t\t},\n\t\t\t\t});\n\tconst brotliCopy =\n\t\tbrotli != null && gzipCopy != null && brotli.byteLength < gzipCopy.byteLength\n\t\t\t? brotli\n\t\t\t: undefined;\n\tconst copies: readonly (readonly [Encoding, Uint8Array | undefined])[] = [\n\t\t[\"gzip\", gzipCopy],\n\t\t[\"br\", brotliCopy],\n\t];\n\tfor (const [encoding, copy] of copies) {\n\t\tconst copyPath = join(dirname(path), copyName(basename(path), encoding));\n\t\tif (copy == null) {\n\t\t\trmSync(copyPath, { force: true });\n\t\t} else {\n\t\t\twriteFileSync(copyPath, copy);\n\t\t}\n\t}\n}\n\n/**\n * Runs {@link writeCopies} for each file in the client build, except dotfiles\n * such as the copies. With `changedSince`, only for a file that changed at or\n * after that time, in milliseconds since the epoch.\n */\nfunction writeAllCopies(\n\tclientDirectory: string,\n\t{ changedSince }: { changedSince?: number } = {},\n): void {\n\tif (!existsSync(clientDirectory)) {\n\t\treturn;\n\t}\n\tfor (const entry of readdirSync(clientDirectory, { recursive: true, withFileTypes: true })) {\n\t\tconst path = join(entry.parentPath, entry.name);\n\t\t// Why skip dotfiles: the server never sends one, such as `.app-server.json`.\n\t\tif (\n\t\t\tentry.isFile() &&\n\t\t\t!entry.name.startsWith(\".\") &&\n\t\t\t(changedSince == null ||\n\t\t\t\t(statSync(path, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= changedSince)\n\t\t) {\n\t\t\twriteCopies(path);\n\t\t}\n\t}\n}\n\n/**\n * The Vite plugin for `@ngrok/app-server`. Put it next to the framework's\n * plugin.\n *\n * - It adds the server entry to the server build, such as\n * `build/server/app-server.js` on the node host. The entry bundles the app\n * (the default export of `app`) with the framework's server module, so the\n * server gets the app's path aliases and its one copy of the framework.\n * The framework's own entry does not change. When a runtime runs the entry\n * as its main module, the entry starts the server.\n * - In a build, it bundles each dependency into the server build. It copies\n * each package that stays external into `node_modules` in the server build.\n * So the build directory runs with no install.\n * - After the client build, it writes `.app-server.json` in the client\n * build with the build ID: a hash of the client bundle. After the build,\n * it adds the files that the server build wrote to the client's assets\n * directory, such as React Router's route manifest. The `buildId` plugin\n * sends the ID.\n * - During the framework's prerender pass, it records each prerendered path\n * and the headers of each prerendered file that is not an HTML document into\n * `.app-server.json` in the client build. The `prerendered` plugin replays\n * the headers. A document's headers depend on its request, so they are not\n * recorded.\n * - After the build and after the prerender pass, it records the hash of each\n * inline script of each HTML file in `.app-server.json`, for the\n * `contentSecurityPolicy` plugin. It also writes a gzip copy (`.<file>.gz`)\n * and a brotli copy (`.<file>.br`) next to each text file of 1 KiB or more\n * in the client build, HTML included. The static stages send a copy, so the\n * server does not compress these files for each request.\n *\n * @example\n * // vite.config.ts\n * export default defineConfig({ plugins: [reactRouter(), appServer()] });\n */\nexport function appServer(options: AppServerOptions = {}): Plugin[] {\n\tconst host = options.host ?? node();\n\t// Why one value: `configResolved` sets all three, so no hook sees a config with no framework.\n\tlet resolved:\n\t\t| { config: ResolvedConfig; framework: FrameworkBuild; appModule: string | undefined }\n\t\t| undefined;\n\tlet clientBuild: ClientBuild | undefined;\n\tconst copies: Plugin = {\n\t\tname: \"@ngrok/app-server:compressed-copies\",\n\t\t// Why last: the framework prerenders in a `buildApp` hook of an `enforce: \"post\"` plugin.\n\t\tenforce: \"post\",\n\t\tbuildApp: {\n\t\t\torder: \"post\",\n\t\t\thandler: async (builder) => {\n\t\t\t\tconst clientDirectory = outDir(builder.config, \"client\");\n\t\t\t\tcompleteBuildManifest(\n\t\t\t\t\tclientDirectory,\n\t\t\t\t\tclientBuild == null ? undefined : appBuildId(clientBuild),\n\t\t\t\t);\n\t\t\t\twriteAllCopies(clientDirectory);\n\t\t\t\thost.output?.(hostOutput(builder.config, host));\n\t\t\t},\n\t\t},\n\t};\n\tconst main: Plugin = {\n\t\tname: \"@ngrok/app-server\",\n\t\tconfigResolved: (config) => {\n\t\t\tconst framework = options.framework ?? detectFramework(config.plugins);\n\t\t\tframework.validate?.(config);\n\t\t\tresolved = {\n\t\t\t\tconfig,\n\t\t\t\tframework,\n\t\t\t\tappModule:\n\t\t\t\t\toptions.app == null ? defaultApp(config.root) : resolve(config.root, options.app),\n\t\t\t};\n\t\t},\n\t\tbuildStart() {\n\t\t\t// Why a chunk and not an input: the framework's own entry stays the same, and its prerender\n\t\t\t// preview reads that entry.\n\t\t\tif (isServerBuild(this.environment)) {\n\t\t\t\tthis.emitFile({ type: \"chunk\", id: SERVER_ENTRY_ID, fileName: host.entryFileName });\n\t\t\t}\n\t\t},\n\t\twriteBundle(output, bundle) {\n\t\t\tif (this.environment.name === \"client\") {\n\t\t\t\tconst directory = output.dir ?? outDir(this.environment.config, \"client\");\n\t\t\t\tconst assetsDirectory = join(directory, this.environment.config.build.assetsDir);\n\t\t\t\tclientBuild = {\n\t\t\t\t\tbundleId: bundleBuildId(bundle),\n\t\t\t\t\tassetsDirectory,\n\t\t\t\t\tassets: new Set(filesIn(assetsDirectory)),\n\t\t\t\t};\n\t\t\t\twriteBuildManifest(directory, {\n\t\t\t\t\tbuildId: clientBuild.bundleId,\n\t\t\t\t\tprerendered: [],\n\t\t\t\t\theaders: {},\n\t\t\t\t\tscriptHashes: {},\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\trenderStart(output) {\n\t\t\t// Why: the server entry uses `import.meta.url`, and the CLI loads it as an ES module.\n\t\t\tif (this.environment.name === SERVER_ENVIRONMENT && output.format !== \"es\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@ngrok/app-server needs an ES module server build, and this build has the format \"${output.format}\".`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tresolveId: (id) => (id === SERVER_ENTRY_ID ? RESOLVED_SERVER_ENTRY_ID : undefined),\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SERVER_ENTRY_ID || resolved == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst { config, framework, appModule } = resolved;\n\t\t\tconst clientDirectory = outDir(config, \"client\");\n\t\t\tconst serverDirectory = outDir(config, SERVER_ENVIRONMENT);\n\t\t\tconst fromClient = relative(clientDirectory, serverDirectory);\n\t\t\t// Why: the static stages serve each file in the client build, so they would serve the server's\n\t\t\t// code. Why a build only: development serves no build directory.\n\t\t\tif (\n\t\t\t\tthis.environment.mode === \"build\" &&\n\t\t\t\t!fromClient.startsWith(\"..\") &&\n\t\t\t\t!isAbsolute(fromClient)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@ngrok/app-server needs the server build outside the client build, and both are in ${clientDirectory}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Why a URL in a build: the build can move, and the client build stays next to it.\n\t\t\tconst fromEntry = relative(\n\t\t\t\tdirname(join(serverDirectory, host.entryFileName)),\n\t\t\t\tclientDirectory,\n\t\t\t).replaceAll(\"\\\\\", \"/\");\n\t\t\treturn serverEntrySource({\n\t\t\t\tframework,\n\t\t\t\thost,\n\t\t\t\tappModule,\n\t\t\t\tclientDirectory:\n\t\t\t\t\tthis.environment.mode === \"build\"\n\t\t\t\t\t\t? `new URL(${JSON.stringify(`${fromEntry}/`)}, import.meta.url).href`\n\t\t\t\t\t\t: JSON.stringify(clientDirectory),\n\t\t\t});\n\t\t},\n\t\tconfigurePreviewServer: (server) => {\n\t\t\tif (resolved?.framework.isPrerenderPass(server) === true) {\n\t\t\t\t// Why the preview's config: the framework starts the preview with a new instance of this plugin.\n\t\t\t\tcapture(server, () => host.output?.(hostOutput(server.config, host)));\n\t\t\t}\n\t\t},\n\t};\n\treturn [main, copies, standalone()];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA,MAAM,eAAe;;;;;;;;AASrB,SAAgB,gBAAgB,WAAmB,QAAqC;CACvF,MAAM,WAAoB,KAAK,MAAM,aAAa,KAAK,WAAW,cAAc,GAAG,MAAM,CAAC;CAC1F,MAAM,QAAQ,OAAO,SAAS,UAAU;EACvC,MAAM,QACL,OAAO,aAAa,YAAY,YAAY,OAAO,QAAQ,IAAI,UAAU,KAAK,IAAI;EACnF,OAAO,OAAO,UAAU,YAAY,SAAS,OAC1C,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,SAAS,aAAa,KAAK,IAAI,CAAC,IAC3D,CAAC;CACL,CAAC;CACD,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC;AAC1B;;;;;;;AAQA,SAAgB,YAAY,WAA2B;CAEtD,OADc,UAAU,MAAM,GACnB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EF;GACA,YAAY,OAAQ,2CAAyB,2BAA2B;GACxE,KAAK,IAAI;IACR,IAAI,OAAO,4BAA4B,YAAY,MAClD,OAAO;IAER,MAAM,EAAE,QAAQ,WAAW,cAAc;IACzC,MAAM,kBAAkB,OAAO,QAAQ,QAAQ;IAC/C,MAAM,kBAAkB,OAAO,QAAQ,kBAAkB;IACzD,MAAM,aAAa,SAAS,iBAAiB,eAAe;IAG5D,IACC,KAAK,YAAY,SAAS,WAC1B,CAAC,WAAW,WAAW,IAAI,KAC3B,CAAC,WAAW,UAAU,GAEtB,MAAM,IAAI,MACT,sFAAsF,gBAAgB,EACvG;IAGD,MAAM,YAAY,SACjB,QAAQ,KAAK,iBAAiB,KAAK,aAAa,CAAC,GACjD,eACD,CAAC,CAAC,WAAW,MAAM,GAAG;IACtB,OAAO,kBAAkB;KACxB;KACA;KACA;KACA,iBACC,KAAK,YAAY,SAAS,UACvB,WAAW,KAAK,UAAU,GAAG,UAAU,EAAE,EAAE,2BAC3C,KAAK,UAAU,eAAe;IACnC,CAAC;GACF;GACA,yBAAyB,WAAW;IACnC,IAAI,UAAU,UAAU,gBAAgB,MAAM,MAAM,MAEnD,QAAQ,cAAc,KAAK,SAAS,WAAW,OAAO,QAAQ,IAAI,CAAC,CAAC;GAEtE;EAEU;EAAG;GAtGb,MAAM;GAEN,SAAS;GACT,UAAU;IACT,OAAO;IACP,SAAS,OAAO,YAAY;KAC3B,MAAM,kBAAkB,OAAO,QAAQ,QAAQ,QAAQ;KACvD,sBACC,iBACA,eAAe,OAAO,SAAY,WAAW,WAAW,CACzD;KACA,eAAe,eAAe;KAC9B,KAAK,SAAS,WAAW,QAAQ,QAAQ,IAAI,CAAC;IAC/C;GACD;EAwFkB;EAAG,WAAW;CAAC;AACnC"}
package/dist/vite.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as appServer, i as SERVER_ENTRY_ID, n as FrameworkBuild, o as serverEntrySource, r as HostBuild, t as AppServerOptions } from "./index-oSE-tYRW.js";
2
- export { AppServerOptions, FrameworkBuild, HostBuild, SERVER_ENTRY_ID, appServer, serverEntrySource };
1
+ import { a as SERVER_ENTRY_ID, i as HostOutput, n as FrameworkBuild, o as appServer, r as HostBuild, s as serverEntrySource, t as AppServerOptions } from "./index-Bo5G9LuQ.js";
2
+ export { AppServerOptions, FrameworkBuild, HostBuild, HostOutput, SERVER_ENTRY_ID, appServer, serverEntrySource };
package/dist/vite.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as appServer, r as serverEntrySource, t as SERVER_ENTRY_ID } from "./vite-mYZ2Y69u.js";
1
+ import { n as appServer, r as serverEntrySource, t as SERVER_ENTRY_ID } from "./vite-iioAoxSt.js";
2
2
 
3
3
  export { SERVER_ENTRY_ID, appServer, serverEntrySource };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ngrok/app-server",
3
- "version": "0.2.0",
4
- "description": "A composable Hono app server for React Router and TanStack Start: prerendered pages, streamed compression, structured logs, and clean shutdown on Node, Bun, and Deno.",
3
+ "version": "0.3.0",
4
+ "description": "A composable Hono app server for React Router and TanStack Start: prerendered pages, streamed compression, structured logs, and clean shutdown on Node, Bun, Deno, and Vercel.",
5
5
  "homepage": "https://github.com/ngrok/app-server#readme",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ngrok/app-server/issues"
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/index.d.ts",
26
26
  "import": "./dist/index.js"
27
27
  },
28
+ "./client": {
29
+ "types": "./dist/client.d.ts",
30
+ "import": "./dist/client.js"
31
+ },
28
32
  "./node": {
29
33
  "types": "./dist/node.d.ts",
30
34
  "import": "./dist/node.js"
@@ -49,6 +53,14 @@
49
53
  "types": "./dist/tanstack-start-vite.d.ts",
50
54
  "import": "./dist/tanstack-start-vite.js"
51
55
  },
56
+ "./vercel": {
57
+ "types": "./dist/vercel.d.ts",
58
+ "import": "./dist/vercel.js"
59
+ },
60
+ "./vercel/vite": {
61
+ "types": "./dist/vercel-vite.d.ts",
62
+ "import": "./dist/vercel-vite.js"
63
+ },
52
64
  "./vite": {
53
65
  "types": "./dist/vite.d.ts",
54
66
  "import": "./dist/vite.js"
@@ -62,11 +74,14 @@
62
74
  "devDependencies": {
63
75
  "@changesets/changelog-github": "1.0.1",
64
76
  "@changesets/cli": "3.0.3",
77
+ "@fixture/cjs-greeting": "link:test/fixtures/cjs-greeting",
65
78
  "@react-router/dev": "8.5.1",
79
+ "@react-router/serve": "8.5.1",
66
80
  "@tanstack/react-router": "1.170.46",
67
81
  "@tanstack/react-start": "1.169.4",
68
- "@types/node": "24.19.2",
82
+ "@types/node": "26.6.6",
69
83
  "@vitejs/plugin-react": "6.1.2",
84
+ "happy-dom": "20.14.6",
70
85
  "oxfmt": "0.75.0",
71
86
  "oxlint": "1.90.0",
72
87
  "oxlint-tsgolint": "7.0.2005",
@@ -80,10 +95,14 @@
80
95
  "zod": "4.6.7"
81
96
  },
82
97
  "peerDependencies": {
98
+ "@tanstack/react-router": "^1.170.0",
83
99
  "react-router": "^8.5.0",
84
100
  "vite": "^8.3.0"
85
101
  },
86
102
  "peerDependenciesMeta": {
103
+ "@tanstack/react-router": {
104
+ "optional": true
105
+ },
87
106
  "react-router": {
88
107
  "optional": true
89
108
  },
@@ -92,10 +111,11 @@
92
111
  }
93
112
  },
94
113
  "engines": {
95
- "node": "^24.0.0"
114
+ "node": "^26.0.0"
96
115
  },
97
116
  "scripts": {
98
117
  "build": "tsdown",
118
+ "bench": "node ./test/bench.ts",
99
119
  "changeset": "changeset",
100
120
  "fmt": "oxfmt --write .",
101
121
  "fmt:check": "oxfmt --check .",
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-manifest-8NfD1wnO.js","names":[],"sources":["../src/core/build-manifest.ts"],"sourcesContent":["import type { StaticFiles } from \"./types.js\";\n\n/**\n * The file under the client build that the Vite plugin writes during the\n * prerender pass. It is a dotfile, so the static stages never serve it.\n */\nexport const BUILD_MANIFEST_FILE = \".app-server.json\";\n\n/** What the Vite plugin records during the prerender pass. */\nexport type BuildManifest = {\n\t/** The URL paths that answered with a 2xx, sorted. */\n\tprerendered: string[];\n\t/** The headers of each prerendered file that is not an HTML document, by URL path. */\n\theaders: Record<string, Record<string, string>>;\n};\n\n/**\n * The key for a URL path in {@link BuildManifest}: the path with no trailing\n * slash, so `/a/` and `/a` share headers. The root stays `/`.\n *\n * @example\n * manifestKey(\"/components/button/\"); // => \"/components/button\"\n */\nexport function manifestKey(pathname: string): string {\n\tconst trimmed = pathname.replace(/\\/+$/u, \"\");\n\treturn trimmed === \"\" ? \"/\" : trimmed;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t!Array.isArray(value) &&\n\t\tObject.values(value).every((entry) => typeof entry === \"string\")\n\t);\n}\n\n/**\n * Reads the build manifest of a client build. A build with no file has an\n * empty one. A file in any other shape throws, so a bad build stops startup.\n */\nexport async function readBuildManifest(files: StaticFiles): Promise<BuildManifest> {\n\tconst path = `/${BUILD_MANIFEST_FILE}`;\n\tif ((await files.stat(path))?.kind !== \"file\") {\n\t\treturn { prerendered: [], headers: {} };\n\t}\n\tconst parsed: unknown = await new Response(await files.open(path)).json();\n\tif (\n\t\ttypeof parsed !== \"object\" ||\n\t\tparsed == null ||\n\t\t!(\"prerendered\" in parsed) ||\n\t\t!Array.isArray(parsed.prerendered) ||\n\t\t!parsed.prerendered.every((entry) => typeof entry === \"string\") ||\n\t\t!(\"headers\" in parsed) ||\n\t\ttypeof parsed.headers !== \"object\" ||\n\t\tparsed.headers == null\n\t) {\n\t\tthrow new Error(\n\t\t\t`${BUILD_MANIFEST_FILE} must hold a \"prerendered\" list and a \"headers\" object.`,\n\t\t);\n\t}\n\tconst headers: Record<string, Record<string, string>> = {};\n\tfor (const [key, value] of Object.entries(parsed.headers)) {\n\t\tif (!isStringRecord(value)) {\n\t\t\tthrow new Error(`${BUILD_MANIFEST_FILE}: the headers for ${key} must be strings.`);\n\t\t}\n\t\theaders[key] = value;\n\t}\n\treturn { prerendered: parsed.prerendered, headers };\n}\n"],"mappings":";;;;;AAMA,MAAa,sBAAsB;;;;;;;;AAiBnC,SAAgB,YAAY,UAA0B;CACrD,MAAM,UAAU,SAAS,QAAQ,SAAS,EAAE;CAC5C,OAAO,YAAY,KAAK,MAAM;AAC/B;AAEA,SAAS,eAAe,OAAiD;CACxE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,UAAU,OAAO,UAAU,QAAQ;AAEjE;;;;;AAMA,eAAsB,kBAAkB,OAA4C;CACnF,MAAM,OAAO,IAAI;CACjB,KAAK,MAAM,MAAM,KAAK,IAAI,EAAC,EAAG,SAAS,QACtC,OAAO;EAAE,aAAa,CAAC;EAAG,SAAS,CAAC;CAAE;CAEvC,MAAM,SAAkB,MAAM,IAAI,SAAS,MAAM,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK;CACxE,IACC,OAAO,WAAW,YAClB,UAAU,QACV,EAAE,iBAAiB,WACnB,CAAC,MAAM,QAAQ,OAAO,WAAW,KACjC,CAAC,OAAO,YAAY,OAAO,UAAU,OAAO,UAAU,QAAQ,KAC9D,EAAE,aAAa,WACf,OAAO,OAAO,YAAY,YAC1B,OAAO,WAAW,MAElB,MAAM,IAAI,MACT,GAAG,oBAAoB,wDACxB;CAED,MAAM,UAAkD,CAAC;CACzD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,OAAO,GAAG;EAC1D,IAAI,CAAC,eAAe,KAAK,GACxB,MAAM,IAAI,MAAM,GAAG,oBAAoB,oBAAoB,IAAI,kBAAkB;EAElF,QAAQ,OAAO;CAChB;CACA,OAAO;EAAE,aAAa,OAAO;EAAa;CAAQ;AACnD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deno-DNRgzHrk.js","names":[],"sources":["../src/node/runtimes/deno.ts"],"sourcesContent":["import type { FetchHandler, StartedListener } from \"../../core/types.js\";\nimport { listenerUrl } from \"./listen-options.js\";\nimport type { ListenOptions } from \"./listen-options.js\";\n\n/** The part of Deno's server that the listener uses. */\ntype DenoServer = {\n\taddr: { port: number };\n\tshutdown: () => Promise<void>;\n};\n\n/** The part of the `Deno` global that the listener uses. */\ntype DenoGlobal = {\n\tserve: (\n\t\toptions: { port: number; hostname?: string; onListen: () => void },\n\t\thandler: (\n\t\t\trequest: Request,\n\t\t\tinfo: { remoteAddr: { hostname: string } },\n\t\t) => Response | Promise<Response>,\n\t) => DenoServer;\n};\n\n/** Wraps a response body so the listener can end it at the deadline. `open` holds its closer while the body is open. */\nfunction closableResponse(response: Response, open: Set<() => void>): Response {\n\tif (response.body == null) {\n\t\treturn response;\n\t}\n\tconst reader = response.body.getReader();\n\tlet force: () => void;\n\tconst body = new ReadableStream<Uint8Array>({\n\t\tstart(controller) {\n\t\t\tforce = () => {\n\t\t\t\topen.delete(force);\n\t\t\t\tcontroller.error(new Error(\"The shutdown deadline passed.\"));\n\t\t\t\tvoid reader.cancel();\n\t\t\t};\n\t\t\topen.add(force);\n\t\t},\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done) {\n\t\t\t\t\topen.delete(force);\n\t\t\t\t\tcontroller.close();\n\t\t\t\t} else {\n\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\topen.delete(force);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tasync cancel(reason) {\n\t\t\topen.delete(force);\n\t\t\treturn reader.cancel(reason);\n\t\t},\n\t});\n\treturn new Response(body, response);\n}\n\n/** Listens with `Deno.serve`. */\nexport async function listen(\n\tfetch: FetchHandler,\n\toptions: ListenOptions,\n): Promise<StartedListener> {\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- `Deno` is a runtime global with no types in this package.\n\tconst deno = Reflect.get(globalThis, \"Deno\") as DenoGlobal;\n\t// Why: Deno has no forced close, and `shutdown()` waits for each open request. At the\n\t// deadline, the listener answers each pending request with a 503 and ends each open body.\n\tconst open = new Set<() => void>();\n\tconst server = deno.serve(\n\t\t{\n\t\t\tport: options.port,\n\t\t\t...(options.hostname == null ? {} : { hostname: options.hostname }),\n\t\t\t// Why a no-op: the server logs its own startup line.\n\t\t\tonListen: () => {},\n\t\t},\n\t\tasync (request, info) => {\n\t\t\tconst forced = Promise.withResolvers<Response>();\n\t\t\tconst force = () => {\n\t\t\t\topen.delete(force);\n\t\t\t\tforced.resolve(new Response(null, { status: 503 }));\n\t\t\t};\n\t\t\topen.add(force);\n\t\t\tconst answer = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn closableResponse(\n\t\t\t\t\t\tawait fetch(request, { remoteAddress: info.remoteAddr.hostname }),\n\t\t\t\t\t\topen,\n\t\t\t\t\t);\n\t\t\t\t} finally {\n\t\t\t\t\topen.delete(force);\n\t\t\t\t}\n\t\t\t})();\n\t\t\treturn Promise.race([answer, forced.promise]);\n\t\t},\n\t);\n\treturn {\n\t\turl: listenerUrl(options.hostname, server.addr.port),\n\t\tstop: async ({ deadlineMs }) => {\n\t\t\tconst deadline = setTimeout(() => {\n\t\t\t\tfor (const force of open) {\n\t\t\t\t\tforce();\n\t\t\t\t}\n\t\t\t}, deadlineMs);\n\t\t\tawait server.shutdown();\n\t\t\tclearTimeout(deadline);\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAsBA,SAAS,iBAAiB,UAAoB,MAAiC;CAC9E,IAAI,SAAS,QAAQ,MACpB,OAAO;CAER,MAAM,SAAS,SAAS,KAAK,UAAU;CACvC,IAAI;CACJ,MAAM,OAAO,IAAI,eAA2B;EAC3C,MAAM,YAAY;GACjB,cAAc;IACb,KAAK,OAAO,KAAK;IACjB,WAAW,sBAAM,IAAI,MAAM,+BAA+B,CAAC;IAC3D,AAAK,OAAO,OAAO;GACpB;GACA,KAAK,IAAI,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