@blinkk/root 1.0.0-alpha.12 → 1.0.0-alpha.13
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/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -442,9 +442,9 @@ async function viteServerMiddleware(options) {
|
|
|
442
442
|
},
|
|
443
443
|
plugins: vitePlugins
|
|
444
444
|
});
|
|
445
|
-
return async (req,
|
|
445
|
+
return async (req, res, next) => {
|
|
446
446
|
req.viteServer = viteServer;
|
|
447
|
-
next
|
|
447
|
+
viteServer.middlewares(req, res, next);
|
|
448
448
|
};
|
|
449
449
|
}
|
|
450
450
|
function rootDevRendererMiddleware() {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/commands/dev.ts","../src/render/vite-plugin-root.ts","../src/core/fsutils.ts","../src/render/asset-map/dev-asset-map.ts","../src/cli/load-config.ts","../src/render/html-minify.ts","../src/core/middleware.ts","../src/cli/commands/build.ts","../src/render/asset-map/build-asset-map.ts","../src/cli/commands/preview.ts","../src/cli/commands/start.ts"],"sourcesContent":["import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {default as express} from 'express';\nimport {createServer as createViteServer} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {DevServerAssetMap} from '../../render/asset-map/dev-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {isDirectory, isJsFile} from '../../core/fsutils.js';\nimport glob from 'tiny-glob';\nimport {dim} from 'kleur/colors';\nimport {Server, Request, Response, NextFunction} from '../../core/types.js';\nimport {configureServerPlugins, getVitePlugins} from '../../core/plugin.js';\nimport {RootConfig} from '../../core/config.js';\nimport {rootProjectMiddleware} from '../../core/middleware.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function dev(rootProjectDir?: string) {\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: development`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options?: {rootDir?: string}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n\n const server = express();\n server.disable('x-powered-by');\n\n // Inject req context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await viteServerMiddleware({rootDir, rootConfig}));\n server.use(rootDevRendererMiddleware());\n\n const plugins = rootConfig.plugins || [];\n await configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n for (const middleware of userMiddlewares) {\n server.use(middleware);\n }\n // Add the root.js dev server middlewares.\n server.use(rootDevServerMiddleware());\n server.use(rootDevServer404Middleware());\n },\n plugins,\n {type: 'dev'}\n );\n\n return server;\n}\n\n/**\n * Middleware that initializes a vite server and injects it into the request\n * context.\n */\nasync function viteServerMiddleware(options: {\n rootDir: string;\n rootConfig: RootConfig;\n}) {\n const rootDir = options.rootDir;\n const rootConfig = options.rootConfig;\n const viteConfig = rootConfig.vite || {};\n\n const routeFiles: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob('routes/**/*', {cwd: rootDir});\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n routeFiles.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elements.push(moduleId.slice(1));\n }\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const vitePlugins = [\n pluginRoot({rootDir, rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ];\n\n const viteServer = await createViteServer({\n ...viteConfig,\n mode: 'development',\n root: rootDir,\n publicDir: path.join(rootDir, 'public'),\n server: {middlewareMode: true},\n appType: 'custom',\n optimizeDeps: {\n include: [\n ...routeFiles,\n ...elements,\n ...bundleScripts,\n ...(viteConfig.optimizeDeps?.include || []),\n ],\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: vitePlugins,\n });\n return async (req: Request, _: Response, next: NextFunction) => {\n req.viteServer = viteServer;\n next();\n };\n}\n\nfunction rootDevRendererMiddleware() {\n const renderModulePath = path.resolve(__dirname, './render.js');\n return async (req: Request, _: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const viteServer = req.viteServer!;\n // Dynamically import the render.js module using vite's SSR import loader.\n const render = await viteServer.ssrLoadModule(renderModulePath);\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(viteServer.moduleGraph);\n req.renderer = new render.Renderer(rootConfig, {assetMap});\n next();\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const url = req.originalUrl;\n const renderer = req.renderer!;\n const viteServer = req.viteServer!;\n const rootConfig = req.rootConfig!;\n try {\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n // Inject the Vite HMR client.\n let html = await viteServer.transformIndexHtml(url, data.html || '');\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n // If an error is caught, let Vite fix the stack trace so it maps back to\n // your actual source code.\n viteServer.ssrFixStacktrace(e);\n console.error(e);\n try {\n if (renderer) {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } else {\n next(e);\n }\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n\nfunction rootDevServer404Middleware() {\n return async (req: Request, res: Response) => {\n const url = req.originalUrl;\n const ext = path.extname(url);\n const renderer = req.renderer!;\n if (!ext) {\n const data = await renderer.renderDevServer404();\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n","import path from 'path';\nimport glob from 'tiny-glob';\nimport {RootConfig} from '../core/config';\nimport {isDirectory, isJsFile} from '../core/fsutils';\n\nconst JSX_ELEMENTS_REGEX = /jsxs?\\(\"(\\w[\\w-]+\\w)\"/g;\nconst HTML_ELEMENTS_REGEX = /<(\\w[\\w-]+\\w)/g;\n\nexport interface RootPluginOptions {\n rootDir: string;\n rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options?: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = options?.rootConfig || {};\n const elementsDirs = [path.join(rootDir, 'elements')];\n const includeDirs = rootConfig.elements?.include || [];\n includeDirs.forEach((dirPath) => {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n });\n\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n let elementMap: Record<string, string>;\n async function updateElementMap() {\n elementMap = {};\n await Promise.all(\n elementsDirs.map(async (dirPath: string) => {\n const dirExists = await isDirectory(dirPath);\n if (!dirExists) {\n return;\n }\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elementMap[parts.name] = moduleId;\n }\n }\n });\n })\n );\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!elementMap) {\n await updateElementMap();\n }\n if (tagname in elementMap) {\n return elementMap[tagname];\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return elementsDirs.some((elementsDir) => {\n return id.startsWith(elementsDir);\n });\n }\n\n return {\n name: 'vite-plugin-root',\n\n resolveId(id: string) {\n if (id === elementsVirtualId) {\n return resolvedElementsVirtualId;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === resolvedElementsVirtualId) {\n await updateElementMap();\n return `export const elementsMap = ${JSON.stringify(elementMap)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n const idParts = path.parse(id);\n const deps = new Set<string>();\n const tagnames = [\n ...src.matchAll(JSX_ELEMENTS_REGEX),\n ...src.matchAll(HTML_ELEMENTS_REGEX),\n ];\n for (const match of tagnames) {\n const tagname = match[1];\n // All custom elements should contain a dash.\n if (!tagname.includes('-')) {\n continue;\n }\n // Avoid circular deps.\n if (tagname === idParts.name) {\n continue;\n }\n deps.add(tagname);\n }\n const importUrls: string[] = [];\n await Promise.all(\n Array.from(deps).map(async (tagname) => {\n const importUrl = await getElementImport(tagname);\n if (importUrl) {\n importUrls.push(importUrl);\n }\n })\n );\n if (importUrls.length > 0) {\n const importLines = importUrls\n .map((url) => `import '${url}';`)\n .join('\\n');\n const code = `${src}\n\n// autogenerated by root:\n${importLines}\n`;\n return {code};\n }\n return null;\n }\n return null;\n },\n };\n}\n","import {promises as fs} from 'node:fs';\nimport path from 'node:path';\nimport fsExtra from 'fs-extra';\n\nexport function isJsFile(filename: string) {\n return !!filename.match(/\\.(j|t)sx?$/);\n}\n\nexport async function writeFile(filepath: string, content: string) {\n const dirPath = path.dirname(filepath);\n await makeDir(dirPath);\n await fs.writeFile(filepath, content);\n}\n\nexport async function makeDir(dirpath: string) {\n try {\n await fs.access(dirpath);\n } catch (e) {\n await fs.mkdir(dirpath, {recursive: true});\n }\n}\n\nexport async function copyDir(srcdir: string, dstdir: string) {\n if (!fsExtra.existsSync(srcdir)) {\n return;\n }\n fsExtra.copySync(srcdir, dstdir, {recursive: true, overwrite: true});\n}\n\nexport async function rmDir(dirpath: string) {\n await fs.rm(dirpath, {recursive: true, force: true});\n}\n\nexport async function loadJson<T = unknown>(filepath: string): Promise<T> {\n const content = await fs.readFile(filepath, 'utf-8');\n return JSON.parse(content);\n}\n\nexport async function isDirectory(dirpath: string) {\n return fs\n .stat(dirpath)\n .then((fsStat) => {\n return fsStat.isDirectory();\n })\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return false;\n }\n throw err;\n });\n}\n\nexport function fileExists(filepath: string): Promise<boolean> {\n return fs\n .access(filepath)\n .then(() => true)\n .catch(() => false);\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private moduleGraph: ModuleGraph;\n\n constructor(moduleGraph: ModuleGraph) {\n this.moduleGraph = moduleGraph;\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n const viteModule = await this.moduleGraph.getModuleByUrl(moduleId);\n if (!viteModule || !viteModule.id) {\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n return {\n moduleId: moduleId,\n assetUrl: moduleId,\n getCssDeps: async () => [],\n getJsDeps: async () => [moduleId],\n };\n }\n return new DevServerAsset(this, viteModule);\n }\n}\n\nexport class DevServerAsset implements Asset {\n moduleId: string;\n assetUrl: string;\n private assetMap: AssetMap;\n private viteModule: ModuleNode;\n\n constructor(assetMap: AssetMap, viteModule: ModuleNode) {\n this.assetMap = assetMap;\n this.viteModule = viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.moduleId.endsWith('.scss')) {\n const parts = path.parse(asset.assetUrl);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {bundleRequire} from 'bundle-require';\nimport JoyCon from 'joycon';\nimport {RootConfig} from '../core/config';\n\nexport async function loadRootConfig(rootDir: string): Promise<RootConfig> {\n const joycon = new JoyCon();\n const configPath = await joycon.resolve({\n cwd: rootDir,\n files: ['root.config.ts'],\n });\n if (configPath) {\n const configBundle = await bundleRequire({\n filepath: configPath,\n });\n return configBundle.mod.default || {};\n }\n return {};\n}\n","import {minify} from 'html-minifier-terser';\n\nexport async function htmlMinify(html: string): Promise<string> {\n try {\n const min = await minify(html, {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n });\n return min.trimStart();\n } catch (e) {\n console.error('failed to minify html:', e);\n return html;\n }\n}\n","import {RootConfig} from './config';\nimport {Request, Response, NextFunction} from './types';\n\n/**\n * Middleware that injects the root.js project config into the request context.\n */\nexport function rootProjectMiddleware(options: {\n rootDir: string;\n rootConfig: RootConfig;\n}) {\n return (req: Request, _: Response, next: NextFunction) => {\n req.rootConfig = Object.assign({}, options.rootConfig, {\n rootDir: options.rootDir,\n });\n next();\n };\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport fsExtra from 'fs-extra';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, UserConfig} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {\n copyDir,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../core/fsutils.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {dim} from 'kleur/colors';\nimport {getVitePlugins} from '../../core/plugin.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\ninterface BuildOptions {\n ssrOnly?: boolean;\n mode?: string;\n}\n\nexport async function build(rootProjectDir?: string, options?: BuildOptions) {\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n const ssrOnly = options?.ssrOnly || false;\n const mode = options?.mode || 'production';\n\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} output: ${distDir}/html`);\n console.log(`${dim('┃')} mode: ${mode}`);\n console.log();\n\n await rmDir(distDir);\n await makeDir(distDir);\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n const elementMap: Record<string, string> = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elements.push(fullPath);\n elementMap[parts.name] = moduleId;\n }\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n pluginRoot({rootDir, rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ];\n\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n mode: mode,\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: vitePlugins,\n };\n\n // Bundle the render.js file with vite, which is pre-optimized for rendering\n // HTML routes.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n rollupOptions: {\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n });\n\n // Pre-render any client scripts and CSS deps.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n rollupOptions: {\n input: [...pages, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n });\n\n const viteManifest = await loadJson<Manifest>(\n path.join(distDir, 'client/manifest.json')\n );\n\n // Use the output of the client build to generate an asset map, which is used\n // by the renderer for automatically injecting dependencies for a page.\n const assetMap = BuildAssetMap.fromViteManifest(viteManifest, elementMap);\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(assetMap.toJson(), null, 2)\n );\n\n // Write SSG output to `dist/html`.\n const buildDir = path.join(distDir, 'html');\n\n // Recursively copy files from `public` to `dist/html`.\n const publicDir = path.join(rootDir, 'public');\n if (fsExtra.existsSync(path.join(rootDir, 'public'))) {\n fsExtra.copySync(publicDir, buildDir);\n } else {\n makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html`.\n copyDir(path.join(distDir, 'client/assets'), path.join(buildDir, 'assets'));\n copyDir(path.join(distDir, 'client/chunks'), path.join(buildDir, 'chunks'));\n\n // Pre-render HTML pages (SSG).\n if (!ssrOnly) {\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const renderer = new render.Renderer(rootConfig, {assetMap});\n const sitemap = await renderer.getSitemap();\n\n await Promise.all(\n Object.keys(sitemap).map(async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n const data = await renderer.renderRoute(route, {\n routeParams: params,\n });\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outPath = path.join(distDir, `html${urlPath}`, 'index.html');\n\n if (outPath.endsWith('404/index.html')) {\n outPath = outPath.replace('404/index.html', '404.html');\n }\n\n const html = await htmlMinify(data.html || '');\n await writeFile(outPath, html);\n\n const relPath = outPath.slice(path.dirname(distDir).length + 1);\n console.log(`saved ${relPath}`);\n })\n );\n }\n}\n","import {Manifest} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private moduleIdToAsset: Map<string, BuildAsset>;\n\n constructor() {\n this.moduleIdToAsset = new Map();\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n return this.moduleIdToAsset.get(moduleId) || null;\n }\n\n private add(asset: BuildAsset) {\n this.moduleIdToAsset.set(asset.moduleId, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const moduleId of this.moduleIdToAsset.keys()) {\n result[moduleId] = this.moduleIdToAsset.get(moduleId)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n viteManifest: Manifest,\n elementMap: Record<string, string>\n ) {\n const assetMap = new BuildAssetMap();\n\n const elementModuleIds = new Set();\n Object.values(elementMap).forEach((moduleId) =>\n elementModuleIds.add(moduleId)\n );\n\n Object.keys(viteManifest).forEach((manifestKey) => {\n const moduleId = `/${manifestKey}`;\n const manifestChunk = viteManifest[manifestKey];\n const isElement = elementModuleIds.has(moduleId);\n const assetData = {\n moduleId,\n assetUrl: `/${manifestChunk.file}`,\n importedModules: (manifestChunk.imports || []).map(\n (relPath) => `/${relPath}`\n ),\n importedCss: (manifestChunk.css || []).map((relPath) => `/${relPath}`),\n isElement: isElement,\n };\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n\n static fromRootManifest(rootManifest: BuildAssetManifest) {\n const assetMap = new BuildAssetMap();\n Object.keys(rootManifest).forEach((moduleId) => {\n const assetData = rootManifest[moduleId];\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n}\n\nexport class BuildAsset {\n moduleId: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private importedModules: string[];\n private importedCss: string[];\n isElement: boolean;\n\n constructor(\n assetMap: BuildAssetMap,\n assetData: {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.moduleId = assetData.moduleId;\n this.assetUrl = assetData.assetUrl;\n this.importedModules = assetData.importedModules;\n this.importedCss = assetData.importedCss;\n this.isElement = assetData.isElement;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n moduleId: this.moduleId,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n isElement: this.isElement,\n };\n }\n}\n","import path from 'node:path';\nimport {default as express} from 'express';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {loadRootConfig} from '../load-config';\nimport {Renderer} from '../../render/render.js';\nimport {fileExists, loadJson} from '../../core/fsutils';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {htmlMinify} from '../../render/html-minify';\nimport {dim} from 'kleur/colors';\nimport {configureServerPlugins} from '../../core/plugin';\nimport sirv from 'sirv';\nimport compression from 'compression';\nimport {rootProjectMiddleware} from '../../core/middleware';\nimport {RootConfig} from '../../core/config';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport async function preview(rootProjectDir?: string) {\n // TODO(stevenle): figure out standard practice for NODE_ENV when using the\n // preview command.\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: staging`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options: {rootDir: string}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await rootPreviewRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(rootPreviewServerMiddleware());\n // TODO(stevenle): handle 404/500 errors.\n },\n plugins,\n {type: 'preview'}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootPreviewRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootManifest);\n const renderer = new render.Renderer(rootConfig, {assetMap}) as Renderer;\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootPreviewServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const renderer = req.renderer!;\n try {\n const url = req.originalUrl;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n try {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n","import path from 'node:path';\nimport {default as express} from 'express';\nimport {loadRootConfig} from '../load-config';\nimport {Renderer} from '../../render/render.js';\nimport {fileExists, loadJson} from '../../core/fsutils';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {htmlMinify} from '../../render/html-minify';\nimport {dim} from 'kleur/colors';\nimport {configureServerPlugins} from '../../core/plugin';\nimport sirv from 'sirv';\nimport compression from 'compression';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {rootProjectMiddleware} from '../../core/middleware';\nimport {RootConfig} from '../../core/config';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport async function start(rootProjectDir?: string) {\n process.env.NODE_ENV = 'production';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: production`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options: {rootDir: string}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await rootProdRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(rootProdServerMiddleware());\n // TODO(stevenle): handle 404/500 errors.\n },\n plugins,\n {type: 'prod'}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootProdRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootManifest);\n const renderer = new render.Renderer(rootConfig, {assetMap}) as Renderer;\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootProdServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const renderer = req.renderer!;\n try {\n const url = req.originalUrl;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n try {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n"],"mappings":";;;;;;AAAA,OAAOA,WAAU;AACjB,SAAQ,qBAAoB;AAC5B,SAAQ,WAAW,eAAc;AACjC,SAAQ,gBAAgB,wBAAuB;;;ACH/C,OAAOC,WAAU;AACjB,OAAO,UAAU;;;ACDjB,SAAQ,YAAY,UAAS;AAC7B,OAAO,UAAU;AACjB,OAAO,aAAa;AAEb,SAAS,SAAS,UAAkB;AACzC,SAAO,CAAC,CAAC,SAAS,MAAM,aAAa;AACvC;AAEA,eAAsB,UAAU,UAAkB,SAAiB;AACjE,QAAM,UAAU,KAAK,QAAQ,QAAQ;AACrC,QAAM,QAAQ,OAAO;AACrB,QAAM,GAAG,UAAU,UAAU,OAAO;AACtC;AAEA,eAAsB,QAAQ,SAAiB;AAC7C,MAAI;AACF,UAAM,GAAG,OAAO,OAAO;AAAA,EACzB,SAAS,GAAP;AACA,UAAM,GAAG,MAAM,SAAS,EAAC,WAAW,KAAI,CAAC;AAAA,EAC3C;AACF;AAEA,eAAsB,QAAQ,QAAgB,QAAgB;AAC5D,MAAI,CAAC,QAAQ,WAAW,MAAM,GAAG;AAC/B;AAAA,EACF;AACA,UAAQ,SAAS,QAAQ,QAAQ,EAAC,WAAW,MAAM,WAAW,KAAI,CAAC;AACrE;AAEA,eAAsB,MAAM,SAAiB;AAC3C,QAAM,GAAG,GAAG,SAAS,EAAC,WAAW,MAAM,OAAO,KAAI,CAAC;AACrD;AAEA,eAAsB,SAAsB,UAA8B;AACxE,QAAM,U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nC,eAAO,MAAM,WAAW,IAAI;AAAA,MAC9B;AACA,UAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAAA,IAC7D,SAAS,GAAP;AACA,UAAI;AACF,cAAM,EAAC,KAAI,IAAI,MAAM,SAAS,YAAY,CAAC;AAC3C,YAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAAA,MAC7D,SAAS,IAAP;AACA,gBAAQ,MAAM,+BAA+B;AAC7C,gBAAQ,MAAM,EAAE;AAChB,aAAK,CAAC;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":["path","path","path","path","glob","path","glob","path","fileURLToPath","fsExtra","glob","dim","__dirname","path","fileURLToPath","dim","glob","fsExtra","path","express","dim","path","createServer","dim","express","path","express","dim","sirv","compression","path","createServer","dim","express","compression","sirv"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/dev.ts","../src/render/vite-plugin-root.ts","../src/core/fsutils.ts","../src/render/asset-map/dev-asset-map.ts","../src/cli/load-config.ts","../src/render/html-minify.ts","../src/core/middleware.ts","../src/cli/commands/build.ts","../src/render/asset-map/build-asset-map.ts","../src/cli/commands/preview.ts","../src/cli/commands/start.ts"],"sourcesContent":["import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {default as express} from 'express';\nimport {createServer as createViteServer} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {DevServerAssetMap} from '../../render/asset-map/dev-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {isDirectory, isJsFile} from '../../core/fsutils.js';\nimport glob from 'tiny-glob';\nimport {dim} from 'kleur/colors';\nimport {Server, Request, Response, NextFunction} from '../../core/types.js';\nimport {configureServerPlugins, getVitePlugins} from '../../core/plugin.js';\nimport {RootConfig} from '../../core/config.js';\nimport {rootProjectMiddleware} from '../../core/middleware.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function dev(rootProjectDir?: string) {\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: development`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options?: {rootDir?: string}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n\n const server = express();\n server.disable('x-powered-by');\n\n // Inject req context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await viteServerMiddleware({rootDir, rootConfig}));\n server.use(rootDevRendererMiddleware());\n\n const plugins = rootConfig.plugins || [];\n await configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n for (const middleware of userMiddlewares) {\n server.use(middleware);\n }\n // Add the root.js dev server middlewares.\n server.use(rootDevServerMiddleware());\n server.use(rootDevServer404Middleware());\n },\n plugins,\n {type: 'dev'}\n );\n\n return server;\n}\n\n/**\n * Middleware that initializes a vite server and injects it into the request\n * context.\n */\nasync function viteServerMiddleware(options: {\n rootDir: string;\n rootConfig: RootConfig;\n}) {\n const rootDir = options.rootDir;\n const rootConfig = options.rootConfig;\n const viteConfig = rootConfig.vite || {};\n\n const routeFiles: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob('routes/**/*', {cwd: rootDir});\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n routeFiles.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elements.push(moduleId.slice(1));\n }\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const vitePlugins = [\n pluginRoot({rootDir, rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ];\n\n const viteServer = await createViteServer({\n ...viteConfig,\n mode: 'development',\n root: rootDir,\n publicDir: path.join(rootDir, 'public'),\n server: {middlewareMode: true},\n appType: 'custom',\n optimizeDeps: {\n include: [\n ...routeFiles,\n ...elements,\n ...bundleScripts,\n ...(viteConfig.optimizeDeps?.include || []),\n ],\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: vitePlugins,\n });\n return async (req: Request, res: Response, next: NextFunction) => {\n req.viteServer = viteServer;\n viteServer.middlewares(req, res, next);\n };\n}\n\nfunction rootDevRendererMiddleware() {\n const renderModulePath = path.resolve(__dirname, './render.js');\n return async (req: Request, _: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const viteServer = req.viteServer!;\n // Dynamically import the render.js module using vite's SSR import loader.\n const render = await viteServer.ssrLoadModule(renderModulePath);\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(viteServer.moduleGraph);\n req.renderer = new render.Renderer(rootConfig, {assetMap});\n next();\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const url = req.originalUrl;\n const renderer = req.renderer!;\n const viteServer = req.viteServer!;\n const rootConfig = req.rootConfig!;\n try {\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n // Inject the Vite HMR client.\n let html = await viteServer.transformIndexHtml(url, data.html || '');\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n // If an error is caught, let Vite fix the stack trace so it maps back to\n // your actual source code.\n viteServer.ssrFixStacktrace(e);\n console.error(e);\n try {\n if (renderer) {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } else {\n next(e);\n }\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n\nfunction rootDevServer404Middleware() {\n return async (req: Request, res: Response) => {\n const url = req.originalUrl;\n const ext = path.extname(url);\n const renderer = req.renderer!;\n if (!ext) {\n const data = await renderer.renderDevServer404();\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n","import path from 'path';\nimport glob from 'tiny-glob';\nimport {RootConfig} from '../core/config';\nimport {isDirectory, isJsFile} from '../core/fsutils';\n\nconst JSX_ELEMENTS_REGEX = /jsxs?\\(\"(\\w[\\w-]+\\w)\"/g;\nconst HTML_ELEMENTS_REGEX = /<(\\w[\\w-]+\\w)/g;\n\nexport interface RootPluginOptions {\n rootDir: string;\n rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options?: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = options?.rootConfig || {};\n const elementsDirs = [path.join(rootDir, 'elements')];\n const includeDirs = rootConfig.elements?.include || [];\n includeDirs.forEach((dirPath) => {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n });\n\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n let elementMap: Record<string, string>;\n async function updateElementMap() {\n elementMap = {};\n await Promise.all(\n elementsDirs.map(async (dirPath: string) => {\n const dirExists = await isDirectory(dirPath);\n if (!dirExists) {\n return;\n }\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elementMap[parts.name] = moduleId;\n }\n }\n });\n })\n );\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!elementMap) {\n await updateElementMap();\n }\n if (tagname in elementMap) {\n return elementMap[tagname];\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return elementsDirs.some((elementsDir) => {\n return id.startsWith(elementsDir);\n });\n }\n\n return {\n name: 'vite-plugin-root',\n\n resolveId(id: string) {\n if (id === elementsVirtualId) {\n return resolvedElementsVirtualId;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === resolvedElementsVirtualId) {\n await updateElementMap();\n return `export const elementsMap = ${JSON.stringify(elementMap)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n const idParts = path.parse(id);\n const deps = new Set<string>();\n const tagnames = [\n ...src.matchAll(JSX_ELEMENTS_REGEX),\n ...src.matchAll(HTML_ELEMENTS_REGEX),\n ];\n for (const match of tagnames) {\n const tagname = match[1];\n // All custom elements should contain a dash.\n if (!tagname.includes('-')) {\n continue;\n }\n // Avoid circular deps.\n if (tagname === idParts.name) {\n continue;\n }\n deps.add(tagname);\n }\n const importUrls: string[] = [];\n await Promise.all(\n Array.from(deps).map(async (tagname) => {\n const importUrl = await getElementImport(tagname);\n if (importUrl) {\n importUrls.push(importUrl);\n }\n })\n );\n if (importUrls.length > 0) {\n const importLines = importUrls\n .map((url) => `import '${url}';`)\n .join('\\n');\n const code = `${src}\n\n// autogenerated by root:\n${importLines}\n`;\n return {code};\n }\n return null;\n }\n return null;\n },\n };\n}\n","import {promises as fs} from 'node:fs';\nimport path from 'node:path';\nimport fsExtra from 'fs-extra';\n\nexport function isJsFile(filename: string) {\n return !!filename.match(/\\.(j|t)sx?$/);\n}\n\nexport async function writeFile(filepath: string, content: string) {\n const dirPath = path.dirname(filepath);\n await makeDir(dirPath);\n await fs.writeFile(filepath, content);\n}\n\nexport async function makeDir(dirpath: string) {\n try {\n await fs.access(dirpath);\n } catch (e) {\n await fs.mkdir(dirpath, {recursive: true});\n }\n}\n\nexport async function copyDir(srcdir: string, dstdir: string) {\n if (!fsExtra.existsSync(srcdir)) {\n return;\n }\n fsExtra.copySync(srcdir, dstdir, {recursive: true, overwrite: true});\n}\n\nexport async function rmDir(dirpath: string) {\n await fs.rm(dirpath, {recursive: true, force: true});\n}\n\nexport async function loadJson<T = unknown>(filepath: string): Promise<T> {\n const content = await fs.readFile(filepath, 'utf-8');\n return JSON.parse(content);\n}\n\nexport async function isDirectory(dirpath: string) {\n return fs\n .stat(dirpath)\n .then((fsStat) => {\n return fsStat.isDirectory();\n })\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return false;\n }\n throw err;\n });\n}\n\nexport function fileExists(filepath: string): Promise<boolean> {\n return fs\n .access(filepath)\n .then(() => true)\n .catch(() => false);\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private moduleGraph: ModuleGraph;\n\n constructor(moduleGraph: ModuleGraph) {\n this.moduleGraph = moduleGraph;\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n const viteModule = await this.moduleGraph.getModuleByUrl(moduleId);\n if (!viteModule || !viteModule.id) {\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n return {\n moduleId: moduleId,\n assetUrl: moduleId,\n getCssDeps: async () => [],\n getJsDeps: async () => [moduleId],\n };\n }\n return new DevServerAsset(this, viteModule);\n }\n}\n\nexport class DevServerAsset implements Asset {\n moduleId: string;\n assetUrl: string;\n private assetMap: AssetMap;\n private viteModule: ModuleNode;\n\n constructor(assetMap: AssetMap, viteModule: ModuleNode) {\n this.assetMap = assetMap;\n this.viteModule = viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.moduleId.endsWith('.scss')) {\n const parts = path.parse(asset.assetUrl);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {bundleRequire} from 'bundle-require';\nimport JoyCon from 'joycon';\nimport {RootConfig} from '../core/config';\n\nexport async function loadRootConfig(rootDir: string): Promise<RootConfig> {\n const joycon = new JoyCon();\n const configPath = await joycon.resolve({\n cwd: rootDir,\n files: ['root.config.ts'],\n });\n if (configPath) {\n const configBundle = await bundleRequire({\n filepath: configPath,\n });\n return configBundle.mod.default || {};\n }\n return {};\n}\n","import {minify} from 'html-minifier-terser';\n\nexport async function htmlMinify(html: string): Promise<string> {\n try {\n const min = await minify(html, {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n });\n return min.trimStart();\n } catch (e) {\n console.error('failed to minify html:', e);\n return html;\n }\n}\n","import {RootConfig} from './config';\nimport {Request, Response, NextFunction} from './types';\n\n/**\n * Middleware that injects the root.js project config into the request context.\n */\nexport function rootProjectMiddleware(options: {\n rootDir: string;\n rootConfig: RootConfig;\n}) {\n return (req: Request, _: Response, next: NextFunction) => {\n req.rootConfig = Object.assign({}, options.rootConfig, {\n rootDir: options.rootDir,\n });\n next();\n };\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport fsExtra from 'fs-extra';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, UserConfig} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {\n copyDir,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../core/fsutils.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {dim} from 'kleur/colors';\nimport {getVitePlugins} from '../../core/plugin.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\ninterface BuildOptions {\n ssrOnly?: boolean;\n mode?: string;\n}\n\nexport async function build(rootProjectDir?: string, options?: BuildOptions) {\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n const ssrOnly = options?.ssrOnly || false;\n const mode = options?.mode || 'production';\n\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} output: ${distDir}/html`);\n console.log(`${dim('┃')} mode: ${mode}`);\n console.log();\n\n await rmDir(distDir);\n await makeDir(distDir);\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n const elementMap: Record<string, string> = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n if (!excludeElement(moduleId)) {\n elements.push(fullPath);\n elementMap[parts.name] = moduleId;\n }\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n pluginRoot({rootDir, rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ];\n\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n mode: mode,\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: vitePlugins,\n };\n\n // Bundle the render.js file with vite, which is pre-optimized for rendering\n // HTML routes.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n rollupOptions: {\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n });\n\n // Pre-render any client scripts and CSS deps.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n rollupOptions: {\n input: [...pages, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n });\n\n const viteManifest = await loadJson<Manifest>(\n path.join(distDir, 'client/manifest.json')\n );\n\n // Use the output of the client build to generate an asset map, which is used\n // by the renderer for automatically injecting dependencies for a page.\n const assetMap = BuildAssetMap.fromViteManifest(viteManifest, elementMap);\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(assetMap.toJson(), null, 2)\n );\n\n // Write SSG output to `dist/html`.\n const buildDir = path.join(distDir, 'html');\n\n // Recursively copy files from `public` to `dist/html`.\n const publicDir = path.join(rootDir, 'public');\n if (fsExtra.existsSync(path.join(rootDir, 'public'))) {\n fsExtra.copySync(publicDir, buildDir);\n } else {\n makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html`.\n copyDir(path.join(distDir, 'client/assets'), path.join(buildDir, 'assets'));\n copyDir(path.join(distDir, 'client/chunks'), path.join(buildDir, 'chunks'));\n\n // Pre-render HTML pages (SSG).\n if (!ssrOnly) {\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const renderer = new render.Renderer(rootConfig, {assetMap});\n const sitemap = await renderer.getSitemap();\n\n await Promise.all(\n Object.keys(sitemap).map(async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n const data = await renderer.renderRoute(route, {\n routeParams: params,\n });\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outPath = path.join(distDir, `html${urlPath}`, 'index.html');\n\n if (outPath.endsWith('404/index.html')) {\n outPath = outPath.replace('404/index.html', '404.html');\n }\n\n const html = await htmlMinify(data.html || '');\n await writeFile(outPath, html);\n\n const relPath = outPath.slice(path.dirname(distDir).length + 1);\n console.log(`saved ${relPath}`);\n })\n );\n }\n}\n","import {Manifest} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private moduleIdToAsset: Map<string, BuildAsset>;\n\n constructor() {\n this.moduleIdToAsset = new Map();\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n return this.moduleIdToAsset.get(moduleId) || null;\n }\n\n private add(asset: BuildAsset) {\n this.moduleIdToAsset.set(asset.moduleId, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const moduleId of this.moduleIdToAsset.keys()) {\n result[moduleId] = this.moduleIdToAsset.get(moduleId)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n viteManifest: Manifest,\n elementMap: Record<string, string>\n ) {\n const assetMap = new BuildAssetMap();\n\n const elementModuleIds = new Set();\n Object.values(elementMap).forEach((moduleId) =>\n elementModuleIds.add(moduleId)\n );\n\n Object.keys(viteManifest).forEach((manifestKey) => {\n const moduleId = `/${manifestKey}`;\n const manifestChunk = viteManifest[manifestKey];\n const isElement = elementModuleIds.has(moduleId);\n const assetData = {\n moduleId,\n assetUrl: `/${manifestChunk.file}`,\n importedModules: (manifestChunk.imports || []).map(\n (relPath) => `/${relPath}`\n ),\n importedCss: (manifestChunk.css || []).map((relPath) => `/${relPath}`),\n isElement: isElement,\n };\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n\n static fromRootManifest(rootManifest: BuildAssetManifest) {\n const assetMap = new BuildAssetMap();\n Object.keys(rootManifest).forEach((moduleId) => {\n const assetData = rootManifest[moduleId];\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n}\n\nexport class BuildAsset {\n moduleId: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private importedModules: string[];\n private importedCss: string[];\n isElement: boolean;\n\n constructor(\n assetMap: BuildAssetMap,\n assetData: {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.moduleId = assetData.moduleId;\n this.assetUrl = assetData.assetUrl;\n this.importedModules = assetData.importedModules;\n this.importedCss = assetData.importedCss;\n this.isElement = assetData.isElement;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n moduleId: this.moduleId,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n isElement: this.isElement,\n };\n }\n}\n","import path from 'node:path';\nimport {default as express} from 'express';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {loadRootConfig} from '../load-config';\nimport {Renderer} from '../../render/render.js';\nimport {fileExists, loadJson} from '../../core/fsutils';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {htmlMinify} from '../../render/html-minify';\nimport {dim} from 'kleur/colors';\nimport {configureServerPlugins} from '../../core/plugin';\nimport sirv from 'sirv';\nimport compression from 'compression';\nimport {rootProjectMiddleware} from '../../core/middleware';\nimport {RootConfig} from '../../core/config';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport async function preview(rootProjectDir?: string) {\n // TODO(stevenle): figure out standard practice for NODE_ENV when using the\n // preview command.\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: staging`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options: {rootDir: string}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await rootPreviewRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(rootPreviewServerMiddleware());\n // TODO(stevenle): handle 404/500 errors.\n },\n plugins,\n {type: 'preview'}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootPreviewRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootManifest);\n const renderer = new render.Renderer(rootConfig, {assetMap}) as Renderer;\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootPreviewServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const renderer = req.renderer!;\n try {\n const url = req.originalUrl;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n try {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n","import path from 'node:path';\nimport {default as express} from 'express';\nimport {loadRootConfig} from '../load-config';\nimport {Renderer} from '../../render/render.js';\nimport {fileExists, loadJson} from '../../core/fsutils';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {htmlMinify} from '../../render/html-minify';\nimport {dim} from 'kleur/colors';\nimport {configureServerPlugins} from '../../core/plugin';\nimport sirv from 'sirv';\nimport compression from 'compression';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {rootProjectMiddleware} from '../../core/middleware';\nimport {RootConfig} from '../../core/config';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport async function start(rootProjectDir?: string) {\n process.env.NODE_ENV = 'production';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://localhost:${port}`);\n console.log(`${dim('┃')} mode: production`);\n console.log();\n server.listen(port);\n}\n\nasync function createServer(options: {rootDir: string}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootDir, rootConfig}));\n server.use(await rootProdRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(rootProdServerMiddleware());\n // TODO(stevenle): handle 404/500 errors.\n },\n plugins,\n {type: 'prod'}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootProdRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootManifest);\n const renderer = new render.Renderer(rootConfig, {assetMap}) as Renderer;\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootProdServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const rootConfig = req.rootConfig!;\n const renderer = req.renderer!;\n try {\n const url = req.originalUrl;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n try {\n const {html} = await renderer.renderError(e);\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n } catch (e2) {\n console.error('failed to render custom error');\n console.error(e2);\n next(e);\n }\n }\n };\n}\n"],"mappings":";;;;;;AAAA,OAAOA,WAAU;AACjB,SAAQ,qBAAoB;AAC5B,SAAQ,WAAW,eAAc;AACjC,SAAQ,gBAAgB,wBAAuB;;;ACH/C,OAAOC,WAAU;AACjB,OAAO,UAAU;;;ACDjB,SAAQ,YAAY,UAAS;AAC7B,OAAO,UAAU;AACjB,OAAO,aAAa;AAEb,SAAS,SAAS,UAAkB;AACzC,SAAO,CAAC,CAAC,SAAS,MAAM,aAAa;AACvC;AAEA,eAAsB,UAAU,UAAkB,SAAiB;AACjE,QAAM,UAAU,KAAK,QAAQ,QAAQ;AACrC,QAAM,QAAQ,OAAO;AACrB,QAAM,GAAG,UAAU,UAAU,OAAO;AACtC;AAEA,eAAsB,QAAQ,SAAiB;AAC7C,MAAI;AACF,UAAM,GAAG,OAAO,OAAO;AAAA,EACzB,SAAS,GAAP;AACA,UAAM,GAAG,MAAM,SAAS,EAAC,WAAW,KAAI,CAAC;AAAA,EAC3C;AACF;AAEA,eAAsB,QAAQ,QAAgB,QAAgB;AAC5D,MAAI,CAAC,QAAQ,WAAW,MAAM,GAAG;AAC/B;AAAA,EACF;AACA,UAAQ,SAAS,QAAQ,QAAQ,EAAC,WAAW,MAAM,WAAW,KAAI,CAAC;AACrE;AAEA,eAAsB,MAAM,SAAiB;AAC3C,QAAM,GAAG,GAAG,SAAS,EAAC,WAAW,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AM;AAC/B,aAAK;AACL;AAAA,MACF;AACA,UAAI,OAAO,KAAK,QAAQ;AACxB,UAAI,WAAW,eAAe,OAAO;AACnC,eAAO,MAAM,WAAW,IAAI;AAAA,MAC9B;AACA,UAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAAA,IAC7D,SAAS,GAAP;AACA,UAAI;AACF,cAAM,EAAC,KAAI,IAAI,MAAM,SAAS,YAAY,CAAC;AAC3C,YAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAAA,MAC7D,SAAS,IAAP;AACA,gBAAQ,MAAM,+BAA+B;AAC7C,gBAAQ,MAAM,EAAE;AAChB,aAAK,CAAC;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":["path","path","path","path","glob","path","glob","path","fileURLToPath","fsExtra","glob","dim","__dirname","path","fileURLToPath","dim","glob","fsExtra","path","express","dim","path","createServer","dim","express","path","express","dim","sirv","compression","path","createServer","dim","express","compression","sirv"]}
|