@maizzle/framework 6.0.0-rc.25 → 6.0.0-rc.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.d.ts +19 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +139 -102
- package/dist/build.js.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/render/buildTemplate.d.ts +49 -0
- package/dist/render/buildTemplate.d.ts.map +1 -0
- package/dist/render/buildTemplate.js +139 -0
- package/dist/render/buildTemplate.js.map +1 -0
- package/dist/render/createRenderer.d.ts +3 -1
- package/dist/render/createRenderer.d.ts.map +1 -1
- package/dist/render/createRenderer.js +40 -3
- package/dist/render/createRenderer.js.map +1 -1
- package/dist/render/index.js +1 -1
- package/dist/render/parallel/buildWorker.d.ts +31 -0
- package/dist/render/parallel/buildWorker.d.ts.map +1 -0
- package/dist/render/parallel/buildWorker.js +66 -0
- package/dist/render/parallel/buildWorker.js.map +1 -0
- package/dist/render/parallel/worker.mjs +28 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +73 -53
- package/dist/serve.js.map +1 -1
- package/dist/server/sfc-utils.js +1 -1
- package/dist/server/ui/pages/Preview.vue +34 -11
- package/dist/server/ui/vite-env.d.ts +1 -0
- package/dist/types/config.d.ts +22 -1
- package/dist/types/config.d.ts.map +1 -1
- package/package.json +6 -5
|
@@ -9,8 +9,8 @@ import { componentNameFromPath } from "../utils/componentSources.js";
|
|
|
9
9
|
import { shikiToCodeBlock } from "../components/utils.js";
|
|
10
10
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { dirname, relative, resolve } from "node:path";
|
|
12
|
-
import { glob, globSync } from "tinyglobby";
|
|
13
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { glob, globSync } from "tinyglobby";
|
|
14
14
|
import { defu as defu$1 } from "defu";
|
|
15
15
|
import { createSSRApp } from "vue";
|
|
16
16
|
import { createServer, mergeConfig } from "vite";
|
|
@@ -148,6 +148,14 @@ async function createRenderer(options = {}) {
|
|
|
148
148
|
const VIRTUAL_SFC_ID = "virtual:maizzle-sfc.vue";
|
|
149
149
|
let virtualSfcSource = "";
|
|
150
150
|
/**
|
|
151
|
+
* Per-render source overrides keyed by absolute template path. Lets the
|
|
152
|
+
* build's beforeRender event rewrite a template's source before compile
|
|
153
|
+
* while keeping the real file id — so relative imports, asset URLs and
|
|
154
|
+
* component resolution still resolve against the actual file location
|
|
155
|
+
* (which the virtual-SFC path can't do).
|
|
156
|
+
*/
|
|
157
|
+
const sourceOverrides = /* @__PURE__ */ new Map();
|
|
158
|
+
/**
|
|
151
159
|
* Never load the host project's vite.config.ts here. Doing so pulls
|
|
152
160
|
* every host plugin (Nitro, TanStack Start, the Maizzle plugin
|
|
153
161
|
* itself, …) into this isolated SSR pipeline, where they override
|
|
@@ -171,6 +179,13 @@ async function createRenderer(options = {}) {
|
|
|
171
179
|
if (id === VIRTUAL_SFC_ID) return virtualSfcSource;
|
|
172
180
|
}
|
|
173
181
|
},
|
|
182
|
+
{
|
|
183
|
+
name: "maizzle:source-override",
|
|
184
|
+
load(id) {
|
|
185
|
+
const override = sourceOverrides.get(id.split("?")[0]);
|
|
186
|
+
if (override !== void 0) return override;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
174
189
|
vue({
|
|
175
190
|
include: [/\.vue$/, /\.md$/],
|
|
176
191
|
template: {
|
|
@@ -286,7 +301,7 @@ isCustomElement: (tag) => tag.startsWith("amp-") }
|
|
|
286
301
|
};
|
|
287
302
|
const server = await createServer(userViteConfig ? mergeConfig(userViteConfig, maizzleConfig) : maizzleConfig);
|
|
288
303
|
return {
|
|
289
|
-
async render(input, config) {
|
|
304
|
+
async render(input, config, opts) {
|
|
290
305
|
let component;
|
|
291
306
|
let configKey;
|
|
292
307
|
let contextKey;
|
|
@@ -304,7 +319,29 @@ isCustomElement: (tag) => tag.startsWith("amp-") }
|
|
|
304
319
|
const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID);
|
|
305
320
|
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
306
321
|
component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default;
|
|
307
|
-
} else
|
|
322
|
+
} else {
|
|
323
|
+
/**
|
|
324
|
+
* A beforeRender handler may have rewritten the source. Register it
|
|
325
|
+
* under the real path id and invalidate so ssrLoadModule compiles
|
|
326
|
+
* the override; clear + invalidate afterwards so the override never
|
|
327
|
+
* leaks into a later render of the same path.
|
|
328
|
+
*/
|
|
329
|
+
const hasOverride = opts?.source !== void 0;
|
|
330
|
+
if (hasOverride) {
|
|
331
|
+
sourceOverrides.set(input, opts.source);
|
|
332
|
+
const mod = await server.moduleGraph.getModuleByUrl(input);
|
|
333
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
component = (await server.ssrLoadModule(input)).default;
|
|
337
|
+
} finally {
|
|
338
|
+
if (hasOverride) {
|
|
339
|
+
sourceOverrides.delete(input);
|
|
340
|
+
const mod = await server.moduleGraph.getModuleByUrl(input);
|
|
341
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
308
345
|
} else {
|
|
309
346
|
component = input;
|
|
310
347
|
configKey = MaizzleConfigKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.js","names":["relPath","merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, relative as relPath, resolve } from 'node:path'\nimport { mkdirSync, writeFileSync, existsSync, rmSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { isLaravel } from '../utils/detect.ts'\nimport { rowSourceLocation } from './plugins/rowSourceLocation.ts'\nimport { rawExtract } from './plugins/rawExtract.ts'\nimport { codeBlockExtract } from './plugins/codeBlockExtract.ts'\nimport { markdownExtract } from './plugins/markdownExtract.ts'\nimport { createServer, mergeConfig, type InlineConfig, type Plugin } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { glob, globSync } from 'tinyglobby'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport { componentNameFromPath, type NormalizedComponentSource } from '../utils/componentSources.ts'\nimport { shikiToCodeBlock } from '../components/utils.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig, MarkdownConfig } from '../types/index.ts'\nimport type { MarkdownExit } from 'markdown-exit'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n outputPath?: RenderContext['outputPath']\n tailwindBlocks?: RenderContext['tailwindBlocks']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n invalidateAll(): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownConfig\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n /**\n * Additional component sources to register for auto-import. Already\n * normalized — pass through `normalizeComponentSources()` first.\n */\n componentDirs?: NormalizedComponentSource[]\n /** User Vite config options to merge into the internal SSR server */\n vite?: InlineConfig\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptionsRaw, root = process.cwd(), componentDirs = [], vite: userViteConfig } = options\n const { shikiTheme = 'github-light', ...markdownOptions } = markdownOptionsRaw ?? {}\n\n /**\n * Sources without an explicit prefix get registered via unplugin's `dirs`\n * (folder name auto-namespaces). Sources with an explicit `prefix` are\n * registered through a custom resolver below so we fully control naming.\n */\n const dirSources = componentDirs.filter(s => s.prefix === undefined)\n const prefixedSources = componentDirs.filter(s => s.prefix !== undefined)\n\n /**\n * Absolute component dirs — used to skip auto-wrapping `.md` files that\n * are imported as reusable components (vs. entry-point email templates).\n */\n const componentDirsAbs = [resolve(root, 'components'), ...componentDirs.map(s => s.path)]\n\n const dtsDir = isLaravel()\n ? resolve(process.cwd(), 'resources/js/types/maizzle')\n : resolve(root, '.maizzle')\n\n /**\n * Built-in framework components live at this path. When a user provides\n * a top-level file with the same (PascalCased) basename, drop the\n * built-in from unplugin's scan so the user's component is the only\n * candidate. This avoids the \"naming conflicts\" warning and the\n * alphabetical-glob ordering pitfall that decides who wins when\n * both are present in `dirs`.\n */\n const frameworkComponentsDir = resolve(__dirname, '../components')\n\n function topLevelBasenamesLower(dir: string): Set<string> {\n if (!existsSync(dir)) return new Set()\n const files = globSync(['*.vue', '*.md'], { cwd: dir, absolute: false })\n return new Set(files.map(f => f.replace(/\\.(vue|md)$/, '').toLowerCase()))\n }\n\n const frameworkFiles = globSync(['*.vue', '*.md'], { cwd: frameworkComponentsDir, absolute: false })\n const frameworkByLower = new Map(\n frameworkFiles.map(f => [f.replace(/\\.(vue|md)$/, '').toLowerCase(), f]),\n )\n\n const shadowedNames = new Set<string>()\n for (const dir of [resolve(root, 'components'), ...dirSources.map(s => s.path)]) {\n for (const lower of topLevelBasenamesLower(dir)) {\n if (frameworkByLower.has(lower)) shadowedNames.add(lower)\n }\n }\n\n const frameworkExcludes = [...shadowedNames]\n .map(lower => `${frameworkComponentsDir}/${frameworkByLower.get(lower)}`)\n\n /**\n * Pre-scanned name → absolute-path map for prefixed sources. Rebuilt\n * on file add/unlink via the watcher hook plugin further down. Drives\n * the runtime resolver and the d.ts we emit for IDE autocompletion.\n */\n const prefixedNameMap = new Map<string, string>()\n\n async function scanPrefixedSources(): Promise<void> {\n prefixedNameMap.clear()\n const seen = new Map<string, string>()\n for (const source of prefixedSources) {\n const files = await glob(['**/*.vue', '**/*.md'], { cwd: source.path, absolute: true })\n for (const file of files) {\n const name = componentNameFromPath({\n filePath: file,\n dirRoot: source.path,\n prefix: source.prefix,\n pathPrefix: source.pathPrefix,\n })\n const existing = seen.get(name)\n if (existing && existing !== file) {\n throw new Error(\n `[maizzle] Component name collision: \"${name}\" resolved from both \"${existing}\" and \"${file}\". `\n + 'Rename one of the files or split them into separate sources with distinct prefixes.',\n )\n }\n seen.set(name, file)\n prefixedNameMap.set(name, file)\n }\n }\n }\n\n await scanPrefixedSources()\n\n const prefixedResolver = (name: string) => prefixedNameMap.get(name)\n\n /**\n * unplugin-vue-components' own d.ts only covers components found via\n * `dirs`; its `types` option emits named-import entries which break\n * for SFC `default` exports. Write a sibling d.ts for prefixed\n * sources so editors get correct autocompletion via TypeScript\n * interface merging on `vue.GlobalComponents`.\n */\n const prefixedDtsPath = resolve(dtsDir, 'prefixed-components.d.ts')\n\n function writePrefixedDts(): void {\n if (!dts) return\n if (prefixedNameMap.size === 0) {\n if (existsSync(prefixedDtsPath)) rmSync(prefixedDtsPath)\n return\n }\n const dtsBase = dirname(prefixedDtsPath)\n mkdirSync(dtsBase, { recursive: true })\n const lines = Array.from(prefixedNameMap.entries())\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, file]) => {\n const relativePath = relPath(dtsBase, file).replace(/\\\\/g, '/')\n const importPath = relativePath.startsWith('.') ? relativePath : `./${relativePath}`\n return ` ${name}: typeof import('${importPath}')['default']`\n })\n .join('\\n')\n writeFileSync(\n prefixedDtsPath,\n `/* eslint-disable */\\n// @ts-nocheck\\n// biome-ignore lint: disable\\n// oxlint-disable\\n// Generated by Maizzle for prefixed component sources\\n\\nexport {}\\n\\n/* prettier-ignore */\\ndeclare module 'vue' {\\n export interface GlobalComponents {\\n${lines}\\n }\\n}\\n`,\n )\n }\n\n writePrefixedDts()\n\n /**\n * Watches prefixed source dirs and rebuilds {@link prefixedNameMap} when\n * files are added/removed. Vite's watcher already covers `dirSources`\n * via unplugin-vue-components' own filesystem hooks.\n */\n const prefixedSourceWatcher: Plugin | null = prefixedSources.length > 0\n ? {\n name: 'maizzle:prefixed-component-watcher',\n configureServer(server) {\n for (const source of prefixedSources) {\n server.watcher.add(source.path)\n }\n const refresh = async (file: string) => {\n if (!prefixedSources.some(s => file.startsWith(`${s.path}/`))) return\n if (!/\\.(vue|md)$/.test(file)) return\n await scanPrefixedSources()\n writePrefixedDts()\n }\n server.watcher.on('add', refresh)\n server.watcher.on('unlink', refresh)\n },\n }\n : null\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n /**\n * Never load the host project's vite.config.ts here. Doing so pulls\n * every host plugin (Nitro, TanStack Start, the Maizzle plugin\n * itself, …) into this isolated SSR pipeline, where they override\n * env factories, re-trigger configureServer hooks, and break\n * Vite's hot channel wiring. Users who need extra Vite plugins\n * for SSR pass them explicitly via the `vite` option.\n */\n const maizzleConfig: InlineConfig = {\n configFile: false,\n plugins: [\n rawExtract(),\n codeBlockExtract(),\n markdownExtract(),\n rowSourceLocation(),\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n compilerOptions: {\n /**\n * AMP4Email tags (<amp-carousel>, <amp-img>, <amp-list> ...)\n * render verbatim — skip the component resolver. Users who\n * want to wrap an amp tag in a Vue component should register\n * it under a PascalCase name (e.g. `components/AmpCarousel.vue`\n * → `<AmpCarousel>`).\n */\n isCustomElement: (tag: string) => tag.startsWith('amp-'),\n },\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n wrapperClasses: 'prose',\n wrapperComponent: (id: string, raw: string) => {\n const fm = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---/)?.[1]\n const layout = fm?.match(/^[ \\t]*layout[ \\t]*:[ \\t]*['\"]?([A-Za-z][\\w-]*|false|none)['\"]?[ \\t]*$/m)?.[1]\n if (layout === 'false' || layout === 'none') return null\n if (layout) return layout\n /**\n * No `layout:` set — default to the built-in `MarkdownLayout`\n * for entry-template `.md` files. Skip for `.md` files inside\n * component dirs, which are reusable fragments imported into\n * other templates.\n */\n const inComponentDir = componentDirsAbs.some(d => id === d || id.startsWith(`${d}/`))\n return inComponentDir ? null : 'MarkdownLayout'\n },\n markdownOptions: {\n async highlight(code: string, lang: string) {\n const { codeToHtml } = await import('shiki')\n return codeToHtml(code, { lang, theme: shikiTheme })\n },\n },\n markdownSetup(md: MarkdownExit) {\n const defaultFence = md.renderer.rules.fence!\n md.renderer.rules.fence = (...args) =>\n Promise.resolve(defaultFence(...args)).then(shikiToCodeBlock)\n\n const defaultCodeBlock = md.renderer.rules.code_block!\n md.renderer.rules.code_block = (...args) => shikiToCodeBlock(defaultCodeBlock(...args) as string)\n },\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n /**\n * unplugin-auto-import's default `include` doesn't match `.md`, so\n * auto-imports (Vue, unhead and Maizzle composables/filters) were\n * never injected into Markdown templates — `useConfig()` and friends\n * threw at runtime. Extend the default list with `.md` (and its\n * `?vue` script sub-requests) to mirror the `.md` coverage the\n * Components plugin already declares below.\n */\n include: [/\\.[jt]sx?$/, /\\.vue$/, /\\.vue\\?vue/, /\\.md$/, /\\.md\\?vue/],\n dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n frameworkComponentsDir,\n resolve(root, 'components'),\n ...dirSources.map(s => s.path),\n ],\n /**\n * Drop built-in component files whose name the user has shadowed.\n * This makes the user's version the only match — no \"naming\n * conflicts\" warning, no glob-ordering games.\n */\n globsExclude: frameworkExcludes,\n directoryAsNamespace: true,\n collapseSamePrefixes: true,\n resolvers: prefixedSources.length > 0 ? [prefixedResolver] : undefined,\n dts: dts ? resolve(dtsDir, 'components.d.ts') : false,\n }),\n ...(prefixedSourceWatcher ? [prefixedSourceWatcher] : []),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n /**\n * Watcher is required so unplugin-vue-components and unplugin-auto-import\n * detect added/removed component files and rewrite their .d.ts on the fly.\n * (We only render via SSR — HMR is off, but chokidar still drives plugins.)\n */\n fs: {\n allow: [process.cwd(), root, ...componentDirs.map(s => s.path), vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n }\n\n /**\n * Merge user's vite config (from config.vite) under Maizzle's config.\n * mergeConfig(a, b) → b overrides a for scalars, arrays concatenate.\n * This ensures Maizzle's critical settings (middlewareMode, appType,\n * etc.) always win, while user plugins and other options remain.\n */\n const finalConfig = userViteConfig\n ? mergeConfig(userViteConfig, maizzleConfig)\n : maizzleConfig\n\n const server = await createServer(finalConfig)\n\n return {\n async render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n /**\n * String input goes through Vite — must use ssrLoadModule for\n * injection keys so they share the same module instance as SFC.\n */\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n component = (await server.ssrLoadModule(input)).default\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n\n // Register user Vue plugins, directives, and global properties\n if (config.vue) {\n const plugins = typeof config.vue.plugins === 'function'\n ? config.vue.plugins()\n : config.vue.plugins ?? []\n for (const plugin of plugins) {\n app.use(plugin)\n }\n for (const [name, directive] of Object.entries(config.vue.directives ?? {})) {\n app.directive(name, directive)\n }\n Object.assign(app.config.globalProperties, config.vue.globalProperties)\n }\n\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n const ssrContext: Record<string, any> = {}\n let html: string = await renderToString(app, ssrContext)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = head.render()\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n // Inject SSR teleport content into their target elements\n const hasTeleports = ssrContext.teleports && Object.keys(ssrContext.teleports).length > 0\n const hasFonts = (renderContext.fonts?.length ?? 0) > 0\n\n if (hasTeleports || hasFonts) {\n const { parse: parseDom, serialize: serializeDom, walk } = await import('../utils/ast/index.ts')\n let dom = parseDom(html)\n\n if (hasTeleports) {\n for (const [rawTarget, content] of Object.entries(ssrContext.teleports) as [string, string][]) {\n if (!content) continue\n\n const prepend = rawTarget.endsWith(':start')\n const target = prepend ? rawTarget.slice(0, -6) : rawTarget\n const targetChildren = parseDom(content)\n\n walk(dom, (node) => {\n const el = node as import('domhandler').Element\n\n if (!el.name) return\n\n const matched\n = target === el.name\n || (target.startsWith('#') && el.attribs?.id === target.slice(1))\n || (target.startsWith('.') && el.attribs?.class?.split(/\\s+/).includes(target.slice(1)))\n\n if (matched) {\n for (const child of targetChildren) {\n child.parent = el as any\n }\n\n el.children = prepend\n ? [...targetChildren, ...(el.children || [])] as any\n : [...(el.children || []), ...targetChildren] as any\n }\n })\n }\n }\n\n if (hasFonts) {\n const { injectFonts } = await import('./injectFonts.ts')\n injectFonts(dom, renderContext.fonts!, parseDom, walk)\n }\n\n html = serializeDom(dom)\n }\n\n // Inject preheader text from usePreheader() composable\n if (renderContext.preheader) {\n const { text, fillerCount } = renderContext.preheader\n const filler = '\\u2007\\uFEFF\\u034F '.repeat(fillerCount)\n const previewHtml = `<div style=\"display:none\">${text}${filler}\\u00A0</div>`\n html = html.replace(/<body([^>]*)>/, `<body$1>${previewHtml}`)\n }\n\n /**\n * Strip Vue SSR fragment markers + teleport anchor comments. These\n * are rendering hygiene, not transformer concerns — must run\n * regardless of `useTransformers` state. Fragment markers contain\n * `-->`, which would prematurely terminate MSO conditional\n * comments downstream.\n */\n html = html\n .replaceAll('<!--[-->', '')\n .replaceAll('<!--]-->', '')\n .replaceAll('<!--teleport start anchor-->', '')\n .replaceAll('<!--teleport anchor-->', '')\n .replaceAll('<!--teleport start-->', '')\n .replaceAll('<!--teleport end-->', '')\n\n return {\n html,\n doctype: renderContext.doctype,\n /**\n * Layer sfcConfig over config — sfcConfig is a partial override\n * emitted by composables (defineConfig, useTransformers, etc.).\n * A naive replacement (`sfcConfig ?? config`) drops defaults\n * from the resolved config when the SFC only sets a single\n * key, since the composables' inject() of globalConfig can\n * return `{}` in dev when ssrLoadModule and the SFC's\n * auto-imported module resolve to different module\n * instances (different Symbols).\n */\n templateConfig: renderContext.sfcConfig ? merge(renderContext.sfcConfig, config) : config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n outputPath: renderContext.outputPath,\n tailwindBlocks: renderContext.tailwindBlocks,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async invalidateAll(): Promise<void> {\n for (const mod of server.moduleGraph.idToModuleMap.values()) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n /**\n * unplugin-auto-import schedules a 500ms-throttled, fire-and-forget\n * d.ts write on its first scan. server.close() doesn't drain that\n * pending write, so callers tearing down the working dir right\n * after close (tests, ephemeral build pipelines) can race the\n * mkdir against a missing parent directory. Wait one throttle\n * window past close so the lingering write resolves while\n * the dir still exists.\n */\n if (dts) {\n await new Promise(resolve => setTimeout(resolve, 600))\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;AAExD,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,QAAQ,kBAAkB,CAAC,CAAC;AAChF,MAAM,0BAA0B,QAAQ,cAAc,OAAO,KAAK,QAAQ,mCAAmC,CAAC,CAAC;AAC/G,MAAM,kBAAkB,QAAQ,QAAQ,cAAc,OAAO,KAAK,QAAQ,aAAa,CAAC,CAAC,GAAG,IAAI;AAChG,MAAM,kBAAkB,QAAQ,cAAc,OAAO,KAAK,QAAQ,yBAAyB,CAAC,CAAC;;;;;;;AAyC7F,eAAsB,eACpB,UAAiC,CAAC,GACf;CACnB,MAAM,EAAE,MAAM,OAAO,UAAU,oBAAoB,OAAO,QAAQ,IAAI,GAAG,gBAAgB,CAAC,GAAG,MAAM,mBAAmB;CACtH,MAAM,EAAE,aAAa,gBAAgB,GAAG,oBAAoB,sBAAsB,CAAC;;;;;;CAOnF,MAAM,aAAa,cAAc,QAAO,MAAK,EAAE,WAAW,KAAA,CAAS;CACnE,MAAM,kBAAkB,cAAc,QAAO,MAAK,EAAE,WAAW,KAAA,CAAS;;;;;CAMxE,MAAM,mBAAmB,CAAC,QAAQ,MAAM,YAAY,GAAG,GAAG,cAAc,KAAI,MAAK,EAAE,IAAI,CAAC;CAExF,MAAM,SAAS,UAAU,IACrB,QAAQ,QAAQ,IAAI,GAAG,4BAA4B,IACnD,QAAQ,MAAM,UAAU;;;;;;;;;CAU5B,MAAM,yBAAyB,QAAQ,WAAW,eAAe;CAEjE,SAAS,uBAAuB,KAA0B;EACxD,IAAI,CAAC,WAAW,GAAG,GAAG,uBAAO,IAAI,IAAI;EACrC,MAAM,QAAQ,SAAS,CAAC,SAAS,MA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,MAAM,OAAO;KACrC,YAAY,KAAK,cAAc,OAAQ,UAAU,IAAI;IACvD;IAEA,OAAO,aAAa,GAAG;GACzB;GAGA,IAAI,cAAc,WAAW;IAC3B,MAAM,EAAE,MAAM,gBAAgB,cAAc;IAE5C,MAAM,cAAc,6BAA6B,OADlC,OAAsB,OAAO,WACiB,EAAE;IAC/D,OAAO,KAAK,QAAQ,iBAAiB,WAAW,aAAa;GAC/D;;;;;;;;GASA,OAAO,KACJ,WAAW,YAAY,EAAE,CAAC,CAC1B,WAAW,YAAY,EAAE,CAAC,CAC1B,WAAW,gCAAgC,EAAE,CAAC,CAC9C,WAAW,0BAA0B,EAAE,CAAC,CACxC,WAAW,yBAAyB,EAAE,CAAC,CACvC,WAAW,uBAAuB,EAAE;GAEvC,OAAO;IACL;IACA,SAAS,cAAc;;;;;;;;;;;IAWvB,gBAAgB,cAAc,YAAYA,OAAM,cAAc,WAAW,MAAM,IAAI;IACnF,kBAAkB,cAAc;IAChC,WAAW,cAAc;IACzB,YAAY,cAAc;IAC1B,gBAAgB,cAAc;GAChC;EACF;EAEA,MAAM,WAAW,UAAiC;GAChD,MAAM,MAAM,MAAM,OAAO,YAAY,eAAe,QAAQ;GAC5D,IAAI,KACF,OAAO,YAAY,iBAAiB,GAAG;EAE3C;EAEA,MAAM,gBAA+B;GACnC,KAAK,MAAM,OAAO,OAAO,YAAY,cAAc,OAAO,GACxD,OAAO,YAAY,iBAAiB,GAAG;EAE3C;EAEA,MAAM,QAAuB;GAC3B,MAAM,OAAO,MAAM;;;;;;;;;;GAUnB,IAAI,KACF,MAAM,IAAI,SAAQ,YAAW,WAAW,SAAS,GAAG,CAAC;EAEzD;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"createRenderer.js","names":["relPath","merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, relative as relPath, resolve } from 'node:path'\nimport { mkdirSync, writeFileSync, existsSync, rmSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { isLaravel } from '../utils/detect.ts'\nimport { rowSourceLocation } from './plugins/rowSourceLocation.ts'\nimport { rawExtract } from './plugins/rawExtract.ts'\nimport { codeBlockExtract } from './plugins/codeBlockExtract.ts'\nimport { markdownExtract } from './plugins/markdownExtract.ts'\nimport { createServer, mergeConfig, type InlineConfig, type Plugin } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { glob, globSync } from 'tinyglobby'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport { componentNameFromPath, type NormalizedComponentSource } from '../utils/componentSources.ts'\nimport { shikiToCodeBlock } from '../components/utils.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig, MarkdownConfig } from '../types/index.ts'\nimport type { MarkdownExit } from 'markdown-exit'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n outputPath?: RenderContext['outputPath']\n tailwindBlocks?: RenderContext['tailwindBlocks']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig, opts?: { source?: string }): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n invalidateAll(): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownConfig\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n /**\n * Additional component sources to register for auto-import. Already\n * normalized — pass through `normalizeComponentSources()` first.\n */\n componentDirs?: NormalizedComponentSource[]\n /** User Vite config options to merge into the internal SSR server */\n vite?: InlineConfig\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptionsRaw, root = process.cwd(), componentDirs = [], vite: userViteConfig } = options\n const { shikiTheme = 'github-light', ...markdownOptions } = markdownOptionsRaw ?? {}\n\n /**\n * Sources without an explicit prefix get registered via unplugin's `dirs`\n * (folder name auto-namespaces). Sources with an explicit `prefix` are\n * registered through a custom resolver below so we fully control naming.\n */\n const dirSources = componentDirs.filter(s => s.prefix === undefined)\n const prefixedSources = componentDirs.filter(s => s.prefix !== undefined)\n\n /**\n * Absolute component dirs — used to skip auto-wrapping `.md` files that\n * are imported as reusable components (vs. entry-point email templates).\n */\n const componentDirsAbs = [resolve(root, 'components'), ...componentDirs.map(s => s.path)]\n\n const dtsDir = isLaravel()\n ? resolve(process.cwd(), 'resources/js/types/maizzle')\n : resolve(root, '.maizzle')\n\n /**\n * Built-in framework components live at this path. When a user provides\n * a top-level file with the same (PascalCased) basename, drop the\n * built-in from unplugin's scan so the user's component is the only\n * candidate. This avoids the \"naming conflicts\" warning and the\n * alphabetical-glob ordering pitfall that decides who wins when\n * both are present in `dirs`.\n */\n const frameworkComponentsDir = resolve(__dirname, '../components')\n\n function topLevelBasenamesLower(dir: string): Set<string> {\n if (!existsSync(dir)) return new Set()\n const files = globSync(['*.vue', '*.md'], { cwd: dir, absolute: false })\n return new Set(files.map(f => f.replace(/\\.(vue|md)$/, '').toLowerCase()))\n }\n\n const frameworkFiles = globSync(['*.vue', '*.md'], { cwd: frameworkComponentsDir, absolute: false })\n const frameworkByLower = new Map(\n frameworkFiles.map(f => [f.replace(/\\.(vue|md)$/, '').toLowerCase(), f]),\n )\n\n const shadowedNames = new Set<string>()\n for (const dir of [resolve(root, 'components'), ...dirSources.map(s => s.path)]) {\n for (const lower of topLevelBasenamesLower(dir)) {\n if (frameworkByLower.has(lower)) shadowedNames.add(lower)\n }\n }\n\n const frameworkExcludes = [...shadowedNames]\n .map(lower => `${frameworkComponentsDir}/${frameworkByLower.get(lower)}`)\n\n /**\n * Pre-scanned name → absolute-path map for prefixed sources. Rebuilt\n * on file add/unlink via the watcher hook plugin further down. Drives\n * the runtime resolver and the d.ts we emit for IDE autocompletion.\n */\n const prefixedNameMap = new Map<string, string>()\n\n async function scanPrefixedSources(): Promise<void> {\n prefixedNameMap.clear()\n const seen = new Map<string, string>()\n for (const source of prefixedSources) {\n const files = await glob(['**/*.vue', '**/*.md'], { cwd: source.path, absolute: true })\n for (const file of files) {\n const name = componentNameFromPath({\n filePath: file,\n dirRoot: source.path,\n prefix: source.prefix,\n pathPrefix: source.pathPrefix,\n })\n const existing = seen.get(name)\n if (existing && existing !== file) {\n throw new Error(\n `[maizzle] Component name collision: \"${name}\" resolved from both \"${existing}\" and \"${file}\". `\n + 'Rename one of the files or split them into separate sources with distinct prefixes.',\n )\n }\n seen.set(name, file)\n prefixedNameMap.set(name, file)\n }\n }\n }\n\n await scanPrefixedSources()\n\n const prefixedResolver = (name: string) => prefixedNameMap.get(name)\n\n /**\n * unplugin-vue-components' own d.ts only covers components found via\n * `dirs`; its `types` option emits named-import entries which break\n * for SFC `default` exports. Write a sibling d.ts for prefixed\n * sources so editors get correct autocompletion via TypeScript\n * interface merging on `vue.GlobalComponents`.\n */\n const prefixedDtsPath = resolve(dtsDir, 'prefixed-components.d.ts')\n\n function writePrefixedDts(): void {\n if (!dts) return\n if (prefixedNameMap.size === 0) {\n if (existsSync(prefixedDtsPath)) rmSync(prefixedDtsPath)\n return\n }\n const dtsBase = dirname(prefixedDtsPath)\n mkdirSync(dtsBase, { recursive: true })\n const lines = Array.from(prefixedNameMap.entries())\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, file]) => {\n const relativePath = relPath(dtsBase, file).replace(/\\\\/g, '/')\n const importPath = relativePath.startsWith('.') ? relativePath : `./${relativePath}`\n return ` ${name}: typeof import('${importPath}')['default']`\n })\n .join('\\n')\n writeFileSync(\n prefixedDtsPath,\n `/* eslint-disable */\\n// @ts-nocheck\\n// biome-ignore lint: disable\\n// oxlint-disable\\n// Generated by Maizzle for prefixed component sources\\n\\nexport {}\\n\\n/* prettier-ignore */\\ndeclare module 'vue' {\\n export interface GlobalComponents {\\n${lines}\\n }\\n}\\n`,\n )\n }\n\n writePrefixedDts()\n\n /**\n * Watches prefixed source dirs and rebuilds {@link prefixedNameMap} when\n * files are added/removed. Vite's watcher already covers `dirSources`\n * via unplugin-vue-components' own filesystem hooks.\n */\n const prefixedSourceWatcher: Plugin | null = prefixedSources.length > 0\n ? {\n name: 'maizzle:prefixed-component-watcher',\n configureServer(server) {\n for (const source of prefixedSources) {\n server.watcher.add(source.path)\n }\n const refresh = async (file: string) => {\n if (!prefixedSources.some(s => file.startsWith(`${s.path}/`))) return\n if (!/\\.(vue|md)$/.test(file)) return\n await scanPrefixedSources()\n writePrefixedDts()\n }\n server.watcher.on('add', refresh)\n server.watcher.on('unlink', refresh)\n },\n }\n : null\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n /**\n * Per-render source overrides keyed by absolute template path. Lets the\n * build's beforeRender event rewrite a template's source before compile\n * while keeping the real file id — so relative imports, asset URLs and\n * component resolution still resolve against the actual file location\n * (which the virtual-SFC path can't do).\n */\n const sourceOverrides = new Map<string, string>()\n\n /**\n * Never load the host project's vite.config.ts here. Doing so pulls\n * every host plugin (Nitro, TanStack Start, the Maizzle plugin\n * itself, …) into this isolated SSR pipeline, where they override\n * env factories, re-trigger configureServer hooks, and break\n * Vite's hot channel wiring. Users who need extra Vite plugins\n * for SSR pass them explicitly via the `vite` option.\n */\n const maizzleConfig: InlineConfig = {\n configFile: false,\n plugins: [\n rawExtract(),\n codeBlockExtract(),\n markdownExtract(),\n rowSourceLocation(),\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n {\n name: 'maizzle:source-override',\n load(id) {\n const override = sourceOverrides.get(id.split('?')[0])\n if (override !== undefined) return override\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n compilerOptions: {\n /**\n * AMP4Email tags (<amp-carousel>, <amp-img>, <amp-list> ...)\n * render verbatim — skip the component resolver. Users who\n * want to wrap an amp tag in a Vue component should register\n * it under a PascalCase name (e.g. `components/AmpCarousel.vue`\n * → `<AmpCarousel>`).\n */\n isCustomElement: (tag: string) => tag.startsWith('amp-'),\n },\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n wrapperClasses: 'prose',\n wrapperComponent: (id: string, raw: string) => {\n const fm = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---/)?.[1]\n const layout = fm?.match(/^[ \\t]*layout[ \\t]*:[ \\t]*['\"]?([A-Za-z][\\w-]*|false|none)['\"]?[ \\t]*$/m)?.[1]\n if (layout === 'false' || layout === 'none') return null\n if (layout) return layout\n /**\n * No `layout:` set — default to the built-in `MarkdownLayout`\n * for entry-template `.md` files. Skip for `.md` files inside\n * component dirs, which are reusable fragments imported into\n * other templates.\n */\n const inComponentDir = componentDirsAbs.some(d => id === d || id.startsWith(`${d}/`))\n return inComponentDir ? null : 'MarkdownLayout'\n },\n markdownOptions: {\n async highlight(code: string, lang: string) {\n const { codeToHtml } = await import('shiki')\n return codeToHtml(code, { lang, theme: shikiTheme })\n },\n },\n markdownSetup(md: MarkdownExit) {\n const defaultFence = md.renderer.rules.fence!\n md.renderer.rules.fence = (...args) =>\n Promise.resolve(defaultFence(...args)).then(shikiToCodeBlock)\n\n const defaultCodeBlock = md.renderer.rules.code_block!\n md.renderer.rules.code_block = (...args) => shikiToCodeBlock(defaultCodeBlock(...args) as string)\n },\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n /**\n * unplugin-auto-import's default `include` doesn't match `.md`, so\n * auto-imports (Vue, unhead and Maizzle composables/filters) were\n * never injected into Markdown templates — `useConfig()` and friends\n * threw at runtime. Extend the default list with `.md` (and its\n * `?vue` script sub-requests) to mirror the `.md` coverage the\n * Components plugin already declares below.\n */\n include: [/\\.[jt]sx?$/, /\\.vue$/, /\\.vue\\?vue/, /\\.md$/, /\\.md\\?vue/],\n dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n frameworkComponentsDir,\n resolve(root, 'components'),\n ...dirSources.map(s => s.path),\n ],\n /**\n * Drop built-in component files whose name the user has shadowed.\n * This makes the user's version the only match — no \"naming\n * conflicts\" warning, no glob-ordering games.\n */\n globsExclude: frameworkExcludes,\n directoryAsNamespace: true,\n collapseSamePrefixes: true,\n resolvers: prefixedSources.length > 0 ? [prefixedResolver] : undefined,\n dts: dts ? resolve(dtsDir, 'components.d.ts') : false,\n }),\n ...(prefixedSourceWatcher ? [prefixedSourceWatcher] : []),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n /**\n * Watcher is required so unplugin-vue-components and unplugin-auto-import\n * detect added/removed component files and rewrite their .d.ts on the fly.\n * (We only render via SSR — HMR is off, but chokidar still drives plugins.)\n */\n fs: {\n allow: [process.cwd(), root, ...componentDirs.map(s => s.path), vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n }\n\n /**\n * Merge user's vite config (from config.vite) under Maizzle's config.\n * mergeConfig(a, b) → b overrides a for scalars, arrays concatenate.\n * This ensures Maizzle's critical settings (middlewareMode, appType,\n * etc.) always win, while user plugins and other options remain.\n */\n const finalConfig = userViteConfig\n ? mergeConfig(userViteConfig, maizzleConfig)\n : maizzleConfig\n\n const server = await createServer(finalConfig)\n\n return {\n async render(input: string | Component, config: MaizzleConfig, opts?: { source?: string }): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n /**\n * String input goes through Vite — must use ssrLoadModule for\n * injection keys so they share the same module instance as SFC.\n */\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n /**\n * A beforeRender handler may have rewritten the source. Register it\n * under the real path id and invalidate so ssrLoadModule compiles\n * the override; clear + invalidate afterwards so the override never\n * leaks into a later render of the same path.\n */\n const hasOverride = opts?.source !== undefined\n if (hasOverride) {\n sourceOverrides.set(input, opts!.source!)\n const mod = await server.moduleGraph.getModuleByUrl(input)\n if (mod) server.moduleGraph.invalidateModule(mod)\n }\n try {\n component = (await server.ssrLoadModule(input)).default\n } finally {\n if (hasOverride) {\n sourceOverrides.delete(input)\n const mod = await server.moduleGraph.getModuleByUrl(input)\n if (mod) server.moduleGraph.invalidateModule(mod)\n }\n }\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n\n // Register user Vue plugins, directives, and global properties\n if (config.vue) {\n const plugins = typeof config.vue.plugins === 'function'\n ? config.vue.plugins()\n : config.vue.plugins ?? []\n for (const plugin of plugins) {\n app.use(plugin)\n }\n for (const [name, directive] of Object.entries(config.vue.directives ?? {})) {\n app.directive(name, directive)\n }\n Object.assign(app.config.globalProperties, config.vue.globalProperties)\n }\n\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n const ssrContext: Record<string, any> = {}\n let html: string = await renderToString(app, ssrContext)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = head.render()\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n // Inject SSR teleport content into their target elements\n const hasTeleports = ssrContext.teleports && Object.keys(ssrContext.teleports).length > 0\n const hasFonts = (renderContext.fonts?.length ?? 0) > 0\n\n if (hasTeleports || hasFonts) {\n const { parse: parseDom, serialize: serializeDom, walk } = await import('../utils/ast/index.ts')\n let dom = parseDom(html)\n\n if (hasTeleports) {\n for (const [rawTarget, content] of Object.entries(ssrContext.teleports) as [string, string][]) {\n if (!content) continue\n\n const prepend = rawTarget.endsWith(':start')\n const target = prepend ? rawTarget.slice(0, -6) : rawTarget\n const targetChildren = parseDom(content)\n\n walk(dom, (node) => {\n const el = node as import('domhandler').Element\n\n if (!el.name) return\n\n const matched\n = target === el.name\n || (target.startsWith('#') && el.attribs?.id === target.slice(1))\n || (target.startsWith('.') && el.attribs?.class?.split(/\\s+/).includes(target.slice(1)))\n\n if (matched) {\n for (const child of targetChildren) {\n child.parent = el as any\n }\n\n el.children = prepend\n ? [...targetChildren, ...(el.children || [])] as any\n : [...(el.children || []), ...targetChildren] as any\n }\n })\n }\n }\n\n if (hasFonts) {\n const { injectFonts } = await import('./injectFonts.ts')\n injectFonts(dom, renderContext.fonts!, parseDom, walk)\n }\n\n html = serializeDom(dom)\n }\n\n // Inject preheader text from usePreheader() composable\n if (renderContext.preheader) {\n const { text, fillerCount } = renderContext.preheader\n const filler = '\\u2007\\uFEFF\\u034F '.repeat(fillerCount)\n const previewHtml = `<div style=\"display:none\">${text}${filler}\\u00A0</div>`\n html = html.replace(/<body([^>]*)>/, `<body$1>${previewHtml}`)\n }\n\n /**\n * Strip Vue SSR fragment markers + teleport anchor comments. These\n * are rendering hygiene, not transformer concerns — must run\n * regardless of `useTransformers` state. Fragment markers contain\n * `-->`, which would prematurely terminate MSO conditional\n * comments downstream.\n */\n html = html\n .replaceAll('<!--[-->', '')\n .replaceAll('<!--]-->', '')\n .replaceAll('<!--teleport start anchor-->', '')\n .replaceAll('<!--teleport anchor-->', '')\n .replaceAll('<!--teleport start-->', '')\n .replaceAll('<!--teleport end-->', '')\n\n return {\n html,\n doctype: renderContext.doctype,\n /**\n * Layer sfcConfig over config — sfcConfig is a partial override\n * emitted by composables (defineConfig, useTransformers, etc.).\n * A naive replacement (`sfcConfig ?? config`) drops defaults\n * from the resolved config when the SFC only sets a single\n * key, since the composables' inject() of globalConfig can\n * return `{}` in dev when ssrLoadModule and the SFC's\n * auto-imported module resolve to different module\n * instances (different Symbols).\n */\n templateConfig: renderContext.sfcConfig ? merge(renderContext.sfcConfig, config) : config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n outputPath: renderContext.outputPath,\n tailwindBlocks: renderContext.tailwindBlocks,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async invalidateAll(): Promise<void> {\n for (const mod of server.moduleGraph.idToModuleMap.values()) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n /**\n * unplugin-auto-import schedules a 500ms-throttled, fire-and-forget\n * d.ts write on its first scan. server.close() doesn't drain that\n * pending write, so callers tearing down the working dir right\n * after close (tests, ephemeral build pipelines) can race the\n * mkdir against a missing parent directory. Wait one throttle\n * window past close so the lingering write resolves while\n * the dir still exists.\n */\n if (dts) {\n await new Promise(resolve => setTimeout(resolve, 600))\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;AAExD,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,QAAQ,kBAAkB,CAAC,CAAC;AAChF,MAAM,0BAA0B,QAAQ,cAAc,OAAO,KAAK,QAAQ,mCAAmC,CAAC,CAAC;AAC/G,MAAM,kBAAkB,QAAQ,QAAQ,cAAc,OAAO,KAAK,QAAQ,aAAa,CAAC,CAAC,GAAG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|
import { resolveConfig } from "../config/index.js";
|
|
2
|
-
import { runTransformers } from "../transformers/index.js";
|
|
3
2
|
import { normalizeComponentSources } from "../utils/componentSources.js";
|
|
4
3
|
import { createRenderer } from "./createRenderer.js";
|
|
4
|
+
import { runTransformers } from "../transformers/index.js";
|
|
5
5
|
import { createPlaintext } from "../plaintext.js";
|
|
6
6
|
import { stripForHtml, stripForPlaintext } from "../utils/output-markers.js";
|
|
7
7
|
import { getActiveRenderer } from "./active.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MaizzleConfig } from "../../types/config.js";
|
|
2
|
+
//#region src/render/parallel/buildWorker.d.ts
|
|
3
|
+
interface BuildWorkerData {
|
|
4
|
+
/** Template paths (glob-relative, as produced on the main thread) for this batch. */
|
|
5
|
+
templatePaths: string[];
|
|
6
|
+
/** Config file path to reload (undefined → load maizzle.config from cwd). */
|
|
7
|
+
configPath?: string;
|
|
8
|
+
/** Serialized, post-beforeCreate config data from the main thread. */
|
|
9
|
+
configData: Partial<MaizzleConfig>;
|
|
10
|
+
outputPath: string;
|
|
11
|
+
outputExtension: string;
|
|
12
|
+
contentBase: string;
|
|
13
|
+
}
|
|
14
|
+
interface BuildWorkerResult {
|
|
15
|
+
files: string[];
|
|
16
|
+
sfcAfterBuildCount: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build one batch of templates in a worker thread.
|
|
20
|
+
*
|
|
21
|
+
* Config function hooks (beforeRender/afterRender/afterTransform) can't cross
|
|
22
|
+
* the thread boundary, so the worker reloads the config module to recover them,
|
|
23
|
+
* then overlays the main thread's serialized config DATA on top — so
|
|
24
|
+
* beforeCreate mutations and resolved values win while the reloaded config only
|
|
25
|
+
* backfills the lost functions. beforeCreate/afterBuild are owned by the main
|
|
26
|
+
* thread and never run here.
|
|
27
|
+
*/
|
|
28
|
+
declare function run(data: BuildWorkerData): Promise<BuildWorkerResult>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { BuildWorkerData, BuildWorkerResult, run };
|
|
31
|
+
//# sourceMappingURL=buildWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWorker.d.ts","names":[],"sources":["../../../src/render/parallel/buildWorker.ts"],"mappings":";;UAQiB,eAAA;;EAEf,aAAA;EAFe;EAIf,UAAA;;EAEA,UAAA,EAAY,OAAO,CAAC,aAAA;EACpB,UAAA;EACA,eAAA;EACA,WAAA;AAAA;AAAA,UAGe,iBAAA;EACf,KAAA;EACA,kBAAkB;AAAA;;AALP;AAGb;;;;AAEoB;AAyBpB;;;iBAAsB,GAAA,CAAI,IAAA,EAAM,eAAA,GAAkB,OAAA,CAAQ,iBAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { resolveConfig } from "../../config/index.js";
|
|
2
|
+
import { EventManager } from "../../events/index.js";
|
|
3
|
+
import { normalizeComponentSources } from "../../utils/componentSources.js";
|
|
4
|
+
import { createRenderer } from "../createRenderer.js";
|
|
5
|
+
import { buildTemplate } from "../buildTemplate.js";
|
|
6
|
+
import { createDefu } from "defu";
|
|
7
|
+
//#region src/render/parallel/buildWorker.ts
|
|
8
|
+
/**
|
|
9
|
+
* Overlay config data with array-replace (not defu's default concat) so the
|
|
10
|
+
* main thread's arrays — content globs, plugin/source lists — fully replace the
|
|
11
|
+
* reloaded config's instead of duplicating every entry.
|
|
12
|
+
*/
|
|
13
|
+
const mergeConfig = createDefu((obj, key, value) => {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
if (!(key in obj)) obj[key] = value;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Build one batch of templates in a worker thread.
|
|
21
|
+
*
|
|
22
|
+
* Config function hooks (beforeRender/afterRender/afterTransform) can't cross
|
|
23
|
+
* the thread boundary, so the worker reloads the config module to recover them,
|
|
24
|
+
* then overlays the main thread's serialized config DATA on top — so
|
|
25
|
+
* beforeCreate mutations and resolved values win while the reloaded config only
|
|
26
|
+
* backfills the lost functions. beforeCreate/afterBuild are owned by the main
|
|
27
|
+
* thread and never run here.
|
|
28
|
+
*/
|
|
29
|
+
async function run(data) {
|
|
30
|
+
const { templatePaths, configPath, configData, outputPath, outputExtension, contentBase } = data;
|
|
31
|
+
const config = mergeConfig(configData, await resolveConfig(configPath));
|
|
32
|
+
const events = new EventManager();
|
|
33
|
+
events.registerConfig(config);
|
|
34
|
+
const renderer = await createRenderer({
|
|
35
|
+
markdown: config.markdown,
|
|
36
|
+
root: config.root,
|
|
37
|
+
componentDirs: normalizeComponentSources(config.components?.source, process.cwd()),
|
|
38
|
+
vite: config.vite
|
|
39
|
+
});
|
|
40
|
+
const files = [];
|
|
41
|
+
let sfcAfterBuildCount = 0;
|
|
42
|
+
try {
|
|
43
|
+
for (const templatePath of templatePaths) {
|
|
44
|
+
const result = await buildTemplate(templatePath, {
|
|
45
|
+
config,
|
|
46
|
+
renderer,
|
|
47
|
+
events,
|
|
48
|
+
outputPath,
|
|
49
|
+
outputExtension,
|
|
50
|
+
contentBase
|
|
51
|
+
});
|
|
52
|
+
files.push(...result.files);
|
|
53
|
+
sfcAfterBuildCount += result.sfcAfterBuildCount;
|
|
54
|
+
}
|
|
55
|
+
} finally {
|
|
56
|
+
await renderer.close();
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
files,
|
|
60
|
+
sfcAfterBuildCount
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { run };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=buildWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWorker.js","names":[],"sources":["../../../src/render/parallel/buildWorker.ts"],"sourcesContent":["import { createDefu } from 'defu'\nimport { resolveConfig } from '../../config/index.ts'\nimport { createRenderer } from '../createRenderer.ts'\nimport { EventManager } from '../../events/index.ts'\nimport { normalizeComponentSources } from '../../utils/componentSources.ts'\nimport { buildTemplate } from '../buildTemplate.ts'\nimport type { MaizzleConfig } from '../../types/index.ts'\n\nexport interface BuildWorkerData {\n /** Template paths (glob-relative, as produced on the main thread) for this batch. */\n templatePaths: string[]\n /** Config file path to reload (undefined → load maizzle.config from cwd). */\n configPath?: string\n /** Serialized, post-beforeCreate config data from the main thread. */\n configData: Partial<MaizzleConfig>\n outputPath: string\n outputExtension: string\n contentBase: string\n}\n\nexport interface BuildWorkerResult {\n files: string[]\n sfcAfterBuildCount: number\n}\n\n/**\n * Overlay config data with array-replace (not defu's default concat) so the\n * main thread's arrays — content globs, plugin/source lists — fully replace the\n * reloaded config's instead of duplicating every entry.\n */\nconst mergeConfig = createDefu((obj, key, value) => {\n if (Array.isArray(value)) {\n if (!(key in obj)) obj[key as keyof typeof obj] = value\n return true\n }\n})\n\n/**\n * Build one batch of templates in a worker thread.\n *\n * Config function hooks (beforeRender/afterRender/afterTransform) can't cross\n * the thread boundary, so the worker reloads the config module to recover them,\n * then overlays the main thread's serialized config DATA on top — so\n * beforeCreate mutations and resolved values win while the reloaded config only\n * backfills the lost functions. beforeCreate/afterBuild are owned by the main\n * thread and never run here.\n */\nexport async function run(data: BuildWorkerData): Promise<BuildWorkerResult> {\n const { templatePaths, configPath, configData, outputPath, outputExtension, contentBase } = data\n\n const reloaded = await resolveConfig(configPath)\n const config = mergeConfig(configData, reloaded) as MaizzleConfig\n\n const events = new EventManager()\n events.registerConfig(config)\n\n const renderer = await createRenderer({\n markdown: config.markdown,\n root: config.root,\n componentDirs: normalizeComponentSources(config.components?.source, process.cwd()),\n vite: config.vite,\n })\n\n const files: string[] = []\n let sfcAfterBuildCount = 0\n\n try {\n for (const templatePath of templatePaths) {\n const result = await buildTemplate(templatePath, {\n config,\n renderer,\n events,\n outputPath,\n outputExtension,\n contentBase,\n })\n files.push(...result.files)\n sfcAfterBuildCount += result.sfcAfterBuildCount\n }\n } finally {\n await renderer.close()\n }\n\n return { files, sfcAfterBuildCount }\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,cAAc,YAAY,KAAK,KAAK,UAAU;CAClD,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI,EAAE,OAAO,MAAM,IAAI,OAA2B;EAClD,OAAO;CACT;AACF,CAAC;;;;;;;;;;;AAYD,eAAsB,IAAI,MAAmD;CAC3E,MAAM,EAAE,eAAe,YAAY,YAAY,YAAY,iBAAiB,gBAAgB;CAG5F,MAAM,SAAS,YAAY,YAAY,MADhB,cAAc,UAAU,CACA;CAE/C,MAAM,SAAS,IAAI,aAAa;CAChC,OAAO,eAAe,MAAM;CAE5B,MAAM,WAAW,MAAM,eAAe;EACpC,UAAU,OAAO;EACjB,MAAM,OAAO;EACb,eAAe,0BAA0B,OAAO,YAAY,QAAQ,QAAQ,IAAI,CAAC;EACjF,MAAM,OAAO;CACf,CAAC;CAED,MAAM,QAAkB,CAAC;CACzB,IAAI,qBAAqB;CAEzB,IAAI;EACF,KAAK,MAAM,gBAAgB,eAAe;GACxC,MAAM,SAAS,MAAM,cAAc,cAAc;IAC/C;IACA;IACA;IACA;IACA;IACA;GACF,CAAC;GACD,MAAM,KAAK,GAAG,OAAO,KAAK;GAC1B,sBAAsB,OAAO;EAC/B;CACF,UAAU;EACR,MAAM,SAAS,MAAM;CACvB;CAEA,OAAO;EAAE;EAAO;CAAmB;AACrC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Tinypool worker entry. Plain JS so it loads in a raw worker thread without a
|
|
2
|
+
// TS toolchain. In the published dist the implementation is already compiled to
|
|
3
|
+
// `.js` and is imported natively (fast); during dev/tests only the `.ts` source
|
|
4
|
+
// exists and is loaded through jiti.
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
+
import { existsSync } from 'node:fs'
|
|
7
|
+
|
|
8
|
+
let implPromise
|
|
9
|
+
|
|
10
|
+
function loadImpl() {
|
|
11
|
+
if (!implPromise) {
|
|
12
|
+
const jsPath = fileURLToPath(new URL('./buildWorker.js', import.meta.url))
|
|
13
|
+
if (existsSync(jsPath)) {
|
|
14
|
+
implPromise = import(pathToFileURL(jsPath).href)
|
|
15
|
+
} else {
|
|
16
|
+
const tsPath = fileURLToPath(new URL('./buildWorker.ts', import.meta.url))
|
|
17
|
+
implPromise = import('jiti').then(({ createJiti }) =>
|
|
18
|
+
createJiti(fileURLToPath(import.meta.url)).import(tsPath),
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return implPromise
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default async function buildWorker(data) {
|
|
26
|
+
const impl = await loadImpl()
|
|
27
|
+
return impl.run(data)
|
|
28
|
+
}
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","names":[],"sources":["../src/serve.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"serve.d.ts","names":[],"sources":["../src/serve.ts"],"mappings":";;;;UAmDiB,YAAA;EACf,MAAA,GAAS,OAAO,CAAC,aAAA;;EAEjB,IAAA;EAH2B;EAK3B,IAAA;EAJgB;EAMhB,MAAA;AAAA;;;;;;AAAM;AAYR;;;iBAAsB,KAAA,CAAM,OAAA,GAAS,YAAA,GAAiB,OAAA,CAAA,aAAA;AAAA,iBA6lBtC,WAAA,CAAY,MAAA,EAAQ,aAAa,EAAE,WAAA"}
|