@torpor/build 0.1.2 → 0.1.4

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 (67) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{Server-CB99REgs.d.cts → Site-Df1k0TuQ.d.cts} +27 -1
  3. package/dist/{Server-CB99REgs.d.ts → Site-Df1k0TuQ.d.ts} +27 -1
  4. package/dist/bin/index.cjs +164 -166
  5. package/dist/bin/index.cjs.map +1 -1
  6. package/dist/bin/index.js +2 -3
  7. package/dist/bin/index.js.map +1 -1
  8. package/dist/chunk-L3QBUPXY.js +176 -0
  9. package/dist/chunk-L3QBUPXY.js.map +1 -0
  10. package/dist/{chunk-ENB7RXFX.js → chunk-Q623TPGO.js} +43 -185
  11. package/dist/chunk-Q623TPGO.js.map +1 -0
  12. package/dist/index.cjs +174 -118
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +12 -4
  17. package/dist/index.js.map +1 -1
  18. package/dist/metafile-cjs.json +1 -1
  19. package/dist/metafile-esm.json +1 -1
  20. package/dist/run.cjs +164 -166
  21. package/dist/run.cjs.map +1 -1
  22. package/dist/run.d.cts +1 -2
  23. package/dist/run.d.ts +1 -2
  24. package/dist/run.js +2 -3
  25. package/package.json +1 -1
  26. package/src/index.ts +4 -1
  27. package/src/site/Site.ts +2 -2
  28. package/src/site/clientEntry.ts +1 -1
  29. package/src/site/defaultAdapter.ts +11 -0
  30. package/src/site/runDev.ts +1 -1
  31. package/src/site/serverEntry.ts +2 -2
  32. package/tsconfig.json +1 -1
  33. package/tsup.config.ts +1 -9
  34. package/dist/Site-CgoeDt8k.d.cts +0 -29
  35. package/dist/Site-D95nwrAg.d.ts +0 -29
  36. package/dist/adapters/cloudflare/index.cjs +0 -125
  37. package/dist/adapters/cloudflare/index.cjs.map +0 -1
  38. package/dist/adapters/cloudflare/index.d.cts +0 -13
  39. package/dist/adapters/cloudflare/index.d.ts +0 -13
  40. package/dist/adapters/cloudflare/index.js +0 -80
  41. package/dist/adapters/cloudflare/index.js.map +0 -1
  42. package/dist/adapters/node/index.cjs +0 -152
  43. package/dist/adapters/node/index.cjs.map +0 -1
  44. package/dist/adapters/node/index.d.cts +0 -8
  45. package/dist/adapters/node/index.d.ts +0 -8
  46. package/dist/adapters/node/index.js +0 -8
  47. package/dist/adapters/node/index.js.map +0 -1
  48. package/dist/chunk-5X4T3PZN.js +0 -23
  49. package/dist/chunk-5X4T3PZN.js.map +0 -1
  50. package/dist/chunk-ALHFYD7U.js +0 -113
  51. package/dist/chunk-ALHFYD7U.js.map +0 -1
  52. package/dist/chunk-ENB7RXFX.js.map +0 -1
  53. package/dist/chunk-V4XTDQEV.js +0 -19
  54. package/dist/chunk-V4XTDQEV.js.map +0 -1
  55. package/src/adapters/cloudflare/_worker.ts +0 -38
  56. package/src/adapters/cloudflare/index.ts +0 -98
  57. package/src/adapters/node/constants.ts +0 -1
  58. package/src/adapters/node/createFetchHandler.ts +0 -29
  59. package/src/adapters/node/createNodeServer.ts +0 -8
  60. package/src/adapters/node/index.ts +0 -18
  61. package/src/adapters/node/nodeMessageToRequest.ts +0 -43
  62. package/src/adapters/node/responseToNodeResponse.ts +0 -44
  63. /package/src/{adapters/node → server/connect}/createMiddlewareHandler.ts +0 -0
  64. /package/src/{adapters/node → server/connect}/flattenHeaders.ts +0 -0
  65. /package/src/{adapters/node → server/connect}/nodeMessageToNodeResponse.ts +0 -0
  66. /package/src/{adapters/node → server/connect}/readableToBuffer.ts +0 -0
  67. /package/src/{adapters/node → server/connect}/requestToNodeMessage.ts +0 -0
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import Server from "./server/Server";
1
2
  import Site from "./site/Site";
3
+ import type Adapter from "./types/Adapter";
2
4
  import type PageEndPoint from "./types/PageEndPoint";
3
5
  import type PageLoadEvent from "./types/PageLoadEvent";
4
6
  import type PageServerAction from "./types/PageServerAction";
@@ -9,9 +11,10 @@ import type ServerHook from "./types/ServerHook";
9
11
  import type ServerLoadEvent from "./types/ServerLoadEvent";
10
12
  import type ServerRequest from "./types/ServerRequest";
11
13
 
12
- export { Site };
14
+ export { Server, Site };
13
15
 
14
16
  export type {
17
+ Adapter,
15
18
  PageEndPoint,
16
19
  PageServerEndPoint,
17
20
  PageServerLoad,
package/src/site/Site.ts CHANGED
@@ -2,7 +2,6 @@ import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { Plugin } from "vite";
4
4
  import tsconfigPaths from "vite-tsconfig-paths";
5
- import node from "../adapters/node";
6
5
  import Adapter from "../types/Adapter";
7
6
  import {
8
7
  HOOK_ROUTE,
@@ -13,6 +12,7 @@ import {
13
12
  PAGE_SERVER_ROUTE,
14
13
  SERVER_ROUTE,
15
14
  } from "../types/RouteType";
15
+ import defaultAdapter from "./defaultAdapter";
16
16
 
17
17
  // 1. The user sets this up
18
18
  // 2. It is passed into serverEntry and clientEntry through a Vite plugin
@@ -32,7 +32,7 @@ export default class Site {
32
32
  // tsconfigPaths themselves if they want to do something funky
33
33
  plugins: Plugin[] = [tsconfigPaths({ loose: true })];
34
34
  // Is default adapter a bad idea?
35
- adapter: Adapter = node;
35
+ adapter: Adapter = defaultAdapter;
36
36
 
37
37
  constructor() {
38
38
  this.root = process.cwd();
@@ -43,7 +43,7 @@ async function navigateToLocation(location: Location, firstTime = false) {
43
43
  }
44
44
 
45
45
  async function navigate(path: string, query: URLSearchParams, firstTime = false): Promise<boolean> {
46
- console.log(`navigating to '${path}'${query.size ? ` with ${query}` : ""}`);
46
+ //console.log(`navigating to '${path}'${query.size ? ` with ${query}` : ""}`);
47
47
 
48
48
  const parent = document.getElementById("app");
49
49
  if (!parent) {
@@ -0,0 +1,11 @@
1
+ import Adapter from "../types/Adapter";
2
+
3
+ // TODO: This should be an adapter-auto package that conditionally loads other packages...
4
+
5
+ const defaultAdapter: Adapter = {
6
+ serve: () => {
7
+ console.log("An adapter needs to be set in site.config");
8
+ },
9
+ };
10
+
11
+ export default defaultAdapter;
@@ -3,9 +3,9 @@ import { configDotenv } from "dotenv";
3
3
  import { promises as fs } from "node:fs";
4
4
  import path from "node:path";
5
5
  import { createServer as createViteServer } from "vite";
6
- import createMiddlewareHandler from "../adapters/node/createMiddlewareHandler.ts";
7
6
  import { serverError } from "../response.ts";
8
7
  import Server from "../server/Server.ts";
8
+ import createMiddlewareHandler from "../server/connect/createMiddlewareHandler.ts";
9
9
  import Site from "./Site.ts";
10
10
  import manifest from "./manifest.ts";
11
11
  import prepareTemplate from "./prepareTemplate.ts";
@@ -26,7 +26,7 @@ import Router from "./Router.ts";
26
26
  const router = new Router();
27
27
  router.addPages(manifest.routes);
28
28
 
29
- console.log(`routes:\n ${router.routes.map((r) => r.path).join("\n ")}`);
29
+ //console.log(`routes:\n ${router.routes.map((r) => r.path).join("\n ")}`);
30
30
 
31
31
  export async function load(ev: ServerEvent, template: string) {
32
32
  //const url = new URL(`http://${process.env.HOST ?? "localhost"}${ev.request.url}`);
@@ -34,7 +34,7 @@ export async function load(ev: ServerEvent, template: string) {
34
34
  const path = url.pathname;
35
35
  const query = url.searchParams;
36
36
 
37
- console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : ""}`);
37
+ //console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : ""}`);
38
38
 
39
39
  const route = router.match(path, query);
40
40
  if (!route) {
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "skipLibCheck": true,
6
6
  "verbatimModuleSyntax": false
7
7
  },
8
- "include": ["src", "src/site/app"]
8
+ "include": ["src"]
9
9
  }
package/tsup.config.ts CHANGED
@@ -1,15 +1,7 @@
1
1
  import { defineConfig } from "tsup";
2
2
 
3
3
  export default defineConfig({
4
- entry: [
5
- "src/index.ts",
6
- "src/state.ts",
7
- "src/response.ts",
8
- "src/run.ts",
9
- "src/bin/index.ts",
10
- "src/adapters/node/index.ts",
11
- "src/adapters/cloudflare/index.ts",
12
- ],
4
+ entry: ["src/index.ts", "src/response.ts", "src/run.ts", "src/state.ts", "src/bin/index.ts"],
13
5
  format: ["esm", "cjs"],
14
6
  dts: true,
15
7
  clean: true,
@@ -1,29 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { S as Server } from './Server-CB99REgs.cjs';
3
-
4
- type Adapter = {
5
- prebuild?: (site: Site) => Promise<void> | void;
6
- postbuild?: (site: Site) => Promise<void> | void;
7
- serve: (server: Server, site: Site) => void;
8
- };
9
-
10
- /**
11
- * The Site class contains the information necessary to setup a @torpor/build
12
- * site, including routes, plugins, and options.
13
- */
14
- declare class Site {
15
- #private;
16
- root: string;
17
- routes: {
18
- path: string;
19
- file: string;
20
- type: number;
21
- }[];
22
- plugins: Plugin[];
23
- adapter: Adapter;
24
- constructor();
25
- addRouteFolder(folder: string): Promise<void>;
26
- addRouteFile(path: string, file: string): void;
27
- }
28
-
29
- export { Site as S };
@@ -1,29 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { S as Server } from './Server-CB99REgs.js';
3
-
4
- type Adapter = {
5
- prebuild?: (site: Site) => Promise<void> | void;
6
- postbuild?: (site: Site) => Promise<void> | void;
7
- serve: (server: Server, site: Site) => void;
8
- };
9
-
10
- /**
11
- * The Site class contains the information necessary to setup a @torpor/build
12
- * site, including routes, plugins, and options.
13
- */
14
- declare class Site {
15
- #private;
16
- root: string;
17
- routes: {
18
- path: string;
19
- file: string;
20
- type: number;
21
- }[];
22
- plugins: Plugin[];
23
- adapter: Adapter;
24
- constructor();
25
- addRouteFolder(folder: string): Promise<void>;
26
- addRouteFile(path: string, file: string): void;
27
- }
28
-
29
- export { Site as S };
@@ -1,125 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/adapters/cloudflare/index.ts
31
- var cloudflare_exports = {};
32
- __export(cloudflare_exports, {
33
- default: () => cloudflare_default
34
- });
35
- module.exports = __toCommonJS(cloudflare_exports);
36
- var import_node_fs = require("fs");
37
- var import_node_path = __toESM(require("path"), 1);
38
- var import_node_url = require("url");
39
- var import_vite = require("vite");
40
-
41
- // src/site/prepareTemplate.ts
42
- function prepareTemplate(template, clientScript) {
43
- let contentStart = regexIndexOf(template, /\<div\s+id=("app"|'app'|app)\s+/);
44
- contentStart = template.indexOf(">", contentStart) + 1;
45
- let contentEnd = template.indexOf("</div>", contentStart);
46
- if (contentStart === -1 || contentEnd === -1) {
47
- throw new Error(`Couldn't find <div id="app"></div>`);
48
- }
49
- return template.substring(0, contentStart) + "%COMPONENT_HTML%" + template.substring(contentEnd) + `<script type="module" src="${clientScript}"></script>`;
50
- }
51
- function regexIndexOf(string, regex, position) {
52
- var indexOf = string.substring(position || 0).search(regex);
53
- return indexOf >= 0 ? indexOf + (position || 0) : indexOf;
54
- }
55
-
56
- // src/adapters/cloudflare/index.ts
57
- var import_meta = {};
58
- var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
59
- var cloudflare_default = {
60
- postbuild,
61
- serve: () => {
62
- console.log("TODO");
63
- }
64
- };
65
- async function postbuild(site) {
66
- const distFolder = import_node_path.default.resolve(site.root, "dist");
67
- const clientFolder = import_node_path.default.join(distFolder, "client");
68
- const serverFolder = import_node_path.default.join(distFolder, "server");
69
- const tempFolder = import_node_path.default.join(distFolder, "temp");
70
- const cloudflareFolder = import_node_path.default.join(distFolder, "cloudflare");
71
- let workerFile = import_node_path.default.resolve(__dirname, "../../../src/adapters/cloudflare/_worker.ts");
72
- let workerSource = await import_node_fs.promises.readFile(workerFile, "utf-8");
73
- let clientScript = (await import_node_fs.promises.readdir(import_node_path.default.join(clientFolder, "assets"))).find(
74
- (f) => f.startsWith("clientEntry-")
75
- );
76
- if (!clientScript) {
77
- throw new Error("clientEntry.js not found");
78
- }
79
- clientScript = `/assets/${clientScript}`;
80
- let siteHtml = import_node_path.default.join(clientFolder, "site.html");
81
- let template = await import_node_fs.promises.readFile(siteHtml, "utf-8");
82
- template = prepareTemplate(template, clientScript);
83
- const serverClass = import_node_path.default.resolve(__dirname, "../../../src/server/Server.ts");
84
- const serverScript = import_node_path.default.join(serverFolder, "serverEntry.js");
85
- workerSource = workerSource.replace("%SERVER_CLASS%", serverClass).replace("%SERVER_SCRIPT%", serverScript).replace("%HTML_TEMPLATE%", template);
86
- workerFile = import_node_path.default.join(tempFolder, "_worker.ts");
87
- await import_node_fs.promises.mkdir(tempFolder);
88
- await import_node_fs.promises.writeFile(workerFile, workerSource);
89
- await (0, import_vite.build)(
90
- (0, import_vite.defineConfig)({
91
- build: {
92
- outDir: cloudflareFolder,
93
- rollupOptions: {
94
- input: [workerFile],
95
- output: {
96
- entryFileNames: `[name].js`,
97
- chunkFileNames: `[name].js`,
98
- assetFileNames: `[name].[ext]`
99
- },
100
- preserveEntrySignatures: "strict"
101
- },
102
- // HACK: We don't need to minify as the worker isn't downloaded?
103
- // And it makes debugging easier
104
- minify: false,
105
- // HACK: Disable preload so that the _worker.js file doesn't end
106
- // up with document and window references that are not available
107
- modulePreload: false
108
- }
109
- })
110
- );
111
- workerFile = import_node_path.default.join(distFolder, "cloudflare", "_worker.js");
112
- const wranglerConfig = {
113
- name: "torpor-miniflare",
114
- main: "cloudflare/_worker.js",
115
- compatibility_date: "2025-01-01",
116
- assets: {
117
- directory: "./client",
118
- binding: "ASSETS"
119
- }
120
- };
121
- const wranglerFile = import_node_path.default.join(distFolder, "wrangler.json");
122
- await import_node_fs.promises.writeFile(wranglerFile, JSON.stringify(wranglerConfig, null, 2).replaceAll(" ", " "));
123
- await import_node_fs.promises.rm(tempFolder, { recursive: true });
124
- }
125
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/adapters/cloudflare/index.ts","../../../src/site/prepareTemplate.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { build, defineConfig } from \"vite\";\nimport Site from \"../../site/Site\";\nimport prepareTemplate from \"../../site/prepareTemplate\";\nimport type Adapter from \"../../types/Adapter\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// Compile _worker.ts\n\tlet workerFile = path.resolve(__dirname, \"../../../src/adapters/cloudflare/_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.resolve(__dirname, \"../../../src/server/Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\t//let workerSource = await fs.readFile(workerFile, \"utf-8\");\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\tworkerFile = path.join(distFolder, \"cloudflare\", \"_worker.js\");\n\n\t// Build a wrangler.json file for running with `wrangler dev`\n\tconst wranglerConfig = {\n\t\tname: \"torpor-miniflare\",\n\t\tmain: \"cloudflare/_worker.js\",\n\t\tcompatibility_date: \"2025-01-01\",\n\t\tassets: {\n\t\t\tdirectory: \"./client\",\n\t\t\tbinding: \"ASSETS\",\n\t\t},\n\t};\n\tconst wranglerFile = path.join(distFolder, \"wrangler.json\");\n\tawait fs.writeFile(wranglerFile, JSON.stringify(wranglerConfig, null, 2).replaceAll(\" \", \"\\t\"));\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n","export default function prepareTemplate(template: string, clientScript: string) {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+B;AAC/B,uBAAiB;AACjB,sBAA8B;AAC9B,kBAAoC;;;ACHrB,SAAR,gBAAiC,UAAkB,cAAsB;AAC/E,MAAI,eAAe,aAAa,UAAU,iCAAiC;AAC3E,iBAAe,SAAS,QAAQ,KAAK,YAAY,IAAI;AACrD,MAAI,aAAa,SAAS,QAAQ,UAAU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
3
- import '../../Server-CB99REgs.cjs';
4
- import 'cookie';
5
-
6
- declare const _default: {
7
- postbuild: typeof postbuild;
8
- serve: () => void;
9
- };
10
-
11
- declare function postbuild(site: Site): Promise<void>;
12
-
13
- export { _default as default };
@@ -1,13 +0,0 @@
1
- import { S as Site } from '../../Site-D95nwrAg.js';
2
- import 'vite';
3
- import '../../Server-CB99REgs.js';
4
- import 'cookie';
5
-
6
- declare const _default: {
7
- postbuild: typeof postbuild;
8
- serve: () => void;
9
- };
10
-
11
- declare function postbuild(site: Site): Promise<void>;
12
-
13
- export { _default as default };
@@ -1,80 +0,0 @@
1
- import {
2
- prepareTemplate
3
- } from "../../chunk-V4XTDQEV.js";
4
-
5
- // src/adapters/cloudflare/index.ts
6
- import { promises as fs } from "node:fs";
7
- import path from "node:path";
8
- import { fileURLToPath } from "node:url";
9
- import { build, defineConfig } from "vite";
10
- var __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- var cloudflare_default = {
12
- postbuild,
13
- serve: () => {
14
- console.log("TODO");
15
- }
16
- };
17
- async function postbuild(site) {
18
- const distFolder = path.resolve(site.root, "dist");
19
- const clientFolder = path.join(distFolder, "client");
20
- const serverFolder = path.join(distFolder, "server");
21
- const tempFolder = path.join(distFolder, "temp");
22
- const cloudflareFolder = path.join(distFolder, "cloudflare");
23
- let workerFile = path.resolve(__dirname, "../../../src/adapters/cloudflare/_worker.ts");
24
- let workerSource = await fs.readFile(workerFile, "utf-8");
25
- let clientScript = (await fs.readdir(path.join(clientFolder, "assets"))).find(
26
- (f) => f.startsWith("clientEntry-")
27
- );
28
- if (!clientScript) {
29
- throw new Error("clientEntry.js not found");
30
- }
31
- clientScript = `/assets/${clientScript}`;
32
- let siteHtml = path.join(clientFolder, "site.html");
33
- let template = await fs.readFile(siteHtml, "utf-8");
34
- template = prepareTemplate(template, clientScript);
35
- const serverClass = path.resolve(__dirname, "../../../src/server/Server.ts");
36
- const serverScript = path.join(serverFolder, "serverEntry.js");
37
- workerSource = workerSource.replace("%SERVER_CLASS%", serverClass).replace("%SERVER_SCRIPT%", serverScript).replace("%HTML_TEMPLATE%", template);
38
- workerFile = path.join(tempFolder, "_worker.ts");
39
- await fs.mkdir(tempFolder);
40
- await fs.writeFile(workerFile, workerSource);
41
- await build(
42
- defineConfig({
43
- build: {
44
- outDir: cloudflareFolder,
45
- rollupOptions: {
46
- input: [workerFile],
47
- output: {
48
- entryFileNames: `[name].js`,
49
- chunkFileNames: `[name].js`,
50
- assetFileNames: `[name].[ext]`
51
- },
52
- preserveEntrySignatures: "strict"
53
- },
54
- // HACK: We don't need to minify as the worker isn't downloaded?
55
- // And it makes debugging easier
56
- minify: false,
57
- // HACK: Disable preload so that the _worker.js file doesn't end
58
- // up with document and window references that are not available
59
- modulePreload: false
60
- }
61
- })
62
- );
63
- workerFile = path.join(distFolder, "cloudflare", "_worker.js");
64
- const wranglerConfig = {
65
- name: "torpor-miniflare",
66
- main: "cloudflare/_worker.js",
67
- compatibility_date: "2025-01-01",
68
- assets: {
69
- directory: "./client",
70
- binding: "ASSETS"
71
- }
72
- };
73
- const wranglerFile = path.join(distFolder, "wrangler.json");
74
- await fs.writeFile(wranglerFile, JSON.stringify(wranglerConfig, null, 2).replaceAll(" ", " "));
75
- await fs.rm(tempFolder, { recursive: true });
76
- }
77
- export {
78
- cloudflare_default as default
79
- };
80
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/adapters/cloudflare/index.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { build, defineConfig } from \"vite\";\nimport Site from \"../../site/Site\";\nimport prepareTemplate from \"../../site/prepareTemplate\";\nimport type Adapter from \"../../types/Adapter\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport default {\n\tpostbuild,\n\tserve: (/* server: Server, site: Site*/) => {\n\t\tconsole.log(\"TODO\");\n\t},\n} satisfies Adapter;\n\nasync function postbuild(site: Site) {\n\t// Build _worker.js as per\n\t// https://developers.cloudflare.com/pages/functions/advanced-mode/\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\tconst tempFolder = path.join(distFolder, \"temp\");\n\tconst cloudflareFolder = path.join(distFolder, \"cloudflare\");\n\n\t// Compile _worker.ts\n\tlet workerFile = path.resolve(__dirname, \"../../../src/adapters/cloudflare/_worker.ts\");\n\tlet workerSource = await fs.readFile(workerFile, \"utf-8\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read and prepare site.html so that we can just splice components into it\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\ttemplate = prepareTemplate(template, clientScript);\n\n\tconst serverClass = path.resolve(__dirname, \"../../../src/server/Server.ts\");\n\tconst serverScript = path.join(serverFolder, \"serverEntry.js\");\n\n\t// Splice file names into _worker.ts\n\t//let workerSource = await fs.readFile(workerFile, \"utf-8\");\n\tworkerSource = workerSource\n\t\t.replace(\"%SERVER_CLASS%\", serverClass)\n\t\t.replace(\"%SERVER_SCRIPT%\", serverScript)\n\t\t.replace(\"%HTML_TEMPLATE%\", template);\n\n\tworkerFile = path.join(tempFolder, \"_worker.ts\");\n\tawait fs.mkdir(tempFolder);\n\tawait fs.writeFile(workerFile, workerSource);\n\n\tawait build(\n\t\tdefineConfig({\n\t\t\tbuild: {\n\t\t\t\toutDir: cloudflareFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [workerFile],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: `[name].js`,\n\t\t\t\t\t\tchunkFileNames: `[name].js`,\n\t\t\t\t\t\tassetFileNames: `[name].[ext]`,\n\t\t\t\t\t},\n\t\t\t\t\tpreserveEntrySignatures: \"strict\",\n\t\t\t\t},\n\t\t\t\t// HACK: We don't need to minify as the worker isn't downloaded?\n\t\t\t\t// And it makes debugging easier\n\t\t\t\tminify: false,\n\t\t\t\t// HACK: Disable preload so that the _worker.js file doesn't end\n\t\t\t\t// up with document and window references that are not available\n\t\t\t\tmodulePreload: false,\n\t\t\t},\n\t\t}),\n\t);\n\tworkerFile = path.join(distFolder, \"cloudflare\", \"_worker.js\");\n\n\t// Build a wrangler.json file for running with `wrangler dev`\n\tconst wranglerConfig = {\n\t\tname: \"torpor-miniflare\",\n\t\tmain: \"cloudflare/_worker.js\",\n\t\tcompatibility_date: \"2025-01-01\",\n\t\tassets: {\n\t\t\tdirectory: \"./client\",\n\t\t\tbinding: \"ASSETS\",\n\t\t},\n\t};\n\tconst wranglerFile = path.join(distFolder, \"wrangler.json\");\n\tawait fs.writeFile(wranglerFile, JSON.stringify(wranglerConfig, null, 2).replaceAll(\" \", \"\\t\"));\n\n\tawait fs.rm(tempFolder, { recursive: true });\n}\n"],"mappings":";;;;;AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,OAAO,oBAAoB;AAKpC,IAAM,YAAY,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAE7D,IAAO,qBAAQ;AAAA,EACd;AAAA,EACA,OAAO,MAAqC;AAC3C,YAAQ,IAAI,MAAM;AAAA,EACnB;AACD;AAEA,eAAe,UAAU,MAAY;AAIpC,QAAM,aAAa,KAAK,QAAQ,KAAK,MAAM,MAAM;AACjD,QAAM,eAAe,KAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,eAAe,KAAK,KAAK,YAAY,QAAQ;AACnD,QAAM,aAAa,KAAK,KAAK,YAAY,MAAM;AAC/C,QAAM,mBAAmB,KAAK,KAAK,YAAY,YAAY;AAG3D,MAAI,a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AAAA,IACV;AAAA,EACD;AACA,QAAM,eAAe,KAAK,KAAK,YAAY,eAAe;AAC1D,QAAM,GAAG,UAAU,cAAc,KAAK,UAAU,gBAAgB,MAAM,CAAC,EAAE,WAAW,MAAM,GAAI,CAAC;AAE/F,QAAM,GAAG,GAAG,YAAY,EAAE,WAAW,KAAK,CAAC;AAC5C;","names":[]}
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/adapters/node/index.ts
21
- var node_exports = {};
22
- __export(node_exports, {
23
- default: () => node_default
24
- });
25
- module.exports = __toCommonJS(node_exports);
26
-
27
- // src/adapters/node/createNodeServer.ts
28
- var import_node_http = require("http");
29
-
30
- // src/adapters/node/constants.ts
31
- var INTERNAL_BODY = Symbol("internal_body");
32
-
33
- // src/adapters/node/nodeMessageToRequest.ts
34
- var import_node_stream = require("stream");
35
-
36
- // src/adapters/node/flattenHeaders.ts
37
- function flattenHeaders(headers) {
38
- const flatHeaders = new Headers();
39
- for (const [key, value] of Object.entries(headers)) {
40
- if (value === void 0 || value === null) {
41
- continue;
42
- } else if (Array.isArray(value)) {
43
- for (const v of value) {
44
- if (v !== void 0 && v !== null) {
45
- value.forEach((v2) => flatHeaders.append(key, v2));
46
- }
47
- }
48
- } else {
49
- flatHeaders.set(key, String(value));
50
- }
51
- }
52
- return flatHeaders;
53
- }
54
-
55
- // src/adapters/node/nodeMessageToRequest.ts
56
- async function nodeMessageToRequest(req) {
57
- let path = req.url;
58
- if (path === void 0) {
59
- throw new Error(`Empty request URL`);
60
- }
61
- if (!path.startsWith("/")) {
62
- path = "/" + path;
63
- }
64
- const { host } = req.headers;
65
- if (host == void 0) {
66
- throw new Error(`Missing "Host" header`);
67
- }
68
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https" : "http";
69
- const url = `${protocol}://${host}${path}`;
70
- const headers = flattenHeaders(req.headers);
71
- const body = req.method !== "GET" && req.method !== "HEAD" ? import_node_stream.Readable.toWeb(req) : null;
72
- return new Request(url, {
73
- method: req.method,
74
- headers,
75
- body,
76
- // @ts-ignore this is needed for using a Readable for some reason
77
- duplex: "half"
78
- });
79
- }
80
-
81
- // src/adapters/node/responseToNodeResponse.ts
82
- var import_types = require("util/types");
83
- async function responseToNodeResponse(res, outgoing) {
84
- outgoing.statusCode = res.status;
85
- outgoing.statusMessage = res.statusText;
86
- res.headers.forEach((value, key) => {
87
- outgoing.setHeader(key, value);
88
- });
89
- const body = res[INTERNAL_BODY];
90
- if (body === null || body === void 0) {
91
- outgoing.writeHead(res.status, res.statusText);
92
- outgoing.end();
93
- } else if (typeof body === "string" || body instanceof Uint8Array) {
94
- outgoing.writeHead(res.status, res.statusText);
95
- outgoing.end(body);
96
- } else if (body instanceof Blob) {
97
- outgoing.writeHead(res.status, res.statusText);
98
- outgoing.end(new Uint8Array(await body.arrayBuffer()));
99
- } else if (body instanceof ArrayBuffer) {
100
- outgoing.writeHead(res.status, res.statusText);
101
- outgoing.end(new Uint8Array(body));
102
- } else if ((0, import_types.isArrayBufferView)(body)) {
103
- outgoing.writeHead(res.status, res.statusText);
104
- outgoing.end(new Uint8Array(body.buffer));
105
- } else if (body instanceof FormData) {
106
- outgoing.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
107
- outgoing.writeHead(res.status, res.statusText);
108
- outgoing.end();
109
- } else {
110
- outgoing.writeHead(res.status, res.statusText);
111
- outgoing.end();
112
- }
113
- }
114
-
115
- // src/adapters/node/createFetchHandler.ts
116
- var GlobalResponse = Response;
117
- globalThis.Response = class Response2 extends GlobalResponse {
118
- [INTERNAL_BODY] = null;
119
- constructor(body, init) {
120
- super(body, init);
121
- this[INTERNAL_BODY] = body;
122
- }
123
- };
124
- function createFetchHandler(handler) {
125
- return async (incoming, outgoing) => {
126
- const req = await nodeMessageToRequest(incoming);
127
- const res = await handler(req);
128
- return await responseToNodeResponse(res, outgoing);
129
- };
130
- }
131
-
132
- // src/adapters/node/createNodeServer.ts
133
- function createNodeServer(handler) {
134
- return (0, import_node_http.createServer)(createFetchHandler(handler));
135
- }
136
-
137
- // src/adapters/node/index.ts
138
- var node_default = {
139
- serve: (server) => {
140
- process.env.PROTOCOL ??= "http:";
141
- process.env.HOST ??= "localhost";
142
- process.env.PORT ??= "7059";
143
- console.log(`
144
- Connecting to ${process.env.HOST}:${process.env.PORT}`);
145
- const devServer = createNodeServer(server.fetch);
146
- devServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {
147
- console.log(`Listening on ${process.env.HOST}:${process.env.PORT}
148
- `);
149
- });
150
- }
151
- };
152
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/adapters/node/index.ts","../../../src/adapters/node/createNodeServer.ts","../../../src/adapters/node/constants.ts","../../../src/adapters/node/nodeMessageToRequest.ts","../../../src/adapters/node/flattenHeaders.ts","../../../src/adapters/node/responseToNodeResponse.ts","../../../src/adapters/node/createFetchHandler.ts"],"sourcesContent":["import Server from \"../../server/Server\";\nimport type Adapter from \"../../types/Adapter\";\nimport createNodeServer from \"./createNodeServer\";\n\nexport default {\n\tserve: (server: Server) => {\n\t\tprocess.env.PROTOCOL ??= \"http:\";\n\t\tprocess.env.HOST ??= \"localhost\";\n\t\tprocess.env.PORT ??= \"7059\";\n\n\t\t// Create the Node server and start listening\n\t\tconsole.log(`\\nConnecting to ${process.env.HOST}:${process.env.PORT}`);\n\t\tconst devServer = createNodeServer(server.fetch);\n\t\tdevServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {\n\t\t\tconsole.log(`Listening on ${process.env.HOST}:${process.env.PORT}\\n`);\n\t\t});\n\t},\n} satisfies Adapter;\n","import { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(handler: (req: Request) => Response | Promise<Response>) {\n\t// Create a server, polyfill it so that it can handle standard fetch methods,\n\t// and pass our app fetch method to the handler\n\treturn createServer(createFetchHandler(handler));\n}\n","export const INTERNAL_BODY = Symbol(\"internal_body\");\n","import { type IncomingMessage } from \"node:http\";\nimport { Http2ServerRequest } from \"node:http2\";\nimport { Readable } from \"node:stream\";\nimport flattenHeaders from \"./flattenHeaders\";\n\n// From https://stackoverflow.com/a/78849544\n// and https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n\nexport default async function nodeMessageToRequest(\n\treq: IncomingMessage | Http2ServerRequest,\n): Promise<Request> {\n\t// Build the full url\n\tlet path = req.url;\n\tif (path === undefined) {\n\t\tthrow new Error(`Empty request URL`);\n\t}\n\tif (!path.startsWith(\"/\")) {\n\t\tpath = \"/\" + path;\n\t}\n\tconst { host } = req.headers;\n\tif (host == undefined) {\n\t\tthrow new Error(`Missing \"Host\" header`);\n\t}\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst url = `${protocol}://${host}${path}`;\n\n\t// Flatten the headers\n\tconst headers = flattenHeaders(req.headers);\n\n\t// Convert body to Buffer if applicable\n\tconst body =\n\t\treq.method !== \"GET\" && req.method !== \"HEAD\"\n\t\t\t? (Readable.toWeb(req) as ReadableStream) // await readableToBuffer(req)\n\t\t\t: null;\n\n\treturn new Request(url, {\n\t\tmethod: req.method,\n\t\theaders: headers,\n\t\tbody: body,\n\t\t// @ts-ignore this is needed for using a Readable for some reason\n\t\tduplex: \"half\",\n\t});\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import { ServerResponse } from \"node:http\";\nimport { Http2ServerResponse } from \"node:http2\";\nimport { isArrayBufferView } from \"node:util/types\";\nimport { INTERNAL_BODY } from \"./constants\";\n\nexport default async function responseToNodeResponse(\n\tres: Response,\n\toutgoing: ServerResponse | Http2ServerResponse,\n) {\n\toutgoing.statusCode = res.status;\n\toutgoing.statusMessage = res.statusText;\n\n\tres.headers.forEach((value, key) => {\n\t\toutgoing.setHeader(key, value);\n\t});\n\n\tconst body = (res as any)[INTERNAL_BODY];\n\n\tif (body === null || body === undefined) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else if (typeof body === \"string\" || body instanceof Uint8Array) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(body);\n\t} else if (body instanceof Blob) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(await body.arrayBuffer()));\n\t} else if (body instanceof ArrayBuffer) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body));\n\t} else if (isArrayBufferView(body)) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body.buffer));\n\t} else if (body instanceof FormData) {\n\t\t// TODO\n\t\toutgoing.setHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t}\n}\n","import { type IncomingMessage, ServerResponse } from \"node:http\";\nimport { Http2ServerRequest, Http2ServerResponse } from \"node:http2\";\nimport { INTERNAL_BODY } from \"./constants\";\nimport nodeMessageToRequest from \"./nodeMessageToRequest\";\nimport responseToNodeResponse from \"./responseToNodeResponse\";\n\n// From https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n// Referenced from https://marvinh.dev/blog/modern-way-to-write-javascript-servers/\n\nconst GlobalResponse = Response;\nglobalThis.Response = class Response extends GlobalResponse {\n\t[INTERNAL_BODY]: BodyInit | null | undefined = null;\n\n\tconstructor(body?: BodyInit | null, init?: ResponseInit) {\n\t\tsuper(body, init);\n\t\tthis[INTERNAL_BODY] = body;\n\t}\n};\n\nexport function createFetchHandler(handler: (req: Request) => Response | Promise<Response>) {\n\treturn async (\n\t\tincoming: IncomingMessage | Http2ServerRequest,\n\t\toutgoing: ServerResponse | Http2ServerResponse,\n\t) => {\n\t\tconst req = await nodeMessageToRequest(incoming);\n\t\tconst res = await handler(req);\n\t\treturn await responseToNodeResponse(res, outgoing);\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA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AAmB,SAAyD;AAC3F,SAAO,OACN,UACA,aACI;AACJ,UAAM,MAAM,MAAM,qBAAqB,QAAQ;AAC/C,UAAM,MAAM,MAAM,QAAQ,GAAG;AAC7B,WAAO,MAAM,uBAAuB,KAAK,QAAQ;AAAA,EAClD;AACD;;;ALzBe,SAAR,iBAAkC,SAAyD;AAGjG,aAAO,+BAAa,mBAAmB,OAAO,CAAC;AAChD;;;ADHA,IAAO,eAAQ;AAAA,EACd,OAAO,CAAC,WAAmB;AAC1B,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS;AAGrB,YAAQ,IAAI;AAAA,gBAAmB,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,EAAE;AACrE,UAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,cAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,GAAG,QAAQ,IAAI,MAAM,MAAM;AACpE,cAAQ,IAAI,gBAAgB,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI;AAAA,CAAI;AAAA,IACrE,CAAC;AAAA,EACF;AACD;","names":["v","Response"]}
@@ -1,8 +0,0 @@
1
- import { S as Server } from '../../Server-CB99REgs.cjs';
2
- import 'cookie';
3
-
4
- declare const _default: {
5
- serve: (server: Server) => void;
6
- };
7
-
8
- export { _default as default };
@@ -1,8 +0,0 @@
1
- import { S as Server } from '../../Server-CB99REgs.js';
2
- import 'cookie';
3
-
4
- declare const _default: {
5
- serve: (server: Server) => void;
6
- };
7
-
8
- export { _default as default };
@@ -1,8 +0,0 @@
1
- import {
2
- node_default
3
- } from "../../chunk-ALHFYD7U.js";
4
- import "../../chunk-5X4T3PZN.js";
5
- export {
6
- node_default as default
7
- };
8
- //# sourceMappingURL=index.js.map