@blinkk/root 1.0.0-alpha.29 → 1.0.0-alpha.30
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/{chunk-ACIQKW7Y.js → chunk-MLJ4KUD5.js} +1 -1
- package/dist/chunk-MLJ4KUD5.js.map +1 -0
- package/dist/cli.js +41 -11
- package/dist/cli.js.map +1 -1
- package/dist/{config-c00c91ee.d.ts → config-0a9ae264.d.ts} +18 -0
- package/dist/core.d.ts +9 -7
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/render.d.ts +3 -1
- package/dist/render.js +1 -1
- package/package.json +3 -1
- package/dist/chunk-ACIQKW7Y.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/components/error-page.tsx","../src/core/components/head.ts","../src/core/components/html.ts","../src/core/components/script.ts","../src/core/i18n.ts","../src/core/request-context.ts"],"sourcesContent":["export interface ErrorPageProps {\n error: unknown;\n}\n\nexport function ErrorPage(props: ErrorPageProps) {\n const error = props.error;\n\n let message = undefined;\n if (import.meta.env.DEV) {\n if (error instanceof Error) {\n message = error.stack;\n } else {\n message = String(error);\n }\n }\n\n return (\n <div>\n <div>\n <p>An error occured during route handling or page rendering.</p>\n {message && <pre>{message}</pre>}\n </div>\n </div>\n );\n}\n","import {ComponentChildren, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const HEAD_CONTEXT = createContext<ComponentChildren[]>([]);\n\nexport interface HeadProps {\n children?: ComponentChildren;\n}\n\n/**\n * The <Head> component can be used for injecting elements into the HTML head\n * tag from any part of a page.\n */\nexport function Head(props: HeadProps) {\n let context: ComponentChildren[];\n try {\n context = useContext(HEAD_CONTEXT);\n } catch (err) {\n console.log(err);\n throw new Error(\n '<Head> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props.children);\n return null;\n}\n","import {ComponentChildren, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport interface HtmlContextValue {\n attrs: Record<string, string>;\n}\n\nexport const HTML_CONTEXT = createContext<HtmlContextValue>({attrs: {}});\n\nexport type HtmlProps = preact.JSX.HTMLAttributes<HTMLHtmlElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The `<Html>` component can be used to update attrs used in the `<html>` tag.\n *\n * Usage:\n *\n * import {Html} from '@blinkk/root';\n *\n * export default function Page() {\n * return (\n * <Html lang={locale}>\n * <h1>Hello world</h1>\n * </Html>\n * );\n * }\n */\nexport function Html({children, ...attrs}: HtmlProps) {\n let context: Record<string, any>;\n try {\n context = useContext(HTML_CONTEXT);\n context.attrs = attrs;\n } catch (err) {\n console.log(err);\n throw new Error(\n '<Html> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n return children;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const SCRIPT_CONTEXT = createContext<ScriptProps[]>([]);\n\nexport interface ScriptProps {\n src: string;\n type?: string;\n}\n\n/**\n * The <Script> component is used for rendering any custom script modules. At\n * the moment, the system only pre-renders and bundles files that are in the\n * `/bundles` folder at the root of the project.\n */\nexport function Script(props: ScriptProps) {\n let context: ScriptProps[];\n try {\n context = useContext(SCRIPT_CONTEXT);\n } catch (err) {\n throw new Error(\n '<Script> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props);\n return null;\n}\n","import path from 'node:path';\nimport {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const I18N_CONTEXT = createContext<I18nContext | null>(null);\n\nexport interface I18nContext {\n locale: string;\n translations: Record<string, string>;\n}\n\nexport function getTranslations(locale: string): Record<string, string> {\n const translations: Record<string, Record<string, string>> = {};\n const translationsFiles = import.meta.glob(['/translations/*.json'], {\n eager: true,\n }) as Record<string, {default?: Record<string, string>}>;\n Object.keys(translationsFiles).forEach((translationPath) => {\n const parts = path.parse(translationPath);\n const locale = parts.name;\n const module = translationsFiles[translationPath];\n if (module && module.default) {\n translations[locale] = module.default;\n }\n });\n return translations[locale] || {};\n}\n\nexport function useI18nContext() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('could not find i18n context');\n }\n return context;\n}\n\nexport function useTranslations() {\n const context = useI18nContext();\n const translations = context.translations || {};\n const t = (str: string, params?: Record<string, string>) => {\n let translation = translations[str] || str || '';\n if (params) {\n for (const key of Object.keys(params)) {\n const val = String(params[key] || '');\n translation = translation.replaceAll(`{${key}}`, val);\n }\n }\n return translation;\n };\n return t;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {Route} from '../render/router';\n\nexport interface RequestContext {\n /** The route file. */\n route: Route;\n /**\n * Route param values. E.g. for a route like `routes/blog/[slug].tsx`,\n * visiting `/blog/foo` will pass {slug: 'foo'} here.\n */\n routeParams: Record<string, string>;\n /** Props passed to the route's server component. */\n props: any;\n /** The current locale. */\n locale: string;\n /** Translations map for the current locale. */\n translations: Record<string, string>;\n}\n\nexport const REQUEST_CONTEXT = createContext<RequestContext | null>(null);\n\nexport function useRequestContext() {\n const context = useContext(REQUEST_CONTEXT);\n if (!context) {\n throw new Error('could not find request context');\n }\n return context;\n}\n"],"mappings":";AAkBM,SACE,KADF;AAdC,SAAS,UAAU,OAAuB;AAC/C,QAAM,QAAQ,MAAM;AAEpB,MAAI,UAAU;AACd,MAAI,YAAY,IAAI,KAAK;AACvB,QAAI,iBAAiB,OAAO;AAC1B,gBAAU,MAAM;AAAA,IAClB,OAAO;AACL,gBAAU,OAAO,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SACE,oBAAC;AAAA,IACC,+BAAC;AAAA,MACC;AAAA,4BAAC;AAAA,UAAE;AAAA,SAAyD;AAAA,QAC3D,WAAW,oBAAC;AAAA,UAAK;AAAA,SAAQ;AAAA;AAAA,KAC5B;AAAA,GACF;AAEJ;;;ACxBA,SAA2B,qBAAoB;AAC/C,SAAQ,kBAAiB;AAElB,IAAM,eAAe,cAAmC,CAAC,CAAC;AA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E,QAAQ,CAAC,oBAAoB;AAC1D,UAAM,QAAQ,KAAK,MAAM,eAAe;AACxC,UAAME,UAAS,MAAM;AACrB,UAAM,SAAS,kBAAkB;AACjC,QAAI,UAAU,OAAO,SAAS;AAC5B,mBAAaA,WAAU,OAAO;AAAA,IAChC;AAAA,EACF,CAAC;AACD,SAAO,aAAa,WAAW,CAAC;AAClC;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAUD,YAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB;AAChC,QAAM,UAAU,eAAe;AAC/B,QAAM,eAAe,QAAQ,gBAAgB,CAAC;AAC9C,QAAM,IAAI,CAAC,KAAa,WAAoC;AAC1D,QAAI,cAAc,aAAa,QAAQ,OAAO;AAC9C,QAAI,QAAQ;AACV,iBAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AACrC,cAAM,MAAM,OAAO,OAAO,QAAQ,EAAE;AACpC,sBAAc,YAAY,WAAW,IAAI,QAAQ,GAAG;AAAA,MACtD;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACjDA,SAAQ,iBAAAE,sBAAoB;AAC5B,SAAQ,cAAAC,mBAAiB;AAmBlB,IAAM,kBAAkBD,eAAqC,IAAI;AAEjE,SAAS,oBAAoB;AAClC,QAAM,UAAUC,YAAW,eAAe;AAC1C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO;AACT;","names":["createContext","useContext","createContext","useContext","createContext","useContext","locale","createContext","useContext"]}
|
package/dist/cli.js
CHANGED
|
@@ -345,13 +345,14 @@ async function loadRootConfig(rootDir) {
|
|
|
345
345
|
|
|
346
346
|
// src/render/html-minify.ts
|
|
347
347
|
import { minify } from "html-minifier-terser";
|
|
348
|
-
async function htmlMinify(html) {
|
|
348
|
+
async function htmlMinify(html, options) {
|
|
349
|
+
const minifyOptions = options || {
|
|
350
|
+
collapseWhitespace: true,
|
|
351
|
+
removeComments: true,
|
|
352
|
+
preserveLineBreaks: true
|
|
353
|
+
};
|
|
349
354
|
try {
|
|
350
|
-
const min = await minify(html,
|
|
351
|
-
collapseWhitespace: true,
|
|
352
|
-
removeComments: true,
|
|
353
|
-
preserveLineBreaks: true
|
|
354
|
-
});
|
|
355
|
+
const min = await minify(html, minifyOptions);
|
|
355
356
|
return min.trimStart();
|
|
356
357
|
} catch (e) {
|
|
357
358
|
console.error("failed to minify html:", e);
|
|
@@ -410,6 +411,23 @@ async function findOpenPort(min, max) {
|
|
|
410
411
|
throw new Error(`no ports open between ${min} and ${max}`);
|
|
411
412
|
}
|
|
412
413
|
|
|
414
|
+
// src/render/html-pretty.ts
|
|
415
|
+
import { default as beautify } from "js-beautify";
|
|
416
|
+
async function htmlPretty(html, options) {
|
|
417
|
+
const prettyOptions = options || {
|
|
418
|
+
indent_size: 0,
|
|
419
|
+
end_with_newline: true,
|
|
420
|
+
extra_liners: []
|
|
421
|
+
};
|
|
422
|
+
try {
|
|
423
|
+
const output = beautify.html(html, prettyOptions);
|
|
424
|
+
return output.trimStart();
|
|
425
|
+
} catch (e) {
|
|
426
|
+
console.error("failed to pretty html:", e);
|
|
427
|
+
return html;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
413
431
|
// src/cli/commands/dev.ts
|
|
414
432
|
var __dirname = path5.dirname(fileURLToPath(import.meta.url));
|
|
415
433
|
async function dev(rootProjectDir) {
|
|
@@ -557,8 +575,11 @@ function rootDevServerMiddleware() {
|
|
|
557
575
|
return;
|
|
558
576
|
}
|
|
559
577
|
let html = await viteServer.transformIndexHtml(url, data.html || "");
|
|
578
|
+
if (rootConfig.prettyHtml !== false) {
|
|
579
|
+
html = await htmlPretty(html, rootConfig.prettyHtmlOptions);
|
|
580
|
+
}
|
|
560
581
|
if (rootConfig.minifyHtml !== false) {
|
|
561
|
-
html = await htmlMinify(html);
|
|
582
|
+
html = await htmlMinify(html, rootConfig.minifyHtmlOptions);
|
|
562
583
|
}
|
|
563
584
|
res.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
564
585
|
} catch (e) {
|
|
@@ -843,7 +864,7 @@ async function build(rootProjectDir, options) {
|
|
|
843
864
|
input: [...routeFiles, ...elements, ...bundleScripts],
|
|
844
865
|
output: {
|
|
845
866
|
format: "esm",
|
|
846
|
-
entryFileNames: "[name].[hash].min.js",
|
|
867
|
+
entryFileNames: "assets/[name].[hash].min.js",
|
|
847
868
|
chunkFileNames: "chunks/[name].[hash].min.js",
|
|
848
869
|
assetFileNames: "assets/[name].[hash][extname]",
|
|
849
870
|
...(_d = (_c = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.output
|
|
@@ -911,8 +932,11 @@ async function build(rootProjectDir, options) {
|
|
|
911
932
|
}
|
|
912
933
|
const outPath = path7.join(buildDir, outFilePath);
|
|
913
934
|
let html = data.html || "";
|
|
935
|
+
if (rootConfig.prettyHtml !== false) {
|
|
936
|
+
html = await htmlPretty(html, rootConfig.prettyHtmlOptions);
|
|
937
|
+
}
|
|
914
938
|
if (rootConfig.minifyHtml !== false) {
|
|
915
|
-
html = await htmlMinify(html);
|
|
939
|
+
html = await htmlMinify(html, rootConfig.minifyHtmlOptions);
|
|
916
940
|
}
|
|
917
941
|
await writeFile(outPath, html);
|
|
918
942
|
printFileOutput(fileSize(outPath), "dist/html/", outFilePath);
|
|
@@ -1016,8 +1040,11 @@ function rootPreviewServerMiddleware() {
|
|
|
1016
1040
|
return;
|
|
1017
1041
|
}
|
|
1018
1042
|
let html = data.html || "";
|
|
1043
|
+
if (rootConfig.prettyHtml !== false) {
|
|
1044
|
+
html = await htmlPretty(html, rootConfig.prettyHtmlOptions);
|
|
1045
|
+
}
|
|
1019
1046
|
if (rootConfig.minifyHtml !== false) {
|
|
1020
|
-
html = await htmlMinify(html);
|
|
1047
|
+
html = await htmlMinify(html, rootConfig.minifyHtmlOptions);
|
|
1021
1048
|
}
|
|
1022
1049
|
res.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1023
1050
|
} catch (e) {
|
|
@@ -1107,8 +1134,11 @@ function rootProdServerMiddleware() {
|
|
|
1107
1134
|
return;
|
|
1108
1135
|
}
|
|
1109
1136
|
let html = data.html || "";
|
|
1137
|
+
if (rootConfig.prettyHtml !== false) {
|
|
1138
|
+
html = await htmlPretty(html, rootConfig.prettyHtmlOptions);
|
|
1139
|
+
}
|
|
1110
1140
|
if (rootConfig.minifyHtml !== false) {
|
|
1111
|
-
html = await htmlMinify(html);
|
|
1141
|
+
html = await htmlMinify(html, rootConfig.minifyHtmlOptions);
|
|
1112
1142
|
}
|
|
1113
1143
|
res.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1114
1144
|
} catch (e) {
|
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/elements.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/ports.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';\nimport {findOpenPort} from '../ports.js';\nimport {getElements} from '../../core/elements.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 defaultPort = parseInt(process.env.PORT || '4007');\n const port = await findOpenPort(defaultPort, defaultPort + 10);\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 const server = await createServer({rootDir, port});\n server.listen(port);\n}\n\nasync function createServer(options?: {\n rootDir?: string;\n port?: number;\n}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n const port = options?.port;\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, port}));\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 port?: number;\n}) {\n const rootDir = options.rootDir;\n const rootConfig = options.rootConfig;\n const viteConfig = rootConfig.vite || {};\n\n let hmrOptions = viteConfig.server?.hmr;\n if (typeof hmrOptions === 'undefined' && options.port) {\n // Automatically set the HMR port to `port + 10`. This allows multiple\n // root.js dev servers to run without conflicts.\n hmrOptions = {port: options.port + 10};\n }\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 elementsMap = await getElements(rootConfig);\n const elements = Object.values(elementsMap).map((mod) => mod.src);\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\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 viteServer = await createViteServer({\n ...viteConfig,\n mode: 'development',\n root: rootDir,\n publicDir: path.join(rootDir, 'public'),\n server: {\n ...(viteConfig.server || {}),\n middlewareMode: true,\n hmr: hmrOptions,\n },\n appType: 'custom',\n optimizeDeps: {\n ...(viteConfig.optimizeDeps || {}),\n include: [\n ...routeFiles,\n ...elements,\n ...bundleScripts,\n ...(viteConfig.optimizeDeps?.include || []),\n ],\n },\n ssr: {\n ...(viteConfig.ssr || {}),\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n ...(viteConfig.esbuild || {}),\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: [\n await pluginRoot({rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ],\n });\n return async (req: Request, res: Response, next: NextFunction) => {\n try {\n req.viteServer = viteServer;\n viteServer.middlewares(req, res, next);\n } catch (e) {\n next(e);\n }\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 try {\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(\n rootConfig,\n viteServer.moduleGraph\n );\n req.renderer = new render.Renderer(rootConfig, {assetMap});\n next();\n } catch (e) {\n next(e);\n }\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const url = req.path;\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 // HTML minification is `true` by default. Set to `false` to disable.\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.path;\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 'node:path';\nimport {ElementModule} from 'virtual:root-elements';\nimport {RootConfig} from '../core/config';\nimport {getElements} from '../core/elements';\nimport {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 rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n const rootConfig = options.rootConfig;\n\n let tagNameToElement: Record<string, ElementModule>;\n const customElementFiles: Set<string> = new Set();\n async function updateElementMap() {\n tagNameToElement = await getElements(rootConfig);\n customElementFiles.clear();\n Object.values(tagNameToElement).forEach((elementModule) => {\n customElementFiles.add(elementModule.filePath);\n customElementFiles.add(elementModule.realPath);\n });\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!tagNameToElement) {\n await updateElementMap();\n }\n if (tagname in tagNameToElement) {\n const elementModule = tagNameToElement[tagname];\n if (elementModule.filePath === elementModule.realPath) {\n return elementModule.src;\n }\n // TODO(stevenle): handle symlinked elements.\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return customElementFiles.has(id);\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(tagNameToElement)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n await updateElementMap();\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 fs from 'node:fs';\nimport path from 'node:path';\nimport glob from 'tiny-glob';\nimport {ElementModule} from 'virtual:root-elements';\nimport {searchForWorkspaceRoot} from 'vite';\nimport {RootConfig} from './config';\nimport {directoryContains, isDirectory, isJsFile} from './fsutils';\n\n/**\n * Returns a map of all the element file definitions in the project.\n */\nexport async function getElements(\n rootConfig: RootConfig\n): Promise<Record<string, ElementModule>> {\n const rootDir = rootConfig.rootDir;\n const workspaceRoot = searchForWorkspaceRoot(rootDir);\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 (!directoryContains(rootDir, elementsDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be within the project's workspace (${workspaceRoot})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n\n const elementMap: Record<string, ElementModule> = {};\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 filePath = path.join(dirPath, file);\n const src = path.relative(rootDir, filePath);\n const realPath = fs.realpathSync(filePath);\n if (!excludeElement(src)) {\n elementMap[parts.name] = {\n src,\n filePath,\n realPath,\n };\n }\n }\n });\n }\n }\n return elementMap;\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\nexport async function directoryContains(\n dirpath: string,\n subpath: string\n): Promise<boolean> {\n const outer = await fs.realpath(dirpath);\n const inner = await fs.realpath(subpath);\n const rel = path.relative(outer, inner);\n return !rel.startsWith('..');\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode, searchForWorkspaceRoot} from 'vite';\nimport {RootConfig} from '../../core/config';\nimport {directoryContains} from '../../core/fsutils';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private moduleGraph: ModuleGraph;\n\n constructor(rootConfig: RootConfig, moduleGraph: ModuleGraph) {\n this.rootConfig = rootConfig;\n this.moduleGraph = moduleGraph;\n }\n\n async get(src: string): Promise<Asset | null> {\n const file = path.resolve(this.rootConfig.rootDir, src);\n\n const viteModules = this.moduleGraph.getModulesByFile(file);\n if (viteModules && viteModules.size > 0) {\n const [viteModule] = viteModules;\n return new DevServerAsset(src, {\n assetMap: this,\n viteModule: viteModule,\n });\n }\n\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n if (file.startsWith(this.rootConfig.rootDir)) {\n const assetUrl = file.slice(this.rootConfig.rootDir.length);\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n const workspaceRoot = searchForWorkspaceRoot(this.rootConfig.rootDir);\n if (await directoryContains(workspaceRoot, file)) {\n const assetUrl = `/@fs/${file}`;\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n\n console.log(`could not find asset in asset map: ${src}`);\n return null;\n }\n\n filePathToSrc(file: string) {\n return path.relative(this.rootConfig.rootDir, file);\n }\n}\n\nexport class DevServerAsset implements Asset {\n src: string;\n moduleId: string;\n assetUrl: string;\n private assetMap: DevServerAssetMap;\n private viteModule: ModuleNode;\n\n constructor(\n src: string,\n options: {\n assetMap: DevServerAssetMap;\n viteModule: ModuleNode;\n }\n ) {\n this.src = src;\n this.assetMap = options.assetMap;\n this.viteModule = options.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.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\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.src.endsWith('.scss')) {\n const parts = path.parse(asset.src);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\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 Object.assign({}, configBundle.mod.default || {}, {rootDir});\n }\n return {rootDir};\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 {createServer} from 'node:net';\n\n/**\n * Checks whether a port is open.\n */\nexport function isPortOpen(port: number): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const server = createServer();\n server.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n resolve(false);\n return;\n }\n reject(err);\n });\n server.on('close', () => {\n resolve(true);\n });\n server.listen(port, () => {\n server.close((err) => {\n if (err) {\n console.log(`error closing server: ${err}`);\n reject(err);\n }\n });\n });\n });\n}\n\n/**\n * Finds the first open port between two values.\n */\nexport async function findOpenPort(min: number, max: number): Promise<number> {\n let port = min;\n while (port <= max) {\n const isOpen = await isPortOpen(port);\n if (isOpen) {\n return port;\n }\n port += 1;\n }\n throw new Error(`no ports open between ${min} and ${max}`);\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 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, blue, cyan} from 'kleur/colors';\nimport {getVitePlugins} from '../../core/plugin.js';\nimport {getElements} from '../../core/elements.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 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(path.resolve(rootDir, file));\n }\n });\n }\n\n const elementsMap = await getElements(rootConfig);\n const elements = Object.values(elementsMap).map((mod) =>\n path.resolve(rootDir, mod.src)\n );\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n pluginRoot({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 ...viteConfig?.build?.rollupOptions,\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].min.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 ...viteConfig?.build?.rollupOptions,\n input: [...routeFiles, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n entryFileNames: '[name].[hash].min.js',\n chunkFileNames: 'chunks/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n ...viteConfig?.build?.rollupOptions?.output,\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(\n rootConfig,\n viteManifest,\n elementsMap\n );\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n const rootManifest = assetMap.toJson();\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(rootManifest, 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` using the\n // root manifest. Ignore route files.\n console.log('\\njs/css output:');\n makeDir(path.join(buildDir, 'assets'));\n makeDir(path.join(buildDir, 'chunks'));\n Object.keys(rootManifest).forEach((src) => {\n // Don't expose route files in the final output. If any client-side code\n // relies on route dependencies, it should probably be broken out into a\n // shared component instead.\n if (isRouteFile(src)) {\n return;\n }\n const assetData = rootManifest[src];\n const assetRelPath = assetData.assetUrl.slice(1);\n const assetFrom = path.join(distDir, 'client', assetRelPath);\n const assetTo = path.join(buildDir, assetRelPath);\n fsExtra.copySync(assetFrom, assetTo);\n printFileOutput(fileSize(assetTo), 'dist/html/', assetRelPath);\n });\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 console.log('\\nhtml output:');\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 outFilePath = path.join(urlPath.slice(1), 'index.html');\n if (outFilePath.endsWith('404/index.html')) {\n outFilePath = outFilePath.replace('404/index.html', '404.html');\n }\n const outPath = path.join(buildDir, outFilePath);\n\n let html = data.html || '';\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n await writeFile(outPath, html);\n\n printFileOutput(fileSize(outPath), 'dist/html/', outFilePath);\n })\n );\n }\n}\n\nfunction isRouteFile(filepath: string) {\n return filepath.startsWith('routes') && isJsFile(filepath);\n}\n\nfunction fileSize(filepath: string) {\n const stats = fsExtra.statSync(filepath);\n const bytes = stats.size;\n\n const k = 1024;\n if (bytes < k) {\n return (bytes / k).toFixed(2) + ' kB';\n }\n const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + units[i];\n}\n\nfunction printFileOutput(\n fileSize: string,\n outputDir: string,\n outputFile: string\n) {\n const indent = ' '.repeat(2);\n const paddedSize = fileSize.padStart(9, ' ');\n console.log(\n `${indent}${dim(paddedSize)} ${dim(outputDir)}${cyan(outputFile)}`\n );\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport {ElementModule} from 'virtual:root-elements';\nimport {Manifest} from 'vite';\nimport {RootConfig} from '../../core/config';\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private srcToAsset: Map<string, BuildAsset>;\n\n constructor(rootConfig: RootConfig) {\n this.rootConfig = rootConfig;\n this.srcToAsset = new Map();\n }\n\n async get(src: string): Promise<Asset | null> {\n const asset = this.srcToAsset.get(src);\n if (asset) {\n return asset;\n }\n // Try resolving the realpath of the asset, following symlinks.\n const realSrc = realPathRelativeTo(this.rootConfig.rootDir, src);\n if (realSrc !== src) {\n const asset = this.srcToAsset.get(realSrc);\n if (asset) {\n return asset;\n }\n }\n console.log(`could not find build asset: ${src}`);\n return null;\n }\n\n private add(asset: BuildAsset) {\n this.srcToAsset.set(asset.src, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const src of this.srcToAsset.keys()) {\n result[src] = this.srcToAsset.get(src)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n rootConfig: RootConfig,\n viteManifest: Manifest,\n elementMap: Record<string, ElementModule>\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n\n const elementFiles = new Set();\n Object.values(elementMap).forEach((elementModule) => {\n elementFiles.add(elementModule.src);\n // Vite will resolve symlinks, so we need to follow the src and add the\n // realpath to the element files.\n const realSrc = realPathRelativeTo(rootConfig.rootDir, elementModule.src);\n if (realSrc !== elementModule.src) {\n elementFiles.add(realSrc);\n }\n });\n\n Object.keys(viteManifest).forEach((manifestKey) => {\n const src = manifestKey;\n const manifestChunk = viteManifest[manifestKey];\n const isElement = elementFiles.has(src);\n const assetData = {\n src: src,\n assetUrl: `/${manifestChunk.file}`,\n importedModules: manifestChunk.imports || [],\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(\n rootConfig: RootConfig,\n rootManifest: BuildAssetManifest\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\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\n/**\n * Returns the realpath of a src file, relative to the rootDir.\n */\nfunction realPathRelativeTo(rootDir: string, src: string) {\n const fullPath = path.resolve(rootDir, src);\n if (!fs.existsSync(fullPath)) {\n return src;\n }\n const realpath = fs.realpathSync(path.resolve(rootDir, src));\n return path.relative(rootDir, realpath);\n}\n\nexport class BuildAsset {\n src: 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 src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.src = assetData.src;\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.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (src) => {\n const importedAsset = (await this.assetMap.get(src)) 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.src)) {\n return;\n }\n visited.add(asset.src);\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 src: this.src,\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(rootConfig, 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.path;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n // HTML minification is `true` by default. Set to `false` to disable.\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(rootConfig, 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.path;\n const data = await renderer.render(url);\n if (data.notFound || !data.html) {\n next();\n return;\n }\n let html = data.html || '';\n // HTML minification is `true` by default. Set to `false` to disable.\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;;;ACAjB,OAAOC,SAAQ;AACf,OAAOC,WAAU;AACjB,OAAO,UAAU;AAEjB,SAAQ,8BAA6B;;;ACJrC,SAAQ,YAAY,UAAS;AAC7B,OAAO,UAAU;AACjB,OAAO,aAAa;AAEb,SAAS,SAAS,UAAkB;AACzC,SAAO,CAAC,CAAC,SAA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,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","fs","path","path","fs","path","path","searchForWorkspaceRoot","path","searchForWorkspaceRoot","glob","path","createServer","glob","path","fileURLToPath","fsExtra","glob","fs","path","asset","dim","__dirname","path","fileURLToPath","dim","glob","fsExtra","fileSize","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/elements.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/ports.ts","../src/render/html-pretty.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';\nimport {findOpenPort} from '../ports.js';\nimport {getElements} from '../../core/elements.js';\nimport {htmlPretty} from '../../render/html-pretty.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 defaultPort = parseInt(process.env.PORT || '4007');\n const port = await findOpenPort(defaultPort, defaultPort + 10);\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 const server = await createServer({rootDir, port});\n server.listen(port);\n}\n\nasync function createServer(options?: {\n rootDir?: string;\n port?: number;\n}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir);\n const port = options?.port;\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, port}));\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 port?: number;\n}) {\n const rootDir = options.rootDir;\n const rootConfig = options.rootConfig;\n const viteConfig = rootConfig.vite || {};\n\n let hmrOptions = viteConfig.server?.hmr;\n if (typeof hmrOptions === 'undefined' && options.port) {\n // Automatically set the HMR port to `port + 10`. This allows multiple\n // root.js dev servers to run without conflicts.\n hmrOptions = {port: options.port + 10};\n }\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 elementsMap = await getElements(rootConfig);\n const elements = Object.values(elementsMap).map((mod) => mod.src);\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\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 viteServer = await createViteServer({\n ...viteConfig,\n mode: 'development',\n root: rootDir,\n publicDir: path.join(rootDir, 'public'),\n server: {\n ...(viteConfig.server || {}),\n middlewareMode: true,\n hmr: hmrOptions,\n },\n appType: 'custom',\n optimizeDeps: {\n ...(viteConfig.optimizeDeps || {}),\n include: [\n ...routeFiles,\n ...elements,\n ...bundleScripts,\n ...(viteConfig.optimizeDeps?.include || []),\n ],\n },\n ssr: {\n ...(viteConfig.ssr || {}),\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n ...(viteConfig.esbuild || {}),\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: [\n await pluginRoot({rootConfig}),\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootConfig.plugins || []),\n ],\n });\n return async (req: Request, res: Response, next: NextFunction) => {\n try {\n req.viteServer = viteServer;\n viteServer.middlewares(req, res, next);\n } catch (e) {\n next(e);\n }\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 try {\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(\n rootConfig,\n viteServer.moduleGraph\n );\n req.renderer = new render.Renderer(rootConfig, {assetMap});\n next();\n } catch (e) {\n next(e);\n }\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const url = req.path;\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.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\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.path;\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 'node:path';\nimport {ElementModule} from 'virtual:root-elements';\nimport {RootConfig} from '../core/config';\nimport {getElements} from '../core/elements';\nimport {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 rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n const rootConfig = options.rootConfig;\n\n let tagNameToElement: Record<string, ElementModule>;\n const customElementFiles: Set<string> = new Set();\n async function updateElementMap() {\n tagNameToElement = await getElements(rootConfig);\n customElementFiles.clear();\n Object.values(tagNameToElement).forEach((elementModule) => {\n customElementFiles.add(elementModule.filePath);\n customElementFiles.add(elementModule.realPath);\n });\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!tagNameToElement) {\n await updateElementMap();\n }\n if (tagname in tagNameToElement) {\n const elementModule = tagNameToElement[tagname];\n if (elementModule.filePath === elementModule.realPath) {\n return elementModule.src;\n }\n // TODO(stevenle): handle symlinked elements.\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return customElementFiles.has(id);\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(tagNameToElement)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n await updateElementMap();\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 fs from 'node:fs';\nimport path from 'node:path';\nimport glob from 'tiny-glob';\nimport {ElementModule} from 'virtual:root-elements';\nimport {searchForWorkspaceRoot} from 'vite';\nimport {RootConfig} from './config';\nimport {directoryContains, isDirectory, isJsFile} from './fsutils';\n\n/**\n * Returns a map of all the element file definitions in the project.\n */\nexport async function getElements(\n rootConfig: RootConfig\n): Promise<Record<string, ElementModule>> {\n const rootDir = rootConfig.rootDir;\n const workspaceRoot = searchForWorkspaceRoot(rootDir);\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 (!directoryContains(rootDir, elementsDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be within the project's workspace (${workspaceRoot})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n\n const elementMap: Record<string, ElementModule> = {};\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 filePath = path.join(dirPath, file);\n const src = path.relative(rootDir, filePath);\n const realPath = fs.realpathSync(filePath);\n if (!excludeElement(src)) {\n elementMap[parts.name] = {\n src,\n filePath,\n realPath,\n };\n }\n }\n });\n }\n }\n return elementMap;\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\nexport async function directoryContains(\n dirpath: string,\n subpath: string\n): Promise<boolean> {\n const outer = await fs.realpath(dirpath);\n const inner = await fs.realpath(subpath);\n const rel = path.relative(outer, inner);\n return !rel.startsWith('..');\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode, searchForWorkspaceRoot} from 'vite';\nimport {RootConfig} from '../../core/config';\nimport {directoryContains} from '../../core/fsutils';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private moduleGraph: ModuleGraph;\n\n constructor(rootConfig: RootConfig, moduleGraph: ModuleGraph) {\n this.rootConfig = rootConfig;\n this.moduleGraph = moduleGraph;\n }\n\n async get(src: string): Promise<Asset | null> {\n const file = path.resolve(this.rootConfig.rootDir, src);\n\n const viteModules = this.moduleGraph.getModulesByFile(file);\n if (viteModules && viteModules.size > 0) {\n const [viteModule] = viteModules;\n return new DevServerAsset(src, {\n assetMap: this,\n viteModule: viteModule,\n });\n }\n\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n if (file.startsWith(this.rootConfig.rootDir)) {\n const assetUrl = file.slice(this.rootConfig.rootDir.length);\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n const workspaceRoot = searchForWorkspaceRoot(this.rootConfig.rootDir);\n if (await directoryContains(workspaceRoot, file)) {\n const assetUrl = `/@fs/${file}`;\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n\n console.log(`could not find asset in asset map: ${src}`);\n return null;\n }\n\n filePathToSrc(file: string) {\n return path.relative(this.rootConfig.rootDir, file);\n }\n}\n\nexport class DevServerAsset implements Asset {\n src: string;\n moduleId: string;\n assetUrl: string;\n private assetMap: DevServerAssetMap;\n private viteModule: ModuleNode;\n\n constructor(\n src: string,\n options: {\n assetMap: DevServerAssetMap;\n viteModule: ModuleNode;\n }\n ) {\n this.src = src;\n this.assetMap = options.assetMap;\n this.viteModule = options.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.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\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.src.endsWith('.scss')) {\n const parts = path.parse(asset.src);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\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 Object.assign({}, configBundle.mod.default || {}, {rootDir});\n }\n return {rootDir};\n}\n","import {minify, Options} from 'html-minifier-terser';\n\nexport type HtmlMinifyOptions = Options;\n\nexport async function htmlMinify(\n html: string,\n options?: HtmlMinifyOptions\n): Promise<string> {\n const minifyOptions = options || {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n };\n try {\n const min = await minify(html, minifyOptions);\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 {createServer} from 'node:net';\n\n/**\n * Checks whether a port is open.\n */\nexport function isPortOpen(port: number): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const server = createServer();\n server.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n resolve(false);\n return;\n }\n reject(err);\n });\n server.on('close', () => {\n resolve(true);\n });\n server.listen(port, () => {\n server.close((err) => {\n if (err) {\n console.log(`error closing server: ${err}`);\n reject(err);\n }\n });\n });\n });\n}\n\n/**\n * Finds the first open port between two values.\n */\nexport async function findOpenPort(min: number, max: number): Promise<number> {\n let port = min;\n while (port <= max) {\n const isOpen = await isPortOpen(port);\n if (isOpen) {\n return port;\n }\n port += 1;\n }\n throw new Error(`no ports open between ${min} and ${max}`);\n}\n","import {default as beautify, HTMLBeautifyOptions} from 'js-beautify';\n\nexport type HtmlPrettyOptions = HTMLBeautifyOptions;\n\nexport async function htmlPretty(\n html: string,\n options?: HtmlPrettyOptions\n): Promise<string> {\n const prettyOptions = options || {\n indent_size: 0,\n end_with_newline: true,\n extra_liners: [],\n };\n try {\n const output = beautify.html(html, prettyOptions);\n return output.trimStart();\n } catch (e) {\n console.error('failed to pretty html:', e);\n return html;\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 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, blue, cyan} from 'kleur/colors';\nimport {getVitePlugins} from '../../core/plugin.js';\nimport {getElements} from '../../core/elements.js';\nimport {htmlPretty} from '../../render/html-pretty.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 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(path.resolve(rootDir, file));\n }\n });\n }\n\n const elementsMap = await getElements(rootConfig);\n const elements = Object.values(elementsMap).map((mod) =>\n path.resolve(rootDir, mod.src)\n );\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n pluginRoot({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 ...viteConfig?.build?.rollupOptions,\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].min.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 ...viteConfig?.build?.rollupOptions,\n input: [...routeFiles, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n entryFileNames: 'assets/[name].[hash].min.js',\n chunkFileNames: 'chunks/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n ...viteConfig?.build?.rollupOptions?.output,\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(\n rootConfig,\n viteManifest,\n elementsMap\n );\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n const rootManifest = assetMap.toJson();\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(rootManifest, 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` using the\n // root manifest. Ignore route files.\n console.log('\\njs/css output:');\n makeDir(path.join(buildDir, 'assets'));\n makeDir(path.join(buildDir, 'chunks'));\n Object.keys(rootManifest).forEach((src) => {\n // Don't expose route files in the final output. If any client-side code\n // relies on route dependencies, it should probably be broken out into a\n // shared component instead.\n if (isRouteFile(src)) {\n return;\n }\n const assetData = rootManifest[src];\n const assetRelPath = assetData.assetUrl.slice(1);\n const assetFrom = path.join(distDir, 'client', assetRelPath);\n const assetTo = path.join(buildDir, assetRelPath);\n fsExtra.copySync(assetFrom, assetTo);\n printFileOutput(fileSize(assetTo), 'dist/html/', assetRelPath);\n });\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 console.log('\\nhtml output:');\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 outFilePath = path.join(urlPath.slice(1), 'index.html');\n if (outFilePath.endsWith('404/index.html')) {\n outFilePath = outFilePath.replace('404/index.html', '404.html');\n }\n const outPath = path.join(buildDir, outFilePath);\n\n let html = data.html || '';\n if (rootConfig.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\n }\n await writeFile(outPath, html);\n\n printFileOutput(fileSize(outPath), 'dist/html/', outFilePath);\n })\n );\n }\n}\n\nfunction isRouteFile(filepath: string) {\n return filepath.startsWith('routes') && isJsFile(filepath);\n}\n\nfunction fileSize(filepath: string) {\n const stats = fsExtra.statSync(filepath);\n const bytes = stats.size;\n\n const k = 1024;\n if (bytes < k) {\n return (bytes / k).toFixed(2) + ' kB';\n }\n const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + units[i];\n}\n\nfunction printFileOutput(\n fileSize: string,\n outputDir: string,\n outputFile: string\n) {\n const indent = ' '.repeat(2);\n const paddedSize = fileSize.padStart(9, ' ');\n console.log(\n `${indent}${dim(paddedSize)} ${dim(outputDir)}${cyan(outputFile)}`\n );\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport {ElementModule} from 'virtual:root-elements';\nimport {Manifest} from 'vite';\nimport {RootConfig} from '../../core/config';\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private srcToAsset: Map<string, BuildAsset>;\n\n constructor(rootConfig: RootConfig) {\n this.rootConfig = rootConfig;\n this.srcToAsset = new Map();\n }\n\n async get(src: string): Promise<Asset | null> {\n const asset = this.srcToAsset.get(src);\n if (asset) {\n return asset;\n }\n // Try resolving the realpath of the asset, following symlinks.\n const realSrc = realPathRelativeTo(this.rootConfig.rootDir, src);\n if (realSrc !== src) {\n const asset = this.srcToAsset.get(realSrc);\n if (asset) {\n return asset;\n }\n }\n console.log(`could not find build asset: ${src}`);\n return null;\n }\n\n private add(asset: BuildAsset) {\n this.srcToAsset.set(asset.src, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const src of this.srcToAsset.keys()) {\n result[src] = this.srcToAsset.get(src)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n rootConfig: RootConfig,\n viteManifest: Manifest,\n elementMap: Record<string, ElementModule>\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n\n const elementFiles = new Set();\n Object.values(elementMap).forEach((elementModule) => {\n elementFiles.add(elementModule.src);\n // Vite will resolve symlinks, so we need to follow the src and add the\n // realpath to the element files.\n const realSrc = realPathRelativeTo(rootConfig.rootDir, elementModule.src);\n if (realSrc !== elementModule.src) {\n elementFiles.add(realSrc);\n }\n });\n\n Object.keys(viteManifest).forEach((manifestKey) => {\n const src = manifestKey;\n const manifestChunk = viteManifest[manifestKey];\n const isElement = elementFiles.has(src);\n const assetData = {\n src: src,\n assetUrl: `/${manifestChunk.file}`,\n importedModules: manifestChunk.imports || [],\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(\n rootConfig: RootConfig,\n rootManifest: BuildAssetManifest\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\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\n/**\n * Returns the realpath of a src file, relative to the rootDir.\n */\nfunction realPathRelativeTo(rootDir: string, src: string) {\n const fullPath = path.resolve(rootDir, src);\n if (!fs.existsSync(fullPath)) {\n return src;\n }\n const realpath = fs.realpathSync(path.resolve(rootDir, src));\n return path.relative(rootDir, realpath);\n}\n\nexport class BuildAsset {\n src: 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 src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.src = assetData.src;\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.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (src) => {\n const importedAsset = (await this.assetMap.get(src)) 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.src)) {\n return;\n }\n visited.add(asset.src);\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 src: this.src,\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';\nimport {htmlPretty} from '../../render/html-pretty.js';\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(rootConfig, 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.path;\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.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\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';\nimport {htmlPretty} from '../../render/html-pretty';\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(rootConfig, 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.path;\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.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\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;;;ACAjB,OAAOC,SAAQ;AACf,OAAOC,WAAU;AACjB,OAAO,UAAU;AAEjB,SAAQ,8BAA6B;;;ACJrC,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;AASA,eAAsB,MAAM,SAAiB;AAC3C,QAAM,GAAG,GAAG,SAAS,EAAC,WAAW,MAAM,OAAO,KAAI,CAAC;AACrD;AAEA,eAAsB,SAAsB,UAA8B;AACxE,QAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO;AACnD,SAAO,KAAK,MAAM,O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AI,WAAW,eAAe,OAAO;AACnC,eAAO,MAAM,WAAW,MAAM,WAAW,iBAAiB;AAAA,MAC5D;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","fs","path","path","fs","path","path","searchForWorkspaceRoot","path","searchForWorkspaceRoot","glob","path","createServer","glob","path","fileURLToPath","fsExtra","glob","fs","path","asset","dim","__dirname","path","fileURLToPath","dim","glob","fsExtra","fileSize","path","express","dim","path","createServer","dim","express","path","express","dim","sirv","compression","path","createServer","dim","express","compression","sirv"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Express, Request as Request$1, Response as Response$1, NextFunction as NextFunction$1 } from 'express';
|
|
2
2
|
import { ViteDevServer, PluginOption, UserConfig } from 'vite';
|
|
3
3
|
import { ComponentType } from 'preact';
|
|
4
|
+
import { Options } from 'html-minifier-terser';
|
|
5
|
+
import { HTMLBeautifyOptions } from 'js-beautify';
|
|
4
6
|
|
|
5
7
|
interface RouteModule {
|
|
6
8
|
default?: ComponentType<unknown>;
|
|
@@ -141,6 +143,10 @@ interface Plugin {
|
|
|
141
143
|
declare function configureServerPlugins(server: Server, callback: () => Promise<void>, plugins: Plugin[], options: ConfigureServerOptions): Promise<void>;
|
|
142
144
|
declare function getVitePlugins(plugins: Plugin[]): PluginOption[];
|
|
143
145
|
|
|
146
|
+
declare type HtmlMinifyOptions = Options;
|
|
147
|
+
|
|
148
|
+
declare type HtmlPrettyOptions = HTMLBeautifyOptions;
|
|
149
|
+
|
|
144
150
|
interface RootUserConfig {
|
|
145
151
|
/**
|
|
146
152
|
* Config for auto-injecting custom element dependencies.
|
|
@@ -176,6 +182,18 @@ interface RootUserConfig {
|
|
|
176
182
|
* in order to disable, pass `minifyHtml: false` to root.config.ts.
|
|
177
183
|
*/
|
|
178
184
|
minifyHtml?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Options to pass to html-minifier-terser.
|
|
187
|
+
*/
|
|
188
|
+
minifyHtmlOptions?: HtmlMinifyOptions;
|
|
189
|
+
/**
|
|
190
|
+
* Whether to pretty print HTML output.
|
|
191
|
+
*/
|
|
192
|
+
prettyHtml?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Options to pass to js-beautify.
|
|
195
|
+
*/
|
|
196
|
+
prettyHtmlOptions?: HtmlPrettyOptions;
|
|
179
197
|
/**
|
|
180
198
|
* Whether to include a sitemap.xml file to the build output.
|
|
181
199
|
*/
|
package/dist/core.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as preact from 'preact';
|
|
2
2
|
import { ComponentChildren } from 'preact';
|
|
3
|
-
import { R as Route } from './config-
|
|
4
|
-
export { C as ConfigureServerHook, f as ConfigureServerOptions, i as GetStaticPaths, G as GetStaticProps, N as NextFunction, P as Plugin, j as Request, k as Response, b as RootConfig, c as RootI18nConfig, d as RootServerConfig, a as RootUserConfig, S as Server, g as configureServerPlugins, e as defineConfig, h as getVitePlugins } from './config-
|
|
3
|
+
import { R as Route } from './config-0a9ae264.js';
|
|
4
|
+
export { C as ConfigureServerHook, f as ConfigureServerOptions, i as GetStaticPaths, G as GetStaticProps, N as NextFunction, P as Plugin, j as Request, k as Response, b as RootConfig, c as RootI18nConfig, d as RootServerConfig, a as RootUserConfig, S as Server, g as configureServerPlugins, e as defineConfig, h as getVitePlugins } from './config-0a9ae264.js';
|
|
5
5
|
import 'express';
|
|
6
6
|
import 'vite';
|
|
7
|
+
import 'html-minifier-terser';
|
|
8
|
+
import 'js-beautify';
|
|
7
9
|
|
|
8
10
|
interface ErrorPageProps {
|
|
9
11
|
error: unknown;
|
|
@@ -24,11 +26,11 @@ interface HtmlContextValue {
|
|
|
24
26
|
attrs: Record<string, string>;
|
|
25
27
|
}
|
|
26
28
|
declare const HTML_CONTEXT: preact.Context<HtmlContextValue>;
|
|
27
|
-
declare type HtmlProps = {
|
|
28
|
-
|
|
29
|
-
}
|
|
29
|
+
declare type HtmlProps = preact.JSX.HTMLAttributes<HTMLHtmlElement> & {
|
|
30
|
+
children?: ComponentChildren;
|
|
31
|
+
};
|
|
30
32
|
/**
|
|
31
|
-
* The
|
|
33
|
+
* The `<Html>` component can be used to update attrs used in the `<html>` tag.
|
|
32
34
|
*
|
|
33
35
|
* Usage:
|
|
34
36
|
*
|
|
@@ -42,7 +44,7 @@ declare type HtmlProps = {
|
|
|
42
44
|
* );
|
|
43
45
|
* }
|
|
44
46
|
*/
|
|
45
|
-
declare function Html({ children, ...attrs }: HtmlProps):
|
|
47
|
+
declare function Html({ children, ...attrs }: HtmlProps): ComponentChildren;
|
|
46
48
|
|
|
47
49
|
declare const SCRIPT_CONTEXT: preact.Context<ScriptProps[]>;
|
|
48
50
|
interface ScriptProps {
|
package/dist/core.js
CHANGED
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/config.ts"],"sourcesContent":["import {Request, Response, NextFunction} from './types';\nimport {Plugin} from './plugin';\nimport {UserConfig as ViteUserConfig} from 'vite';\n\nexport interface RootUserConfig {\n /**\n * Config for auto-injecting custom element dependencies.\n */\n elements?: {\n /**\n * A list of directories to use to look for custom elements. The dir path\n * should be relative to the project dir, e.g. \"path/to/elements\" or\n * \"node_modules/my-package\".\n */\n include?: string[];\n\n /**\n * A list of RegEx patterns to exclude. The string passed to the RegEx is\n * the file URL relative to the project root, e.g. \"/elements/foo/foo.ts\".\n */\n exclude?: RegExp[];\n };\n\n /**\n * Config options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Config options for the Root.js express server.\n */\n server?: RootServerConfig;\n\n /**\n * Vite config.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Whether to automatically minify HTML output. This is enabled by default,\n * in order to disable, pass `minifyHtml: false` to root.config.ts.\n */\n minifyHtml?: boolean;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\n\n /**\n * Plugins.\n */\n plugins?: Plugin[];\n}\n\nexport type RootConfig = RootUserConfig & {\n rootDir: string;\n};\n\nexport interface RootI18nConfig {\n /**\n * Locales enabled for the site.\n */\n locales?: string[];\n\n /**\n * The default locale to use. Defaults is `en`.\n */\n defaultLocale?: string;\n\n /**\n * URL format for localized content. Default is `/{locale}/{path}`.\n */\n urlFormat?: string;\n}\n\nexport interface RootServerConfig {\n /**\n * An array of middleware to add to the express server. These middleware are\n * added to the beginning of the express app.\n */\n middlewares?: Array<\n (req: Request, res: Response, next: NextFunction) => void | Promise<void>\n >;\n}\n\nexport function defineConfig(config: RootUserConfig): RootUserConfig {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/core/config.ts"],"sourcesContent":["import {Request, Response, NextFunction} from './types';\nimport {Plugin} from './plugin';\nimport {UserConfig as ViteUserConfig} from 'vite';\nimport {HtmlMinifyOptions} from '../render/html-minify';\nimport {HtmlPrettyOptions} from '../render/html-pretty';\n\nexport interface RootUserConfig {\n /**\n * Config for auto-injecting custom element dependencies.\n */\n elements?: {\n /**\n * A list of directories to use to look for custom elements. The dir path\n * should be relative to the project dir, e.g. \"path/to/elements\" or\n * \"node_modules/my-package\".\n */\n include?: string[];\n\n /**\n * A list of RegEx patterns to exclude. The string passed to the RegEx is\n * the file URL relative to the project root, e.g. \"/elements/foo/foo.ts\".\n */\n exclude?: RegExp[];\n };\n\n /**\n * Config options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Config options for the Root.js express server.\n */\n server?: RootServerConfig;\n\n /**\n * Vite config.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Whether to automatically minify HTML output. This is enabled by default,\n * in order to disable, pass `minifyHtml: false` to root.config.ts.\n */\n minifyHtml?: boolean;\n\n /**\n * Options to pass to html-minifier-terser.\n */\n minifyHtmlOptions?: HtmlMinifyOptions;\n\n /**\n * Whether to pretty print HTML output.\n */\n prettyHtml?: boolean;\n\n /**\n * Options to pass to js-beautify.\n */\n prettyHtmlOptions?: HtmlPrettyOptions;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\n\n /**\n * Plugins.\n */\n plugins?: Plugin[];\n}\n\nexport type RootConfig = RootUserConfig & {\n rootDir: string;\n};\n\nexport interface RootI18nConfig {\n /**\n * Locales enabled for the site.\n */\n locales?: string[];\n\n /**\n * The default locale to use. Defaults is `en`.\n */\n defaultLocale?: string;\n\n /**\n * URL format for localized content. Default is `/{locale}/{path}`.\n */\n urlFormat?: string;\n}\n\nexport interface RootServerConfig {\n /**\n * An array of middleware to add to the express server. These middleware are\n * added to the beginning of the express app.\n */\n middlewares?: Array<\n (req: Request, res: Response, next: NextFunction) => void | Promise<void>\n >;\n}\n\nexport function defineConfig(config: RootUserConfig): RootUserConfig {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwGO,SAAS,aAAa,QAAwC;AACnE,SAAO;AACT;","names":[]}
|
package/dist/render.d.ts
CHANGED
package/dist/render.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blinkk/root",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
4
|
"author": "s@blinkk.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"fs-extra": "^10.1.0",
|
|
36
36
|
"html-minifier-terser": "^7.0.0",
|
|
37
37
|
"joycon": "^3.1.1",
|
|
38
|
+
"js-beautify": "^1.14.7",
|
|
38
39
|
"kleur": "^4.1.5",
|
|
39
40
|
"sass": "^1.49.9",
|
|
40
41
|
"sirv": "^2.0.2",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@types/express": "^4.17.13",
|
|
51
52
|
"@types/fs-extra": "^9.0.13",
|
|
52
53
|
"@types/html-minifier-terser": "^7.0.0",
|
|
54
|
+
"@types/js-beautify": "^1.13.3",
|
|
53
55
|
"@types/node": "^18.7.14",
|
|
54
56
|
"@types/preact-custom-element": "^4.0.1",
|
|
55
57
|
"nodemon": "^2.0.19",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/components/error-page.tsx","../src/core/components/head.ts","../src/core/components/html.ts","../src/core/components/script.ts","../src/core/i18n.ts","../src/core/request-context.ts"],"sourcesContent":["export interface ErrorPageProps {\n error: unknown;\n}\n\nexport function ErrorPage(props: ErrorPageProps) {\n const error = props.error;\n\n let message = undefined;\n if (import.meta.env.DEV) {\n if (error instanceof Error) {\n message = error.stack;\n } else {\n message = String(error);\n }\n }\n\n return (\n <div>\n <div>\n <p>An error occured during route handling or page rendering.</p>\n {message && <pre>{message}</pre>}\n </div>\n </div>\n );\n}\n","import {ComponentChildren, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const HEAD_CONTEXT = createContext<ComponentChildren[]>([]);\n\nexport interface HeadProps {\n children?: ComponentChildren;\n}\n\n/**\n * The <Head> component can be used for injecting elements into the HTML head\n * tag from any part of a page.\n */\nexport function Head(props: HeadProps) {\n let context: ComponentChildren[];\n try {\n context = useContext(HEAD_CONTEXT);\n } catch (err) {\n console.log(err);\n throw new Error(\n '<Head> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props.children);\n return null;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport interface HtmlContextValue {\n attrs: Record<string, string>;\n}\n\nexport const HTML_CONTEXT = createContext<HtmlContextValue>({attrs: {}});\n\nexport type HtmlProps = {\n [key: string]: string;\n} & preact.JSX.HTMLAttributes<HTMLHtmlElement>;\n\n/**\n * The <Html> component can be used to update attrs used in the <html> tag.\n *\n * Usage:\n *\n * import {Html} from '@blinkk/root';\n *\n * export default function Page() {\n * return (\n * <Html lang={locale}>\n * <h1>Hello world</h1>\n * </Html>\n * );\n * }\n */\nexport function Html({children, ...attrs}: HtmlProps) {\n let context: Record<string, any>;\n try {\n context = useContext(HTML_CONTEXT);\n context.attrs = attrs;\n } catch (err) {\n console.log(err);\n throw new Error(\n '<Html> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n return children;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const SCRIPT_CONTEXT = createContext<ScriptProps[]>([]);\n\nexport interface ScriptProps {\n src: string;\n type?: string;\n}\n\n/**\n * The <Script> component is used for rendering any custom script modules. At\n * the moment, the system only pre-renders and bundles files that are in the\n * `/bundles` folder at the root of the project.\n */\nexport function Script(props: ScriptProps) {\n let context: ScriptProps[];\n try {\n context = useContext(SCRIPT_CONTEXT);\n } catch (err) {\n throw new Error(\n '<Script> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props);\n return null;\n}\n","import path from 'node:path';\nimport {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const I18N_CONTEXT = createContext<I18nContext | null>(null);\n\nexport interface I18nContext {\n locale: string;\n translations: Record<string, string>;\n}\n\nexport function getTranslations(locale: string): Record<string, string> {\n const translations: Record<string, Record<string, string>> = {};\n const translationsFiles = import.meta.glob(['/translations/*.json'], {\n eager: true,\n }) as Record<string, {default?: Record<string, string>}>;\n Object.keys(translationsFiles).forEach((translationPath) => {\n const parts = path.parse(translationPath);\n const locale = parts.name;\n const module = translationsFiles[translationPath];\n if (module && module.default) {\n translations[locale] = module.default;\n }\n });\n return translations[locale] || {};\n}\n\nexport function useI18nContext() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('could not find i18n context');\n }\n return context;\n}\n\nexport function useTranslations() {\n const context = useI18nContext();\n const translations = context.translations || {};\n const t = (str: string, params?: Record<string, string>) => {\n let translation = translations[str] || str || '';\n if (params) {\n for (const key of Object.keys(params)) {\n const val = String(params[key] || '');\n translation = translation.replaceAll(`{${key}}`, val);\n }\n }\n return translation;\n };\n return t;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {Route} from '../render/router';\n\nexport interface RequestContext {\n /** The route file. */\n route: Route;\n /**\n * Route param values. E.g. for a route like `routes/blog/[slug].tsx`,\n * visiting `/blog/foo` will pass {slug: 'foo'} here.\n */\n routeParams: Record<string, string>;\n /** Props passed to the route's server component. */\n props: any;\n /** The current locale. */\n locale: string;\n /** Translations map for the current locale. */\n translations: Record<string, string>;\n}\n\nexport const REQUEST_CONTEXT = createContext<RequestContext | null>(null);\n\nexport function useRequestContext() {\n const context = useContext(REQUEST_CONTEXT);\n if (!context) {\n throw new Error('could not find request context');\n }\n return context;\n}\n"],"mappings":";AAkBM,SACE,KADF;AAdC,SAAS,UAAU,OAAuB;AAC/C,QAAM,QAAQ,MAAM;AAEpB,MAAI,UAAU;AACd,MAAI,YAAY,IAAI,KAAK;AACvB,QAAI,iBAAiB,OAAO;AAC1B,gBAAU,MAAM;AAAA,IAClB,OAAO;AACL,gBAAU,OAAO,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SACE,oBAAC;AAAA,IACC,+BAAC;AAAA,MACC;AAAA,4BAAC;AAAA,UAAE;AAAA,SAAyD;AAAA,QAC3D,WAAW,oBAAC;AAAA,UAAK;AAAA,SAAQ;AAAA;AAAA,KAC5B;AAAA,GACF;AAEJ;;;ACxBA,SAA2B,qBAAoB;AAC/C,SAAQ,kBAAiB;AAElB,IAAM,eAAe,cAAmC,CAAC,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AiB,EAAE,QAAQ,CAAC,oBAAoB;AAC1D,UAAM,QAAQ,KAAK,MAAM,eAAe;AACxC,UAAME,UAAS,MAAM;AACrB,UAAM,SAAS,kBAAkB;AACjC,QAAI,UAAU,OAAO,SAAS;AAC5B,mBAAaA,WAAU,OAAO;AAAA,IAChC;AAAA,EACF,CAAC;AACD,SAAO,aAAa,WAAW,CAAC;AAClC;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAUD,YAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB;AAChC,QAAM,UAAU,eAAe;AAC/B,QAAM,eAAe,QAAQ,gBAAgB,CAAC;AAC9C,QAAM,IAAI,CAAC,KAAa,WAAoC;AAC1D,QAAI,cAAc,aAAa,QAAQ,OAAO;AAC9C,QAAI,QAAQ;AACV,iBAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AACrC,cAAM,MAAM,OAAO,OAAO,QAAQ,EAAE;AACpC,sBAAc,YAAY,WAAW,IAAI,QAAQ,GAAG;AAAA,MACtD;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ACjDA,SAAQ,iBAAAE,sBAAoB;AAC5B,SAAQ,cAAAC,mBAAiB;AAmBlB,IAAM,kBAAkBD,eAAqC,IAAI;AAEjE,SAAS,oBAAoB;AAClC,QAAM,UAAUC,YAAW,eAAe;AAC1C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO;AACT;","names":["createContext","useContext","createContext","useContext","createContext","useContext","locale","createContext","useContext"]}
|