@pajecawav/yamf 0.0.3 → 0.0.5
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 +262 -0
- package/dist/components/Head.d.ts +0 -1
- package/dist/components/Head.d.ts.map +1 -1
- package/dist/components/Head.js.map +1 -1
- package/dist/context/ssr.d.ts +1 -1
- package/dist/context/ssr.d.ts.map +1 -1
- package/dist/context/ssr.js.map +1 -1
- package/dist/hooks/useEvent.d.ts +0 -1
- package/dist/hooks/useEvent.d.ts.map +1 -1
- package/dist/hooks/useEvent.js.map +1 -1
- package/dist/hooks/useHead.d.ts +3 -3
- package/dist/hooks/useHead.d.ts.map +1 -1
- package/dist/hooks/useHead.js +8 -2
- package/dist/hooks/useHead.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/island/client.js +2 -0
- package/dist/island/client.js.map +1 -1
- package/dist/island/types.d.ts +1 -1
- package/dist/island/types.d.ts.map +1 -1
- package/dist/page.d.ts +8 -9
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +11 -5
- package/dist/page.js.map +1 -1
- package/dist/server/entry.d.mts +2 -5
- package/dist/server/entry.d.mts.map +1 -1
- package/dist/server/entry.mjs +4 -4
- package/dist/server/entry.mjs.map +1 -1
- package/dist/server/island/server.d.mts +0 -1
- package/dist/server/island/server.d.mts.map +1 -1
- package/dist/server/island/server.mjs.map +1 -1
- package/dist/server/island/types.d.mts +1 -1
- package/dist/server/island/types.d.mts.map +1 -1
- package/dist/server/shared/assets.d.mts.map +1 -1
- package/dist/server/shared/head.d.mts +8 -0
- package/dist/server/shared/head.d.mts.map +1 -0
- package/dist/shared/assets.d.ts.map +1 -1
- package/dist/shared/head.d.ts +8 -0
- package/dist/shared/head.d.ts.map +1 -0
- package/dist/vite/index.d.mts +0 -1
- package/dist/vite/index.d.mts.map +1 -1
- package/dist/vite/index.mjs +2 -0
- package/dist/vite/index.mjs.map +1 -1
- package/dist/vite/islands.mjs.map +1 -1
- package/dist/vite/shared/utils.mjs.map +1 -1
- package/dist/vite/virtual-assets.mjs +2 -2
- package/dist/vite/virtual-assets.mjs.map +1 -1
- package/dist/vite/virtual-pages.mjs +4 -3
- package/dist/vite/virtual-pages.mjs.map +1 -1
- package/dist/vite/virtual-root.mjs +46 -0
- package/dist/vite/virtual-root.mjs.map +1 -0
- package/dist/vite/virtual-template.mjs +1 -1
- package/dist/vite/virtual-template.mjs.map +1 -1
- package/package.json +30 -26
- package/src/hooks/useHead.tsx +14 -2
- package/src/index.ts +2 -1
- package/src/island/client.tsx +3 -0
- package/src/island/types.ts +1 -1
- package/src/page.tsx +19 -15
- package/src/server/entry.tsx +5 -7
- package/src/shared/head.ts +3 -0
- package/src/virtual.d.ts +7 -0
- package/src/vite/index.ts +2 -0
- package/src/vite/virtual-assets.ts +1 -1
- package/src/vite/virtual-pages.ts +3 -2
- package/src/vite/virtual-root.ts +48 -0
|
@@ -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;cACC;MACT;QACC;QACA;QACA;QACA,iBAAiB;QACjB,UAAU;QACV,QAAQ,IAAI;;;;;cAMH,eACZ,WAAW,IACX,oBACA,QAAQ,0BACN"}
|
|
@@ -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\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,
|
|
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,MAAM;EAGpE,OACC,oBAAC,eAAD;GACC,gBAAc,UAAU,KAAK;GAC7B,cAAY,OAAO;GACnB,gBAAc;GAEd,iBAAe,MAAM;GAErB,OAAO,EAAE,SAAS,WAAW;aAE7B,oBAAC,WAAD,EAAW,GAAI,MAAQ,CAAA;EACX,CAAA;CAEf;CAEA,OAAO,eAAe,kBAAkB,QAAQ,EAC/C,OAAO,UAAU,KAClB,CAAC;CAED,OAAO;AACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/island/types.ts"],"mappings":";KAAY
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/island/types.ts"],"mappings":";KAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.mts","names":[],"sources":["../../../src/shared/assets.ts"],"mappings":";KAKY
|
|
1
|
+
{"version":3,"file":"assets.d.mts","names":[],"sources":["../../../src/shared/assets.ts"],"mappings":";KAKY;EACX;EACA;IAAM;;EACN;IAAO;IAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head.d.mts","names":[],"sources":["../../../src/shared/head.ts"],"mappings":";;KAEY,WAAW;EAAmB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","names":[],"sources":["../../src/shared/assets.ts"],"mappings":";KACY,
|
|
1
|
+
{"version":3,"file":"assets.d.ts","names":[],"sources":["../../src/shared/assets.ts"],"mappings":";KACY,qBAAqB;EAChC,SAAS,MAAM,0BAA0B;;KAG9B;EACX;EACA;IAAM;;EACN;IAAO;IAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head.d.ts","names":[],"sources":["../../src/shared/head.ts"],"mappings":";;KAEY,WAAW;EAAmB,MAAM"}
|
package/dist/vite/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/vite/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/vite/index.ts"],"mappings":";;;UAUiB;EAChB,QAAQ;;cAGH,OAAQ,UAAU,gBAAc"}
|
package/dist/vite/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { islands } from "./islands.mjs";
|
|
2
2
|
import { virtualAssets } from "./virtual-assets.mjs";
|
|
3
3
|
import { virtualPages } from "./virtual-pages.mjs";
|
|
4
|
+
import { virtualRoot } from "./virtual-root.mjs";
|
|
4
5
|
import { virtualTemplate } from "./virtual-template.mjs";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { nitro } from "nitro/vite";
|
|
@@ -33,6 +34,7 @@ const yamf = (options) => {
|
|
|
33
34
|
plugins.push(virtualAssets());
|
|
34
35
|
plugins.push(virtualPages());
|
|
35
36
|
plugins.push(virtualTemplate());
|
|
37
|
+
plugins.push(virtualRoot());
|
|
36
38
|
plugins.push(nitro({
|
|
37
39
|
serverDir: "./src",
|
|
38
40
|
renderer: false,
|
package/dist/vite/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport type { NitroPluginConfig } from \"nitro/vite\";\nimport { nitro } from \"nitro/vite\";\nimport type { EnvironmentOptions, PluginOption } from \"vite\";\nimport { islands } from \"./islands\";\nimport { virtualAssets } from \"./virtual-assets\";\nimport { virtualPages } from \"./virtual-pages\";\nimport { virtualTemplate } from \"./virtual-template\";\n\nexport interface YamfOptions {\n\tnitro?: NitroPluginConfig;\n}\n\nconst yamf = (options?: YamfOptions): PluginOption[] => {\n\tconst plugins: PluginOption[] = [];\n\n\t// TODO: extendable config\n\tplugins.push({\n\t\tname: \"yamf:config\",\n\t\tconfig() {\n\t\t\tconst ssrEnv: EnvironmentOptions = {\n\t\t\t\tbuild: {\n\t\t\t\t\t// TODO: figure out if this should be true\n\t\t\t\t\tcssCodeSplit: false,\n\t\t\t\t\trolldownOptions: {\n\t\t\t\t\t\tinput: \"./src/server.tsx\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tssr: {\n\t\t\t\t\t// we need to inline because otherwise fullstack plugin fails to build manifest for assets imports\n\t\t\t\t\tnoExternal: [\"@pajecawav/yamf\"],\n\t\t\t\t},\n\t\t\t\toptimizeDeps: {\n\t\t\t\t\tinclude: [\n\t\t\t\t\t\t\"hono\",\n\t\t\t\t\t\t\"hono/jsx/dom/client\",\n\t\t\t\t\t\t\"hono/jsx/jsx-runtime\",\n\t\t\t\t\t\t\"devalue\",\n\t\t\t\t\t\t\"ufo\",\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tenvironments: {\n\t\t\t\t\t...(existsSync(\"./src/server.tsx\") ? { ssr: ssrEnv } : {}),\n\t\t\t\t\tclient: {\n\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\trolldownOptions: {\n\t\t\t\t\t\t\t\tinput: \"./src/client/index.ts\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tplugins.push(islands());\n\n\tplugins.push(virtualAssets());\n\tplugins.push(virtualPages());\n\tplugins.push(virtualTemplate());\n\n\tplugins.push(\n\t\tnitro({\n\t\t\tserverDir: \"./src\",\n\t\t\trenderer: false,\n\t\t\t...options?.nitro,\n\t\t\tcompressPublicAssets: {\n\t\t\t\tgzip: true,\n\t\t\t\tbrotli: true,\n\t\t\t},\n\t\t\tpublicAssets: [\n\t\t\t\t{\n\t\t\t\t\tbaseURL: \"assets\",\n\t\t\t\t\tdir: \"./public/assets\",\n\t\t\t\t\tmaxAge: 365 * 24 * 60 * 60,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t);\n\n\treturn plugins;\n};\n\nexport default yamf;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport type { NitroPluginConfig } from \"nitro/vite\";\nimport { nitro } from \"nitro/vite\";\nimport type { EnvironmentOptions, PluginOption } from \"vite\";\nimport { islands } from \"./islands\";\nimport { virtualAssets } from \"./virtual-assets\";\nimport { virtualPages } from \"./virtual-pages\";\nimport { virtualRoot } from \"./virtual-root\";\nimport { virtualTemplate } from \"./virtual-template\";\n\nexport interface YamfOptions {\n\tnitro?: NitroPluginConfig;\n}\n\nconst yamf = (options?: YamfOptions): PluginOption[] => {\n\tconst plugins: PluginOption[] = [];\n\n\t// TODO: extendable config\n\tplugins.push({\n\t\tname: \"yamf:config\",\n\t\tconfig() {\n\t\t\tconst ssrEnv: EnvironmentOptions = {\n\t\t\t\tbuild: {\n\t\t\t\t\t// TODO: figure out if this should be true\n\t\t\t\t\tcssCodeSplit: false,\n\t\t\t\t\trolldownOptions: {\n\t\t\t\t\t\tinput: \"./src/server.tsx\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tssr: {\n\t\t\t\t\t// we need to inline because otherwise fullstack plugin fails to build manifest for assets imports\n\t\t\t\t\tnoExternal: [\"@pajecawav/yamf\"],\n\t\t\t\t},\n\t\t\t\toptimizeDeps: {\n\t\t\t\t\tinclude: [\n\t\t\t\t\t\t\"hono\",\n\t\t\t\t\t\t\"hono/jsx/dom/client\",\n\t\t\t\t\t\t\"hono/jsx/jsx-runtime\",\n\t\t\t\t\t\t\"devalue\",\n\t\t\t\t\t\t\"ufo\",\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tenvironments: {\n\t\t\t\t\t...(existsSync(\"./src/server.tsx\") ? { ssr: ssrEnv } : {}),\n\t\t\t\t\tclient: {\n\t\t\t\t\t\tbuild: {\n\t\t\t\t\t\t\trolldownOptions: {\n\t\t\t\t\t\t\t\tinput: \"./src/client/index.ts\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tplugins.push(islands());\n\n\tplugins.push(virtualAssets());\n\tplugins.push(virtualPages());\n\tplugins.push(virtualTemplate());\n\tplugins.push(virtualRoot());\n\n\tplugins.push(\n\t\tnitro({\n\t\t\tserverDir: \"./src\",\n\t\t\trenderer: false,\n\t\t\t...options?.nitro,\n\t\t\tcompressPublicAssets: {\n\t\t\t\tgzip: true,\n\t\t\t\tbrotli: true,\n\t\t\t},\n\t\t\tpublicAssets: [\n\t\t\t\t{\n\t\t\t\t\tbaseURL: \"assets\",\n\t\t\t\t\tdir: \"./public/assets\",\n\t\t\t\t\tmaxAge: 365 * 24 * 60 * 60,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t);\n\n\treturn plugins;\n};\n\nexport default yamf;\n"],"mappings":";;;;;;;;AAcA,MAAM,QAAQ,YAA0C;CACvD,MAAM,UAA0B,CAAC;CAGjC,QAAQ,KAAK;EACZ,MAAM;EACN,SAAS;GAWR,OAAO;IACN,KAAK,EAEJ,YAAY,CAAC,iBAAiB,EAC/B;IACA,cAAc,EACb,SAAS;KACR;KACA;KACA;KACA;KACA;IACD,EACD;IACA,cAAc;KACb,GAAI,WAAW,kBAAkB,IAAI,EAAE,KAAK,EAxB7C,OAAO;MAEN,cAAc;MACd,iBAAiB,EAChB,OAAO,mBACR;KACD,EAkBkD,EAAE,IAAI,CAAC;KACxD,QAAQ,EACP,OAAO,EACN,iBAAiB,EAChB,OAAO,wBACR,EACD,EACD;IACD;GACD;EACD;CACD,CAAC;CAED,QAAQ,KAAK,QAAQ,CAAC;CAEtB,QAAQ,KAAK,cAAc,CAAC;CAC5B,QAAQ,KAAK,aAAa,CAAC;CAC3B,QAAQ,KAAK,gBAAgB,CAAC;CAC9B,QAAQ,KAAK,YAAY,CAAC;CAE1B,QAAQ,KACP,MAAM;EACL,WAAW;EACX,UAAU;EACV,GAAG,SAAS;EACZ,sBAAsB;GACrB,MAAM;GACN,QAAQ;EACT;EACA,cAAc,CACb;GACC,SAAS;GACT,KAAK;GACL,QAAQ,MAAM,KAAK,KAAK;EACzB,CACD;CACD,CAAC,CACF;CAEA,OAAO;AACR"}
|
|
@@ -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// @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":"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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":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/shared/utils.ts"],"sourcesContent":["export const js = (str: TemplateStringsArray, ...args: unknown[]): string => {\n\treturn str.reduce((acc, cur, i) => {\n\t\treturn acc + cur + String(args[i]);\n\t}, \"\");\n};\n"],"mappings":";AAAA,MAAa,MAAM,KAA2B,GAAG,SAA4B;CAC5E,OAAO,IAAI,QAAQ,KAAK,KAAK,MAAM;EAClC,OAAO,MAAM,MAAM,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/shared/utils.ts"],"sourcesContent":["export const js = (str: TemplateStringsArray, ...args: unknown[]): string => {\n\treturn str.reduce((acc, cur, i) => {\n\t\treturn acc + cur + String(args[i]);\n\t}, \"\");\n};\n"],"mappings":";AAAA,MAAa,MAAM,KAA2B,GAAG,SAA4B;CAC5E,OAAO,IAAI,QAAQ,KAAK,KAAK,MAAM;EAClC,OAAO,MAAM,MAAM,OAAO,KAAK,EAAE;CAClC,GAAG,EAAE;AACN"}
|
|
@@ -2,7 +2,7 @@ import { js } from "./shared/utils.mjs";
|
|
|
2
2
|
//#region src/vite/virtual-assets.ts
|
|
3
3
|
const virtualAssets = () => {
|
|
4
4
|
const virtualModuleId = "virtual:yamf:assets";
|
|
5
|
-
const resolvedVirtualModuleId = "\
|
|
5
|
+
const resolvedVirtualModuleId = "\0virtual:yamf:assets";
|
|
6
6
|
return {
|
|
7
7
|
name: "yamf:virtual-assets",
|
|
8
8
|
resolveId(id) {
|
|
@@ -11,7 +11,7 @@ const virtualAssets = () => {
|
|
|
11
11
|
load(id) {
|
|
12
12
|
if (id !== resolvedVirtualModuleId) return;
|
|
13
13
|
return js`
|
|
14
|
-
import clientAssets from "./src/client
|
|
14
|
+
import clientAssets from "./src/client?assets=client";
|
|
15
15
|
|
|
16
16
|
export { clientAssets };
|
|
17
17
|
`.trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-assets.mjs","names":[],"sources":["../../src/vite/virtual-assets.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nexport const virtualAssets = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:assets\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-assets\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn js`\nimport clientAssets from \"./src/client
|
|
1
|
+
{"version":3,"file":"virtual-assets.mjs","names":[],"sources":["../../src/vite/virtual-assets.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nexport const virtualAssets = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:assets\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-assets\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn js`\nimport clientAssets from \"./src/client?assets=client\";\n\nexport { clientAssets };\n`.trim();\n\t\t},\n\t};\n};\n"],"mappings":";;AAGA,MAAa,sBAA8B;CAC1C,MAAM,kBAAkB;CACxB,MAAM,0BAA0B;CAEhC,OAAO;EACN,MAAM;EACN,UAAU,IAAI;GACb,IAAI,OAAO,iBACV,OAAO;EAIT;EACA,KAAK,IAAI;GACR,IAAI,OAAO,yBACV;GAGD,OAAO,EAAE;;;;EAIV,KAAK;EACL;CACD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { js } from "./shared/utils.mjs";
|
|
|
2
2
|
//#region src/vite/virtual-pages.ts
|
|
3
3
|
const virtualPages = () => {
|
|
4
4
|
const virtualModuleId = "virtual:yamf:pages";
|
|
5
|
-
const resolvedVirtualModuleId = "\
|
|
5
|
+
const resolvedVirtualModuleId = "\0virtual:yamf:pages";
|
|
6
6
|
return {
|
|
7
7
|
name: "yamf:virtual-pages",
|
|
8
8
|
resolveId(id) {
|
|
@@ -11,11 +11,12 @@ const virtualPages = () => {
|
|
|
11
11
|
load(id) {
|
|
12
12
|
if (id !== resolvedVirtualModuleId) return;
|
|
13
13
|
return js`
|
|
14
|
-
const pages = import.meta.glob("/src/pages/**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}", {
|
|
14
|
+
const pages = import.meta.glob("/src/pages/**/*.page.{js,mjs,cjs,ts,mts,cts,tsx,jsx}", {
|
|
15
15
|
import: "default",
|
|
16
16
|
});
|
|
17
|
+
|
|
17
18
|
const assets = import.meta.glob(
|
|
18
|
-
"/src/pages/**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}",
|
|
19
|
+
"/src/pages/**/*.page.{js,mjs,cjs,ts,mts,cts,tsx,jsx}",
|
|
19
20
|
{
|
|
20
21
|
import: "default",
|
|
21
22
|
query: "?assets=ssr",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-pages.mjs","names":[],"sources":["../../src/vite/virtual-pages.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nexport const virtualPages = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:pages\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-pages\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn js`\nconst pages = import.meta.glob(\"/src/pages/**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}\", {\n\timport: \"default\",\n});\nconst assets = import.meta.glob(\n\t\"/src/pages/**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}\",\n\t{\n\t\timport: \"default\",\n\t\tquery: \"?assets=ssr\",\n\t\teager: true,\n\t},\n);\n\nexport { pages, assets };\n`.trim();\n\t\t},\n\t};\n};\n"],"mappings":";;AAGA,MAAa,qBAA6B;CACzC,MAAM,kBAAkB;CACxB,MAAM,0BAA0B
|
|
1
|
+
{"version":3,"file":"virtual-pages.mjs","names":[],"sources":["../../src/vite/virtual-pages.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nexport const virtualPages = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:pages\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-pages\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn js`\nconst pages = import.meta.glob(\"/src/pages/**/*.page.{js,mjs,cjs,ts,mts,cts,tsx,jsx}\", {\n\timport: \"default\",\n});\n\nconst assets = import.meta.glob(\n\t\"/src/pages/**/*.page.{js,mjs,cjs,ts,mts,cts,tsx,jsx}\",\n\t{\n\t\timport: \"default\",\n\t\tquery: \"?assets=ssr\",\n\t\teager: true,\n\t},\n);\n\nexport { pages, assets };\n`.trim();\n\t\t},\n\t};\n};\n"],"mappings":";;AAGA,MAAa,qBAA6B;CACzC,MAAM,kBAAkB;CACxB,MAAM,0BAA0B;CAEhC,OAAO;EACN,MAAM;EACN,UAAU,IAAI;GACb,IAAI,OAAO,iBACV,OAAO;EAIT;EACA,KAAK,IAAI;GACR,IAAI,OAAO,yBACV;GAGD,OAAO,EAAE;;;;;;;;;;;;;;;EAeV,KAAK;EACL;CACD;AACD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { js } from "./shared/utils.mjs";
|
|
2
|
+
import { resolveModulePath } from "exsolve";
|
|
3
|
+
//#region src/vite/virtual-root.ts
|
|
4
|
+
const ROOT_PATH = "./src/root";
|
|
5
|
+
const virtualRoot = () => {
|
|
6
|
+
const virtualModuleId = "virtual:yamf:root";
|
|
7
|
+
const resolvedVirtualModuleId = "\0virtual:yamf:root";
|
|
8
|
+
return {
|
|
9
|
+
name: "yamf:virtual-root",
|
|
10
|
+
resolveId(id) {
|
|
11
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
12
|
+
},
|
|
13
|
+
load(id) {
|
|
14
|
+
if (id !== resolvedVirtualModuleId) return;
|
|
15
|
+
if (!resolveModulePath(ROOT_PATH, {
|
|
16
|
+
try: true,
|
|
17
|
+
suffixes: ["", "/index"],
|
|
18
|
+
extensions: [
|
|
19
|
+
".tsx",
|
|
20
|
+
".jsx",
|
|
21
|
+
".ts",
|
|
22
|
+
".js",
|
|
23
|
+
".mjs",
|
|
24
|
+
".cjs",
|
|
25
|
+
".mts",
|
|
26
|
+
".cts"
|
|
27
|
+
]
|
|
28
|
+
})) return js`
|
|
29
|
+
const Root = null;
|
|
30
|
+
const rootAssets = null;
|
|
31
|
+
|
|
32
|
+
export { Root, rootAssets };
|
|
33
|
+
`;
|
|
34
|
+
return js`
|
|
35
|
+
import Root from "${ROOT_PATH}";
|
|
36
|
+
import rootAssets from "${ROOT_PATH}?assets=ssr";
|
|
37
|
+
|
|
38
|
+
export { Root, rootAssets };
|
|
39
|
+
`.trim();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { virtualRoot };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=virtual-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-root.mjs","names":[],"sources":["../../src/vite/virtual-root.ts"],"sourcesContent":["import { resolveModulePath } from \"exsolve\";\nimport type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nconst ROOT_PATH = \"./src/root\";\n\nexport const virtualRoot = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:root\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-root\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst root = resolveModulePath(ROOT_PATH, {\n\t\t\t\ttry: true,\n\t\t\t\tsuffixes: [\"\", \"/index\"],\n\t\t\t\textensions: [\".tsx\", \".jsx\", \".ts\", \".js\", \".mjs\", \".cjs\", \".mts\", \".cts\"],\n\t\t\t});\n\n\t\t\tif (!root) {\n\t\t\t\treturn js`\nconst Root = null;\nconst rootAssets = null;\n\nexport { Root, rootAssets };\n `;\n\t\t\t}\n\n\t\t\treturn js`\nimport Root from \"${ROOT_PATH}\";\nimport rootAssets from \"${ROOT_PATH}?assets=ssr\";\n\nexport { Root, rootAssets };\n`.trim();\n\t\t},\n\t};\n};\n"],"mappings":";;;AAIA,MAAM,YAAY;AAElB,MAAa,oBAA4B;CACxC,MAAM,kBAAkB;CACxB,MAAM,0BAA0B;CAEhC,OAAO;EACN,MAAM;EACN,UAAU,IAAI;GACb,IAAI,OAAO,iBACV,OAAO;EAIT;EACA,KAAK,IAAI;GACR,IAAI,OAAO,yBACV;GASD,IAAI,CANS,kBAAkB,WAAW;IACzC,KAAK;IACL,UAAU,CAAC,IAAI,QAAQ;IACvB,YAAY;KAAC;KAAQ;KAAQ;KAAO;KAAO;KAAQ;KAAQ;KAAQ;IAAM;GAC1E,CAEQ,GACP,OAAO,EAAE;;;;;;GAQV,OAAO,EAAE;oBACQ,UAAU;0BACJ,UAAU;;;EAGlC,KAAK;EACL;CACD;AACD"}
|
|
@@ -14,7 +14,7 @@ const DEFAULT_TEMPLATE = `
|
|
|
14
14
|
`.trim();
|
|
15
15
|
const virtualTemplate = () => {
|
|
16
16
|
const virtualModuleId = "virtual:yamf:template";
|
|
17
|
-
const resolvedVirtualModuleId = "\
|
|
17
|
+
const resolvedVirtualModuleId = "\0virtual:yamf:template";
|
|
18
18
|
return {
|
|
19
19
|
name: "yamf:virtual-template",
|
|
20
20
|
resolveId(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-template.mjs","names":[],"sources":["../../src/vite/virtual-template.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { relative } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nconst TEMPLATE_PATH = \"./src/template.html\";\n\nconst DEFAULT_TEMPLATE = /* html */ `\n<!DOCTYPE html>\n<html>\n <head></head>\n <body>\n <!--ssr-outlet-->\n </body>\n</html>\n`.trim();\n\nexport const virtualTemplate = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:template\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-template\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tasync load(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst template = await readFile(TEMPLATE_PATH, \"utf8\");\n\n\t\t\t\treturn js`export const template = ${JSON.stringify(template)};`;\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\treturn js`export const template = ${JSON.stringify(DEFAULT_TEMPLATE)};`;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\thandleHotUpdate({ file, server }) {\n\t\t\tif (relative(file, TEMPLATE_PATH) === \"\") {\n\t\t\t\tconst mod = server.moduleGraph.getModuleById(resolvedVirtualModuleId);\n\n\t\t\t\tif (mod) {\n\t\t\t\t\tserver.moduleGraph.invalidateModule(mod);\n\t\t\t\t}\n\n\t\t\t\t// TODO: should reload?\n\t\t\t\t// server.ws.send({ type: \"full-reload\" });\n\t\t\t}\n\t\t},\n\t};\n};\n"],"mappings":";;;;AAKA,MAAM,gBAAgB;AAEtB,MAAM,mBAA8B;;;;;;;;EAQlC,
|
|
1
|
+
{"version":3,"file":"virtual-template.mjs","names":[],"sources":["../../src/vite/virtual-template.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { relative } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nconst TEMPLATE_PATH = \"./src/template.html\";\n\nconst DEFAULT_TEMPLATE = /* html */ `\n<!DOCTYPE html>\n<html>\n <head></head>\n <body>\n <!--ssr-outlet-->\n </body>\n</html>\n`.trim();\n\nexport const virtualTemplate = (): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:template\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-template\",\n\t\tresolveId(id) {\n\t\t\tif (id === virtualModuleId) {\n\t\t\t\treturn resolvedVirtualModuleId;\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tasync load(id) {\n\t\t\tif (id !== resolvedVirtualModuleId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst template = await readFile(TEMPLATE_PATH, \"utf8\");\n\n\t\t\t\treturn js`export const template = ${JSON.stringify(template)};`;\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n\t\t\t\t\treturn js`export const template = ${JSON.stringify(DEFAULT_TEMPLATE)};`;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\thandleHotUpdate({ file, server }) {\n\t\t\tif (relative(file, TEMPLATE_PATH) === \"\") {\n\t\t\t\tconst mod = server.moduleGraph.getModuleById(resolvedVirtualModuleId);\n\n\t\t\t\tif (mod) {\n\t\t\t\t\tserver.moduleGraph.invalidateModule(mod);\n\t\t\t\t}\n\n\t\t\t\t// TODO: should reload?\n\t\t\t\t// server.ws.send({ type: \"full-reload\" });\n\t\t\t}\n\t\t},\n\t};\n};\n"],"mappings":";;;;AAKA,MAAM,gBAAgB;AAEtB,MAAM,mBAA8B;;;;;;;;EAQlC,KAAK;AAEP,MAAa,wBAAgC;CAC5C,MAAM,kBAAkB;CACxB,MAAM,0BAA0B;CAEhC,OAAO;EACN,MAAM;EACN,UAAU,IAAI;GACb,IAAI,OAAO,iBACV,OAAO;EAIT;EACA,MAAM,KAAK,IAAI;GACd,IAAI,OAAO,yBACV;GAGD,IAAI;IACH,MAAM,WAAW,MAAM,SAAS,eAAe,MAAM;IAErD,OAAO,EAAE,2BAA2B,KAAK,UAAU,QAAQ,EAAE;GAC9D,SAAS,OAAO;IACf,IAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,UAC/D,OAAO,EAAE,2BAA2B,KAAK,UAAU,gBAAgB,EAAE;IAGtE,MAAM;GACP;EACD;EACA,gBAAgB,EAAE,MAAM,UAAU;GACjC,IAAI,SAAS,MAAM,aAAa,MAAM,IAAI;IACzC,MAAM,MAAM,OAAO,YAAY,cAAc,uBAAuB;IAEpE,IAAI,KACH,OAAO,YAAY,iBAAiB,GAAG;GAKzC;EACD;CACD;AACD"}
|
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.5",
|
|
5
5
|
"description": "Yet another meta framework",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/pajecawav/yamf#readme",
|
|
@@ -30,50 +30,54 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"hono": "^4.12.
|
|
34
|
-
"vite": "^8.0.
|
|
33
|
+
"hono": "^4.12.23",
|
|
34
|
+
"vite": "^8.0.16"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@babel/generator": "^7.29.
|
|
38
|
-
"@babel/parser": "^7.29.
|
|
39
|
-
"@babel/traverse": "^7.29.
|
|
40
|
-
"@babel/types": "^7.29.
|
|
41
|
-
"devalue": "^5.8.
|
|
42
|
-
"
|
|
43
|
-
"
|
|
37
|
+
"@babel/generator": "^7.29.7",
|
|
38
|
+
"@babel/parser": "^7.29.7",
|
|
39
|
+
"@babel/traverse": "^7.29.7",
|
|
40
|
+
"@babel/types": "^7.29.7",
|
|
41
|
+
"devalue": "^5.8.1",
|
|
42
|
+
"exsolve": "^1.1.0",
|
|
43
|
+
"nitro": "3.0.260610-beta",
|
|
44
|
+
"rou3": "^0.9.1",
|
|
44
45
|
"ufo": "^1.6.4",
|
|
45
|
-
"unhead": "^3.1.
|
|
46
|
+
"unhead": "^3.1.7"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@pajecawav/tools": "^0.0.
|
|
49
|
+
"@pajecawav/tools": "^0.0.5",
|
|
49
50
|
"@types/babel__generator": "^7.27.0",
|
|
50
51
|
"@types/babel__traverse": "^7.28.0",
|
|
51
|
-
"@types/node": "^24.
|
|
52
|
-
"@
|
|
53
|
-
"@vitest/
|
|
54
|
-
"@vitest/ui": "^4.1.5",
|
|
52
|
+
"@types/node": "^24.13.3",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
54
|
+
"@vitest/ui": "^4.1.10",
|
|
55
55
|
"cross-env": "^10.1.0",
|
|
56
|
-
"hono": "^4.12.
|
|
56
|
+
"hono": "^4.12.29",
|
|
57
57
|
"husky": "^9.1.7",
|
|
58
|
-
"npm-run-all2": "^
|
|
59
|
-
"oxfmt": "^0.
|
|
60
|
-
"oxlint": "^1.
|
|
61
|
-
"oxlint-tsgolint": "^0.
|
|
62
|
-
"publint": "^0.3.
|
|
63
|
-
"tsdown": "0.22.
|
|
64
|
-
"
|
|
65
|
-
"
|
|
58
|
+
"npm-run-all2": "^9.0.2",
|
|
59
|
+
"oxfmt": "^0.58.0",
|
|
60
|
+
"oxlint": "^1.73.0",
|
|
61
|
+
"oxlint-tsgolint": "^0.24.0",
|
|
62
|
+
"publint": "^0.3.21",
|
|
63
|
+
"tsdown": "0.22.4",
|
|
64
|
+
"typescript": "~7.0.2",
|
|
65
|
+
"vite": "^8.0.16",
|
|
66
|
+
"vitest": "^4.1.10"
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
68
69
|
"build": "tsdown",
|
|
69
70
|
"dev": "tsdown --watch",
|
|
71
|
+
"play": "pnpm --filter=playground dev",
|
|
72
|
+
"play:build": "pnpm --filter=playground build",
|
|
73
|
+
"play:preview": "pnpm --filter=playground preview",
|
|
70
74
|
"test": "vitest run --passWithNoTests",
|
|
71
75
|
"test:watch": "vitest watch",
|
|
72
76
|
"test:coverage": "vitest run --coverage",
|
|
73
77
|
"test:ui": "vitest --ui",
|
|
74
78
|
"lint": "cross-env FORCE_COLOR=1 run-p -l lint:*",
|
|
75
79
|
"lint:oxlint": "oxlint .",
|
|
76
|
-
"lint:tsc": "
|
|
80
|
+
"lint:tsc": "tsc -b --noEmit",
|
|
77
81
|
"lint:format": "pt format --check",
|
|
78
82
|
"lint:package": "publint",
|
|
79
83
|
"format": "pt format"
|
package/src/hooks/useHead.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useHead as _useHead } from "unhead";
|
|
1
|
+
import { useHead as _useHead, useSeoMeta as _useSeoMeta } from "unhead";
|
|
2
2
|
import type { ClientUnhead } from "unhead/client";
|
|
3
3
|
import { createHead } from "unhead/client";
|
|
4
|
-
import type { ResolvableHead } from "unhead/types";
|
|
4
|
+
import type { ResolvableHead, UseSeoMetaInput } from "unhead/types";
|
|
5
5
|
import { useSSRContext } from "#/context/ssr";
|
|
6
6
|
|
|
7
7
|
declare global {
|
|
@@ -25,3 +25,15 @@ export const useHead = (input?: ResolvableHead): void => {
|
|
|
25
25
|
_useHead(window.__UNHEAD__, input);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const useSeoMeta = (input?: UseSeoMetaInput): void => {
|
|
30
|
+
if (import.meta.env.SSR) {
|
|
31
|
+
const ctx = useSSRContext();
|
|
32
|
+
|
|
33
|
+
if (ctx?.head) {
|
|
34
|
+
_useSeoMeta(ctx.head, input);
|
|
35
|
+
}
|
|
36
|
+
} else if (window.__UNHEAD__) {
|
|
37
|
+
_useSeoMeta(window.__UNHEAD__, input);
|
|
38
|
+
}
|
|
39
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ export type { PageHandler } from "./page";
|
|
|
3
3
|
|
|
4
4
|
export { useSSRContext } from "./context/ssr";
|
|
5
5
|
export { useEvent } from "./hooks/useEvent";
|
|
6
|
-
export { useHead } from "./hooks/useHead";
|
|
6
|
+
export { useHead, useSeoMeta } from "./hooks/useHead";
|
|
7
7
|
|
|
8
8
|
export type { IslandClientDirective, IslandProps } from "./island/types";
|
|
9
9
|
|
|
10
10
|
export type { ImportAssetsResult, ImportAssetsResultRaw } from "./shared/assets";
|
|
11
|
+
export type { YamfHead } from "./shared/head";
|
|
11
12
|
|
|
12
13
|
export { Head, type HeadProps } from "./components/Head";
|
package/src/island/client.tsx
CHANGED
|
@@ -62,6 +62,7 @@ customElements.define(
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
switch (islandClient) {
|
|
65
|
+
case true:
|
|
65
66
|
case "load":
|
|
66
67
|
initIsland();
|
|
67
68
|
break;
|
|
@@ -77,9 +78,11 @@ customElements.define(
|
|
|
77
78
|
initIsland();
|
|
78
79
|
}
|
|
79
80
|
break;
|
|
81
|
+
case false:
|
|
80
82
|
case "skip":
|
|
81
83
|
break;
|
|
82
84
|
default:
|
|
85
|
+
islandClient satisfies never;
|
|
83
86
|
// oxlint-disable-next-line typescript/restrict-template-expressions
|
|
84
87
|
throw new Error(`Invalid island-client value: ${islandClient}`);
|
|
85
88
|
}
|
package/src/island/types.ts
CHANGED
package/src/page.tsx
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Fragment } from "hono/jsx";
|
|
1
|
+
import { Fragment, type Child } from "hono/jsx";
|
|
3
2
|
import { renderToReadableStream } from "hono/jsx/streaming";
|
|
4
3
|
import { Hono } from "hono/tiny";
|
|
5
4
|
import type { EventHandlerResponse, H3Event } from "nitro/h3";
|
|
6
5
|
import { HTTPResponse, withServerTiming } from "nitro/h3";
|
|
6
|
+
import { useSeoMeta } from "unhead";
|
|
7
7
|
import type { Unhead } from "unhead/server";
|
|
8
8
|
import { transformHtmlTemplate } from "unhead/server";
|
|
9
9
|
import { createStreamableHead, wrapStream } from "unhead/stream/server";
|
|
10
|
-
import type {
|
|
11
|
-
import {
|
|
10
|
+
import type { ResolvableLink, UseSeoMetaInput } from "unhead/types";
|
|
11
|
+
import { Root as RootComponent } from "virtual:yamf:root";
|
|
12
12
|
import { template } from "virtual:yamf:template";
|
|
13
13
|
import { SSRContext } from "./context/ssr";
|
|
14
14
|
import type { ImportAssetsResult } from "./shared/assets";
|
|
15
|
+
import { YamfHead } from "./shared/head";
|
|
15
16
|
|
|
16
17
|
export type PageHandler = (
|
|
17
18
|
event: H3Event,
|
|
18
19
|
params: {
|
|
19
|
-
|
|
20
|
-
head?:
|
|
21
|
-
Layout?: FC<PropsWithChildren>;
|
|
20
|
+
assets: ImportAssetsResult;
|
|
21
|
+
head?: YamfHead;
|
|
22
22
|
},
|
|
23
23
|
) => EventHandlerResponse;
|
|
24
24
|
|
|
25
25
|
export type PageRenderer = (
|
|
26
26
|
event: H3Event,
|
|
27
|
-
params: {
|
|
28
|
-
|
|
27
|
+
params: {
|
|
28
|
+
head: Unhead;
|
|
29
|
+
seoHead: (input: UseSeoMetaInput) => void;
|
|
30
|
+
},
|
|
31
|
+
) => HTTPResponse | Child | Promise<Child | HTTPResponse>;
|
|
29
32
|
|
|
30
33
|
interface DefinePageOptions {
|
|
31
34
|
render: PageRenderer;
|
|
32
35
|
stream?: boolean;
|
|
33
|
-
Layout?: FC<PropsWithChildren>;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export const definePage = (options: DefinePageOptions): PageHandler => {
|
|
37
|
-
return async (event, {
|
|
38
|
-
const assets = serverAssets ? clientAssets.merge(serverAssets) : clientAssets;
|
|
39
|
-
|
|
39
|
+
return async (event, { assets, head: headInit }) => {
|
|
40
40
|
const { head } = createStreamableHead({ init: [headInit] });
|
|
41
|
+
const seoHead = (input?: UseSeoMetaInput) => useSeoMeta(head, input);
|
|
42
|
+
seoHead(headInit?.seo);
|
|
41
43
|
|
|
42
44
|
head.push({
|
|
43
45
|
link: [
|
|
@@ -47,15 +49,17 @@ export const definePage = (options: DefinePageOptions): PageHandler => {
|
|
|
47
49
|
script: [{ type: "module", src: assets.entry }],
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
const content = await options.render(event, { head });
|
|
52
|
+
const content = await options.render(event, { head, seoHead });
|
|
51
53
|
|
|
52
54
|
if (content instanceof HTTPResponse) {
|
|
53
55
|
return content;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
const Root = RootComponent ?? Fragment;
|
|
59
|
+
|
|
56
60
|
const App = async () => (
|
|
57
61
|
<SSRContext value={{ head, event }}>
|
|
58
|
-
<
|
|
62
|
+
<Root>{content}</Root>
|
|
59
63
|
</SSRContext>
|
|
60
64
|
);
|
|
61
65
|
|
package/src/server/entry.tsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { FC, PropsWithChildren } from "hono/jsx";
|
|
3
2
|
import type { EventHandlerRequest, EventHandlerWithFetch, H3Event } from "nitro/h3";
|
|
4
3
|
import { defineHandler, HTTPError, writeEarlyHints } from "nitro/h3";
|
|
5
4
|
import { addRoute, createRouter, findRoute } from "rou3";
|
|
6
5
|
import { withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
7
|
-
import type { ResolvableHead } from "unhead/types";
|
|
8
6
|
import { clientAssets } from "virtual:yamf:assets";
|
|
9
7
|
import { pages, assets as pagesServerAssets } from "virtual:yamf:pages";
|
|
8
|
+
import { rootAssets } from "virtual:yamf:root";
|
|
10
9
|
import type { PageHandler } from "#/page";
|
|
10
|
+
import { YamfHead } from "#/shared/head";
|
|
11
11
|
|
|
12
12
|
interface Route {
|
|
13
13
|
handler: () => Promise<PageHandler>;
|
|
@@ -47,8 +47,7 @@ for (const [relativePath, handler] of Object.entries(pages).toSorted((a, b) =>
|
|
|
47
47
|
export type ServerEntry = EventHandlerWithFetch<EventHandlerRequest, Promise<unknown>>;
|
|
48
48
|
|
|
49
49
|
export interface DefineServerEntryOptions {
|
|
50
|
-
head?:
|
|
51
|
-
Layout?: FC<PropsWithChildren>;
|
|
50
|
+
head?: YamfHead | ((event: H3Event) => YamfHead);
|
|
52
51
|
disableEarlyHints?: boolean;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -63,7 +62,7 @@ export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEnt
|
|
|
63
62
|
const { handler, serverAssets } = route.data;
|
|
64
63
|
event.context.params = route.params;
|
|
65
64
|
|
|
66
|
-
const assets =
|
|
65
|
+
const assets = clientAssets.merge(...[rootAssets, serverAssets].filter(x => !!x));
|
|
67
66
|
|
|
68
67
|
if (!options?.disableEarlyHints) {
|
|
69
68
|
const link = [
|
|
@@ -77,9 +76,8 @@ export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEnt
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
return (await handler())(event, {
|
|
80
|
-
|
|
79
|
+
assets,
|
|
81
80
|
head: typeof options?.head === "function" ? options.head(event) : options?.head,
|
|
82
|
-
Layout: options?.Layout,
|
|
83
81
|
});
|
|
84
82
|
});
|
|
85
83
|
};
|