@pajecawav/yamf 0.0.6 → 0.0.8
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 +32 -1
- package/dist/components/Head.d.ts +2 -3
- package/dist/components/Head.d.ts.map +1 -1
- package/dist/context/ssr.d.ts +1 -2
- package/dist/context/ssr.d.ts.map +1 -1
- package/dist/hooks/useEvent.d.ts +1 -2
- package/dist/hooks/useEvent.d.ts.map +1 -1
- package/dist/hooks/useHead.d.ts +2 -3
- package/dist/hooks/useHead.d.ts.map +1 -1
- package/dist/hooks/useHead.js.map +1 -1
- package/dist/island/types.d.ts +2 -3
- package/dist/island/types.d.ts.map +1 -1
- package/dist/page.d.ts +3 -4
- package/dist/page.d.ts.map +1 -1
- package/dist/server/entry.d.mts +3 -4
- package/dist/server/entry.d.mts.map +1 -1
- package/dist/server/entry.mjs +11 -1
- package/dist/server/entry.mjs.map +1 -1
- package/dist/server/island/server.d.mts +2 -3
- package/dist/server/island/server.d.mts.map +1 -1
- package/dist/server/island/server.mjs +2 -2
- package/dist/server/island/server.mjs.map +1 -1
- package/dist/server/island/types.d.mts +1 -2
- package/dist/server/island/types.d.mts.map +1 -1
- package/dist/server/shared/assets.d.mts +1 -2
- package/dist/server/shared/assets.d.mts.map +1 -1
- package/dist/server/shared/head.d.mts +1 -2
- package/dist/server/shared/head.d.mts.map +1 -1
- package/dist/shared/assets.d.ts +2 -3
- package/dist/shared/assets.d.ts.map +1 -1
- package/dist/shared/head.d.ts +1 -2
- package/dist/shared/head.d.ts.map +1 -1
- package/dist/vite/index.d.mts +2 -2
- package/dist/vite/index.d.mts.map +1 -1
- package/dist/vite/index.mjs +3 -1
- package/dist/vite/index.mjs.map +1 -1
- package/dist/vite/islands.mjs +38 -59
- package/dist/vite/islands.mjs.map +1 -1
- package/dist/vite/virtual-assets.mjs +1 -1
- package/dist/vite/virtual-assets.mjs.map +1 -1
- package/dist/vite/virtual-error-handler.mjs +23 -0
- package/dist/vite/virtual-error-handler.mjs.map +1 -0
- package/dist/vite/virtual-pages.mjs +1 -1
- package/dist/vite/virtual-pages.mjs.map +1 -1
- package/dist/vite/virtual-root.mjs +1 -1
- package/dist/vite/virtual-root.mjs.map +1 -1
- package/dist/vite/virtual-template.mjs +1 -1
- package/dist/vite/virtual-template.mjs.map +1 -1
- package/package.json +22 -31
- package/src/island/server.tsx +7 -5
- package/src/server/entry.tsx +25 -3
- package/src/virtual.d.ts +8 -0
- package/src/vite/index.ts +2 -0
- package/src/vite/islands.ts +76 -175
- package/src/vite/virtual-error-handler.ts +40 -0
|
@@ -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 { withMagicString } from \"rolldown-string\";\nimport type { ParserOptions, Plugin } from \"vite\";\nimport { Visitor } from \"vite\";\n\nconst ISLAND_REGEX = /\\.island\\.(j|t)sx?$/;\n\ntype Lang = NonNullable<ParserOptions[\"lang\"]>;\n\nfunction langFromId(id: string): Lang {\n\tif (id.endsWith(\".tsx\")) {\n\t\treturn \"tsx\";\n\t}\n\tif (id.endsWith(\".ts\")) {\n\t\treturn \"ts\";\n\t}\n\tif (id.endsWith(\".jsx\")) {\n\t\treturn \"jsx\";\n\t}\n\treturn \"js\";\n}\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: withMagicString(function (this, s, 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 program = this.parse(s.original, {\n\t\t\t\t\t\tlang: langFromId(id),\n\t\t\t\t\t});\n\n\t\t\t\t\t// prepend server island runtime + asset imports:\n\t\t\t\t\t// import * as __runtime from \"@pajecawav/yamf/server\";\n\t\t\t\t\t// import __assets from \"<id>?assets=client\";\n\t\t\t\t\ts.prepend(`import * as __runtime from \"@pajecawav/yamf/server\";\\n`);\n\t\t\t\t\ts.prepend(`import __assets from \"${id}?assets=client\";\\n`);\n\n\t\t\t\t\tconst seenExports = new Set<string>();\n\n\t\t\t\t\tnew Visitor({\n\t\t\t\t\t\tExportDefaultDeclaration(node) {\n\t\t\t\t\t\t\tconst declaration = node.declaration;\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tdeclaration.type !== \"FunctionDeclaration\" &&\n\t\t\t\t\t\t\t\tdeclaration.type !== \"FunctionExpression\" &&\n\t\t\t\t\t\t\t\tdeclaration.type !== \"ArrowFunctionExpression\"\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\t// export default <fn> ->\n\t\t\t\t\t\t\t// const __ISLAND__ = <fn>; export default __runtime.createIsland(__ISLAND__, \"default\", __assets)\n\t\t\t\t\t\t\ts.overwrite(node.start, declaration.start, \"const __ISLAND__ = \");\n\t\t\t\t\t\t\ts.appendRight(\n\t\t\t\t\t\t\t\tdeclaration.end,\n\t\t\t\t\t\t\t\t`; export default __runtime.createIsland(__ISLAND__, \"default\", __assets)`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tExportNamedDeclaration(node) {\n\t\t\t\t\t\t\tconst declaration = node.declaration;\n\t\t\t\t\t\t\tif (declaration?.type === \"VariableDeclaration\") {\n\t\t\t\t\t\t\t\tconst declarator = declaration.declarations[0];\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!declarator ||\n\t\t\t\t\t\t\t\t\tdeclarator.id.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\t!declarator.init ||\n\t\t\t\t\t\t\t\t\tseenExports.has(declarator.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 = declarator.id.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\t// export const <name> = <init> ->\n\t\t\t\t\t\t\t\t// const __wrap_<name> = <init>; export const <name> = __runtime.createIsland(__wrap_<name>, \"<name>\", __assets)\n\t\t\t\t\t\t\t\ts.overwrite(\n\t\t\t\t\t\t\t\t\tnode.start,\n\t\t\t\t\t\t\t\t\tdeclarator.init.start,\n\t\t\t\t\t\t\t\t\t`const __wrap_${exportName} = `,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\ts.appendRight(\n\t\t\t\t\t\t\t\t\tdeclarator.init.end,\n\t\t\t\t\t\t\t\t\t`; export const ${exportName} = __runtime.createIsland(__wrap_${exportName}, \"${exportName}\", __assets)`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else if (declaration?.type === \"FunctionDeclaration\") {\n\t\t\t\t\t\t\t\tconst fnId = declaration.id;\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!fnId ||\n\t\t\t\t\t\t\t\t\tfnId.type !== \"Identifier\" ||\n\t\t\t\t\t\t\t\t\tseenExports.has(fnId.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 = fnId.name;\n\t\t\t\t\t\t\t\tseenExports.add(exportName);\n\n\t\t\t\t\t\t\t\t// export function <name>() {} ->\n\t\t\t\t\t\t\t\t// function __wrap_<name>() {}; export const <name> = __runtime.createIsland(__wrap_<name>, \"<name>\", __assets)\n\t\t\t\t\t\t\t\ts.remove(node.start, declaration.start);\n\t\t\t\t\t\t\t\ts.overwrite(fnId.start, fnId.end, `__wrap_${exportName}`);\n\t\t\t\t\t\t\t\ts.appendRight(\n\t\t\t\t\t\t\t\t\tdeclaration.end,\n\t\t\t\t\t\t\t\t\t`; export const ${exportName} = __runtime.createIsland(__wrap_${exportName}, \"${exportName}\", __assets)`,\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}).visit(program);\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: withMagicString(function (s) {\n\t\t\t\t\tif (s.original.includes(\"__island_raw_import__\")) {\n\t\t\t\t\t\ts.replaceAll(\"__island_raw_import__\", \"import\");\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t];\n};\n"],"mappings":";;;AAKA,MAAM,eAAe;AAIrB,SAAS,WAAW,IAAkB;CACrC,IAAI,GAAG,SAAS,MAAM,GACrB,OAAO;CAER,IAAI,GAAG,SAAS,KAAK,GACpB,OAAO;CAER,IAAI,GAAG,SAAS,MAAM,GACrB,OAAO;CAER,OAAO;AACR;AAEA,MAAa,gBAA0B;CACtC,OAAO,CACN;EACC,MAAM;EACN,WAAW;GACV,QAAQ,EAAE,IAAI,aAAa;GAC3B,SAAS,gBAAgB,SAAgB,GAAG,IAAI;IAC/C,IAAI,KAAK,YAAY,SAAS,OAC7B;IAGD,MAAM,UAAU,KAAK,MAAM,EAAE,UAAU,EACtC,MAAM,WAAW,EAAE,EACpB,CAAC;IAKD,EAAE,QAAQ,wDAAwD;IAClE,EAAE,QAAQ,yBAAyB,GAAG,mBAAmB;IAEzD,MAAM,8BAAc,IAAI,IAAY;IAEpC,IAAI,QAAQ;KACX,yBAAyB,MAAM;MAC9B,MAAM,cAAc,KAAK;MACzB,IACC,YAAY,SAAS,yBACrB,YAAY,SAAS,wBACrB,YAAY,SAAS,2BAErB;MAKD,EAAE,UAAU,KAAK,OAAO,YAAY,OAAO,qBAAqB;MAChE,EAAE,YACD,YAAY,KACZ,0EACD;KACD;KACA,uBAAuB,MAAM;MAC5B,MAAM,cAAc,KAAK;MACzB,IAAI,aAAa,SAAS,uBAAuB;OAChD,MAAM,aAAa,YAAY,aAAa;OAC5C,IACC,CAAC,cACD,WAAW,GAAG,SAAS,gBACvB,CAAC,WAAW,QACZ,YAAY,IAAI,WAAW,GAAG,IAAI,GAElC;OAED,MAAM,aAAa,WAAW,GAAG;OACjC,YAAY,IAAI,UAAU;OAI1B,EAAE,UACD,KAAK,OACL,WAAW,KAAK,OAChB,gBAAgB,WAAW,IAC5B;OACA,EAAE,YACD,WAAW,KAAK,KAChB,kBAAkB,WAAW,mCAAmC,WAAW,KAAK,WAAW,aAC5F;MACD,OAAO,IAAI,aAAa,SAAS,uBAAuB;OACvD,MAAM,OAAO,YAAY;OACzB,IACC,CAAC,QACD,KAAK,SAAS,gBACd,YAAY,IAAI,KAAK,IAAI,GAEzB;OAED,MAAM,aAAa,KAAK;OACxB,YAAY,IAAI,UAAU;OAI1B,EAAE,OAAO,KAAK,OAAO,YAAY,KAAK;OACtC,EAAE,UAAU,KAAK,OAAO,KAAK,KAAK,UAAU,YAAY;OACxD,EAAE,YACD,YAAY,KACZ,kBAAkB,WAAW,mCAAmC,WAAW,KAAK,WAAW,aAC5F;MACD;KACD;IACD,CAAC,CAAC,CAAC,MAAM,OAAO;GACjB,CAAC;EACF;CACD,GACA;EACC,MAAM;EACN,WAAW;GACV,OAAO;GACP,SAAS,gBAAgB,SAAU,GAAG;IACrC,IAAI,EAAE,SAAS,SAAS,uBAAuB,GAC9C,EAAE,WAAW,yBAAyB,QAAQ;GAEhD,CAAC;EACF;CACD,CACD;AACD"}
|
|
@@ -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 = "\0" + virtualModuleId;
|
|
6
6
|
return {
|
|
7
7
|
name: "yamf:virtual-assets",
|
|
8
8
|
resolveId(id) {
|
|
@@ -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?assets=client\";\n\nexport { clientAssets };\n`.trim();\n\t\t},\n\t};\n};\n"],"mappings":";;AAGA,MAAa,sBAA8B;CAC1C,MAAM,kBAAkB;CACxB,MAAM,0BAA0B;
|
|
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,OAAO;CAEvC,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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { js } from "./shared/utils.mjs";
|
|
2
|
+
//#region src/vite/virtual-error-handler.ts
|
|
3
|
+
const virtualErrorHandler = (options) => {
|
|
4
|
+
const virtualModuleId = "virtual:yamf:error-handler";
|
|
5
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
6
|
+
return {
|
|
7
|
+
name: "yamf:virtual-error-handler",
|
|
8
|
+
resolveId(id) {
|
|
9
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
10
|
+
},
|
|
11
|
+
load(id) {
|
|
12
|
+
if (id !== resolvedVirtualModuleId) return;
|
|
13
|
+
const errorHandler = options?.nitro?.errorHandler;
|
|
14
|
+
if (!errorHandler) return js`export const errorHandler = null;`;
|
|
15
|
+
if (Array.isArray(errorHandler)) throw new Error("Multiple error handlers are not supported");
|
|
16
|
+
return js`export { default as errorHandler } from "${errorHandler}";`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { virtualErrorHandler };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=virtual-error-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-error-handler.mjs","names":[],"sources":["../../src/vite/virtual-error-handler.ts"],"sourcesContent":["import type { NitroPluginConfig } from \"nitro/vite\";\nimport type { Plugin } from \"vite\";\nimport { js } from \"../shared/utils\";\n\nexport interface VirtualErrorHandlerOptions {\n\tnitro?: NitroPluginConfig;\n}\n\nexport const virtualErrorHandler = (options?: VirtualErrorHandlerOptions): Plugin => {\n\tconst virtualModuleId = \"virtual:yamf:error-handler\";\n\tconst resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\n\n\treturn {\n\t\tname: \"yamf:virtual-error-handler\",\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 errorHandler = options?.nitro?.errorHandler;\n\n\t\t\tif (!errorHandler) {\n\t\t\t\treturn js`export const errorHandler = null;`;\n\t\t\t}\n\n\t\t\tif (Array.isArray(errorHandler)) {\n\t\t\t\tthrow new Error(\"Multiple error handlers are not supported\");\n\t\t\t}\n\n\t\t\treturn js`export { default as errorHandler } from \"${errorHandler}\";`;\n\t\t},\n\t};\n};\n"],"mappings":";;AAQA,MAAa,uBAAuB,YAAiD;CACpF,MAAM,kBAAkB;CACxB,MAAM,0BAA0B,OAAO;CAEvC,OAAO;EACN,MAAM;EACN,UAAU,IAAI;GACb,IAAI,OAAO,iBACV,OAAO;EAIT;EACA,KAAK,IAAI;GACR,IAAI,OAAO,yBACV;GAGD,MAAM,eAAe,SAAS,OAAO;GAErC,IAAI,CAAC,cACJ,OAAO,EAAE;GAGV,IAAI,MAAM,QAAQ,YAAY,GAC7B,MAAM,IAAI,MAAM,2CAA2C;GAG5D,OAAO,EAAE,4CAA4C,aAAa;EACnE;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 = "\0" + virtualModuleId;
|
|
6
6
|
return {
|
|
7
7
|
name: "yamf:virtual-pages",
|
|
8
8
|
resolveId(id) {
|
|
@@ -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/**/*.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;
|
|
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,OAAO;CAEvC,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"}
|
|
@@ -4,7 +4,7 @@ import { resolveModulePath } from "exsolve";
|
|
|
4
4
|
const ROOT_PATH = "./src/root";
|
|
5
5
|
const virtualRoot = () => {
|
|
6
6
|
const virtualModuleId = "virtual:yamf:root";
|
|
7
|
-
const resolvedVirtualModuleId = "\
|
|
7
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
8
8
|
return {
|
|
9
9
|
name: "yamf:virtual-root",
|
|
10
10
|
resolveId(id) {
|
|
@@ -1 +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;
|
|
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,OAAO;CAEvC,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 = "\0" + virtualModuleId;
|
|
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\tserver.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;
|
|
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\tserver.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,OAAO;CAEvC,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;IAGxC,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;GACvC;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.8",
|
|
5
5
|
"description": "Yet another meta framework",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/pajecawav/yamf#readme",
|
|
@@ -30,43 +30,36 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@hono/react-compat": "^0.0.3",
|
|
34
33
|
"hono": "^4.12.30",
|
|
35
34
|
"vite": "^8.1.5"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"nitro": "3.0.260610-beta",
|
|
45
|
-
"rou3": "^0.9.1",
|
|
37
|
+
"@hono/react-compat": "^0.0.3",
|
|
38
|
+
"devalue": "^5.9.2",
|
|
39
|
+
"exsolve": "^1.1.1",
|
|
40
|
+
"nitro": "3.0.260903-beta",
|
|
41
|
+
"rolldown-string": "^0.3.1",
|
|
42
|
+
"rou3": "^0.9.2",
|
|
46
43
|
"ufo": "^1.6.4",
|
|
47
|
-
"unhead": "^3.
|
|
48
|
-
"wouter": "^3.
|
|
44
|
+
"unhead": "^3.4.0",
|
|
45
|
+
"wouter": "^3.11.0"
|
|
49
46
|
},
|
|
50
47
|
"devDependencies": {
|
|
51
48
|
"@hono/react-compat": "^0.0.3",
|
|
52
|
-
"@pajecawav/tools": "^0.0.
|
|
53
|
-
"@
|
|
54
|
-
"@types/
|
|
55
|
-
"@types/node": "^24.13.3",
|
|
56
|
-
"@vitest/coverage-v8": "^4.1.10",
|
|
57
|
-
"@vitest/ui": "^4.1.10",
|
|
49
|
+
"@pajecawav/tools": "^0.0.9",
|
|
50
|
+
"@playwright/test": "^1.63.0",
|
|
51
|
+
"@types/node": "^26.4.1",
|
|
58
52
|
"cross-env": "^10.1.0",
|
|
59
|
-
"hono": "^4.
|
|
53
|
+
"hono": "^4.13.7",
|
|
60
54
|
"husky": "^9.1.7",
|
|
61
|
-
"npm-run-all2": "^9.0.
|
|
62
|
-
"oxfmt": "^0.
|
|
63
|
-
"oxlint": "^1.
|
|
64
|
-
"oxlint-tsgolint": "^0.
|
|
65
|
-
"publint": "^0.3.
|
|
66
|
-
"tsdown": "0.
|
|
55
|
+
"npm-run-all2": "^9.0.3",
|
|
56
|
+
"oxfmt": "^0.66.0",
|
|
57
|
+
"oxlint": "^1.81.0",
|
|
58
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
59
|
+
"publint": "^0.3.24",
|
|
60
|
+
"tsdown": "0.23.0",
|
|
67
61
|
"typescript": "~7.0.2",
|
|
68
|
-
"vite": "^8.
|
|
69
|
-
"vitest": "^4.1.10"
|
|
62
|
+
"vite": "^8.2.2"
|
|
70
63
|
},
|
|
71
64
|
"scripts": {
|
|
72
65
|
"build": "tsdown",
|
|
@@ -74,10 +67,8 @@
|
|
|
74
67
|
"play": "pnpm --filter=playground dev",
|
|
75
68
|
"play:build": "pnpm --filter=playground build",
|
|
76
69
|
"play:preview": "pnpm --filter=playground preview",
|
|
77
|
-
"test": "
|
|
78
|
-
"test:
|
|
79
|
-
"test:coverage": "vitest run --coverage",
|
|
80
|
-
"test:ui": "vitest --ui",
|
|
70
|
+
"test": "playwright test",
|
|
71
|
+
"test:ui": "playwright test --ui",
|
|
81
72
|
"lint": "cross-env FORCE_COLOR=1 run-p -l lint:*",
|
|
82
73
|
"lint:oxlint": "oxlint .",
|
|
83
74
|
"lint:tsc": "tsc -b --noEmit",
|
package/src/island/server.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringify } from "devalue";
|
|
2
2
|
import type { Child, FC } from "hono/jsx";
|
|
3
3
|
import type { ImportAssetsResultRaw } from "#/shared/assets";
|
|
4
|
-
import type { IslandClientDirective } from "./types";
|
|
4
|
+
import type { IslandClientDirective, IslandProps } from "./types";
|
|
5
5
|
|
|
6
6
|
declare module "hono/jsx" {
|
|
7
7
|
namespace JSX {
|
|
@@ -10,7 +10,7 @@ declare module "hono/jsx" {
|
|
|
10
10
|
"island-props"?: string;
|
|
11
11
|
"island-src": string;
|
|
12
12
|
"island-entry": string;
|
|
13
|
-
"island-client"
|
|
13
|
+
"island-client"?: IslandClientDirective;
|
|
14
14
|
children: Child;
|
|
15
15
|
style?: JSX.CSSProperties;
|
|
16
16
|
};
|
|
@@ -23,7 +23,10 @@ export const createIsland = (
|
|
|
23
23
|
exportName: string,
|
|
24
24
|
assets: ImportAssetsResultRaw,
|
|
25
25
|
): FC => {
|
|
26
|
-
const ComponentWrapper: FC & { name: string } =
|
|
26
|
+
const ComponentWrapper: FC<IslandProps> & { name: string } = ({
|
|
27
|
+
"yamf-client": clientDirective,
|
|
28
|
+
...props
|
|
29
|
+
}) => {
|
|
27
30
|
if (!assets.entry) {
|
|
28
31
|
throw new Error(`Missing island entry for island ${Component.name}`);
|
|
29
32
|
}
|
|
@@ -33,8 +36,7 @@ export const createIsland = (
|
|
|
33
36
|
island-props={stringify(props)}
|
|
34
37
|
island-src={assets.entry}
|
|
35
38
|
island-entry={exportName}
|
|
36
|
-
|
|
37
|
-
island-client={props["yamf-client"] as IslandClientDirective}
|
|
39
|
+
island-client={clientDirective}
|
|
38
40
|
// TODO: export CSS?
|
|
39
41
|
style={{ display: "contents" }}
|
|
40
42
|
>
|
package/src/server/entry.tsx
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
defineHandler,
|
|
4
|
+
EventHandler,
|
|
5
|
+
H3Event,
|
|
6
|
+
HTTPError,
|
|
7
|
+
writeEarlyHints,
|
|
8
|
+
type EventHandlerRequest,
|
|
9
|
+
type EventHandlerWithFetch,
|
|
10
|
+
} from "nitro/h3";
|
|
4
11
|
import { addRoute, createRouter, findRoute } from "rou3";
|
|
5
12
|
import { withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
6
13
|
import { clientAssets } from "virtual:yamf:assets";
|
|
14
|
+
import { errorHandler } from "virtual:yamf:error-handler";
|
|
7
15
|
import { pages, assets as pagesServerAssets } from "virtual:yamf:pages";
|
|
8
16
|
import { rootAssets } from "virtual:yamf:root";
|
|
9
17
|
import type { PageHandler } from "#/page";
|
|
@@ -52,7 +60,7 @@ export interface DefineServerEntryOptions {
|
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEntry => {
|
|
55
|
-
|
|
63
|
+
const rootHandler: EventHandler<EventHandlerRequest, Promise<unknown>> = async event => {
|
|
56
64
|
const route = findRoute(router, "GET", event.url.pathname);
|
|
57
65
|
|
|
58
66
|
if (!route) {
|
|
@@ -79,5 +87,19 @@ export const defineServerEntry = (options?: DefineServerEntryOptions): ServerEnt
|
|
|
79
87
|
assets,
|
|
80
88
|
head: typeof options?.head === "function" ? options.head(event) : options?.head,
|
|
81
89
|
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return defineHandler(async event => {
|
|
93
|
+
if (!errorHandler) {
|
|
94
|
+
return rootHandler(event);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
return await rootHandler(event);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
const httpError = error instanceof HTTPError ? error : new HTTPError({ cause: error });
|
|
101
|
+
|
|
102
|
+
return errorHandler(httpError, event);
|
|
103
|
+
}
|
|
82
104
|
});
|
|
83
105
|
};
|
package/src/virtual.d.ts
CHANGED
|
@@ -18,3 +18,11 @@ declare module "virtual:yamf:root" {
|
|
|
18
18
|
|
|
19
19
|
export { Root, rootAssets };
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
declare module "virtual:yamf:error-handler" {
|
|
23
|
+
import type { H3Event, HTTPError } from "nitro/h3";
|
|
24
|
+
|
|
25
|
+
type ErrorHandler = (error: HTTPError, event: H3Event) => Promise<Response | undefined>;
|
|
26
|
+
|
|
27
|
+
export const errorHandler: ErrorHandler | null;
|
|
28
|
+
}
|
package/src/vite/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { nitro } from "nitro/vite";
|
|
|
4
4
|
import type { EnvironmentOptions, PluginOption } from "vite";
|
|
5
5
|
import { islands } from "./islands";
|
|
6
6
|
import { virtualAssets } from "./virtual-assets";
|
|
7
|
+
import { virtualErrorHandler } from "./virtual-error-handler";
|
|
7
8
|
import { virtualPages } from "./virtual-pages";
|
|
8
9
|
import { virtualRoot } from "./virtual-root";
|
|
9
10
|
import { virtualTemplate } from "./virtual-template";
|
|
@@ -75,6 +76,7 @@ const yamf = (options?: YamfOptions): PluginOption[] => {
|
|
|
75
76
|
|
|
76
77
|
plugins.push(islands());
|
|
77
78
|
|
|
79
|
+
plugins.push(virtualErrorHandler(options));
|
|
78
80
|
plugins.push(virtualAssets());
|
|
79
81
|
plugins.push(virtualPages());
|
|
80
82
|
plugins.push(virtualTemplate());
|