@torpor/build 1.9.0 → 1.11.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/README.md +1 -1
- package/dist/{SessionHelper-MaodMaLU.d.mts → CacheOptions-C4-ebVt9.d.mts} +58 -8
- package/dist/CacheOptions-C4-ebVt9.d.mts.map +1 -0
- package/dist/{MiddlewareFunction-BZilnEei.d.mts → MiddlewareFunction-DMYxjzF4.d.mts} +31 -2
- package/dist/MiddlewareFunction-DMYxjzF4.d.mts.map +1 -0
- package/dist/{Router-By9Nlg39.d.mts → Router-DyK3DTWQ.d.mts} +4 -4
- package/dist/Router-DyK3DTWQ.d.mts.map +1 -0
- package/dist/{Server-dcRbdPXf.mjs → Server-BCijhgZp.mjs} +3 -3
- package/dist/{Server-dcRbdPXf.mjs.map → Server-BCijhgZp.mjs.map} +1 -1
- package/dist/{Server-qn5Ws_d0.d.mts → Server-ClwvuilS.d.mts} +2 -2
- package/dist/{Server-qn5Ws_d0.d.mts.map → Server-ClwvuilS.d.mts.map} +1 -1
- package/dist/{ServerEvent-BY4f3RVF.mjs → ServerEvent-BBRkd4Ya.mjs} +136 -31
- package/dist/ServerEvent-BBRkd4Ya.mjs.map +1 -0
- package/dist/{ServerHook-W111nEhe.d.mts → ServerHook-DY-NSG6n.d.mts} +2 -2
- package/dist/{ServerHook-W111nEhe.d.mts.map → ServerHook-DY-NSG6n.d.mts.map} +1 -1
- package/dist/{ServerLoadEvent-BH6oG1o6.d.mts → ServerLoadEvent-CpcgsKCU.d.mts} +32 -8
- package/dist/ServerLoadEvent-CpcgsKCU.d.mts.map +1 -0
- package/dist/{Site-DGZJB7Do.d.mts → Site-BEMQW1_y.d.mts} +216 -11
- package/dist/Site-BEMQW1_y.d.mts.map +1 -0
- package/dist/{basePath-DQnbHc7o.mjs → basePath-B6hmOMl4.mjs} +89 -4
- package/dist/basePath-B6hmOMl4.mjs.map +1 -0
- package/dist/bin/index.js +37 -2
- package/dist/bin/index.js.map +1 -1
- package/dist/clientEntry.mjs +10 -5
- package/dist/clientEntry.mjs.map +1 -1
- package/dist/dev.d.mts +2 -2
- package/dist/dev.mjs +2 -2
- package/dist/{devPlugin-lLzauETn.mjs → devPlugin-BGrTpcC2.mjs} +3 -3
- package/dist/{devPlugin-lLzauETn.mjs.map → devPlugin-BGrTpcC2.mjs.map} +1 -1
- package/dist/discovery.d.mts +1 -1
- package/dist/discovery.mjs +1 -1
- package/dist/index.d.mts +22 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{load-BODDzmH0.mjs → load-Dw187nJ_.mjs} +95 -52
- package/dist/load-Dw187nJ_.mjs.map +1 -0
- package/dist/nav.d.mts +30 -3
- package/dist/nav.d.mts.map +1 -1
- package/dist/nav.mjs +40 -12
- package/dist/nav.mjs.map +1 -1
- package/dist/nodeDev.d.mts +1 -1
- package/dist/nodeDev.mjs +1 -1
- package/dist/openapi.d.mts +24 -80
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +36 -1
- package/dist/openapi.mjs.map +1 -0
- package/dist/{plugin-D8Www11B.mjs → plugin-BQsMnkTj.mjs} +42 -3
- package/dist/plugin-BQsMnkTj.mjs.map +1 -0
- package/dist/{read-DxMVAh5Y.mjs → read-CPW2iPum.mjs} +21 -2
- package/dist/read-CPW2iPum.mjs.map +1 -0
- package/dist/{response-C5EZsszY.mjs → response-B4UoOJvv.mjs} +3 -24
- package/dist/response-B4UoOJvv.mjs.map +1 -0
- package/dist/response.mjs +2 -2
- package/dist/run.d.mts +1 -1
- package/dist/run.d.mts.map +1 -1
- package/dist/run.mjs +1 -1
- package/dist/{runHooks-D5p1Rh7i.mjs → runHooks-C7kt7SEo.mjs} +36 -2
- package/dist/runHooks-C7kt7SEo.mjs.map +1 -0
- package/dist/{runOpenApi-C5yMpQU1.mjs → runOpenApi-DK-QnYEr.mjs} +279 -35
- package/dist/runOpenApi-DK-QnYEr.mjs.map +1 -0
- package/dist/server/Server.d.mts +1 -1
- package/dist/server/Server.mjs +1 -1
- package/dist/server.d.mts +30 -6
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +47 -3
- package/dist/server.mjs.map +1 -1
- package/dist/{serverEntry-BGii8bB6.d.mts → serverEntry-BFad1k1C.d.mts} +3 -3
- package/dist/serverEntry-BFad1k1C.d.mts.map +1 -0
- package/dist/{serverEntry-D1hE-Jzt.mjs → serverEntry-DAT7o7o2.mjs} +3 -5
- package/dist/serverEntry-DAT7o7o2.mjs.map +1 -0
- package/dist/serverEntry.d.mts +1 -1
- package/dist/serverEntry.mjs +1 -1
- package/dist/{serverHandlers-CSBUEgJt.mjs → serverHandlers-B1L8I72-.mjs} +434 -202
- package/dist/serverHandlers-B1L8I72-.mjs.map +1 -0
- package/dist/{sitemap-xmE0zfme.d.mts → sitemap-CKmagPyL.d.mts} +2 -2
- package/dist/{sitemap-xmE0zfme.d.mts.map → sitemap-CKmagPyL.d.mts.map} +1 -1
- package/dist/{sitemap-4imxJVrG.mjs → sitemap-DdzFjGlo.mjs} +2 -2
- package/dist/{sitemap-4imxJVrG.mjs.map → sitemap-DdzFjGlo.mjs.map} +1 -1
- package/dist/state.d.mts +1 -4
- package/dist/state.d.mts.map +1 -1
- package/dist/state.mjs +1 -1
- package/dist/test.d.mts +2 -2
- package/dist/test.mjs +2 -2
- package/dist/{unprocessable-DwAG44Rh.mjs → unprocessable-BZXwyN0n.mjs} +23 -2
- package/dist/unprocessable-BZXwyN0n.mjs.map +1 -0
- package/package.json +10 -7
- package/src/types/manifest.d.ts +3 -0
- package/dist/MiddlewareFunction-BZilnEei.d.mts.map +0 -1
- package/dist/Router-By9Nlg39.d.mts.map +0 -1
- package/dist/ServerEvent-BY4f3RVF.mjs.map +0 -1
- package/dist/ServerLoadEvent-BH6oG1o6.d.mts.map +0 -1
- package/dist/SessionHelper-MaodMaLU.d.mts.map +0 -1
- package/dist/Site-DGZJB7Do.d.mts.map +0 -1
- package/dist/_page-CW6SLuT4.mjs +0 -14
- package/dist/_page-CW6SLuT4.mjs.map +0 -1
- package/dist/basePath-DQnbHc7o.mjs.map +0 -1
- package/dist/load-BODDzmH0.mjs.map +0 -1
- package/dist/plugin-D8Www11B.mjs.map +0 -1
- package/dist/read-DxMVAh5Y.mjs.map +0 -1
- package/dist/response-C5EZsszY.mjs.map +0 -1
- package/dist/runHooks-D5p1Rh7i.mjs.map +0 -1
- package/dist/runOpenApi-C5yMpQU1.mjs.map +0 -1
- package/dist/serverEntry-BGii8bB6.d.mts.map +0 -1
- package/dist/serverEntry-D1hE-Jzt.mjs.map +0 -1
- package/dist/serverHandlers-CSBUEgJt.mjs.map +0 -1
- package/dist/unprocessable-DwAG44Rh.mjs.map +0 -1
package/dist/clientEntry.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/nav/navigationFailure.ts","../src/site/clientEntry.ts"],"sourcesContent":["import type { NavigationResult } from \"./navigate.ts\";\n\n/**\n * The detail of the `torpor:navigation-failed` window event.\n */\nexport type NavigationFailureDetail = {\n\t/** The url the navigation was headed to. */\n\thref: string;\n\t/** Why the page was kept: the network is unreachable. */\n\treason: \"offline\";\n\t/** The failure that would have triggered the document fallback. */\n\terror?: unknown;\n};\n\n/** What the caller should do after a navigation rendered nothing. */\nexport type NavigationFallback = \"document\" | \"kept\";\n\n/**\n * Decides what happens after a navigation rendered nothing.\n *\n * A failed navigation while offline can't be recovered by a document load\n * either (unless a service worker has that url cached), so the current page is\n * kept — often holding an unsaved form or an optimistic edit — and the app is\n * told through the cancelable `torpor:navigation-failed` `CustomEvent` on\n * `window`. Everything else takes the document fallback: by-design server\n * navigations (`+server` routes, redirects), and online failures such as a\n * stale chunk hash, which a reload fixes by picking up the new manifest.\n *\n * `navigator.onLine` only reports that the machine has a network interface,\n * not that the server is reachable, so it is used here as a hint (it decides\n * whether to keep the page, not whether the network works). The event carries\n * the caught error so an app can tell the cases apart.\n *\n * Returns `\"document\"` when the caller should navigate the document, and\n * `\"kept\"` when the page was left in place.\n */\nexport default function handleNavigationFailure(\n\thref: string,\n\tresult: NavigationResult,\n): NavigationFallback {\n\tif (result.type !== \"failed\" || navigator.onLine !== false) {\n\t\treturn \"document\";\n\t}\n\n\tconst event = new CustomEvent<NavigationFailureDetail>(\"torpor:navigation-failed\", {\n\t\tcancelable: true,\n\t\tdetail: { href, reason: \"offline\", error: result.error },\n\t});\n\t// An app that cancels the event (e.g. its service worker caches the target\n\t// shell) asks for the document navigation after all\n\tif (!window.dispatchEvent(event)) {\n\t\treturn \"document\";\n\t}\n\n\tconsole.warn(\n\t\t`Navigation to ${href} failed while offline; staying on the current page. ` +\n\t\t\t\"Listen for torpor:navigation-failed to show your own notice.\",\n\t);\n\treturn \"kept\";\n}\n","import manifest from \"@torpor/build/manifest\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport type { NavigationResult } from \"../nav/navigate.ts\";\nimport handleNavigationFailure from \"../nav/navigationFailure.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport Router from \"./Router.ts\";\nimport { setBasePath } from \"./basePath.ts\";\n\nsetBasePath(manifest.base);\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\nclient.viewTransitions = manifest.viewTransitions ?? false;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tlet result: NavigationResult;\n\t\ttry {\n\t\t\tresult = await navigate(url);\n\t\t} catch (error) {\n\t\t\t// `navigate` already catches its own failures, but never let an\n\t\t\t// unexpected throw swallow the fallback\n\t\t\tconsole.error(error);\n\t\t\tresult = { type: \"failed\", error };\n\t\t}\n\t\tif (result.type === \"rendered\") {\n\t\t\t// Save the scroll position of the outgoing page on the current\n\t\t\t// history entry, so that going (or coming) back can restore it\n\t\t\twindow.history.replaceState({ scroll: window.scrollY }, \"\", document.location.href);\n\t\t\twindow.history.pushState({ scroll: 0 }, \"\", url);\n\t\t} else if (handleNavigationFailure(href, result) === \"document\") {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n// Keyboard focus, and the press-down that precedes a click (a fast click can\n// land before any hover), warm the target too, so the navigation can await the\n// same in-flight request rather than starting its own\nwindow.addEventListener(\"focusin\", maybePrefetch);\nwindow.addEventListener(\"pointerdown\", maybePrefetch);\n\nasync function maybePrefetch(e: Event) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\t// Nothing to warm for the page we're already on\n\t\tif (path === document.location.pathname) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\ttry {\n\t\t\t\t// A route with no client endpoint (a pure `+server` route) has\n\t\t\t\t// nothing to prefetch\n\t\t\t\tconst clientEndPoint: PageEndPoint | undefined = handler.endPoint\n\t\t\t\t\t? (await handler.endPoint())?.default\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!clientEndPoint?.component) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Just dummy this up\n\t\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, true);\n\t\t\t} catch {\n\t\t\t\t// A prefetch is best-effort: the real navigation retries\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: Event) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\tconst mouse = e as MouseEvent;\n\treturn (\n\t\te.defaultPrevented ||\n\t\tmouse.altKey ||\n\t\tmouse.ctrlKey ||\n\t\tmouse.metaKey ||\n\t\tmouse.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tconst result = await navigateToLocation(document.location);\n\tif (result.type !== \"rendered\") {\n\t\t// TODO: keep the page and notify the app when offline, like a click\n\t\t// failure; the url has already moved here, so that needs a history fix\n\t\twindow.location.reload();\n\t\treturn;\n\t}\n\t// Restore the scroll position that was saved on the history entry\n\trequestAnimationFrame(() => {\n\t\tconst state = window.history.state as { scroll?: number } | null;\n\t\twindow.scrollTo(0, state?.scroll ?? 0);\n\t});\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(\n\tlocation: Location,\n\tfirstTime = false,\n): Promise<NavigationResult> {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAwB,wBACvB,MACA,QACqB;CACrB,IAAI,OAAO,SAAS,YAAY,UAAU,WAAW,OACpD,OAAO;CAGR,MAAM,QAAQ,IAAI,YAAqC,4BAA4B;EAClF,YAAY;EACZ,QAAQ;GAAE;GAAM,QAAQ;GAAW,OAAO,OAAO;EAAM;CACxD,CAAC;CAGD,IAAI,CAAC,OAAO,cAAc,KAAK,GAC9B,OAAO;CAGR,QAAQ,KACP,iBAAiB,KAAK,iHAEvB;CACA,OAAO;AACR;;;AC/CA,YAAY,SAAS,IAAI;AAGzB,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAChB,OAAO,kBAAkB,SAAS,mBAAmB;AAGrD,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,EAAE,eAAe;EAEjB,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,IAAI;EACJ,IAAI;GACH,SAAS,MAAM,SAAS,GAAG;EAC5B,SAAS,OAAO;GAGf,QAAQ,MAAM,KAAK;GACnB,SAAS;IAAE,MAAM;IAAU;GAAM;EAClC;EACA,IAAI,OAAO,SAAS,YAAY;GAG/B,OAAO,QAAQ,aAAa,EAAE,QAAQ,OAAO,QAAQ,GAAG,IAAI,SAAS,SAAS,IAAI;GAClF,OAAO,QAAQ,U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K,aAAa,UAAU,KAC5B,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAE/C,KAAI,MADiB,mBAAmB,SAAS,QAAQ,EAAA,CAC9C,SAAS,YAAY;EAG/B,OAAO,SAAS,OAAO;EACvB;CACD;CAEA,4BAA4B;EAC3B,MAAM,QAAQ,OAAO,QAAQ;EAC7B,OAAO,SAAS,GAAG,OAAO,UAAU,CAAC;CACtC,CAAC;AACF,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBACd,UACA,YAAY,OACgB;CAG5B,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
|
|
1
|
+
{"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/nav/navigationFailure.ts","../src/site/clientEntry.ts"],"sourcesContent":["import type { NavigationResult } from \"./navigate.ts\";\n\n/**\n * The detail of the `torpor:navigation-failed` window event.\n */\nexport type NavigationFailureDetail = {\n\t/** The url the navigation was headed to. */\n\thref: string;\n\t/** Why the page was kept: the network is unreachable. */\n\treason: \"offline\";\n\t/** The failure that would have triggered the document fallback. */\n\terror?: unknown;\n};\n\n/** What the caller should do after a navigation rendered nothing. */\nexport type NavigationFallback = \"document\" | \"kept\";\n\n/**\n * Decides what happens after a navigation rendered nothing.\n *\n * A failed navigation while offline can't be recovered by a document load\n * either (unless a service worker has that url cached), so the current page is\n * kept — often holding an unsaved form or an optimistic edit — and the app is\n * told through the cancelable `torpor:navigation-failed` `CustomEvent` on\n * `window`. Everything else takes the document fallback: by-design server\n * navigations (`+server` routes, redirects), and online failures such as a\n * stale chunk hash, which a reload fixes by picking up the new manifest.\n *\n * `navigator.onLine` only reports that the machine has a network interface,\n * not that the server is reachable, so it is used here as a hint (it decides\n * whether to keep the page, not whether the network works). The event carries\n * the caught error so an app can tell the cases apart.\n *\n * Returns `\"document\"` when the caller should navigate the document, and\n * `\"kept\"` when the page was left in place.\n */\nexport default function handleNavigationFailure(\n\thref: string,\n\tresult: NavigationResult,\n): NavigationFallback {\n\tif (result.type !== \"failed\" || navigator.onLine !== false) {\n\t\treturn \"document\";\n\t}\n\n\tconst event = new CustomEvent<NavigationFailureDetail>(\"torpor:navigation-failed\", {\n\t\tcancelable: true,\n\t\tdetail: { href, reason: \"offline\", error: result.error },\n\t});\n\t// An app that cancels the event (e.g. its service worker caches the target\n\t// shell) asks for the document navigation after all\n\tif (!window.dispatchEvent(event)) {\n\t\treturn \"document\";\n\t}\n\n\tconsole.warn(\n\t\t`Navigation to ${href} failed while offline; staying on the current page. ` +\n\t\t\t\"Listen for torpor:navigation-failed to show your own notice.\",\n\t);\n\treturn \"kept\";\n}\n","import manifest from \"@torpor/build/manifest\";\nimport { setUrlRewriter } from \"@torpor/view\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport type { NavigationResult } from \"../nav/navigate.ts\";\nimport handleNavigationFailure from \"../nav/navigationFailure.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport Router from \"./Router.ts\";\nimport { addBaseToPath, getBasePath, setBasePath } from \"./basePath.ts\";\n\nsetBasePath(manifest.base);\n\n// Markup is written base-free: the server adds the base to the links in its\n// HTML, and this adds it to the ones the client sets (dynamic attributes,\n// and pages and branches rendered on the client)\nconst base = getBasePath();\nif (base) {\n\tsetUrlRewriter((url) => addBaseToPath(url, base));\n}\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\nclient.viewTransitions = manifest.viewTransitions ?? false;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tlet result: NavigationResult;\n\t\ttry {\n\t\t\tresult = await navigate(url);\n\t\t} catch (error) {\n\t\t\t// `navigate` already catches its own failures, but never let an\n\t\t\t// unexpected throw swallow the fallback\n\t\t\tconsole.error(error);\n\t\t\tresult = { type: \"failed\", error };\n\t\t}\n\t\tif (result.type === \"rendered\") {\n\t\t\t// Save the scroll position of the outgoing page on the current\n\t\t\t// history entry, so that going (or coming) back can restore it\n\t\t\twindow.history.replaceState({ scroll: window.scrollY }, \"\", document.location.href);\n\t\t\twindow.history.pushState({ scroll: 0 }, \"\", url);\n\t\t} else if (result.type === \"superseded\") {\n\t\t\t// A newer navigation won; it owns the history entry and the page,\n\t\t\t// so do nothing (in particular, don't fall back to a document load)\n\t\t\treturn;\n\t\t} else if (handleNavigationFailure(href, result) === \"document\") {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n// Keyboard focus, and the press-down that precedes a click (a fast click can\n// land before any hover), warm the target too, so the navigation can await the\n// same in-flight request rather than starting its own\nwindow.addEventListener(\"focusin\", maybePrefetch);\nwindow.addEventListener(\"pointerdown\", maybePrefetch);\n\nasync function maybePrefetch(e: Event) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\t// Nothing to warm for the page we're already on\n\t\tif (path === document.location.pathname) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\ttry {\n\t\t\t\t// A route with no client endpoint (a pure `+server` route) has\n\t\t\t\t// nothing to prefetch\n\t\t\t\tconst clientEndPoint: PageEndPoint | undefined = handler.endPoint\n\t\t\t\t\t? (await handler.endPoint())?.default\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!clientEndPoint?.component) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Just dummy this up\n\t\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, true);\n\t\t\t} catch {\n\t\t\t\t// A prefetch is best-effort: the real navigation retries\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: Event) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\tconst mouse = e as MouseEvent;\n\treturn (\n\t\te.defaultPrevented ||\n\t\tmouse.altKey ||\n\t\tmouse.ctrlKey ||\n\t\tmouse.metaKey ||\n\t\tmouse.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tconst result = await navigateToLocation(document.location);\n\tif (result.type === \"superseded\") {\n\t\t// A newer navigation (another popstate, or a click) owns the url; it\n\t\t// handles the page and the scroll position\n\t\treturn;\n\t}\n\tif (result.type !== \"rendered\") {\n\t\t// TODO: keep the page and notify the app when offline, like a click\n\t\t// failure; the url has already moved here, so that needs a history fix\n\t\twindow.location.reload();\n\t\treturn;\n\t}\n\t// Restore the scroll position that was saved on the history entry\n\trequestAnimationFrame(() => {\n\t\tconst state = window.history.state as { scroll?: number } | null;\n\t\twindow.scrollTo(0, state?.scroll ?? 0);\n\t});\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(\n\tlocation: Location,\n\tfirstTime = false,\n): Promise<NavigationResult> {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAwB,wBACvB,MACA,QACqB;CACrB,IAAI,OAAO,SAAS,YAAY,UAAU,WAAW,OACpD,OAAO;CAGR,MAAM,QAAQ,IAAI,YAAqC,4BAA4B;EAClF,YAAY;EACZ,QAAQ;GAAE;GAAM,QAAQ;GAAW,OAAO,OAAO;EAAM;CACxD,CAAC;CAGD,IAAI,CAAC,OAAO,cAAc,KAAK,GAC9B,OAAO;CAGR,QAAQ,KACP,iBAAiB,KAAK,iHAEvB;CACA,OAAO;AACR;;;AC9CA,YAAY,SAAS,IAAI;AAKzB,MAAM,OAAO,YAAY;AACzB,IAAI,MACH,gBAAgB,QAAQ,cAAc,KAAK,IAAI,CAAC;AAIjD,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAChB,OAAO,kBAAkB,SAAS,mBAAmB;AAGrD,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,M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S,QAAQ,MAAM,OAAO,CAAO,GAAG,gBAAgB,IAAI;GAC5E,QAAQ,CAER;EACD;CACD;AACD;AAEA,SAAS,QAAQ,QAA2D;CAI3E,IAAI,EAAE,kBAAkB,UAAU;CAClC,MAAM,OAAO,OAAO,QAAQ,SAAS;CACrC,IAAI,MAAM,aAAa,MAAM,CAAC,EAAE,WAAW,GAAG,GAAG;CACjD,OAAQ,QAA8B,KAAA;AACvC;AAEA,SAAS,uBAAuB,MAAyB,GAAU;CAKlE,MAAM,QAAQ;CACd,OACC,EAAE,oBACF,MAAM,UACN,MAAM,WACN,MAAM,WACN,MAAM,YACL,KAAK,UAAU,KAAK,WAAW,WAChC,KAAK,QAAQ,cACb,KAAK,aAAa,UAAU,KAC5B,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAC/C,MAAM,SAAS,MAAM,mBAAmB,SAAS,QAAQ;CACzD,IAAI,OAAO,SAAS,cAGnB;CAED,IAAI,OAAO,SAAS,YAAY;EAG/B,OAAO,SAAS,OAAO;EACvB;CACD;CAEA,4BAA4B;EAC3B,MAAM,QAAQ,OAAO,QAAQ;EAC7B,OAAO,SAAS,GAAG,OAAO,UAAU,CAAC;CACtC,CAAC;AACF,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBACd,UACA,YAAY,OACgB;CAG5B,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
|
package/dist/dev.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
2
|
-
import { t as load } from "./serverEntry-
|
|
1
|
+
import { t as Server } from "./Server-ClwvuilS.mjs";
|
|
2
|
+
import { t as load } from "./serverEntry-BFad1k1C.mjs";
|
|
3
3
|
export { Server, load };
|
package/dist/dev.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
2
|
-
import { t as load } from "./serverEntry-
|
|
1
|
+
import { t as Server } from "./Server-BCijhgZp.mjs";
|
|
2
|
+
import { t as load } from "./serverEntry-DAT7o7o2.mjs";
|
|
3
3
|
export { Server, load };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as serverError } from "./response-
|
|
2
|
-
import { t as Server } from "./Server-
|
|
1
|
+
import { r as serverError } from "./response-B4UoOJvv.mjs";
|
|
2
|
+
import { t as Server } from "./Server-BCijhgZp.mjs";
|
|
3
3
|
import { t as flattenHeaders } from "./flattenHeaders-DM5qsSqO.mjs";
|
|
4
4
|
import { existsSync, promises, realpathSync } from "node:fs";
|
|
5
5
|
import fpath from "node:path";
|
|
@@ -141,4 +141,4 @@ async function sendResponse(response, res) {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
export { siteEntryPaths as i, prepareTemplate as n, detectSourceMode as r, devPlugin as t };
|
|
143
143
|
|
|
144
|
-
//# sourceMappingURL=devPlugin-
|
|
144
|
+
//# sourceMappingURL=devPlugin-BGrTpcC2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devPlugin-lLzauETn.mjs","names":["path","path","fs"],"sources":["../src/utils/entryPaths.ts","../src/run/prepareTemplate.ts","../src/run/devPlugin.ts"],"sourcesContent":["import { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to the site entry files that `tb` loads from the installed\n * `@torpor/build` package, in either source (linked framework) or dist\n * (registry install) mode.\n */\nexport type SiteEntryPaths = {\n\tserverEntry: string;\n\tclientEntry: string;\n\tclientDevEntry: string;\n};\n\n/**\n * Whether tb should run the framework from its TypeScript source instead of\n * its compiled dist. This is a framework-development convenience: registry\n * installs always run dist. Source mode is enabled explicitly via the\n * TORPOR_SOURCE_DEV env var, or automatically when both `@torpor/build` and\n * `@torpor/view` are symlinked into the app from outside node_modules (as\n * workspace links and `link:` overrides do). Both packages must be linked,\n * because source mode resolves their `torpor:source` export conditions, which\n * point at src files that registry installs don't ship.\n */\nexport function detectSourceMode(siteRoot: string): boolean {\n\tif (process.env.TORPOR_SOURCE_DEV) return true;\n\tconst packages = [\"@torpor/build\", \"@torpor/view\"];\n\treturn packages.every((pkg) => {\n\t\ttry {\n\t\t\tconst dist = path.resolve(siteRoot, \"node_modules\", pkg, \"dist/index.mjs\");\n\t\t\tconst real = realpathSync(dist);\n\t\t\treturn !real.includes(\"node_modules\");\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\n/**\n * The site entry files for the given mode: raw TypeScript sources when the\n * framework is linked (Vite transforms them, and edits show up without a\n * rebuild), compiled `.mjs` bundles for registry installs.\n */\nexport function siteEntryPaths(siteRoot: string, sourceMode: boolean): SiteEntryPaths {\n\tconst folder = path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/site\" : \"dist\",\n\t);\n\tconst ext = sourceMode ? \".ts\" : \".mjs\";\n\treturn {\n\t\tserverEntry: path.join(folder, `serverEntry${ext}`),\n\t\tclientEntry: path.join(folder, `clientEntry${ext}`),\n\t\tclientDevEntry: path.join(folder, `clientEntryDev${ext}`),\n\t};\n}\n\n/**\n * The torpor `Server` class module that a Cloudflare `_worker.ts` imports,\n * for the given mode.\n */\nexport function serverClassPath(siteRoot: string, sourceMode: boolean): string {\n\treturn path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/server/Server.ts\" : \"dist/server/Server.mjs\",\n\t);\n}\n","export default function prepareTemplate(\n\ttemplate: string,\n\tclientScript: string,\n\tclientDevScript?: string,\n): 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 divMatchStart = regexIndexOf(result, /<div\\s+id=(\"app\"|'app'|app)[\\s>]/);\n\tif (divMatchStart === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tlet bodyStart = result.indexOf(\">\", divMatchStart) + 1;\n\tlet bodyEnd = result.indexOf(\"</div>\", bodyStart);\n\tif (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\tif (clientDevScript) {\n\t\tresult += `<script type=\"module\" src=\"${clientDevScript}\"></script>`;\n\t}\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 { type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport { type Plugin, type ViteDevServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport flattenHeaders from \"../server/connect/flattenHeaders.ts\";\nimport type Site from \"../site/Site.ts\";\nimport { siteEntryPaths } from \"../utils/entryPaths\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\ntype ReqHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;\n\n/**\n * The default Node-runtime dev plugin. Reads `src/site.html`, sets up a torpor\n * `Server` whose catch-all route renders via `vite.ssrLoadModule`, and registers\n * a Connect middleware (after Vite's own middlewares) that bridges Node\n * req/res to the torpor Server's fetch handler.\n *\n * Adapters that need a different runtime (e.g. workerd) provide their own\n * `dev()` plugin instead.\n */\nexport default function devPlugin(site: Site, sourceMode = false): Plugin {\n\treturn {\n\t\tname: \"torpor-dev\",\n\t\tconfigureServer(vite) {\n\t\t\t// Kick off async setup immediately; the middleware awaits it so we\n\t\t\t// don't depend on whether Vite awaits configureServer itself.\n\t\t\tconst handlerPromise = createDevHandler(vite, site, sourceMode);\n\t\t\t// Return a post-hook so our middleware runs AFTER Vite's internal\n\t\t\t// middlewares (static serving, transforms, HMR), acting as the SSR\n\t\t\t// fallback.\n\t\t\treturn () => {\n\t\t\t\tvite.middlewares.use(async (req, res, next) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst handler = await handlerPromise;\n\t\t\t\t\t\tawait handler(req, res);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tnext(e as Error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t};\n}\n\nasync function createDevHandler(\n\tvite: ViteDevServer,\n\tsite: Site,\n\tsourceMode: boolean,\n): Promise<ReqHandler> {\n\tconst entries = siteEntryPaths(site.root, sourceMode);\n\tconst serverScript = entries.serverEntry;\n\n\t// Read site.html if present\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). An endpoints-only\n\t// site has no site.html, and no template is needed\n\tlet template: string | undefined;\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tif (existsSync(templateFile)) {\n\t\ttemplate = await fs.readFile(templateFile, \"utf-8\");\n\n\t\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t\t// universal transform, not individual transforms for each route\n\t\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t\t// Prepare site.html so that we can just splice components into it\n\t\ttemplate = prepareTemplate(template, entries.clientEntry, entries.clientDevEntry);\n\t}\n\n\tconst server = new Server();\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// Put adapter-specific functionality in the `adapter` property of\n\t// globalThis for now\n\t// @ts-ignore\n\tglobalThis.adapter = { env: process.env };\n\n\treturn async (req, res) => {\n\t\tconst request = await nodeReqToRequest(req);\n\t\tconst response = await server.fetch(request);\n\t\tawait sendResponse(response, res);\n\t};\n}\n\nasync function nodeReqToRequest(req: IncomingMessage): Promise<Request> {\n\tconst url = req.url ?? \"/\";\n\tconst host = req.headers.host ?? \"localhost\";\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst init: RequestInit = {\n\t\tmethod: req.method,\n\t\theaders: flattenHeaders(req.headers),\n\t};\n\tif (req.method !== \"GET\" && req.method !== \"HEAD\") {\n\t\tinit.body = Readable.toWeb(req) as ReadableStream;\n\t\t// @ts-ignore duplex is required when streaming a body\n\t\tinit.duplex = \"half\";\n\t}\n\treturn new Request(`${protocol}://${host}${url}`, init);\n}\n\nasync function sendResponse(response: Response, res: ServerResponse): Promise<void> {\n\tres.statusCode = response.status;\n\tresponse.headers.forEach((value, key) => res.setHeader(key, value));\n\tif (!response.body) {\n\t\tres.end();\n\t\treturn;\n\t}\n\tReadable.fromWeb(response.body as unknown as import(\"node:stream/web\").ReadableStream).pipe(res);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAiB,UAA2B;CAC3D,IAAI,QAAQ,IAAI,mBAAmB,OAAO;CAE1C,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QAAQ,QAAQ;CACjC,MAAM,WAAW,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,UAAU;CAC/E,MAAM,OAAoB;EACzB,QAAQ,IAAI;EACZ,SAAS,eAAe,IAAI,OAAO;CACpC;CACA,IAAI,IAAI,WAAW,SAAS,IAAI,WAAW,QAAQ;EAClD,KAAK,OAAO,SAAS,MAAM,GAAG;EAE9B,KAAK,SAAS;CACf;CACA,OAAO,IAAI,QAAQ,GAAG,SAAS,KAAK,OAAO,OAAO,IAAI;AACvD;AAEA,eAAe,aAAa,UAAoB,KAAoC;CACnF,IAAI,aAAa,SAAS;CAC1B,SAAS,QAAQ,SAAS,OAAO,QAAQ,IAAI,UAAU,KAAK,KAAK,CAAC;CAClE,IAAI,CAAC,SAAS,MAAM;EACnB,IAAI,IAAI;EACR;CACD;CACA,SAAS,QAAQ,SAAS,IAA2D,CAAC,CAAC,KAAK,GAAG;AAChG"}
|
|
1
|
+
{"version":3,"file":"devPlugin-BGrTpcC2.mjs","names":["path","path","fs"],"sources":["../src/utils/entryPaths.ts","../src/run/prepareTemplate.ts","../src/run/devPlugin.ts"],"sourcesContent":["import { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to the site entry files that `tb` loads from the installed\n * `@torpor/build` package, in either source (linked framework) or dist\n * (registry install) mode.\n */\nexport type SiteEntryPaths = {\n\tserverEntry: string;\n\tclientEntry: string;\n\tclientDevEntry: string;\n};\n\n/**\n * Whether tb should run the framework from its TypeScript source instead of\n * its compiled dist. This is a framework-development convenience: registry\n * installs always run dist. Source mode is enabled explicitly via the\n * TORPOR_SOURCE_DEV env var, or automatically when both `@torpor/build` and\n * `@torpor/view` are symlinked into the app from outside node_modules (as\n * workspace links and `link:` overrides do). Both packages must be linked,\n * because source mode resolves their `torpor:source` export conditions, which\n * point at src files that registry installs don't ship.\n */\nexport function detectSourceMode(siteRoot: string): boolean {\n\tif (process.env.TORPOR_SOURCE_DEV) return true;\n\tconst packages = [\"@torpor/build\", \"@torpor/view\"];\n\treturn packages.every((pkg) => {\n\t\ttry {\n\t\t\tconst dist = path.resolve(siteRoot, \"node_modules\", pkg, \"dist/index.mjs\");\n\t\t\tconst real = realpathSync(dist);\n\t\t\treturn !real.includes(\"node_modules\");\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\n/**\n * The site entry files for the given mode: raw TypeScript sources when the\n * framework is linked (Vite transforms them, and edits show up without a\n * rebuild), compiled `.mjs` bundles for registry installs.\n */\nexport function siteEntryPaths(siteRoot: string, sourceMode: boolean): SiteEntryPaths {\n\tconst folder = path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/site\" : \"dist\",\n\t);\n\tconst ext = sourceMode ? \".ts\" : \".mjs\";\n\treturn {\n\t\tserverEntry: path.join(folder, `serverEntry${ext}`),\n\t\tclientEntry: path.join(folder, `clientEntry${ext}`),\n\t\tclientDevEntry: path.join(folder, `clientEntryDev${ext}`),\n\t};\n}\n\n/**\n * The torpor `Server` class module that a Cloudflare `_worker.ts` imports,\n * for the given mode.\n */\nexport function serverClassPath(siteRoot: string, sourceMode: boolean): string {\n\treturn path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/server/Server.ts\" : \"dist/server/Server.mjs\",\n\t);\n}\n","export default function prepareTemplate(\n\ttemplate: string,\n\tclientScript: string,\n\tclientDevScript?: string,\n): 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 divMatchStart = regexIndexOf(result, /<div\\s+id=(\"app\"|'app'|app)[\\s>]/);\n\tif (divMatchStart === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tlet bodyStart = result.indexOf(\">\", divMatchStart) + 1;\n\tlet bodyEnd = result.indexOf(\"</div>\", bodyStart);\n\tif (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\tif (clientDevScript) {\n\t\tresult += `<script type=\"module\" src=\"${clientDevScript}\"></script>`;\n\t}\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 { type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport { type Plugin, type ViteDevServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport flattenHeaders from \"../server/connect/flattenHeaders.ts\";\nimport type Site from \"../site/Site.ts\";\nimport { siteEntryPaths } from \"../utils/entryPaths\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\ntype ReqHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;\n\n/**\n * The default Node-runtime dev plugin. Reads `src/site.html`, sets up a torpor\n * `Server` whose catch-all route renders via `vite.ssrLoadModule`, and registers\n * a Connect middleware (after Vite's own middlewares) that bridges Node\n * req/res to the torpor Server's fetch handler.\n *\n * Adapters that need a different runtime (e.g. workerd) provide their own\n * `dev()` plugin instead.\n */\nexport default function devPlugin(site: Site, sourceMode = false): Plugin {\n\treturn {\n\t\tname: \"torpor-dev\",\n\t\tconfigureServer(vite) {\n\t\t\t// Kick off async setup immediately; the middleware awaits it so we\n\t\t\t// don't depend on whether Vite awaits configureServer itself.\n\t\t\tconst handlerPromise = createDevHandler(vite, site, sourceMode);\n\t\t\t// Return a post-hook so our middleware runs AFTER Vite's internal\n\t\t\t// middlewares (static serving, transforms, HMR), acting as the SSR\n\t\t\t// fallback.\n\t\t\treturn () => {\n\t\t\t\tvite.middlewares.use(async (req, res, next) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst handler = await handlerPromise;\n\t\t\t\t\t\tawait handler(req, res);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tnext(e as Error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t};\n}\n\nasync function createDevHandler(\n\tvite: ViteDevServer,\n\tsite: Site,\n\tsourceMode: boolean,\n): Promise<ReqHandler> {\n\tconst entries = siteEntryPaths(site.root, sourceMode);\n\tconst serverScript = entries.serverEntry;\n\n\t// Read site.html if present\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). An endpoints-only\n\t// site has no site.html, and no template is needed\n\tlet template: string | undefined;\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tif (existsSync(templateFile)) {\n\t\ttemplate = await fs.readFile(templateFile, \"utf-8\");\n\n\t\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t\t// universal transform, not individual transforms for each route\n\t\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t\t// Prepare site.html so that we can just splice components into it\n\t\ttemplate = prepareTemplate(template, entries.clientEntry, entries.clientDevEntry);\n\t}\n\n\tconst server = new Server();\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// Put adapter-specific functionality in the `adapter` property of\n\t// globalThis for now\n\t// @ts-ignore\n\tglobalThis.adapter = { env: process.env };\n\n\treturn async (req, res) => {\n\t\tconst request = await nodeReqToRequest(req);\n\t\tconst response = await server.fetch(request);\n\t\tawait sendResponse(response, res);\n\t};\n}\n\nasync function nodeReqToRequest(req: IncomingMessage): Promise<Request> {\n\tconst url = req.url ?? \"/\";\n\tconst host = req.headers.host ?? \"localhost\";\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst init: RequestInit = {\n\t\tmethod: req.method,\n\t\theaders: flattenHeaders(req.headers),\n\t};\n\tif (req.method !== \"GET\" && req.method !== \"HEAD\") {\n\t\tinit.body = Readable.toWeb(req) as ReadableStream;\n\t\t// @ts-ignore duplex is required when streaming a body\n\t\tinit.duplex = \"half\";\n\t}\n\treturn new Request(`${protocol}://${host}${url}`, init);\n}\n\nasync function sendResponse(response: Response, res: ServerResponse): Promise<void> {\n\tres.statusCode = response.status;\n\tresponse.headers.forEach((value, key) => res.setHeader(key, value));\n\tif (!response.body) {\n\t\tres.end();\n\t\treturn;\n\t}\n\tReadable.fromWeb(response.body as unknown as import(\"node:stream/web\").ReadableStream).pipe(res);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAiB,UAA2B;CAC3D,IAAI,QAAQ,IAAI,mBAAmB,OAAO;CAE1C,OAAO,CADW,iBAAiB,cACrB,CAAC,CAAC,OAAO,QAAQ;EAC9B,IAAI;GACH,MAAM,OAAOA,MAAK,QAAQ,UAAU,gBAAgB,KAA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;EACZ,SAAS,eAAe,IAAI,OAAO;CACpC;CACA,IAAI,IAAI,WAAW,SAAS,IAAI,WAAW,QAAQ;EAClD,KAAK,OAAO,SAAS,MAAM,GAAG;EAE9B,KAAK,SAAS;CACf;CACA,OAAO,IAAI,QAAQ,GAAG,SAAS,KAAK,OAAO,OAAO,IAAI;AACvD;AAEA,eAAe,aAAa,UAAoB,KAAoC;CACnF,IAAI,aAAa,SAAS;CAC1B,SAAS,QAAQ,SAAS,OAAO,QAAQ,IAAI,UAAU,KAAK,KAAK,CAAC;CAClE,IAAI,CAAC,SAAS,MAAM;EACnB,IAAI,IAAI;EACR;CACD;CACA,SAAS,QAAQ,SAAS,IAA2D,CAAC,CAAC,KAAK,GAAG;AAChG"}
|
package/dist/discovery.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as sitemapResponse, r as HeadElement, t as SitemapOptions } from "./sitemap-
|
|
1
|
+
import { n as sitemapResponse, r as HeadElement, t as SitemapOptions } from "./sitemap-CKmagPyL.mjs";
|
|
2
2
|
//#region src/discovery/seo.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The elements to build head markup from: a page title, a description and
|
package/dist/discovery.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as Router } from "./Router-
|
|
1
|
+
import { t as Router } from "./Router-DyK3DTWQ.mjs";
|
|
2
2
|
import { a as RouteParamsOf, i as RouteArgsOf, n as ParseRouteParams, r as RouteArgs } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
3
|
-
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-
|
|
4
|
-
import { t as ServerHook } from "./ServerHook-
|
|
5
|
-
import { a as PageLoadReturn, i as PageEndPoint, o as PageLoadEvent } from "./sitemap-
|
|
3
|
+
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-CpcgsKCU.mjs";
|
|
4
|
+
import { t as ServerHook } from "./ServerHook-DY-NSG6n.mjs";
|
|
5
|
+
import { a as PageLoadReturn, i as PageEndPoint, o as PageLoadEvent } from "./sitemap-CKmagPyL.mjs";
|
|
6
6
|
import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
|
|
7
7
|
import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { C as PageServerActionSchemas, D as SitePlugin, E as PageServerAction, O as Adapter, S as LoadQuery, T as PageServerLoad, a as SchemaQuery, b as ActionBody, c as ServerRequest, i as SchemaBody, n as Budgets, o as ServerEndPoint, r as ParamsOf, s as ServerEndPointSchemas, t as Site, w as PageServerEndPoint, x as LoadParams } from "./Site-BEMQW1_y.mjs";
|
|
9
9
|
import { t as Jsonify } from "./Jsonify-hFz5OjtZ.mjs";
|
|
10
10
|
//#region src/types/PageData.d.ts
|
|
11
11
|
/**
|
|
@@ -73,5 +73,21 @@ interface PageProps<Data = Record<string, any>, Form = Record<string, any>> {
|
|
|
73
73
|
form: Form | undefined;
|
|
74
74
|
}
|
|
75
75
|
//#endregion
|
|
76
|
-
|
|
76
|
+
//#region src/types/LayoutServerEndPoint.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* For _layout.server. The same as a `PageServerEndPoint`, except that it
|
|
79
|
+
* can't declare `middleware`: layout loads run for the pages below them, but
|
|
80
|
+
* not for the API endpoints (`+server.ts`) in the same folders, so a guard
|
|
81
|
+
* here would leave those open. Guard a folder with a `_hook.server.ts`,
|
|
82
|
+
* which runs for every request below it.
|
|
83
|
+
*/
|
|
84
|
+
type LayoutServerEndPoint<Route extends string | undefined = undefined, Data = Record<string, any>, Schemas extends PageServerActionSchemas = PageServerActionSchemas> = Omit<PageServerEndPoint<Route, Data, Schemas>, "middleware"> & {
|
|
85
|
+
/**
|
|
86
|
+
* Not supported on layouts, and an error at runtime. Use a
|
|
87
|
+
* `_hook.server.ts` in the layout's folder to guard it.
|
|
88
|
+
*/
|
|
89
|
+
middleware?: never;
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
export { type ActionBody, type Adapter, type Budgets, type FormDataRecord, type Jsonify, type LayoutServerEndPoint, type LoadParams, type LoadQuery, type MergePageData, type PageData, type PageEndPoint, type PageForm, type PageLoadEvent, type PageLoadReturn, type PageProps, type PageServerAction, type PageServerActionSchemas, type PageServerEndPoint, type PageServerLoad, type ParamsOf, type ParseRouteParams, type QueryRecord, type RouteArgs, type RouteArgsOf, type RouteParamsOf, Router, type SchemaBody, type SchemaQuery, type ServerEndPoint, type ServerEndPointSchemas, type ServerHook, type ServerLoadEvent, type ServerRequest, Site, type SitePlugin, type StandardSchemaV1, type TypedResponse, type UntypedResponse };
|
|
77
93
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/PageData.ts","../src/types/PageForm.ts","../src/types/PageProps.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAaY,SAAS,YAAY;EAAmB,QAAQ,qBAAqB;IAC9E,YAAY,QAAQ,iBAAiB,oBAAoB,QACxD,OACA,sBACD;;;;;;;;;;;;;;KAeS,cAAc,2BAA2B,yBAAyB,gBAAgB,QAC3F,SAAS,SAAS,cAAc;;;;KC9B9B,cAAc,cACjB,WAAW,UAAU,QAAQ,aAAY,qBAAqB,UAC5D,YAAY,QAAQ,0BAEhB;;;;;;;;;;;;;;KAeI,SAAS,YAAY;EAAmB,gBAAgB;KAChE,YAAY,4BACZ,sBACA,cAAc,YAAY,kBAAkB,oBAAoB,QAC/D,OACA,sBACF;;;;;;;UCxBsB,UAAU,OAAO,qBAAqB,OAAO;;;;EAIrE,MAAM;;;;EAIN,MAAM"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/PageData.ts","../src/types/PageForm.ts","../src/types/PageProps.ts","../src/types/LayoutServerEndPoint.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAaY,SAAS,YAAY;EAAmB,QAAQ,qBAAqB;IAC9E,YAAY,QAAQ,iBAAiB,oBAAoB,QACxD,OACA,sBACD;;;;;;;;;;;;;;KAeS,cAAc,2BAA2B,yBAAyB,gBAAgB,QAC3F,SAAS,SAAS,cAAc;;;;KC9B9B,cAAc,cACjB,WAAW,UAAU,QAAQ,aAAY,qBAAqB,UAC5D,YAAY,QAAQ,0BAEhB;;;;;;;;;;;;;;KAeI,SAAS,YAAY;EAAmB,gBAAgB;KAChE,YAAY,4BACZ,sBACA,cAAc,YAAY,kBAAkB,oBAAoB,QAC/D,OACA,sBACF;;;;;;;UCxBsB,UAAU,OAAO,qBAAqB,OAAO;;;;EAIrE,MAAM;;;;EAIN,MAAM;;;;;;;;;;;KCFF,qBACJ,8CACA,OAAO,qBACP,gBAAgB,0BAA0B,2BACvC,KAAK,mBAAmB,OAAO,MAAM;;;;;EAKxC"}
|
package/dist/index.mjs
CHANGED
|
@@ -280,6 +280,15 @@ var Site = class {
|
|
|
280
280
|
*/
|
|
281
281
|
sitemap;
|
|
282
282
|
/**
|
|
283
|
+
* Limits on what each page may ship, checked by `tb --build`, which
|
|
284
|
+
* also reports how much JavaScript the heaviest pages load before they
|
|
285
|
+
* hydrate. `js` is the most gzipped JavaScript (in bytes) a page may load
|
|
286
|
+
* that way, e.g. `{ js: 250_000 }`; a page over it is a warning, or a
|
|
287
|
+
* build failure with `fail: true`. Chunks loaded later through dynamic
|
|
288
|
+
* imports don't count.
|
|
289
|
+
*/
|
|
290
|
+
budgets;
|
|
291
|
+
/**
|
|
283
292
|
* A Standard Schema (zod, valibot, arktype, etc) used to validate (and
|
|
284
293
|
* parse) the server environment. When set, `env()` from
|
|
285
294
|
* `@torpor/build/env` checks the environment on first use per request and
|
|
@@ -355,6 +364,7 @@ var Site = class {
|
|
|
355
364
|
this.prerender = other.prerender;
|
|
356
365
|
this.sitemap = other.sitemap;
|
|
357
366
|
this.origin = other.origin;
|
|
367
|
+
this.budgets = other.budgets;
|
|
358
368
|
return changed;
|
|
359
369
|
}
|
|
360
370
|
/**
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["fs"],"sources":["../src/site/defaultAdapter.ts","../src/site/Site.ts"],"sourcesContent":["import type Server from \"../server/Server\";\nimport type Adapter from \"../types/Adapter\";\n\n/**\n * The known adapter packages, in preference order, with the platform env\n * markers that select them when the site is built in a deployment\n * environment. Only packages that are actually installed (somewhere in the\n * site's node_modules) can be resolved.\n */\nconst ADAPTER_PACKAGES = [\n\t{\n\t\t// The preferred fallback: a node server runs anywhere\n\t\tpkg: \"@torpor/adapter-node\",\n\t\tplatforms: [] as string[],\n\t},\n\t{\n\t\tpkg: \"@torpor/adapter-cloudflare\",\n\t\t// Set when building in a Cloudflare Pages environment. More markers\n\t\t// can be added as adapters are (e.g. `VERCEL` for an adapter-vercel)\n\t\tplatforms: [\"CF_PAGES\"],\n\t},\n];\n\n/**\n * Loads an adapter package, returning undefined when it isn't installed.\n * The import deliberately uses a variable specifier so that bundlers never\n * try to resolve adapter packages from @torpor/build.\n */\nasync function loadAdapterPackage(pkg: string): Promise<Adapter | undefined> {\n\ttry {\n\t\treturn (await import(/* @vite-ignore */ pkg)).default;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport type AdapterResolution = {\n\t/** The resolved adapter, or undefined when none could be found */\n\tadapter: Adapter | undefined;\n\t/** The package the adapter was resolved from */\n\tpkg: string | undefined;\n\t/** Why the adapter was chosen, for logging */\n\treason: string;\n};\n\nexport type ResolveAdapterOptions = {\n\t/** The environment to check for platform markers (defaults to process.env) */\n\tenv?: Record<string, string | undefined>;\n\t/** Loads an adapter package by name (defaults to a dynamic import) */\n\tload?: (pkg: string) => Promise<Adapter | undefined>;\n};\n\n/**\n * Finds an adapter to use when the site doesn't set one explicitly:\n *\n * 1. A platform build environment (e.g. `CF_PAGES` for Cloudflare Pages)\n * selects its adapter, when the adapter package is installed.\n * 2. Otherwise an installed adapter is used, preferring `adapter-node`\n * (a node server runs anywhere).\n * 3. Otherwise nothing is found, and the caller decides what to do (warn,\n * or serve on the current runtime).\n */\nexport async function resolveAdapter(\n\toptions: ResolveAdapterOptions = {},\n): Promise<AdapterResolution> {\n\tconst env = options.env ?? process.env;\n\tconst load = options.load ?? loadAdapterPackage;\n\n\t// Import each package at most once\n\tconst loaded = new Map<string, Adapter | undefined>();\n\tconst loadOnce = async (pkg: string) => {\n\t\tif (!loaded.has(pkg)) loaded.set(pkg, await load(pkg));\n\t\treturn loaded.get(pkg);\n\t};\n\n\t// 1. A deployment environment selects its adapter\n\tfor (const candidate of ADAPTER_PACKAGES) {\n\t\tfor (const marker of candidate.platforms) {\n\t\t\tif (env[marker] === undefined) continue;\n\t\t\tconst adapter = await loadOnce(candidate.pkg);\n\t\t\tif (adapter) {\n\t\t\t\treturn { adapter, pkg: candidate.pkg, reason: `${marker} detected` };\n\t\t\t}\n\t\t}\n\t}\n\n\t// 2. An installed adapter (the list is in preference order)\n\tfor (const candidate of ADAPTER_PACKAGES) {\n\t\tconst adapter = await loadOnce(candidate.pkg);\n\t\tif (adapter) {\n\t\t\treturn { adapter, pkg: candidate.pkg, reason: \"installed\" };\n\t\t}\n\t}\n\n\treturn { adapter: undefined, pkg: undefined, reason: \"none found\" };\n}\n\n/**\n * The current runtime, when preview can serve a fetch handler without an\n * adapter package. (Node's request conversion lives in adapter-node, so\n * node is deliberately not handled here.)\n */\nfunction currentRuntime(): \"bun\" | \"deno\" | undefined {\n\tconst global = globalThis as any;\n\tif (global.Bun) return \"bun\";\n\tif (global.Deno) return \"deno\";\n\treturn undefined;\n}\n\n/**\n * Serves the built output on the current runtime, for when no adapter\n * package could be found. Returns false when the runtime isn't supported.\n */\nfunction serveOnCurrentRuntime(server: Server): boolean {\n\tconst runtime = currentRuntime();\n\tif (!runtime) return false;\n\n\tconst global = globalThis as any;\n\tconst port = parseInt(process.env.PORT ?? \"7059\");\n\tconst hostname = process.env.HOST ?? \"localhost\";\n\tconsole.log(`[torpor] Serving on the ${runtime} runtime at ${hostname}:${port}`);\n\n\tif (runtime === \"bun\") {\n\t\tglobal.Bun.serve({ port, hostname, fetch: (req: Request) => server.fetch(req) });\n\t} else {\n\t\tglobal.Deno.serve({ port, hostname }, (req: Request) => server.fetch(req));\n\t}\n\treturn true;\n}\n\n// The resolution is cached per process, and the \"Using ...\" message is only\n// logged once\nlet cache: Promise<AdapterResolution> | undefined;\nlet loggedPkg: string | undefined;\n\nfunction getCachedResolution(): Promise<AdapterResolution> {\n\treturn (cache ??= resolveAdapter());\n}\n\nfunction logAdapter(pkg: string, reason: string): void {\n\tif (loggedPkg === pkg) return;\n\tloggedPkg = pkg;\n\tconsole.log(`[torpor] Using the ${pkg.replace(\"@torpor/adapter-\", \"\")} adapter (${reason})`);\n}\n\n/**\n * The adapter used when the site doesn't set one explicitly. Rather than\n * being a real adapter, it resolves one at the time it's needed (see\n * `resolveAdapter`), and as a last resort serves the built output on the\n * current runtime -- Bun and Deno can serve a fetch handler natively, while\n * node needs `@torpor/adapter-node`.\n *\n * Dev mode is not affected: with no `dev` hook, the framework's default\n * Node-runtime dev plugin is used.\n */\nconst defaultAdapter: Adapter = {\n\tasync serve(server, site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (adapter && pkg) {\n\t\t\tlogAdapter(pkg, reason);\n\t\t\tawait adapter.serve(server, site);\n\t\t\treturn;\n\t\t}\n\t\tif (serveOnCurrentRuntime(server)) return;\n\t\tconsole.log(\n\t\t\t\"[torpor] No adapter found -- install one (e.g. `pnpm add @torpor/adapter-node`) or set `site.adapter` in site.config.ts\",\n\t\t);\n\t},\n\tasync prebuild(site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (!adapter || !pkg) return;\n\t\tlogAdapter(pkg, reason);\n\t\tawait adapter.prebuild?.(site);\n\t},\n\tasync postbuild(site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (!adapter || !pkg) return;\n\t\tlogAdapter(pkg, reason);\n\t\tawait adapter.postbuild?.(site);\n\t},\n};\n\nexport default defaultAdapter;\n","import { promises as fs } from \"node:fs\";\nimport fpath from \"node:path\";\nimport { type Plugin, type UserConfig } from \"vite\";\nimport type Adapter from \"../types/Adapter\";\nimport type { SitemapOptions } from \"../discovery/sitemap\";\nimport type MiddlewareFunction from \"../server/types/MiddlewareFunction\";\nimport type { StandardSchemaV1 } from \"../types/StandardSchema\";\nimport type SitePlugin from \"../types/SitePlugin\";\nimport type { InlineEndPoint } from \"../types/Route\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport type Route from \"../types/Route\";\nimport type ServerEndPoint from \"../types/ServerEndPoint\";\nimport type ServerHook from \"../types/ServerHook\";\nimport {\n\tERROR_ROUTE,\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tRouteType,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport defaultAdapter from \"./defaultAdapter\";\n\n// 1. The user sets this up\n// 2. It is passed into serverEntry and clientEntry through a Vite plugin\n// (defined in manifest.ts)\n// 3. In those files, it is used to build a Router\n\n/**\n * The Site class contains the information necessary to setup a @torpor/build\n * site, including routes, plugins, and options.\n */\nexport default class Site {\n\troot: string;\n\t/**\n\t * The directory the build is written to: an absolute path, or a path\n\t * relative to `root`. Defaults to `\"dist\"`.\n\t *\n\t * Set it to give an app its own output when several apps share one source\n\t * root -- e.g. a web and an Electron app that both build from the same\n\t * package via `addRouteFolder`. Without it they'd both write to\n\t * `<root>/dist` and clobber each other.\n\t */\n\toutput?: string;\n\troutes: Route[] = [];\n\t/**\n\t * Route folders registered with `addRouteFolder`, in registration order.\n\t * The dev server uses these to know which directories hold route files, so\n\t * adding or removing one can rebuild the route table without a restart.\n\t */\n\trouteFolders: { folder: string; subFolder?: string }[] = [];\n\t/**\n\t * Torpor site plugins, run when the site config is loaded (for dev and\n\t * build) and when the server starts up. Use these to register extra\n\t * routes (e.g. `openApi()` from `@torpor/build/openapi`) or add other\n\t * framework-level functionality\n\t */\n\tplugins: SitePlugin[] = [];\n\t/**\n\t * Vite plugins to add to the client and server builds\n\t */\n\tvitePlugins: Plugin[] = [];\n\t/**\n\t * The site's adapter, e.g. from `@torpor/adapter-node`,\n\t * `@torpor/adapter-cloudflare` or `@torpor/adapter-electron`. When not set,\n\t * one is resolved when it's\n\t * needed: a deployment environment (e.g. `CF_PAGES`) picks the platform's\n\t * adapter when installed, an installed adapter is used otherwise, and\n\t * preview falls back to serving on the current runtime. See\n\t * defaultAdapter.ts\n\t */\n\tadapter: Adapter = defaultAdapter;\n\t/**\n\t * Extra inputs, as absolute file paths, that will be compiled with the\n\t * output. What you do with them after that is up to you. File paths ending\n\t * with server.ts/js will only be compiled with the server output\n\t */\n\tinputs: string[] = [];\n\t/**\n\t * Vite config options to merge with the standard Torpor build options.\n\t * `plugins` and `build.rollupOptions.input` will be overridden, so you\n\t * should set `Site.vitePlugins` and `Site.inputs` instead. Other options may be\n\t * overridden or incompatible, so experimentation may be required\n\t */\n\tviteConfig?: UserConfig;\n\t/**\n\t * The path to the site.config file. Set automatically by the CLI; used by\n\t * the manifest plugin to import inline endpoints for server builds.\n\t */\n\tconfigFile?: string;\n\t/**\n\t * A state map for plugins to store their configuration and state on the\n\t * site, so that framework internals (e.g. the manifest plugin) and other\n\t * plugins can read them back:\n\t *\n\t * ```ts\n\t * const myKey = Symbol.for(\"my-plugin\");\n\t * site.pluginState.set(myKey, options);\n\t * ```\n\t *\n\t * Prefer `Symbol.for(\"...\")` keys (or plain strings) over `Symbol()`,\n\t * because the user's config file and framework internals can be loaded as\n\t * separate module instances -- registry symbols are shared across\n\t * instances, `Symbol()` ones are not.\n\t */\n\tpluginState: Map<PropertyKey, unknown> = new Map();\n\t/**\n\t * The path the site is mounted under, e.g. \"/app\". Incoming server\n\t * requests that don't carry it are not found; everything the framework\n\t * generates (HTML attributes, redirect locations, paths from `route()`)\n\t * gets it added. Server code and markup stay base-free.\n\t */\n\tbasePath: string = \"\";\n\t/**\n\t * Wraps client-side navigations in the View Transitions API -- where the\n\t * browser supports it -- so pages cross-fade by default and can be\n\t * animated with `::view-transition-old/new` CSS. Opt-in: off unless set\n\t * to `true`. The initial hydration never transitions.\n\t */\n\tviewTransitions?: boolean;\n\t/**\n\t * Prerendering, applied to every page route that doesn't have (or\n\t * inherit) a `prerender` flag of its own. `true` prerenders everything;\n\t * a `Record<string, boolean>` maps route paths -- exact (`/about`) or\n\t * prefix (`/blog/**` for a path and everything below it) -- to flags,\n\t * with the most specific matching key winning. Route endpoint and\n\t * layout flags always take precedence over this.\n\t */\n\tprerender?: boolean | Record<string, boolean>;\n\t/**\n\t * The site's absolute origin, e.g. \"https://example.com\". Required for\n\t * a build-time sitemap (see `sitemap`), since there is no request to\n\t * take the host from.\n\t */\n\torigin?: string;\n\t/**\n\t * Global middleware, run for every request before routing -- including\n\t * requests that won't match a route (maintenance mode, legacy url\n\t * redirects, etc). Each middleware's `enter` runs in order and may\n\t * return a Response to short-circuit the request; `exit` hooks run in\n\t * reverse after the handler. Middleware see the raw request url.\n\t *\n\t * Route middleware (scoped to a single route) is set on the route's\n\t * server endpoint instead, e.g. `middleware: [...]` in\n\t * `+page.server.ts` or `+server.ts`.\n\t */\n\tmiddleware: MiddlewareFunction[] = [];\n\t/**\n\t * Writes a sitemap.xml listing the prerendered pages at build time\n\t * (see `prerender`). Pass a custom path (e.g. \"/blog/sitemap.xml\") or\n\t * `true` for \"/sitemap.xml\"; requires `origin` to be set.\n\t *\n\t * For a runtime sitemap -- one that reads the database and keeps up with\n\t * content that isn't prerendered -- pass a config instead, e.g.\n\t * `sitemap = { get: async () => [\"/posts/a\", \"/posts/b\"] }`, which serves\n\t * the XML live at that path (customizable with `path`).\n\t */\n\tsitemap?: SitemapOptions | boolean | string;\n\t/**\n\t * A Standard Schema (zod, valibot, arktype, etc) used to validate (and\n\t * parse) the server environment. When set, `env()` from\n\t * `@torpor/build/env` checks the environment on first use per request and\n\t * throws with the schema's issues -- so a missing or invalid key fails\n\t * immediately instead of passing `undefined` along. The schema must\n\t * validate synchronously.\n\t */\n\tenv?: StandardSchemaV1<unknown, TorporEnv>;\n\t/**\n\t * Inline endpoints keyed by `\"path:type\"`. Populated by `addRoute` when\n\t * the user passes an inline endpoint object instead of a file path.\n\t */\n\tinlineEndPoints: Record<string, InlineEndPoint> = {};\n\n\tconstructor() {\n\t\tthis.root = process.cwd();\n\t}\n\n\t/** The absolute output directory: `output` resolved against `root`, or `<root>/dist`. */\n\tget outputFolder(): string {\n\t\treturn fpath.resolve(this.root, this.output ?? \"dist\");\n\t}\n\n\t/**\n\t * Adds a folder of routes, based on the names of the files in the folder\n\t * @param folder The folder containing the routes\n\t * @param subFolder If a subFolder is set, all routes in the folder will be\n\t * placed under the subFolder, and only hooks, layouts etc will be used if\n\t * they have the same subFolder. This can be used to create e.g. an `api`\n\t * set of routes with their own hook for authorization from various clients\n\t */\n\tasync addRouteFolder(folder: string, subFolder?: string): Promise<void> {\n\t\tconst routeFolder = fpath.join(this.root, folder);\n\t\tconst routeFiles = await fs.readdir(routeFolder, { recursive: true });\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\t// Remember the folder so dev can tell which directories hold route\n\t\t// files and rebuild the route table when one is added or removed\n\t\tif (!this.routeFolders.some((f) => f.folder === folder && f.subFolder === subFolder)) {\n\t\t\tthis.routeFolders.push({ folder, subFolder });\n\t\t}\n\t\tfor (let file of routeFiles) {\n\t\t\t// The file must start with `+` or `_` and end with `.js` or `.ts`\n\t\t\tif (/^(\\+|_).+(\\.js|\\.ts)$/.test(fpath.basename(file))) {\n\t\t\t\tlet routePath = this.#routePath(file);\n\t\t\t\tif (subFolder !== undefined) {\n\t\t\t\t\troutePath = subFolder + routePath;\n\t\t\t\t}\n\t\t\t\tlet type = this.#routeType(file);\n\t\t\t\tfile = fpath.relative(this.root, fpath.resolve(routeFolder, file));\n\t\t\t\tthis.routes.push({\n\t\t\t\t\tpath: routePath,\n\t\t\t\t\tfile,\n\t\t\t\t\ttype,\n\t\t\t\t\tsubFolder: subFolder,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis.#sortRoutes();\n\t}\n\n\t/**\n\t * Copies the runtime route state from a freshly loaded Site (produced by\n\t * re-reading the site config) onto this one, so the running dev server can\n\t * pick up route and config changes without a restart.\n\t *\n\t * Only route-relevant state is copied; Vite-config-level fields (`adapter`,\n\t * `vitePlugins`, `viteConfig`, `inputs`) are left alone, since changing\n\t * those needs a restart anyway.\n\t *\n\t * Returns true when the route table changed.\n\t */\n\tapplyRouteState(other: Site): boolean {\n\t\tconst changed = !routesEqual(this.routes, other.routes);\n\t\tthis.routes = other.routes;\n\t\tthis.routeFolders = other.routeFolders;\n\t\tthis.inlineEndPoints = other.inlineEndPoints;\n\t\tthis.plugins = other.plugins;\n\t\tthis.pluginState = other.pluginState;\n\t\tthis.env = other.env;\n\t\tthis.middleware = other.middleware;\n\t\tthis.basePath = other.basePath;\n\t\tthis.viewTransitions = other.viewTransitions;\n\t\tthis.prerender = other.prerender;\n\t\tthis.sitemap = other.sitemap;\n\t\tthis.origin = other.origin;\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Adds a file route, which can have a standard name (e.g. +page.ts) or any\n\t * name if you pass the type\n\t * @param path The route path\n\t * @param file The file\n\t * @param type The file type (if the file name is non-standard)\n\t */\n\taddRouteFile(\n\t\tpath: string,\n\t\tfile: string,\n\t\ttype?:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t\tsubFolder?: string,\n\t): void {\n\t\tlet routePath = this.#routePath(fpath.join(path, type ?? fpath.basename(file)));\n\t\tlet routeType = type ? this.#routeTypeFromString(type) : this.#routeType(file);\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\tthis.routes.push({\n\t\t\tpath: routePath,\n\t\t\tfile,\n\t\t\ttype: routeType,\n\t\t\tsubFolder: subFolder,\n\t\t});\n\t\tthis.#sortRoutes();\n\t}\n\n\t#routePath(file: string): string {\n\t\tlet routePath = file\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/(\\.ts|\\.js)$/, \"\")\n\t\t\t.replace(/_hook.server$/, \"_hook/~server\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\t#routeType(file: string): RouteType {\n\t\tlet routePath = file.replace(/^\\//, \"\").replace(/(\\.ts|\\.js)$/, \"\");\n\t\tif (routePath.endsWith(\"+page\")) {\n\t\t\treturn PAGE_ROUTE;\n\t\t} else if (routePath.endsWith(\"+page.server\")) {\n\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"+server\")) {\n\t\t\treturn SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout\")) {\n\t\t\treturn LAYOUT_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout.server\")) {\n\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook\")) {\n\t\t\treturn HOOK_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook.server\")) {\n\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_error\")) {\n\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t\treturn -1;\n\t}\n\n\t#routeTypeFromString(\n\t\ttype:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t) {\n\t\tswitch (type) {\n\t\t\tcase \"+page\":\n\t\t\t\treturn PAGE_ROUTE;\n\t\t\tcase \"+page.server\":\n\t\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t\tcase \"+server\":\n\t\t\t\treturn SERVER_ROUTE;\n\t\t\tcase \"_layout\":\n\t\t\t\treturn LAYOUT_ROUTE;\n\t\t\tcase \"_layout.server\":\n\t\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t\tcase \"_hook\":\n\t\t\t\treturn HOOK_ROUTE;\n\t\t\tcase \"_hook.server\":\n\t\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t\tcase \"_error\":\n\t\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a route in code, without needing the standard file naming\n\t * conventions (+page.ts, +page.server.ts, etc). This is useful for small\n\t * sites with one or two pages.\n\t *\n\t * Any combination of options may be provided; each maps to the\n\t * corresponding file-route type:\n\t *\n\t * - `page` — a `+page` (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t * - `pageServer` — a `+page.server` (`PageServerEndPoint`, file or inline)\n\t * - `server` — a `+server` HTTP endpoint (`ServerEndPoint`, file or inline)\n\t * - `layout` — a `_layout` (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t * - `layoutServer` — a `_layout.server` (`PageServerEndPoint`, file or inline)\n\t * - `hookServer` — a `_hook.server` (`ServerHook`, file or inline)\n\t * - `error` — an `_error` page (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t *\n\t * Options that need a component (`page`, `layout`, `error`) must be file\n\t * paths so the component is included in the client bundle. Server-only\n\t * options (`pageServer`, `server`, `layoutServer`, `hookServer`) accept\n\t * either a file path or an inline object; inline server code is kept out\n\t * of the client bundle automatically.\n\t *\n\t * @example\n\t * // A page with an inline server action\n\t * site.addRoute(\"/\", {\n\t * page: \"./src/Counter.torp\",\n\t * pageServer: { actions: { set: async ({ request }) => ok() } },\n\t * });\n\t * @example\n\t * // A JSON API endpoint\n\t * site.addRoute(\"/api/time\", {\n\t * server: { get: async () => ok({ time: Date.now() }) },\n\t * });\n\t * @example\n\t * // A root layout, server hook, and error page\n\t * site.addRoute(\"/\", {\n\t * layout: \"./src/Layout.torp\",\n\t * hookServer: { enter: async (event) => {} },\n\t * error: \"./src/ErrorPage.torp\",\n\t * });\n\t *\n\t * @param path The route path, e.g. `/` or `/about`\n\t * @param options File paths and/or inline endpoints for the route\n\t * @param subFolder An optional subFolder for grouping routes\n\t */\n\taddRoute(\n\t\tpath: string,\n\t\toptions: {\n\t\t\tpage?: string;\n\t\t\tpageServer?: string | PageServerEndPoint;\n\t\t\tserver?: string | ServerEndPoint;\n\t\t\tlayout?: string;\n\t\t\tlayoutServer?: string | PageServerEndPoint;\n\t\t\thookServer?: string | ServerHook;\n\t\t\terror?: string;\n\t\t},\n\t\tsubFolder?: string,\n\t): void {\n\t\tlet normalizedSubFolder = subFolder;\n\t\tif (normalizedSubFolder !== undefined && !normalizedSubFolder.startsWith(\"/\")) {\n\t\t\tnormalizedSubFolder = \"/\" + normalizedSubFolder;\n\t\t}\n\n\t\t// The base path with any trailing slash stripped, so that we can\n\t\t// append \"/_layout\", \"/~server\" etc. For the root \"/\" this is \"\".\n\t\tlet base = path.replace(/\\/$/, \"\");\n\n\t\tif (options.page !== undefined) {\n\t\t\tthis.#pushRoute(path, PAGE_ROUTE, options.page, normalizedSubFolder);\n\t\t}\n\t\tif (options.pageServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/~server`,\n\t\t\t\tPAGE_SERVER_ROUTE,\n\t\t\t\toptions.pageServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.server !== undefined) {\n\t\t\tthis.#pushRoute(path, SERVER_ROUTE, options.server, normalizedSubFolder);\n\t\t}\n\t\tif (options.layout !== undefined) {\n\t\t\tthis.#pushRoute(`${base}/_layout`, LAYOUT_ROUTE, options.layout, normalizedSubFolder);\n\t\t}\n\t\tif (options.layoutServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/_layout/~server`,\n\t\t\t\tLAYOUT_SERVER_ROUTE,\n\t\t\t\toptions.layoutServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.hookServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/_hook/~server`,\n\t\t\t\tHOOK_SERVER_ROUTE,\n\t\t\t\toptions.hookServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.error !== undefined) {\n\t\t\tthis.#pushRoute(`${base}/_error`, ERROR_ROUTE, options.error, normalizedSubFolder);\n\t\t}\n\n\t\tthis.#sortRoutes();\n\t}\n\n\t/**\n\t * Pushes a single route entry, handling both file-path and inline-endpoint\n\t * targets. File paths are resolved relative to the site root; inline\n\t * endpoints are also stored in `inlineEndPoints` keyed by `\"path:type\"`\n\t * so the manifest plugin can resolve them at build time.\n\t *\n\t * If a route with the same path and type was already added, it is\n\t * replaced, so that running a plugin twice (config load and server\n\t * startup) doesn't add duplicate routes.\n\t */\n\t#pushRoute(\n\t\troutePath: string,\n\t\ttype: RouteType,\n\t\ttarget: string | InlineEndPoint,\n\t\tsubFolder?: string,\n\t): void {\n\t\tconst index = this.routes.findIndex((r) => r.path === routePath && r.type === type);\n\t\tif (typeof target === \"string\") {\n\t\t\tlet file = fpath.relative(this.root, fpath.resolve(this.root, target));\n\t\t\tif (index >= 0) {\n\t\t\t\tthis.routes[index] = { path: routePath, file, type, subFolder };\n\t\t\t} else {\n\t\t\t\tthis.routes.push({ path: routePath, file, type, subFolder });\n\t\t\t}\n\t\t} else {\n\t\t\tlet key = `${routePath}:${type}`;\n\t\t\tthis.inlineEndPoints[key] = target;\n\t\t\tif (index >= 0) {\n\t\t\t\tthis.routes[index] = { path: routePath, endPoint: target, type, subFolder };\n\t\t\t} else {\n\t\t\t\tthis.routes.push({ path: routePath, endPoint: target, type, subFolder });\n\t\t\t}\n\t\t}\n\t}\n\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\n/**\n * Whether two route tables are equivalent for the purpose of deciding\n * whether a route-file change actually changed the router. Compares the\n * identifying fields of each route, in order.\n */\nfunction routesEqual(a: Route[], b: Route[]): boolean {\n\tif (a.length !== b.length) return false;\n\tfor (let i = 0; i < a.length; i++) {\n\t\tconst x = a[i];\n\t\tconst y = b[i];\n\t\tif (\n\t\t\tx.path !== y.path ||\n\t\t\tx.type !== y.type ||\n\t\t\tx.file !== y.file ||\n\t\t\tx.subFolder !== y.subFolder\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,mBAAmB,CACxB;CAEC,KAAK;CACL,WAAW,CAAC;AACb,GACA;CACC,KAAK;CAGL,WAAW,CAAC,UAAU;AACvB,CACD;;;;;;AAOA,eAAe,mBAAmB,KAA2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AClC,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;EAClC,MAAM,IAAI,EAAE;EACZ,MAAM,IAAI,EAAE;EACZ,IACC,EAAE,SAAS,EAAE,QACb,EAAE,SAAS,EAAE,QACb,EAAE,SAAS,EAAE,QACb,EAAE,cAAc,EAAE,WAElB,OAAO;CAET;CACA,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["fs"],"sources":["../src/site/defaultAdapter.ts","../src/site/Site.ts"],"sourcesContent":["import type Server from \"../server/Server\";\nimport type Adapter from \"../types/Adapter\";\n\n/**\n * The known adapter packages, in preference order, with the platform env\n * markers that select them when the site is built in a deployment\n * environment. Only packages that are actually installed (somewhere in the\n * site's node_modules) can be resolved.\n */\nconst ADAPTER_PACKAGES = [\n\t{\n\t\t// The preferred fallback: a node server runs anywhere\n\t\tpkg: \"@torpor/adapter-node\",\n\t\tplatforms: [] as string[],\n\t},\n\t{\n\t\tpkg: \"@torpor/adapter-cloudflare\",\n\t\t// Set when building in a Cloudflare Pages environment. More markers\n\t\t// can be added as adapters are (e.g. `VERCEL` for an adapter-vercel)\n\t\tplatforms: [\"CF_PAGES\"],\n\t},\n];\n\n/**\n * Loads an adapter package, returning undefined when it isn't installed.\n * The import deliberately uses a variable specifier so that bundlers never\n * try to resolve adapter packages from @torpor/build.\n */\nasync function loadAdapterPackage(pkg: string): Promise<Adapter | undefined> {\n\ttry {\n\t\treturn (await import(/* @vite-ignore */ pkg)).default;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport type AdapterResolution = {\n\t/** The resolved adapter, or undefined when none could be found */\n\tadapter: Adapter | undefined;\n\t/** The package the adapter was resolved from */\n\tpkg: string | undefined;\n\t/** Why the adapter was chosen, for logging */\n\treason: string;\n};\n\nexport type ResolveAdapterOptions = {\n\t/** The environment to check for platform markers (defaults to process.env) */\n\tenv?: Record<string, string | undefined>;\n\t/** Loads an adapter package by name (defaults to a dynamic import) */\n\tload?: (pkg: string) => Promise<Adapter | undefined>;\n};\n\n/**\n * Finds an adapter to use when the site doesn't set one explicitly:\n *\n * 1. A platform build environment (e.g. `CF_PAGES` for Cloudflare Pages)\n * selects its adapter, when the adapter package is installed.\n * 2. Otherwise an installed adapter is used, preferring `adapter-node`\n * (a node server runs anywhere).\n * 3. Otherwise nothing is found, and the caller decides what to do (warn,\n * or serve on the current runtime).\n */\nexport async function resolveAdapter(\n\toptions: ResolveAdapterOptions = {},\n): Promise<AdapterResolution> {\n\tconst env = options.env ?? process.env;\n\tconst load = options.load ?? loadAdapterPackage;\n\n\t// Import each package at most once\n\tconst loaded = new Map<string, Adapter | undefined>();\n\tconst loadOnce = async (pkg: string) => {\n\t\tif (!loaded.has(pkg)) loaded.set(pkg, await load(pkg));\n\t\treturn loaded.get(pkg);\n\t};\n\n\t// 1. A deployment environment selects its adapter\n\tfor (const candidate of ADAPTER_PACKAGES) {\n\t\tfor (const marker of candidate.platforms) {\n\t\t\tif (env[marker] === undefined) continue;\n\t\t\tconst adapter = await loadOnce(candidate.pkg);\n\t\t\tif (adapter) {\n\t\t\t\treturn { adapter, pkg: candidate.pkg, reason: `${marker} detected` };\n\t\t\t}\n\t\t}\n\t}\n\n\t// 2. An installed adapter (the list is in preference order)\n\tfor (const candidate of ADAPTER_PACKAGES) {\n\t\tconst adapter = await loadOnce(candidate.pkg);\n\t\tif (adapter) {\n\t\t\treturn { adapter, pkg: candidate.pkg, reason: \"installed\" };\n\t\t}\n\t}\n\n\treturn { adapter: undefined, pkg: undefined, reason: \"none found\" };\n}\n\n/**\n * The current runtime, when preview can serve a fetch handler without an\n * adapter package. (Node's request conversion lives in adapter-node, so\n * node is deliberately not handled here.)\n */\nfunction currentRuntime(): \"bun\" | \"deno\" | undefined {\n\tconst global = globalThis as any;\n\tif (global.Bun) return \"bun\";\n\tif (global.Deno) return \"deno\";\n\treturn undefined;\n}\n\n/**\n * Serves the built output on the current runtime, for when no adapter\n * package could be found. Returns false when the runtime isn't supported.\n */\nfunction serveOnCurrentRuntime(server: Server): boolean {\n\tconst runtime = currentRuntime();\n\tif (!runtime) return false;\n\n\tconst global = globalThis as any;\n\tconst port = parseInt(process.env.PORT ?? \"7059\");\n\tconst hostname = process.env.HOST ?? \"localhost\";\n\tconsole.log(`[torpor] Serving on the ${runtime} runtime at ${hostname}:${port}`);\n\n\tif (runtime === \"bun\") {\n\t\tglobal.Bun.serve({ port, hostname, fetch: (req: Request) => server.fetch(req) });\n\t} else {\n\t\tglobal.Deno.serve({ port, hostname }, (req: Request) => server.fetch(req));\n\t}\n\treturn true;\n}\n\n// The resolution is cached per process, and the \"Using ...\" message is only\n// logged once\nlet cache: Promise<AdapterResolution> | undefined;\nlet loggedPkg: string | undefined;\n\nfunction getCachedResolution(): Promise<AdapterResolution> {\n\treturn (cache ??= resolveAdapter());\n}\n\nfunction logAdapter(pkg: string, reason: string): void {\n\tif (loggedPkg === pkg) return;\n\tloggedPkg = pkg;\n\tconsole.log(`[torpor] Using the ${pkg.replace(\"@torpor/adapter-\", \"\")} adapter (${reason})`);\n}\n\n/**\n * The adapter used when the site doesn't set one explicitly. Rather than\n * being a real adapter, it resolves one at the time it's needed (see\n * `resolveAdapter`), and as a last resort serves the built output on the\n * current runtime -- Bun and Deno can serve a fetch handler natively, while\n * node needs `@torpor/adapter-node`.\n *\n * Dev mode is not affected: with no `dev` hook, the framework's default\n * Node-runtime dev plugin is used.\n */\nconst defaultAdapter: Adapter = {\n\tasync serve(server, site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (adapter && pkg) {\n\t\t\tlogAdapter(pkg, reason);\n\t\t\tawait adapter.serve(server, site);\n\t\t\treturn;\n\t\t}\n\t\tif (serveOnCurrentRuntime(server)) return;\n\t\tconsole.log(\n\t\t\t\"[torpor] No adapter found -- install one (e.g. `pnpm add @torpor/adapter-node`) or set `site.adapter` in site.config.ts\",\n\t\t);\n\t},\n\tasync prebuild(site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (!adapter || !pkg) return;\n\t\tlogAdapter(pkg, reason);\n\t\tawait adapter.prebuild?.(site);\n\t},\n\tasync postbuild(site) {\n\t\tconst { adapter, pkg, reason } = await getCachedResolution();\n\t\tif (!adapter || !pkg) return;\n\t\tlogAdapter(pkg, reason);\n\t\tawait adapter.postbuild?.(site);\n\t},\n};\n\nexport default defaultAdapter;\n","import { promises as fs } from \"node:fs\";\nimport fpath from \"node:path\";\nimport { type Plugin, type UserConfig } from \"vite\";\nimport type Adapter from \"../types/Adapter\";\nimport type { SitemapOptions } from \"../discovery/sitemap\";\nimport type MiddlewareFunction from \"../server/types/MiddlewareFunction\";\nimport type { StandardSchemaV1 } from \"../types/StandardSchema\";\nimport type SitePlugin from \"../types/SitePlugin\";\nimport type { InlineEndPoint } from \"../types/Route\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport type Route from \"../types/Route\";\nimport type ServerEndPoint from \"../types/ServerEndPoint\";\nimport type Budgets from \"../types/Budgets\";\nimport type ServerHook from \"../types/ServerHook\";\nimport {\n\tERROR_ROUTE,\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tRouteType,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport defaultAdapter from \"./defaultAdapter\";\n\n// 1. The user sets this up\n// 2. It is passed into serverEntry and clientEntry through a Vite plugin\n// (defined in manifest.ts)\n// 3. In those files, it is used to build a Router\n\n/**\n * The Site class contains the information necessary to setup a @torpor/build\n * site, including routes, plugins, and options.\n */\nexport default class Site {\n\troot: string;\n\t/**\n\t * The directory the build is written to: an absolute path, or a path\n\t * relative to `root`. Defaults to `\"dist\"`.\n\t *\n\t * Set it to give an app its own output when several apps share one source\n\t * root -- e.g. a web and an Electron app that both build from the same\n\t * package via `addRouteFolder`. Without it they'd both write to\n\t * `<root>/dist` and clobber each other.\n\t */\n\toutput?: string;\n\troutes: Route[] = [];\n\t/**\n\t * Route folders registered with `addRouteFolder`, in registration order.\n\t * The dev server uses these to know which directories hold route files, so\n\t * adding or removing one can rebuild the route table without a restart.\n\t */\n\trouteFolders: { folder: string; subFolder?: string }[] = [];\n\t/**\n\t * Torpor site plugins, run when the site config is loaded (for dev and\n\t * build) and when the server starts up. Use these to register extra\n\t * routes (e.g. `openApi()` from `@torpor/build/openapi`) or add other\n\t * framework-level functionality\n\t */\n\tplugins: SitePlugin[] = [];\n\t/**\n\t * Vite plugins to add to the client and server builds\n\t */\n\tvitePlugins: Plugin[] = [];\n\t/**\n\t * The site's adapter, e.g. from `@torpor/adapter-node`,\n\t * `@torpor/adapter-cloudflare` or `@torpor/adapter-electron`. When not set,\n\t * one is resolved when it's\n\t * needed: a deployment environment (e.g. `CF_PAGES`) picks the platform's\n\t * adapter when installed, an installed adapter is used otherwise, and\n\t * preview falls back to serving on the current runtime. See\n\t * defaultAdapter.ts\n\t */\n\tadapter: Adapter = defaultAdapter;\n\t/**\n\t * Extra inputs, as absolute file paths, that will be compiled with the\n\t * output. What you do with them after that is up to you. File paths ending\n\t * with server.ts/js will only be compiled with the server output\n\t */\n\tinputs: string[] = [];\n\t/**\n\t * Vite config options to merge with the standard Torpor build options.\n\t * `plugins` and `build.rollupOptions.input` will be overridden, so you\n\t * should set `Site.vitePlugins` and `Site.inputs` instead. Other options may be\n\t * overridden or incompatible, so experimentation may be required\n\t */\n\tviteConfig?: UserConfig;\n\t/**\n\t * The path to the site.config file. Set automatically by the CLI; used by\n\t * the manifest plugin to import inline endpoints for server builds.\n\t */\n\tconfigFile?: string;\n\t/**\n\t * A state map for plugins to store their configuration and state on the\n\t * site, so that framework internals (e.g. the manifest plugin) and other\n\t * plugins can read them back:\n\t *\n\t * ```ts\n\t * const myKey = Symbol.for(\"my-plugin\");\n\t * site.pluginState.set(myKey, options);\n\t * ```\n\t *\n\t * Prefer `Symbol.for(\"...\")` keys (or plain strings) over `Symbol()`,\n\t * because the user's config file and framework internals can be loaded as\n\t * separate module instances -- registry symbols are shared across\n\t * instances, `Symbol()` ones are not.\n\t */\n\tpluginState: Map<PropertyKey, unknown> = new Map();\n\t/**\n\t * The path the site is mounted under, e.g. \"/app\". Incoming server\n\t * requests that don't carry it are not found; everything the framework\n\t * generates (HTML attributes, redirect locations, paths from `route()`)\n\t * gets it added. Server code and markup stay base-free.\n\t */\n\tbasePath: string = \"\";\n\t/**\n\t * Wraps client-side navigations in the View Transitions API -- where the\n\t * browser supports it -- so pages cross-fade by default and can be\n\t * animated with `::view-transition-old/new` CSS. Opt-in: off unless set\n\t * to `true`. The initial hydration never transitions.\n\t */\n\tviewTransitions?: boolean;\n\t/**\n\t * Prerendering, applied to every page route that doesn't have (or\n\t * inherit) a `prerender` flag of its own. `true` prerenders everything;\n\t * a `Record<string, boolean>` maps route paths -- exact (`/about`) or\n\t * prefix (`/blog/**` for a path and everything below it) -- to flags,\n\t * with the most specific matching key winning. Route endpoint and\n\t * layout flags always take precedence over this.\n\t */\n\tprerender?: boolean | Record<string, boolean>;\n\t/**\n\t * The site's absolute origin, e.g. \"https://example.com\". Required for\n\t * a build-time sitemap (see `sitemap`), since there is no request to\n\t * take the host from.\n\t */\n\torigin?: string;\n\t/**\n\t * Global middleware, run for every request before routing -- including\n\t * requests that won't match a route (maintenance mode, legacy url\n\t * redirects, etc). Each middleware's `enter` runs in order and may\n\t * return a Response to short-circuit the request; `exit` hooks run in\n\t * reverse after the handler. Middleware see the raw request url.\n\t *\n\t * Route middleware (scoped to a single route) is set on the route's\n\t * server endpoint instead, e.g. `middleware: [...]` in\n\t * `+page.server.ts` or `+server.ts`.\n\t */\n\tmiddleware: MiddlewareFunction[] = [];\n\t/**\n\t * Writes a sitemap.xml listing the prerendered pages at build time\n\t * (see `prerender`). Pass a custom path (e.g. \"/blog/sitemap.xml\") or\n\t * `true` for \"/sitemap.xml\"; requires `origin` to be set.\n\t *\n\t * For a runtime sitemap -- one that reads the database and keeps up with\n\t * content that isn't prerendered -- pass a config instead, e.g.\n\t * `sitemap = { get: async () => [\"/posts/a\", \"/posts/b\"] }`, which serves\n\t * the XML live at that path (customizable with `path`).\n\t */\n\tsitemap?: SitemapOptions | boolean | string;\n\t/**\n\t * Limits on what each page may ship, checked by `tb --build`, which\n\t * also reports how much JavaScript the heaviest pages load before they\n\t * hydrate. `js` is the most gzipped JavaScript (in bytes) a page may load\n\t * that way, e.g. `{ js: 250_000 }`; a page over it is a warning, or a\n\t * build failure with `fail: true`. Chunks loaded later through dynamic\n\t * imports don't count.\n\t */\n\tbudgets?: Budgets;\n\t/**\n\t * A Standard Schema (zod, valibot, arktype, etc) used to validate (and\n\t * parse) the server environment. When set, `env()` from\n\t * `@torpor/build/env` checks the environment on first use per request and\n\t * throws with the schema's issues -- so a missing or invalid key fails\n\t * immediately instead of passing `undefined` along. The schema must\n\t * validate synchronously.\n\t */\n\tenv?: StandardSchemaV1<unknown, TorporEnv>;\n\t/**\n\t * Inline endpoints keyed by `\"path:type\"`. Populated by `addRoute` when\n\t * the user passes an inline endpoint object instead of a file path.\n\t */\n\tinlineEndPoints: Record<string, InlineEndPoint> = {};\n\n\tconstructor() {\n\t\tthis.root = process.cwd();\n\t}\n\n\t/** The absolute output directory: `output` resolved against `root`, or `<root>/dist`. */\n\tget outputFolder(): string {\n\t\treturn fpath.resolve(this.root, this.output ?? \"dist\");\n\t}\n\n\t/**\n\t * Adds a folder of routes, based on the names of the files in the folder\n\t * @param folder The folder containing the routes\n\t * @param subFolder If a subFolder is set, all routes in the folder will be\n\t * placed under the subFolder, and only hooks, layouts etc will be used if\n\t * they have the same subFolder. This can be used to create e.g. an `api`\n\t * set of routes with their own hook for authorization from various clients\n\t */\n\tasync addRouteFolder(folder: string, subFolder?: string): Promise<void> {\n\t\tconst routeFolder = fpath.join(this.root, folder);\n\t\tconst routeFiles = await fs.readdir(routeFolder, { recursive: true });\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\t// Remember the folder so dev can tell which directories hold route\n\t\t// files and rebuild the route table when one is added or removed\n\t\tif (!this.routeFolders.some((f) => f.folder === folder && f.subFolder === subFolder)) {\n\t\t\tthis.routeFolders.push({ folder, subFolder });\n\t\t}\n\t\tfor (let file of routeFiles) {\n\t\t\t// The file must start with `+` or `_` and end with `.js` or `.ts`\n\t\t\tif (/^(\\+|_).+(\\.js|\\.ts)$/.test(fpath.basename(file))) {\n\t\t\t\tlet routePath = this.#routePath(file);\n\t\t\t\tif (subFolder !== undefined) {\n\t\t\t\t\troutePath = subFolder + routePath;\n\t\t\t\t}\n\t\t\t\tlet type = this.#routeType(file);\n\t\t\t\tfile = fpath.relative(this.root, fpath.resolve(routeFolder, file));\n\t\t\t\tthis.routes.push({\n\t\t\t\t\tpath: routePath,\n\t\t\t\t\tfile,\n\t\t\t\t\ttype,\n\t\t\t\t\tsubFolder: subFolder,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis.#sortRoutes();\n\t}\n\n\t/**\n\t * Copies the runtime route state from a freshly loaded Site (produced by\n\t * re-reading the site config) onto this one, so the running dev server can\n\t * pick up route and config changes without a restart.\n\t *\n\t * Only route-relevant state is copied; Vite-config-level fields (`adapter`,\n\t * `vitePlugins`, `viteConfig`, `inputs`) are left alone, since changing\n\t * those needs a restart anyway.\n\t *\n\t * Returns true when the route table changed.\n\t */\n\tapplyRouteState(other: Site): boolean {\n\t\tconst changed = !routesEqual(this.routes, other.routes);\n\t\tthis.routes = other.routes;\n\t\tthis.routeFolders = other.routeFolders;\n\t\tthis.inlineEndPoints = other.inlineEndPoints;\n\t\tthis.plugins = other.plugins;\n\t\tthis.pluginState = other.pluginState;\n\t\tthis.env = other.env;\n\t\tthis.middleware = other.middleware;\n\t\tthis.basePath = other.basePath;\n\t\tthis.viewTransitions = other.viewTransitions;\n\t\tthis.prerender = other.prerender;\n\t\tthis.sitemap = other.sitemap;\n\t\tthis.origin = other.origin;\n\t\tthis.budgets = other.budgets;\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Adds a file route, which can have a standard name (e.g. +page.ts) or any\n\t * name if you pass the type\n\t * @param path The route path\n\t * @param file The file\n\t * @param type The file type (if the file name is non-standard)\n\t */\n\taddRouteFile(\n\t\tpath: string,\n\t\tfile: string,\n\t\ttype?:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t\tsubFolder?: string,\n\t): void {\n\t\tlet routePath = this.#routePath(fpath.join(path, type ?? fpath.basename(file)));\n\t\tlet routeType = type ? this.#routeTypeFromString(type) : this.#routeType(file);\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\tthis.routes.push({\n\t\t\tpath: routePath,\n\t\t\tfile,\n\t\t\ttype: routeType,\n\t\t\tsubFolder: subFolder,\n\t\t});\n\t\tthis.#sortRoutes();\n\t}\n\n\t#routePath(file: string): string {\n\t\tlet routePath = file\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/(\\.ts|\\.js)$/, \"\")\n\t\t\t.replace(/_hook.server$/, \"_hook/~server\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\t#routeType(file: string): RouteType {\n\t\tlet routePath = file.replace(/^\\//, \"\").replace(/(\\.ts|\\.js)$/, \"\");\n\t\tif (routePath.endsWith(\"+page\")) {\n\t\t\treturn PAGE_ROUTE;\n\t\t} else if (routePath.endsWith(\"+page.server\")) {\n\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"+server\")) {\n\t\t\treturn SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout\")) {\n\t\t\treturn LAYOUT_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout.server\")) {\n\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook\")) {\n\t\t\treturn HOOK_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook.server\")) {\n\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_error\")) {\n\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t\treturn -1;\n\t}\n\n\t#routeTypeFromString(\n\t\ttype:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t) {\n\t\tswitch (type) {\n\t\t\tcase \"+page\":\n\t\t\t\treturn PAGE_ROUTE;\n\t\t\tcase \"+page.server\":\n\t\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t\tcase \"+server\":\n\t\t\t\treturn SERVER_ROUTE;\n\t\t\tcase \"_layout\":\n\t\t\t\treturn LAYOUT_ROUTE;\n\t\t\tcase \"_layout.server\":\n\t\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t\tcase \"_hook\":\n\t\t\t\treturn HOOK_ROUTE;\n\t\t\tcase \"_hook.server\":\n\t\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t\tcase \"_error\":\n\t\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a route in code, without needing the standard file naming\n\t * conventions (+page.ts, +page.server.ts, etc). This is useful for small\n\t * sites with one or two pages.\n\t *\n\t * Any combination of options may be provided; each maps to the\n\t * corresponding file-route type:\n\t *\n\t * - `page` — a `+page` (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t * - `pageServer` — a `+page.server` (`PageServerEndPoint`, file or inline)\n\t * - `server` — a `+server` HTTP endpoint (`ServerEndPoint`, file or inline)\n\t * - `layout` — a `_layout` (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t * - `layoutServer` — a `_layout.server` (`PageServerEndPoint`, file or inline)\n\t * - `hookServer` — a `_hook.server` (`ServerHook`, file or inline)\n\t * - `error` — an `_error` page (`.torp` component or `.ts`/`.js` `PageEndPoint`)\n\t *\n\t * Options that need a component (`page`, `layout`, `error`) must be file\n\t * paths so the component is included in the client bundle. Server-only\n\t * options (`pageServer`, `server`, `layoutServer`, `hookServer`) accept\n\t * either a file path or an inline object; inline server code is kept out\n\t * of the client bundle automatically.\n\t *\n\t * @example\n\t * // A page with an inline server action\n\t * site.addRoute(\"/\", {\n\t * page: \"./src/Counter.torp\",\n\t * pageServer: { actions: { set: async ({ request }) => ok() } },\n\t * });\n\t * @example\n\t * // A JSON API endpoint\n\t * site.addRoute(\"/api/time\", {\n\t * server: { get: async () => ok({ time: Date.now() }) },\n\t * });\n\t * @example\n\t * // A root layout, server hook, and error page\n\t * site.addRoute(\"/\", {\n\t * layout: \"./src/Layout.torp\",\n\t * hookServer: { enter: async (event) => {} },\n\t * error: \"./src/ErrorPage.torp\",\n\t * });\n\t *\n\t * @param path The route path, e.g. `/` or `/about`\n\t * @param options File paths and/or inline endpoints for the route\n\t * @param subFolder An optional subFolder for grouping routes\n\t */\n\taddRoute(\n\t\tpath: string,\n\t\toptions: {\n\t\t\tpage?: string;\n\t\t\tpageServer?: string | PageServerEndPoint;\n\t\t\tserver?: string | ServerEndPoint;\n\t\t\tlayout?: string;\n\t\t\tlayoutServer?: string | PageServerEndPoint;\n\t\t\thookServer?: string | ServerHook;\n\t\t\terror?: string;\n\t\t},\n\t\tsubFolder?: string,\n\t): void {\n\t\tlet normalizedSubFolder = subFolder;\n\t\tif (normalizedSubFolder !== undefined && !normalizedSubFolder.startsWith(\"/\")) {\n\t\t\tnormalizedSubFolder = \"/\" + normalizedSubFolder;\n\t\t}\n\n\t\t// The base path with any trailing slash stripped, so that we can\n\t\t// append \"/_layout\", \"/~server\" etc. For the root \"/\" this is \"\".\n\t\tlet base = path.replace(/\\/$/, \"\");\n\n\t\tif (options.page !== undefined) {\n\t\t\tthis.#pushRoute(path, PAGE_ROUTE, options.page, normalizedSubFolder);\n\t\t}\n\t\tif (options.pageServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/~server`,\n\t\t\t\tPAGE_SERVER_ROUTE,\n\t\t\t\toptions.pageServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.server !== undefined) {\n\t\t\tthis.#pushRoute(path, SERVER_ROUTE, options.server, normalizedSubFolder);\n\t\t}\n\t\tif (options.layout !== undefined) {\n\t\t\tthis.#pushRoute(`${base}/_layout`, LAYOUT_ROUTE, options.layout, normalizedSubFolder);\n\t\t}\n\t\tif (options.layoutServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/_layout/~server`,\n\t\t\t\tLAYOUT_SERVER_ROUTE,\n\t\t\t\toptions.layoutServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.hookServer !== undefined) {\n\t\t\tthis.#pushRoute(\n\t\t\t\t`${base}/_hook/~server`,\n\t\t\t\tHOOK_SERVER_ROUTE,\n\t\t\t\toptions.hookServer,\n\t\t\t\tnormalizedSubFolder,\n\t\t\t);\n\t\t}\n\t\tif (options.error !== undefined) {\n\t\t\tthis.#pushRoute(`${base}/_error`, ERROR_ROUTE, options.error, normalizedSubFolder);\n\t\t}\n\n\t\tthis.#sortRoutes();\n\t}\n\n\t/**\n\t * Pushes a single route entry, handling both file-path and inline-endpoint\n\t * targets. File paths are resolved relative to the site root; inline\n\t * endpoints are also stored in `inlineEndPoints` keyed by `\"path:type\"`\n\t * so the manifest plugin can resolve them at build time.\n\t *\n\t * If a route with the same path and type was already added, it is\n\t * replaced, so that running a plugin twice (config load and server\n\t * startup) doesn't add duplicate routes.\n\t */\n\t#pushRoute(\n\t\troutePath: string,\n\t\ttype: RouteType,\n\t\ttarget: string | InlineEndPoint,\n\t\tsubFolder?: string,\n\t): void {\n\t\tconst index = this.routes.findIndex((r) => r.path === routePath && r.type === type);\n\t\tif (typeof target === \"string\") {\n\t\t\tlet file = fpath.relative(this.root, fpath.resolve(this.root, target));\n\t\t\tif (index >= 0) {\n\t\t\t\tthis.routes[index] = { path: routePath, file, type, subFolder };\n\t\t\t} else {\n\t\t\t\tthis.routes.push({ path: routePath, file, type, subFolder });\n\t\t\t}\n\t\t} else {\n\t\t\tlet key = `${routePath}:${type}`;\n\t\t\tthis.inlineEndPoints[key] = target;\n\t\t\tif (index >= 0) {\n\t\t\t\tthis.routes[index] = { path: routePath, endPoint: target, type, subFolder };\n\t\t\t} else {\n\t\t\t\tthis.routes.push({ path: routePath, endPoint: target, type, subFolder });\n\t\t\t}\n\t\t}\n\t}\n\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\n/**\n * Whether two route tables are equivalent for the purpose of deciding\n * whether a route-file change actually changed the router. Compares the\n * identifying fields of each route, in order.\n */\nfunction routesEqual(a: Route[], b: Route[]): boolean {\n\tif (a.length !== b.length) return false;\n\tfor (let i = 0; i < a.length; i++) {\n\t\tconst x = a[i];\n\t\tconst y = b[i];\n\t\tif (\n\t\t\tx.path !== y.path ||\n\t\t\tx.type !== y.type ||\n\t\t\tx.file !== y.file ||\n\t\t\tx.subFolder !== y.subFolder\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,mBAAmB,CACxB;CAEC,KAAK;CACL,WAAW,CAAC;AACb,GACA;CACC,KAAK;CAGL,WAAW,CAAC,UAAU;AACvB,CACD;;;;;;AAOA,eAAe,mBAAmB,KAA2C;CAC5E,IAAI;EACH,QAAQ,MAAM;;GAA0B;EAAI,CAAE;CAC/C,QAAQ;EACP;CACD;AACD;;;;;;;;;;;AA4BA,eAAsB,eACrB,UAAiC,CAAC,GACL;CAC7B,MAAM,MAAM,QAAQ,OAAO,QAAQ;CACnC,MAAM,OAAO,QAAQ,QAAQ;CAG7B,MAAM,yBAAS,IAAI,IAAiC;CACpD,MAAM,WAAW,OAAO,QAAgB;EACvC,IAAI,CAAC,OAAO,IAAI,GAAG,GAAG,OAAO,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;EACrD,OAAO,OAAO,IAAI,GAAG;CACtB;CAGA,KAAK,MAAM,aAAa,kBACvB,KAAK,MAAM,UAAU,UAAU,WAAW;EACzC,IAAI,IAAI,YAAY,KAAA,GAAW;EAC/B,MAAM,UAAU,MAAM,SAAS,UAAU,GAAG;EAC5C,IAAI,SACH,OAAO;GAAE;GAAS,KAAK,UAAU;GAAK,QAAQ,GAAG,OAAO;EAAW;CAErE;CAID,KAAK,MAAM,aAAa,kBAAkB;EACzC,MAAM,UAAU,MAAM,SAAS,UAAU,GAAG;EAC5C,IAAI,SACH,OAAO;GAAE;GAAS,KAAK,UAAU;GAAK,QAAQ;EAAY;CAE5D;CAEA,OAAO;EAAE,SAAS,KAAA;EAAW,KAAK,KAAA;EAAW,QAAQ;CAAa;AACnE;;;;;;AAOA,SAAS,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