@pajecawav/yamf 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/ssr.d.ts +2 -3
- package/dist/context/ssr.d.ts.map +1 -1
- package/dist/context/ssr.js.map +1 -1
- package/dist/hooks/useEvent.d.ts +2 -3
- package/dist/hooks/useEvent.d.ts.map +1 -1
- package/dist/hooks/useEvent.js.map +1 -1
- package/dist/island/client.js.map +1 -1
- package/dist/page.d.ts +3 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js.map +1 -1
- package/dist/server/entry.d.mts +2 -1
- package/dist/server/entry.d.mts.map +1 -1
- package/dist/server/entry.mjs +4 -1
- package/dist/server/entry.mjs.map +1 -1
- package/dist/server/island/server.d.mts.map +1 -1
- package/dist/server/island/server.mjs.map +1 -1
- package/dist/vite/islands.mjs.map +1 -1
- package/package.json +5 -5
- package/src/context/ssr.ts +1 -2
- package/src/hooks/useEvent.tsx +1 -2
- package/src/island/client.tsx +2 -2
- package/src/island/server.tsx +1 -1
- package/src/page.tsx +3 -3
- package/src/server/entry.tsx +12 -7
- package/src/virtual.d.ts +0 -1
- package/src/vite/islands.ts +1 -1
package/dist/context/ssr.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { EventHandlerRequest } from "nitro/h3";
|
|
2
1
|
import { ServerUnhead } from "unhead/server";
|
|
3
|
-
import { H3Event
|
|
2
|
+
import { H3Event } from "nitro";
|
|
4
3
|
|
|
5
4
|
//#region src/context/ssr.d.ts
|
|
6
5
|
interface SSRContextValue {
|
|
7
6
|
head: ServerUnhead;
|
|
8
|
-
event: H3Event
|
|
7
|
+
event: H3Event;
|
|
9
8
|
}
|
|
10
9
|
declare const useSSRContext: () => SSRContextValue | null;
|
|
11
10
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.ts","names":[],"sources":["../../src/context/ssr.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","names":[],"sources":["../../src/context/ssr.ts"],"mappings":";;;;UAIU,eAAA;EACT,IAAA,EAAM,YAAA;EACN,KAAA,EAAO,OAAA;AAAA;AAAA,cAOK,aAAA,QAAoB,eAAA"}
|
package/dist/context/ssr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.js","names":[],"sources":["../../src/context/ssr.ts"],"sourcesContent":["import { type Context, createContext, useContext } from \"hono/jsx\";\nimport type { H3Event } from \"nitro\";\nimport type {
|
|
1
|
+
{"version":3,"file":"ssr.js","names":[],"sources":["../../src/context/ssr.ts"],"sourcesContent":["import { type Context, createContext, useContext } from \"hono/jsx\";\nimport type { H3Event } from \"nitro\";\nimport type { ServerUnhead } from \"unhead/server\";\n\ninterface SSRContextValue {\n\thead: ServerUnhead;\n\tevent: H3Event;\n}\n\nexport const SSRContext: Context<SSRContextValue | null> = createContext<SSRContextValue | null>(\n\tnull,\n);\n\nexport const useSSRContext = (): SSRContextValue | null => {\n\treturn useContext(SSRContext);\n};\n"],"mappings":";;AASA,MAAa,aAA8C,cAC1D,KACA;AAED,MAAa,sBAA8C;CAC1D,OAAO,WAAW,WAAW"}
|
package/dist/hooks/useEvent.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { H3Event as H3Event$1 } from "nitro";
|
|
1
|
+
import { H3Event } from "nitro";
|
|
3
2
|
|
|
4
3
|
//#region src/hooks/useEvent.d.ts
|
|
5
|
-
declare const useEvent: () => H3Event
|
|
4
|
+
declare const useEvent: () => H3Event;
|
|
6
5
|
//#endregion
|
|
7
6
|
export { useEvent };
|
|
8
7
|
//# sourceMappingURL=useEvent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.d.ts","names":[],"sources":["../../src/hooks/useEvent.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEvent.d.ts","names":[],"sources":["../../src/hooks/useEvent.tsx"],"mappings":";;;cAGa,QAAA,QAAe,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.js","names":[],"sources":["../../src/hooks/useEvent.tsx"],"sourcesContent":["import type { H3Event } from \"nitro\";\nimport
|
|
1
|
+
{"version":3,"file":"useEvent.js","names":[],"sources":["../../src/hooks/useEvent.tsx"],"sourcesContent":["import type { H3Event } from \"nitro\";\nimport { useSSRContext } from \"#/context/ssr\";\n\nexport const useEvent = (): H3Event => {\n\tconst ctx = useSSRContext();\n\n\tif (!ctx) {\n\t\tthrow new Error(\"SSR context not found\");\n\t}\n\n\treturn ctx.event;\n};\n"],"mappings":";;AAGA,MAAa,iBAA0B;CACtC,MAAM,MAAM,eAAe;CAE3B,IAAI,CAAC,KACJ,MAAM,IAAI,MAAM,wBAAwB;CAGzC,OAAO,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/island/client.tsx"],"sourcesContent":["import { parse } from \"devalue\";\nimport type { FC } from \"hono/jsx\";\nimport { hydrateRoot } from \"hono/jsx/dom/client\";\nimport { withLeadingSlash } from \"ufo\";\nimport type { IslandClientDirective } from \"./types\";\n\ndeclare let __island_raw_import__: <T>(file: string) => Promise<T>;\n\nconst listeners = new WeakMap<Element, VoidFunction>();\n\nconst observer = new IntersectionObserver(entries => {\n\tfor (const entry of entries) {\n\t\tif (entry.isIntersecting) {\n\t\t\tlisteners.get(entry.target)?.();\n\t\t\tunobserve(entry.target);\n\t\t}\n\t}\n});\n\nconst observe = (target: Element, cb: VoidFunction) => {\n\tobserver.observe(target);\n\tlisteners.set(target, cb);\n};\n\nconst unobserve = (target: Element) => {\n\tobserver.unobserve(target);\n\tlisteners.delete(target);\n};\n\ncustomElements.define(\n\t\"yamf-island\",\n\tclass extends HTMLElement {\n\t\tpublic connectedCallback() {\n\t\t\
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/island/client.tsx"],"sourcesContent":["import { parse } from \"devalue\";\nimport type { FC } from \"hono/jsx\";\nimport { hydrateRoot } from \"hono/jsx/dom/client\";\nimport { withLeadingSlash } from \"ufo\";\nimport type { IslandClientDirective } from \"./types\";\n\ndeclare let __island_raw_import__: <T>(file: string) => Promise<T>;\n\nconst listeners = new WeakMap<Element, VoidFunction>();\n\nconst observer = new IntersectionObserver(entries => {\n\tfor (const entry of entries) {\n\t\tif (entry.isIntersecting) {\n\t\t\tlisteners.get(entry.target)?.();\n\t\t\tunobserve(entry.target);\n\t\t}\n\t}\n});\n\nconst observe = (target: Element, cb: VoidFunction) => {\n\tobserver.observe(target);\n\tlisteners.set(target, cb);\n};\n\nconst unobserve = (target: Element) => {\n\tobserver.unobserve(target);\n\tlisteners.delete(target);\n};\n\ncustomElements.define(\n\t\"yamf-island\",\n\tclass extends HTMLElement {\n\t\tpublic connectedCallback() {\n\t\t\tconst islandProps = parse(this.getAttribute(\"island-props\") ?? \"{}\");\n\t\t\tconst islandSrc = this.getAttribute(\"island-src\");\n\t\t\tconst islandEntry = this.getAttribute(\"island-entry\");\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion\n\t\t\tconst islandClient = (this.getAttribute(\"island-client\") ??\n\t\t\t\t\"load\") as IslandClientDirective;\n\n\t\t\tif (!islandSrc) {\n\t\t\t\tthrow new Error(\"Missing island-src attribute\");\n\t\t\t}\n\n\t\t\tif (!islandEntry) {\n\t\t\t\tthrow new Error(\"Missing island-entry attribute\");\n\t\t\t}\n\n\t\t\tconst hydrateIsland = (mod: Record<string, FC>) => {\n\t\t\t\tconst Comp = mod[islandEntry];\n\n\t\t\t\tif (!Comp) {\n\t\t\t\t\tthrow new Error(`Missing island entry ${islandEntry} in ${islandSrc}`);\n\t\t\t\t}\n\n\t\t\t\thydrateRoot(this, <Comp {...islandProps} />);\n\t\t\t};\n\n\t\t\tconst initIsland = () => {\n\t\t\t\tconst src = withLeadingSlash(islandSrc);\n\t\t\t\tvoid __island_raw_import__<Record<string, FC>>(src).then(hydrateIsland);\n\t\t\t};\n\n\t\t\tswitch (islandClient) {\n\t\t\t\tcase \"load\":\n\t\t\t\t\tinitIsland();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"idle\":\n\t\t\t\t\trequestIdleCallback(initIsland);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"visible\":\n\t\t\t\t\t// yamf-island has `display: contents` which breaks IntersectionObserver\n\t\t\t\t\t// so we have to observe the first child instead if it exists\n\t\t\t\t\tif (this.firstElementChild) {\n\t\t\t\t\t\tobserve(this.firstElementChild, initIsland);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinitIsland();\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"skip\":\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\t// oxlint-disable-next-line typescript/restrict-template-expressions\n\t\t\t\t\tthrow new Error(`Invalid island-client value: ${islandClient}`);\n\t\t\t}\n\t\t}\n\n\t\tpublic disconnectedCallback() {\n\t\t\tunobserve(this);\n\t\t}\n\t},\n);\n"],"mappings":";;;;;AAQA,MAAM,4BAAY,IAAI,SAAgC;AAEtD,MAAM,WAAW,IAAI,sBAAqB,YAAW;CACpD,KAAK,MAAM,SAAS,SACnB,IAAI,MAAM,gBAAgB;EACzB,UAAU,IAAI,MAAM,OAAO,IAAI;EAC/B,UAAU,MAAM,OAAO;;EAGxB;AAEF,MAAM,WAAW,QAAiB,OAAqB;CACtD,SAAS,QAAQ,OAAO;CACxB,UAAU,IAAI,QAAQ,GAAG;;AAG1B,MAAM,aAAa,WAAoB;CACtC,SAAS,UAAU,OAAO;CAC1B,UAAU,OAAO,OAAO;;AAGzB,eAAe,OACd,eACA,cAAc,YAAY;CACzB,oBAA2B;EAC1B,MAAM,cAAc,MAAM,KAAK,aAAa,eAAe,IAAI,KAAK;EACpE,MAAM,YAAY,KAAK,aAAa,aAAa;EACjD,MAAM,cAAc,KAAK,aAAa,eAAe;EAErD,MAAM,eAAgB,KAAK,aAAa,gBAAgB,IACvD;EAED,IAAI,CAAC,WACJ,MAAM,IAAI,MAAM,+BAA+B;EAGhD,IAAI,CAAC,aACJ,MAAM,IAAI,MAAM,iCAAiC;EAGlD,MAAM,iBAAiB,QAA4B;GAClD,MAAM,OAAO,IAAI;GAEjB,IAAI,CAAC,MACJ,MAAM,IAAI,MAAM,wBAAwB,YAAY,MAAM,YAAY;GAGvE,YAAY,MAAM,oBAAC,MAAD,EAAM,GAAI,aAAe,CAAA,CAAC;;EAG7C,MAAM,mBAAmB;GACxB,MAAM,MAAM,iBAAiB,UAAU;GACvC,sBAA+C,IAAI,CAAC,KAAK,cAAc;;EAGxE,QAAQ,cAAR;GACC,KAAK;IACJ,YAAY;IACZ;GACD,KAAK;IACJ,oBAAoB,WAAW;IAC/B;GACD,KAAK;IAGJ,IAAI,KAAK,mBACR,QAAQ,KAAK,mBAAmB,WAAW;SAE3C,YAAY;IAEb;GACD,KAAK,QACJ;GACD,SAEC,MAAM,IAAI,MAAM,gCAAgC,eAAe;;;CAIlE,uBAA8B;EAC7B,UAAU,KAAK;;EAGjB"}
|
package/dist/page.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ImportAssetsResult } from "./shared/assets.js";
|
|
2
2
|
import { Child, FC, PropsWithChildren } from "hono/jsx";
|
|
3
|
-
import {
|
|
3
|
+
import { EventHandlerResponse, H3Event, HTTPResponse } from "nitro/h3";
|
|
4
4
|
import { Unhead } from "unhead/server";
|
|
5
5
|
import { ResolvableHead } from "unhead/types";
|
|
6
6
|
|
|
7
7
|
//#region src/page.d.ts
|
|
8
|
-
type PageHandler = (event: H3Event
|
|
8
|
+
type PageHandler = (event: H3Event, params: {
|
|
9
9
|
serverAssets?: ImportAssetsResult;
|
|
10
10
|
head?: ResolvableHead;
|
|
11
11
|
Layout?: FC<PropsWithChildren>;
|
|
12
12
|
}) => EventHandlerResponse;
|
|
13
|
-
type PageRenderer = (event: H3Event
|
|
13
|
+
type PageRenderer = (event: H3Event, params: {
|
|
14
14
|
head: Unhead;
|
|
15
15
|
}) => HTTPResponse | Promise<HTTPResponse> | Child | Promise<Child>;
|
|
16
16
|
interface DefinePageOptions {
|
package/dist/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","names":[],"sources":["../src/page.tsx"],"mappings":";;;;;;;KAeY,WAAA,IACX,KAAA,EAAO,OAAA,
|
|
1
|
+
{"version":3,"file":"page.d.ts","names":[],"sources":["../src/page.tsx"],"mappings":";;;;;;;KAeY,WAAA,IACX,KAAA,EAAO,OAAA,EACP,MAAA;EACC,YAAA,GAAe,kBAAA;EACf,IAAA,GAAO,cAAA;EACP,MAAA,GAAS,EAAA,CAAG,iBAAA;AAAA,MAET,oBAAA;AAAA,KAEO,YAAA,IACX,KAAA,EAAO,OAAA,EACP,MAAA;EAAU,IAAA,EAAM,MAAA;AAAA,MACZ,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,KAAA,GAAQ,OAAA,CAAQ,KAAA;AAAA,UAElD,iBAAA;EACT,MAAA,EAAQ,YAAA;EACR,MAAA;EACA,MAAA,GAAS,EAAA,CAAG,iBAAA;AAAA;AAAA,cAGA,UAAA,GAAc,OAAA,EAAS,iBAAA,KAAoB,WAAA"}
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","names":[],"sources":["../src/page.tsx"],"sourcesContent":["import type { Child, FC, PropsWithChildren } from \"hono/jsx\";\nimport { Fragment } from \"hono/jsx\";\nimport { renderToReadableStream } from \"hono/jsx/streaming\";\nimport { Hono } from \"hono/tiny\";\nimport type {
|
|
1
|
+
{"version":3,"file":"page.js","names":[],"sources":["../src/page.tsx"],"sourcesContent":["import type { Child, FC, PropsWithChildren } from \"hono/jsx\";\nimport { Fragment } from \"hono/jsx\";\nimport { renderToReadableStream } from \"hono/jsx/streaming\";\nimport { Hono } from \"hono/tiny\";\nimport type { EventHandlerResponse, H3Event } from \"nitro/h3\";\nimport { HTTPResponse, withServerTiming } from \"nitro/h3\";\nimport type { Unhead } from \"unhead/server\";\nimport { transformHtmlTemplate } from \"unhead/server\";\nimport { createStreamableHead, wrapStream } from \"unhead/stream/server\";\nimport type { ResolvableHead, ResolvableLink } from \"unhead/types\";\nimport { clientAssets } from \"virtual:yamf:assets\";\nimport { template } from \"virtual:yamf:template\";\nimport { SSRContext } from \"./context/ssr\";\nimport type { ImportAssetsResult } from \"./shared/assets\";\n\nexport type PageHandler = (\n\tevent: H3Event,\n\tparams: {\n\t\tserverAssets?: ImportAssetsResult;\n\t\thead?: ResolvableHead;\n\t\tLayout?: FC<PropsWithChildren>;\n\t},\n) => EventHandlerResponse;\n\nexport type PageRenderer = (\n\tevent: H3Event,\n\tparams: { head: Unhead },\n) => HTTPResponse | Promise<HTTPResponse> | Child | Promise<Child>;\n\ninterface DefinePageOptions {\n\trender: PageRenderer;\n\tstream?: boolean;\n\tLayout?: FC<PropsWithChildren>;\n}\n\nexport const definePage = (options: DefinePageOptions): PageHandler => {\n\treturn async (event, { serverAssets, head: headInit, Layout = options.Layout ?? Fragment }) => {\n\t\tconst assets = serverAssets ? clientAssets.merge(serverAssets) : clientAssets;\n\n\t\tconst { head } = createStreamableHead({ init: [headInit] });\n\n\t\thead.push({\n\t\t\tlink: [\n\t\t\t\t...assets.js.map((attrs): ResolvableLink => ({ rel: \"modulepreload\", ...attrs })),\n\t\t\t\t...assets.css.map((attrs): ResolvableLink => ({ rel: \"stylesheet\", ...attrs })),\n\t\t\t],\n\t\t\tscript: [{ type: \"module\", src: assets.entry }],\n\t\t});\n\n\t\tconst content = await options.render(event, { head });\n\n\t\tif (content instanceof HTTPResponse) {\n\t\t\treturn content;\n\t\t}\n\n\t\tconst App = async () => (\n\t\t\t<SSRContext value={{ head, event }}>\n\t\t\t\t<Layout>{content}</Layout>\n\t\t\t</SSRContext>\n\t\t);\n\n\t\tconst responseInit = {\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"text/html; charset=utf-8\",\n\t\t\t},\n\t\t};\n\n\t\tif (!options.stream) {\n\t\t\t// TODO: figure out how expensive this is\n\t\t\treturn new Hono()\n\t\t\t\t.get(\"/\", async c =>\n\t\t\t\t\twithServerTiming(event, \"#render\", async () => {\n\t\t\t\t\t\tconst response = await c.html(<App />);\n\n\t\t\t\t\t\tlet html = await response.text();\n\n\t\t\t\t\t\thtml = transformHtmlTemplate(\n\t\t\t\t\t\t\thead,\n\t\t\t\t\t\t\ttemplate.replace(\"<!--ssr-outlet-->\", html ?? \"\"),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn new Response(html, responseInit);\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.request(\"/\");\n\t\t}\n\n\t\tconst stream = wrapStream(head, renderToReadableStream(<App />), template);\n\n\t\treturn new Response(stream, responseInit);\n\t};\n};\n"],"mappings":";;;;;;;;;;;AAmCA,MAAa,cAAc,YAA4C;CACtE,OAAO,OAAO,OAAO,EAAE,cAAc,MAAM,UAAU,SAAS,QAAQ,UAAU,eAAe;EAC9F,MAAM,SAAS,eAAe,aAAa,MAAM,aAAa,GAAG;EAEjE,MAAM,EAAE,SAAS,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;EAE3D,KAAK,KAAK;GACT,MAAM,CACL,GAAG,OAAO,GAAG,KAAK,WAA2B;IAAE,KAAK;IAAiB,GAAG;IAAO,EAAE,EACjF,GAAG,OAAO,IAAI,KAAK,WAA2B;IAAE,KAAK;IAAc,GAAG;IAAO,EAAE,CAC/E;GACD,QAAQ,CAAC;IAAE,MAAM;IAAU,KAAK,OAAO;IAAO,CAAC;GAC/C,CAAC;EAEF,MAAM,UAAU,MAAM,QAAQ,OAAO,OAAO,EAAE,MAAM,CAAC;EAErD,IAAI,mBAAmB,cACtB,OAAO;EAGR,MAAM,MAAM,YACX,oBAAC,YAAD;GAAY,OAAO;IAAE;IAAM;IAAO;aACjC,oBAAC,QAAD,EAAA,UAAS,SAAiB,CAAA;GACd,CAAA;EAGd,MAAM,eAAe,EACpB,SAAS,EACR,gBAAgB,4BAChB,EACD;EAED,IAAI,CAAC,QAAQ,QAEZ,OAAO,IAAI,MAAM,CACf,IAAI,KAAK,OAAM,MACf,iBAAiB,OAAO,WAAW,YAAY;GAG9C,IAAI,OAAO,OAAM,MAFM,EAAE,KAAK,oBAAC,KAAD,EAAO,CAAA,CAAC,EAEZ,MAAM;GAEhC,OAAO,sBACN,MACA,SAAS,QAAQ,qBAAqB,QAAQ,GAAG,CACjD;GAED,OAAO,IAAI,SAAS,MAAM,aAAa;IACtC,CACF,CACA,QAAQ,IAAI;EAGf,MAAM,SAAS,WAAW,MAAM,uBAAuB,oBAAC,KAAD,EAAO,CAAA,CAAC,EAAE,SAAS;EAE1E,OAAO,IAAI,SAAS,QAAQ,aAAa"}
|
package/dist/server/entry.d.mts
CHANGED
|
@@ -5,8 +5,9 @@ import { ResolvableHead } from "unhead/types";
|
|
|
5
5
|
//#region src/server/entry.d.ts
|
|
6
6
|
type ServerEntry = EventHandlerWithFetch<EventHandlerRequest, Promise<unknown>>;
|
|
7
7
|
interface DefineServerEntryOptions {
|
|
8
|
-
head?: ResolvableHead | ((event: H3Event
|
|
8
|
+
head?: ResolvableHead | ((event: H3Event) => ResolvableHead);
|
|
9
9
|
Layout?: FC<PropsWithChildren>;
|
|
10
|
+
disableEarlyHints?: boolean;
|
|
10
11
|
}
|
|
11
12
|
declare const defineServerEntry: (options?: DefineServerEntryOptions) => ServerEntry;
|
|
12
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.mts","names":[],"sources":["../../src/server/entry.tsx"],"mappings":";;;;;KA8CY,WAAA,GAAc,qBAAA,CAAsB,mBAAA,EAAqB,OAAA;AAAA,UAEpD,wBAAA;EAChB,IAAA,GAAO,cAAA,KAAmB,KAAA,EAAO,OAAA,
|
|
1
|
+
{"version":3,"file":"entry.d.mts","names":[],"sources":["../../src/server/entry.tsx"],"mappings":";;;;;KA8CY,WAAA,GAAc,qBAAA,CAAsB,mBAAA,EAAqB,OAAA;AAAA,UAEpD,wBAAA;EAChB,IAAA,GAAO,cAAA,KAAmB,KAAA,EAAO,OAAA,KAAY,cAAA;EAC7C,MAAA,GAAS,EAAA,CAAG,iBAAA;EACZ,iBAAA;AAAA;AAAA,cAGY,iBAAA,GAAqB,OAAA,GAAU,wBAAA,KAA2B,WAAA"}
|
package/dist/server/entry.mjs
CHANGED
|
@@ -24,7 +24,10 @@ const defineServerEntry = (options) => {
|
|
|
24
24
|
const { handler, serverAssets } = route.data;
|
|
25
25
|
event.context.params = route.params;
|
|
26
26
|
const assets = serverAssets ? serverAssets.merge(clientAssets) : clientAssets;
|
|
27
|
-
|
|
27
|
+
if (!options?.disableEarlyHints) {
|
|
28
|
+
const link = [...assets.js.map((script) => `<${script.href}>; rel=modulepreload`), ...assets.css.map((style) => `<${style.href}>; rel=preload; as=style`)];
|
|
29
|
+
if (link.length) await writeEarlyHints(event, { link });
|
|
30
|
+
}
|
|
28
31
|
return (await handler())(event, {
|
|
29
32
|
serverAssets,
|
|
30
33
|
head: typeof options?.head === "function" ? options.head(event) : options?.head,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.mjs","names":["
|
|
1
|
+
{"version":3,"file":"entry.mjs","names":["pagesServerAssets"],"sources":["../../src/server/entry.tsx"],"sourcesContent":["import path from \"node:path\";\nimport type { FC, PropsWithChildren } from \"hono/jsx\";\nimport type { EventHandlerRequest, EventHandlerWithFetch, H3Event } from \"nitro/h3\";\nimport { defineHandler, HTTPError, writeEarlyHints } from \"nitro/h3\";\nimport { addRoute, createRouter, findRoute } from \"rou3\";\nimport { withLeadingSlash, withoutTrailingSlash } from \"ufo\";\nimport type { ResolvableHead } from \"unhead/types\";\nimport { clientAssets } from \"virtual:yamf:assets\";\nimport { pages, assets as pagesServerAssets } from \"virtual:yamf:pages\";\nimport type { PageHandler } from \"#/page\";\n\ninterface Route {\n\thandler: () => Promise<PageHandler>;\n\tserverAssets?: ImportAssetsResult;\n}\n\nconst router = createRouter<Route>();\n\nfor (const [relativePath, handler] of Object.entries(pages).toSorted((a, b) =>\n\ta[0].localeCompare(b[0]),\n)) {\n\tconst ext = path.extname(relativePath);\n\n\tlet route = path.relative(\"/src/pages\", relativePath);\n\n\tif (ext.length) {\n\t\troute = route.slice(0, -ext.length);\n\t}\n\n\troute =\n\t\troute\n\t\t\t.replace(/\\.[A-Za-z]+$/, \"\")\n\t\t\t.replace(/\\(([^(/\\\\]+)\\)[/\\\\]/g, \"\")\n\t\t\t.replace(/\\[\\.{3}]/g, \"**\")\n\t\t\t.replace(/\\[\\.{3}([^\\]]+)]/g, (_, p: string) => \"**:\" + p.replace(/[^\\w-]/g, \"_\"))\n\t\t\t.replace(/\\[([^/\\]]+)]/g, (_, p: string) => \":\" + p.replace(/[^\\w-]/g, \"_\"))\n\t\t\t.replace(/(\\/|^)index$/, \"\") || \"/\";\n\n\troute = withLeadingSlash(withoutTrailingSlash(route));\n\n\taddRoute(router, \"GET\", route, {\n\t\thandler,\n\t\tserverAssets: pagesServerAssets[relativePath],\n\t});\n}\n\nexport type ServerEntry = EventHandlerWithFetch<EventHandlerRequest, Promise<unknown>>;\n\nexport interface DefineServerEntryOptions {\n\thead?: ResolvableHead | ((event: H3Event) => ResolvableHead);\n\tLayout?: FC<PropsWithChildren>;\n\tdisableEarlyHints?: boolean;\n}\n\nexport const defineServerEntry = (options?: DefineServerEntryOptions): ServerEntry => {\n\treturn defineHandler(async event => {\n\t\tconst route = findRoute(router, \"GET\", event.url.pathname);\n\n\t\tif (!route) {\n\t\t\tthrow new HTTPError(\"Not found\", { status: 404 });\n\t\t}\n\n\t\tconst { handler, serverAssets } = route.data;\n\t\tevent.context.params = route.params;\n\n\t\tconst assets = serverAssets ? serverAssets.merge(clientAssets) : clientAssets;\n\n\t\tif (!options?.disableEarlyHints) {\n\t\t\tconst link = [\n\t\t\t\t...assets.js.map(script => `<${script.href}>; rel=modulepreload`),\n\t\t\t\t...assets.css.map(style => `<${style.href}>; rel=preload; as=style`),\n\t\t\t];\n\n\t\t\tif (link.length) {\n\t\t\t\tawait writeEarlyHints(event, { link });\n\t\t\t}\n\t\t}\n\n\t\treturn (await handler())(event, {\n\t\t\tserverAssets,\n\t\t\thead: typeof options?.head === \"function\" ? options.head(event) : options?.head,\n\t\t\tLayout: options?.Layout,\n\t\t});\n\t});\n};\n"],"mappings":";;;;;;;AAgBA,MAAM,SAAS,cAAqB;AAEpC,KAAK,MAAM,CAAC,cAAc,YAAY,OAAO,QAAQ,MAAM,CAAC,UAAU,GAAG,MACxE,EAAE,GAAG,cAAc,EAAE,GAAG,CACxB,EAAE;CACF,MAAM,MAAM,KAAK,QAAQ,aAAa;CAEtC,IAAI,QAAQ,KAAK,SAAS,cAAc,aAAa;CAErD,IAAI,IAAI,QACP,QAAQ,MAAM,MAAM,GAAG,CAAC,IAAI,OAAO;CAGpC,QACC,MACE,QAAQ,gBAAgB,GAAG,CAC3B,QAAQ,wBAAwB,GAAG,CACnC,QAAQ,aAAa,KAAK,CAC1B,QAAQ,sBAAsB,GAAG,MAAc,QAAQ,EAAE,QAAQ,WAAW,IAAI,CAAC,CACjF,QAAQ,kBAAkB,GAAG,MAAc,MAAM,EAAE,QAAQ,WAAW,IAAI,CAAC,CAC3E,QAAQ,gBAAgB,GAAG,IAAI;CAElC,QAAQ,iBAAiB,qBAAqB,MAAM,CAAC;CAErD,SAAS,QAAQ,OAAO,OAAO;EAC9B;EACA,cAAcA,OAAkB;EAChC,CAAC;;AAWH,MAAa,qBAAqB,YAAoD;CACrF,OAAO,cAAc,OAAM,UAAS;EACnC,MAAM,QAAQ,UAAU,QAAQ,OAAO,MAAM,IAAI,SAAS;EAE1D,IAAI,CAAC,OACJ,MAAM,IAAI,UAAU,aAAa,EAAE,QAAQ,KAAK,CAAC;EAGlD,MAAM,EAAE,SAAS,iBAAiB,MAAM;EACxC,MAAM,QAAQ,SAAS,MAAM;EAE7B,MAAM,SAAS,eAAe,aAAa,MAAM,aAAa,GAAG;EAEjE,IAAI,CAAC,SAAS,mBAAmB;GAChC,MAAM,OAAO,CACZ,GAAG,OAAO,GAAG,KAAI,WAAU,IAAI,OAAO,KAAK,sBAAsB,EACjE,GAAG,OAAO,IAAI,KAAI,UAAS,IAAI,MAAM,KAAK,0BAA0B,CACpE;GAED,IAAI,KAAK,QACR,MAAM,gBAAgB,OAAO,EAAE,MAAM,CAAC;;EAIxC,QAAQ,MAAM,SAAS,EAAE,OAAO;GAC/B;GACA,MAAM,OAAO,SAAS,SAAS,aAAa,QAAQ,KAAK,MAAM,GAAG,SAAS;GAC3E,QAAQ,SAAS;GACjB,CAAC;GACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../../../src/island/server.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../../src/island/server.tsx"],"mappings":";;;;;;YAMW,GAAA;IAAA,UACC,iBAAA;MACT,aAAA;QACC,cAAA;QACA,YAAA;QACA,cAAA;QACA,eAAA,EAAiB,qBAAA;QACjB,QAAA,EAAU,KAAA;QACV,KAAA,GAAQ,GAAA,CAAI,aAAA;MAAA;IAAA;EAAA;AAAA;AAAA,cAMH,YAAA,GACZ,SAAA,EAAW,EAAA,EACX,UAAA,UACA,MAAA,EAAQ,qBAAA,KACN,EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":[],"sources":["../../../src/island/server.tsx"],"sourcesContent":["import { stringify } from \"devalue\";\nimport type { Child, FC } from \"hono/jsx\";\nimport type { ImportAssetsResultRaw } from \"#/shared/assets\";\nimport type { IslandClientDirective } from \"./types\";\n\ndeclare module \"hono/jsx\" {\n\
|
|
1
|
+
{"version":3,"file":"server.mjs","names":[],"sources":["../../../src/island/server.tsx"],"sourcesContent":["import { stringify } from \"devalue\";\nimport type { Child, FC } from \"hono/jsx\";\nimport type { ImportAssetsResultRaw } from \"#/shared/assets\";\nimport type { IslandClientDirective } from \"./types\";\n\ndeclare module \"hono/jsx\" {\n\tnamespace JSX {\n\t\tinterface IntrinsicElements {\n\t\t\t\"yamf-island\": {\n\t\t\t\t\"island-props\"?: string;\n\t\t\t\t\"island-src\": string;\n\t\t\t\t\"island-entry\": string;\n\t\t\t\t\"island-client\": IslandClientDirective;\n\t\t\t\tchildren: Child;\n\t\t\t\tstyle?: JSX.CSSProperties;\n\t\t\t};\n\t\t}\n\t}\n}\n\nexport const createIsland = (\n\tComponent: FC,\n\texportName: string,\n\tassets: ImportAssetsResultRaw,\n): FC => {\n\tconst ComponentWrapper: FC & { name: string } = props => {\n\t\tif (!assets.entry) {\n\t\t\tthrow new Error(`Missing island entry for island ${Component.name}`);\n\t\t}\n\n\t\treturn (\n\t\t\t<yamf-island\n\t\t\t\tisland-props={stringify(props)}\n\t\t\t\tisland-src={assets.entry}\n\t\t\t\tisland-entry={exportName}\n\t\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion\n\t\t\t\tisland-client={props[\"yamf-client\"] as IslandClientDirective}\n\t\t\t\t// TODO: export CSS?\n\t\t\t\tstyle={{ display: \"contents\" }}\n\t\t\t>\n\t\t\t\t<Component {...props} />\n\t\t\t</yamf-island>\n\t\t);\n\t};\n\n\tObject.defineProperty(ComponentWrapper, \"name\", {\n\t\tvalue: Component.name,\n\t});\n\n\treturn ComponentWrapper;\n};\n"],"mappings":";;;AAoBA,MAAa,gBACZ,WACA,YACA,WACQ;CACR,MAAM,oBAA0C,UAAS;EACxD,IAAI,CAAC,OAAO,OACX,MAAM,IAAI,MAAM,mCAAmC,UAAU,OAAO;EAGrE,OACC,oBAAC,eAAD;GACC,gBAAc,UAAU,MAAM;GAC9B,cAAY,OAAO;GACnB,gBAAc;GAEd,iBAAe,MAAM;GAErB,OAAO,EAAE,SAAS,YAAY;aAE9B,oBAAC,WAAD,EAAW,GAAI,OAAS,CAAA;GACX,CAAA;;CAIhB,OAAO,eAAe,kBAAkB,QAAQ,EAC/C,OAAO,UAAU,MACjB,CAAC;CAEF,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"islands.mjs","names":[],"sources":["../../src/vite/islands.ts"],"sourcesContent":["// reference https://github.com/hi-ogawa/vite-plugin-fullstack/blob/28e9540a68529c58842e9a3bf17d2193a065d524/examples/island/src/framework/island/plugin.ts\nimport { generate } from \"@babel/generator\";\nimport { parse } from \"@babel/parser\";\nimport _traverse from \"@babel/traverse\";\nimport {\n\tcallExpression,\n\texportDefaultDeclaration,\n\texportNamedDeclaration,\n\tfunctionDeclaration,\n\tfunctionExpression,\n\tidentifier,\n\timportDeclaration,\n\timportDefaultSpecifier,\n\timportNamespaceSpecifier,\n\tmemberExpression,\n\tstringLiteral,\n\tvariableDeclaration,\n\tvariableDeclarator,\n} from \"@babel/types\";\nimport type { Plugin } from \"vite\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst traverse = (_traverse.default as typeof _traverse) ?? _traverse;\n\nconst ISLAND_REGEX = /\\.island\\.(j|t)sx?$/;\n\nexport const islands = (): Plugin[] => {\n\treturn [\n\t\t{\n\t\t\tname: \"yamf:islands\",\n\t\t\ttransform: {\n\t\t\t\tfilter: { id: ISLAND_REGEX },\n\t\t\t\thandler(code, id) {\n\t\t\t\t\tif (this.environment.name !== \"ssr\") {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst seenExports = new Set<string>();\n\n\t\t\t\t\tconst ast = parse(code, {\n\t\t\t\t\t\tsourceType: \"module\",\n\t\t\t\t\t\tplugins: [\"typescript\", \"jsx\"],\n\t\t\t\t\t});\n\n\t\t\t\t\ttraverse(ast, {\n\t\t\t\t\t\tProgram(path) {\n\t\t\t\t\t\t\t// prepends server island runtime\n\t\t\t\t\t\t\t// import * as __runtime from \"yamf/server\";\n\t\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t\t\"body\",\n\t\t\t\t\t\t\t\timportDeclaration(\n\t\t\t\t\t\t\t\t\t[importNamespaceSpecifier(identifier(\"__runtime\"))],\n\t\t\t\t\t\t\t\t\tstringLiteral(\"@pajecawav/yamf/server\"),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// prepends asset imports for the island:\n\t\t\t\t\t\t\t// import __assets from \"MODULE_ID?assets=client\";\n\t\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t\t\"body\",\n\t\t\t\t\t\t\t\timportDeclaration(\n\t\t\t\t\t\t\t\t\t[importDefaultSpecifier(identifier(\"__assets\"))],\n\t\t\t\t\t\t\t\t\tstringLiteral(`${id}?assets=client`),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\t\t\tconst declarationType = path.node.declaration.type;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\tdeclarationType === \"FunctionDeclaration\" ||\n\t\t\t\t\t\t\t\t\tdeclarationType === \"FunctionExpression\" ||\n\t\t\t\t\t\t\t\t\tdeclarationType === \"ArrowFunctionExpression\"\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst originalFunction =\n\t\t\t\t\t\t\t\tpath.node.declaration.type === \"FunctionExpression\" ||\n\t\t\t\t\t\t\t\tpath.node.declaration.type === \"ArrowFunctionExpression\"\n\t\t\t\t\t\t\t\t\t? path.node.declaration\n\t\t\t\t\t\t\t\t\t: functionExpression(\n\t\t\t\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.params,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.body,\n\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.async,\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst islandIdentifier = identifier(\"__ISLAND__\");\n\n\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\tvariableDeclarator(islandIdentifier, originalFunction),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\texportDefaultDeclaration(\n\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\tstringLiteral(\"default\"),\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tExportNamedDeclaration(path) {\n\t\t\t\t\t\t\tif (path.node.declaration?.type === \"VariableDeclaration\") {\n\t\t\t\t\t\t\t\tconst declaration = path.node.declaration.declarations.at(0);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!declaration ||\n\t\t\t\t\t\t\t\t\tdeclaration.id.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\tseenExports.has(declaration.id.name)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst exportName = declaration.id.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\tconst islandIdentifier = identifier(`__wrap_${exportName}`);\n\n\t\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\tvariableDeclarator(islandIdentifier, declaration.init),\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\t\texportNamedDeclaration(\n\t\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\t\tvariableDeclarator(\n\t\t\t\t\t\t\t\t\t\t\t\tidentifier(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstringLiteral(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else if (path.node.declaration?.type === \"FunctionDeclaration\") {\n\t\t\t\t\t\t\t\tconst declaration = path.node.declaration;\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!declaration ||\n\t\t\t\t\t\t\t\t\tdeclaration.id?.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\tseenExports.has(declaration.id.name)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst exportName = declaration.id.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\tconst islandIdentifier = identifier(`__wrap_${exportName}`);\n\n\t\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\t\tfunctionDeclaration(\n\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\tdeclaration.params,\n\t\t\t\t\t\t\t\t\t\tdeclaration.body,\n\t\t\t\t\t\t\t\t\t\tdeclaration.generator,\n\t\t\t\t\t\t\t\t\t\tdeclaration.async,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\t\texportNamedDeclaration(\n\t\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\t\tvariableDeclarator(\n\t\t\t\t\t\t\t\t\t\t\t\tidentifier(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstringLiteral(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tconst result = generate(ast);\n\n\t\t\t\t\treturn { code: result.code, map: result.map };\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"yamf:islands:raw-import\",\n\t\t\ttransform: {\n\t\t\t\torder: \"post\",\n\t\t\t\thandler(code) {\n\t\t\t\t\tif (code.includes(\"__island_raw_import__\")) {\n\t\t\t\t\t\treturn code.replaceAll(\"__island_raw_import__\", \"import\");\n\t\t\t\t\t}\n\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t];\n};\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"islands.mjs","names":[],"sources":["../../src/vite/islands.ts"],"sourcesContent":["// reference https://github.com/hi-ogawa/vite-plugin-fullstack/blob/28e9540a68529c58842e9a3bf17d2193a065d524/examples/island/src/framework/island/plugin.ts\nimport { generate } from \"@babel/generator\";\nimport { parse } from \"@babel/parser\";\nimport _traverse from \"@babel/traverse\";\nimport {\n\tcallExpression,\n\texportDefaultDeclaration,\n\texportNamedDeclaration,\n\tfunctionDeclaration,\n\tfunctionExpression,\n\tidentifier,\n\timportDeclaration,\n\timportDefaultSpecifier,\n\timportNamespaceSpecifier,\n\tmemberExpression,\n\tstringLiteral,\n\tvariableDeclaration,\n\tvariableDeclarator,\n} from \"@babel/types\";\nimport type { Plugin } from \"vite\";\n\n// @ts-ignore\n// oxlint-disable-next-line typescript/no-unsafe-type-assertion\nconst traverse = (_traverse.default as typeof _traverse) ?? _traverse;\n\nconst ISLAND_REGEX = /\\.island\\.(j|t)sx?$/;\n\nexport const islands = (): Plugin[] => {\n\treturn [\n\t\t{\n\t\t\tname: \"yamf:islands\",\n\t\t\ttransform: {\n\t\t\t\tfilter: { id: ISLAND_REGEX },\n\t\t\t\thandler(code, id) {\n\t\t\t\t\tif (this.environment.name !== \"ssr\") {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst seenExports = new Set<string>();\n\n\t\t\t\t\tconst ast = parse(code, {\n\t\t\t\t\t\tsourceType: \"module\",\n\t\t\t\t\t\tplugins: [\"typescript\", \"jsx\"],\n\t\t\t\t\t});\n\n\t\t\t\t\ttraverse(ast, {\n\t\t\t\t\t\tProgram(path) {\n\t\t\t\t\t\t\t// prepends server island runtime\n\t\t\t\t\t\t\t// import * as __runtime from \"yamf/server\";\n\t\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t\t\"body\",\n\t\t\t\t\t\t\t\timportDeclaration(\n\t\t\t\t\t\t\t\t\t[importNamespaceSpecifier(identifier(\"__runtime\"))],\n\t\t\t\t\t\t\t\t\tstringLiteral(\"@pajecawav/yamf/server\"),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// prepends asset imports for the island:\n\t\t\t\t\t\t\t// import __assets from \"MODULE_ID?assets=client\";\n\t\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t\t\"body\",\n\t\t\t\t\t\t\t\timportDeclaration(\n\t\t\t\t\t\t\t\t\t[importDefaultSpecifier(identifier(\"__assets\"))],\n\t\t\t\t\t\t\t\t\tstringLiteral(`${id}?assets=client`),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\t\t\tconst declarationType = path.node.declaration.type;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\tdeclarationType === \"FunctionDeclaration\" ||\n\t\t\t\t\t\t\t\t\tdeclarationType === \"FunctionExpression\" ||\n\t\t\t\t\t\t\t\t\tdeclarationType === \"ArrowFunctionExpression\"\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst originalFunction =\n\t\t\t\t\t\t\t\tpath.node.declaration.type === \"FunctionExpression\" ||\n\t\t\t\t\t\t\t\tpath.node.declaration.type === \"ArrowFunctionExpression\"\n\t\t\t\t\t\t\t\t\t? path.node.declaration\n\t\t\t\t\t\t\t\t\t: functionExpression(\n\t\t\t\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.params,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.body,\n\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\t\tpath.node.declaration.async,\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst islandIdentifier = identifier(\"__ISLAND__\");\n\n\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\tvariableDeclarator(islandIdentifier, originalFunction),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\texportDefaultDeclaration(\n\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\tstringLiteral(\"default\"),\n\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tExportNamedDeclaration(path) {\n\t\t\t\t\t\t\tif (path.node.declaration?.type === \"VariableDeclaration\") {\n\t\t\t\t\t\t\t\tconst declaration = path.node.declaration.declarations.at(0);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!declaration ||\n\t\t\t\t\t\t\t\t\tdeclaration.id.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\tseenExports.has(declaration.id.name)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst exportName = declaration.id.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\tconst islandIdentifier = identifier(`__wrap_${exportName}`);\n\n\t\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\tvariableDeclarator(islandIdentifier, declaration.init),\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\t\texportNamedDeclaration(\n\t\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\t\tvariableDeclarator(\n\t\t\t\t\t\t\t\t\t\t\t\tidentifier(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstringLiteral(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else if (path.node.declaration?.type === \"FunctionDeclaration\") {\n\t\t\t\t\t\t\t\tconst declaration = path.node.declaration;\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!declaration ||\n\t\t\t\t\t\t\t\t\tdeclaration.id?.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\tseenExports.has(declaration.id.name)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst exportName = declaration.id.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\tconst islandIdentifier = identifier(`__wrap_${exportName}`);\n\n\t\t\t\t\t\t\t\tpath.insertBefore(\n\t\t\t\t\t\t\t\t\tfunctionDeclaration(\n\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\tdeclaration.params,\n\t\t\t\t\t\t\t\t\t\tdeclaration.body,\n\t\t\t\t\t\t\t\t\t\tdeclaration.generator,\n\t\t\t\t\t\t\t\t\t\tdeclaration.async,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tpath.replaceWith(\n\t\t\t\t\t\t\t\t\texportNamedDeclaration(\n\t\t\t\t\t\t\t\t\t\tvariableDeclaration(\"const\", [\n\t\t\t\t\t\t\t\t\t\t\tvariableDeclarator(\n\t\t\t\t\t\t\t\t\t\t\t\tidentifier(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\tcallExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\tmemberExpression(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__runtime\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"createIsland\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tislandIdentifier,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstringLiteral(exportName),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidentifier(\"__assets\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tconst result = generate(ast);\n\n\t\t\t\t\treturn { code: result.code, map: result.map };\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"yamf:islands:raw-import\",\n\t\t\ttransform: {\n\t\t\t\torder: \"post\",\n\t\t\t\thandler(code) {\n\t\t\t\t\tif (code.includes(\"__island_raw_import__\")) {\n\t\t\t\t\t\treturn code.replaceAll(\"__island_raw_import__\", \"import\");\n\t\t\t\t\t}\n\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t];\n};\n"],"mappings":";;;;;AAuBA,MAAM,WAAY,UAAU,WAAgC;AAE5D,MAAM,eAAe;AAErB,MAAa,gBAA0B;CACtC,OAAO,CACN;EACC,MAAM;EACN,WAAW;GACV,QAAQ,EAAE,IAAI,cAAc;GAC5B,QAAQ,MAAM,IAAI;IACjB,IAAI,KAAK,YAAY,SAAS,OAC7B;IAGD,MAAM,8BAAc,IAAI,KAAa;IAErC,MAAM,MAAM,MAAM,MAAM;KACvB,YAAY;KACZ,SAAS,CAAC,cAAc,MAAM;KAC9B,CAAC;IAEF,SAAS,KAAK;KACb,QAAQ,MAAM;MAGb,KAAK,iBACJ,QACA,kBACC,CAAC,yBAAyB,WAAW,YAAY,CAAC,CAAC,EACnD,cAAc,yBAAyB,CACvC,CACD;MAID,KAAK,iBACJ,QACA,kBACC,CAAC,uBAAuB,WAAW,WAAW,CAAC,CAAC,EAChD,cAAc,GAAG,GAAG,gBAAgB,CACpC,CACD;;KAEF,yBAAyB,MAAM;MAC9B,MAAM,kBAAkB,KAAK,KAAK,YAAY;MAE9C,IACC,EACC,oBAAoB,yBACpB,oBAAoB,wBACpB,oBAAoB,4BAGrB;MAGD,MAAM,mBACL,KAAK,KAAK,YAAY,SAAS,wBAC/B,KAAK,KAAK,YAAY,SAAS,4BAC5B,KAAK,KAAK,cACV,mBACA,MACA,KAAK,KAAK,YAAY,QACtB,KAAK,KAAK,YAAY,MACtB,KAAA,GACA,KAAK,KAAK,YAAY,MACtB;MAEJ,MAAM,mBAAmB,WAAW,aAAa;MAEjD,KAAK,aACJ,oBAAoB,SAAS,CAC5B,mBAAmB,kBAAkB,iBAAiB,CACtD,CAAC,CACF;MAED,KAAK,YACJ,yBACC,eACC,iBACC,WAAW,YAAY,EACvB,WAAW,eAAe,CAC1B,EACD;OACC;OACA,cAAc,UAAU;OACxB,WAAW,WAAW;OACtB,CACD,CACD,CACD;;KAEF,uBAAuB,MAAM;MAC5B,IAAI,KAAK,KAAK,aAAa,SAAS,uBAAuB;OAC1D,MAAM,cAAc,KAAK,KAAK,YAAY,aAAa,GAAG,EAAE;OAE5D,IACC,CAAC,eACD,YAAY,GAAG,SAAS,gBACxB,YAAY,IAAI,YAAY,GAAG,KAAK,EAEpC;OAED,MAAM,aAAa,YAAY,GAAG;OAClC,YAAY,IAAI,WAAW;OAE3B,MAAM,mBAAmB,WAAW,UAAU,aAAa;OAE3D,KAAK,aACJ,oBAAoB,SAAS,CAC5B,mBAAmB,kBAAkB,YAAY,KAAK,CACtD,CAAC,CACF;OAED,KAAK,YACJ,uBACC,oBAAoB,SAAS,CAC5B,mBACC,WAAW,WAAW,EACtB,eACC,iBACC,WAAW,YAAY,EACvB,WAAW,eAAe,CAC1B,EACD;QACC;QACA,cAAc,WAAW;QACzB,WAAW,WAAW;QACtB,CACD,CACD,CACD,CAAC,CACF,CACD;aACK,IAAI,KAAK,KAAK,aAAa,SAAS,uBAAuB;OACjE,MAAM,cAAc,KAAK,KAAK;OAE9B,IACC,CAAC,eACD,YAAY,IAAI,SAAS,gBACzB,YAAY,IAAI,YAAY,GAAG,KAAK,EAEpC;OAED,MAAM,aAAa,YAAY,GAAG;OAClC,YAAY,IAAI,WAAW;OAE3B,MAAM,mBAAmB,WAAW,UAAU,aAAa;OAE3D,KAAK,aACJ,oBACC,kBACA,YAAY,QACZ,YAAY,MACZ,YAAY,WACZ,YAAY,MACZ,CACD;OAED,KAAK,YACJ,uBACC,oBAAoB,SAAS,CAC5B,mBACC,WAAW,WAAW,EACtB,eACC,iBACC,WAAW,YAAY,EACvB,WAAW,eAAe,CAC1B,EACD;QACC;QACA,cAAc,WAAW;QACzB,WAAW,WAAW;QACtB,CACD,CACD,CACD,CAAC,CACF,CACD;;;KAGH,CAAC;IAEF,MAAM,SAAS,SAAS,IAAI;IAE5B,OAAO;KAAE,MAAM,OAAO;KAAM,KAAK,OAAO;KAAK;;GAE9C;EACD,EACD;EACC,MAAM;EACN,WAAW;GACV,OAAO;GACP,QAAQ,MAAM;IACb,IAAI,KAAK,SAAS,wBAAwB,EACzC,OAAO,KAAK,WAAW,yBAAyB,SAAS;;GAK3D;EACD,CACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pajecawav/yamf",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "Yet another meta framework",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/pajecawav/yamf#readme",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
"unhead": "^3.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@pajecawav/tools": "^0.0.
|
|
48
|
+
"@pajecawav/tools": "^0.0.3",
|
|
49
49
|
"@types/babel__generator": "^7.27.0",
|
|
50
50
|
"@types/babel__traverse": "^7.28.0",
|
|
51
51
|
"@types/node": "^24.12.3",
|
|
52
|
+
"@typescript/native-preview": "7.0.0-dev.20260510.1",
|
|
52
53
|
"@vitest/coverage-v8": "^4.1.5",
|
|
53
54
|
"@vitest/ui": "^4.1.5",
|
|
54
55
|
"cross-env": "^10.1.0",
|
|
@@ -60,7 +61,6 @@
|
|
|
60
61
|
"oxlint-tsgolint": "^0.22.1",
|
|
61
62
|
"publint": "^0.3.20",
|
|
62
63
|
"tsdown": "0.22.0",
|
|
63
|
-
"typescript": "^6.0.3",
|
|
64
64
|
"vite": "^8.0.11",
|
|
65
65
|
"vitest": "^4.1.5"
|
|
66
66
|
},
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"test:watch": "vitest watch",
|
|
72
72
|
"test:coverage": "vitest run --coverage",
|
|
73
73
|
"test:ui": "vitest --ui",
|
|
74
|
-
"lint": "run-p -l lint:*",
|
|
74
|
+
"lint": "cross-env FORCE_COLOR=1 run-p -l lint:*",
|
|
75
75
|
"lint:oxlint": "oxlint .",
|
|
76
|
-
"lint:tsc": "
|
|
76
|
+
"lint:tsc": "tsgo -b --noEmit",
|
|
77
77
|
"lint:format": "pt format --check",
|
|
78
78
|
"lint:package": "publint",
|
|
79
79
|
"format": "pt format"
|
package/src/context/ssr.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { type Context, createContext, useContext } from "hono/jsx";
|
|
2
2
|
import type { H3Event } from "nitro";
|
|
3
|
-
import type { EventHandlerRequest } from "nitro/h3";
|
|
4
3
|
import type { ServerUnhead } from "unhead/server";
|
|
5
4
|
|
|
6
5
|
interface SSRContextValue {
|
|
7
6
|
head: ServerUnhead;
|
|
8
|
-
event: H3Event
|
|
7
|
+
event: H3Event;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export const SSRContext: Context<SSRContextValue | null> = createContext<SSRContextValue | null>(
|
package/src/hooks/useEvent.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { H3Event } from "nitro";
|
|
2
|
-
import type { EventHandlerRequest } from "nitro/h3";
|
|
3
2
|
import { useSSRContext } from "#/context/ssr";
|
|
4
3
|
|
|
5
|
-
export const useEvent = (): H3Event
|
|
4
|
+
export const useEvent = (): H3Event => {
|
|
6
5
|
const ctx = useSSRContext();
|
|
7
6
|
|
|
8
7
|
if (!ctx) {
|
package/src/island/client.tsx
CHANGED
|
@@ -31,10 +31,10 @@ customElements.define(
|
|
|
31
31
|
"yamf-island",
|
|
32
32
|
class extends HTMLElement {
|
|
33
33
|
public connectedCallback() {
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
35
34
|
const islandProps = parse(this.getAttribute("island-props") ?? "{}");
|
|
36
35
|
const islandSrc = this.getAttribute("island-src");
|
|
37
36
|
const islandEntry = this.getAttribute("island-entry");
|
|
37
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
38
38
|
const islandClient = (this.getAttribute("island-client") ??
|
|
39
39
|
"load") as IslandClientDirective;
|
|
40
40
|
|
|
@@ -80,7 +80,7 @@ customElements.define(
|
|
|
80
80
|
case "skip":
|
|
81
81
|
break;
|
|
82
82
|
default:
|
|
83
|
-
//
|
|
83
|
+
// oxlint-disable-next-line typescript/restrict-template-expressions
|
|
84
84
|
throw new Error(`Invalid island-client value: ${islandClient}`);
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/island/server.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import type { ImportAssetsResultRaw } from "#/shared/assets";
|
|
|
4
4
|
import type { IslandClientDirective } from "./types";
|
|
5
5
|
|
|
6
6
|
declare module "hono/jsx" {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
7
|
namespace JSX {
|
|
9
8
|
interface IntrinsicElements {
|
|
10
9
|
"yamf-island": {
|
|
@@ -34,6 +33,7 @@ export const createIsland = (
|
|
|
34
33
|
island-props={stringify(props)}
|
|
35
34
|
island-src={assets.entry}
|
|
36
35
|
island-entry={exportName}
|
|
36
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
37
37
|
island-client={props["yamf-client"] as IslandClientDirective}
|
|
38
38
|
// TODO: export CSS?
|
|
39
39
|
style={{ display: "contents" }}
|
package/src/page.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { Child, FC, PropsWithChildren } from "hono/jsx";
|
|
|
2
2
|
import { Fragment } from "hono/jsx";
|
|
3
3
|
import { renderToReadableStream } from "hono/jsx/streaming";
|
|
4
4
|
import { Hono } from "hono/tiny";
|
|
5
|
-
import type {
|
|
5
|
+
import type { EventHandlerResponse, H3Event } from "nitro/h3";
|
|
6
6
|
import { HTTPResponse, withServerTiming } from "nitro/h3";
|
|
7
7
|
import type { Unhead } from "unhead/server";
|
|
8
8
|
import { transformHtmlTemplate } from "unhead/server";
|
|
@@ -14,7 +14,7 @@ import { SSRContext } from "./context/ssr";
|
|
|
14
14
|
import type { ImportAssetsResult } from "./shared/assets";
|
|
15
15
|
|
|
16
16
|
export type PageHandler = (
|
|
17
|
-
event: H3Event
|
|
17
|
+
event: H3Event,
|
|
18
18
|
params: {
|
|
19
19
|
serverAssets?: ImportAssetsResult;
|
|
20
20
|
head?: ResolvableHead;
|
|
@@ -23,7 +23,7 @@ export type PageHandler = (
|
|
|
23
23
|
) => EventHandlerResponse;
|
|
24
24
|
|
|
25
25
|
export type PageRenderer = (
|
|
26
|
-
event: H3Event
|
|
26
|
+
event: H3Event,
|
|
27
27
|
params: { head: Unhead },
|
|
28
28
|
) => HTTPResponse | Promise<HTTPResponse> | Child | Promise<Child>;
|
|
29
29
|
|
package/src/server/entry.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { addRoute, createRouter, findRoute } from "rou3";
|
|
|
6
6
|
import { withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
7
7
|
import type { ResolvableHead } from "unhead/types";
|
|
8
8
|
import { clientAssets } from "virtual:yamf:assets";
|
|
9
|
-
import { pages, assets as
|
|
9
|
+
import { pages, assets as pagesServerAssets } from "virtual:yamf:pages";
|
|
10
10
|
import type { PageHandler } from "#/page";
|
|
11
11
|
|
|
12
12
|
interface Route {
|
|
@@ -40,15 +40,16 @@ for (const [relativePath, handler] of Object.entries(pages).toSorted((a, b) =>
|
|
|
40
40
|
|
|
41
41
|
addRoute(router, "GET", route, {
|
|
42
42
|
handler,
|
|
43
|
-
serverAssets:
|
|
43
|
+
serverAssets: pagesServerAssets[relativePath],
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export type ServerEntry = EventHandlerWithFetch<EventHandlerRequest, Promise<unknown>>;
|
|
48
48
|
|
|
49
49
|
export interface DefineServerEntryOptions {
|
|
50
|
-
head?: ResolvableHead | ((event: H3Event
|
|
50
|
+
head?: ResolvableHead | ((event: H3Event) => ResolvableHead);
|
|
51
51
|
Layout?: FC<PropsWithChildren>;
|
|
52
|
+
disableEarlyHints?: boolean;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEntry => {
|
|
@@ -64,12 +65,16 @@ export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEnt
|
|
|
64
65
|
|
|
65
66
|
const assets = serverAssets ? serverAssets.merge(clientAssets) : clientAssets;
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
link
|
|
68
|
+
if (!options?.disableEarlyHints) {
|
|
69
|
+
const link = [
|
|
69
70
|
...assets.js.map(script => `<${script.href}>; rel=modulepreload`),
|
|
70
71
|
...assets.css.map(style => `<${style.href}>; rel=preload; as=style`),
|
|
71
|
-
]
|
|
72
|
-
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
if (link.length) {
|
|
75
|
+
await writeEarlyHints(event, { link });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
73
78
|
|
|
74
79
|
return (await handler())(event, {
|
|
75
80
|
serverAssets,
|
package/src/virtual.d.ts
CHANGED
package/src/vite/islands.ts
CHANGED
|
@@ -19,8 +19,8 @@ import {
|
|
|
19
19
|
} from "@babel/types";
|
|
20
20
|
import type { Plugin } from "vite";
|
|
21
21
|
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
22
|
// @ts-ignore
|
|
23
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
24
24
|
const traverse = (_traverse.default as typeof _traverse) ?? _traverse;
|
|
25
25
|
|
|
26
26
|
const ISLAND_REGEX = /\.island\.(j|t)sx?$/;
|