@torpor/build 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/{RouteType-g8Ce5gOd.js → RouteType-VOBjKJ8I.js} +3 -3
- package/dist/{RouteType-g8Ce5gOd.js.map → RouteType-VOBjKJ8I.js.map} +1 -1
- package/dist/{Server-CSpY_-Ba.d.ts → Server-DL9neaq0.d.ts} +2 -2
- package/dist/Server-DL9neaq0.d.ts.map +1 -0
- package/dist/{ServerEvent-2-CnAy1W.js → ServerEvent-Dnk2FIKQ.js} +3 -4
- package/dist/{ServerEvent-2-CnAy1W.js.map → ServerEvent-Dnk2FIKQ.js.map} +1 -1
- package/dist/{Site-D4x1l0p5.d.ts → Site-B8TxSzPk.d.ts} +3 -3
- package/dist/Site-B8TxSzPk.d.ts.map +1 -0
- package/dist/{_page-CsdPubw4.js → _page-B8QZDML_.js} +3 -3
- package/dist/_page-B8QZDML_.js.map +1 -0
- package/dist/bin/index.js +6 -6
- package/dist/{connectMiddleware-DbLj0St1.js → connectMiddleware-PBcWWRr-.js} +4 -4
- package/dist/{connectMiddleware-DbLj0St1.js.map → connectMiddleware-PBcWWRr-.js.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/nav.js +47 -28
- package/dist/nav.js.map +1 -1
- package/dist/{pathToRegex-CTgx7hQP.js → pathToRegex-BTPkBIYJ.js} +2 -2
- package/dist/{pathToRegex-CTgx7hQP.js.map → pathToRegex-BTPkBIYJ.js.map} +1 -1
- package/dist/{response-D-XpIuMH.js → response-KnPcsvtU.js} +3 -3
- package/dist/{response-D-XpIuMH.js.map → response-KnPcsvtU.js.map} +1 -1
- package/dist/response.js +2 -2
- package/dist/{run-CNdaKSPR.js → run-CaFHeN6K.js} +10 -9
- package/dist/run-CaFHeN6K.js.map +1 -0
- package/dist/run.d.ts +2 -2
- package/dist/run.js +6 -6
- package/dist/{seeOther-BmehiI4C.js → seeOther-C-36lhS5.js} +2 -2
- package/dist/{seeOther-BmehiI4C.js.map → seeOther-C-36lhS5.js.map} +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +3 -3
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/test.js +8 -15
- package/dist/test.js.map +1 -1
- package/package.json +8 -8
- package/src/nav/formSubmit.ts +48 -0
- package/src/nav/loadData.ts +1 -1
- package/src/nav/navigate.ts +18 -9
- package/src/run/prepareTemplate.ts +8 -1
- package/src/run/runBuild.ts +0 -1
- package/src/run/runDev.ts +3 -3
- package/src/site/clientEntry.ts +5 -0
- package/src/site/clientEntryDev.ts +3 -0
- package/src/site/serverEntry.ts +25 -7
- package/src/state/internal.ts +4 -3
- package/src/test/runTest.ts +1 -1
- package/src/types/LayoutPath.ts +1 -1
- package/dist/Server-CSpY_-Ba.d.ts.map +0 -1
- package/dist/Site-D4x1l0p5.d.ts.map +0 -1
- package/dist/_page-CsdPubw4.js.map +0 -1
- package/dist/run-CNdaKSPR.js.map +0 -1
package/src/nav/navigate.ts
CHANGED
|
@@ -6,6 +6,7 @@ import client from "../state/client";
|
|
|
6
6
|
import type LayoutPath from "../types/LayoutPath";
|
|
7
7
|
import type PageEndPoint from "../types/PageEndPoint";
|
|
8
8
|
import type PageServerEndPoint from "../types/PageServerEndPoint";
|
|
9
|
+
import formSubmit from "./formSubmit";
|
|
9
10
|
import loadData from "./loadData";
|
|
10
11
|
|
|
11
12
|
// @ts-ignore
|
|
@@ -20,7 +21,7 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
20
21
|
const path = url.pathname;
|
|
21
22
|
const query = url.searchParams;
|
|
22
23
|
|
|
23
|
-
console.log(`navigating to '${path}'${query.size ? ` with ${query}` : ""}`);
|
|
24
|
+
//console.log(`navigating to '${path}'${query.size ? ` with ${query}` : ""}`);
|
|
24
25
|
|
|
25
26
|
const route = client.router.match(path, query);
|
|
26
27
|
if (!route) {
|
|
@@ -39,7 +40,6 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
39
40
|
} else {
|
|
40
41
|
$page.status = 200;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
43
|
const handler = route.handler;
|
|
44
44
|
const params = route.params || {};
|
|
45
45
|
|
|
@@ -77,9 +77,18 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
77
77
|
$page.form = form;
|
|
78
78
|
formInput.remove();
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
let $props: Record<string, any> = { data };
|
|
81
|
+
|
|
82
|
+
// We may have form data in $page.form, either from the hidden input
|
|
83
|
+
// (above), or added via onformsubmit (below)
|
|
84
|
+
$props.form = $page.form;
|
|
85
|
+
|
|
86
|
+
// Add some special context for submitting Forms client-side
|
|
87
|
+
const $context = {
|
|
88
|
+
TorporBuildContext: { onformsubmit: formSubmit },
|
|
89
|
+
};
|
|
81
90
|
|
|
82
|
-
client.layoutStack.push({ path: route.handler.path, data: {}, reuse: false,
|
|
91
|
+
client.layoutStack.push({ path: route.handler.path, data: {}, reuse: false, slotRegion: null });
|
|
83
92
|
client.layoutStack = newLayoutStack;
|
|
84
93
|
let layoutStack = client.layoutStack;
|
|
85
94
|
|
|
@@ -91,9 +100,9 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
91
100
|
if (handler.layouts) {
|
|
92
101
|
let slotFunctions: SlotRender[] = [];
|
|
93
102
|
// The last slot function will render the client component
|
|
94
|
-
slotFunctions[handler.layouts.length] = function clientComponent(parent, anchor
|
|
103
|
+
slotFunctions[handler.layouts.length] = function clientComponent(parent, anchor) {
|
|
95
104
|
let i = layoutStack.length - 1;
|
|
96
|
-
layoutStack[i].
|
|
105
|
+
layoutStack[i].slotRegion = fillLayoutSlot(
|
|
97
106
|
clientEndPoint.component!,
|
|
98
107
|
slotFunctions[i + 1],
|
|
99
108
|
parent,
|
|
@@ -112,8 +121,8 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
112
121
|
// Set the parent to add the new content to (from the old
|
|
113
122
|
// content), clear the range under this point, and set the
|
|
114
123
|
// component to the slot function within this layout
|
|
115
|
-
parent = layoutStack[i].
|
|
116
|
-
clearLayoutSlot(layoutStack[i].
|
|
124
|
+
parent = layoutStack[i].slotRegion.startNode.parentNode as HTMLElement;
|
|
125
|
+
clearLayoutSlot(layoutStack[i].slotRegion);
|
|
117
126
|
component = slotFunctions[i + 1];
|
|
118
127
|
break;
|
|
119
128
|
} else if (i === 0) {
|
|
@@ -121,7 +130,7 @@ export default async function navigate(url: URL, withHydration = false): Promise
|
|
|
121
130
|
slots = { _: slotFunctions[i + 1] };
|
|
122
131
|
} else {
|
|
123
132
|
slotFunctions[i] = function layoutComponent(parent, anchor, _, $context) {
|
|
124
|
-
layoutStack[i - 1].
|
|
133
|
+
layoutStack[i - 1].slotRegion = fillLayoutSlot(
|
|
125
134
|
layoutEndPoint.component!,
|
|
126
135
|
slotFunctions[i + 1],
|
|
127
136
|
parent,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export default function prepareTemplate(
|
|
1
|
+
export default function prepareTemplate(
|
|
2
|
+
template: string,
|
|
3
|
+
clientScript: string,
|
|
4
|
+
clientDevScript?: string,
|
|
5
|
+
): string {
|
|
2
6
|
let result = template;
|
|
3
7
|
|
|
4
8
|
// Put %COMPONENT_HEAD% before </head>
|
|
@@ -20,6 +24,9 @@ export default function prepareTemplate(template: string, clientScript: string):
|
|
|
20
24
|
result = result.substring(0, bodyStart) + "%COMPONENT_BODY%" + result.substring(bodyEnd);
|
|
21
25
|
|
|
22
26
|
// Add the clientEntry script at the very end, for hydrating and navigating
|
|
27
|
+
if (clientDevScript) {
|
|
28
|
+
result += `<script type="module" src="${clientDevScript}"></script>`;
|
|
29
|
+
}
|
|
23
30
|
result += `<script type="module" src="${clientScript}"></script>`;
|
|
24
31
|
|
|
25
32
|
return result;
|
package/src/run/runBuild.ts
CHANGED
|
@@ -27,7 +27,6 @@ export default async function runBuild(site: Site): Promise<void> {
|
|
|
27
27
|
// TODO: From a setting
|
|
28
28
|
let siteHtml = path.resolve(site.root, "src/site.html");
|
|
29
29
|
|
|
30
|
-
// TODO: Is this going to be the correct path after installing from npm?
|
|
31
30
|
const siteFolder = path.resolve(site.root, "./node_modules/@torpor/build/src/site/");
|
|
32
31
|
let clientScript = path.join(siteFolder, "clientEntry.ts");
|
|
33
32
|
let serverScript = path.join(siteFolder, "serverEntry.ts");
|
package/src/run/runDev.ts
CHANGED
|
@@ -20,7 +20,7 @@ export default async function runDev(site: Site): Promise<void> {
|
|
|
20
20
|
const config = structuredClone(site.viteConfig ?? {});
|
|
21
21
|
config.server = { middlewareMode: true };
|
|
22
22
|
config.appType = "custom";
|
|
23
|
-
config.plugins = [manifest(site, true), torpor(), ...site.plugins];
|
|
23
|
+
config.plugins = [manifest(site, true), torpor({ dev: true }), ...site.plugins];
|
|
24
24
|
|
|
25
25
|
// HACK: To be able to import `.torp` files from barrel files in
|
|
26
26
|
// node_modules, we need to add their libraries to `ssr.noExternal` in
|
|
@@ -45,13 +45,13 @@ export default async function runDev(site: Site): Promise<void> {
|
|
|
45
45
|
// universal transform, not individual transforms for each route
|
|
46
46
|
template = await vite.transformIndexHtml("", template);
|
|
47
47
|
|
|
48
|
-
// TODO: Is this going to be the correct path after installing from npm?
|
|
49
48
|
const siteFolder = path.resolve(site.root, "./node_modules/@torpor/build/src/site/");
|
|
50
49
|
let clientScript = path.join(siteFolder, "clientEntry.ts");
|
|
50
|
+
let clientDevScript = path.join(siteFolder, "clientEntryDev.ts");
|
|
51
51
|
let serverScript = path.join(siteFolder, "serverEntry.ts");
|
|
52
52
|
|
|
53
53
|
// Prepare site.html so that we can just splice components into it
|
|
54
|
-
template = prepareTemplate(template, clientScript);
|
|
54
|
+
template = prepareTemplate(template, clientScript, clientDevScript);
|
|
55
55
|
|
|
56
56
|
// Use Vite's Connect instance as middleware. We need to wrap it with
|
|
57
57
|
// createMiddlewareHandler that converts Connect middleware to
|
package/src/site/clientEntry.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import manifest from "@torpor/build/manifest";
|
|
2
2
|
import loadData from "../nav/loadData.ts";
|
|
3
3
|
import navigate from "../nav/navigate.ts";
|
|
4
|
+
import $page from "../state/$page.ts";
|
|
4
5
|
import client from "../state/client";
|
|
5
6
|
import type LayoutPath from "../types/LayoutPath";
|
|
6
7
|
import type PageEndPoint from "../types/PageEndPoint";
|
|
@@ -99,5 +100,9 @@ window.addEventListener("popstate", async () => {
|
|
|
99
100
|
await navigateToLocation(document.location, true);
|
|
100
101
|
|
|
101
102
|
async function navigateToLocation(location: Location, firstTime = false) {
|
|
103
|
+
// Reset $page on submit and link navigation
|
|
104
|
+
// TODO: Should we put data in $page.data??
|
|
105
|
+
$page.form = undefined;
|
|
106
|
+
|
|
102
107
|
return await navigate(new URL(location.toString()), firstTime);
|
|
103
108
|
}
|
package/src/site/serverEntry.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import manifest from "@torpor/build/manifest";
|
|
2
|
-
import { type ServerComponent, type ServerSlotRender } from "@torpor/view";
|
|
2
|
+
import { type ServerComponent, type ServerSlotRender } from "@torpor/view/ssr";
|
|
3
3
|
import notFound from "../response/notFound.ts";
|
|
4
4
|
import ok from "../response/ok.ts";
|
|
5
5
|
import seeOther from "../response/seeOther.ts";
|
|
@@ -30,7 +30,6 @@ router.addPages(manifest.routes);
|
|
|
30
30
|
//console.log(`routes:\n ${router.routes.map((r) => r.path).join("\n ")}`);
|
|
31
31
|
|
|
32
32
|
export async function load(ev: ServerEvent, template: string): Promise<Response> {
|
|
33
|
-
//const url = new URL(`http://${process.env.HOST ?? "localhost"}${ev.request.url}`);
|
|
34
33
|
const url = new URL(ev.request.url);
|
|
35
34
|
const path = url.pathname;
|
|
36
35
|
const query = url.searchParams;
|
|
@@ -303,22 +302,41 @@ async function runAction(
|
|
|
303
302
|
}
|
|
304
303
|
}
|
|
305
304
|
|
|
306
|
-
|
|
305
|
+
let result = await action(serverParams);
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
307
|
+
if (ev.request.headers.has("x-torpor-form-submit")) {
|
|
308
|
+
// If the form was submitted from javascript, just return the
|
|
309
|
+
// response and it will be handled on the client
|
|
310
|
+
// TODO: Should we make the user return a response??
|
|
311
|
+
result ??= ok();
|
|
312
|
+
|
|
313
|
+
// If it's a redirect, we need to stop the browser handling it
|
|
314
|
+
if (result.status >= 300 && result.status <= 399) {
|
|
315
|
+
const location = result.headers.get("location") ?? "";
|
|
316
|
+
result = ok();
|
|
317
|
+
result.headers.set("x-torpor-form-redirect", "");
|
|
318
|
+
result.headers.set("location", location);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return result;
|
|
322
|
+
} else if (
|
|
312
323
|
!result ||
|
|
313
324
|
(result.status >= 200 && result.status <= 299) ||
|
|
314
325
|
(result.status >= 400 && result.status <= 499)
|
|
315
326
|
) {
|
|
327
|
+
// If the form was submitted without javascript, and there was
|
|
328
|
+
// no result, an ok result, or a 4xx error, re-render the view
|
|
329
|
+
// with the form result
|
|
330
|
+
// TODO: do not re-run hooks?
|
|
316
331
|
const newUrl = new URL(url.pathname, url);
|
|
317
332
|
const formStatus = result?.status;
|
|
318
333
|
const form = await result?.json();
|
|
319
334
|
$page.form = form;
|
|
320
335
|
return await loadView(ev, newUrl, handler, params, template, formStatus, form);
|
|
321
336
|
} else {
|
|
337
|
+
// If the form was submitted without javascript and there was a
|
|
338
|
+
// redirect or server error, just return the result to handle it
|
|
339
|
+
// as normal
|
|
322
340
|
return result;
|
|
323
341
|
}
|
|
324
342
|
}
|
package/src/state/internal.ts
CHANGED
|
@@ -4,8 +4,9 @@ import type InternalState from "../types/InternalState";
|
|
|
4
4
|
import type PageState from "../types/PageState";
|
|
5
5
|
|
|
6
6
|
// Do a weird little dance to ensure that everyone has the same $page and
|
|
7
|
-
// client, regardless of if they are entering via serverEntry/clientEntry or
|
|
8
|
-
//
|
|
7
|
+
// client, regardless of if they are entering via serverEntry/clientEntry or
|
|
8
|
+
// importing from the @torpor/build library (e.g. in components). There may be
|
|
9
|
+
// an easier way to do this!
|
|
9
10
|
|
|
10
11
|
const INTERNAL_GLOBAL: unique symbol = Symbol.for("torpor-internal");
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ export default function internal(): InternalState {
|
|
|
17
18
|
{
|
|
18
19
|
status: 404,
|
|
19
20
|
url: new URL("http://localhost"),
|
|
20
|
-
form:
|
|
21
|
+
form: undefined,
|
|
21
22
|
error: {
|
|
22
23
|
message: "",
|
|
23
24
|
},
|
package/src/test/runTest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ServerComponent, type ServerSlotRender } from "@torpor/view";
|
|
1
|
+
import { type ServerComponent, type ServerSlotRender } from "@torpor/view/ssr";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import notFound from "../response/notFound.ts";
|
|
4
4
|
import ok from "../response/ok.ts";
|
package/src/types/LayoutPath.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server-CSpY_-Ba.d.ts","names":[],"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts","../src/server/types/MiddlewareFunction.ts","../src/server/types/ServerFunction.ts","../src/server/Server.ts"],"sourcesContent":[],"mappings":";;;cAEqB,YAAA;WACX;EAHyC,OAE9B,EAEX,GAFW,CAAA,MAAA,EAAA,MAAA,CAAA;EAAA,WAAA,CAAA,OAAA,EAIC,OAJD;UACX,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;UACA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAgBkC,gBAhBlC,CAAA,EAAA,IAAA;QAEY,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA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-1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_page-CsdPubw4.js","names":["INTERNAL_GLOBAL: unique symbol","$page: PageState","client: ClientState","$page: PageState"],"sources":["../src/state/internal.ts","../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\nimport type ClientState from \"../types/ClientState\";\nimport type InternalState from \"../types/InternalState\";\nimport type PageState from \"../types/PageState\";\n\n// Do a weird little dance to ensure that everyone has the same $page and\n// client, regardless of if they are entering via serverEntry/clientEntry or the\n// built library. There may be an easier way to do this!\n\nconst INTERNAL_GLOBAL: unique symbol = Symbol.for(\"torpor-internal\");\n\nexport default function internal(): InternalState {\n\t// @ts-ignore\n\tif (globalThis[INTERNAL_GLOBAL] === undefined) {\n\t\t// TODO: Should use the SSR $watch if entering via serverEntry\n\t\tconst $page: PageState = $watch(\n\t\t\t{\n\t\t\t\tstatus: 404,\n\t\t\t\turl: new URL(\"http://localhost\"),\n\t\t\t\tform: {},\n\t\t\t\terror: {\n\t\t\t\t\tmessage: \"\",\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tshallow: true,\n\t\t\t},\n\t\t);\n\t\tconst client: ClientState = {\n\t\t\t// @ts-ignore This will definitely, 100% get set\n\t\t\trouter: null,\n\t\t\tlayoutStack: [],\n\t\t\t// TODO: Probably expire after 30 seconds or something?\n\t\t\tprefetchedData: {},\n\t\t};\n\n\t\t// @ts-ignore\n\t\tglobalThis[INTERNAL_GLOBAL] = {\n\t\t\t$page,\n\t\t\tclient,\n\t\t} satisfies InternalState;\n\t}\n\t// @ts-ignore\n\treturn globalThis[INTERNAL_GLOBAL] as InternalState;\n}\n","import type PageState from \"../types/PageState\";\nimport internal from \"./internal\";\n\nconst $page: PageState = internal().$page;\n\nexport default $page;\n"],"mappings":";;;AASA,MAAMA,kBAAiC,OAAO,IAAI,kBAAkB;AAEpE,SAAwB,WAA0B;AAEjD,KAAI,WAAW,qBAAqB,QAAW;EAE9C,MAAMC,UAAmB,OACxB;GACC,QAAQ;GACR,KAAK,IAAI,IAAI,mBAAmB;GAChC,MAAM,EAAE;GACR,OAAO,EACN,SAAS,IACT;GACD,EACD,EACC,SAAS,MACT,CACD;EACD,MAAMC,SAAsB;GAE3B,QAAQ;GACR,aAAa,EAAE;GAEf,gBAAgB,EAAE;GAClB;AAGD,aAAW,mBAAmB;GAC7B;GACA;GACA;;AAGF,QAAO,WAAW;;;;;ACxCnB,MAAMC,QAAmB,UAAU,CAAC;AAEpC,oBAAe"}
|
package/dist/run-CNdaKSPR.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-CNdaKSPR.js","names":["path","path","fs","createViteServer","path","fs","e: any","types: Record<string, string>","path","fs","e: any","path"],"sources":["../src/site/manifest.ts","../src/run/runBuild.ts","../src/run/prepareTemplate.ts","../src/run/runDev.ts","../src/server/contentType.ts","../src/run/runPreview.ts","../src/run/run.ts"],"sourcesContent":["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\t// @ts-ignore\n\t\tload(id, viteOptions) {\n\t\t\tif (id === moduleId) {\n\t\t\t\tlet serverRequest = server && !!viteOptions?.ssr;\n\t\t\t\treturn `\n${!serverRequest ? \"const load = { default: { load: true } };\" : \"\"}\nexport default {\n routes: [\n ${site.routes\n\t\t\t.map((r) => {\n\t\t\t\tif (serverRequest || !/server\\.(ts|js)$/.test(r.file)) {\n\t\t\t\t\treturn `{ path: \"${r.path}\", type: ${r.type}, endPoint: ${serverRequest || !/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}\", 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 { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport Site from \"../site/Site\";\nimport manifest from \"../site/manifest.ts\";\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): Promise<void> {\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\tconst clientConfig = structuredClone(site.viteConfig ?? {});\n\tclientConfig.plugins = [manifest(site), torpor(), ...site.plugins];\n\tclientConfig.build ??= {};\n\tclientConfig.build.outDir = clientFolder;\n\tclientConfig.build.rollupOptions ??= {};\n\tclientConfig.build.rollupOptions.input = [\n\t\tsiteHtml,\n\t\tclientScript,\n\t\t...site.routes\n\t\t\t.filter((r) => !/server\\.(ts|js)$/.test(r.file))\n\t\t\t.map((r) => path.resolve(site.root, r.file)),\n\t\t...site.inputs.filter((f) => !/server\\.(ts|js)$/.test(f)),\n\t];\n\tclientConfig.build.ssrManifest = true;\n\tawait build(defineConfig(clientConfig));\n\n\t// Build the server assets, including the server entry script and the route\n\t// files\n\tconst serverConfig = structuredClone(site.viteConfig ?? {});\n\tserverConfig.plugins = [manifest(site, true), torpor(), ...site.plugins];\n\tserverConfig.build ??= {};\n\tserverConfig.build.outDir = serverFolder;\n\tserverConfig.build.rollupOptions ??= {};\n\tserverConfig.build.rollupOptions.input = [\n\t\tserverScript,\n\t\t...site.routes.map((r) => path.resolve(site.root, r.file)),\n\t\t...site.inputs,\n\t];\n\tserverConfig.build.ssr = serverScript;\n\tawait build(defineConfig(serverConfig));\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","export default function prepareTemplate(template: string, clientScript: string): string {\n\tlet result = template;\n\n\t// Put %COMPONENT_HEAD% before </head>\n\t// This is where styles will go\n\tlet headStart = result.indexOf(\"</head>\");\n\tif (headStart === -1) {\n\t\tthrow new Error(`Couldn't find <head> end tag`);\n\t}\n\tresult = result.substring(0, headStart) + \"%COMPONENT_HEAD%\" + result.substring(headStart);\n\n\t// Put %COMPONENT_BODY% inside <div id=\"app\"></div>\n\t// This is where the component's HTML will go\n\tlet bodyStart = regexIndexOf(result, /<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tbodyStart = result.indexOf(\">\", bodyStart) + 1;\n\tlet bodyEnd = result.indexOf(\"</div>\", bodyStart);\n\tif (bodyStart === -1 || bodyEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tresult = result.substring(0, bodyStart) + \"%COMPONENT_BODY%\" + result.substring(bodyEnd);\n\n\t// Add the clientEntry script at the very end, for hydrating and navigating\n\tresult += `<script type=\"module\" src=\"${clientScript}\"></script>`;\n\n\treturn result;\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 estorpor from \"@torpor/unplugin/esbuild\";\nimport torpor from \"@torpor/unplugin/vite\";\nimport { configDotenv } from \"dotenv\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { createServer as createViteServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport connectMiddleware from \"../server/connect/connectMiddleware.ts\";\nimport Site from \"../site/Site.ts\";\nimport manifest from \"../site/manifest.ts\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\nexport default async function runDev(site: Site): Promise<void> {\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 config = structuredClone(site.viteConfig ?? {});\n\tconfig.server = { middlewareMode: true };\n\tconfig.appType = \"custom\";\n\tconfig.plugins = [manifest(site, true), torpor(), ...site.plugins];\n\n\t// HACK: To be able to import `.torp` files from barrel files in\n\t// node_modules, we need to add their libraries to `ssr.noExternal` in\n\t// site.config.ts, and let esbuild know how to compile them here\n\tconfig.optimizeDeps ??= {};\n\tconfig.optimizeDeps.extensions ??= [];\n\tconfig.optimizeDeps.extensions.push(\".torp\");\n\tconfig.optimizeDeps.esbuildOptions ??= {};\n\tconfig.optimizeDeps.esbuildOptions.plugins ??= [];\n\tconfig.optimizeDeps.esbuildOptions.plugins.push(estorpor());\n\n\tconst vite = await createViteServer(config);\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 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// 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(connectMiddleware(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","// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types\n\nexport default function contentType(extension: string): 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","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/Site\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\nimport runBuild from \"./runBuild\";\n\nexport default async function runPreview(site: Site): Promise<void> {\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\tconst body = bufferToArrayBuffer(await fs.readFile(file));\n\t\t\t\treturn new Response(body, {\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\n// From https://stackoverflow.com/a/79345620\n// No idea why it is needed\nfunction bufferToArrayBuffer(buffer: Buffer): ArrayBuffer {\n\treturn buffer.buffer.slice(\n\t\tbuffer.byteOffset,\n\t\tbuffer.byteOffset + buffer.byteLength,\n\t) as ArrayBuffer;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { transformWithEsbuild } from \"vite\";\nimport Site from \"../site/Site\";\nimport runBuild from \"./runBuild\";\nimport runDev from \"./runDev\";\nimport runPreview from \"./runPreview\";\n\nexport default async function run(\n\tfolder: string,\n\tmode: \"dev\" | \"build\" | \"preview\",\n): Promise<void> {\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 = fs.readFileSync(tsConfigFile, \"utf-8\");\n\t\tlet transformed = await transformWithEsbuild(source, tsConfigFile, {\n\t\t\tloader: \"ts\",\n\t\t});\n\t\tfs.writeFileSync(configFile, transformed.code);\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"],"mappings":";;;;;;;;;;AAKA,MAAM,WAAW;;;;;AAMjB,SAAwB,SAAS,MAAY,SAAS,OAAe;AACpE,QAAO;EACN,MAAM;EACN,WAAW;GACV,OAAO;GACP,QAAQ,IAAI;AACX,QAAI,OAAO,SACV,QAAO;;GAGT;EAED,KAAK,IAAI,aAAa;AACrB,OAAI,OAAO,UAAU;IACpB,IAAI,gBAAgB,UAAU,CAAC,CAAC,aAAa;AAC7C,WAAO;EACT,CAAC,gBAAgB,8CAA8C,GAAG;;;MAG9D,KAAK,OACP,KAAK,MAAM;AACX,SAAI,iBAAiB,CAAC,mBAAmB,KAAK,EAAE,KAAK,CACpD,QAAO,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,iBAAiB,CAAC,mBAAmB,KAAK,EAAE,KAAK,GAAG,oCAAoCA,MAAK,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,MAAM,YAAY;UAC3L;MAKN,MAAM,WAAW,aAAaA,MAAK,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,CAAC,SAAS,QAAQ;AAC7E,aAAO,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,cA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