@blinkk/root 1.0.0-alpha.4 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/root.js +19 -15
- package/dist/{chunk-CDPH3RKE.js → chunk-5FQTLGCQ.js} +22 -5
- package/dist/{chunk-CDPH3RKE.js.map → chunk-5FQTLGCQ.js.map} +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +102 -62
- package/dist/cli.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/render.js +89 -62
- package/dist/render.js.map +1 -1
- package/dist/{types-07f4e3d2.d.ts → types-27ca8c1c.d.ts} +4 -0
- package/package.json +2 -2
package/bin/root.js
CHANGED
|
@@ -10,20 +10,24 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
11
11
|
const packageJson = require(path.join(__dirname, '../package.json'));
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
program
|
|
13
|
+
async function main() {
|
|
14
|
+
const program = new Command('root');
|
|
15
|
+
program.version(packageJson.version);
|
|
15
16
|
|
|
16
|
-
program
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
program
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
program
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
program
|
|
18
|
+
.command('build [path]')
|
|
19
|
+
.description('generates a static build')
|
|
20
|
+
.action(build);
|
|
21
|
+
program
|
|
22
|
+
.command('dev [path]')
|
|
23
|
+
.description('starts the server in development mode')
|
|
24
|
+
.action(dev);
|
|
25
|
+
program
|
|
26
|
+
.command('start [path]')
|
|
27
|
+
.description('starts the server in production mode')
|
|
28
|
+
.action(start);
|
|
28
29
|
|
|
29
|
-
program.
|
|
30
|
+
await program.parseAsync(process.argv);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
main();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/components/error-page.tsx
|
|
2
|
-
import {
|
|
2
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
3
3
|
function ErrorPage(props) {
|
|
4
4
|
const error = props.error;
|
|
5
5
|
let message = void 0;
|
|
@@ -10,7 +10,18 @@ function ErrorPage(props) {
|
|
|
10
10
|
message = String(error);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
return /* @__PURE__ */
|
|
13
|
+
return /* @__PURE__ */ jsx("div", {
|
|
14
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
15
|
+
children: [
|
|
16
|
+
/* @__PURE__ */ jsx("p", {
|
|
17
|
+
children: "An error occured during route handling or page rendering."
|
|
18
|
+
}),
|
|
19
|
+
message && /* @__PURE__ */ jsx("pre", {
|
|
20
|
+
children: message
|
|
21
|
+
})
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
});
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
// src/core/components/head.ts
|
|
@@ -23,7 +34,10 @@ function Head(props) {
|
|
|
23
34
|
context = useContext(HEAD_CONTEXT);
|
|
24
35
|
} catch (err) {
|
|
25
36
|
console.log(err);
|
|
26
|
-
throw new Error(
|
|
37
|
+
throw new Error(
|
|
38
|
+
"<Head> component is not supported in the browser, or during suspense renders.",
|
|
39
|
+
{ cause: err }
|
|
40
|
+
);
|
|
27
41
|
}
|
|
28
42
|
context.push(props.children);
|
|
29
43
|
return null;
|
|
@@ -38,7 +52,10 @@ function Script(props) {
|
|
|
38
52
|
try {
|
|
39
53
|
context = useContext2(SCRIPT_CONTEXT);
|
|
40
54
|
} catch (err) {
|
|
41
|
-
throw new Error(
|
|
55
|
+
throw new Error(
|
|
56
|
+
"<Script> component is not supported in the browser, or during suspense renders.",
|
|
57
|
+
{ cause: err }
|
|
58
|
+
);
|
|
42
59
|
}
|
|
43
60
|
context.push(props);
|
|
44
61
|
return null;
|
|
@@ -93,4 +110,4 @@ export {
|
|
|
93
110
|
getTranslations,
|
|
94
111
|
useTranslations
|
|
95
112
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
113
|
+
//# sourceMappingURL=chunk-5FQTLGCQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/components/error-page.tsx","../src/core/components/head.ts","../src/core/components/script.ts","../src/core/i18n.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport {h} from 'preact';\n\nexport 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 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 * `src/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 useTranslations() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('could not find i18n context');\n }\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"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/core/components/error-page.tsx","../src/core/components/head.ts","../src/core/components/script.ts","../src/core/i18n.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport {h} from 'preact';\n\nexport 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 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 * `src/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 useTranslations() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('could not find i18n context');\n }\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(`{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AAS,gBAAgB,QAAwC;AACtE,QAAM,eAAuD,CAAC;AAC9D,QAAM,oBAAoB,YAAY,KAAK,CAAC,sBAAsB,GAAG;AAAA,IACnE,OAAO;AAAA,EACT,CAAC;AACD,SAAO,KAAK,iBAAiB,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,kBAAkB;AAChC,QAAM,UAAUD,YAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,QAAM,gBAAe,mCAAS,iBAAgB,CAAC;AAC/C,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;","names":["createContext","useContext","createContext","useContext","locale"]}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -65,28 +65,32 @@ function pluginRoot(options) {
|
|
|
65
65
|
includeDirs.forEach((dirPath) => {
|
|
66
66
|
const elementsDir = path2.resolve(rootDir, dirPath);
|
|
67
67
|
if (!elementsDir.startsWith(rootDir)) {
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error(
|
|
69
|
+
`the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`
|
|
70
|
+
);
|
|
69
71
|
}
|
|
70
72
|
elementsDirs.push(elementsDir);
|
|
71
73
|
});
|
|
72
74
|
let elementMap;
|
|
73
75
|
async function updateElementMap() {
|
|
74
76
|
elementMap = {};
|
|
75
|
-
await Promise.all(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const files = await glob("**/*", { cwd: dirPath });
|
|
81
|
-
files.forEach((file) => {
|
|
82
|
-
const parts = path2.parse(file);
|
|
83
|
-
if (isJsFile(parts.base)) {
|
|
84
|
-
const fullPath = path2.join(dirPath, file);
|
|
85
|
-
const moduleId = fullPath.slice(rootDir.length);
|
|
86
|
-
elementMap[parts.name] = moduleId;
|
|
77
|
+
await Promise.all(
|
|
78
|
+
elementsDirs.map(async (dirPath) => {
|
|
79
|
+
const dirExists = await isDirectory(dirPath);
|
|
80
|
+
if (!dirExists) {
|
|
81
|
+
return;
|
|
87
82
|
}
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
const files = await glob("**/*", { cwd: dirPath });
|
|
84
|
+
files.forEach((file) => {
|
|
85
|
+
const parts = path2.parse(file);
|
|
86
|
+
if (isJsFile(parts.base)) {
|
|
87
|
+
const fullPath = path2.join(dirPath, file);
|
|
88
|
+
const moduleId = fullPath.slice(rootDir.length);
|
|
89
|
+
elementMap[parts.name] = moduleId;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
})
|
|
93
|
+
);
|
|
90
94
|
}
|
|
91
95
|
async function getElementImport(tagname) {
|
|
92
96
|
if (!elementMap) {
|
|
@@ -139,12 +143,14 @@ function pluginRoot(options) {
|
|
|
139
143
|
deps.add(tagname);
|
|
140
144
|
}
|
|
141
145
|
const importUrls = [];
|
|
142
|
-
await Promise.all(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
await Promise.all(
|
|
147
|
+
Array.from(deps).map(async (tagname) => {
|
|
148
|
+
const importUrl = await getElementImport(tagname);
|
|
149
|
+
if (importUrl) {
|
|
150
|
+
importUrls.push(importUrl);
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
);
|
|
148
154
|
if (importUrls.length > 0) {
|
|
149
155
|
const importLines = importUrls.map((url) => `import '${url}';`).join("\n");
|
|
150
156
|
const code = `${src}
|
|
@@ -276,7 +282,7 @@ async function htmlMinify(html) {
|
|
|
276
282
|
|
|
277
283
|
// src/cli/commands/dev.ts
|
|
278
284
|
import glob2 from "tiny-glob";
|
|
279
|
-
var
|
|
285
|
+
var __dirname = path4.dirname(fileURLToPath(import.meta.url));
|
|
280
286
|
async function createServer(options) {
|
|
281
287
|
const app = express();
|
|
282
288
|
app.use(express.static("public"));
|
|
@@ -285,14 +291,14 @@ async function createServer(options) {
|
|
|
285
291
|
const port = parseInt(process.env.PORT || "4007");
|
|
286
292
|
console.log("\u{1F333} Root.js");
|
|
287
293
|
console.log();
|
|
288
|
-
console.log(`Started server: http://localhost:${port}`);
|
|
294
|
+
console.log(`Started dev server: http://localhost:${port}`);
|
|
289
295
|
app.listen(port);
|
|
290
296
|
}
|
|
291
297
|
async function getMiddlewares(options) {
|
|
292
298
|
const rootDir = (options == null ? void 0 : options.rootDir) || process.cwd();
|
|
293
299
|
const rootConfig = await loadRootConfig(rootDir);
|
|
294
300
|
const viteConfig = rootConfig.vite || {};
|
|
295
|
-
const renderModulePath = path4.resolve(
|
|
301
|
+
const renderModulePath = path4.resolve(__dirname, "./render.js");
|
|
296
302
|
const pages = [];
|
|
297
303
|
if (await isDirectory(path4.join(rootDir, "routes"))) {
|
|
298
304
|
const pageFiles = await glob2(path4.join(rootDir, "routes/**/*"));
|
|
@@ -325,6 +331,7 @@ async function getMiddlewares(options) {
|
|
|
325
331
|
}
|
|
326
332
|
const viteServer = await createViteServer({
|
|
327
333
|
...viteConfig,
|
|
334
|
+
mode: "development",
|
|
328
335
|
server: { middlewareMode: true },
|
|
329
336
|
appType: "custom",
|
|
330
337
|
optimizeDeps: {
|
|
@@ -341,20 +348,28 @@ async function getMiddlewares(options) {
|
|
|
341
348
|
});
|
|
342
349
|
const rootMiddleware = async (req, res, next) => {
|
|
343
350
|
const url = req.originalUrl;
|
|
344
|
-
|
|
345
|
-
const renderer = new render.Renderer(rootConfig);
|
|
351
|
+
let renderer = null;
|
|
346
352
|
try {
|
|
353
|
+
const render = await viteServer.ssrLoadModule(renderModulePath);
|
|
354
|
+
renderer = new render.Renderer(rootConfig);
|
|
347
355
|
const assetMap = new DevServerAssetMap(viteServer.moduleGraph);
|
|
348
356
|
const data = await renderer.render(url, {
|
|
349
357
|
assetMap
|
|
350
358
|
});
|
|
351
|
-
|
|
359
|
+
let html = await viteServer.transformIndexHtml(url, data.html || "");
|
|
360
|
+
if (rootConfig.minifyHtml !== false) {
|
|
361
|
+
html = await htmlMinify(html);
|
|
362
|
+
}
|
|
352
363
|
res.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
353
364
|
} catch (e) {
|
|
354
365
|
viteServer.ssrFixStacktrace(e);
|
|
355
366
|
try {
|
|
356
|
-
|
|
357
|
-
|
|
367
|
+
if (renderer) {
|
|
368
|
+
const { html } = await renderer.renderError(e);
|
|
369
|
+
res.status(500).set({ "Content-Type": "text/html" }).end(html);
|
|
370
|
+
} else {
|
|
371
|
+
next(e);
|
|
372
|
+
}
|
|
358
373
|
} catch (e2) {
|
|
359
374
|
console.error("failed to render custom error");
|
|
360
375
|
console.error(e2);
|
|
@@ -364,8 +379,13 @@ async function getMiddlewares(options) {
|
|
|
364
379
|
};
|
|
365
380
|
return [viteServer.middlewares, rootMiddleware];
|
|
366
381
|
}
|
|
367
|
-
function dev(rootDir) {
|
|
368
|
-
|
|
382
|
+
async function dev(rootDir) {
|
|
383
|
+
process.env.NODE_ENV = "development";
|
|
384
|
+
try {
|
|
385
|
+
await createServer({ rootDir });
|
|
386
|
+
} catch (err) {
|
|
387
|
+
console.error("an error occurred");
|
|
388
|
+
}
|
|
369
389
|
}
|
|
370
390
|
|
|
371
391
|
// src/cli/commands/build.ts
|
|
@@ -384,7 +404,10 @@ var BuildAssetMap = class {
|
|
|
384
404
|
this.moduleIdToAsset = /* @__PURE__ */ new Map();
|
|
385
405
|
Object.keys(this.manifest).forEach((manifestKey) => {
|
|
386
406
|
const moduleId = `/${manifestKey}`;
|
|
387
|
-
this.moduleIdToAsset.set(
|
|
407
|
+
this.moduleIdToAsset.set(
|
|
408
|
+
moduleId,
|
|
409
|
+
new BuildAsset(this, moduleId, this.manifest[manifestKey])
|
|
410
|
+
);
|
|
388
411
|
});
|
|
389
412
|
}
|
|
390
413
|
async get(moduleId) {
|
|
@@ -407,8 +430,12 @@ var BuildAsset = class {
|
|
|
407
430
|
this.moduleId = moduleId;
|
|
408
431
|
this.manifestData = manifestData;
|
|
409
432
|
this.assetUrl = `/${manifestData.file}`;
|
|
410
|
-
this.importedModules = (this.manifestData.imports || []).map(
|
|
411
|
-
|
|
433
|
+
this.importedModules = (this.manifestData.imports || []).map(
|
|
434
|
+
(relPath) => `/${relPath}`
|
|
435
|
+
);
|
|
436
|
+
this.importedCss = (this.manifestData.css || []).map(
|
|
437
|
+
(relPath) => `/${relPath}`
|
|
438
|
+
);
|
|
412
439
|
}
|
|
413
440
|
async getCssDeps() {
|
|
414
441
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -437,10 +464,12 @@ var BuildAsset = class {
|
|
|
437
464
|
if ([".js", ".jsx", ".ts", ".tsx"].includes(parts.ext) && this.assetMap.isElement(asset.moduleId)) {
|
|
438
465
|
urls.add(asset.assetUrl);
|
|
439
466
|
}
|
|
440
|
-
await Promise.all(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
467
|
+
await Promise.all(
|
|
468
|
+
asset.importedModules.map(async (moduleId) => {
|
|
469
|
+
const importedAsset = await this.assetMap.get(moduleId);
|
|
470
|
+
this.collectJs(importedAsset, urls, visited);
|
|
471
|
+
})
|
|
472
|
+
);
|
|
444
473
|
}
|
|
445
474
|
async collectCss(asset, urls, visited) {
|
|
446
475
|
if (!asset) {
|
|
@@ -456,10 +485,12 @@ var BuildAsset = class {
|
|
|
456
485
|
if (asset.importedCss) {
|
|
457
486
|
asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));
|
|
458
487
|
}
|
|
459
|
-
await Promise.all(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
488
|
+
await Promise.all(
|
|
489
|
+
asset.importedModules.map(async (moduleId) => {
|
|
490
|
+
const importedAsset = await this.assetMap.get(moduleId);
|
|
491
|
+
this.collectCss(importedAsset, urls, visited);
|
|
492
|
+
})
|
|
493
|
+
);
|
|
463
494
|
}
|
|
464
495
|
toJson() {
|
|
465
496
|
return {
|
|
@@ -472,7 +503,7 @@ var BuildAsset = class {
|
|
|
472
503
|
};
|
|
473
504
|
|
|
474
505
|
// src/cli/commands/build.ts
|
|
475
|
-
var
|
|
506
|
+
var __dirname2 = path6.dirname(fileURLToPath2(import.meta.url));
|
|
476
507
|
async function build(rootProjectDir) {
|
|
477
508
|
var _a;
|
|
478
509
|
console.log("\u{1F333} Root.js");
|
|
@@ -496,7 +527,9 @@ async function build(rootProjectDir) {
|
|
|
496
527
|
for (const dirPath of elementsInclude) {
|
|
497
528
|
const elementsDir = path6.resolve(rootDir, dirPath);
|
|
498
529
|
if (!elementsDir.startsWith(rootDir)) {
|
|
499
|
-
throw new Error(
|
|
530
|
+
throw new Error(
|
|
531
|
+
`the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`
|
|
532
|
+
);
|
|
500
533
|
}
|
|
501
534
|
elementsDirs.push(elementsDir);
|
|
502
535
|
}
|
|
@@ -543,7 +576,7 @@ async function build(rootProjectDir) {
|
|
|
543
576
|
publicDir: false,
|
|
544
577
|
build: {
|
|
545
578
|
rollupOptions: {
|
|
546
|
-
input: [path6.resolve(
|
|
579
|
+
input: [path6.resolve(__dirname2, "./render.js")],
|
|
547
580
|
output: {
|
|
548
581
|
format: "esm",
|
|
549
582
|
chunkFileNames: "chunks/[name].[hash].js",
|
|
@@ -587,9 +620,14 @@ async function build(rootProjectDir) {
|
|
|
587
620
|
reportCompressedSize: false
|
|
588
621
|
}
|
|
589
622
|
});
|
|
590
|
-
const manifest = await loadJson(
|
|
623
|
+
const manifest = await loadJson(
|
|
624
|
+
path6.join(distDir, "client/manifest.json")
|
|
625
|
+
);
|
|
591
626
|
const assetMap = new BuildAssetMap(manifest, { elementMap });
|
|
592
|
-
writeFile(
|
|
627
|
+
writeFile(
|
|
628
|
+
path6.join(distDir, "client/root-manifest.json"),
|
|
629
|
+
JSON.stringify(assetMap.toJson(), null, 2)
|
|
630
|
+
);
|
|
593
631
|
const buildDir = path6.join(distDir, "html");
|
|
594
632
|
const publicDir = path6.join(rootDir, "public");
|
|
595
633
|
if (fsExtra2.existsSync(path6.join(rootDir, "public"))) {
|
|
@@ -602,21 +640,23 @@ async function build(rootProjectDir) {
|
|
|
602
640
|
const render = await import(path6.join(distDir, "server/render.js"));
|
|
603
641
|
const renderer = new render.Renderer(rootConfig);
|
|
604
642
|
const sitemap = await renderer.getSitemap();
|
|
605
|
-
await Promise.all(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
643
|
+
await Promise.all(
|
|
644
|
+
Object.keys(sitemap).map(async (urlPath) => {
|
|
645
|
+
const { route, params } = sitemap[urlPath];
|
|
646
|
+
const data = await renderer.renderRoute(route, {
|
|
647
|
+
assetMap,
|
|
648
|
+
routeParams: params
|
|
649
|
+
});
|
|
650
|
+
let outPath = path6.join(distDir, `html${urlPath}`, "index.html");
|
|
651
|
+
if (outPath.endsWith("404/index.html")) {
|
|
652
|
+
outPath = outPath.replace("404/index.html", "404.html");
|
|
653
|
+
}
|
|
654
|
+
const html = await htmlMinify(data.html || "");
|
|
655
|
+
await writeFile(outPath, html);
|
|
656
|
+
const relPath = outPath.slice(path6.dirname(distDir).length + 1);
|
|
657
|
+
console.log(`saved ${relPath}`);
|
|
658
|
+
})
|
|
659
|
+
);
|
|
620
660
|
}
|
|
621
661
|
|
|
622
662
|
// src/cli/commands/start.ts
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/commands/dev.ts","../src/render/vite-plugin-root.ts","../src/core/fsutils.ts","../src/render/asset-map/dev-asset-map.ts","../src/cli/load-config.ts","../src/render/html-minify.ts","../src/cli/commands/build.ts","../src/render/asset-map/build-asset-map.ts","../src/cli/commands/start.ts"],"sourcesContent":["import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {default as express, Request, Response, NextFunction} 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 {Renderer} from '../../render/render.js';\nimport {isDirectory, isJsFile} from '../../core/fsutils.js';\nimport glob from 'tiny-glob';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function createServer(options?: {rootDir?: string}) {\n const app = express();\n\n app.use(express.static('public'));\n const middlewares = await getMiddlewares({rootDir: options?.rootDir});\n middlewares.forEach((middleware) => app.use(middleware));\n\n const port = parseInt(process.env.PORT || '4007');\n console.log('🌳 Root.js');\n console.log();\n console.log(`Started server: http://localhost:${port}`);\n app.listen(port);\n}\n\nexport async function getMiddlewares(options?: {rootDir?: string}) {\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = await loadRootConfig(rootDir);\n const viteConfig = rootConfig.vite || {};\n const renderModulePath = path.resolve(__dirname, './render.js');\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elements: string[] = [];\n if (await isDirectory(path.join(rootDir, 'elements'))) {\n const elementFiles = await glob(path.join(rootDir, 'elements/**/*'));\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n elements.push(file);\n }\n });\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteServer = await createViteServer({\n ...viteConfig,\n server: {middlewareMode: true},\n appType: 'custom',\n optimizeDeps: {\n include: [...pages, ...elements, ...bundleScripts],\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: [...(viteConfig.plugins || []), pluginRoot({rootDir, rootConfig})],\n });\n\n const rootMiddleware = async (\n req: Request,\n res: Response,\n next: NextFunction\n ) => {\n const url = req.originalUrl;\n const render = await viteServer.ssrLoadModule(renderModulePath);\n const renderer = new render.Renderer(rootConfig) as Renderer;\n try {\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(viteServer.moduleGraph);\n const data = await renderer.render(url, {\n assetMap: assetMap,\n });\n // Inject the Vite HMR client.\n const html = await htmlMinify(\n await viteServer.transformIndexHtml(url, data.html || '')\n );\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 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 return [viteServer.middlewares, rootMiddleware];\n}\n\nexport function dev(rootDir?: string) {\n createServer({rootDir});\n}\n","import path from 'path';\nimport glob from 'tiny-glob';\nimport {RootConfig} from '../core/config';\nimport {isDirectory, isJsFile} from '../core/fsutils';\n\nconst JSX_ELEMENTS_REGEX = /jsxs?\\(\"(\\w[\\w-]+\\w)\"/g;\nconst HTML_ELEMENTS_REGEX = /<(\\w[\\w-]+\\w)/g;\n\nexport interface RootPluginOptions {\n rootDir: string;\n rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options?: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = options?.rootConfig || {};\n const elementsDirs = [path.join(rootDir, 'elements')];\n const includeDirs = rootConfig.elements?.include || [];\n includeDirs.forEach((dirPath) => {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n });\n\n let elementMap: Record<string, string>;\n async function updateElementMap() {\n elementMap = {};\n await Promise.all(\n elementsDirs.map(async (dirPath: string) => {\n const dirExists = await isDirectory(dirPath);\n if (!dirExists) {\n return;\n }\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n elementMap[parts.name] = moduleId;\n }\n });\n })\n );\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!elementMap) {\n await updateElementMap();\n }\n if (tagname in elementMap) {\n return elementMap[tagname];\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return elementsDirs.some((elementsDir) => {\n return id.startsWith(elementsDir);\n });\n }\n\n return {\n name: 'vite-plugin-root',\n\n resolveId(id: string) {\n if (id === elementsVirtualId) {\n return resolvedElementsVirtualId;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === resolvedElementsVirtualId) {\n await updateElementMap();\n return `export const elementsMap = ${JSON.stringify(elementMap)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n const idParts = path.parse(id);\n const deps = new Set<string>();\n const tagnames = [\n ...src.matchAll(JSX_ELEMENTS_REGEX),\n ...src.matchAll(HTML_ELEMENTS_REGEX),\n ];\n for (const match of tagnames) {\n const tagname = match[1];\n // All custom elements should contain a dash.\n if (!tagname.includes('-')) {\n continue;\n }\n // Avoid circular deps.\n if (tagname === idParts.name) {\n continue;\n }\n deps.add(tagname);\n }\n const importUrls: string[] = [];\n await Promise.all(\n Array.from(deps).map(async (tagname) => {\n const importUrl = await getElementImport(tagname);\n if (importUrl) {\n importUrls.push(importUrl);\n }\n })\n );\n if (importUrls.length > 0) {\n const importLines = importUrls\n .map((url) => `import '${url}';`)\n .join('\\n');\n const code = `${src}\n\n// autogenerated by root:\n${importLines}\n`;\n return {code};\n }\n return null;\n }\n return null;\n },\n };\n}\n","import {promises as fs} from 'node:fs';\nimport path from 'node:path';\nimport fsExtra from 'fs-extra';\n\nexport function isJsFile(filename: string) {\n return !!filename.match(/\\.(j|t)sx?$/);\n}\n\nexport async function writeFile(filepath: string, content: string) {\n const dirPath = path.dirname(filepath);\n await makeDir(dirPath);\n await fs.writeFile(filepath, content);\n}\n\nexport async function makeDir(dirpath: string) {\n try {\n await fs.access(dirpath);\n } catch (e) {\n await fs.mkdir(dirpath, {recursive: true});\n }\n}\n\nexport async function copyDir(srcdir: string, dstdir: string) {\n if (!fsExtra.existsSync(srcdir)) {\n return;\n }\n fsExtra.copySync(srcdir, dstdir, {recursive: true, overwrite: true});\n}\n\nexport async function rmDir(dirpath: string) {\n await fs.rm(dirpath, {recursive: true, force: true});\n}\n\nexport async function loadJson<T = unknown>(filepath: string): Promise<T> {\n const content = await fs.readFile(filepath, 'utf-8');\n return JSON.parse(content);\n}\n\nexport async function isDirectory(dirpath: string) {\n return fs\n .stat(dirpath)\n .then((fsStat) => {\n return fsStat.isDirectory();\n })\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return false;\n }\n throw err;\n });\n}\n\nexport function fileExists(filepath: string): Promise<boolean> {\n return fs\n .access(filepath)\n .then(() => true)\n .catch(() => false);\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private moduleGraph: ModuleGraph;\n\n constructor(moduleGraph: ModuleGraph) {\n this.moduleGraph = moduleGraph;\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n const viteModule = await this.moduleGraph.getModuleByUrl(moduleId);\n if (!viteModule || !viteModule.id) {\n return null;\n }\n return new DevServerAsset(this, viteModule);\n }\n}\n\nexport class DevServerAsset implements Asset {\n moduleId: string;\n assetUrl: string;\n private assetMap: AssetMap;\n private viteModule: ModuleNode;\n\n constructor(assetMap: AssetMap, viteModule: ModuleNode) {\n this.assetMap = assetMap;\n this.viteModule = viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.moduleId.endsWith('.scss')) {\n const parts = path.parse(asset.assetUrl);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {bundleRequire} from 'bundle-require';\nimport JoyCon from 'joycon';\nimport {RootConfig} from '../core/config';\n\nexport async function loadRootConfig(rootDir: string): Promise<RootConfig> {\n const joycon = new JoyCon();\n const configPath = await joycon.resolve({\n cwd: rootDir,\n files: ['root.config.ts'],\n });\n if (configPath) {\n const configBundle = await bundleRequire({\n filepath: configPath,\n });\n return configBundle.mod.default || {};\n }\n return {};\n}\n","import {minify} from 'html-minifier-terser';\n\nexport async function htmlMinify(html: string): Promise<string> {\n const min = await minify(html, {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n });\n return min.trimStart();\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport fsExtra from 'fs-extra';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, UserConfig} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {\n copyDir,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../core/fsutils.js';\nimport {Renderer} from '../../render/render.js';\nimport {htmlMinify} from '../../render/html-minify.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function build(rootProjectDir?: string) {\n console.log('🌳 Root.js');\n\n const rootDir = rootProjectDir || process.cwd();\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n await rmDir(distDir);\n await makeDir(distDir);\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n const elementMap: Record<string, string> = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n elements.push(fullPath);\n elementMap[parts.name] = moduleId;\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: [...(viteConfig.plugins || []), pluginRoot({rootDir, rootConfig})],\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 mode: 'production',\n publicDir: false,\n build: {\n rollupOptions: {\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n });\n\n // Pre-render any client scripts and CSS deps.\n await viteBuild({\n ...baseConfig,\n mode: 'production',\n publicDir: false,\n build: {\n rollupOptions: {\n input: [...pages, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n });\n\n const manifest = 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 = new BuildAssetMap(manifest, {elementMap});\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(assetMap.toJson(), null, 2)\n );\n\n // Write SSG output to `dist/html`.\n const buildDir = path.join(distDir, 'html');\n\n // Recursively copy files from `public` to `dist/html`.\n const publicDir = path.join(rootDir, 'public');\n if (fsExtra.existsSync(path.join(rootDir, 'public'))) {\n fsExtra.copySync(publicDir, buildDir);\n } else {\n makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html`.\n copyDir(path.join(distDir, 'client/assets'), path.join(buildDir, 'assets'));\n copyDir(path.join(distDir, 'client/chunks'), path.join(buildDir, 'chunks'));\n\n // Render HTML pages.\n const render = await import(path.join(distDir, 'server/render.js'));\n const renderer = new render.Renderer(rootConfig) as Renderer;\n const sitemap = await renderer.getSitemap();\n\n await Promise.all(\n Object.keys(sitemap).map(async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n const data = await renderer.renderRoute(route, {\n assetMap,\n routeParams: params,\n });\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outPath = path.join(distDir, `html${urlPath}`, 'index.html');\n\n if (outPath.endsWith('404/index.html')) {\n outPath = outPath.replace('404/index.html', '404.html');\n }\n\n const html = await htmlMinify(data.html || '');\n await writeFile(outPath, html);\n\n const relPath = outPath.slice(path.dirname(distDir).length + 1);\n console.log(`saved ${relPath}`);\n })\n );\n}\n","import path from 'path';\nimport {Manifest, ManifestChunk} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\ntype BuildAssetManifest = Record<\n string,\n {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private manifest: Manifest;\n private moduleIdToAsset: Map<string, BuildAsset>;\n private elementMap: Record<string, string>;\n\n constructor(\n manifest: Manifest,\n options: {elementMap: Record<string, string>}\n ) {\n this.manifest = manifest;\n this.elementMap = options.elementMap;\n this.moduleIdToAsset = new Map();\n Object.keys(this.manifest).forEach((manifestKey) => {\n const moduleId = `/${manifestKey}`;\n this.moduleIdToAsset.set(\n moduleId,\n new BuildAsset(this, moduleId, this.manifest[manifestKey])\n );\n });\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n return this.moduleIdToAsset.get(moduleId) || null;\n }\n\n isElement(moduleId: string): boolean {\n return Object.values(this.elementMap).includes(moduleId);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const moduleId of this.moduleIdToAsset.keys()) {\n result[moduleId] = this.moduleIdToAsset.get(moduleId)!.toJson();\n }\n return result;\n }\n}\n\nexport class BuildAsset {\n moduleId: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private manifestData: ManifestChunk;\n private importedModules: string[];\n private importedCss: string[];\n\n constructor(\n assetMap: BuildAssetMap,\n moduleId: string,\n manifestData: ManifestChunk\n ) {\n this.assetMap = assetMap;\n this.moduleId = moduleId;\n this.manifestData = manifestData;\n this.assetUrl = `/${manifestData.file}`;\n this.importedModules = (this.manifestData.imports || []).map(\n (relPath) => `/${relPath}`\n );\n this.importedCss = (this.manifestData.css || []).map(\n (relPath) => `/${relPath}`\n );\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n this.assetMap.isElement(asset.moduleId)\n ) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n moduleId: this.moduleId,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n };\n }\n}\n","export async function start() {\n console.log('SSR production server is coming soon');\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;;;ACHA;AACA;;;ACDA;AACA;AACA;AAEO,kBAAkB,UAAkB;AACzC,SAAO,CAAC,CAAC,SAAS,MAAM,aAAa;AACvC;AAEA,yBAAgC,UAAkB,SAAiB;AACjE,QAAM,UAAU,KAAK,QAAQ,QAAQ;AACrC,QAAM,QAAQ,OAAO;AACrB,QAAM,GAAG,UAAU,UAAU,OAAO;AACtC;AAEA,uBAA8B,SAAiB;AAC7C,MAAI;AACF,UAAM,GAAG,OAAO,OAAO;AAAA,EACzB,SAAS,GAAP;AACA,UAAM,GAAG,MAAM,SAAS,EAAC,WAAW,KAAI,CAAC;AAAA,EAC3C;AACF;AAEA,uBAA8B,QAAgB,QAAgB;AAC5D,MAAI,CAAC,QAAQ,WAAW,MAAM,GAAG;AAC/B;AAAA,EACF;AACA,UAAQ,SAAS,QAAQ,QAAQ,EAAC,WAAW,MAAM,WAAW,KAAI,CAAC;AACrE;AAEA,qBAA4B,SAAiB;AAC3C,QAAM,GAAG,GAAG,SAAS,EAAC,WAAW,MAAM,OAAO,KAAI,CAAC;AACrD;AAEA,wBAA4C,UAA8B;AACxE,QAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO;AACnD,SAAO,KAAK,MAAM,OAAO;AAC3B;AAEA,2BAAkC,SAAiB;AACjD,SAAO,GACJ,KAAK,OAAO,EACZ,KAAK,CAAC,WAAW;AAChB,WAAO,OAAO,YAAY;AAAA,EAC5B,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,QAAI,IAAI,SAAS,UAAU;AACzB,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR,CAAC;AACL;;;AD7CA,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAOrB,oBAAoB,SAA6B;AAbxD;AAcE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AAU,QAAQ,MAAM,MAAK,QAAQ,OAAO,EAAE,SAAS,CAAC;AAC9D,YAAQ,IAAI,SAAS,SAAS;AAAA,EAChC,CAAC,CACH;AACF;;;AE7MA,uBAA8B;AAC5B,UAAQ,IAAI,sCAAsC;AACpD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/dev.ts","../src/render/vite-plugin-root.ts","../src/core/fsutils.ts","../src/render/asset-map/dev-asset-map.ts","../src/cli/load-config.ts","../src/render/html-minify.ts","../src/cli/commands/build.ts","../src/render/asset-map/build-asset-map.ts","../src/cli/commands/start.ts"],"sourcesContent":["import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {default as express, Request, Response, NextFunction} 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 {Renderer} from '../../render/render.js';\nimport {isDirectory, isJsFile} from '../../core/fsutils.js';\nimport glob from 'tiny-glob';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function createServer(options?: {rootDir?: string}) {\n const app = express();\n\n app.use(express.static('public'));\n const middlewares = await getMiddlewares({rootDir: options?.rootDir});\n middlewares.forEach((middleware) => app.use(middleware));\n\n const port = parseInt(process.env.PORT || '4007');\n console.log('🌳 Root.js');\n console.log();\n console.log(`Started dev server: http://localhost:${port}`);\n app.listen(port);\n}\n\nexport async function getMiddlewares(options?: {rootDir?: string}) {\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = await loadRootConfig(rootDir);\n const viteConfig = rootConfig.vite || {};\n const renderModulePath = path.resolve(__dirname, './render.js');\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elements: string[] = [];\n if (await isDirectory(path.join(rootDir, 'elements'))) {\n const elementFiles = await glob(path.join(rootDir, 'elements/**/*'));\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n elements.push(file);\n }\n });\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteServer = await createViteServer({\n ...viteConfig,\n mode: 'development',\n server: {middlewareMode: true},\n appType: 'custom',\n optimizeDeps: {\n include: [...pages, ...elements, ...bundleScripts],\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n },\n plugins: [...(viteConfig.plugins || []), pluginRoot({rootDir, rootConfig})],\n });\n\n const rootMiddleware = async (\n req: Request,\n res: Response,\n next: NextFunction\n ) => {\n const url = req.originalUrl;\n let renderer: Renderer | null = null;\n try {\n const render = await viteServer.ssrLoadModule(renderModulePath);\n renderer = new render.Renderer(rootConfig) as Renderer;\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(viteServer.moduleGraph);\n const data = await renderer.render(url, {\n assetMap: assetMap,\n });\n // Inject the Vite HMR client.\n let html = await viteServer.transformIndexHtml(url, data.html || '');\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html);\n }\n res.status(200).set({'Content-Type': 'text/html'}).end(html);\n } catch (e) {\n // If an error is caught, let Vite fix the stack trace so it maps back to\n // your actual source code.\n viteServer.ssrFixStacktrace(e);\n 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 return [viteServer.middlewares, rootMiddleware];\n}\n\nexport async function dev(rootDir?: string) {\n process.env.NODE_ENV = 'development';\n try {\n await createServer({rootDir});\n } catch (err) {\n console.error('an error occurred');\n }\n}\n","import path from 'path';\nimport glob from 'tiny-glob';\nimport {RootConfig} from '../core/config';\nimport {isDirectory, isJsFile} from '../core/fsutils';\n\nconst JSX_ELEMENTS_REGEX = /jsxs?\\(\"(\\w[\\w-]+\\w)\"/g;\nconst HTML_ELEMENTS_REGEX = /<(\\w[\\w-]+\\w)/g;\n\nexport interface RootPluginOptions {\n rootDir: string;\n rootConfig: RootConfig;\n}\n\nexport function pluginRoot(options?: RootPluginOptions) {\n const elementsVirtualId = 'virtual:root-elements';\n const resolvedElementsVirtualId = '\\0' + elementsVirtualId;\n\n const rootDir = options?.rootDir || process.cwd();\n const rootConfig = options?.rootConfig || {};\n const elementsDirs = [path.join(rootDir, 'elements')];\n const includeDirs = rootConfig.elements?.include || [];\n includeDirs.forEach((dirPath) => {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n });\n\n let elementMap: Record<string, string>;\n async function updateElementMap() {\n elementMap = {};\n await Promise.all(\n elementsDirs.map(async (dirPath: string) => {\n const dirExists = await isDirectory(dirPath);\n if (!dirExists) {\n return;\n }\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n elementMap[parts.name] = moduleId;\n }\n });\n })\n );\n }\n\n async function getElementImport(tagname: string): Promise<string | null> {\n if (!elementMap) {\n await updateElementMap();\n }\n if (tagname in elementMap) {\n return elementMap[tagname];\n }\n return null;\n }\n\n function isCustomElement(id: string) {\n if (!isJsFile(id)) {\n return false;\n }\n return elementsDirs.some((elementsDir) => {\n return id.startsWith(elementsDir);\n });\n }\n\n return {\n name: 'vite-plugin-root',\n\n resolveId(id: string) {\n if (id === elementsVirtualId) {\n return resolvedElementsVirtualId;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === resolvedElementsVirtualId) {\n await updateElementMap();\n return `export const elementsMap = ${JSON.stringify(elementMap)}`;\n }\n return null;\n },\n\n async transform(src: string, id: string): Promise<any> {\n if (isCustomElement(id)) {\n const idParts = path.parse(id);\n const deps = new Set<string>();\n const tagnames = [\n ...src.matchAll(JSX_ELEMENTS_REGEX),\n ...src.matchAll(HTML_ELEMENTS_REGEX),\n ];\n for (const match of tagnames) {\n const tagname = match[1];\n // All custom elements should contain a dash.\n if (!tagname.includes('-')) {\n continue;\n }\n // Avoid circular deps.\n if (tagname === idParts.name) {\n continue;\n }\n deps.add(tagname);\n }\n const importUrls: string[] = [];\n await Promise.all(\n Array.from(deps).map(async (tagname) => {\n const importUrl = await getElementImport(tagname);\n if (importUrl) {\n importUrls.push(importUrl);\n }\n })\n );\n if (importUrls.length > 0) {\n const importLines = importUrls\n .map((url) => `import '${url}';`)\n .join('\\n');\n const code = `${src}\n\n// autogenerated by root:\n${importLines}\n`;\n return {code};\n }\n return null;\n }\n return null;\n },\n };\n}\n","import {promises as fs} from 'node:fs';\nimport path from 'node:path';\nimport fsExtra from 'fs-extra';\n\nexport function isJsFile(filename: string) {\n return !!filename.match(/\\.(j|t)sx?$/);\n}\n\nexport async function writeFile(filepath: string, content: string) {\n const dirPath = path.dirname(filepath);\n await makeDir(dirPath);\n await fs.writeFile(filepath, content);\n}\n\nexport async function makeDir(dirpath: string) {\n try {\n await fs.access(dirpath);\n } catch (e) {\n await fs.mkdir(dirpath, {recursive: true});\n }\n}\n\nexport async function copyDir(srcdir: string, dstdir: string) {\n if (!fsExtra.existsSync(srcdir)) {\n return;\n }\n fsExtra.copySync(srcdir, dstdir, {recursive: true, overwrite: true});\n}\n\nexport async function rmDir(dirpath: string) {\n await fs.rm(dirpath, {recursive: true, force: true});\n}\n\nexport async function loadJson<T = unknown>(filepath: string): Promise<T> {\n const content = await fs.readFile(filepath, 'utf-8');\n return JSON.parse(content);\n}\n\nexport async function isDirectory(dirpath: string) {\n return fs\n .stat(dirpath)\n .then((fsStat) => {\n return fsStat.isDirectory();\n })\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return false;\n }\n throw err;\n });\n}\n\nexport function fileExists(filepath: string): Promise<boolean> {\n return fs\n .access(filepath)\n .then(() => true)\n .catch(() => false);\n}\n","import path from 'node:path';\nimport {ModuleGraph, ModuleNode} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private moduleGraph: ModuleGraph;\n\n constructor(moduleGraph: ModuleGraph) {\n this.moduleGraph = moduleGraph;\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n const viteModule = await this.moduleGraph.getModuleByUrl(moduleId);\n if (!viteModule || !viteModule.id) {\n return null;\n }\n return new DevServerAsset(this, viteModule);\n }\n}\n\nexport class DevServerAsset implements Asset {\n moduleId: string;\n assetUrl: string;\n private assetMap: AssetMap;\n private viteModule: ModuleNode;\n\n constructor(assetMap: AssetMap, viteModule: ModuleNode) {\n this.assetMap = assetMap;\n this.viteModule = viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.moduleId.endsWith('.scss')) {\n const parts = path.parse(asset.assetUrl);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.id) {\n const importedAsset = new DevServerAsset(this.assetMap, viteModule);\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {bundleRequire} from 'bundle-require';\nimport JoyCon from 'joycon';\nimport {RootConfig} from '../core/config';\n\nexport async function loadRootConfig(rootDir: string): Promise<RootConfig> {\n const joycon = new JoyCon();\n const configPath = await joycon.resolve({\n cwd: rootDir,\n files: ['root.config.ts'],\n });\n if (configPath) {\n const configBundle = await bundleRequire({\n filepath: configPath,\n });\n return configBundle.mod.default || {};\n }\n return {};\n}\n","import {minify} from 'html-minifier-terser';\n\nexport async function htmlMinify(html: string): Promise<string> {\n const min = await minify(html, {\n collapseWhitespace: true,\n removeComments: true,\n preserveLineBreaks: true,\n });\n return min.trimStart();\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport fsExtra from 'fs-extra';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, UserConfig} from 'vite';\nimport {pluginRoot} from '../../render/vite-plugin-root.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {loadRootConfig} from '../load-config.js';\nimport {\n copyDir,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../core/fsutils.js';\nimport {Renderer} from '../../render/render.js';\nimport {htmlMinify} from '../../render/html-minify.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport async function build(rootProjectDir?: string) {\n console.log('🌳 Root.js');\n\n const rootDir = rootProjectDir || process.cwd();\n const rootConfig = await loadRootConfig(rootDir);\n const distDir = path.join(rootDir, 'dist');\n await rmDir(distDir);\n await makeDir(distDir);\n\n const pages: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob(path.join(rootDir, 'routes/**/*'));\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n pages.push(file);\n }\n });\n }\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!elementsDir.startsWith(rootDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be relative to the project's root dir (${rootDir})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n const elements: string[] = [];\n const elementMap: Record<string, string> = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const elementFiles = await glob('**/*', {cwd: dirPath});\n elementFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n const fullPath = path.join(dirPath, file);\n const moduleId = fullPath.slice(rootDir.length);\n elements.push(fullPath);\n elementMap[parts.name] = moduleId;\n }\n });\n }\n }\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob(path.join(rootDir, 'bundles/*'));\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const viteConfig = rootConfig.vite || {};\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n esbuild: {\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: [...(viteConfig.plugins || []), pluginRoot({rootDir, rootConfig})],\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 mode: 'production',\n publicDir: false,\n build: {\n rollupOptions: {\n input: [path.resolve(__dirname, './render.js')],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n ssr: {\n noExternal: ['@blinkk/root'],\n },\n });\n\n // Pre-render any client scripts and CSS deps.\n await viteBuild({\n ...baseConfig,\n mode: 'production',\n publicDir: false,\n build: {\n rollupOptions: {\n input: [...pages, ...elements, ...bundleScripts],\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[name].[hash].js',\n assetFileNames: 'assets/[name].[hash][extname]',\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n polyfillModulePreload: false,\n reportCompressedSize: false,\n },\n });\n\n const manifest = 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 = new BuildAssetMap(manifest, {elementMap});\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(assetMap.toJson(), null, 2)\n );\n\n // Write SSG output to `dist/html`.\n const buildDir = path.join(distDir, 'html');\n\n // Recursively copy files from `public` to `dist/html`.\n const publicDir = path.join(rootDir, 'public');\n if (fsExtra.existsSync(path.join(rootDir, 'public'))) {\n fsExtra.copySync(publicDir, buildDir);\n } else {\n makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html`.\n copyDir(path.join(distDir, 'client/assets'), path.join(buildDir, 'assets'));\n copyDir(path.join(distDir, 'client/chunks'), path.join(buildDir, 'chunks'));\n\n // Render HTML pages.\n const render = await import(path.join(distDir, 'server/render.js'));\n const renderer = new render.Renderer(rootConfig) as Renderer;\n const sitemap = await renderer.getSitemap();\n\n await Promise.all(\n Object.keys(sitemap).map(async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n const data = await renderer.renderRoute(route, {\n assetMap,\n routeParams: params,\n });\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outPath = path.join(distDir, `html${urlPath}`, 'index.html');\n\n if (outPath.endsWith('404/index.html')) {\n outPath = outPath.replace('404/index.html', '404.html');\n }\n\n const html = await htmlMinify(data.html || '');\n await writeFile(outPath, html);\n\n const relPath = outPath.slice(path.dirname(distDir).length + 1);\n console.log(`saved ${relPath}`);\n })\n );\n}\n","import path from 'path';\nimport {Manifest, ManifestChunk} from 'vite';\nimport {Asset, AssetMap} from './asset-map';\n\ntype BuildAssetManifest = Record<\n string,\n {\n moduleId: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private manifest: Manifest;\n private moduleIdToAsset: Map<string, BuildAsset>;\n private elementMap: Record<string, string>;\n\n constructor(\n manifest: Manifest,\n options: {elementMap: Record<string, string>}\n ) {\n this.manifest = manifest;\n this.elementMap = options.elementMap;\n this.moduleIdToAsset = new Map();\n Object.keys(this.manifest).forEach((manifestKey) => {\n const moduleId = `/${manifestKey}`;\n this.moduleIdToAsset.set(\n moduleId,\n new BuildAsset(this, moduleId, this.manifest[manifestKey])\n );\n });\n }\n\n async get(moduleId: string): Promise<Asset | null> {\n return this.moduleIdToAsset.get(moduleId) || null;\n }\n\n isElement(moduleId: string): boolean {\n return Object.values(this.elementMap).includes(moduleId);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const moduleId of this.moduleIdToAsset.keys()) {\n result[moduleId] = this.moduleIdToAsset.get(moduleId)!.toJson();\n }\n return result;\n }\n}\n\nexport class BuildAsset {\n moduleId: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private manifestData: ManifestChunk;\n private importedModules: string[];\n private importedCss: string[];\n\n constructor(\n assetMap: BuildAssetMap,\n moduleId: string,\n manifestData: ManifestChunk\n ) {\n this.assetMap = assetMap;\n this.moduleId = moduleId;\n this.manifestData = manifestData;\n this.assetUrl = `/${manifestData.file}`;\n this.importedModules = (this.manifestData.imports || []).map(\n (relPath) => `/${relPath}`\n );\n this.importedCss = (this.manifestData.css || []).map(\n (relPath) => `/${relPath}`\n );\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n this.assetMap.isElement(asset.moduleId)\n ) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n moduleId: this.moduleId,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n };\n }\n}\n","export async function start() {\n console.log('SSR production server is coming soon');\n}\n"],"mappings":";AAAA,OAAOA,WAAU;AACjB,SAAQ,qBAAoB;AAC5B,SAAQ,WAAW,eAA+C;AAClE,SAAQ,gBAAgB,wBAAuB;;;ACH/C,OAAOC,WAAU;AACjB,OAAO,UAAU;;;ACDjB,SAAQ,YAAY,UAAS;AAC7B,OAAO,UAAU;AACjB,OAAO,aAAa;AAEb,SAAS,SAAS,UAAkB;AACzC,SAAO,CAAC,CAAC,SAAS,MAAM,aAAa;AACvC;AAEA,eAAsB,UAAU,UAAkB,SAAiB;AACjE,QAAM,UAAU,KAAK,QAAQ,QAAQ;AACrC,QAAM,QAAQ,OAAO;AACrB,QAAM,GAAG,UAAU,UAAU,OAAO;AACtC;AAEA,eAAsB,QAAQ,SAAiB;AAC7C,MAAI;AACF,UAAM,GAAG,OAAO,OAAO;AAAA,EACzB,SAAS,GAAP;AACA,UAAM,GAAG,MAAM,SAAS,EAAC,WAAW,KAAI,CAAC;AAAA,EAC3C;AACF;AAEA,eAAsB,QAAQ,QAAgB,QAAgB;AAC5D,MAAI,CAAC,QAAQ,WAAW,MAAM,GAAG;AAC/B;AAAA,EACF;AACA,UAAQ,SAAS,QAAQ,QAAQ,EAAC,WAAW,MAAM,WAAW,KAAI,CAAC;AACrE;AAEA,eAAsB,MAAM,SAAiB;AAC3C,QAAM,GAAG,GAAG,SAAS,EAAC,WAAW,MAAM,OAAO,KAAI,CAAC;AACrD;AAEA,eAAsB,SAAsB,UAA8B;AACxE,QAAM,UAAU,MAAM,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AsC;AACpD;","names":["path","path","path","path","glob","path","path","fileURLToPath","fsExtra","glob","path","__dirname","path","fileURLToPath","glob","fsExtra"]}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as preact from 'preact';
|
|
2
2
|
import { h, ComponentChildren } from 'preact';
|
|
3
|
-
export { b as GetStaticPaths, G as GetStaticProps, R as RootConfig, a as RootI18nConfig, d as defineConfig } from './types-
|
|
3
|
+
export { b as GetStaticPaths, G as GetStaticProps, R as RootConfig, a as RootI18nConfig, d as defineConfig } from './types-27ca8c1c.js';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
6
|
interface ErrorPageProps {
|
package/dist/core.js
CHANGED
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/config.ts"],"sourcesContent":["import {UserConfig as ViteUserConfig} from 'vite';\n\nexport interface RootConfig {\n /**\n * Configuration 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 /**\n * Configuration options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Vite configuration.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\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 function defineConfig(config: RootConfig): RootConfig {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/core/config.ts"],"sourcesContent":["import {UserConfig as ViteUserConfig} from 'vite';\n\nexport interface RootConfig {\n /**\n * Configuration 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 /**\n * Configuration options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Vite configuration.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Whether to automatically minify HTML output.\n */\n minifyHtml?: boolean;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\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 function defineConfig(config: RootConfig): RootConfig {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;AAsDO,SAAS,aAAa,QAAgC;AAC3D,SAAO;AACT;","names":[]}
|
package/dist/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType } from 'preact';
|
|
2
|
-
import { b as GetStaticPaths, G as GetStaticProps, R as RootConfig } from './types-
|
|
2
|
+
import { b as GetStaticPaths, G as GetStaticProps, R as RootConfig } from './types-27ca8c1c.js';
|
|
3
3
|
import 'vite';
|
|
4
4
|
|
|
5
5
|
interface RouteModule {
|
package/dist/render.js
CHANGED
|
@@ -4,10 +4,9 @@ import {
|
|
|
4
4
|
I18N_CONTEXT,
|
|
5
5
|
SCRIPT_CONTEXT,
|
|
6
6
|
getTranslations
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5FQTLGCQ.js";
|
|
8
8
|
|
|
9
9
|
// src/render/render.tsx
|
|
10
|
-
import { h } from "preact";
|
|
11
10
|
import renderToString from "preact-render-to-string";
|
|
12
11
|
|
|
13
12
|
// src/render/router.ts
|
|
@@ -143,9 +142,12 @@ function getRoutes(config) {
|
|
|
143
142
|
const locales = ((_a = config.i18n) == null ? void 0 : _a.locales) || [];
|
|
144
143
|
const i18nUrlFormat = ((_b = config.i18n) == null ? void 0 : _b.urlFormat) || "/{locale}/{path}";
|
|
145
144
|
const defaultLocale = ((_c = config.i18n) == null ? void 0 : _c.defaultLocale) || "en";
|
|
146
|
-
const routes = import.meta.glob(
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
const routes = import.meta.glob(
|
|
146
|
+
["/routes/*.ts", "/routes/**/*.ts", "/routes/*.tsx", "/routes/**/*.tsx"],
|
|
147
|
+
{
|
|
148
|
+
eager: true
|
|
149
|
+
}
|
|
150
|
+
);
|
|
149
151
|
const trie = new RouteTrie();
|
|
150
152
|
Object.keys(routes).forEach((filePath) => {
|
|
151
153
|
let routePath = filePath.replace(/^\/routes/, "");
|
|
@@ -181,30 +183,36 @@ async function getAllPathsForRoute(urlPathFormat, route) {
|
|
|
181
183
|
const routeModule = route.module;
|
|
182
184
|
if (routeModule.getStaticPaths) {
|
|
183
185
|
const staticPaths = await routeModule.getStaticPaths();
|
|
184
|
-
staticPaths.paths.forEach(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
staticPaths.paths.forEach(
|
|
187
|
+
(pathParams) => {
|
|
188
|
+
urlPaths.push({
|
|
189
|
+
urlPath: replaceParams(urlPathFormat, pathParams.params),
|
|
190
|
+
params: pathParams.params || {}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
);
|
|
190
194
|
} else {
|
|
191
195
|
urlPaths.push({ urlPath: urlPathFormat, params: {} });
|
|
192
196
|
}
|
|
193
197
|
return urlPaths;
|
|
194
198
|
}
|
|
195
199
|
function replaceParams(urlPathFormat, params) {
|
|
196
|
-
const urlPath = urlPathFormat.replaceAll(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
const urlPath = urlPathFormat.replaceAll(
|
|
201
|
+
/\[(\.\.\.)?([\w\-_]*)\]/g,
|
|
202
|
+
(match, _wildcard, key) => {
|
|
203
|
+
const val = params[key];
|
|
204
|
+
if (!val) {
|
|
205
|
+
throw new Error(`unreplaced param ${match} in url: ${urlPathFormat}`);
|
|
206
|
+
}
|
|
207
|
+
return val;
|
|
200
208
|
}
|
|
201
|
-
|
|
202
|
-
});
|
|
209
|
+
);
|
|
203
210
|
return urlPath;
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
// src/render/render.tsx
|
|
207
214
|
import { elementsMap } from "virtual:root-elements";
|
|
215
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
208
216
|
var Renderer = class {
|
|
209
217
|
constructor(config) {
|
|
210
218
|
this.routes = getRoutes(config);
|
|
@@ -222,7 +230,9 @@ var Renderer = class {
|
|
|
222
230
|
const assetMap = options.assetMap;
|
|
223
231
|
const Component = route.module.default;
|
|
224
232
|
if (!Component) {
|
|
225
|
-
throw new Error(
|
|
233
|
+
throw new Error(
|
|
234
|
+
"unable to render route. the route should have a default export that renders a jsx component."
|
|
235
|
+
);
|
|
226
236
|
}
|
|
227
237
|
let props = {};
|
|
228
238
|
if (route.module.getStaticProps) {
|
|
@@ -240,21 +250,24 @@ var Renderer = class {
|
|
|
240
250
|
const translations = getTranslations(locale);
|
|
241
251
|
const headComponents = [];
|
|
242
252
|
const userScripts = [];
|
|
243
|
-
const vdom = /* @__PURE__ */
|
|
244
|
-
value: { locale, translations }
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
const vdom = /* @__PURE__ */ jsx(I18N_CONTEXT.Provider, {
|
|
254
|
+
value: { locale, translations },
|
|
255
|
+
children: /* @__PURE__ */ jsx(SCRIPT_CONTEXT.Provider, {
|
|
256
|
+
value: userScripts,
|
|
257
|
+
children: /* @__PURE__ */ jsx(HEAD_CONTEXT.Provider, {
|
|
258
|
+
value: headComponents,
|
|
259
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
260
|
+
...props
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
});
|
|
252
265
|
const mainHtml = renderToString(vdom, {}, { pretty: true });
|
|
253
266
|
const pageAsset = await assetMap.get(route.modulePath);
|
|
254
267
|
const cssDeps = await (pageAsset == null ? void 0 : pageAsset.getCssDeps());
|
|
255
268
|
if (cssDeps) {
|
|
256
269
|
cssDeps.forEach((cssUrl) => {
|
|
257
|
-
headComponents.push(/* @__PURE__ */
|
|
270
|
+
headComponents.push(/* @__PURE__ */ jsx("link", {
|
|
258
271
|
rel: "stylesheet",
|
|
259
272
|
href: cssUrl
|
|
260
273
|
}));
|
|
@@ -262,22 +275,23 @@ var Renderer = class {
|
|
|
262
275
|
}
|
|
263
276
|
const scriptDeps = await this.getScriptDeps(mainHtml, { assetMap });
|
|
264
277
|
scriptDeps.forEach((jsUrls) => {
|
|
265
|
-
headComponents.push(/* @__PURE__ */
|
|
278
|
+
headComponents.push(/* @__PURE__ */ jsx("script", {
|
|
266
279
|
type: "module",
|
|
267
280
|
src: jsUrls
|
|
268
281
|
}));
|
|
269
282
|
});
|
|
270
|
-
await Promise.all(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
283
|
+
await Promise.all(
|
|
284
|
+
userScripts.map(async (scriptDep) => {
|
|
285
|
+
const scriptAsset = await assetMap.get(scriptDep.src);
|
|
286
|
+
if (scriptAsset) {
|
|
287
|
+
const scriptUrl = scriptAsset ? scriptAsset.assetUrl : scriptDep.src;
|
|
288
|
+
headComponents.push(/* @__PURE__ */ jsx("script", {
|
|
289
|
+
type: "module",
|
|
290
|
+
src: scriptUrl
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
);
|
|
281
295
|
const html = await this.renderHtml({ mainHtml, locale, headComponents });
|
|
282
296
|
return { html };
|
|
283
297
|
}
|
|
@@ -295,15 +309,28 @@ var Renderer = class {
|
|
|
295
309
|
return sitemap;
|
|
296
310
|
}
|
|
297
311
|
async renderHtml(options) {
|
|
298
|
-
const page = /* @__PURE__ */
|
|
299
|
-
lang: options.locale
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
312
|
+
const page = /* @__PURE__ */ jsxs("html", {
|
|
313
|
+
lang: options.locale,
|
|
314
|
+
children: [
|
|
315
|
+
/* @__PURE__ */ jsxs("head", {
|
|
316
|
+
children: [
|
|
317
|
+
/* @__PURE__ */ jsx("meta", {
|
|
318
|
+
charSet: "utf-8"
|
|
319
|
+
}),
|
|
320
|
+
options.headComponents
|
|
321
|
+
]
|
|
322
|
+
}),
|
|
323
|
+
/* @__PURE__ */ jsx("body", {
|
|
324
|
+
dangerouslySetInnerHTML: { __html: options.mainHtml }
|
|
325
|
+
})
|
|
326
|
+
]
|
|
327
|
+
});
|
|
305
328
|
const html = `<!doctype html>
|
|
306
|
-
${renderToString(
|
|
329
|
+
${renderToString(
|
|
330
|
+
page,
|
|
331
|
+
{},
|
|
332
|
+
{ pretty: true }
|
|
333
|
+
)}
|
|
307
334
|
`;
|
|
308
335
|
return html;
|
|
309
336
|
}
|
|
@@ -314,7 +341,7 @@ ${renderToString(page, {}, { pretty: true })}
|
|
|
314
341
|
};
|
|
315
342
|
}
|
|
316
343
|
async renderError(error) {
|
|
317
|
-
const mainHtml = renderToString(/* @__PURE__ */
|
|
344
|
+
const mainHtml = renderToString(/* @__PURE__ */ jsx(ErrorPage, {
|
|
318
345
|
error
|
|
319
346
|
}));
|
|
320
347
|
const html = await this.renderHtml({ mainHtml, locale: "en" });
|
|
@@ -325,20 +352,20 @@ ${renderToString(page, {}, { pretty: true })}
|
|
|
325
352
|
const deps = /* @__PURE__ */ new Set();
|
|
326
353
|
const re = /<(\w[\w-]+\w)/g;
|
|
327
354
|
const matches = Array.from(html.matchAll(re));
|
|
328
|
-
await Promise.all(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
355
|
+
await Promise.all(
|
|
356
|
+
matches.map(async (match) => {
|
|
357
|
+
const tagName = match[1];
|
|
358
|
+
if (tagName && tagName.includes("-") && tagName in elementsMap) {
|
|
359
|
+
const modulePath = elementsMap[tagName];
|
|
360
|
+
const asset = await assetMap.get(modulePath);
|
|
361
|
+
if (!asset) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const assetJsDeps = await asset.getJsDeps();
|
|
365
|
+
assetJsDeps.forEach((dep) => deps.add(dep));
|
|
335
366
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
} else {
|
|
339
|
-
console.log(`could not find tag name: ${tagName}`);
|
|
340
|
-
}
|
|
341
|
-
}));
|
|
367
|
+
})
|
|
368
|
+
);
|
|
342
369
|
return Array.from(deps);
|
|
343
370
|
}
|
|
344
371
|
};
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render/render.tsx","../src/render/router.ts","../src/render/route-trie.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport {h, ComponentChildren} from 'preact';\nimport renderToString from 'preact-render-to-string';\nimport {getRoutes, Route, getAllPathsForRoute} from './router';\nimport {HEAD_CONTEXT} from '../core/components/head';\nimport {ErrorPage} from '../core/components/error-page';\nimport {getTranslations, I18N_CONTEXT} from '../core/i18n';\nimport {ScriptProps, SCRIPT_CONTEXT} from '../core/components/script';\nimport {AssetMap} from './asset-map/asset-map';\nimport {RootConfig} from '../core/config';\nimport {RouteTrie} from './route-trie';\nimport {elementsMap} from 'virtual:root-elements';\n\ninterface RenderOptions {\n assetMap: AssetMap;\n}\n\ninterface RenderHtmlOptions {\n mainHtml: string;\n locale: string;\n headComponents?: ComponentChildren[];\n}\n\nexport class Renderer {\n private routes: RouteTrie<Route>;\n\n constructor(config: RootConfig) {\n this.routes = getRoutes(config);\n }\n\n async render(\n url: string,\n options: RenderOptions\n ): Promise<{html: string; notFound?: boolean}> {\n const assetMap = options.assetMap;\n const [route, routeParams] = this.routes.get(url);\n if (route && route.module && route.module.default) {\n return await this.renderRoute(route, {routeParams, assetMap});\n }\n return this.render404();\n }\n\n async renderRoute(\n route: Route,\n options: {routeParams: Record<string, string>; assetMap: AssetMap}\n ): Promise<{html: string; notFound?: boolean}> {\n const routeParams = options.routeParams;\n const assetMap = options.assetMap;\n const Component = route.module.default;\n if (!Component) {\n throw new Error(\n 'unable to render route. the route should have a default export that renders a jsx component.'\n );\n }\n let props = {};\n if (route.module.getStaticProps) {\n const propsData = await route.module.getStaticProps({\n params: routeParams,\n });\n if (propsData.notFound) {\n return this.render404();\n }\n if (propsData.props) {\n props = propsData.props;\n }\n }\n\n const locale = route.locale;\n const translations = getTranslations(locale);\n\n const headComponents: ComponentChildren[] = [];\n const userScripts: ScriptProps[] = [];\n const vdom = (\n <I18N_CONTEXT.Provider value={{locale, translations}}>\n <SCRIPT_CONTEXT.Provider value={userScripts}>\n <HEAD_CONTEXT.Provider value={headComponents}>\n <Component {...props} />\n </HEAD_CONTEXT.Provider>\n </SCRIPT_CONTEXT.Provider>\n </I18N_CONTEXT.Provider>\n );\n const mainHtml = renderToString(vdom, {}, {pretty: true});\n\n // Walk the page's dependency tree for CSS dependencies that are added via\n // `import 'foo.scss'` or `import 'foo.module.scss'`.\n const pageAsset = await assetMap.get(route.modulePath);\n const cssDeps = await pageAsset?.getCssDeps();\n if (cssDeps) {\n cssDeps.forEach((cssUrl) => {\n headComponents.push(<link rel=\"stylesheet\" href={cssUrl} />);\n });\n }\n\n // Parse the HTML for custom elements that are found within the project\n // and automatically inject the script deps for them.\n const scriptDeps = await this.getScriptDeps(mainHtml, {assetMap});\n scriptDeps.forEach((jsUrls) => {\n headComponents.push(<script type=\"module\" src={jsUrls} />);\n });\n\n // Add user defined scripts added via the `<Script>` component.\n await Promise.all(\n userScripts.map(async (scriptDep) => {\n const scriptAsset = await assetMap.get(scriptDep.src);\n if (!scriptAsset && import.meta.env.PROD) {\n console.log(`could not find precompiled asset: ${scriptDep.src}`);\n }\n const scriptUrl = scriptAsset ? scriptAsset.assetUrl : scriptDep.src;\n headComponents.push(<script type=\"module\" src={scriptUrl} />);\n })\n );\n\n const html = await this.renderHtml({mainHtml, locale, headComponents});\n return {html};\n }\n\n async getSitemap(): Promise<\n Record<string, {route: Route; params: Record<string, string>}>\n > {\n const sitemap: Record<\n string,\n {route: Route; params: Record<string, string>}\n > = {};\n await this.routes.walk(async (urlPath: string, route: Route) => {\n const routePaths = await getAllPathsForRoute(urlPath, route);\n routePaths.forEach((routePath) => {\n sitemap[routePath.urlPath] = {\n route,\n params: routePath.params,\n };\n });\n });\n return sitemap;\n }\n\n private async renderHtml(options: RenderHtmlOptions) {\n const page = (\n <html lang={options.locale}>\n <head>\n <meta charSet=\"utf-8\" />\n {options.headComponents}\n </head>\n <body dangerouslySetInnerHTML={{__html: options.mainHtml}} />\n </html>\n );\n const html = `<!doctype html>\\n${renderToString(\n page,\n {},\n {pretty: true}\n )}\\n`;\n return html;\n }\n\n async render404() {\n return {\n html: '<!doctype html><html><title>404 Not Found</title><h1>404 Not Found</h1>',\n notFound: true,\n };\n }\n\n async renderError(error: unknown) {\n const mainHtml = renderToString(<ErrorPage error={error} />);\n const html = await this.renderHtml({mainHtml, locale: 'en'});\n return {html};\n }\n\n private async getScriptDeps(\n html: string,\n options: {assetMap: AssetMap}\n ): Promise<string[]> {\n const assetMap = options.assetMap as AssetMap;\n const deps = new Set<string>();\n\n const re = /<(\\w[\\w-]+\\w)/g;\n const matches = Array.from(html.matchAll(re));\n await Promise.all(\n matches.map(async (match) => {\n const tagName = match[1];\n // Custom elements require a dash.\n if (tagName && tagName.includes('-') && tagName in elementsMap) {\n const modulePath = elementsMap[tagName];\n const asset = await assetMap.get(modulePath);\n if (!asset) {\n return;\n }\n const assetJsDeps = await asset.getJsDeps();\n assetJsDeps.forEach((dep) => deps.add(dep));\n } else {\n console.log(`could not find tag name: ${tagName}`);\n }\n })\n );\n\n return Array.from(deps);\n }\n}\n","import path from 'node:path';\nimport {ComponentType} from 'preact';\nimport {RootConfig} from '../core/config';\nimport {GetStaticPaths, GetStaticProps} from '../core/types';\nimport {RouteTrie} from './route-trie';\n\nexport interface RouteModule {\n default?: ComponentType<unknown>;\n getStaticPaths?: GetStaticPaths;\n getStaticProps?: GetStaticProps;\n}\n\nexport interface Route {\n modulePath: string;\n module: RouteModule;\n locale: string;\n}\n\nexport function getRoutes(config: RootConfig) {\n const locales = config.i18n?.locales || [];\n const i18nUrlFormat = config.i18n?.urlFormat || '/{locale}/{path}';\n const defaultLocale = config.i18n?.defaultLocale || 'en';\n\n const routes = import.meta.glob(\n ['/routes/*.ts', '/routes/**/*.ts', '/routes/*.tsx', '/routes/**/*.tsx'],\n {\n eager: true,\n }\n );\n const trie = new RouteTrie<Route>();\n Object.keys(routes).forEach((filePath) => {\n let routePath = filePath.replace(/^\\/routes/, '');\n const parts = path.parse(routePath);\n if (parts.name.startsWith('_')) {\n return;\n }\n if (parts.name === 'index') {\n routePath = parts.dir;\n } else {\n routePath = path.join(parts.dir, parts.name);\n }\n trie.add(routePath, {\n modulePath: filePath,\n module: routes[filePath] as RouteModule,\n locale: defaultLocale,\n });\n\n // At the moment, all routes are assumed to use the site-wide i18n config.\n // TODO(stevenle): provide routes with a way to override the default\n // i18n serving behavior.\n locales.forEach((locale) => {\n const localeRoutePath = i18nUrlFormat\n .replace('{locale}', locale)\n .replace('{path}', routePath.replace(/^\\/*/, ''));\n if (localeRoutePath !== routePath) {\n trie.add(localeRoutePath, {\n modulePath: filePath,\n module: routes[filePath] as RouteModule,\n locale: locale,\n });\n }\n });\n });\n return trie;\n}\n\nexport async function getAllPathsForRoute(\n urlPathFormat: string,\n route: Route\n): Promise<Array<{urlPath: string; params: Record<string, string>}>> {\n const urlPaths: Array<{urlPath: string; params: Record<string, string>}> = [];\n const routeModule = route.module;\n if (routeModule.getStaticPaths) {\n const staticPaths = await routeModule.getStaticPaths();\n staticPaths.paths.forEach(\n (pathParams: {params: Record<string, string>}) => {\n urlPaths.push({\n urlPath: replaceParams(urlPathFormat, pathParams.params),\n params: pathParams.params || {},\n });\n }\n );\n } else {\n urlPaths.push({urlPath: urlPathFormat, params: {}});\n }\n return urlPaths;\n}\n\nexport function replaceParams(\n urlPathFormat: string,\n params: Record<string, string>\n) {\n const urlPath = urlPathFormat.replaceAll(\n /\\[(\\.\\.\\.)?([\\w\\-_]*)\\]/g,\n (match: string, _wildcard: string, key: string) => {\n const val = params[key];\n if (!val) {\n throw new Error(`unreplaced param ${match} in url: ${urlPathFormat}`);\n }\n return val;\n }\n );\n return urlPath;\n}\n","/**\n * A trie data structure that stores routes. The trie supports `:param` and\n * `*wildcard` values.\n */\nexport class RouteTrie<T> {\n private children: Record<string, RouteTrie<T>> = {};\n private paramChild?: ParamChild<T>;\n private wildcardChild?: WildcardChild<T>;\n private route?: T;\n\n /**\n * Adds a route to the trie.\n */\n add(path: string, route: T) {\n path = this.normalizePath(path);\n\n // If the end was reached, save the value to the node.\n if (path === '') {\n this.route = route;\n return;\n }\n\n const [head, tail] = this.splitPath(path);\n if (head.startsWith('[...') && head.endsWith(']')) {\n const paramName = head.slice(4, -1);\n this.wildcardChild = new WildcardChild(paramName, route);\n return;\n }\n\n let nextNode: RouteTrie<T>;\n if (head.startsWith('[') && head.endsWith(']')) {\n if (!this.paramChild) {\n const paramName = head.slice(1, -1);\n this.paramChild = new ParamChild(paramName);\n }\n nextNode = this.paramChild.trie;\n } else {\n nextNode = this.children[head];\n if (!nextNode) {\n nextNode = new RouteTrie();\n this.children[head] = nextNode;\n }\n }\n nextNode.add(tail, route);\n }\n\n /**\n * Returns a route mapped to the given path and any parameter values from the\n * URL.\n */\n get(path: string): [T | undefined, Record<string, string>] {\n const params = {};\n const route = this.getRoute(path, params);\n return [route, params];\n }\n\n /**\n * Walks the route trie and calls a callback function for each route.\n */\n walk(cb: (urlPath: string, route: T) => Promise<void> | void): Promise<void> {\n const promises: Array<Promise<void>> = [];\n const addPromise = (promise: Promise<void> | void) => {\n if (promise) {\n promises.push(promise);\n }\n };\n if (this.route) {\n addPromise(cb('/', this.route));\n }\n if (this.paramChild) {\n const param = `[${this.paramChild.name}]`;\n this.paramChild.trie.walk((childPath: string, route: T) => {\n const paramUrlPath = `/${param}${childPath}`;\n addPromise(cb(paramUrlPath, route));\n });\n }\n if (this.wildcardChild) {\n const wildcardUrlPath = `/[...${this.wildcardChild.name}]`;\n addPromise(cb(wildcardUrlPath, this.wildcardChild.route));\n }\n for (const subpath of Object.keys(this.children)) {\n const childTrie = this.children[subpath];\n childTrie.walk((childPath: string, childRoute: T) => {\n addPromise(cb(`/${subpath}${childPath}`, childRoute));\n });\n }\n return Promise.all(promises).then(() => {});\n }\n\n /**\n * Removes all routes from the trie.\n */\n clear() {\n this.children = {};\n this.paramChild = undefined;\n this.wildcardChild = undefined;\n this.route = undefined;\n }\n\n private getRoute(\n urlPath: string,\n params: Record<string, string>\n ): T | undefined {\n urlPath = this.normalizePath(urlPath);\n if (urlPath === '') {\n return this.route;\n }\n\n const [head, tail] = this.splitPath(urlPath);\n\n const child = this.children[head];\n if (child) {\n const route = child.getRoute(tail, params);\n if (route) {\n return route;\n }\n }\n\n if (this.paramChild) {\n const route = this.paramChild.trie.getRoute(tail, params);\n if (route) {\n params[this.paramChild.name] = head;\n return route;\n }\n }\n\n if (this.wildcardChild) {\n params[this.wildcardChild.name] = urlPath;\n return this.wildcardChild.route;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a path for inclusion into the route trie.\n */\n private normalizePath(path: string) {\n // Remove leading slashes.\n return path.replace(/^\\/+/g, '');\n }\n\n /**\n * Splits the parent directory from its children, e.g.:\n *\n * splitPath(\"foo/bar/baz\") -> [\"foo\", \"bar/baz\"]\n */\n private splitPath(path: string): [string, string] {\n const i = path.indexOf('/');\n if (i === -1) {\n return [path, ''];\n }\n return [path.slice(0, i), path.slice(i + 1)];\n }\n}\n\n/**\n * A node in the RouteTrie for a :param child.\n */\nclass ParamChild<T> {\n readonly name: string;\n readonly trie: RouteTrie<T> = new RouteTrie();\n\n constructor(name: string) {\n this.name = name;\n }\n}\n\n/**\n * A node in the RouteTrie for a *wildcard child.\n */\nclass WildcardChild<T> {\n readonly name: string;\n readonly route: T;\n\n constructor(name: string, route: T) {\n this.name = name;\n this.route = route;\n }\n}\n"],"mappings":";;;;;;;;;AACA;AACA;;;ACFA;;;ACIO,IAAM,YAAN,MAAmB;AAAA,EAAnB;AACL,SAAQ,WAAyC,CAAC;AAAA;AAAA,EAQlD,IAAI,OAAc,OAAU;AAC1B,YAAO,KAAK,cAAc,KAAI;AAG9B,QAAI,UAAS,IAAI;AACf,WAAK,QAAQ;AACb;AAAA,IACF;AAEA,UAAM,CAAC,MAAM,QAAQ,KAAK,UAAU,KAAI;AACxC,QAAI,KAAK,WAAW,MAAM,KAAK,KAAK,SAAS,GAAG,GAAG;AACjD,YAAM,YAAY,KAAK,MAAM,GAAG,EAAE;AAClC,WAAK,gBAAgB,IAAI,cAAc,WAAW,KAAK;AACvD;AAAA,IACF;AAEA,QAAI;AACJ,QAAI,KAAK,WAAW,GAAG,KAAK,KAAK,SAAS,GAAG,GAAG;AAC9C,UAAI,CAAC,KAAK,YAAY;AACpB,cAAM,YAAY,KAAK,MAAM,GAAG,EAAE;AAClC,aAAK,aAAa,IAAI,WAAW,SAAS;AAAA,MAC5C;AACA,iBAAW,KAAK,WAAW;AAAA,IAC7B,OAAO;AACL,iBAAW,KAAK,SAAS;AACzB,UAAI,CAAC,UAAU;AACb,mBAAW,IAAI,UAAU;AACzB,aAAK,SAAS,QAAQ;AAAA,MACxB;AAAA,IACF;AACA,aAAS,IAAI,MAAM,KAAK;AAAA,EAC1B;AAAA,EAMA,IAAI,OAAuD;AACzD,UAAM,SAAS,CAAC;AAChB,UAAM,QAAQ,KAAK,SAAS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,CAAC;AAAA,MAC5C,OAAO;AACL,gBAAQ,IAAI,4BAA4B,SAAS;AAAA,MACnD;AAAA,IACF,CAAC,CACH;AAEA,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/render/render.tsx","../src/render/router.ts","../src/render/route-trie.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport {ComponentChildren} from 'preact';\nimport renderToString from 'preact-render-to-string';\nimport {getRoutes, Route, getAllPathsForRoute} from './router';\nimport {HEAD_CONTEXT} from '../core/components/head';\nimport {ErrorPage} from '../core/components/error-page';\nimport {getTranslations, I18N_CONTEXT} from '../core/i18n';\nimport {ScriptProps, SCRIPT_CONTEXT} from '../core/components/script';\nimport {AssetMap} from './asset-map/asset-map';\nimport {RootConfig} from '../core/config';\nimport {RouteTrie} from './route-trie';\nimport {elementsMap} from 'virtual:root-elements';\n\ninterface RenderOptions {\n assetMap: AssetMap;\n}\n\ninterface RenderHtmlOptions {\n mainHtml: string;\n locale: string;\n headComponents?: ComponentChildren[];\n}\n\nexport class Renderer {\n private routes: RouteTrie<Route>;\n\n constructor(config: RootConfig) {\n this.routes = getRoutes(config);\n }\n\n async render(\n url: string,\n options: RenderOptions\n ): Promise<{html: string; notFound?: boolean}> {\n const assetMap = options.assetMap;\n const [route, routeParams] = this.routes.get(url);\n if (route && route.module && route.module.default) {\n return await this.renderRoute(route, {routeParams, assetMap});\n }\n return this.render404();\n }\n\n async renderRoute(\n route: Route,\n options: {routeParams: Record<string, string>; assetMap: AssetMap}\n ): Promise<{html: string; notFound?: boolean}> {\n const routeParams = options.routeParams;\n const assetMap = options.assetMap;\n const Component = route.module.default;\n if (!Component) {\n throw new Error(\n 'unable to render route. the route should have a default export that renders a jsx component.'\n );\n }\n let props = {};\n if (route.module.getStaticProps) {\n const propsData = await route.module.getStaticProps({\n params: routeParams,\n });\n if (propsData.notFound) {\n return this.render404();\n }\n if (propsData.props) {\n props = propsData.props;\n }\n }\n\n const locale = route.locale;\n const translations = getTranslations(locale);\n\n const headComponents: ComponentChildren[] = [];\n const userScripts: ScriptProps[] = [];\n const vdom = (\n <I18N_CONTEXT.Provider value={{locale, translations}}>\n <SCRIPT_CONTEXT.Provider value={userScripts}>\n <HEAD_CONTEXT.Provider value={headComponents}>\n <Component {...props} />\n </HEAD_CONTEXT.Provider>\n </SCRIPT_CONTEXT.Provider>\n </I18N_CONTEXT.Provider>\n );\n const mainHtml = renderToString(vdom, {}, {pretty: true});\n\n // Walk the page's dependency tree for CSS dependencies that are added via\n // `import 'foo.scss'` or `import 'foo.module.scss'`.\n const pageAsset = await assetMap.get(route.modulePath);\n const cssDeps = await pageAsset?.getCssDeps();\n if (cssDeps) {\n cssDeps.forEach((cssUrl) => {\n headComponents.push(<link rel=\"stylesheet\" href={cssUrl} />);\n });\n }\n\n // Parse the HTML for custom elements that are found within the project\n // and automatically inject the script deps for them.\n const scriptDeps = await this.getScriptDeps(mainHtml, {assetMap});\n scriptDeps.forEach((jsUrls) => {\n headComponents.push(<script type=\"module\" src={jsUrls} />);\n });\n\n // Add user defined scripts added via the `<Script>` component.\n await Promise.all(\n userScripts.map(async (scriptDep) => {\n const scriptAsset = await assetMap.get(scriptDep.src);\n if (scriptAsset) {\n const scriptUrl = scriptAsset ? scriptAsset.assetUrl : scriptDep.src;\n headComponents.push(<script type=\"module\" src={scriptUrl} />);\n }\n })\n );\n\n const html = await this.renderHtml({mainHtml, locale, headComponents});\n return {html};\n }\n\n async getSitemap(): Promise<\n Record<string, {route: Route; params: Record<string, string>}>\n > {\n const sitemap: Record<\n string,\n {route: Route; params: Record<string, string>}\n > = {};\n await this.routes.walk(async (urlPath: string, route: Route) => {\n const routePaths = await getAllPathsForRoute(urlPath, route);\n routePaths.forEach((routePath) => {\n sitemap[routePath.urlPath] = {\n route,\n params: routePath.params,\n };\n });\n });\n return sitemap;\n }\n\n private async renderHtml(options: RenderHtmlOptions) {\n const page = (\n <html lang={options.locale}>\n <head>\n <meta charSet=\"utf-8\" />\n {options.headComponents}\n </head>\n <body dangerouslySetInnerHTML={{__html: options.mainHtml}} />\n </html>\n );\n const html = `<!doctype html>\\n${renderToString(\n page,\n {},\n {pretty: true}\n )}\\n`;\n return html;\n }\n\n async render404() {\n return {\n html: '<!doctype html><html><title>404 Not Found</title><h1>404 Not Found</h1>',\n notFound: true,\n };\n }\n\n async renderError(error: unknown) {\n const mainHtml = renderToString(<ErrorPage error={error} />);\n const html = await this.renderHtml({mainHtml, locale: 'en'});\n return {html};\n }\n\n private async getScriptDeps(\n html: string,\n options: {assetMap: AssetMap}\n ): Promise<string[]> {\n const assetMap = options.assetMap as AssetMap;\n const deps = new Set<string>();\n\n const re = /<(\\w[\\w-]+\\w)/g;\n const matches = Array.from(html.matchAll(re));\n await Promise.all(\n matches.map(async (match) => {\n const tagName = match[1];\n // Custom elements require a dash.\n if (tagName && tagName.includes('-') && tagName in elementsMap) {\n const modulePath = elementsMap[tagName];\n const asset = await assetMap.get(modulePath);\n if (!asset) {\n return;\n }\n const assetJsDeps = await asset.getJsDeps();\n assetJsDeps.forEach((dep) => deps.add(dep));\n }\n })\n );\n\n return Array.from(deps);\n }\n}\n","import path from 'node:path';\nimport {ComponentType} from 'preact';\nimport {RootConfig} from '../core/config';\nimport {GetStaticPaths, GetStaticProps} from '../core/types';\nimport {RouteTrie} from './route-trie';\n\nexport interface RouteModule {\n default?: ComponentType<unknown>;\n getStaticPaths?: GetStaticPaths;\n getStaticProps?: GetStaticProps;\n}\n\nexport interface Route {\n modulePath: string;\n module: RouteModule;\n locale: string;\n}\n\nexport function getRoutes(config: RootConfig) {\n const locales = config.i18n?.locales || [];\n const i18nUrlFormat = config.i18n?.urlFormat || '/{locale}/{path}';\n const defaultLocale = config.i18n?.defaultLocale || 'en';\n\n const routes = import.meta.glob(\n ['/routes/*.ts', '/routes/**/*.ts', '/routes/*.tsx', '/routes/**/*.tsx'],\n {\n eager: true,\n }\n );\n const trie = new RouteTrie<Route>();\n Object.keys(routes).forEach((filePath) => {\n let routePath = filePath.replace(/^\\/routes/, '');\n const parts = path.parse(routePath);\n if (parts.name.startsWith('_')) {\n return;\n }\n if (parts.name === 'index') {\n routePath = parts.dir;\n } else {\n routePath = path.join(parts.dir, parts.name);\n }\n trie.add(routePath, {\n modulePath: filePath,\n module: routes[filePath] as RouteModule,\n locale: defaultLocale,\n });\n\n // At the moment, all routes are assumed to use the site-wide i18n config.\n // TODO(stevenle): provide routes with a way to override the default\n // i18n serving behavior.\n locales.forEach((locale) => {\n const localeRoutePath = i18nUrlFormat\n .replace('{locale}', locale)\n .replace('{path}', routePath.replace(/^\\/*/, ''));\n if (localeRoutePath !== routePath) {\n trie.add(localeRoutePath, {\n modulePath: filePath,\n module: routes[filePath] as RouteModule,\n locale: locale,\n });\n }\n });\n });\n return trie;\n}\n\nexport async function getAllPathsForRoute(\n urlPathFormat: string,\n route: Route\n): Promise<Array<{urlPath: string; params: Record<string, string>}>> {\n const urlPaths: Array<{urlPath: string; params: Record<string, string>}> = [];\n const routeModule = route.module;\n if (routeModule.getStaticPaths) {\n const staticPaths = await routeModule.getStaticPaths();\n staticPaths.paths.forEach(\n (pathParams: {params: Record<string, string>}) => {\n urlPaths.push({\n urlPath: replaceParams(urlPathFormat, pathParams.params),\n params: pathParams.params || {},\n });\n }\n );\n } else {\n urlPaths.push({urlPath: urlPathFormat, params: {}});\n }\n return urlPaths;\n}\n\nexport function replaceParams(\n urlPathFormat: string,\n params: Record<string, string>\n) {\n const urlPath = urlPathFormat.replaceAll(\n /\\[(\\.\\.\\.)?([\\w\\-_]*)\\]/g,\n (match: string, _wildcard: string, key: string) => {\n const val = params[key];\n if (!val) {\n throw new Error(`unreplaced param ${match} in url: ${urlPathFormat}`);\n }\n return val;\n }\n );\n return urlPath;\n}\n","/**\n * A trie data structure that stores routes. The trie supports `:param` and\n * `*wildcard` values.\n */\nexport class RouteTrie<T> {\n private children: Record<string, RouteTrie<T>> = {};\n private paramChild?: ParamChild<T>;\n private wildcardChild?: WildcardChild<T>;\n private route?: T;\n\n /**\n * Adds a route to the trie.\n */\n add(path: string, route: T) {\n path = this.normalizePath(path);\n\n // If the end was reached, save the value to the node.\n if (path === '') {\n this.route = route;\n return;\n }\n\n const [head, tail] = this.splitPath(path);\n if (head.startsWith('[...') && head.endsWith(']')) {\n const paramName = head.slice(4, -1);\n this.wildcardChild = new WildcardChild(paramName, route);\n return;\n }\n\n let nextNode: RouteTrie<T>;\n if (head.startsWith('[') && head.endsWith(']')) {\n if (!this.paramChild) {\n const paramName = head.slice(1, -1);\n this.paramChild = new ParamChild(paramName);\n }\n nextNode = this.paramChild.trie;\n } else {\n nextNode = this.children[head];\n if (!nextNode) {\n nextNode = new RouteTrie();\n this.children[head] = nextNode;\n }\n }\n nextNode.add(tail, route);\n }\n\n /**\n * Returns a route mapped to the given path and any parameter values from the\n * URL.\n */\n get(path: string): [T | undefined, Record<string, string>] {\n const params = {};\n const route = this.getRoute(path, params);\n return [route, params];\n }\n\n /**\n * Walks the route trie and calls a callback function for each route.\n */\n walk(cb: (urlPath: string, route: T) => Promise<void> | void): Promise<void> {\n const promises: Array<Promise<void>> = [];\n const addPromise = (promise: Promise<void> | void) => {\n if (promise) {\n promises.push(promise);\n }\n };\n if (this.route) {\n addPromise(cb('/', this.route));\n }\n if (this.paramChild) {\n const param = `[${this.paramChild.name}]`;\n this.paramChild.trie.walk((childPath: string, route: T) => {\n const paramUrlPath = `/${param}${childPath}`;\n addPromise(cb(paramUrlPath, route));\n });\n }\n if (this.wildcardChild) {\n const wildcardUrlPath = `/[...${this.wildcardChild.name}]`;\n addPromise(cb(wildcardUrlPath, this.wildcardChild.route));\n }\n for (const subpath of Object.keys(this.children)) {\n const childTrie = this.children[subpath];\n childTrie.walk((childPath: string, childRoute: T) => {\n addPromise(cb(`/${subpath}${childPath}`, childRoute));\n });\n }\n return Promise.all(promises).then(() => {});\n }\n\n /**\n * Removes all routes from the trie.\n */\n clear() {\n this.children = {};\n this.paramChild = undefined;\n this.wildcardChild = undefined;\n this.route = undefined;\n }\n\n private getRoute(\n urlPath: string,\n params: Record<string, string>\n ): T | undefined {\n urlPath = this.normalizePath(urlPath);\n if (urlPath === '') {\n return this.route;\n }\n\n const [head, tail] = this.splitPath(urlPath);\n\n const child = this.children[head];\n if (child) {\n const route = child.getRoute(tail, params);\n if (route) {\n return route;\n }\n }\n\n if (this.paramChild) {\n const route = this.paramChild.trie.getRoute(tail, params);\n if (route) {\n params[this.paramChild.name] = head;\n return route;\n }\n }\n\n if (this.wildcardChild) {\n params[this.wildcardChild.name] = urlPath;\n return this.wildcardChild.route;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a path for inclusion into the route trie.\n */\n private normalizePath(path: string) {\n // Remove leading slashes.\n return path.replace(/^\\/+/g, '');\n }\n\n /**\n * Splits the parent directory from its children, e.g.:\n *\n * splitPath(\"foo/bar/baz\") -> [\"foo\", \"bar/baz\"]\n */\n private splitPath(path: string): [string, string] {\n const i = path.indexOf('/');\n if (i === -1) {\n return [path, ''];\n }\n return [path.slice(0, i), path.slice(i + 1)];\n }\n}\n\n/**\n * A node in the RouteTrie for a :param child.\n */\nclass ParamChild<T> {\n readonly name: string;\n readonly trie: RouteTrie<T> = new RouteTrie();\n\n constructor(name: string) {\n this.name = name;\n }\n}\n\n/**\n * A node in the RouteTrie for a *wildcard child.\n */\nclass WildcardChild<T> {\n readonly name: string;\n readonly route: T;\n\n constructor(name: string, route: T) {\n this.name = name;\n this.route = route;\n }\n}\n"],"mappings":";;;;;;;;;AAEA,OAAO,oBAAoB;;;ACF3B,OAAO,UAAU;;;ACIV,IAAM,YAAN,MAAmB;AAAA,EAAnB;AACL,SAAQ,WAAyC,CAAC;AAAA;AAAA,EAQlD,IAAIA,OAAc,OAAU;AAC1B,IAAAA,QAAO,KAAK,cAAcA,KAAI;AAG9B,QAAIA,UAAS,IAAI;AACf,WAAK,QAAQ;AACb;AAAA,IACF;AAEA,UAAM,CAAC,MAAM,IAAI,IAA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AAAA,IACf;AAAA;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY;AAChB,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,MAAM,YAAY,OAAgB;AAChC,UAAM,WAAW,eAAe,oBAAC;AAAA,MAAU;AAAA,KAAc,CAAE;AAC3D,UAAM,OAAO,MAAM,KAAK,WAAW,EAAC,UAAU,QAAQ,KAAI,CAAC;AAC3D,WAAO,EAAC,KAAI;AAAA,EACd;AAAA,EAEA,MAAc,cACZ,MACA,SACmB;AACnB,UAAM,WAAW,QAAQ;AACzB,UAAM,OAAO,oBAAI,IAAY;AAE7B,UAAM,KAAK;AACX,UAAM,UAAU,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC;AAC5C,UAAM,QAAQ;AAAA,MACZ,QAAQ,IAAI,OAAO,UAAU;AAC3B,cAAM,UAAU,MAAM;AAEtB,YAAI,WAAW,QAAQ,SAAS,GAAG,KAAK,WAAW,aAAa;AAC9D,gBAAM,aAAa,YAAY;AAC/B,gBAAM,QAAQ,MAAM,SAAS,IAAI,UAAU;AAC3C,cAAI,CAAC,OAAO;AACV;AAAA,UACF;AACA,gBAAM,cAAc,MAAM,MAAM,UAAU;AAC1C,sBAAY,QAAQ,CAAC,QAAQ,KAAK,IAAI,GAAG,CAAC;AAAA,QAC5C;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AACF;","names":["path"]}
|
|
@@ -21,6 +21,10 @@ interface RootConfig {
|
|
|
21
21
|
* @see {@link https://vitejs.dev/config/} for more information.
|
|
22
22
|
*/
|
|
23
23
|
vite?: UserConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to automatically minify HTML output.
|
|
26
|
+
*/
|
|
27
|
+
minifyHtml?: boolean;
|
|
24
28
|
/**
|
|
25
29
|
* Whether to include a sitemap.xml file to the build output.
|
|
26
30
|
*/
|
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.5",
|
|
4
4
|
"author": "s@blinkk.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"preact-custom-element": "^4.2.1",
|
|
61
61
|
"preact-render-to-string": "^5.2.3",
|
|
62
62
|
"rollup": "^2.79.0",
|
|
63
|
-
"tsup": "^
|
|
63
|
+
"tsup": "^6.2.3",
|
|
64
64
|
"typescript": "^4.7.4",
|
|
65
65
|
"vitest": "^0.18.1"
|
|
66
66
|
},
|