@ngrok/app-server 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -27
- package/dist/{build-id-C6sYO9Yp.js → build-id-B0448vZH.js} +27 -2
- package/dist/build-id-B0448vZH.js.map +1 -0
- package/dist/{build-manifest-UDNk81Ce.js → build-manifest-DBMWe3Lx.js} +12 -2
- package/dist/build-manifest-DBMWe3Lx.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/client-browser.js +1 -1
- package/dist/client.js +1 -1
- package/dist/{entry-CM6Ma-Tv.d.ts → create-server-D4-nVOVJ.d.ts} +56 -70
- package/dist/{create-server-DkTeIJ8L.js → create-server-jMl2ltHD.js} +454 -394
- package/dist/create-server-jMl2ltHD.js.map +1 -0
- package/dist/entry-BPrgE_6K.d.ts +94 -0
- package/dist/entry-D9H4LA9c.js +351 -0
- package/dist/entry-D9H4LA9c.js.map +1 -0
- package/dist/{index-Bo5G9LuQ.d.ts → index-Db7dspq6.d.ts} +6 -1
- package/dist/index.d.ts +5 -14
- package/dist/index.js +3 -3
- package/dist/{load-entry-CmkdlmDX.js → load-entry-D7r0mjEp.js} +4 -4
- package/dist/{load-entry-CmkdlmDX.js.map → load-entry-D7r0mjEp.js.map} +1 -1
- package/dist/{node-BFH82eeL.js → node-C1qudLs_.js} +2 -2
- package/dist/{node-BFH82eeL.js.map → node-C1qudLs_.js.map} +1 -1
- package/dist/node-vite.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/react-router-vite.d.ts +1 -1
- package/dist/react-router.d.ts +3 -2
- package/dist/react-router.js +31 -2
- package/dist/react-router.js.map +1 -1
- package/dist/request-context-BtQ87VYb.js.map +1 -1
- package/dist/{script-hashes-hqUk6kG7.js → script-hashes-C6hQ5XnP.js} +22 -4
- package/dist/script-hashes-C6hQ5XnP.js.map +1 -0
- package/dist/{serve-Cc-ADdhZ.js → serve-E0hSGe6_.js} +2 -2
- package/dist/{serve-Cc-ADdhZ.js.map → serve-E0hSGe6_.js.map} +1 -1
- package/dist/{stale-build-navigation-PnMLtTF8.js → stale-build-navigation-rg5xxmTr.js} +2 -2
- package/dist/{stale-build-navigation-PnMLtTF8.js.map → stale-build-navigation-rg5xxmTr.js.map} +1 -1
- package/dist/{start-Cb3kknlF.js → start-CifYPRq1.js} +34 -6
- package/dist/start-CifYPRq1.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +1 -1
- package/dist/tanstack-start.d.ts +2 -2
- package/dist/testing.d.ts +56 -0
- package/dist/testing.js +114 -0
- package/dist/testing.js.map +1 -0
- package/dist/{trailing-slash-DX7NB88H.d.ts → trailing-slash-CFSv_Gzx.d.ts} +2 -2
- package/dist/{types-DLYxYS6M.d.ts → types-j29vspx_.d.ts} +16 -2
- package/dist/vercel-pages.d.ts +32 -0
- package/dist/vercel-pages.js +54 -0
- package/dist/vercel-pages.js.map +1 -0
- package/dist/vercel-vite.d.ts +30 -9
- package/dist/vercel-vite.js +160 -17
- package/dist/vercel-vite.js.map +1 -1
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +2 -2
- package/dist/{vite-iioAoxSt.js → vite-BDREIgiH.js} +45 -33
- package/dist/vite-BDREIgiH.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +5 -1
- package/dist/build-id-C6sYO9Yp.js.map +0 -1
- package/dist/build-manifest-UDNk81Ce.js.map +0 -1
- package/dist/create-server-DkTeIJ8L.js.map +0 -1
- package/dist/entry-CenmvESk.js +0 -116
- package/dist/entry-CenmvESk.js.map +0 -1
- package/dist/script-hashes-hqUk6kG7.js.map +0 -1
- package/dist/start-Cb3kknlF.js.map +0 -1
- package/dist/vite-iioAoxSt.js.map +0 -1
package/dist/entry-CenmvESk.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { t as errorAttributes } from "./log-BP6xXXZl.js";
|
|
2
|
-
import { _ as abortShutdownSignal, r as serverInternals } from "./create-server-DkTeIJ8L.js";
|
|
3
|
-
import { a as keptFiles } from "./static-files-Beju9riB.js";
|
|
4
|
-
import { r as readBuildManifest } from "./build-manifest-UDNk81Ce.js";
|
|
5
|
-
|
|
6
|
-
// src/core/entry.ts
|
|
7
|
-
/** The version of the contract between the CLI and the `appServer` export of a build. */
|
|
8
|
-
const ENTRY_PROTOCOL = 2;
|
|
9
|
-
/**
|
|
10
|
-
* The `appServer` export of a server build: an app from `createServer`, the
|
|
11
|
-
* host, and the framework adapter for each mode. The `appServer` Vite plugin
|
|
12
|
-
* generates this export. Call this for a build without the plugin.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
|
|
16
|
-
*/
|
|
17
|
-
function createEntry({ app, host, framework, clientDirectory }) {
|
|
18
|
-
const internals = serverInternals(app);
|
|
19
|
-
if (internals == null) throw new Error("The app is not from `createServer()` of the copy of @ngrok/app-server in this build.");
|
|
20
|
-
internals.setRequestStore(host.storage);
|
|
21
|
-
const setupInfo = async (runtime) => {
|
|
22
|
-
const directory = clientDirectory ?? runtime.clientDirectory;
|
|
23
|
-
if (directory == null) throw new Error(`Give createEntry a clientDirectory: the ${runtime.name} adapter does not know the client build.`);
|
|
24
|
-
return {
|
|
25
|
-
files: host.files(directory),
|
|
26
|
-
isDataRequest: runtime.isDataRequest ?? (() => false),
|
|
27
|
-
contentTypes: runtime.contentTypes ?? {},
|
|
28
|
-
gzip: host.gzip,
|
|
29
|
-
logger: internals.logger
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
/** Runs each plugin's `setup` for production, and gives the framework's run side. */
|
|
33
|
-
const prepareProduction = async () => {
|
|
34
|
-
const runtime = framework("production");
|
|
35
|
-
const shared = await setupInfo(runtime);
|
|
36
|
-
const snapshot = await shared.files.snapshot?.();
|
|
37
|
-
const files = snapshot == null ? shared.files : keptFiles(snapshot);
|
|
38
|
-
const manifest = await readBuildManifest(files);
|
|
39
|
-
const info = {
|
|
40
|
-
...shared,
|
|
41
|
-
files,
|
|
42
|
-
mode: "production",
|
|
43
|
-
prerenderedPaths: runtime.prerenderedPaths ?? manifest.prerendered,
|
|
44
|
-
capturedHeaders: new Map(Object.entries(manifest.headers)),
|
|
45
|
-
scriptHashes: new Map(Object.entries(manifest.scriptHashes)),
|
|
46
|
-
buildId: manifest.buildId
|
|
47
|
-
};
|
|
48
|
-
await internals.prepare(info);
|
|
49
|
-
return runtime;
|
|
50
|
-
};
|
|
51
|
-
let preparing;
|
|
52
|
-
/**
|
|
53
|
-
* The production run side, set up once. Why forget a failure: a serverless
|
|
54
|
-
* instance stays up, so the next request runs each `setup` again.
|
|
55
|
-
*/
|
|
56
|
-
const production = async () => {
|
|
57
|
-
preparing ??= prepareProduction().catch((error) => {
|
|
58
|
-
preparing = void 0;
|
|
59
|
-
throw error;
|
|
60
|
-
});
|
|
61
|
-
return preparing;
|
|
62
|
-
};
|
|
63
|
-
let development;
|
|
64
|
-
return {
|
|
65
|
-
protocol: 2,
|
|
66
|
-
app,
|
|
67
|
-
start: async () => {
|
|
68
|
-
const runtime = await production();
|
|
69
|
-
const server = await internals.listen(runtime, host.listeners?.());
|
|
70
|
-
host.lifecycle?.onStop(async () => server.shutdown().catch((error) => {
|
|
71
|
-
internals.logger.log("error", "shutdown failed", errorAttributes(error));
|
|
72
|
-
throw error;
|
|
73
|
-
}));
|
|
74
|
-
},
|
|
75
|
-
fetch: async (request, bindings) => {
|
|
76
|
-
const runtime = await production().catch((error) => {
|
|
77
|
-
internals.logger.log("error", "setup failed", errorAttributes(error));
|
|
78
|
-
throw error;
|
|
79
|
-
});
|
|
80
|
-
return app.fetch(request, {
|
|
81
|
-
...bindings,
|
|
82
|
-
framework: runtime
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
fetchDev: async (request, bindings, devServer) => {
|
|
86
|
-
development ??= framework("development");
|
|
87
|
-
await internals.prepare({
|
|
88
|
-
...await setupInfo(development),
|
|
89
|
-
mode: "development",
|
|
90
|
-
devServer,
|
|
91
|
-
prerenderedPaths: development.prerenderedPaths,
|
|
92
|
-
capturedHeaders: /* @__PURE__ */ new Map(),
|
|
93
|
-
scriptHashes: /* @__PURE__ */ new Map(),
|
|
94
|
-
buildId: void 0
|
|
95
|
-
});
|
|
96
|
-
return app.fetch(request, {
|
|
97
|
-
...bindings,
|
|
98
|
-
framework: development
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
stopPlugins: internals.stopPlugins,
|
|
102
|
-
abortShutdownSignal
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Whether a value is an entry of this protocol version.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* isAppServerEntry((await import("./build/server/app-server.js")).appServer); // => true
|
|
110
|
-
*/
|
|
111
|
-
function isAppServerEntry(value) {
|
|
112
|
-
return typeof value === "object" && value != null && "protocol" in value && value.protocol === 2;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export { isAppServerEntry as n, createEntry as t };
|
|
116
|
-
//# sourceMappingURL=entry-CenmvESk.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-CenmvESk.js","names":[],"sources":["../src/core/entry.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport { readBuildManifest } from \"./build-manifest.js\";\nimport { serverInternals } from \"./create-server.js\";\nimport type { AppServer } from \"./create-server.js\";\nimport { errorAttributes } from \"./log.js\";\nimport { abortShutdownSignal } from \"./shutdown.js\";\nimport { keptFiles } from \"./static-files.js\";\nimport type {\n\tAppServerEnv,\n\tFetchHandler,\n\tFrameworkRuntime,\n\tHostRuntime,\n\tListenerBindings,\n\tMode,\n\tSetupInfo,\n} from \"./types.js\";\n\n/** The version of the contract between the CLI and the `appServer` export of a build. */\nexport const ENTRY_PROTOCOL = 2;\n\n/**\n * What a server build exports as `appServer`. The CLI calls it, so the copy\n * of this package in the build runs the server, and the CLI's copy runs\n * nothing.\n */\nexport type AppServerEntry = {\n\t/** The CLI refuses an entry with another version. */\n\tprotocol: typeof ENTRY_PROTOCOL;\n\t/** The app. Two entries with the same app share its plugins. */\n\tapp: AppServer;\n\t/**\n\t * Production: runs each plugin's `setup` and listens. When the host's\n\t * lifecycle stops, such as on `SIGTERM`, it shuts down.\n\t */\n\tstart: () => Promise<void>;\n\t/**\n\t * Production, for a serverless host: answers one request, and does not\n\t * listen. The first call runs each plugin's `setup`.\n\t */\n\tfetch: FetchHandler;\n\t/** Development: answers one request with the dev server inside the pipeline. */\n\tfetchDev: (\n\t\trequest: Request,\n\t\tbindings: ListenerBindings,\n\t\tdevServer: MiddlewareHandler<AppServerEnv>,\n\t) => Promise<Response>;\n\t/** Runs each plugin's `onShutdown` once, up to the shutdown deadline. */\n\tstopPlugins: () => Promise<void>;\n\t/** Aborts `shutdownSignal()` of this copy of the package. */\n\tabortShutdownSignal: () => void;\n};\n\n/** Options for {@link createEntry}. */\nexport type CreateEntryOptions = {\n\t/** The app from `createServer`. */\n\tapp: AppServer;\n\t/** The run side of the host adapter, such as `host` from `@ngrok/app-server/node`. */\n\thost: HostRuntime;\n\t/** Makes the run side of the framework adapter for a mode. */\n\tframework: (mode: Mode) => FrameworkRuntime;\n\t/**\n\t * The client build, as a file path or a `file:` URL. The entry that the\n\t * Vite plugin generates sets it.\n\t * @default the framework's `clientDirectory`\n\t */\n\tclientDirectory?: string;\n};\n\n/**\n * The `appServer` export of a server build: an app from `createServer`, the\n * host, and the framework adapter for each mode. The `appServer` Vite plugin\n * generates this export. Call this for a build without the plugin.\n *\n * @example\n * export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });\n */\nexport function createEntry({\n\tapp,\n\thost,\n\tframework,\n\tclientDirectory,\n}: CreateEntryOptions): AppServerEntry {\n\tconst internals = serverInternals(app);\n\tif (internals == null) {\n\t\tthrow new Error(\n\t\t\t\"The app is not from `createServer()` of the copy of @ngrok/app-server in this build.\",\n\t\t);\n\t}\n\tinternals.setRequestStore(host.storage);\n\tconst setupInfo = async (runtime: FrameworkRuntime) => {\n\t\tconst directory = clientDirectory ?? runtime.clientDirectory;\n\t\tif (directory == null) {\n\t\t\tthrow new Error(\n\t\t\t\t`Give createEntry a clientDirectory: the ${runtime.name} adapter does not know the client build.`,\n\t\t\t);\n\t\t}\n\t\tconst files = host.files(directory);\n\t\treturn {\n\t\t\tfiles,\n\t\t\tisDataRequest: runtime.isDataRequest ?? (() => false),\n\t\t\tcontentTypes: runtime.contentTypes ?? {},\n\t\t\tgzip: host.gzip,\n\t\t\tlogger: internals.logger,\n\t\t};\n\t};\n\t/** Runs each plugin's `setup` for production, and gives the framework's run side. */\n\tconst prepareProduction = async (): Promise<FrameworkRuntime> => {\n\t\tconst runtime = framework(\"production\");\n\t\tconst shared = await setupInfo(runtime);\n\t\tconst snapshot = await shared.files.snapshot?.();\n\t\t// Why only with a snapshot: it promises that the client build does not change while the server runs.\n\t\tconst files = snapshot == null ? shared.files : keptFiles(snapshot);\n\t\tconst manifest = await readBuildManifest(files);\n\t\tconst info: SetupInfo = {\n\t\t\t...shared,\n\t\t\tfiles,\n\t\t\tmode: \"production\",\n\t\t\tprerenderedPaths: runtime.prerenderedPaths ?? manifest.prerendered,\n\t\t\tcapturedHeaders: new Map(Object.entries(manifest.headers)),\n\t\t\tscriptHashes: new Map(Object.entries(manifest.scriptHashes)),\n\t\t\tbuildId: manifest.buildId,\n\t\t};\n\t\tawait internals.prepare(info);\n\t\treturn runtime;\n\t};\n\tlet preparing: Promise<FrameworkRuntime> | undefined;\n\t/**\n\t * The production run side, set up once. Why forget a failure: a serverless\n\t * instance stays up, so the next request runs each `setup` again.\n\t */\n\tconst production = async (): Promise<FrameworkRuntime> => {\n\t\tpreparing ??= prepareProduction().catch((error: unknown) => {\n\t\t\tpreparing = undefined;\n\t\t\tthrow error;\n\t\t});\n\t\treturn preparing;\n\t};\n\tlet development: FrameworkRuntime | undefined;\n\treturn {\n\t\tprotocol: ENTRY_PROTOCOL,\n\t\tapp,\n\t\tstart: async () => {\n\t\t\tconst runtime = await production();\n\t\t\tconst server = await internals.listen(runtime, host.listeners?.());\n\t\t\thost.lifecycle?.onStop(async () =>\n\t\t\t\tserver.shutdown().catch((error: unknown) => {\n\t\t\t\t\tinternals.logger.log(\"error\", \"shutdown failed\", errorAttributes(error));\n\t\t\t\t\tthrow error;\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tfetch: async (request, bindings) => {\n\t\t\t// Why log it: the host sends a 500 with no log, and no app handler runs before setup ends.\n\t\t\tconst runtime = await production().catch((error: unknown) => {\n\t\t\t\tinternals.logger.log(\"error\", \"setup failed\", errorAttributes(error));\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\treturn app.fetch(request, { ...bindings, framework: runtime });\n\t\t},\n\t\tfetchDev: async (request, bindings, devServer) => {\n\t\t\tdevelopment ??= framework(\"development\");\n\t\t\tawait internals.prepare({\n\t\t\t\t...(await setupInfo(development)),\n\t\t\t\tmode: \"development\",\n\t\t\t\tdevServer,\n\t\t\t\tprerenderedPaths: development.prerenderedPaths,\n\t\t\t\tcapturedHeaders: new Map(),\n\t\t\t\tscriptHashes: new Map(),\n\t\t\t\t// Why none: development has no client build, and Vite's HMR updates an open tab after each edit.\n\t\t\t\tbuildId: undefined,\n\t\t\t});\n\t\t\treturn app.fetch(request, { ...bindings, framework: development });\n\t\t},\n\t\tstopPlugins: internals.stopPlugins,\n\t\tabortShutdownSignal,\n\t};\n}\n\n/**\n * Whether a value is an entry of this protocol version.\n *\n * @example\n * isAppServerEntry((await import(\"./build/server/app-server.js\")).appServer); // => true\n */\nexport function isAppServerEntry(value: unknown): value is AppServerEntry {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"protocol\" in value &&\n\t\tvalue.protocol === ENTRY_PROTOCOL\n\t);\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,iBAAiB;;;;;;;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C;GACjE,KAAK,WAAW,OAAO,YACtB,OAAO,SAAS,CAAC,CAAC,OAAO,UAAmB;IAC3C,UAAU,OAAO,IAAI,SAAS,mBAAmB,gBAAgB,KAAK,CAAC;IACvE,MAAM;GACP,CAAC,CACF;EACD;EACA,OAAO,OAAO,SAAS,aAAa;GAEnC,MAAM,UAAU,MAAM,WAAW,CAAC,CAAC,OAAO,UAAmB;IAC5D,UAAU,OAAO,IAAI,SAAS,gBAAgB,gBAAgB,KAAK,CAAC;IACpE,MAAM;GACP,CAAC;GACD,OAAO,IAAI,MAAM,SAAS;IAAE,GAAG;IAAU,WAAW;GAAQ,CAAC;EAC9D;EACA,UAAU,OAAO,SAAS,UAAU,cAAc;GACjD,gBAAgB,UAAU,aAAa;GACvC,MAAM,UAAU,QAAQ;IACvB,GAAI,MAAM,UAAU,WAAW;IAC/B,MAAM;IACN;IACA,kBAAkB,YAAY;IAC9B,iCAAiB,IAAI,IAAI;IACzB,8BAAc,IAAI,IAAI;IAEtB,SAAS;GACV,CAAC;GACD,OAAO,IAAI,MAAM,SAAS;IAAE,GAAG;IAAU,WAAW;GAAY,CAAC;EAClE;EACA,aAAa,UAAU;EACvB;CACD;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,MAAM;AAER"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"script-hashes-hqUk6kG7.js","names":[],"sources":["../src/node/script-hashes.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFileSync, statSync } from \"node:fs\";\nimport { resolve, sep } from \"node:path\";\nimport { contentType } from \"../core/static-files.js\";\n\n/**\n * An HTML comment, or a `<script>` element. The `attributes` group is the\n * script's attributes, and the `text` group is its text. Why the comment: a\n * `<script>` tag in a comment starts no element.\n */\nconst COMMENT_OR_SCRIPT =\n\t/<!--[\\s\\S]*?-->|<script(?=[\\s/>])(?<attributes>(?:[^>\"']|\"[^\"]*\"|'[^']*')*)>(?<text>[\\s\\S]*?)<\\/script(?=[\\s/>])/giu;\n\n/** An attribute value, so that a `src=` in a value is not the `src` attribute. */\nconst ATTRIBUTE_VALUE = /[=]\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/gu;\n\n/** A `src` attribute, in attributes with no values. */\nconst SRC_ATTRIBUTE = /(?:^|[\\s/])src(?:[\\s/=]|$)/iu;\n\n/**\n * The base64 `SHA-256` of each inline script in `html`, once each, in\n * document order. Why each type: a hash of a data block, such as JSON, trusts\n * no code, and a scan that skips a type that runs breaks the page. Why LF:\n * the browser changes each CRLF and CR to LF before it hashes a script.\n *\n * @example\n * inlineScriptHashes(\"<script>go()</script>\"); // => [\"…base64…\"]\n */\nexport function inlineScriptHashes(html: string): string[] {\n\tconst hashes: string[] = [];\n\tfor (const { groups } of html.replaceAll(/\\r\\n?/gu, \"\\n\").matchAll(COMMENT_OR_SCRIPT)) {\n\t\tif (\n\t\t\tgroups?.text != null &&\n\t\t\t!SRC_ATTRIBUTE.test((groups.attributes ?? \"\").replaceAll(ATTRIBUTE_VALUE, \"=\"))\n\t\t) {\n\t\t\thashes.push(createHash(\"sha256\").update(groups.text).digest(\"base64\"));\n\t\t}\n\t}\n\treturn [...new Set(hashes)];\n}\n\n/**\n * The {@link inlineScriptHashes} of the HTML file at the URL `path` in\n * `directory`, such as Vite's public directory, or `undefined` when it has no\n * such file. Why it reads the file for each call: a developer can edit it at\n * any time, and only a request for an HTML file reads it.\n *\n * @example\n * publicScriptHashes(\"/app/public\", \"/offline.html\"); // => [\"…base64…\"]\n */\nexport function publicScriptHashes(directory: string, path: string): string[] | undefined {\n\tif (directory === \"\") {\n\t\treturn undefined;\n\t}\n\t// Why one `try`: a path that does not decode, a path with a null byte, and a file that the\n\t// developer deletes or locks between the checks each throw. The middleware then answers.\n\ttry {\n\t\tconst decoded = decodeURIComponent(path);\n\t\tconst file = resolve(directory, `.${decoded}`);\n\t\t// Why: a path such as `/../secret.html` must not leave the directory.\n\t\tif (\n\t\t\t!contentType(decoded, {}).startsWith(\"text/html\") ||\n\t\t\t!file.startsWith(`${resolve(directory)}${sep}`) ||\n\t\t\tstatSync(file, { throwIfNoEntry: false })?.isFile() !== true\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn inlineScriptHashes(readFileSync(file, \"utf8\"));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,oBACL;;AAGD,MAAM,kBAAkB;;AAGxB,MAAM,gBAAgB;;;;;;;;;;AAWtB,SAAgB,mBAAmB,MAAwB;CAC1D,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,EAAE,YAAY,KAAK,WAAW,WAAW,IAAI,CAAC,CAAC,SAAS,iBAAiB,GACnF,IACC,QAAQ,QAAQ,QAChB,CAAC,cAAc,MAAM,OAAO,cAAc,GAAE,CAAE,WAAW,iBAAiB,GAAG,CAAC,GAE9E,OAAO,KAAK,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,IAAI,CAAC,CAAC,OAAO,QAAQ,CAAC;CAGvE,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;AAC3B;;;;;;;;;;AAWA,SAAgB,mBAAmB,WAAmB,MAAoC;CACzF,IAAI,cAAc,IACjB;CAID,IAAI;EACH,MAAM,UAAU,mBAAmB,IAAI;EACvC,MAAM,OAAO,QAAQ,WAAW,IAAI,SAAS;EAE7C,IACC,CAAC,YAAY,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,WAAW,KAChD,CAAC,KAAK,WAAW,GAAG,QAAQ,SAAS,IAAI,KAAK,KAC9C,SAAS,MAAM,EAAE,gBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,MAAM,MAExD;EAED,OAAO,mBAAmB,aAAa,MAAM,MAAM,CAAC;CACrD,QAAQ;EACP;CACD;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"start-Cb3kknlF.js","names":["createServer","createHttpServer"],"sources":["../src/cli/served-apps.ts","../src/cli/start-port.ts","../src/cli/start.ts"],"sourcesContent":["import type { AppServerEntry } from \"../core/entry.js\";\n\ntype ServedApp = { entry: AppServerEntry; pending: number; replaced: boolean };\n\n/** What {@link servedApps} returns. */\ntype ServedApps = {\n\t/** Runs `handle` for a request that `entry` serves. */\n\tserve: <Result>(\n\t\tentry: AppServerEntry,\n\t\thandle: (entry: AppServerEntry) => Promise<Result>,\n\t) => Promise<Result>;\n\t/**\n\t * At exit: aborts `shutdownSignal()` and runs the `onShutdown` hooks of each\n\t * app still held. Resolves when the hooks finish or pass the deadline.\n\t */\n\tstopAll: () => Promise<void>;\n};\n\n/**\n * Tracks the apps that `app-server start` serves. An edit to `server.ts` makes a\n * new app, and the old app's plugins still hold what their `setup` opened.\n * When the last request that the old app took returns, its `onShutdown` hooks\n * run, and the tracker lets go of it. A route edit makes a new entry with the\n * same app, which keeps its plugins.\n */\nexport function servedApps(): ServedApps {\n\tlet current: ServedApp | undefined;\n\tconst served = new Set<ServedApp>();\n\t// Why keep the app until its hooks settle: `stopAll` must wait for hooks that already run.\n\t// `stopPlugins` runs the hooks once, so a second call only waits.\n\tconst retire = async (app: ServedApp) => {\n\t\ttry {\n\t\t\tawait app.entry.stopPlugins();\n\t\t} finally {\n\t\t\tserved.delete(app);\n\t\t}\n\t};\n\treturn {\n\t\tserve: async (entry, handle) => {\n\t\t\tif (current?.entry.app === entry.app) {\n\t\t\t\tcurrent.entry = entry;\n\t\t\t} else {\n\t\t\t\tif (current != null) {\n\t\t\t\t\tcurrent.replaced = true;\n\t\t\t\t\tif (current.pending === 0) {\n\t\t\t\t\t\tvoid retire(current);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrent = { entry, pending: 0, replaced: false };\n\t\t\t\tserved.add(current);\n\t\t\t}\n\t\t\tconst app = current;\n\t\t\tapp.pending += 1;\n\t\t\ttry {\n\t\t\t\treturn await handle(entry);\n\t\t\t} finally {\n\t\t\t\tapp.pending -= 1;\n\t\t\t\tif (app.replaced && app.pending === 0) {\n\t\t\t\t\tvoid retire(app);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tstopAll: async () => {\n\t\t\tawait Promise.all(\n\t\t\t\tArray.from(served, async (app) => {\n\t\t\t\t\tapp.entry.abortShutdownSignal();\n\t\t\t\t\tawait retire(app);\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t};\n}\n","import { createServer } from \"node:net\";\nimport type { Server } from \"node:net\";\n\nconst MAX_PORT = 65_535;\n\n/** Options for {@link listenFromPort}. */\nexport type ListenFromPortOptions = {\n\t/** The first port to try. 0 lets the OS pick one. */\n\tport: number;\n\t/** @default every interface */\n\thostname?: string | undefined;\n\t/** When true, a port in use throws and no other port is tried. */\n\tstrictPort: boolean;\n\t/** Runs for each port in use before the next port is tried. */\n\tonPortInUse?: (port: number) => void;\n\t/**\n\t * Runs when `strictPort` is true and the server listens on `hostname`, but\n\t * another server holds the port on a wildcard address.\n\t */\n\tonWildcardInUse?: (port: number) => void;\n};\n\n/**\n * Starts `server` on `port`. When the port is in use, it tries each next port\n * up to 65535, like Vite and `react-router-serve` do in development.\n *\n * @returns the port that the server listens on\n */\nexport async function listenFromPort(\n\tserver: Server,\n\t{ port, hostname, strictPort, onPortInUse, onWildcardInUse }: ListenFromPortOptions,\n): Promise<number> {\n\tif (port === 0) {\n\t\tawait bind(server, port, hostname);\n\t\treturn boundPort(server, port);\n\t}\n\tif (strictPort) {\n\t\t// Why a warning and not an error: a server on one other address also fails the wildcard\n\t\t// check, and that server does not share `hostname`. Vite warns for the same reason.\n\t\tconst freeOnWildcard = hostname == null || (await isFreeOnWildcard(port));\n\t\tawait bind(server, port, hostname);\n\t\tif (!freeOnWildcard) {\n\t\t\tonWildcardInUse?.(port);\n\t\t}\n\t\treturn port;\n\t}\n\tfor (let candidate = port; candidate <= MAX_PORT; candidate++) {\n\t\t// Why the wildcard check: a server on `::` and a server on `localhost` can share a port, and\n\t\t// then the browser can reach the other server.\n\t\tif (hostname == null || (await isFreeOnWildcard(candidate))) {\n\t\t\ttry {\n\t\t\t\tawait bind(server, candidate, hostname);\n\t\t\t\treturn candidate;\n\t\t\t} catch (error) {\n\t\t\t\tif (!isAddressInUse(error)) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tonPortInUse?.(candidate);\n\t}\n\tthrow new Error(`No open port from ${port} to ${MAX_PORT}.`);\n}\n\nasync function bind(server: Server, port: number, hostname: string | undefined): Promise<void> {\n\treturn new Promise<void>((resolve, reject) => {\n\t\tfunction onError(error: Error) {\n\t\t\tserver.off(\"listening\", onListening);\n\t\t\treject(error);\n\t\t}\n\t\tfunction onListening() {\n\t\t\tserver.off(\"error\", onError);\n\t\t\tresolve();\n\t\t}\n\t\tserver.once(\"error\", onError);\n\t\tserver.once(\"listening\", onListening);\n\t\tserver.listen(port, hostname);\n\t});\n}\n\nasync function isFreeOnWildcard(port: number): Promise<boolean> {\n\tconst probe = createServer();\n\ttry {\n\t\tawait bind(probe, port, undefined);\n\t} catch (error) {\n\t\tif (isAddressInUse(error)) {\n\t\t\treturn false;\n\t\t}\n\t\tthrow error;\n\t}\n\tawait new Promise<void>((resolve) => {\n\t\tprobe.close(() => {\n\t\t\tresolve();\n\t\t});\n\t});\n\treturn true;\n}\n\nfunction boundPort(server: Server, fallback: number): number {\n\tconst address = server.address();\n\treturn typeof address === \"object\" && address != null ? address.port : fallback;\n}\n\nfunction isAddressInUse(error: unknown): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === \"EADDRINUSE\";\n}\n","import { createServer as createHttpServer } from \"node:http\";\nimport { errorAttributes, jsonSink } from \"../core/log.js\";\nimport { devServerStage } from \"../node/dev-server.js\";\nimport { exitAfterFlush } from \"../node/exit.js\";\nimport { listenerUrl } from \"../node/runtimes/listen-options.js\";\nimport { requestListener } from \"../node/response-writer.js\";\nimport { parsePort } from \"../node/tcp.js\";\nimport { SERVER_ENTRY_ID } from \"../vite/index.js\";\nimport { loadEntry } from \"./load-entry.js\";\nimport { servedApps } from \"./served-apps.js\";\nimport { listenFromPort } from \"./start-port.js\";\n\n/**\n * Runs the app in development: the same pipeline as production, with Vite in\n * middleware mode inside it. Each request loads the server entry through\n * Vite's SSR runner, so an edit to a route or to the app's `server.ts` applies\n * at once. HMR shares the port.\n *\n * The port is `--port`, else `PORT`, else Vite's `server.port`. When that port is in use, the\n * server tries each next port, unless Vite's `server.strictPort` is true. The\n * host is `HOST`, else Vite's `server.host`.\n */\nexport async function start(): Promise<void> {\n\tconst vite = await import(\"vite\");\n\tconst httpServer = createHttpServer();\n\tconst viteServer = await vite.createServer({\n\t\tserver: { middlewareMode: true, ws: { server: httpServer } },\n\t\tappType: \"custom\",\n\t});\n\t// Why read it for each request: a Vite restart, such as after a config edit, replaces the environments.\n\tconst ssrRunner = () => {\n\t\tconst { ssr } = viteServer.environments;\n\t\tif (ssr == null || !vite.isRunnableDevEnvironment(ssr)) {\n\t\t\tthrow new Error(\"Vite's SSR environment cannot run modules.\");\n\t\t}\n\t\treturn ssr.runner;\n\t};\n\tssrRunner();\n\tif (!viteServer.config.plugins.some((plugin) => plugin.name === \"@ngrok/app-server\")) {\n\t\tawait viteServer.close();\n\t\tthrow new Error(\n\t\t\t\"`app-server start` needs the `appServer` plugin from @ngrok/app-server/vite in the Vite config.\",\n\t\t);\n\t}\n\tconst devServer = devServerStage(viteServer.middlewares, {\n\t\tpublicFiles: () => ({ directory: viteServer.config.publicDir, base: viteServer.config.base }),\n\t});\n\tconst sink = jsonSink();\n\tconst apps = servedApps();\n\n\tconst listener = requestListener(async (request, bindings) => {\n\t\ttry {\n\t\t\treturn await apps.serve(\n\t\t\t\tawait loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)),\n\t\t\t\tasync (entry) => entry.fetchDev(request, bindings, devServer),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tviteServer.ssrFixStacktrace(error);\n\t\t\t}\n\t\t\tsink.log(\"error\", \"dev request failed\", errorAttributes(error));\n\t\t\treturn new Response(error instanceof Error ? (error.stack ?? error.message) : String(error), {\n\t\t\t\tstatus: 500,\n\t\t\t\theaders: { \"Content-Type\": \"text/plain; charset=utf-8\" },\n\t\t\t});\n\t\t}\n\t});\n\thttpServer.on(\"request\", (request, response) => {\n\t\tvoid listener(request, response);\n\t});\n\n\tconst port =\n\t\tprocess.env.PORT == null ? viteServer.config.server.port : parsePort(process.env.PORT);\n\tconst hostname = process.env.HOST || viteHostname(viteServer.config.server.host);\n\tconst boundPort = await listenFromPort(httpServer, {\n\t\tport,\n\t\thostname,\n\t\tstrictPort: viteServer.config.server.strictPort,\n\t\tonPortInUse: (inUse) => {\n\t\t\tsink.log(\"info\", \"port in use, trying the next port\", { \"server.port\": inUse });\n\t\t},\n\t\tonWildcardInUse: (inUse) => {\n\t\t\tsink.log(\"warn\", \"port in use on a wildcard address\", {\n\t\t\t\t\"server.port\": inUse,\n\t\t\t\t\"server.address\": hostname,\n\t\t\t});\n\t\t},\n\t});\n\tsink.log(\"info\", \"listening\", { \"app_server.urls\": [listenerUrl(hostname, boundPort)] });\n\n\tfor (const signal of [\"SIGTERM\", \"SIGINT\"] as const) {\n\t\tprocess.once(signal, () => {\n\t\t\tconst pluginsStopped = apps.stopAll();\n\t\t\thttpServer.closeAllConnections();\n\t\t\tconst httpClosed = new Promise<void>((resolve) => {\n\t\t\t\thttpServer.close(() => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst viteClosed = viteServer.close().catch((error: unknown) => {\n\t\t\t\tsink.log(\"error\", \"Vite close failed\", errorAttributes(error));\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t});\n\t\t\tvoid Promise.all([pluginsStopped, httpClosed, viteClosed]).finally(exitAfterFlush);\n\t\t});\n\t}\n}\n\n/** The hostname for Vite's `server.host`: `true` is every interface, and no value is `localhost`. */\nfunction viteHostname(host: string | boolean | undefined): string | undefined {\n\tif (host === true) {\n\t\treturn undefined;\n\t}\n\treturn typeof host === \"string\" && host !== \"\" ? host : \"localhost\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,SAAgB,aAAyB;CACxC,IAAI;CACJ,MAAM,yBAAS,IAAI,IAAe;CAGlC,MAAM,SAAS,OAAO,QAAmB;EACxC,IAAI;GACH,MAAM,IAAI,MAAM,YAAY;EAC7B,UAAU;GACT,OAAO,OAAO,GAAG;EAClB;CACD;CACA,OAAO;EACN,OAAO,OAAO,OAAO,WAAW;GAC/B,IAAI,SAAS,MAAM,QAAQ,MAAM,KAChC,QAAQ,QAAQ;QACV;IACN,IAAI,WAAW,MAAM;KACpB,QAAQ,WAAW;KACnB,IAAI,QAAQ,YAAY,GACvB,AAAK,OAAO,OAAO;IAErB;IACA,UAAU;KAAE;KAAO,SAAS;KAAG,UAAU;IAAM;IAC/C,OAAO,IAAI,OAAO;GACnB;GACA,MAAM,MAAM;GACZ,IAAI,WAAW;GACf,IAAI;IACH,OAAO,MAAM,OAAO,KAAK;GAC1B,UAAU;IACT,IAAI,WAAW;IACf,IAAI,IAAI,YAAY,IAAI,YAAY,GACnC,AAAK,OAAO,GAAG;GAEjB;EACD;EACA,SAAS,YAAY;GACpB,MAAM,QAAQ,IACb,MAAM,KAAK,QAAQ,OAAO,QAAQ;IACjC,IAAI,MAAM,oBAAoB;IAC9B,MAAM,OAAO,GAAG;GACjB,CAAC,CACF;EACD;CACD;AACD;;;ACpEA,MAAM,WAAW;;;;;;;AAyBjB,eAAsB,eACrB,QACA,EAAE,MAAM,UAAU,YAAY,aAAa,mBACzB;CAClB,IAAI,SAAS,GAAG;EACf,MAAM,KAAK,QAAQ,MAAM,QAAQ;EACjC,OAAO,UAAU,QAAQ,IAAI;CAC9B;CACA,IAAI,YAAY;EAGf,MAAM,iBAAiB,YAAY,QAAS,MAAM,iBAAiB,IAAI;EACvE,MAAM,KAAK,QAAQ,MAAM,QAAQ;EACjC,IAAI,CAAC,gBACJ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IAAI,IAAI;CACtF,MAAM,WAAW,QAAQ,IAAI,QAAQ,aAAa,WAAW,OAAO,OAAO,IAAI;CAC/E,MAAM,YAAY,MAAM,eAAe,YAAY;EAClD;EACA;EACA,YAAY,WAAW,OAAO,OAAO;EACrC,cAAc,UAAU;GACvB,KAAK,IAAI,QAAQ,qCAAqC,EAAE,eAAe,MAAM,CAAC;EAC/E;EACA,kBAAkB,UAAU;GAC3B,KAAK,IAAI,QAAQ,qCAAqC;IACrD,eAAe;IACf,kBAAkB;GACnB,CAAC;EACF;CACD,CAAC;CACD,KAAK,IAAI,QAAQ,aAAa,EAAE,mBAAmB,CAAC,YAAY,UAAU,SAAS,CAAC,EAAE,CAAC;CAEvF,KAAK,MAAM,UAAU,CAAC,WAAW,QAAQ,GACxC,QAAQ,KAAK,cAAc;EAC1B,MAAM,iBAAiB,KAAK,QAAQ;EACpC,WAAW,oBAAoB;EAC/B,MAAM,aAAa,IAAI,SAAe,YAAY;GACjD,WAAW,YAAY;IACtB,QAAQ;GACT,CAAC;EACF,CAAC;EACD,MAAM,aAAa,WAAW,MAAM,CAAC,CAAC,OAAO,UAAmB;GAC/D,KAAK,IAAI,SAAS,qBAAqB,gBAAgB,KAAK,CAAC;GAC7D,QAAQ,WAAW;EACpB,CAAC;EACD,AAAK,QAAQ,IAAI;GAAC;GAAgB;GAAY;EAAU,CAAC,CAAC,CAAC,QAAQ,cAAc;CAClF,CAAC;AAEH;;AAGA,SAAS,aAAa,MAAwD;CAC7E,IAAI,SAAS,MACZ;CAED,OAAO,OAAO,SAAS,YAAY,SAAS,KAAK,OAAO;AACzD"}
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC,CAAC,MAAM,GAAG,UAAU,WAAW,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG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