@torpor/build 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -0
- package/dist/bin/index.cjs +198 -38
- package/dist/bin/index.cjs.map +1 -1
- package/dist/bin/index.js +11 -507
- package/dist/bin/index.js.map +1 -1
- package/dist/chunk-ENB7RXFX.js +669 -0
- package/dist/chunk-ENB7RXFX.js.map +1 -0
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/run.cjs +755 -0
- package/dist/run.cjs.map +1 -0
- package/dist/run.d.cts +14 -0
- package/dist/run.d.ts +14 -0
- package/dist/run.js +16 -0
- package/dist/run.js.map +1 -0
- package/package.json +6 -1
- package/src/bin/index.ts +7 -43
- package/src/run.ts +6 -0
- package/src/site/run.ts +60 -0
- package/src/site/runBuild.ts +4 -5
- package/src/site/runDev.ts +3 -5
- package/tsup.config.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist/bin/index.cjs
CHANGED
|
@@ -23,16 +23,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// src/
|
|
27
|
-
var
|
|
28
|
-
var
|
|
26
|
+
// src/site/run.ts
|
|
27
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
28
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
29
29
|
var import_vite5 = require("vite");
|
|
30
30
|
|
|
31
31
|
// src/site/runBuild.ts
|
|
32
32
|
var import_vite = __toESM(require("@torpor/unplugin/vite"), 1);
|
|
33
33
|
var import_node_fs2 = require("fs");
|
|
34
34
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
35
|
-
var import_node_url = require("url");
|
|
36
35
|
var import_vite2 = require("vite");
|
|
37
36
|
|
|
38
37
|
// src/site/manifest.ts
|
|
@@ -73,8 +72,6 @@ export default {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
// src/site/runBuild.ts
|
|
76
|
-
var import_meta = {};
|
|
77
|
-
var __dirname = import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
78
75
|
async function runBuild(site) {
|
|
79
76
|
const distFolder = import_node_path2.default.resolve(site.root, "dist");
|
|
80
77
|
if ((0, import_node_fs2.existsSync)(distFolder)) {
|
|
@@ -86,8 +83,9 @@ async function runBuild(site) {
|
|
|
86
83
|
await site.adapter.prebuild(site);
|
|
87
84
|
}
|
|
88
85
|
let siteHtml = import_node_path2.default.resolve(site.root, "src/site.html");
|
|
89
|
-
|
|
90
|
-
let
|
|
86
|
+
const siteFolder = import_node_path2.default.resolve(site.root, "./node_modules/@torpor/build/src/site/");
|
|
87
|
+
let clientScript = import_node_path2.default.join(siteFolder, "clientEntry.ts");
|
|
88
|
+
let serverScript = import_node_path2.default.join(siteFolder, "serverEntry.ts");
|
|
91
89
|
await (0, import_vite2.build)(
|
|
92
90
|
(0, import_vite2.defineConfig)({
|
|
93
91
|
plugins: [
|
|
@@ -139,7 +137,7 @@ var import_vite3 = __toESM(require("@torpor/unplugin/vite"), 1);
|
|
|
139
137
|
var import_dotenv = require("dotenv");
|
|
140
138
|
var import_node_fs3 = require("fs");
|
|
141
139
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
142
|
-
var
|
|
140
|
+
var import_node_url = require("url");
|
|
143
141
|
var import_vite4 = require("vite");
|
|
144
142
|
|
|
145
143
|
// src/adapters/node/flattenHeaders.ts
|
|
@@ -326,8 +324,8 @@ function serverError(body) {
|
|
|
326
324
|
}
|
|
327
325
|
|
|
328
326
|
// src/site/pathToRegex.ts
|
|
329
|
-
function pathToRegex(
|
|
330
|
-
const pattern =
|
|
327
|
+
function pathToRegex(path6) {
|
|
328
|
+
const pattern = path6.split("/").map((p) => {
|
|
331
329
|
return p.replace(/\[([^\/]+?)\]/, "(?<$1>[^\\/]+?)");
|
|
332
330
|
}).join("\\/").replaceAll("*", ".*");
|
|
333
331
|
return new RegExp(`^${pattern}$`);
|
|
@@ -463,13 +461,13 @@ var Server = class {
|
|
|
463
461
|
* @param fn The function to call when the pattern is matched.
|
|
464
462
|
* @returns
|
|
465
463
|
*/
|
|
466
|
-
add(
|
|
467
|
-
this.routes.push(new RouteHandler(
|
|
464
|
+
add(path6, fn) {
|
|
465
|
+
this.routes.push(new RouteHandler(path6, fn));
|
|
468
466
|
return this;
|
|
469
467
|
}
|
|
470
|
-
match(
|
|
468
|
+
match(path6) {
|
|
471
469
|
for (let handler of this.routes) {
|
|
472
|
-
let match =
|
|
470
|
+
let match = path6.match(handler.regex);
|
|
473
471
|
if (match) {
|
|
474
472
|
return {
|
|
475
473
|
fn: handler.fn,
|
|
@@ -477,7 +475,7 @@ var Server = class {
|
|
|
477
475
|
};
|
|
478
476
|
}
|
|
479
477
|
}
|
|
480
|
-
console.log(`Server path not found: ${
|
|
478
|
+
console.log(`Server path not found: ${path6}`);
|
|
481
479
|
}
|
|
482
480
|
// TODO:
|
|
483
481
|
//use(path: string, ...fn: MiddlewareFunction[])
|
|
@@ -490,9 +488,9 @@ var RouteHandler = class {
|
|
|
490
488
|
path;
|
|
491
489
|
regex;
|
|
492
490
|
fn;
|
|
493
|
-
constructor(
|
|
494
|
-
this.path =
|
|
495
|
-
this.regex = pathToRegex(
|
|
491
|
+
constructor(path6, fn) {
|
|
492
|
+
this.path = path6;
|
|
493
|
+
this.regex = pathToRegex(path6);
|
|
496
494
|
this.fn = fn;
|
|
497
495
|
}
|
|
498
496
|
};
|
|
@@ -513,8 +511,8 @@ function regexIndexOf(string, regex, position) {
|
|
|
513
511
|
}
|
|
514
512
|
|
|
515
513
|
// src/site/runDev.ts
|
|
516
|
-
var
|
|
517
|
-
var
|
|
514
|
+
var import_meta = {};
|
|
515
|
+
var __dirname = import_node_path3.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
518
516
|
async function runDev(site) {
|
|
519
517
|
const server = new Server();
|
|
520
518
|
const vite = await (0, import_vite4.createServer)({
|
|
@@ -530,8 +528,8 @@ async function runDev(site) {
|
|
|
530
528
|
const templateFile = import_node_path3.default.resolve(site.root, "src/site.html");
|
|
531
529
|
let template = await import_node_fs3.promises.readFile(templateFile, "utf-8");
|
|
532
530
|
template = await vite.transformIndexHtml("", template);
|
|
533
|
-
const clientScript = import_node_path3.default.resolve(
|
|
534
|
-
const serverScript = import_node_path3.default.resolve(
|
|
531
|
+
const clientScript = import_node_path3.default.resolve(__dirname, "../../src/site/clientEntry.ts");
|
|
532
|
+
const serverScript = import_node_path3.default.resolve(__dirname, "../../src/site/serverEntry.ts");
|
|
535
533
|
template = prepareTemplate(template, clientScript);
|
|
536
534
|
server.use(createMiddlewareHandler(vite.middlewares));
|
|
537
535
|
server.add("*", async (ev) => {
|
|
@@ -550,22 +548,158 @@ async function runDev(site) {
|
|
|
550
548
|
site.adapter.serve(server, site);
|
|
551
549
|
}
|
|
552
550
|
|
|
553
|
-
// src/
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
551
|
+
// src/site/runPreview.ts
|
|
552
|
+
var import_dotenv2 = require("dotenv");
|
|
553
|
+
var import_node_fs4 = require("fs");
|
|
554
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
555
|
+
|
|
556
|
+
// src/server/contentType.ts
|
|
557
|
+
function contentType(extension) {
|
|
558
|
+
return types[extension] || "application/octet-stream";
|
|
559
|
+
}
|
|
560
|
+
var types = {
|
|
561
|
+
".aac": "audio/aac",
|
|
562
|
+
".abw": "application/x-abiword",
|
|
563
|
+
".apng": "image/apng",
|
|
564
|
+
".arc": "application/x-freearc",
|
|
565
|
+
".avif": "image/avif",
|
|
566
|
+
".avi": "video/x-msvideo",
|
|
567
|
+
".azw": "application/vnd.amazon.ebook",
|
|
568
|
+
".bin": "application/octet-stream",
|
|
569
|
+
".bmp": "image/bmp",
|
|
570
|
+
".bz": "application/x-bzip",
|
|
571
|
+
".bz2": "application/x-bzip2",
|
|
572
|
+
".cda": "application/x-cdf",
|
|
573
|
+
".csh": "application/x-csh",
|
|
574
|
+
".css": "text/css",
|
|
575
|
+
".csv": "text/csv",
|
|
576
|
+
".doc": "application/msword",
|
|
577
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
578
|
+
".eot": "application/vnd.ms-fontobject",
|
|
579
|
+
".epub": "application/epub+zip",
|
|
580
|
+
".gz": "application/gzip",
|
|
581
|
+
".gif": "image/gif",
|
|
582
|
+
".htm": "text/html",
|
|
583
|
+
".html": "text/html",
|
|
584
|
+
".ico": "image/vnd.microsoft.icon",
|
|
585
|
+
".ics": "text/calendar",
|
|
586
|
+
".jar": "application/java-archive",
|
|
587
|
+
".jpeg": "image/jpeg",
|
|
588
|
+
".jpg": "image/jpeg",
|
|
589
|
+
".js": "text/javascript",
|
|
590
|
+
".json": "application/json",
|
|
591
|
+
".jsonld": "application/ld+json",
|
|
592
|
+
".mid": "audio/midi",
|
|
593
|
+
".midi": "audio/midi",
|
|
594
|
+
".mjs": "text/javascript",
|
|
595
|
+
".mp3": "audio/mpeg",
|
|
596
|
+
".mp4": "video/mp4",
|
|
597
|
+
".mpeg": "video/mpeg",
|
|
598
|
+
".mpkg": "application/vnd.apple.installer+xml",
|
|
599
|
+
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
600
|
+
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
601
|
+
".odt": "application/vnd.oasis.opendocument.text",
|
|
602
|
+
".oga": "audio/ogg",
|
|
603
|
+
".ogv": "video/ogg",
|
|
604
|
+
".ogx": "application/ogg",
|
|
605
|
+
".opus": "audio/ogg",
|
|
606
|
+
".otf": "font/otf",
|
|
607
|
+
".png": "image/png",
|
|
608
|
+
".pdf": "application/pdf",
|
|
609
|
+
".php": "application/x-httpd-php",
|
|
610
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
611
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
612
|
+
".rar": "application/vnd.rar",
|
|
613
|
+
".rtf": "application/rtf",
|
|
614
|
+
".sh": "application/x-sh",
|
|
615
|
+
".svg": "image/svg+xml",
|
|
616
|
+
".tar": "application/x-tar",
|
|
617
|
+
".tif": "image/tiff",
|
|
618
|
+
".tiff": "image/tiff",
|
|
619
|
+
".ts": "video/mp2t",
|
|
620
|
+
".ttf": "font/ttf",
|
|
621
|
+
".txt": "text/plain",
|
|
622
|
+
".vsd": "application/vnd.visio",
|
|
623
|
+
".wav": "audio/wav",
|
|
624
|
+
".weba": "audio/webm",
|
|
625
|
+
".webm": "video/webm",
|
|
626
|
+
".webp": "image/webp",
|
|
627
|
+
".woff": "font/woff",
|
|
628
|
+
".woff2": "font/woff2",
|
|
629
|
+
".xhtml": "application/xhtml+xml",
|
|
630
|
+
".xls": "application/vnd.ms-excel",
|
|
631
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
632
|
+
".xml": "application/xml",
|
|
633
|
+
".xul": "application/vnd.mozilla.xul+xml",
|
|
634
|
+
".zip": "application/zip",
|
|
635
|
+
".3gp": "video/3gpp",
|
|
636
|
+
".3g2": "video/3gpp2",
|
|
637
|
+
".7z": "application/x-7z-compressed"
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/site/runPreview.ts
|
|
641
|
+
async function runPreview(site) {
|
|
642
|
+
await runBuild(site);
|
|
643
|
+
const distFolder = import_node_path4.default.resolve(site.root, "dist");
|
|
644
|
+
const clientFolder = import_node_path4.default.join(distFolder, "client");
|
|
645
|
+
const serverFolder = import_node_path4.default.join(distFolder, "server");
|
|
646
|
+
let clientScript = (await import_node_fs4.promises.readdir(import_node_path4.default.join(clientFolder, "assets"))).find(
|
|
647
|
+
(f) => f.startsWith("clientEntry-")
|
|
648
|
+
);
|
|
649
|
+
if (!clientScript) {
|
|
650
|
+
throw new Error("clientEntry.js not found");
|
|
651
|
+
}
|
|
652
|
+
clientScript = `/assets/${clientScript}`;
|
|
653
|
+
let siteHtml = import_node_path4.default.join(clientFolder, "site.html");
|
|
654
|
+
let template = await import_node_fs4.promises.readFile(siteHtml, "utf-8");
|
|
655
|
+
template = prepareTemplate(template, clientScript);
|
|
656
|
+
const server = new Server();
|
|
657
|
+
server.add("/assets/*", async (ev) => {
|
|
658
|
+
try {
|
|
659
|
+
const url = new URL(ev.request.url);
|
|
660
|
+
const file = import_node_path4.default.join(site.root, "dist", "client", url.pathname);
|
|
661
|
+
if ((0, import_node_fs4.existsSync)(file)) {
|
|
662
|
+
return new Response(await import_node_fs4.promises.readFile(file), {
|
|
663
|
+
status: 200,
|
|
664
|
+
headers: {
|
|
665
|
+
"Content-Type": contentType(import_node_path4.default.extname(file))
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
} catch (e) {
|
|
670
|
+
return serverError(e);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
const serverScript = import_node_path4.default.resolve(serverFolder, "serverEntry.js");
|
|
674
|
+
server.add("*", async (ev) => {
|
|
675
|
+
try {
|
|
676
|
+
const { load } = await import(serverScript);
|
|
677
|
+
return await load(ev, template);
|
|
678
|
+
} catch (e) {
|
|
679
|
+
return serverError(e);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
(0, import_dotenv2.configDotenv)();
|
|
683
|
+
process.env.PROTOCOL ??= "http:";
|
|
684
|
+
process.env.HOST ??= "localhost";
|
|
685
|
+
process.env.PORT ??= "7059";
|
|
686
|
+
site.adapter.serve(server, site);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/site/run.ts
|
|
690
|
+
async function run(folder, mode) {
|
|
557
691
|
let configFile = "";
|
|
558
692
|
let deleteConfigFile = false;
|
|
559
|
-
const jsConfigFile =
|
|
560
|
-
const tsConfigFile =
|
|
561
|
-
if (
|
|
693
|
+
const jsConfigFile = import_node_path5.default.join(folder, "site.config.js");
|
|
694
|
+
const tsConfigFile = import_node_path5.default.join(folder, "site.config.ts");
|
|
695
|
+
if (import_node_fs5.default.existsSync(jsConfigFile)) {
|
|
562
696
|
configFile = jsConfigFile;
|
|
563
|
-
} else if (
|
|
564
|
-
configFile =
|
|
565
|
-
let source = (await (0, import_vite5.transformWithEsbuild)(
|
|
697
|
+
} else if (import_node_fs5.default.existsSync(tsConfigFile)) {
|
|
698
|
+
configFile = import_node_path5.default.join(folder, "site.config.temp.js");
|
|
699
|
+
let source = (await (0, import_vite5.transformWithEsbuild)(import_node_fs5.default.readFileSync(tsConfigFile, "utf-8"), tsConfigFile, {
|
|
566
700
|
loader: "ts"
|
|
567
701
|
})).code;
|
|
568
|
-
|
|
702
|
+
import_node_fs5.default.writeFileSync(configFile, source);
|
|
569
703
|
deleteConfigFile = true;
|
|
570
704
|
} else {
|
|
571
705
|
throw new Error("site.config file not found");
|
|
@@ -575,12 +709,38 @@ async function run() {
|
|
|
575
709
|
throw new Error("Invalid site in config file");
|
|
576
710
|
}
|
|
577
711
|
if (deleteConfigFile) {
|
|
578
|
-
|
|
712
|
+
import_node_fs5.default.rmSync(configFile);
|
|
713
|
+
}
|
|
714
|
+
switch (mode) {
|
|
715
|
+
case "dev": {
|
|
716
|
+
await runDev(site);
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
case "build": {
|
|
720
|
+
await runBuild(site);
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
case "preview": {
|
|
724
|
+
await runPreview(site);
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
default: {
|
|
728
|
+
console.log("No mode passed, running in dev");
|
|
729
|
+
await runDev(site);
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
579
732
|
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// src/bin/index.ts
|
|
736
|
+
(async () => {
|
|
737
|
+
const workingDir = process.cwd();
|
|
580
738
|
if (process.argv.includes("--dev")) {
|
|
581
|
-
await
|
|
739
|
+
await run(workingDir, "dev");
|
|
582
740
|
} else if (process.argv.includes("--build")) {
|
|
583
|
-
await
|
|
741
|
+
await run(workingDir, "build");
|
|
742
|
+
} else if (process.argv.includes("--preview")) {
|
|
743
|
+
await run(workingDir, "preview");
|
|
584
744
|
}
|
|
585
|
-
}
|
|
745
|
+
})();
|
|
586
746
|
//# sourceMappingURL=index.cjs.map
|
package/dist/bin/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.ts","../../src/site/runBuild.ts","../../src/site/manifest.ts","../../src/site/runDev.ts","../../src/adapters/node/flattenHeaders.ts","../../src/adapters/node/nodeMessageToNodeResponse.ts","../../src/adapters/node/readableToBuffer.ts","../../src/adapters/node/requestToNodeMessage.ts","../../src/adapters/node/createMiddlewareHandler.ts","../../src/response/response.ts","../../src/response/serverError.ts","../../src/site/pathToRegex.ts","../../src/server/CookieHelper.ts","../../src/server/HeaderHelper.ts","../../src/server/ServerEvent.ts","../../src/server/Server.ts","../../src/site/prepareTemplate.ts"],"sourcesContent":["#! /usr/bin/env node\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { transformWithEsbuild } from \"vite\";\nimport Site from \"../site/Site\";\nimport runBuild from \"../site/runBuild\";\nimport runDev from \"../site/runDev\";\n\nrun();\n\nasync function run() {\n\t// Look for and load a site.config.js/ts file in the working directory\n\tconst workingDir = process.cwd();\n\tlet configFile = \"\";\n\tlet deleteConfigFile = false;\n\tconst jsConfigFile = path.join(workingDir, \"site.config.js\");\n\tconst tsConfigFile = path.join(workingDir, \"site.config.ts\");\n\tif (fs.existsSync(jsConfigFile)) {\n\t\t// If it's JS, we can just import it straight up\n\t\tconfigFile = jsConfigFile;\n\t} else if (fs.existsSync(tsConfigFile)) {\n\t\t// If it's TS, we need to convert it to JS\n\t\t// TODO: Put the generated file somewhere better (dist?)\n\t\tconfigFile = path.join(workingDir, \"site.config.temp.js\");\n\t\tlet source = (\n\t\t\tawait transformWithEsbuild(fs.readFileSync(tsConfigFile, \"utf-8\"), tsConfigFile, {\n\t\t\t\tloader: \"ts\",\n\t\t\t})\n\t\t).code;\n\t\tfs.writeFileSync(configFile, source);\n\t\tdeleteConfigFile = true;\n\t} else {\n\t\tthrow new Error(\"site.config file not found\");\n\t}\n\n\tconst site = (await import(configFile)).default as Site;\n\tif (!site || !site.root || !site.routes) {\n\t\tthrow new Error(\"Invalid site in config file\");\n\t}\n\tif (deleteConfigFile) {\n\t\tfs.rmSync(configFile);\n\t}\n\n\tif (process.argv.includes(\"--dev\")) {\n\t\tawait runDev(site);\n\t} else if (process.argv.includes(\"--build\")) {\n\t\tawait runBuild(site);\n\t}\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport { existsSync, 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.ts\";\nimport manifest from \"./manifest.ts\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n// TODO: Don't cache index.html in dev?\n// TODO: Multiple hook.server locations\n// TODO: Don't reload layouts during client routing\n// TODO: Call the correct +page and +server routes when in the same folder\n\nexport default async function runBuild(site: Site) {\n\t// Delete the dist folder if it exists\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tif (existsSync(distFolder)) {\n\t\tawait fs.rm(distFolder, { recursive: true });\n\t}\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\n\t// HOOK: Prebuild\n\tif (site.adapter.prebuild) {\n\t\tawait site.adapter.prebuild(site);\n\t}\n\n\t// TODO: From a setting\n\tlet siteHtml = path.resolve(site.root, \"src/site.html\");\n\n\tlet clientScript = path.resolve(__dirname, \"../../src/site/clientEntry.ts\");\n\tlet serverScript = path.resolve(__dirname, \"../../src/site/serverEntry.ts\");\n\n\t// Build the client assets, including site.html and the route files\n\t// EXCLUDING anything with `server.js` in the name\n\tawait build(\n\t\tdefineConfig({\n\t\t\tplugins: [\n\t\t\t\tmanifest(site),\n\t\t\t\t// @ts-ignore\n\t\t\t\ttorpor(),\n\t\t\t\t...site.plugins,\n\t\t\t],\n\t\t\tbuild: {\n\t\t\t\toutDir: clientFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [\n\t\t\t\t\t\tsiteHtml,\n\t\t\t\t\t\tclientScript,\n\t\t\t\t\t\t...site.routes\n\t\t\t\t\t\t\t.filter((r) => !/server\\.(ts|js)$/.test(r.file))\n\t\t\t\t\t\t\t.map((r) => path.resolve(site.root, r.file)),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tssrManifest: true,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Build the server assets, including the server entry script and the route\n\t// files\n\tawait build(\n\t\tdefineConfig({\n\t\t\tplugins: [\n\t\t\t\tmanifest(site, true),\n\t\t\t\t// @ts-ignore\n\t\t\t\ttorpor(),\n\t\t\t\t...site.plugins,\n\t\t\t],\n\t\t\tbuild: {\n\t\t\t\toutDir: serverFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [serverScript, ...site.routes.map((r) => path.resolve(site.root, r.file))],\n\t\t\t\t},\n\t\t\t\tssr: serverScript,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Move the site.html file into /client\n\t// HACK: Should do this in Rollup if possible?\n\tsiteHtml = path.join(clientFolder, \"site.html\");\n\tawait fs.rename(path.join(clientFolder, \"src\", \"site.html\"), siteHtml);\n\tawait fs.rm(path.join(clientFolder, \"src\"), { recursive: true });\n\n\t// HOOK: Postbuild\n\tif (site.adapter.postbuild) {\n\t\tawait site.adapter.postbuild(site);\n\t}\n}\n","import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Plugin } from \"vite\";\nimport Site from \"./Site\";\n\nconst moduleId = \"@torpor/build/manifest\";\n\n/**\n * A Vite plugin that provides information about the app to both clientEntry and\n * serverEntry.\n */\nexport default function manifest(site: Site, server = false): Plugin {\n\treturn {\n\t\tname: \"torpor-manifest\",\n\t\tresolveId: {\n\t\t\torder: \"pre\",\n\t\t\thandler(id) {\n\t\t\t\tif (id === moduleId) {\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tload(id) {\n\t\t\tif (id === moduleId) {\n\t\t\t\treturn `\n${!server ? \"const load = { default: { load: true } };\" : \"\"}\nexport default {\n routes: [\n ${site.routes\n\t\t\t.map((r) => {\n\t\t\t\tif (server || !/server\\.(ts|js)$/.test(r.file)) {\n\t\t\t\t\treturn `{ path: \"${r.path}\", file: \"${r.file}\", type: ${r.type}, endPoint: ${server || !/server\\.(ts|js)$/.test(r.file) ? `() => import(/* @vite-ignore */ \"${path.join(site.root, r.file)}\")` : \"undefined\"} }`;\n\t\t\t\t} else {\n\t\t\t\t\t// On the client, for a server route, we need to check\n\t\t\t\t\t// whether there's a load function and set a dummy endPoint\n\t\t\t\t\t// if so. The correct endpoint will be hit in clientEntry\n\t\t\t\t\t// HACK: Should do this better than checking for `load:` in source...\n\t\t\t\t\tconst haveLoad = readFileSync(path.join(site.root, r.file)).includes(\"load:\");\n\t\t\t\t\treturn `{ path: \"${r.path}\", file: \"${r.file}\", type: ${r.type}, endPoint: ${haveLoad ? \"() => load\" : \"undefined\"} }`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.join(\",\\n \")}\n ],\n};\n`;\n\t\t\t}\n\t\t},\n\t};\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport { configDotenv } from \"dotenv\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createServer as createViteServer } from \"vite\";\nimport createMiddlewareHandler from \"../adapters/node/createMiddlewareHandler.ts\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport Site from \"./Site.ts\";\nimport manifest from \"./manifest.ts\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport default async function runDev(site: Site) {\n\tconst server = new Server();\n\n\t// Create the Vite server in middleware mode and configure the app type as\n\t// \"custom\", disabling Vite's own HTML serving logic so the parent server\n\t// can take control\n\tconst vite = await createViteServer({\n\t\tserver: { middlewareMode: true },\n\t\tappType: \"custom\",\n\t\tplugins: [\n\t\t\tmanifest(site, true),\n\t\t\t// @ts-ignore not sure...\n\t\t\ttorpor(),\n\t\t\t...site.plugins,\n\t\t],\n\t});\n\n\t// Read site.html\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc)\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tlet template = await fs.readFile(templateFile, \"utf-8\");\n\n\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t// universal transform, not individual transforms for each route\n\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst clientScript = path.resolve(__dirname, \"../../src/site/clientEntry.ts\");\n\tconst serverScript = path.resolve(__dirname, \"../../src/site/serverEntry.ts\");\n\n\t// Prepare site.html so that we can just splice components into it\n\ttemplate = prepareTemplate(template, clientScript);\n\n\t// Use vite's Connect instance as middleware. We need to wrap it with\n\t// createMiddlewareHandler that converts Connect middleware to\n\t// Request/Response web handlers\n\tserver.use(createMiddlewareHandler(vite.middlewares));\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry. ssrLoadModule automatically transforms ESM\n\t\t\t// source code to be usable in Node.js. No bundling is required, and\n\t\t\t// it provides efficient invalidation similar to HMR\n\t\t\tconst { load } = await vite.ssrLoadModule(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\t// If an error is caught, let Vite fix the stack trace so it maps\n\t\t\t// back to your actual source code\n\t\t\tvite.ssrFixStacktrace(e);\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Load environment variables from a `.env` file, with defaults if not set\n\tconfigDotenv();\n\n\tprocess.env.PROTOCOL ??= \"http:\";\n\tprocess.env.HOST ??= \"localhost\";\n\tprocess.env.PORT ??= \"7059\";\n\n\t// Serve the site\n\tsite.adapter.serve(server, site);\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 {\n\ttype IncomingMessage,\n\ttype OutgoingHttpHeader,\n\ttype OutgoingHttpHeaders,\n\tServerResponse,\n} from \"node:http\";\nimport { PassThrough, Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/createServerResponse.ts\n\n/**\n * Creates a custom ServerResponse object that allows for intercepting and\n * streaming the response.\n *\n * @param incomingMessage The incoming HTTP request message.\n * @returns An object containing the custom ServerResponse and a function that\n * takes a callback to invoke when the response is readable, providing an object\n * with the readable stream, headers and status code.\n */\nexport default function nodeMessageToNodeResponse(\n\tincomingMessage: IncomingMessage,\n): ServerResponseResponse {\n\tconst res = new ServerResponse(incomingMessage);\n\tconst passThrough = new PassThrough();\n\tlet handled = false;\n\n\tconst onReadable = (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => {\n\t\tconst handleReadable = () => {\n\t\t\tif (handled) return;\n\t\t\thandled = true;\n\t\t\tcb({\n\t\t\t\treadable: Readable.from(passThrough),\n\t\t\t\theaders: res.getHeaders(),\n\t\t\t\tstatus: res.statusCode,\n\t\t\t});\n\t\t};\n\n\t\tpassThrough.once(\"readable\", handleReadable);\n\t\tpassThrough.once(\"end\", handleReadable);\n\t};\n\n\tpassThrough.once(\"finish\", () => {\n\t\tres.emit(\"finish\");\n\t});\n\tpassThrough.once(\"close\", () => {\n\t\tres.destroy();\n\t\tres.emit(\"close\");\n\t});\n\tpassThrough.on(\"drain\", () => {\n\t\tres.emit(\"drain\");\n\t});\n\n\tres.write = passThrough.write.bind(passThrough);\n\tres.end = passThrough.end.bind(passThrough) as any;\n\n\tres.writeHead = function writeHead(\n\t\tstatusCode: number,\n\t\tstatusMessage?: string | OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t\theaders?: OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t): ServerResponse {\n\t\tres.statusCode = statusCode;\n\t\tif (typeof statusMessage === \"object\") {\n\t\t\theaders = statusMessage;\n\t\t\tstatusMessage = undefined;\n\t\t}\n\t\tif (headers) {\n\t\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\tres.setHeader(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t};\n\n\treturn {\n\t\tres,\n\t\tonReadable,\n\t};\n}\n\ntype ServerResponseResponse = {\n\tres: ServerResponse;\n\tonReadable: (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => void;\n};\n","import { Readable } from \"node:stream\";\n\nexport default function readableToBuffer(req: Readable): Promise<Buffer> {\n\treturn new Promise<Buffer>((resolve, reject) => {\n\t\tconst chunks: Buffer[] = [];\n\t\treq.on(\"data\", (chunk: Buffer) => {\n\t\t\tchunks.push(chunk);\n\t\t});\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(Buffer.concat(chunks));\n\t\t});\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n","import { type IncomingMessage } from \"node:http\";\nimport { Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\nconst DUMMY_BASE_URL = \"http://localhost\";\n\n/**\n * Creates an IncomingMessage object from a web Request.\n *\n * @param {Request} request - The web Request object.\n * @returns {IncomingMessage} An IncomingMessage-like object compatible with Node.js HTTP module.\n */\nexport default function requestToNodeMessage(request: Request): IncomingMessage {\n\tconst parsedUrl = new URL(request.url, DUMMY_BASE_URL);\n\tconst pathAndQuery = (parsedUrl.pathname || \"\") + (parsedUrl.search || \"\");\n\t// HACK: Using Readable.fromWeb locks request.body so that the request cannot be used again\n\t// As we're only using this for Vite middlewares, it's safe to discard the body for now?\n\tconst body = /*request.body ? Readable.fromWeb(request.body as any) :*/ Readable.from([]);\n\n\treturn Object.assign(body, {\n\t\turl: pathAndQuery,\n\t\tmethod: request.method,\n\t\theaders: Object.fromEntries(request.headers),\n\t}) as IncomingMessage;\n}\n","import { IncomingMessage, ServerResponse } from \"node:http\";\nimport type MiddlewareFunction from \"../../types/MiddlewareFunction\";\nimport flattenHeaders from \"./flattenHeaders\";\nimport nodeMessageToNodeResponse from \"./nodeMessageToNodeResponse\";\nimport readableToBuffer from \"./readableToBuffer\";\nimport requestToNodeMessage from \"./requestToNodeMessage\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\n/**\n * Converts a Connect-style middleware to a web-compatible request handler.\n *\n * @param handler - The Connect-style middleware function to be converted.\n * @returns A function that handles web requests and returns a Response or undefined.\n */\nexport default function createMiddlewareHandler(\n\thandler: ConnectMiddleware | ConnectMiddlewareBoolean,\n): MiddlewareFunction {\n\treturn async (ev, next) => {\n\t\tconst req = requestToNodeMessage(ev.request);\n\t\tconst { res, onReadable } = nodeMessageToNodeResponse(req);\n\n\t\treturn new Promise<void>(async (resolve, reject) => {\n\t\t\tonReadable(async ({ readable, headers, status }) => {\n\t\t\t\tconst responseBody = statusCodesWithoutBody.includes(status)\n\t\t\t\t\t? null\n\t\t\t\t\t: //(Readable.toWeb(readable) as ReadableStream);\n\t\t\t\t\t\t// HACK: Chunked bodies are not being\n\t\t\t\t\t\t// read correctly somewhere...\n\t\t\t\t\t\tawait readableToBuffer(readable);\n\t\t\t\tev.response = new Response(responseBody, {\n\t\t\t\t\tstatus,\n\t\t\t\t\theaders: flattenHeaders(headers),\n\t\t\t\t});\n\t\t\t\tresolve();\n\t\t\t});\n\n\t\t\tconst cnext = async (error?: unknown) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t} else {\n\t\t\t\t\t// TODO: Can we nest the next functions less? This is a bit weird\n\t\t\t\t\tawait next();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst handled = await handler(req, res, cnext);\n\t\t\t\tif (handled === false) {\n\t\t\t\t\tres.destroy();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tcnext(e);\n\t\t\t}\n\t\t});\n\t};\n}\n\nconst statusCodesWithoutBody = [\n\t100, // Continue\n\t101, // Switching Protocols\n\t102, // Processing (WebDAV)\n\t103, // Early Hints\n\t204, // No Content\n\t205, // Reset Content\n\t304, // Not Modified\n];\n\ntype NextFunction = (err?: unknown) => void;\ntype ConnectMiddleware<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => void | Promise<void>;\ntype ConnectMiddlewareBoolean<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => boolean | Promise<boolean>;\n","/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the content-type\n * header set to \"application/json\". Otherwise, if the body is a string, the\n * content-type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string) {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\theaders = { \"content-type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(body);\n\t\t} else {\n\t\t\theaders = { \"content-type\": \"text/plain\" };\n\t\t}\n\t}\n\treturn new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t});\n}\n","import response from \"./response\";\n\n/**\n * 500 Server Error\n *\n * The server has encountered a situation it does not know how to handle.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body);\n}\n","export default function pathToRegex(path: string): RegExp {\n\tconst pattern = path\n\t\t.split(\"/\")\n\t\t.map((p) => {\n\t\t\treturn p.replace(/\\[([^\\/]+?)\\]/, \"(?<$1>[^\\\\/]+?)\");\n\t\t})\n\t\t.join(\"\\\\/\")\n\t\t.replaceAll(\"*\", \".*\");\n\treturn new RegExp(`^${pattern}$`);\n}\n","import { SerializeOptions, parse, serialize } from \"cookie\";\n\nexport default class CookieHelper {\n\trequest: Request;\n\tcookies: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.cookies.has(name)) {\n\t\t\treturn this.cookies.get(name);\n\t\t}\n\t\t// Otherwise, return the cookie value from the `Cookie` header\n\t\tconst header = this.request.headers.get(\"cookie\");\n\t\treturn parse(header ?? \"\")[name];\n\t}\n\n\tset(name: string, value: string, options?: SerializeOptions) {\n\t\t// Set a cookie header with some default values for security\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\tthis.cookies.set(name, serialize(name, value, options));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions) {\n\t\t// Set a cookie header with an immediate expiry date\n\t\toptions ??= {};\n\t\toptions.expires = new Date(0);\n\t\tthis.cookies.set(name, serialize(name, \"\", options));\n\t}\n}\n","export default class HeaderHelper {\n\trequest: Request;\n\theaders: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.headers.has(name)) {\n\t\t\treturn this.headers.get(name);\n\t\t}\n\t\t// Otherwise, return the value from the header\n\t\treturn this.request.headers.get(name) ?? undefined;\n\t}\n\n\tset(name: string, value: string) {\n\t\tthis.headers.set(name, value);\n\t}\n\n\tdelete(name: string) {\n\t\tthis.headers.delete(name);\n\t}\n}\n","import CookieHelper from \"./CookieHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\n\nexport default class ServerEvent {\n\trequest: Request;\n\tresponse?: Response;\n\t// TODO: Should we cast types??\n\tparams?: { [key: string]: string };\n\n\tcookies: CookieHelper;\n\theaders: HeaderHelper;\n\n\tconstructor(request: Request, params?: { [key: string]: string }) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.cookies = new CookieHelper(request);\n\t\tthis.headers = new HeaderHelper(request);\n\t}\n\n\taddHeaders() {\n\t\tif (!this.response) {\n\t\t\tthrow new Error(\"Response not created yet\");\n\t\t}\n\n\t\tfor (let cookie of this.cookies.cookies.values()) {\n\t\t\tthis.response.headers.append(\"set-cookie\", cookie);\n\t\t}\n\n\t\tfor (let header of this.headers.headers.entries()) {\n\t\t\tthis.response.headers.append(header[0], header[1]);\n\t\t}\n\t}\n}\n","import pathToRegex from \"../site/pathToRegex\";\nimport type MiddlewareFunction from \"../types/MiddlewareFunction\";\nimport ServerEvent from \"./ServerEvent\";\nimport type ServerFunction from \"./ServerFunction\";\n\nconst noop = () => {};\n\n/**\n * A Fetch API Request/Response server.\n */\nexport default class Server {\n\t// TODO: We don't use any of the routes, just add(\"*\") in runDev/runBuild...\n\troutes: RouteHandler[] = [];\n\t// TODO: We only use the Vite middleware here\n\tmiddleware: MiddlewareFunction[] = [];\n\n\tconstructor() {\n\t\tthis.routes = [];\n\t\tthis.middleware = [];\n\t}\n\n\t/**\n\t * The standard Fetch API method that should work in any runtime (including\n\t * Node with polyfills).\n\t * @returns\n\t */\n\tfetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n\t\tconst request = new Request(input, init);\n\t\tconst url = new URL(request.url);\n\t\tconst match = this.match(url.pathname);\n\t\tlet ev = new ServerEvent(request, match?.params);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tawait this.middleware[0](ev, buildNext(this.middleware, 0));\n\t\t\tfunction buildNext(middleware: MiddlewareFunction[], i: number): () => void | Promise<void> {\n\t\t\t\tif (ev.response) {\n\t\t\t\t\treturn noop;\n\t\t\t\t}\n\n\t\t\t\tif (i < middleware.length - 1) {\n\t\t\t\t\tlet next = middleware[i + 1];\n\t\t\t\t\treturn async () => next(ev, buildNext(middleware, i + 1));\n\t\t\t\t} else {\n\t\t\t\t\treturn match\n\t\t\t\t\t\t? async () => {\n\t\t\t\t\t\t\t\tev.response = await match.fn(ev);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: noop;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (match) {\n\t\t\tev.response = await match.fn(ev);\n\t\t} else {\n\t\t\treturn new Response(null, { status: 404 });\n\t\t}\n\n\t\t// TODO: Should I be returning 200 if there's no response? Because it's not an error??\n\t\tev.response ??= new Response(null, { status: 200 });\n\t\tev.addHeaders();\n\n\t\treturn ev.response;\n\t};\n\n\t/**\n\t * Adds a server function at a route path.\n\t * @param path The route path pattern.\n\t * @param fn The function to call when the pattern is matched.\n\t * @returns\n\t */\n\tadd(path: string, fn: ServerFunction): Server {\n\t\tthis.routes.push(new RouteHandler(path, fn));\n\t\treturn this;\n\t}\n\n\tmatch(path: string) {\n\t\tfor (let handler of this.routes) {\n\t\t\tlet match = path.match(handler.regex);\n\t\t\tif (match) {\n\t\t\t\treturn {\n\t\t\t\t\tfn: handler.fn,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tconsole.log(`Server path not found: ${path}`);\n\t}\n\n\t// TODO:\n\t//use(path: string, ...fn: MiddlewareFunction[])\n\tuse(...fn: MiddlewareFunction[]): Server {\n\t\tthis.middleware = this.middleware.concat(fn);\n\t\treturn this;\n\t}\n}\n\nclass RouteHandler {\n\tpath: string;\n\tregex: RegExp;\n\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.fn = fn;\n\t}\n}\n\n//class MiddlewareHandler {\n//\tpath: string;\n//\tregex: RegExp;\n//\tfn: MiddlewareFunction;\n//\n//\tconstructor(path: string, fn: MiddlewareFunction) {\n//\t\tthis.path = path;\n//\t\tthis.regex = pathToRegex(path);\n//\t\tthis.fn = fn;\n//\t}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,kBAAe;AACf,IAAAC,oBAAiB;AACjB,IAAAC,eAAqC;;;ACHrC,kBAAmB;AACnB,IAAAC,kBAA2C;AAC3C,IAAAC,oBAAiB;AACjB,sBAA8B;AAC9B,IAAAC,eAAoC;;;ACJpC,qBAA6B;AAC7B,uBAAiB;AAIjB,IAAM,WAAW;AAMF,SAAR,SAA0B,MAAY,SAAS,OAAe;AACpE,SAAO;AAAA,IACN,MAAM;AAAA,IACN,WAAW;AAAA,MACV,OAAO;AAAA,MACP,QAAQ,IAAI;AACX,YAAI,OAAO,UAAU;AACpB,iBAAO;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,IACA,KAAK,IAAI;AACR,UAAI,OAAO,UAAU;AACpB,eAAO;AAAA,EACT,CAAC,SAAS,8CAA8C,EAAE;AAAA;AAAA;AAAA,MAGtD,KAAK,OACP,IAAI,CAAC,MAAM;AACX,cAAI,UAAU,CAAC,mBAAmB,KAAK,EAAE,IAAI,GAAG;AAC/C,mBAAO,YAAY,EAAE,IAAI,aAAa,EAAE,IAAI,YAAY,EAAE,IAAI,eAAe,UAAU,CAAC,mBAAmB,KAAK,EAAE,IAAI,IAAI,oCAAoC,iBAAAC,QAAK,KAAK,KAAK,MAAM,EAAE,IAAI,CAAC,OAAO,WAAW;AAAA,UAC7M,OAAO;AAKN,kBAAM,eAAW,6BAAa,iBAAAA,QAAK,KAAK,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,OAAO;AAC5E,mBAAO,YAAY,EAAE,IAAI,aAAa,EAAE,IAAI,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import_node_path","import_vite","path","path","fs","torpor","import_vite","import_node_fs","import_node_path","import_node_url","v","import_node_stream","path","buildNext","path","import_meta","__dirname","path","createViteServer","torpor","fs","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../../src/site/run.ts","../../src/site/runBuild.ts","../../src/site/manifest.ts","../../src/site/runDev.ts","../../src/adapters/node/flattenHeaders.ts","../../src/adapters/node/nodeMessageToNodeResponse.ts","../../src/adapters/node/readableToBuffer.ts","../../src/adapters/node/requestToNodeMessage.ts","../../src/adapters/node/createMiddlewareHandler.ts","../../src/response/response.ts","../../src/response/serverError.ts","../../src/site/pathToRegex.ts","../../src/server/CookieHelper.ts","../../src/server/HeaderHelper.ts","../../src/server/ServerEvent.ts","../../src/server/Server.ts","../../src/site/prepareTemplate.ts","../../src/site/runPreview.ts","../../src/server/contentType.ts","../../src/bin/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { transformWithEsbuild } from \"vite\";\nimport Site from \"./Site\";\nimport runBuild from \"./runBuild\";\nimport runDev from \"./runDev\";\nimport runPreview from \"./runPreview\";\n\nexport default async function run(folder: string, mode: \"dev\" | \"build\" | \"preview\") {\n\t// Look for and load a site.config.js/ts file in the working directory\n\tlet configFile = \"\";\n\tlet deleteConfigFile = false;\n\tconst jsConfigFile = path.join(folder, \"site.config.js\");\n\tconst tsConfigFile = path.join(folder, \"site.config.ts\");\n\tif (fs.existsSync(jsConfigFile)) {\n\t\t// If it's JS, we can just import it straight up\n\t\tconfigFile = jsConfigFile;\n\t} else if (fs.existsSync(tsConfigFile)) {\n\t\t// If it's TS, we need to convert it to JS\n\t\t// TODO: Put the generated file somewhere better (dist?)\n\t\tconfigFile = path.join(folder, \"site.config.temp.js\");\n\t\tlet source = (\n\t\t\tawait transformWithEsbuild(fs.readFileSync(tsConfigFile, \"utf-8\"), tsConfigFile, {\n\t\t\t\tloader: \"ts\",\n\t\t\t})\n\t\t).code;\n\t\tfs.writeFileSync(configFile, source);\n\t\tdeleteConfigFile = true;\n\t} else {\n\t\tthrow new Error(\"site.config file not found\");\n\t}\n\n\tconst site = (await import(configFile)).default as Site;\n\tif (!site || !site.root || !site.routes) {\n\t\tthrow new Error(\"Invalid site in config file\");\n\t}\n\tif (deleteConfigFile) {\n\t\tfs.rmSync(configFile);\n\t}\n\n\tswitch (mode) {\n\t\tcase \"dev\": {\n\t\t\tawait runDev(site);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"build\": {\n\t\t\tawait runBuild(site);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"preview\": {\n\t\t\tawait runPreview(site);\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tconsole.log(\"No mode passed, running in dev\");\n\t\t\tawait runDev(site);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\n//import { fileURLToPath } from \"node:url\";\nimport { build, defineConfig } from \"vite\";\nimport Site from \"./Site.ts\";\nimport manifest from \"./manifest.ts\";\n\n//const __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n// TODO: Don't cache index.html in dev?\n// TODO: Multiple hook.server locations\n// TODO: Don't reload layouts during client routing\n// TODO: Call the correct +page and +server routes when in the same folder\n\nexport default async function runBuild(site: Site) {\n\t// Delete the dist folder if it exists\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tif (existsSync(distFolder)) {\n\t\tawait fs.rm(distFolder, { recursive: true });\n\t}\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\n\t// HOOK: Prebuild\n\tif (site.adapter.prebuild) {\n\t\tawait site.adapter.prebuild(site);\n\t}\n\n\t// TODO: From a setting\n\tlet siteHtml = path.resolve(site.root, \"src/site.html\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst siteFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/site/\");\n\tlet clientScript = path.join(siteFolder, \"clientEntry.ts\");\n\tlet serverScript = path.join(siteFolder, \"serverEntry.ts\");\n\n\t// Build the client assets, including site.html and the route files\n\t// EXCLUDING anything with `server.js` in the name\n\tawait build(\n\t\tdefineConfig({\n\t\t\tplugins: [\n\t\t\t\tmanifest(site),\n\t\t\t\t// @ts-ignore\n\t\t\t\ttorpor(),\n\t\t\t\t...site.plugins,\n\t\t\t],\n\t\t\tbuild: {\n\t\t\t\toutDir: clientFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [\n\t\t\t\t\t\tsiteHtml,\n\t\t\t\t\t\tclientScript,\n\t\t\t\t\t\t...site.routes\n\t\t\t\t\t\t\t.filter((r) => !/server\\.(ts|js)$/.test(r.file))\n\t\t\t\t\t\t\t.map((r) => path.resolve(site.root, r.file)),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tssrManifest: true,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Build the server assets, including the server entry script and the route\n\t// files\n\tawait build(\n\t\tdefineConfig({\n\t\t\tplugins: [\n\t\t\t\tmanifest(site, true),\n\t\t\t\t// @ts-ignore\n\t\t\t\ttorpor(),\n\t\t\t\t...site.plugins,\n\t\t\t],\n\t\t\tbuild: {\n\t\t\t\toutDir: serverFolder,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: [serverScript, ...site.routes.map((r) => path.resolve(site.root, r.file))],\n\t\t\t\t},\n\t\t\t\tssr: serverScript,\n\t\t\t},\n\t\t}),\n\t);\n\n\t// Move the site.html file into /client\n\t// HACK: Should do this in Rollup if possible?\n\tsiteHtml = path.join(clientFolder, \"site.html\");\n\tawait fs.rename(path.join(clientFolder, \"src\", \"site.html\"), siteHtml);\n\tawait fs.rm(path.join(clientFolder, \"src\"), { recursive: true });\n\n\t// HOOK: Postbuild\n\tif (site.adapter.postbuild) {\n\t\tawait site.adapter.postbuild(site);\n\t}\n}\n","import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Plugin } from \"vite\";\nimport Site from \"./Site\";\n\nconst moduleId = \"@torpor/build/manifest\";\n\n/**\n * A Vite plugin that provides information about the app to both clientEntry and\n * serverEntry.\n */\nexport default function manifest(site: Site, server = false): Plugin {\n\treturn {\n\t\tname: \"torpor-manifest\",\n\t\tresolveId: {\n\t\t\torder: \"pre\",\n\t\t\thandler(id) {\n\t\t\t\tif (id === moduleId) {\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tload(id) {\n\t\t\tif (id === moduleId) {\n\t\t\t\treturn `\n${!server ? \"const load = { default: { load: true } };\" : \"\"}\nexport default {\n routes: [\n ${site.routes\n\t\t\t.map((r) => {\n\t\t\t\tif (server || !/server\\.(ts|js)$/.test(r.file)) {\n\t\t\t\t\treturn `{ path: \"${r.path}\", file: \"${r.file}\", type: ${r.type}, endPoint: ${server || !/server\\.(ts|js)$/.test(r.file) ? `() => import(/* @vite-ignore */ \"${path.join(site.root, r.file)}\")` : \"undefined\"} }`;\n\t\t\t\t} else {\n\t\t\t\t\t// On the client, for a server route, we need to check\n\t\t\t\t\t// whether there's a load function and set a dummy endPoint\n\t\t\t\t\t// if so. The correct endpoint will be hit in clientEntry\n\t\t\t\t\t// HACK: Should do this better than checking for `load:` in source...\n\t\t\t\t\tconst haveLoad = readFileSync(path.join(site.root, r.file)).includes(\"load:\");\n\t\t\t\t\treturn `{ path: \"${r.path}\", file: \"${r.file}\", type: ${r.type}, endPoint: ${haveLoad ? \"() => load\" : \"undefined\"} }`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.join(\",\\n \")}\n ],\n};\n`;\n\t\t\t}\n\t\t},\n\t};\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport { configDotenv } from \"dotenv\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createServer as createViteServer } from \"vite\";\nimport createMiddlewareHandler from \"../adapters/node/createMiddlewareHandler.ts\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport Site from \"./Site.ts\";\nimport manifest from \"./manifest.ts\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport default async function runDev(site: Site) {\n\tconst server = new Server();\n\n\t// Create the Vite server in middleware mode and configure the app type as\n\t// \"custom\", disabling Vite's own HTML serving logic so the parent server\n\t// can take control\n\tconst vite = await createViteServer({\n\t\tserver: { middlewareMode: true },\n\t\tappType: \"custom\",\n\t\tplugins: [\n\t\t\tmanifest(site, true),\n\t\t\t// @ts-ignore not sure...\n\t\t\ttorpor(),\n\t\t\t...site.plugins,\n\t\t],\n\t});\n\n\t// Read site.html\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc)\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tlet template = await fs.readFile(templateFile, \"utf-8\");\n\n\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t// universal transform, not individual transforms for each route\n\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst clientScript = path.resolve(__dirname, \"../../src/site/clientEntry.ts\");\n\tconst serverScript = path.resolve(__dirname, \"../../src/site/serverEntry.ts\");\n\n\t// Prepare site.html so that we can just splice components into it\n\ttemplate = prepareTemplate(template, clientScript);\n\n\t// Use vite's Connect instance as middleware. We need to wrap it with\n\t// createMiddlewareHandler that converts Connect middleware to\n\t// Request/Response web handlers\n\tserver.use(createMiddlewareHandler(vite.middlewares));\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry. ssrLoadModule automatically transforms ESM\n\t\t\t// source code to be usable in Node.js. No bundling is required, and\n\t\t\t// it provides efficient invalidation similar to HMR\n\t\t\tconst { load } = await vite.ssrLoadModule(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\t// If an error is caught, let Vite fix the stack trace so it maps\n\t\t\t// back to your actual source code\n\t\t\tvite.ssrFixStacktrace(e);\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Load environment variables from a `.env` file, with defaults if not set\n\tconfigDotenv();\n\n\tprocess.env.PROTOCOL ??= \"http:\";\n\tprocess.env.HOST ??= \"localhost\";\n\tprocess.env.PORT ??= \"7059\";\n\n\t// Serve the site\n\tsite.adapter.serve(server, site);\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 {\n\ttype IncomingMessage,\n\ttype OutgoingHttpHeader,\n\ttype OutgoingHttpHeaders,\n\tServerResponse,\n} from \"node:http\";\nimport { PassThrough, Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/createServerResponse.ts\n\n/**\n * Creates a custom ServerResponse object that allows for intercepting and\n * streaming the response.\n *\n * @param incomingMessage The incoming HTTP request message.\n * @returns An object containing the custom ServerResponse and a function that\n * takes a callback to invoke when the response is readable, providing an object\n * with the readable stream, headers and status code.\n */\nexport default function nodeMessageToNodeResponse(\n\tincomingMessage: IncomingMessage,\n): ServerResponseResponse {\n\tconst res = new ServerResponse(incomingMessage);\n\tconst passThrough = new PassThrough();\n\tlet handled = false;\n\n\tconst onReadable = (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => {\n\t\tconst handleReadable = () => {\n\t\t\tif (handled) return;\n\t\t\thandled = true;\n\t\t\tcb({\n\t\t\t\treadable: Readable.from(passThrough),\n\t\t\t\theaders: res.getHeaders(),\n\t\t\t\tstatus: res.statusCode,\n\t\t\t});\n\t\t};\n\n\t\tpassThrough.once(\"readable\", handleReadable);\n\t\tpassThrough.once(\"end\", handleReadable);\n\t};\n\n\tpassThrough.once(\"finish\", () => {\n\t\tres.emit(\"finish\");\n\t});\n\tpassThrough.once(\"close\", () => {\n\t\tres.destroy();\n\t\tres.emit(\"close\");\n\t});\n\tpassThrough.on(\"drain\", () => {\n\t\tres.emit(\"drain\");\n\t});\n\n\tres.write = passThrough.write.bind(passThrough);\n\tres.end = passThrough.end.bind(passThrough) as any;\n\n\tres.writeHead = function writeHead(\n\t\tstatusCode: number,\n\t\tstatusMessage?: string | OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t\theaders?: OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t): ServerResponse {\n\t\tres.statusCode = statusCode;\n\t\tif (typeof statusMessage === \"object\") {\n\t\t\theaders = statusMessage;\n\t\t\tstatusMessage = undefined;\n\t\t}\n\t\tif (headers) {\n\t\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\tres.setHeader(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t};\n\n\treturn {\n\t\tres,\n\t\tonReadable,\n\t};\n}\n\ntype ServerResponseResponse = {\n\tres: ServerResponse;\n\tonReadable: (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => void;\n};\n","import { Readable } from \"node:stream\";\n\nexport default function readableToBuffer(req: Readable): Promise<Buffer> {\n\treturn new Promise<Buffer>((resolve, reject) => {\n\t\tconst chunks: Buffer[] = [];\n\t\treq.on(\"data\", (chunk: Buffer) => {\n\t\t\tchunks.push(chunk);\n\t\t});\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(Buffer.concat(chunks));\n\t\t});\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n","import { type IncomingMessage } from \"node:http\";\nimport { Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\nconst DUMMY_BASE_URL = \"http://localhost\";\n\n/**\n * Creates an IncomingMessage object from a web Request.\n *\n * @param {Request} request - The web Request object.\n * @returns {IncomingMessage} An IncomingMessage-like object compatible with Node.js HTTP module.\n */\nexport default function requestToNodeMessage(request: Request): IncomingMessage {\n\tconst parsedUrl = new URL(request.url, DUMMY_BASE_URL);\n\tconst pathAndQuery = (parsedUrl.pathname || \"\") + (parsedUrl.search || \"\");\n\t// HACK: Using Readable.fromWeb locks request.body so that the request cannot be used again\n\t// As we're only using this for Vite middlewares, it's safe to discard the body for now?\n\tconst body = /*request.body ? Readable.fromWeb(request.body as any) :*/ Readable.from([]);\n\n\treturn Object.assign(body, {\n\t\turl: pathAndQuery,\n\t\tmethod: request.method,\n\t\theaders: Object.fromEntries(request.headers),\n\t}) as IncomingMessage;\n}\n","import { IncomingMessage, ServerResponse } from \"node:http\";\nimport type MiddlewareFunction from \"../../types/MiddlewareFunction\";\nimport flattenHeaders from \"./flattenHeaders\";\nimport nodeMessageToNodeResponse from \"./nodeMessageToNodeResponse\";\nimport readableToBuffer from \"./readableToBuffer\";\nimport requestToNodeMessage from \"./requestToNodeMessage\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\n/**\n * Converts a Connect-style middleware to a web-compatible request handler.\n *\n * @param handler - The Connect-style middleware function to be converted.\n * @returns A function that handles web requests and returns a Response or undefined.\n */\nexport default function createMiddlewareHandler(\n\thandler: ConnectMiddleware | ConnectMiddlewareBoolean,\n): MiddlewareFunction {\n\treturn async (ev, next) => {\n\t\tconst req = requestToNodeMessage(ev.request);\n\t\tconst { res, onReadable } = nodeMessageToNodeResponse(req);\n\n\t\treturn new Promise<void>(async (resolve, reject) => {\n\t\t\tonReadable(async ({ readable, headers, status }) => {\n\t\t\t\tconst responseBody = statusCodesWithoutBody.includes(status)\n\t\t\t\t\t? null\n\t\t\t\t\t: //(Readable.toWeb(readable) as ReadableStream);\n\t\t\t\t\t\t// HACK: Chunked bodies are not being\n\t\t\t\t\t\t// read correctly somewhere...\n\t\t\t\t\t\tawait readableToBuffer(readable);\n\t\t\t\tev.response = new Response(responseBody, {\n\t\t\t\t\tstatus,\n\t\t\t\t\theaders: flattenHeaders(headers),\n\t\t\t\t});\n\t\t\t\tresolve();\n\t\t\t});\n\n\t\t\tconst cnext = async (error?: unknown) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t} else {\n\t\t\t\t\t// TODO: Can we nest the next functions less? This is a bit weird\n\t\t\t\t\tawait next();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst handled = await handler(req, res, cnext);\n\t\t\t\tif (handled === false) {\n\t\t\t\t\tres.destroy();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tcnext(e);\n\t\t\t}\n\t\t});\n\t};\n}\n\nconst statusCodesWithoutBody = [\n\t100, // Continue\n\t101, // Switching Protocols\n\t102, // Processing (WebDAV)\n\t103, // Early Hints\n\t204, // No Content\n\t205, // Reset Content\n\t304, // Not Modified\n];\n\ntype NextFunction = (err?: unknown) => void;\ntype ConnectMiddleware<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => void | Promise<void>;\ntype ConnectMiddlewareBoolean<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => boolean | Promise<boolean>;\n","/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the content-type\n * header set to \"application/json\". Otherwise, if the body is a string, the\n * content-type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string) {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\theaders = { \"content-type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(body);\n\t\t} else {\n\t\t\theaders = { \"content-type\": \"text/plain\" };\n\t\t}\n\t}\n\treturn new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t});\n}\n","import response from \"./response\";\n\n/**\n * 500 Server Error\n *\n * The server has encountered a situation it does not know how to handle.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body);\n}\n","export default function pathToRegex(path: string): RegExp {\n\tconst pattern = path\n\t\t.split(\"/\")\n\t\t.map((p) => {\n\t\t\treturn p.replace(/\\[([^\\/]+?)\\]/, \"(?<$1>[^\\\\/]+?)\");\n\t\t})\n\t\t.join(\"\\\\/\")\n\t\t.replaceAll(\"*\", \".*\");\n\treturn new RegExp(`^${pattern}$`);\n}\n","import { SerializeOptions, parse, serialize } from \"cookie\";\n\nexport default class CookieHelper {\n\trequest: Request;\n\tcookies: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.cookies.has(name)) {\n\t\t\treturn this.cookies.get(name);\n\t\t}\n\t\t// Otherwise, return the cookie value from the `Cookie` header\n\t\tconst header = this.request.headers.get(\"cookie\");\n\t\treturn parse(header ?? \"\")[name];\n\t}\n\n\tset(name: string, value: string, options?: SerializeOptions) {\n\t\t// Set a cookie header with some default values for security\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\tthis.cookies.set(name, serialize(name, value, options));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions) {\n\t\t// Set a cookie header with an immediate expiry date\n\t\toptions ??= {};\n\t\toptions.expires = new Date(0);\n\t\tthis.cookies.set(name, serialize(name, \"\", options));\n\t}\n}\n","export default class HeaderHelper {\n\trequest: Request;\n\theaders: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.headers.has(name)) {\n\t\t\treturn this.headers.get(name);\n\t\t}\n\t\t// Otherwise, return the value from the header\n\t\treturn this.request.headers.get(name) ?? undefined;\n\t}\n\n\tset(name: string, value: string) {\n\t\tthis.headers.set(name, value);\n\t}\n\n\tdelete(name: string) {\n\t\tthis.headers.delete(name);\n\t}\n}\n","import CookieHelper from \"./CookieHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\n\nexport default class ServerEvent {\n\trequest: Request;\n\tresponse?: Response;\n\t// TODO: Should we cast types??\n\tparams?: { [key: string]: string };\n\n\tcookies: CookieHelper;\n\theaders: HeaderHelper;\n\n\tconstructor(request: Request, params?: { [key: string]: string }) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.cookies = new CookieHelper(request);\n\t\tthis.headers = new HeaderHelper(request);\n\t}\n\n\taddHeaders() {\n\t\tif (!this.response) {\n\t\t\tthrow new Error(\"Response not created yet\");\n\t\t}\n\n\t\tfor (let cookie of this.cookies.cookies.values()) {\n\t\t\tthis.response.headers.append(\"set-cookie\", cookie);\n\t\t}\n\n\t\tfor (let header of this.headers.headers.entries()) {\n\t\t\tthis.response.headers.append(header[0], header[1]);\n\t\t}\n\t}\n}\n","import pathToRegex from \"../site/pathToRegex\";\nimport type MiddlewareFunction from \"../types/MiddlewareFunction\";\nimport ServerEvent from \"./ServerEvent\";\nimport type ServerFunction from \"./ServerFunction\";\n\nconst noop = () => {};\n\n/**\n * A Fetch API Request/Response server.\n */\nexport default class Server {\n\t// TODO: We don't use any of the routes, just add(\"*\") in runDev/runBuild...\n\troutes: RouteHandler[] = [];\n\t// TODO: We only use the Vite middleware here\n\tmiddleware: MiddlewareFunction[] = [];\n\n\tconstructor() {\n\t\tthis.routes = [];\n\t\tthis.middleware = [];\n\t}\n\n\t/**\n\t * The standard Fetch API method that should work in any runtime (including\n\t * Node with polyfills).\n\t * @returns\n\t */\n\tfetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n\t\tconst request = new Request(input, init);\n\t\tconst url = new URL(request.url);\n\t\tconst match = this.match(url.pathname);\n\t\tlet ev = new ServerEvent(request, match?.params);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tawait this.middleware[0](ev, buildNext(this.middleware, 0));\n\t\t\tfunction buildNext(middleware: MiddlewareFunction[], i: number): () => void | Promise<void> {\n\t\t\t\tif (ev.response) {\n\t\t\t\t\treturn noop;\n\t\t\t\t}\n\n\t\t\t\tif (i < middleware.length - 1) {\n\t\t\t\t\tlet next = middleware[i + 1];\n\t\t\t\t\treturn async () => next(ev, buildNext(middleware, i + 1));\n\t\t\t\t} else {\n\t\t\t\t\treturn match\n\t\t\t\t\t\t? async () => {\n\t\t\t\t\t\t\t\tev.response = await match.fn(ev);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: noop;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (match) {\n\t\t\tev.response = await match.fn(ev);\n\t\t} else {\n\t\t\treturn new Response(null, { status: 404 });\n\t\t}\n\n\t\t// TODO: Should I be returning 200 if there's no response? Because it's not an error??\n\t\tev.response ??= new Response(null, { status: 200 });\n\t\tev.addHeaders();\n\n\t\treturn ev.response;\n\t};\n\n\t/**\n\t * Adds a server function at a route path.\n\t * @param path The route path pattern.\n\t * @param fn The function to call when the pattern is matched.\n\t * @returns\n\t */\n\tadd(path: string, fn: ServerFunction): Server {\n\t\tthis.routes.push(new RouteHandler(path, fn));\n\t\treturn this;\n\t}\n\n\tmatch(path: string) {\n\t\tfor (let handler of this.routes) {\n\t\t\tlet match = path.match(handler.regex);\n\t\t\tif (match) {\n\t\t\t\treturn {\n\t\t\t\t\tfn: handler.fn,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tconsole.log(`Server path not found: ${path}`);\n\t}\n\n\t// TODO:\n\t//use(path: string, ...fn: MiddlewareFunction[])\n\tuse(...fn: MiddlewareFunction[]): Server {\n\t\tthis.middleware = this.middleware.concat(fn);\n\t\treturn this;\n\t}\n}\n\nclass RouteHandler {\n\tpath: string;\n\tregex: RegExp;\n\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.fn = fn;\n\t}\n}\n\n//class MiddlewareHandler {\n//\tpath: string;\n//\tregex: RegExp;\n//\tfn: MiddlewareFunction;\n//\n//\tconstructor(path: string, fn: MiddlewareFunction) {\n//\t\tthis.path = path;\n//\t\tthis.regex = pathToRegex(path);\n//\t\tthis.fn = fn;\n//\t}\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","import { configDotenv } from \"dotenv\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport contentType from \"../server/contentType.ts\";\nimport Site from \"./Site\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\nimport runBuild from \"./runBuild\";\n\nexport default async function runPreview(site: Site) {\n\t// Build the site\n\tawait runBuild(site);\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\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 site.html\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc)\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\n\t// Prepare site.html so that we can just splice components into it\n\ttemplate = prepareTemplate(template, clientScript);\n\n\t// Configure the server\n\tconst server = new Server();\n\n\t// Serve dist/client/assets statically\n\tserver.add(\"/assets/*\", async (ev) => {\n\t\ttry {\n\t\t\tconst url = new URL(ev.request.url);\n\t\t\tconst file = path.join(site.root, \"dist\", \"client\", url.pathname);\n\t\t\tif (existsSync(file)) {\n\t\t\t\t// TODO: Stream the data?\n\t\t\t\treturn new Response(await fs.readFile(file), {\n\t\t\t\t\tstatus: 200,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": contentType(path.extname(file)),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (e: any) {\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tconst serverScript = path.resolve(serverFolder, \"serverEntry.js\");\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry\n\t\t\tconst { load } = await import(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Load environment variables from a `.env` file, with defaults if not set\n\tconfigDotenv();\n\n\tprocess.env.PROTOCOL ??= \"http:\";\n\tprocess.env.HOST ??= \"localhost\";\n\tprocess.env.PORT ??= \"7059\";\n\n\t// Serve the site\n\tsite.adapter.serve(server, site);\n}\n","// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types\n\nexport default function contentType(extension: string) {\n\treturn types[extension] || \"application/octet-stream\";\n}\n\nconst types: Record<string, string> = {\n\t\".aac\": \"audio/aac\",\n\t\".abw\": \"application/x-abiword\",\n\t\".apng\": \"image/apng\",\n\t\".arc\": \"application/x-freearc\",\n\t\".avif\": \"image/avif\",\n\t\".avi\": \"video/x-msvideo\",\n\t\".azw\": \"application/vnd.amazon.ebook\",\n\t\".bin\": \"application/octet-stream\",\n\t\".bmp\": \"image/bmp\",\n\t\".bz\": \"application/x-bzip\",\n\t\".bz2\": \"application/x-bzip2\",\n\t\".cda\": \"application/x-cdf\",\n\t\".csh\": \"application/x-csh\",\n\t\".css\": \"text/css\",\n\t\".csv\": \"text/csv\",\n\t\".doc\": \"application/msword\",\n\t\".docx\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n\t\".eot\": \"application/vnd.ms-fontobject\",\n\t\".epub\": \"application/epub+zip\",\n\t\".gz\": \"application/gzip\",\n\t\".gif\": \"image/gif\",\n\t\".htm\": \"text/html\",\n\t\".html\": \"text/html\",\n\t\".ico\": \"image/vnd.microsoft.icon\",\n\t\".ics\": \"text/calendar\",\n\t\".jar\": \"application/java-archive\",\n\t\".jpeg\": \"image/jpeg\",\n\t\".jpg\": \"image/jpeg\",\n\t\".js\": \"text/javascript\",\n\t\".json\": \"application/json\",\n\t\".jsonld\": \"application/ld+json\",\n\t\".mid\": \"audio/midi\",\n\t\".midi\": \"audio/midi\",\n\t\".mjs\": \"text/javascript\",\n\t\".mp3\": \"audio/mpeg\",\n\t\".mp4\": \"video/mp4\",\n\t\".mpeg\": \"video/mpeg\",\n\t\".mpkg\": \"application/vnd.apple.installer+xml\",\n\t\".odp\": \"application/vnd.oasis.opendocument.presentation\",\n\t\".ods\": \"application/vnd.oasis.opendocument.spreadsheet\",\n\t\".odt\": \"application/vnd.oasis.opendocument.text\",\n\t\".oga\": \"audio/ogg\",\n\t\".ogv\": \"video/ogg\",\n\t\".ogx\": \"application/ogg\",\n\t\".opus\": \"audio/ogg\",\n\t\".otf\": \"font/otf\",\n\t\".png\": \"image/png\",\n\t\".pdf\": \"application/pdf\",\n\t\".php\": \"application/x-httpd-php\",\n\t\".ppt\": \"application/vnd.ms-powerpoint\",\n\t\".pptx\": \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n\t\".rar\": \"application/vnd.rar\",\n\t\".rtf\": \"application/rtf\",\n\t\".sh\": \"application/x-sh\",\n\t\".svg\": \"image/svg+xml\",\n\t\".tar\": \"application/x-tar\",\n\t\".tif\": \"image/tiff\",\n\t\".tiff\": \"image/tiff\",\n\t\".ts\": \"video/mp2t\",\n\t\".ttf\": \"font/ttf\",\n\t\".txt\": \"text/plain\",\n\t\".vsd\": \"application/vnd.visio\",\n\t\".wav\": \"audio/wav\",\n\t\".weba\": \"audio/webm\",\n\t\".webm\": \"video/webm\",\n\t\".webp\": \"image/webp\",\n\t\".woff\": \"font/woff\",\n\t\".woff2\": \"font/woff2\",\n\t\".xhtml\": \"application/xhtml+xml\",\n\t\".xls\": \"application/vnd.ms-excel\",\n\t\".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n\t\".xml\": \"application/xml\",\n\t\".xul\": \"application/vnd.mozilla.xul+xml\",\n\t\".zip\": \"application/zip\",\n\t\".3gp\": \"video/3gpp\",\n\t\".3g2\": \"video/3gpp2\",\n\t\".7z\": \"application/x-7z-compressed\",\n};\n","#! /usr/bin/env node\nimport run from \"../site/run\";\n\n(async () => {\n\tconst workingDir = process.cwd();\n\tif (process.argv.includes(\"--dev\")) {\n\t\tawait run(workingDir, \"dev\");\n\t} else if (process.argv.includes(\"--build\")) {\n\t\tawait run(workingDir, \"build\");\n\t} else if (process.argv.includes(\"--preview\")) {\n\t\tawait run(workingDir, \"preview\");\n\t}\n})();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAe;AACf,IAAAC,oBAAiB;AACjB,IAAAC,eAAqC;;;ACFrC,kBAAmB;AACnB,IAAAC,kBAA2C;AAC3C,IAAAC,oBAAiB;AAEjB,IAAAC,eAAoC;;;ACJpC,qBAA6B;AAC7B,uBAAiB;AAIjB,IAAM,WAAW;AAMF,SAAR,SAA0B,MAAY,SAAS,OAAe;AACpE,SAAO;AAAA,IACN,MAAM;AAAA,IACN,WAAW;AAAA,MACV,OAAO;AAAA,MACP,QAAQ,IAAI;AACX,YAAI,OAAO,UAAU;AACpB,iBAAO;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,IACA,KAAK,IAAI;AACR,UAAI,OAA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;AACnC,UAAM,IAAI,YAAY,KAAK;AAAA,EAC5B,WAAW,QAAQ,KAAK,SAAS,SAAS,GAAG;AAC5C,UAAM,IAAI,YAAY,OAAO;AAAA,EAC9B,WAAW,QAAQ,KAAK,SAAS,WAAW,GAAG;AAC9C,UAAM,IAAI,YAAY,SAAS;AAAA,EAChC;AACD,GAAG;","names":["import_node_fs","import_node_path","import_vite","import_node_fs","import_node_path","import_vite","path","path","fs","torpor","import_vite","import_node_fs","import_node_path","v","import_node_stream","path","buildNext","path","path","createViteServer","torpor","fs","import_dotenv","import_node_fs","import_node_path","path","fs","path","fs"]}
|