@blinkk/root 1.0.0-beta.52 → 1.0.0-beta.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MNTHVGVU.js → chunk-JIXJPSAN.js} +39 -79
- package/dist/chunk-JIXJPSAN.js.map +1 -0
- package/dist/chunk-LWIDSJFY.js +110 -0
- package/dist/chunk-LWIDSJFY.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +2 -1
- package/dist/core.d.ts +2 -2
- package/dist/functions.js +2 -1
- package/dist/functions.js.map +1 -1
- package/dist/middleware.d.ts +33 -0
- package/dist/middleware.js +11 -0
- package/dist/middleware.js.map +1 -0
- package/dist/node.d.ts +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/{types-cfffcc1d.d.ts → types-a46fd2cb.d.ts} +15 -1
- package/package.json +7 -1
- package/dist/chunk-MNTHVGVU.js.map +0 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rootProjectMiddleware,
|
|
3
|
+
trailingSlashMiddleware
|
|
4
|
+
} from "./chunk-LWIDSJFY.js";
|
|
1
5
|
import {
|
|
2
6
|
copyGlob,
|
|
3
7
|
createViteServer,
|
|
@@ -637,59 +641,15 @@ function formatParams(params) {
|
|
|
637
641
|
}
|
|
638
642
|
|
|
639
643
|
// src/cli/commands/dev.ts
|
|
640
|
-
import
|
|
644
|
+
import path5 from "node:path";
|
|
641
645
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
642
646
|
import { default as express } from "express";
|
|
643
647
|
import { dim as dim2 } from "kleur/colors";
|
|
644
648
|
import sirv from "sirv";
|
|
645
649
|
import glob3 from "tiny-glob";
|
|
646
650
|
|
|
647
|
-
// src/core/middleware.ts
|
|
648
|
-
import path4 from "node:path";
|
|
649
|
-
function rootProjectMiddleware(options) {
|
|
650
|
-
return (req, _, next) => {
|
|
651
|
-
req.rootConfig = options.rootConfig;
|
|
652
|
-
next();
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
function trailingSlashMiddleware(options) {
|
|
656
|
-
var _a;
|
|
657
|
-
const trailingSlash = (_a = options.rootConfig.server) == null ? void 0 : _a.trailingSlash;
|
|
658
|
-
return (req, res, next) => {
|
|
659
|
-
if (trailingSlash === true && !path4.extname(req.path) && !req.path.endsWith("/")) {
|
|
660
|
-
const redirectPath = `${req.path}/`;
|
|
661
|
-
redirectWithQuery(req, res, 301, redirectPath);
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
if (trailingSlash === false && !path4.extname(req.path) && req.path !== "/" && req.path.endsWith("/")) {
|
|
665
|
-
const redirectPath = removeTrailingSlashes(req.path);
|
|
666
|
-
redirectWithQuery(req, res, 301, redirectPath);
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
next();
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
function redirectWithQuery(req, res, redirectCode, redirectPath) {
|
|
673
|
-
const queryStr = getQueryStr(req);
|
|
674
|
-
const redirectUrl = queryStr ? `${redirectPath}?${queryStr}` : redirectPath;
|
|
675
|
-
res.redirect(redirectCode, redirectUrl);
|
|
676
|
-
}
|
|
677
|
-
function getQueryStr(req) {
|
|
678
|
-
const qIndex = req.originalUrl.indexOf("?");
|
|
679
|
-
if (qIndex === -1) {
|
|
680
|
-
return "";
|
|
681
|
-
}
|
|
682
|
-
return req.originalUrl.slice(qIndex + 1);
|
|
683
|
-
}
|
|
684
|
-
function removeTrailingSlashes(urlPath) {
|
|
685
|
-
while (urlPath.endsWith("/") && urlPath !== "/") {
|
|
686
|
-
urlPath = urlPath.slice(0, -1);
|
|
687
|
-
}
|
|
688
|
-
return urlPath;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
651
|
// src/render/asset-map/dev-asset-map.ts
|
|
692
|
-
import
|
|
652
|
+
import path4 from "node:path";
|
|
693
653
|
import { searchForWorkspaceRoot as searchForWorkspaceRoot2 } from "vite";
|
|
694
654
|
var DevServerAssetMap = class {
|
|
695
655
|
constructor(rootConfig, moduleGraph) {
|
|
@@ -697,7 +657,7 @@ var DevServerAssetMap = class {
|
|
|
697
657
|
this.moduleGraph = moduleGraph;
|
|
698
658
|
}
|
|
699
659
|
async get(src) {
|
|
700
|
-
const file =
|
|
660
|
+
const file = path4.resolve(this.rootConfig.rootDir, src);
|
|
701
661
|
const viteModules = this.moduleGraph.getModulesByFile(file);
|
|
702
662
|
if (viteModules && viteModules.size > 0) {
|
|
703
663
|
const [viteModule] = viteModules;
|
|
@@ -729,7 +689,7 @@ var DevServerAssetMap = class {
|
|
|
729
689
|
return null;
|
|
730
690
|
}
|
|
731
691
|
filePathToSrc(file) {
|
|
732
|
-
return
|
|
692
|
+
return path4.relative(this.rootConfig.rootDir, file);
|
|
733
693
|
}
|
|
734
694
|
};
|
|
735
695
|
var DevServerAsset = class {
|
|
@@ -766,7 +726,7 @@ var DevServerAsset = class {
|
|
|
766
726
|
return;
|
|
767
727
|
}
|
|
768
728
|
visited.add(asset.moduleId);
|
|
769
|
-
const parts =
|
|
729
|
+
const parts = path4.parse(asset.assetUrl);
|
|
770
730
|
if ([".js", ".jsx", ".ts", ".tsx"].includes(parts.ext) && asset.moduleId.includes("/elements/")) {
|
|
771
731
|
urls.add(asset.assetUrl);
|
|
772
732
|
}
|
|
@@ -793,7 +753,7 @@ var DevServerAsset = class {
|
|
|
793
753
|
}
|
|
794
754
|
visited.add(asset.assetUrl);
|
|
795
755
|
if (asset.src.endsWith(".scss")) {
|
|
796
|
-
const parts =
|
|
756
|
+
const parts = path4.parse(asset.src);
|
|
797
757
|
if (!parts.name.startsWith("_")) {
|
|
798
758
|
urls.add(asset.assetUrl);
|
|
799
759
|
}
|
|
@@ -849,10 +809,10 @@ async function findOpenPort(min, max) {
|
|
|
849
809
|
}
|
|
850
810
|
|
|
851
811
|
// src/cli/commands/dev.ts
|
|
852
|
-
var __dirname2 =
|
|
812
|
+
var __dirname2 = path5.dirname(fileURLToPath2(import.meta.url));
|
|
853
813
|
async function dev(rootProjectDir, options) {
|
|
854
814
|
process.env.NODE_ENV = "development";
|
|
855
|
-
const rootDir =
|
|
815
|
+
const rootDir = path5.resolve(rootProjectDir || process.cwd());
|
|
856
816
|
const defaultPort = parseInt(process.env.PORT || "4007");
|
|
857
817
|
const host = (options == null ? void 0 : options.host) || "localhost";
|
|
858
818
|
const port = await findOpenPort(defaultPort, defaultPort + 10);
|
|
@@ -865,7 +825,7 @@ async function dev(rootProjectDir, options) {
|
|
|
865
825
|
server.listen(port, host);
|
|
866
826
|
}
|
|
867
827
|
async function createDevServer(options) {
|
|
868
|
-
const rootDir =
|
|
828
|
+
const rootDir = path5.resolve((options == null ? void 0 : options.rootDir) || process.cwd());
|
|
869
829
|
const rootConfig = await loadRootConfig(rootDir, { command: "dev" });
|
|
870
830
|
const port = options == null ? void 0 : options.port;
|
|
871
831
|
const server = express();
|
|
@@ -881,7 +841,7 @@ async function createDevServer(options) {
|
|
|
881
841
|
for (const middleware of userMiddlewares) {
|
|
882
842
|
server.use(middleware);
|
|
883
843
|
}
|
|
884
|
-
const publicDir =
|
|
844
|
+
const publicDir = path5.join(rootDir, "public");
|
|
885
845
|
if (await dirExists(publicDir)) {
|
|
886
846
|
server.use(sirv(publicDir, { dev: false }));
|
|
887
847
|
}
|
|
@@ -903,10 +863,10 @@ async function viteServerMiddleware(options) {
|
|
|
903
863
|
return sourceFile.relPath;
|
|
904
864
|
});
|
|
905
865
|
const bundleScripts = [];
|
|
906
|
-
if (await isDirectory(
|
|
866
|
+
if (await isDirectory(path5.join(rootDir, "bundles"))) {
|
|
907
867
|
const bundleFiles = await glob3("bundles/*", { cwd: rootDir });
|
|
908
868
|
bundleFiles.forEach((file) => {
|
|
909
|
-
const parts =
|
|
869
|
+
const parts = path5.parse(file);
|
|
910
870
|
if (isJsFile(parts.base)) {
|
|
911
871
|
bundleScripts.push(file);
|
|
912
872
|
}
|
|
@@ -918,7 +878,7 @@ async function viteServerMiddleware(options) {
|
|
|
918
878
|
optimizeDeps
|
|
919
879
|
});
|
|
920
880
|
function isInElementsDir(changedFilePath) {
|
|
921
|
-
const filePath =
|
|
881
|
+
const filePath = path5.resolve(changedFilePath);
|
|
922
882
|
const elementsDirs = getElementsDirs(rootConfig);
|
|
923
883
|
return elementsDirs.some((dirPath) => filePath.startsWith(dirPath));
|
|
924
884
|
}
|
|
@@ -937,7 +897,7 @@ async function viteServerMiddleware(options) {
|
|
|
937
897
|
return async (req, res, next) => {
|
|
938
898
|
try {
|
|
939
899
|
req.viteServer = viteServer;
|
|
940
|
-
const renderModulePath =
|
|
900
|
+
const renderModulePath = path5.resolve(__dirname2, "./render.js");
|
|
941
901
|
const render = await viteServer.ssrLoadModule(
|
|
942
902
|
renderModulePath
|
|
943
903
|
);
|
|
@@ -969,7 +929,7 @@ function rootDevServer404Middleware() {
|
|
|
969
929
|
console.error(`\u2753 404 ${req.originalUrl}`);
|
|
970
930
|
if (req.renderer) {
|
|
971
931
|
const url = req.path;
|
|
972
|
-
const ext =
|
|
932
|
+
const ext = path5.extname(url);
|
|
973
933
|
if (!ext) {
|
|
974
934
|
const renderer = req.renderer;
|
|
975
935
|
const data = await renderer.renderDevServer404(req);
|
|
@@ -987,7 +947,7 @@ function rootDevServer500Middleware() {
|
|
|
987
947
|
console.error(String(err.stack || err));
|
|
988
948
|
if (req.renderer) {
|
|
989
949
|
const url = req.path;
|
|
990
|
-
const ext =
|
|
950
|
+
const ext = path5.extname(url);
|
|
991
951
|
if (!ext) {
|
|
992
952
|
const renderer = req.renderer;
|
|
993
953
|
const data = await renderer.renderDevServer500(req, err);
|
|
@@ -1001,14 +961,14 @@ function rootDevServer500Middleware() {
|
|
|
1001
961
|
}
|
|
1002
962
|
|
|
1003
963
|
// src/cli/commands/preview.ts
|
|
1004
|
-
import
|
|
964
|
+
import path6 from "node:path";
|
|
1005
965
|
import compression from "compression";
|
|
1006
966
|
import { default as express2 } from "express";
|
|
1007
967
|
import { dim as dim3 } from "kleur/colors";
|
|
1008
968
|
import sirv2 from "sirv";
|
|
1009
969
|
async function preview(rootProjectDir, options) {
|
|
1010
970
|
process.env.NODE_ENV = "development";
|
|
1011
|
-
const rootDir =
|
|
971
|
+
const rootDir = path6.resolve(rootProjectDir || process.cwd());
|
|
1012
972
|
const server = await createPreviewServer({ rootDir });
|
|
1013
973
|
const port = parseInt(process.env.PORT || "4007");
|
|
1014
974
|
const host = (options == null ? void 0 : options.host) || "localhost";
|
|
@@ -1022,7 +982,7 @@ async function preview(rootProjectDir, options) {
|
|
|
1022
982
|
async function createPreviewServer(options) {
|
|
1023
983
|
const rootDir = options.rootDir;
|
|
1024
984
|
const rootConfig = await loadRootConfig(rootDir, { command: "preview" });
|
|
1025
|
-
const distDir =
|
|
985
|
+
const distDir = path6.join(rootDir, "dist");
|
|
1026
986
|
const server = express2();
|
|
1027
987
|
server.disable("x-powered-by");
|
|
1028
988
|
server.use(compression());
|
|
@@ -1037,7 +997,7 @@ async function createPreviewServer(options) {
|
|
|
1037
997
|
userMiddlewares.forEach((middleware) => {
|
|
1038
998
|
server.use(middleware);
|
|
1039
999
|
});
|
|
1040
|
-
const publicDir =
|
|
1000
|
+
const publicDir = path6.join(distDir, "html");
|
|
1041
1001
|
server.use(sirv2(publicDir, { dev: false }));
|
|
1042
1002
|
server.use(trailingSlashMiddleware({ rootConfig }));
|
|
1043
1003
|
server.use(rootPreviewServerMiddleware());
|
|
@@ -1051,14 +1011,14 @@ async function createPreviewServer(options) {
|
|
|
1051
1011
|
}
|
|
1052
1012
|
async function rootPreviewRendererMiddleware(options) {
|
|
1053
1013
|
const { distDir, rootConfig } = options;
|
|
1054
|
-
const render = await import(
|
|
1055
|
-
const manifestPath =
|
|
1014
|
+
const render = await import(path6.join(distDir, "server/render.js"));
|
|
1015
|
+
const manifestPath = path6.join(distDir, "client/root-manifest.json");
|
|
1056
1016
|
if (!await fileExists(manifestPath)) {
|
|
1057
1017
|
throw new Error(
|
|
1058
1018
|
`could not find ${manifestPath}. run \`root build\` before \`root preview\`.`
|
|
1059
1019
|
);
|
|
1060
1020
|
}
|
|
1061
|
-
const elementGraphJsonPath =
|
|
1021
|
+
const elementGraphJsonPath = path6.join(
|
|
1062
1022
|
distDir,
|
|
1063
1023
|
"client/root-element-graph.json"
|
|
1064
1024
|
);
|
|
@@ -1101,7 +1061,7 @@ function rootPreviewServer404Middleware() {
|
|
|
1101
1061
|
console.error(`\u2753 404 ${req.originalUrl}`);
|
|
1102
1062
|
if (req.renderer) {
|
|
1103
1063
|
const url = req.path;
|
|
1104
|
-
const ext =
|
|
1064
|
+
const ext = path6.extname(url);
|
|
1105
1065
|
if (!ext) {
|
|
1106
1066
|
const renderer = req.renderer;
|
|
1107
1067
|
const data = await renderer.render404({ currentPath: url });
|
|
@@ -1119,7 +1079,7 @@ function rootPreviewServer500Middleware() {
|
|
|
1119
1079
|
console.error(String(err.stack || err));
|
|
1120
1080
|
if (req.renderer) {
|
|
1121
1081
|
const url = req.path;
|
|
1122
|
-
const ext =
|
|
1082
|
+
const ext = path6.extname(url);
|
|
1123
1083
|
if (!ext) {
|
|
1124
1084
|
const renderer = req.renderer;
|
|
1125
1085
|
const data = await renderer.renderDevServer500(req, err);
|
|
@@ -1133,14 +1093,14 @@ function rootPreviewServer500Middleware() {
|
|
|
1133
1093
|
}
|
|
1134
1094
|
|
|
1135
1095
|
// src/cli/commands/start.ts
|
|
1136
|
-
import
|
|
1096
|
+
import path7 from "node:path";
|
|
1137
1097
|
import compression2 from "compression";
|
|
1138
1098
|
import { default as express3 } from "express";
|
|
1139
1099
|
import { dim as dim4 } from "kleur/colors";
|
|
1140
1100
|
import sirv3 from "sirv";
|
|
1141
1101
|
async function start(rootProjectDir, options) {
|
|
1142
1102
|
process.env.NODE_ENV = "production";
|
|
1143
|
-
const rootDir =
|
|
1103
|
+
const rootDir = path7.resolve(rootProjectDir || process.cwd());
|
|
1144
1104
|
const server = await createProdServer({ rootDir });
|
|
1145
1105
|
const port = parseInt(process.env.PORT || "4007");
|
|
1146
1106
|
const host = (options == null ? void 0 : options.host) || "localhost";
|
|
@@ -1154,7 +1114,7 @@ async function start(rootProjectDir, options) {
|
|
|
1154
1114
|
async function createProdServer(options) {
|
|
1155
1115
|
const rootDir = options.rootDir;
|
|
1156
1116
|
const rootConfig = await loadRootConfig(rootDir, { command: "start" });
|
|
1157
|
-
const distDir =
|
|
1117
|
+
const distDir = path7.join(rootDir, "dist");
|
|
1158
1118
|
const server = express3();
|
|
1159
1119
|
server.disable("x-powered-by");
|
|
1160
1120
|
server.use(compression2());
|
|
@@ -1169,7 +1129,7 @@ async function createProdServer(options) {
|
|
|
1169
1129
|
userMiddlewares.forEach((middleware) => {
|
|
1170
1130
|
server.use(middleware);
|
|
1171
1131
|
});
|
|
1172
|
-
const publicDir =
|
|
1132
|
+
const publicDir = path7.join(distDir, "html");
|
|
1173
1133
|
server.use(sirv3(publicDir, { dev: false }));
|
|
1174
1134
|
server.use(trailingSlashMiddleware({ rootConfig }));
|
|
1175
1135
|
server.use(rootProdServerMiddleware());
|
|
@@ -1183,14 +1143,14 @@ async function createProdServer(options) {
|
|
|
1183
1143
|
}
|
|
1184
1144
|
async function rootProdRendererMiddleware(options) {
|
|
1185
1145
|
const { distDir, rootConfig } = options;
|
|
1186
|
-
const render = await import(
|
|
1187
|
-
const manifestPath =
|
|
1146
|
+
const render = await import(path7.join(distDir, "server/render.js"));
|
|
1147
|
+
const manifestPath = path7.join(distDir, "client/root-manifest.json");
|
|
1188
1148
|
if (!await fileExists(manifestPath)) {
|
|
1189
1149
|
throw new Error(
|
|
1190
1150
|
`could not find ${manifestPath}. run \`root build\` before \`root start\`.`
|
|
1191
1151
|
);
|
|
1192
1152
|
}
|
|
1193
|
-
const elementGraphJsonPath =
|
|
1153
|
+
const elementGraphJsonPath = path7.join(
|
|
1194
1154
|
distDir,
|
|
1195
1155
|
"client/root-element-graph.json"
|
|
1196
1156
|
);
|
|
@@ -1233,7 +1193,7 @@ function rootProdServer404Middleware() {
|
|
|
1233
1193
|
console.error(`\u2753 404 ${req.originalUrl}`);
|
|
1234
1194
|
if (req.renderer) {
|
|
1235
1195
|
const url = req.path;
|
|
1236
|
-
const ext =
|
|
1196
|
+
const ext = path7.extname(url);
|
|
1237
1197
|
if (!ext) {
|
|
1238
1198
|
const renderer = req.renderer;
|
|
1239
1199
|
const data = await renderer.render404({ currentPath: url });
|
|
@@ -1251,7 +1211,7 @@ function rootProdServer500Middleware() {
|
|
|
1251
1211
|
console.error(String(err.stack || err));
|
|
1252
1212
|
if (req.renderer) {
|
|
1253
1213
|
const url = req.path;
|
|
1254
|
-
const ext =
|
|
1214
|
+
const ext = path7.extname(url);
|
|
1255
1215
|
if (!ext) {
|
|
1256
1216
|
const renderer = req.renderer;
|
|
1257
1217
|
const data = await renderer.renderError(err);
|
|
@@ -1273,4 +1233,4 @@ export {
|
|
|
1273
1233
|
start,
|
|
1274
1234
|
createProdServer
|
|
1275
1235
|
};
|
|
1276
|
-
//# sourceMappingURL=chunk-
|
|
1236
|
+
//# sourceMappingURL=chunk-JIXJPSAN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/build.ts","../src/node/element-graph.ts","../src/render/asset-map/build-asset-map.ts","../src/utils/batch.ts","../src/cli/commands/dev.ts","../src/render/asset-map/dev-asset-map.ts","../src/utils/ports.ts","../src/cli/commands/preview.ts","../src/cli/commands/start.ts"],"sourcesContent":["/* eslint-disable no-control-regex */\nimport path from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nimport fsExtra from 'fs-extra';\nimport {dim, cyan} from 'kleur/colors';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, ManifestChunk, UserConfig} from 'vite';\n\nimport {getVitePlugins} from '../../core/plugin.js';\nimport {Route} from '../../core/types.js';\nimport {getElements} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {htmlPretty} from '../../render/html-pretty.js';\nimport {batchAsyncCalls} from '../../utils/batch.js';\nimport {\n copyGlob,\n fileExists,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../utils/fsutils.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\ninterface BuildOptions {\n ssrOnly?: boolean;\n mode?: string;\n concurrency?: number;\n}\n\nexport async function build(rootProjectDir?: string, options?: BuildOptions) {\n const mode = options?.mode || 'production';\n process.env.NODE_ENV = mode;\n\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir, {command: 'build'});\n const distDir = path.join(rootDir, 'dist');\n const ssrOnly = options?.ssrOnly || false;\n\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} output: ${distDir}/html`);\n console.log(`${dim('┃')} mode: ${mode}`);\n console.log();\n\n await rmDir(distDir);\n await makeDir(distDir);\n\n const routeFiles: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob('routes/**/*', {cwd: rootDir});\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n routeFiles.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const elementGraph = await getElements(rootConfig);\n const elements = Object.values(elementGraph.sourceFiles).map((sourceFile) => {\n return sourceFile.filePath;\n });\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const rootPlugins = rootConfig.plugins || [];\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootPlugins),\n ];\n\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n mode: mode,\n esbuild: {\n ...viteConfig.esbuild,\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: vitePlugins,\n };\n\n // Bundle the render.js file with vite along with any plugins `ssrInput()`\n // config values. These inputs are bundled through vite and support things\n // like `input.meta.glob()`.\n const ssrInput = {\n render: path.resolve(__dirname, './render.js'),\n };\n rootPlugins.forEach((plugin) => {\n if (plugin.ssrInput) {\n Object.assign(ssrInput, plugin.ssrInput());\n }\n });\n const noExternalConfig = viteConfig.ssr?.noExternal;\n const noExternal: Array<string | RegExp> = [];\n if (noExternalConfig) {\n if (Array.isArray(noExternalConfig)) {\n noExternal.push(...noExternalConfig);\n } else {\n noExternal.push(noExternalConfig as string | RegExp);\n }\n }\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: ssrInput,\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n sanitizeFileName: sanitizeFileName,\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n ssr: {\n ...viteConfig.ssr,\n target: 'node',\n noExternal: ['@blinkk/root', ...noExternal],\n },\n });\n\n // Pre-render CSS deps from /routes/.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: [...routeFiles],\n output: {\n format: 'esm',\n entryFileNames: 'assets/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n chunkFileNames: 'chunks/[hash].min.js',\n sanitizeFileName: sanitizeFileName,\n ...viteConfig?.build?.rollupOptions?.output,\n },\n },\n outDir: path.join(distDir, 'routes'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n });\n\n // Pre-render /elements/ and /bundles/.\n const clientInput = [...elements, ...bundleScripts];\n if (clientInput.length > 0) {\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: [...elements, ...bundleScripts],\n output: {\n format: 'esm',\n entryFileNames: 'assets/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n chunkFileNames: 'chunks/[hash].min.js',\n sanitizeFileName: sanitizeFileName,\n ...viteConfig?.build?.rollupOptions?.output,\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n });\n } else {\n await writeFile(path.join(distDir, 'client/manifest.json'), '{}');\n }\n\n // Copy CSS files from dist/routes/**/*.css to dist/client/ and flatten the\n // routes manifest to ignore imported modules. Then add the route assets to\n // the client manifest.\n await copyGlob(\n '**/*.css',\n path.join(distDir, 'routes'),\n path.join(distDir, 'client')\n );\n const routesManifest = await loadJson<Manifest>(\n path.join(distDir, 'routes/manifest.json')\n );\n const clientManifest = await loadJson<Manifest>(\n path.join(distDir, 'client/manifest.json')\n );\n function collectRouteCss(\n asset: ManifestChunk,\n cssDeps: Set<string>,\n visited: Set<string>\n ) {\n if (!asset || !asset.file || visited.has(asset.file)) {\n return;\n }\n visited.add(asset.file);\n if (asset.css) {\n asset.css.forEach((dep) => cssDeps.add(dep));\n }\n if (asset.imports) {\n asset.imports.forEach((manifestKey) => {\n collectRouteCss(routesManifest[manifestKey], cssDeps, visited);\n });\n }\n }\n Object.keys(routesManifest).forEach((manifestKey) => {\n const asset = routesManifest[manifestKey];\n if (asset.isEntry) {\n const visited = new Set<string>();\n const cssDeps = new Set<string>();\n collectRouteCss(asset, cssDeps, visited);\n asset.css = Array.from(cssDeps);\n asset.imports = [];\n clientManifest[manifestKey] = asset;\n } else if (asset.file.endsWith('.css')) {\n clientManifest[manifestKey] = asset;\n }\n });\n\n // Use the output of the client build to generate an asset map, which is used\n // by the renderer for automatically injecting dependencies for a page.\n const assetMap = BuildAssetMap.fromViteManifest(\n rootConfig,\n clientManifest,\n elementGraph\n );\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n const rootManifest = assetMap.toJson();\n await writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(rootManifest, null, 2)\n );\n\n // Save the element graph to `dist/client` for use by the prod SSR server.\n const elementGraphJson = elementGraph.toJson();\n await writeFile(\n path.join(distDir, 'client/root-element-graph.json'),\n JSON.stringify(elementGraphJson, 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, {dereference: true});\n } else {\n await makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html` using the\n // root manifest. Ignore route files.\n console.log('\\njs/css output:');\n await Promise.all(\n Object.keys(rootManifest).map(async (src) => {\n // Don't expose route files in the final output. If any client-side code\n // relies on route dependencies, it should probably be broken out into a\n // shared component instead.\n if (isRouteFile(src)) {\n return;\n }\n const assetData = rootManifest[src];\n // Ignore files with no assetUrl, which can sometimes occur if a source\n // file is empty.\n if (!assetData.assetUrl) {\n return;\n }\n const assetRelPath = assetData.assetUrl.slice(1);\n const assetFrom = path.join(distDir, 'client', assetRelPath);\n const assetTo = path.join(buildDir, assetRelPath);\n // Ignore assets that don't exist. This is because build artifacts from\n // the routes/ folder are not copied to dist/client (only css deps are).\n if (!(await fileExists(assetFrom))) {\n console.log(`${assetFrom} does not exist`);\n return;\n }\n await fsExtra.copy(assetFrom, assetTo);\n printFileOutput(fileSize(assetTo), 'dist/html/', assetRelPath);\n })\n );\n\n // Pre-render HTML pages (SSG).\n if (!ssrOnly) {\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n const sitemap = await renderer.getSitemap();\n\n console.log('\\nhtml output:');\n const batchSize = Number(options?.concurrency || 10);\n await batchAsyncCalls(Object.keys(sitemap), batchSize, async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n try {\n const data = await renderer.renderRoute(route, {\n routeParams: params,\n });\n if (data.notFound) {\n return;\n }\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outFilePath = path.join(urlPath.slice(1), 'index.html');\n if (outFilePath.endsWith('404/index.html')) {\n outFilePath = outFilePath.replace('404/index.html', '404.html');\n }\n const outPath = path.join(buildDir, outFilePath);\n\n let html = data.html || '';\n if (rootConfig.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\n }\n await writeFile(outPath, html);\n\n printFileOutput(fileSize(outPath), 'dist/html/', outFilePath);\n } catch (e) {\n logBuildError({route, params, urlPath}, e);\n throw new Error(\n `BuildError: ${urlPath} (${route.src}) failed to build.`\n );\n }\n });\n }\n}\n\nfunction isRouteFile(filepath: string) {\n return filepath.startsWith('routes') && isJsFile(filepath);\n}\n\nfunction fileSize(filepath: string) {\n const stats = fsExtra.statSync(filepath);\n const bytes = stats.size;\n\n const k = 1024;\n if (bytes < k) {\n return (bytes / k).toFixed(2) + ' kB';\n }\n const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + units[i];\n}\n\nfunction printFileOutput(\n fileSize: string,\n outputDir: string,\n outputFile: string\n) {\n const indent = ' '.repeat(2);\n const paddedSize = fileSize.padStart(9, ' ');\n console.log(\n `${indent}${dim(paddedSize)} ${dim(outputDir)}${cyan(outputFile)}`\n );\n}\n\nfunction sanitizeFileName(name: string): string {\n return (\n name\n // Remove placeholder vars from paths like routes/[...var].tsx.\n .replaceAll('...', '')\n .replaceAll('_', '')\n .replaceAll('[', '')\n .replaceAll(']', '')\n // Remove non-ascii chars and null bytes.\n .replace(/[^\\x00-\\x7F]/g, '')\n .replace(/\\x00/g, '')\n .toLowerCase()\n );\n}\n\ninterface BuildContext {\n route: Route;\n params: Record<string, string>;\n urlPath: string;\n}\n\nfunction logBuildError(ctx: BuildContext, e: Error) {\n const {route, params, urlPath} = ctx;\n const errorString = String(e.stack || e);\n console.error();\n if (Object.keys(params).length > 0) {\n console.error(\n `An error occurred building ${urlPath} (${route.src}) with params:\n${formatParams(params)}\n\nThe error was:\n ${errorString}\n `.trim()\n );\n } else {\n console.error(\n `An error occurred building ${urlPath} (${route.src})\n\nThe error was:\n ${errorString}`\n );\n }\n}\n\nfunction formatParams(params: Record<string, string>) {\n return Object.entries(params)\n .map(([key, value]) => {\n return ` ${key}: ${value}`;\n })\n .join('\\n');\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport glob from 'tiny-glob';\nimport {searchForWorkspaceRoot} from 'vite';\n\nimport {RootConfig} from '../core/config';\nimport {isValidTagName, parseTagNames} from '../utils/elements';\nimport {directoryContains, isDirectory, isJsFile} from '../utils/fsutils';\n\ninterface ElementSourceFile {\n /** Full file path. */\n filePath: string;\n /** Path relative to the root project directory. */\n relPath: string;\n}\n\n/**\n * Dependency graph for element files to capture which other elements are used\n * by any particular element.\n */\nexport class ElementGraph {\n /**\n * Element tagName => sourceFile.\n */\n readonly sourceFiles: {[tagName: string]: ElementSourceFile} = {};\n\n /**\n * Element tagName => set of element tagName dependencies.\n */\n private deps: Record<string, string[]> = {};\n\n constructor(sourceFiles: {[tagName: string]: ElementSourceFile}) {\n this.sourceFiles = sourceFiles;\n }\n\n toJson() {\n for (const tagName in this.sourceFiles) {\n this.deps[tagName] ??= this.parseDepsFromSource(tagName);\n }\n return {\n sourceFiles: this.sourceFiles,\n deps: this.deps,\n };\n }\n\n static fromJson(data: {deps: any; sourceFiles: any}) {\n const graph = new ElementGraph(data.sourceFiles);\n graph.deps = data.deps;\n return graph;\n }\n\n getDeps(tagName: string, visited?: Set<string>): string[] {\n visited ??= new Set();\n if (visited.has(tagName)) {\n return [];\n }\n\n visited.add(tagName);\n this.deps[tagName] ??= this.parseDepsFromSource(tagName);\n\n const deps = new Set(this.deps[tagName]);\n for (const depTagName of this.deps[tagName]) {\n for (const childDep of this.getDeps(depTagName, visited)) {\n deps.add(childDep);\n }\n }\n return Array.from(deps);\n }\n\n /**\n * Parses an element's source file for usage of other custom elements.\n */\n private parseDepsFromSource(tagName: string): string[] {\n const srcFile = this.sourceFiles[tagName];\n if (!srcFile) {\n throw new Error(`could not find file path for tagName <${tagName}>`);\n }\n const src = fs.readFileSync(srcFile.filePath, 'utf-8');\n const tagNames = parseTagNames(src);\n const deps = new Set<string>();\n for (const depTagName of tagNames) {\n if (depTagName !== tagName && depTagName in this.sourceFiles) {\n deps.add(depTagName);\n }\n }\n return Array.from(deps);\n }\n}\n\n/**\n * Returns a map of all the element file definitions in the project.\n */\nexport async function getElements(\n rootConfig: RootConfig\n): Promise<ElementGraph> {\n const rootDir = rootConfig.rootDir;\n\n const elementsDirs = getElementsDirs(rootConfig);\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n const elementFilePaths: {[tagName: string]: ElementSourceFile} = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base) && isValidTagName(parts.name)) {\n const tagName = parts.name;\n const filePath = path.join(dirPath, file);\n const relPath = path.relative(rootDir, filePath);\n if (!excludeElement(relPath)) {\n elementFilePaths[tagName] = {filePath, relPath};\n }\n }\n });\n }\n }\n\n const graph = new ElementGraph(elementFilePaths);\n return graph;\n}\n\n/**\n * Get all element dirs.\n */\nexport function getElementsDirs(rootConfig: RootConfig) {\n const rootDir = rootConfig.rootDir;\n const workspaceRoot = searchForWorkspaceRoot(rootDir);\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!directoryContains(rootDir, elementsDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be within the project's workspace (${workspaceRoot})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n\n return elementsDirs;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport {Manifest} from 'vite';\n\nimport {RootConfig} from '../../core/config';\nimport {ElementGraph} from '../../node/element-graph';\nimport {isJsFile} from '../../utils/fsutils';\n\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private srcToAsset: Map<string, BuildAsset>;\n\n constructor(rootConfig: RootConfig) {\n this.rootConfig = rootConfig;\n this.srcToAsset = new Map();\n }\n\n async get(src: string): Promise<Asset | null> {\n const asset = this.srcToAsset.get(src);\n if (asset) {\n return asset;\n }\n // Try resolving the realpath of the asset, following symlinks.\n const realSrc = realPathRelativeTo(this.rootConfig.rootDir, src);\n if (realSrc !== src) {\n const asset = this.srcToAsset.get(realSrc);\n if (asset) {\n return asset;\n }\n }\n console.log(`could not find build asset: ${src}`);\n return null;\n }\n\n private add(asset: BuildAsset) {\n this.srcToAsset.set(asset.src, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const src of this.srcToAsset.keys()) {\n result[src] = this.srcToAsset.get(src)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n rootConfig: RootConfig,\n clientManifest: Manifest,\n elementsGraph: ElementGraph\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n\n const elementFiles = new Set();\n Object.values(elementsGraph.sourceFiles).forEach((elementSource) => {\n elementFiles.add(elementSource.relPath);\n // Vite will resolve symlinks, so we need to follow the src and add the\n // realpath to the element files.\n const realSrc = realPathRelativeTo(\n rootConfig.rootDir,\n elementSource.relPath\n );\n if (realSrc !== elementSource.filePath) {\n elementFiles.add(realSrc);\n }\n });\n\n Object.keys(clientManifest).forEach((manifestKey) => {\n const src = manifestKey;\n const manifestChunk = clientManifest[manifestKey];\n const isElement = elementFiles.has(src);\n // NOTES(stevenle): routes/ files are included in the manifest so for\n // their CSS deps, but do not have an asset URL.\n const assetUrl =\n src.startsWith('routes/') && isJsFile(src)\n ? ''\n : `/${manifestChunk.file}`;\n const assetData = {\n src: src,\n assetUrl: assetUrl,\n importedModules: manifestChunk.imports || [],\n importedCss: (manifestChunk.css || []).map((relPath) => `/${relPath}`),\n isElement: isElement,\n };\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n\n return assetMap;\n }\n\n static fromRootManifest(\n rootConfig: RootConfig,\n rootManifest: BuildAssetManifest\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n Object.keys(rootManifest).forEach((moduleId) => {\n const assetData = rootManifest[moduleId];\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n}\n\n/**\n * Returns the realpath of a src file, relative to the rootDir.\n */\nfunction realPathRelativeTo(rootDir: string, src: string) {\n const fullPath = path.resolve(rootDir, src);\n if (!fs.existsSync(fullPath)) {\n return src;\n }\n const realpath = fs.realpathSync(path.resolve(rootDir, src));\n return path.relative(rootDir, realpath);\n}\n\nexport class BuildAsset {\n src: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private importedModules: string[];\n private importedCss: string[];\n isElement: boolean;\n\n constructor(\n assetMap: BuildAssetMap,\n assetData: {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.src = assetData.src;\n this.assetUrl = assetData.assetUrl;\n this.importedModules = assetData.importedModules;\n this.importedCss = assetData.importedCss;\n this.isElement = assetData.isElement;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (src) => {\n const importedAsset = (await this.assetMap.get(src)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n src: this.src,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n isElement: this.isElement,\n };\n }\n}\n","export async function batchAsyncCalls<T, U>(\n data: T[],\n batchSize: number,\n asyncFunction: (item: T) => Promise<U>\n): Promise<U[]> {\n const result: U[] = [];\n const batches = Math.ceil(data.length / batchSize);\n for (let i = 0; i < batches; i++) {\n const batch = data.slice(i * batchSize, (i + 1) * batchSize);\n const batchResults = await Promise.all(batch.map(asyncFunction));\n result.push(...batchResults);\n }\n return result;\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\nimport glob from 'tiny-glob';\n\nimport {RootConfig} from '../../core/config.js';\nimport {configureServerPlugins} from '../../core/plugin.js';\nimport {Server, Request, Response, NextFunction} from '../../core/types.js';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../middleware/middleware.js';\nimport {getElements, getElementsDirs} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config.js';\nimport {createViteServer} from '../../node/vite.js';\nimport {DevServerAssetMap} from '../../render/asset-map/dev-asset-map.js';\nimport {dirExists, isDirectory, isJsFile} from '../../utils/fsutils.js';\nimport {findOpenPort} from '../../utils/ports.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface DevOptions {\n host?: string;\n}\n\nexport async function dev(rootProjectDir?: string, options?: DevOptions) {\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const defaultPort = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n const port = await findOpenPort(defaultPort, defaultPort + 10);\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: development`);\n console.log();\n const server = await createDevServer({rootDir, port});\n server.listen(port, host);\n}\n\nexport async function createDevServer(options?: {\n rootDir?: string;\n port?: number;\n}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir, {command: 'dev'});\n const port = options?.port;\n\n const server = express();\n server.disable('x-powered-by');\n\n // Inject req context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await viteServerMiddleware({rootConfig, port}));\n\n const plugins = rootConfig.plugins || [];\n await configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n for (const middleware of userMiddlewares) {\n server.use(middleware);\n }\n\n // Add static file middleware.\n const publicDir = path.join(rootDir, 'public');\n if (await dirExists(publicDir)) {\n server.use(sirv(publicDir, {dev: false}));\n }\n\n // Add the root.js dev server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootDevServerMiddleware());\n server.use(rootDevServer404Middleware());\n server.use(rootDevServer500Middleware());\n },\n plugins,\n {type: 'dev', rootConfig}\n );\n\n return server;\n}\n\n/**\n * Middleware that initializes a vite server and injects it into the request\n * context.\n */\nasync function viteServerMiddleware(options: {\n rootConfig: RootConfig;\n port?: number;\n}) {\n const rootConfig = options.rootConfig;\n const rootDir = rootConfig.rootDir;\n\n let elementGraph = await getElements(rootConfig);\n const elements = Object.values(elementGraph.sourceFiles).map((sourceFile) => {\n return sourceFile.relPath;\n });\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const optimizeDeps = [...elements, ...bundleScripts];\n const viteServer = await createViteServer(rootConfig, {\n port: options.port,\n optimizeDeps: optimizeDeps,\n });\n\n // Watch for file changes and re-generate the elements graph if any elements\n // are added or deleted.\n function isInElementsDir(changedFilePath: string) {\n const filePath = path.resolve(changedFilePath);\n const elementsDirs = getElementsDirs(rootConfig);\n return elementsDirs.some((dirPath) => filePath.startsWith(dirPath));\n }\n viteServer.watcher.on('add', async (filePath: string) => {\n if (isInElementsDir(filePath)) {\n // Re-generate the elements graph.\n elementGraph = await getElements(rootConfig);\n console.log(`element added: ${filePath}`);\n }\n });\n viteServer.watcher.on('unlink', async (filePath: string) => {\n if (isInElementsDir(filePath)) {\n // Re-generate the elements graph.\n elementGraph = await getElements(rootConfig);\n console.log(`element deleted: ${filePath}`);\n }\n });\n\n return async (req: Request, res: Response, next: NextFunction) => {\n try {\n // Add the viteServer to the req.\n req.viteServer = viteServer;\n // Dynamically import the render.js module using vite's SSR import loader.\n const renderModulePath = path.resolve(__dirname, './render.js');\n const render = (await viteServer.ssrLoadModule(\n renderModulePath\n )) as RenderModule;\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(\n rootConfig,\n viteServer.moduleGraph\n );\n // Add a renderer object to the req for plugins and other middleware to\n // use.\n req.renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n // Run the viteServer middlewares to handle vite-specific endpoints.\n viteServer.middlewares(req, res, next);\n } catch (e) {\n next(e);\n }\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n const viteServer = req.viteServer!;\n try {\n await renderer.handle(req, res, next);\n } catch (err) {\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(err);\n next(err);\n }\n };\n}\n\nfunction rootDevServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer404(req);\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootDevServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer500(req, err);\n const html = data.html || '';\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n next(err);\n };\n}\n","import path from 'node:path';\n\nimport {ModuleGraph, ModuleNode, searchForWorkspaceRoot} from 'vite';\n\nimport {RootConfig} from '../../core/config';\nimport {directoryContains} from '../../utils/fsutils';\n\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private moduleGraph: ModuleGraph;\n\n constructor(rootConfig: RootConfig, moduleGraph: ModuleGraph) {\n this.rootConfig = rootConfig;\n this.moduleGraph = moduleGraph;\n }\n\n async get(src: string): Promise<Asset | null> {\n const file = path.resolve(this.rootConfig.rootDir, src);\n\n const viteModules = this.moduleGraph.getModulesByFile(file);\n if (viteModules && viteModules.size > 0) {\n const [viteModule] = viteModules;\n return new DevServerAsset(src, {\n assetMap: this,\n viteModule: viteModule,\n });\n }\n\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n if (file.startsWith(this.rootConfig.rootDir)) {\n const assetUrl = file.slice(this.rootConfig.rootDir.length);\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n const workspaceRoot = searchForWorkspaceRoot(this.rootConfig.rootDir);\n if (await directoryContains(workspaceRoot, file)) {\n const assetUrl = `/@fs/${file}`;\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n\n console.log(`could not find asset in asset map: ${src}`);\n return null;\n }\n\n filePathToSrc(file: string) {\n return path.relative(this.rootConfig.rootDir, file);\n }\n}\n\nexport class DevServerAsset implements Asset {\n src: string;\n moduleId: string;\n assetUrl: string;\n private assetMap: DevServerAssetMap;\n private viteModule: ModuleNode;\n\n constructor(\n src: string,\n options: {\n assetMap: DevServerAssetMap;\n viteModule: ModuleNode;\n }\n ) {\n this.src = src;\n this.assetMap = options.assetMap;\n this.viteModule = options.viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.src.endsWith('.scss')) {\n const parts = path.parse(asset.src);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {createServer} from 'node:net';\n\n/**\n * Checks whether a port is open.\n */\nexport function isPortOpen(port: number): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const server = createServer();\n server.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n resolve(false);\n return;\n }\n reject(err);\n });\n server.on('close', () => {\n resolve(true);\n });\n server.listen(port, () => {\n server.close((err) => {\n if (err) {\n console.log(`error closing server: ${err}`);\n reject(err);\n }\n });\n });\n });\n}\n\n/**\n * Finds the first open port between two values.\n */\nexport async function findOpenPort(min: number, max: number): Promise<number> {\n let port = min;\n while (port <= max) {\n const isOpen = await isPortOpen(port);\n if (isOpen) {\n return port;\n }\n port += 1;\n }\n throw new Error(`no ports open between ${min} and ${max}`);\n}\n","import path from 'node:path';\n\nimport compression from 'compression';\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\n\nimport {RootConfig} from '../../core/config';\nimport {configureServerPlugins} from '../../core/plugin';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../middleware/middleware';\nimport {ElementGraph} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {fileExists, loadJson} from '../../utils/fsutils';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface PreviewOptions {\n host?: string;\n}\n\nexport async function preview(\n rootProjectDir?: string,\n options?: PreviewOptions\n) {\n // TODO(stevenle): figure out standard practice for NODE_ENV when using the\n // preview command.\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createPreviewServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: preview`);\n console.log();\n server.listen(port, host);\n}\n\nexport async function createPreviewServer(options: {\n rootDir: string;\n}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir, {command: 'preview'});\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await rootPreviewRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootPreviewServerMiddleware());\n\n // Add error handlers.\n server.use(rootPreviewServer404Middleware());\n server.use(rootPreviewServer500Middleware());\n },\n plugins,\n {type: 'preview', rootConfig}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootPreviewRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const elementGraphJsonPath = path.join(\n distDir,\n 'client/root-element-graph.json'\n );\n if (!(await fileExists(elementGraphJsonPath))) {\n throw new Error(\n `could not find ${elementGraphJsonPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootConfig, rootManifest);\n const elementGraphJson = await loadJson<any>(elementGraphJsonPath);\n const elementGraph = ElementGraph.fromJson(elementGraphJson);\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootPreviewServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n try {\n await renderer.handle(req, res, next);\n } catch (e) {\n try {\n console.error(`error rendering ${req.originalUrl}`);\n console.error(e.stack || e);\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\nfunction rootPreviewServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.render404({currentPath: url});\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootPreviewServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer500(req, err);\n const html = data.html || '';\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n next(err);\n };\n}\n","import path from 'node:path';\n\nimport compression from 'compression';\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\n\nimport {RootConfig} from '../../core/config';\nimport {configureServerPlugins} from '../../core/plugin';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../middleware/middleware';\nimport {ElementGraph} from '../../node/element-graph';\nimport {loadRootConfig} from '../../node/load-config';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {fileExists, loadJson} from '../../utils/fsutils';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface StartOptions {\n host?: string;\n}\n\nexport async function start(rootProjectDir?: string, options?: StartOptions) {\n process.env.NODE_ENV = 'production';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createProdServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: production`);\n console.log();\n server.listen(port, host);\n}\n\nexport async function createProdServer(options: {\n rootDir: string;\n}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir, {command: 'start'});\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await rootProdRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootProdServerMiddleware());\n\n // Add error handlers.\n server.use(rootProdServer404Middleware());\n server.use(rootProdServer500Middleware());\n },\n plugins,\n {type: 'prod', rootConfig}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootProdRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const elementGraphJsonPath = path.join(\n distDir,\n 'client/root-element-graph.json'\n );\n if (!(await fileExists(elementGraphJsonPath))) {\n throw new Error(\n `could not find ${elementGraphJsonPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootConfig, rootManifest);\n const elementGraphJson = await loadJson<any>(elementGraphJsonPath);\n const elementGraph = ElementGraph.fromJson(elementGraphJson);\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Prod server request handler.\n */\nfunction rootProdServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n try {\n await renderer.handle(req, res, next);\n } catch (e) {\n try {\n console.error(`error rendering ${req.originalUrl}`);\n console.error(e.stack || e);\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\nfunction rootProdServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.render404({currentPath: url});\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootProdServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderError(err);\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,MAAM,SAAS,YAAY,GAAG;AAC3C,cAAM,OAAO,KAAK,QAAQ;AAC1B,YAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAC3D;AAAA,MACF;AAAA,IACF;AACA,SAAK,GAAG;AAAA,EACV;AACF;","names":["path","glob","fs","path","asset","path","fs","path","glob","fileSize","path","fileURLToPath","dim","glob","path","searchForWorkspaceRoot","path","searchForWorkspaceRoot","__dirname","path","fileURLToPath","dim","glob","path","express","dim","sirv","path","dim","express","sirv","path","compression","express","dim","sirv","path","dim","express","compression","sirv"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// src/middleware/common.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function rootProjectMiddleware(options) {
|
|
4
|
+
return (req, _, next) => {
|
|
5
|
+
req.rootConfig = options.rootConfig;
|
|
6
|
+
next();
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function trailingSlashMiddleware(options) {
|
|
10
|
+
var _a;
|
|
11
|
+
const trailingSlash = (_a = options.rootConfig.server) == null ? void 0 : _a.trailingSlash;
|
|
12
|
+
return (req, res, next) => {
|
|
13
|
+
if (trailingSlash === true && !path.extname(req.path) && !req.path.endsWith("/")) {
|
|
14
|
+
const redirectPath = `${req.path}/`;
|
|
15
|
+
redirectWithQuery(req, res, 301, redirectPath);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (trailingSlash === false && !path.extname(req.path) && req.path !== "/" && req.path.endsWith("/")) {
|
|
19
|
+
const redirectPath = removeTrailingSlashes(req.path);
|
|
20
|
+
redirectWithQuery(req, res, 301, redirectPath);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
next();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function redirectWithQuery(req, res, redirectCode, redirectPath) {
|
|
27
|
+
const queryStr = getQueryStr(req);
|
|
28
|
+
const redirectUrl = queryStr ? `${redirectPath}?${queryStr}` : redirectPath;
|
|
29
|
+
res.redirect(redirectCode, redirectUrl);
|
|
30
|
+
}
|
|
31
|
+
function getQueryStr(req) {
|
|
32
|
+
const qIndex = req.originalUrl.indexOf("?");
|
|
33
|
+
if (qIndex === -1) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
return req.originalUrl.slice(qIndex + 1);
|
|
37
|
+
}
|
|
38
|
+
function removeTrailingSlashes(urlPath) {
|
|
39
|
+
while (urlPath.endsWith("/") && urlPath !== "/") {
|
|
40
|
+
urlPath = urlPath.slice(0, -1);
|
|
41
|
+
}
|
|
42
|
+
return urlPath;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/middleware/multipart.ts
|
|
46
|
+
import busboy from "busboy";
|
|
47
|
+
var DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
48
|
+
function multipartMiddleware(options) {
|
|
49
|
+
const maxFileSize = (options == null ? void 0 : options.maxFileSize) || DEFAULT_MAX_FILE_SIZE;
|
|
50
|
+
return (req, res, next) => {
|
|
51
|
+
const contentType = String(req.headers["content-type"] || "");
|
|
52
|
+
if (req.method === "POST" && contentType.startsWith("multipart/form-data")) {
|
|
53
|
+
const parser = busboy({ headers: req.headers });
|
|
54
|
+
const fields = {};
|
|
55
|
+
const files = {};
|
|
56
|
+
parser.on("field", (fieldname, val) => {
|
|
57
|
+
fields[fieldname] = val;
|
|
58
|
+
});
|
|
59
|
+
parser.on(
|
|
60
|
+
"file",
|
|
61
|
+
(fieldname, file, meta) => {
|
|
62
|
+
const { filename, encoding, mimetype } = meta;
|
|
63
|
+
const fileChunks = [];
|
|
64
|
+
let totalBytesRead = 0;
|
|
65
|
+
file.on("data", (chunk) => {
|
|
66
|
+
totalBytesRead += chunk.length;
|
|
67
|
+
if (totalBytesRead > maxFileSize) {
|
|
68
|
+
console.error(`File size exceeds the limit: ${fieldname}.`);
|
|
69
|
+
file.removeAllListeners("data");
|
|
70
|
+
file.resume();
|
|
71
|
+
} else {
|
|
72
|
+
fileChunks.push(chunk);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
file.on("end", () => {
|
|
76
|
+
if (totalBytesRead <= maxFileSize) {
|
|
77
|
+
const buffer = Buffer.concat(fileChunks);
|
|
78
|
+
files[fieldname] = {
|
|
79
|
+
fieldname,
|
|
80
|
+
buffer,
|
|
81
|
+
originalName: filename,
|
|
82
|
+
encoding,
|
|
83
|
+
mimetype
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
parser.on("finish", () => {
|
|
90
|
+
req.body = fields;
|
|
91
|
+
req.files = files;
|
|
92
|
+
next();
|
|
93
|
+
});
|
|
94
|
+
if (req.rawBody) {
|
|
95
|
+
parser.end(req.rawBody);
|
|
96
|
+
} else {
|
|
97
|
+
req.pipe(parser);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
next();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
rootProjectMiddleware,
|
|
107
|
+
trailingSlashMiddleware,
|
|
108
|
+
multipartMiddleware
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=chunk-LWIDSJFY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/common.ts","../src/middleware/multipart.ts"],"sourcesContent":["import path from 'node:path';\nimport {RootConfig} from '../core/config';\nimport {Request, Response, NextFunction} from '../core/types';\n\n/**\n * Middleware that injects the root.js project config into the request context.\n */\nexport function rootProjectMiddleware(options: {rootConfig: RootConfig}) {\n return (req: Request, _: Response, next: NextFunction) => {\n req.rootConfig = options.rootConfig;\n next();\n };\n}\n\n/**\n * Trailing slash middleware. Handles trailing slash redirects (preserving any\n * query params) using the `server.trailingSlash` config in root.config.ts.\n */\nexport function trailingSlashMiddleware(options: {rootConfig: RootConfig}) {\n const trailingSlash = options.rootConfig.server?.trailingSlash;\n\n return (req: Request, res: Response, next: NextFunction) => {\n // If `trailingSlash: false`, force a trailing slash in the URL.\n if (\n trailingSlash === true &&\n !path.extname(req.path) &&\n !req.path.endsWith('/')\n ) {\n const redirectPath = `${req.path}/`;\n redirectWithQuery(req, res, 301, redirectPath);\n return;\n }\n\n // If `trailingSlash: false`, remove any trailing slash from the URL.\n if (\n trailingSlash === false &&\n !path.extname(req.path) &&\n req.path !== '/' &&\n req.path.endsWith('/')\n ) {\n const redirectPath = removeTrailingSlashes(req.path);\n redirectWithQuery(req, res, 301, redirectPath);\n return;\n }\n\n next();\n };\n}\n\n/**\n * Issues an HTTP redirect, preserving any query params from the original req.\n */\nfunction redirectWithQuery(\n req: Request,\n res: Response,\n redirectCode: number,\n redirectPath: string\n) {\n const queryStr = getQueryStr(req);\n const redirectUrl = queryStr ? `${redirectPath}?${queryStr}` : redirectPath;\n res.redirect(redirectCode, redirectUrl);\n}\n\n/**\n * Returns the query string for a request, or empty string if no query.\n */\nfunction getQueryStr(req: Request): string {\n const qIndex = req.originalUrl.indexOf('?');\n if (qIndex === -1) {\n return '';\n }\n return req.originalUrl.slice(qIndex + 1);\n}\n\n/**\n * Removes trailing slashes from a URL path.\n * Note: A path with only slashes (e.g. `///`) returns `/`.\n */\nfunction removeTrailingSlashes(urlPath: string) {\n while (urlPath.endsWith('/') && urlPath !== '/') {\n urlPath = urlPath.slice(0, -1);\n }\n return urlPath;\n}\n","import busboy from 'busboy';\nimport {Request, Response, NextFunction, MultipartFile} from '../core/types';\n\nconst DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB\n\n/**\n * Middleware for parsing multipart file uploads that's compatible with the dev\n * server and Firebase Functions.\n *\n * Context:\n * https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase\n */\nexport function multipartMiddleware(options?: {maxFileSize?: number}) {\n const maxFileSize = options?.maxFileSize || DEFAULT_MAX_FILE_SIZE;\n\n return (req: Request, res: Response, next: NextFunction) => {\n const contentType = String(req.headers['content-type'] || '');\n if (\n req.method === 'POST' &&\n contentType.startsWith('multipart/form-data')\n ) {\n const parser = busboy({headers: req.headers});\n\n // Data storage for fields and files\n const fields: {[fieldname: string]: string} = {};\n const files: {[name: string]: MultipartFile} = {};\n\n // Handle field data.\n parser.on('field', (fieldname: string, val: any) => {\n fields[fieldname] = val;\n });\n\n // Handle file data. Files are saved to an in-memory buffer.\n parser.on(\n 'file',\n (\n fieldname: string,\n file: any,\n meta: {\n filename: string;\n encoding: string;\n mimetype: string;\n }\n ) => {\n const {filename, encoding, mimetype} = meta;\n const fileChunks: Uint8Array[] = [];\n let totalBytesRead = 0;\n\n file.on('data', (chunk: Uint8Array) => {\n totalBytesRead += chunk.length;\n\n if (totalBytesRead > maxFileSize) {\n // File size exceeds the limit, stop reading.\n console.error(`File size exceeds the limit: ${fieldname}.`);\n file.removeAllListeners('data');\n // Consume and discard remaining data.\n file.resume();\n } else {\n fileChunks.push(chunk);\n }\n });\n\n file.on('end', () => {\n if (totalBytesRead <= maxFileSize) {\n const buffer = Buffer.concat(fileChunks);\n\n files[fieldname] = {\n fieldname,\n buffer,\n originalName: filename,\n encoding,\n mimetype,\n };\n }\n });\n }\n );\n\n // Update `req.body` and `req.files`.\n parser.on('finish', () => {\n req.body = fields;\n req.files = files;\n next();\n });\n\n // Pipe the request to Busboy. On Firebase Functions, `rawBody` contains\n // the multipart request. Otherwise the express request can be piped to\n // the Busboy parser.\n if (req.rawBody) {\n parser.end(req.rawBody);\n } else {\n req.pipe(parser);\n }\n } else {\n next();\n }\n };\n}\n"],"mappings":";AAAA,OAAO,UAAU;AAOV,SAAS,sBAAsB,SAAmC;AACvE,SAAO,CAAC,KAAc,GAAa,SAAuB;AACxD,QAAI,aAAa,QAAQ;AACzB,SAAK;AAAA,EACP;AACF;AAMO,SAAS,wBAAwB,SAAmC;AAlB3E;AAmBE,QAAM,iBAAgB,aAAQ,WAAW,WAAnB,mBAA2B;AAEjD,SA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,SAAwC,CAAC;AAC/C,YAAM,QAAyC,CAAC;AAGhD,aAAO,GAAG,SAAS,CAAC,WAAmB,QAAa;AAClD,eAAO,aAAa;AAAA,MACtB,CAAC;AAGD,aAAO;AAAA,QACL;AAAA,QACA,CACE,WACA,MACA,SAKG;AACH,gBAAM,EAAC,UAAU,UAAU,SAAQ,IAAI;AACvC,gBAAM,aAA2B,CAAC;AAClC,cAAI,iBAAiB;AAErB,eAAK,GAAG,QAAQ,CAAC,UAAsB;AACrC,8BAAkB,MAAM;AAExB,gBAAI,iBAAiB,aAAa;AAEhC,sBAAQ,MAAM,gCAAgC,YAAY;AAC1D,mBAAK,mBAAmB,MAAM;AAE9B,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,KAAK,KAAK;AAAA,YACvB;AAAA,UACF,CAAC;AAED,eAAK,GAAG,OAAO,MAAM;AACnB,gBAAI,kBAAkB,aAAa;AACjC,oBAAM,SAAS,OAAO,OAAO,UAAU;AAEvC,oBAAM,aAAa;AAAA,gBACjB;AAAA,gBACA;AAAA,gBACA,cAAc;AAAA,gBACd;AAAA,gBACA;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAGA,aAAO,GAAG,UAAU,MAAM;AACxB,YAAI,OAAO;AACX,YAAI,QAAQ;AACZ,aAAK;AAAA,MACP,CAAC;AAKD,UAAI,IAAI,SAAS;AACf,eAAO,IAAI,IAAI,OAAO;AAAA,MACxB,OAAO;AACL,YAAI,KAAK,MAAM;AAAA,MACjB;AAAA,IACF,OAAO;AACL,WAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Route } from './types-
|
|
2
|
-
export { C as ConfigureServerHook, f as ConfigureServerOptions, j as GetStaticPaths, G as GetStaticProps, m as Handler, H as HandlerContext, p as HandlerRenderFn, o as HandlerRenderOptions, L as LocaleGroup, N as NextFunction, P as Plugin, k as Request, l as Response, b as RootConfig, c as RootI18nConfig, d as RootServerConfig, a as RootUserConfig, R as Route, n as RouteModule, i as RouteParams, S as Server, g as configureServerPlugins, e as defineConfig, h as getVitePlugins } from './types-
|
|
1
|
+
import { R as Route } from './types-a46fd2cb.js';
|
|
2
|
+
export { C as ConfigureServerHook, f as ConfigureServerOptions, j as GetStaticPaths, G as GetStaticProps, m as Handler, H as HandlerContext, p as HandlerRenderFn, o as HandlerRenderOptions, L as LocaleGroup, M as MultipartFile, N as NextFunction, P as Plugin, k as Request, l as Response, b as RootConfig, c as RootI18nConfig, d as RootServerConfig, a as RootUserConfig, R as Route, n as RouteModule, i as RouteParams, S as Server, g as configureServerPlugins, e as defineConfig, h as getVitePlugins } from './types-a46fd2cb.js';
|
|
3
3
|
import * as preact$1 from 'preact';
|
|
4
4
|
import { FunctionalComponent, ComponentChildren } from 'preact';
|
|
5
5
|
import 'express';
|
package/dist/functions.js
CHANGED
package/dist/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/functions/server.ts"],"sourcesContent":["import path from 'node:path';\nimport {HttpsOptions, onRequest} from 'firebase-functions/v2/https';\nimport {createPreviewServer, createProdServer} from '../cli/cli';\nimport {Server} from '../core/types';\n\nexport interface ProdServerOptions {\n rootDir?: string;\n mode?: 'preview' | 'production';\n httpsOptions?: HttpsOptions;\n}\n\n/**\n * Firebase Function that runs a Root.js server running in SSR mode.\n */\nexport function server(options?: ProdServerOptions) {\n let rootServer: Server;\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n return onRequest(options?.httpsOptions || {}, async (req, res) => {\n if (!rootServer) {\n if (options?.mode === 'preview') {\n rootServer = await createPreviewServer({rootDir});\n } else {\n rootServer = await createProdServer({rootDir});\n }\n }\n await rootServer(req, res);\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/functions/server.ts"],"sourcesContent":["import path from 'node:path';\nimport {HttpsOptions, onRequest} from 'firebase-functions/v2/https';\nimport {createPreviewServer, createProdServer} from '../cli/cli';\nimport {Server} from '../core/types';\n\nexport interface ProdServerOptions {\n rootDir?: string;\n mode?: 'preview' | 'production';\n httpsOptions?: HttpsOptions;\n}\n\n/**\n * Firebase Function that runs a Root.js server running in SSR mode.\n */\nexport function server(options?: ProdServerOptions) {\n let rootServer: Server;\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n return onRequest(options?.httpsOptions || {}, async (req, res) => {\n if (!rootServer) {\n if (options?.mode === 'preview') {\n rootServer = await createPreviewServer({rootDir});\n } else {\n rootServer = await createProdServer({rootDir});\n }\n }\n await rootServer(req, res);\n });\n}\n"],"mappings":";;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAsB,iBAAgB;AAa/B,SAAS,OAAO,SAA6B;AAClD,MAAI;AACJ,QAAM,UAAU,KAAK,SAAQ,mCAAS,YAAW,QAAQ,IAAI,CAAC;AAC9D,SAAO,WAAU,mCAAS,iBAAgB,CAAC,GAAG,OAAO,KAAK,QAAQ;AAChE,QAAI,CAAC,YAAY;AACf,WAAI,mCAAS,UAAS,WAAW;AAC/B,qBAAa,MAAM,oBAAoB,EAAC,QAAO,CAAC;AAAA,MAClD,OAAO;AACL,qBAAa,MAAM,iBAAiB,EAAC,QAAO,CAAC;AAAA,MAC/C;AAAA,IACF;AACA,UAAM,WAAW,KAAK,GAAG;AAAA,EAC3B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { b as RootConfig, k as Request, l as Response, N as NextFunction } from './types-a46fd2cb.js';
|
|
2
|
+
import 'express';
|
|
3
|
+
import 'preact';
|
|
4
|
+
import 'vite';
|
|
5
|
+
import 'html-minifier-terser';
|
|
6
|
+
import 'js-beautify';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Middleware that injects the root.js project config into the request context.
|
|
10
|
+
*/
|
|
11
|
+
declare function rootProjectMiddleware(options: {
|
|
12
|
+
rootConfig: RootConfig;
|
|
13
|
+
}): (req: Request, _: Response, next: NextFunction) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Trailing slash middleware. Handles trailing slash redirects (preserving any
|
|
16
|
+
* query params) using the `server.trailingSlash` config in root.config.ts.
|
|
17
|
+
*/
|
|
18
|
+
declare function trailingSlashMiddleware(options: {
|
|
19
|
+
rootConfig: RootConfig;
|
|
20
|
+
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Middleware for parsing multipart file uploads that's compatible with the dev
|
|
24
|
+
* server and Firebase Functions.
|
|
25
|
+
*
|
|
26
|
+
* Context:
|
|
27
|
+
* https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase
|
|
28
|
+
*/
|
|
29
|
+
declare function multipartMiddleware(options?: {
|
|
30
|
+
maxFileSize?: number;
|
|
31
|
+
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
32
|
+
|
|
33
|
+
export { multipartMiddleware, rootProjectMiddleware, trailingSlashMiddleware };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/node.d.ts
CHANGED
package/dist/render.d.ts
CHANGED
|
@@ -303,6 +303,14 @@ declare type GetStaticPaths<T = RouteParams> = () => Promise<{
|
|
|
303
303
|
params: T;
|
|
304
304
|
}>;
|
|
305
305
|
}>;
|
|
306
|
+
/** Multipart file type for the multipartMiddleware(). */
|
|
307
|
+
interface MultipartFile {
|
|
308
|
+
fieldname: string;
|
|
309
|
+
originalName: string;
|
|
310
|
+
encoding: string;
|
|
311
|
+
mimetype: string;
|
|
312
|
+
buffer: Buffer;
|
|
313
|
+
}
|
|
306
314
|
/** Root.js express app. */
|
|
307
315
|
declare type Server = Express;
|
|
308
316
|
/** Root.js express request. */
|
|
@@ -320,6 +328,12 @@ declare type Request = Request$1 & {
|
|
|
320
328
|
* function.
|
|
321
329
|
*/
|
|
322
330
|
handlerContext?: HandlerContext;
|
|
331
|
+
/** Firebase functions uses rawBody for its multipart data. */
|
|
332
|
+
rawBody?: any;
|
|
333
|
+
/** Map of field name to file. */
|
|
334
|
+
files?: {
|
|
335
|
+
[fieldname: string]: MultipartFile;
|
|
336
|
+
};
|
|
323
337
|
};
|
|
324
338
|
/** Root.js express response. */
|
|
325
339
|
declare type Response = Response$1;
|
|
@@ -410,4 +424,4 @@ interface HandlerRenderOptions {
|
|
|
410
424
|
}
|
|
411
425
|
declare type HandlerRenderFn = (props: any, options?: HandlerRenderOptions) => Promise<void>;
|
|
412
426
|
|
|
413
|
-
export { ConfigureServerHook as C, GetStaticProps as G, HandlerContext as H, LocaleGroup as L, NextFunction as N, Plugin as P, Route as R, Server as S, RootUserConfig as a, RootConfig as b, RootI18nConfig as c, RootServerConfig as d, defineConfig as e, ConfigureServerOptions as f, configureServerPlugins as g, getVitePlugins as h, RouteParams as i, GetStaticPaths as j, Request as k, Response as l, Handler as m, RouteModule as n, HandlerRenderOptions as o, HandlerRenderFn as p, Renderer as q };
|
|
427
|
+
export { ConfigureServerHook as C, GetStaticProps as G, HandlerContext as H, LocaleGroup as L, MultipartFile as M, NextFunction as N, Plugin as P, Route as R, Server as S, RootUserConfig as a, RootConfig as b, RootI18nConfig as c, RootServerConfig as d, defineConfig as e, ConfigureServerOptions as f, configureServerPlugins as g, getVitePlugins as h, RouteParams as i, GetStaticPaths as j, Request as k, Response as l, Handler as m, RouteModule as n, HandlerRenderOptions as o, HandlerRenderFn as p, Renderer as q };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blinkk/root",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.54",
|
|
4
4
|
"author": "s@blinkk.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"types": "./dist/functions.d.ts",
|
|
41
41
|
"import": "./dist/functions.js"
|
|
42
42
|
},
|
|
43
|
+
"./middleware": {
|
|
44
|
+
"types": "./dist/middleware.d.ts",
|
|
45
|
+
"import": "./dist/middleware.js"
|
|
46
|
+
},
|
|
43
47
|
"./node": {
|
|
44
48
|
"types": "./dist/node.d.ts",
|
|
45
49
|
"import": "./dist/node.js"
|
|
@@ -51,6 +55,7 @@
|
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
57
|
"bundle-require": "^4.0.1",
|
|
58
|
+
"busboy": "^1.6.0",
|
|
54
59
|
"commander": "^10.0.0",
|
|
55
60
|
"compression": "^1.7.4",
|
|
56
61
|
"esbuild": "0.17.12",
|
|
@@ -79,6 +84,7 @@
|
|
|
79
84
|
}
|
|
80
85
|
},
|
|
81
86
|
"devDependencies": {
|
|
87
|
+
"@types/busboy": "^1.5.0",
|
|
82
88
|
"@types/compression": "^1.7.2",
|
|
83
89
|
"@types/express": "^4.17.13",
|
|
84
90
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/commands/build.ts","../src/node/element-graph.ts","../src/render/asset-map/build-asset-map.ts","../src/utils/batch.ts","../src/cli/commands/dev.ts","../src/core/middleware.ts","../src/render/asset-map/dev-asset-map.ts","../src/utils/ports.ts","../src/cli/commands/preview.ts","../src/cli/commands/start.ts"],"sourcesContent":["/* eslint-disable no-control-regex */\nimport path from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nimport fsExtra from 'fs-extra';\nimport {dim, cyan} from 'kleur/colors';\nimport glob from 'tiny-glob';\nimport {build as viteBuild, Manifest, ManifestChunk, UserConfig} from 'vite';\n\nimport {getVitePlugins} from '../../core/plugin.js';\nimport {Route} from '../../core/types.js';\nimport {getElements} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config.js';\nimport {BuildAssetMap} from '../../render/asset-map/build-asset-map.js';\nimport {htmlMinify} from '../../render/html-minify.js';\nimport {htmlPretty} from '../../render/html-pretty.js';\nimport {batchAsyncCalls} from '../../utils/batch.js';\nimport {\n copyGlob,\n fileExists,\n isDirectory,\n isJsFile,\n loadJson,\n makeDir,\n rmDir,\n writeFile,\n} from '../../utils/fsutils.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\ninterface BuildOptions {\n ssrOnly?: boolean;\n mode?: string;\n concurrency?: number;\n}\n\nexport async function build(rootProjectDir?: string, options?: BuildOptions) {\n const mode = options?.mode || 'production';\n process.env.NODE_ENV = mode;\n\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir, {command: 'build'});\n const distDir = path.join(rootDir, 'dist');\n const ssrOnly = options?.ssrOnly || false;\n\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} output: ${distDir}/html`);\n console.log(`${dim('┃')} mode: ${mode}`);\n console.log();\n\n await rmDir(distDir);\n await makeDir(distDir);\n\n const routeFiles: string[] = [];\n if (await isDirectory(path.join(rootDir, 'routes'))) {\n const pageFiles = await glob('routes/**/*', {cwd: rootDir});\n pageFiles.forEach((file) => {\n const parts = path.parse(file);\n if (!parts.name.startsWith('_') && isJsFile(parts.base)) {\n routeFiles.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const elementGraph = await getElements(rootConfig);\n const elements = Object.values(elementGraph.sourceFiles).map((sourceFile) => {\n return sourceFile.filePath;\n });\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(path.resolve(rootDir, file));\n }\n });\n }\n\n const rootPlugins = rootConfig.plugins || [];\n const viteConfig = rootConfig.vite || {};\n const vitePlugins = [\n ...(viteConfig.plugins || []),\n ...getVitePlugins(rootPlugins),\n ];\n\n const baseConfig: UserConfig = {\n ...viteConfig,\n root: rootDir,\n mode: mode,\n esbuild: {\n ...viteConfig.esbuild,\n jsx: 'automatic',\n jsxImportSource: 'preact',\n treeShaking: true,\n },\n plugins: vitePlugins,\n };\n\n // Bundle the render.js file with vite along with any plugins `ssrInput()`\n // config values. These inputs are bundled through vite and support things\n // like `input.meta.glob()`.\n const ssrInput = {\n render: path.resolve(__dirname, './render.js'),\n };\n rootPlugins.forEach((plugin) => {\n if (plugin.ssrInput) {\n Object.assign(ssrInput, plugin.ssrInput());\n }\n });\n const noExternalConfig = viteConfig.ssr?.noExternal;\n const noExternal: Array<string | RegExp> = [];\n if (noExternalConfig) {\n if (Array.isArray(noExternalConfig)) {\n noExternal.push(...noExternalConfig);\n } else {\n noExternal.push(noExternalConfig as string | RegExp);\n }\n }\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: ssrInput,\n output: {\n format: 'esm',\n chunkFileNames: 'chunks/[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n sanitizeFileName: sanitizeFileName,\n },\n },\n outDir: path.join(distDir, 'server'),\n ssr: true,\n ssrManifest: false,\n cssCodeSplit: true,\n target: 'esnext',\n minify: false,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n ssr: {\n ...viteConfig.ssr,\n target: 'node',\n noExternal: ['@blinkk/root', ...noExternal],\n },\n });\n\n // Pre-render CSS deps from /routes/.\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: [...routeFiles],\n output: {\n format: 'esm',\n entryFileNames: 'assets/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n chunkFileNames: 'chunks/[hash].min.js',\n sanitizeFileName: sanitizeFileName,\n ...viteConfig?.build?.rollupOptions?.output,\n },\n },\n outDir: path.join(distDir, 'routes'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n });\n\n // Pre-render /elements/ and /bundles/.\n const clientInput = [...elements, ...bundleScripts];\n if (clientInput.length > 0) {\n await viteBuild({\n ...baseConfig,\n publicDir: false,\n build: {\n ...viteConfig?.build,\n rollupOptions: {\n ...viteConfig?.build?.rollupOptions,\n input: [...elements, ...bundleScripts],\n output: {\n format: 'esm',\n entryFileNames: 'assets/[name].[hash].min.js',\n assetFileNames: 'assets/[name].[hash][extname]',\n chunkFileNames: 'chunks/[hash].min.js',\n sanitizeFileName: sanitizeFileName,\n ...viteConfig?.build?.rollupOptions?.output,\n },\n },\n outDir: path.join(distDir, 'client'),\n ssr: false,\n ssrManifest: false,\n manifest: true,\n cssCodeSplit: true,\n target: 'esnext',\n minify: true,\n modulePreload: {polyfill: false},\n reportCompressedSize: false,\n },\n });\n } else {\n await writeFile(path.join(distDir, 'client/manifest.json'), '{}');\n }\n\n // Copy CSS files from dist/routes/**/*.css to dist/client/ and flatten the\n // routes manifest to ignore imported modules. Then add the route assets to\n // the client manifest.\n await copyGlob(\n '**/*.css',\n path.join(distDir, 'routes'),\n path.join(distDir, 'client')\n );\n const routesManifest = await loadJson<Manifest>(\n path.join(distDir, 'routes/manifest.json')\n );\n const clientManifest = await loadJson<Manifest>(\n path.join(distDir, 'client/manifest.json')\n );\n function collectRouteCss(\n asset: ManifestChunk,\n cssDeps: Set<string>,\n visited: Set<string>\n ) {\n if (!asset || !asset.file || visited.has(asset.file)) {\n return;\n }\n visited.add(asset.file);\n if (asset.css) {\n asset.css.forEach((dep) => cssDeps.add(dep));\n }\n if (asset.imports) {\n asset.imports.forEach((manifestKey) => {\n collectRouteCss(routesManifest[manifestKey], cssDeps, visited);\n });\n }\n }\n Object.keys(routesManifest).forEach((manifestKey) => {\n const asset = routesManifest[manifestKey];\n if (asset.isEntry) {\n const visited = new Set<string>();\n const cssDeps = new Set<string>();\n collectRouteCss(asset, cssDeps, visited);\n asset.css = Array.from(cssDeps);\n asset.imports = [];\n clientManifest[manifestKey] = asset;\n } else if (asset.file.endsWith('.css')) {\n clientManifest[manifestKey] = asset;\n }\n });\n\n // Use the output of the client build to generate an asset map, which is used\n // by the renderer for automatically injecting dependencies for a page.\n const assetMap = BuildAssetMap.fromViteManifest(\n rootConfig,\n clientManifest,\n elementGraph\n );\n\n // Save the asset map to `dist/client` for use by the prod SSR server.\n const rootManifest = assetMap.toJson();\n await writeFile(\n path.join(distDir, 'client/root-manifest.json'),\n JSON.stringify(rootManifest, null, 2)\n );\n\n // Save the element graph to `dist/client` for use by the prod SSR server.\n const elementGraphJson = elementGraph.toJson();\n await writeFile(\n path.join(distDir, 'client/root-element-graph.json'),\n JSON.stringify(elementGraphJson, 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, {dereference: true});\n } else {\n await makeDir(buildDir);\n }\n\n // Copy files from `dist/client/{assets,chunks}` to `dist/html` using the\n // root manifest. Ignore route files.\n console.log('\\njs/css output:');\n await Promise.all(\n Object.keys(rootManifest).map(async (src) => {\n // Don't expose route files in the final output. If any client-side code\n // relies on route dependencies, it should probably be broken out into a\n // shared component instead.\n if (isRouteFile(src)) {\n return;\n }\n const assetData = rootManifest[src];\n // Ignore files with no assetUrl, which can sometimes occur if a source\n // file is empty.\n if (!assetData.assetUrl) {\n return;\n }\n const assetRelPath = assetData.assetUrl.slice(1);\n const assetFrom = path.join(distDir, 'client', assetRelPath);\n const assetTo = path.join(buildDir, assetRelPath);\n // Ignore assets that don't exist. This is because build artifacts from\n // the routes/ folder are not copied to dist/client (only css deps are).\n if (!(await fileExists(assetFrom))) {\n console.log(`${assetFrom} does not exist`);\n return;\n }\n await fsExtra.copy(assetFrom, assetTo);\n printFileOutput(fileSize(assetTo), 'dist/html/', assetRelPath);\n })\n );\n\n // Pre-render HTML pages (SSG).\n if (!ssrOnly) {\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n const sitemap = await renderer.getSitemap();\n\n console.log('\\nhtml output:');\n const batchSize = Number(options?.concurrency || 10);\n await batchAsyncCalls(Object.keys(sitemap), batchSize, async (urlPath) => {\n const {route, params} = sitemap[urlPath];\n try {\n const data = await renderer.renderRoute(route, {\n routeParams: params,\n });\n if (data.notFound) {\n return;\n }\n\n // The renderer currently assumes that all paths serve HTML.\n // TODO(stevenle): support non-HTML routes using `routes/[name].[ext].ts`.\n let outFilePath = path.join(urlPath.slice(1), 'index.html');\n if (outFilePath.endsWith('404/index.html')) {\n outFilePath = outFilePath.replace('404/index.html', '404.html');\n }\n const outPath = path.join(buildDir, outFilePath);\n\n let html = data.html || '';\n if (rootConfig.prettyHtml !== false) {\n html = await htmlPretty(html, rootConfig.prettyHtmlOptions);\n }\n // HTML minification is `true` by default. Set to `false` to disable.\n if (rootConfig.minifyHtml !== false) {\n html = await htmlMinify(html, rootConfig.minifyHtmlOptions);\n }\n await writeFile(outPath, html);\n\n printFileOutput(fileSize(outPath), 'dist/html/', outFilePath);\n } catch (e) {\n logBuildError({route, params, urlPath}, e);\n throw new Error(\n `BuildError: ${urlPath} (${route.src}) failed to build.`\n );\n }\n });\n }\n}\n\nfunction isRouteFile(filepath: string) {\n return filepath.startsWith('routes') && isJsFile(filepath);\n}\n\nfunction fileSize(filepath: string) {\n const stats = fsExtra.statSync(filepath);\n const bytes = stats.size;\n\n const k = 1024;\n if (bytes < k) {\n return (bytes / k).toFixed(2) + ' kB';\n }\n const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + units[i];\n}\n\nfunction printFileOutput(\n fileSize: string,\n outputDir: string,\n outputFile: string\n) {\n const indent = ' '.repeat(2);\n const paddedSize = fileSize.padStart(9, ' ');\n console.log(\n `${indent}${dim(paddedSize)} ${dim(outputDir)}${cyan(outputFile)}`\n );\n}\n\nfunction sanitizeFileName(name: string): string {\n return (\n name\n // Remove placeholder vars from paths like routes/[...var].tsx.\n .replaceAll('...', '')\n .replaceAll('_', '')\n .replaceAll('[', '')\n .replaceAll(']', '')\n // Remove non-ascii chars and null bytes.\n .replace(/[^\\x00-\\x7F]/g, '')\n .replace(/\\x00/g, '')\n .toLowerCase()\n );\n}\n\ninterface BuildContext {\n route: Route;\n params: Record<string, string>;\n urlPath: string;\n}\n\nfunction logBuildError(ctx: BuildContext, e: Error) {\n const {route, params, urlPath} = ctx;\n const errorString = String(e.stack || e);\n console.error();\n if (Object.keys(params).length > 0) {\n console.error(\n `An error occurred building ${urlPath} (${route.src}) with params:\n${formatParams(params)}\n\nThe error was:\n ${errorString}\n `.trim()\n );\n } else {\n console.error(\n `An error occurred building ${urlPath} (${route.src})\n\nThe error was:\n ${errorString}`\n );\n }\n}\n\nfunction formatParams(params: Record<string, string>) {\n return Object.entries(params)\n .map(([key, value]) => {\n return ` ${key}: ${value}`;\n })\n .join('\\n');\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport glob from 'tiny-glob';\nimport {searchForWorkspaceRoot} from 'vite';\n\nimport {RootConfig} from '../core/config';\nimport {isValidTagName, parseTagNames} from '../utils/elements';\nimport {directoryContains, isDirectory, isJsFile} from '../utils/fsutils';\n\ninterface ElementSourceFile {\n /** Full file path. */\n filePath: string;\n /** Path relative to the root project directory. */\n relPath: string;\n}\n\n/**\n * Dependency graph for element files to capture which other elements are used\n * by any particular element.\n */\nexport class ElementGraph {\n /**\n * Element tagName => sourceFile.\n */\n readonly sourceFiles: {[tagName: string]: ElementSourceFile} = {};\n\n /**\n * Element tagName => set of element tagName dependencies.\n */\n private deps: Record<string, string[]> = {};\n\n constructor(sourceFiles: {[tagName: string]: ElementSourceFile}) {\n this.sourceFiles = sourceFiles;\n }\n\n toJson() {\n for (const tagName in this.sourceFiles) {\n this.deps[tagName] ??= this.parseDepsFromSource(tagName);\n }\n return {\n sourceFiles: this.sourceFiles,\n deps: this.deps,\n };\n }\n\n static fromJson(data: {deps: any; sourceFiles: any}) {\n const graph = new ElementGraph(data.sourceFiles);\n graph.deps = data.deps;\n return graph;\n }\n\n getDeps(tagName: string, visited?: Set<string>): string[] {\n visited ??= new Set();\n if (visited.has(tagName)) {\n return [];\n }\n\n visited.add(tagName);\n this.deps[tagName] ??= this.parseDepsFromSource(tagName);\n\n const deps = new Set(this.deps[tagName]);\n for (const depTagName of this.deps[tagName]) {\n for (const childDep of this.getDeps(depTagName, visited)) {\n deps.add(childDep);\n }\n }\n return Array.from(deps);\n }\n\n /**\n * Parses an element's source file for usage of other custom elements.\n */\n private parseDepsFromSource(tagName: string): string[] {\n const srcFile = this.sourceFiles[tagName];\n if (!srcFile) {\n throw new Error(`could not find file path for tagName <${tagName}>`);\n }\n const src = fs.readFileSync(srcFile.filePath, 'utf-8');\n const tagNames = parseTagNames(src);\n const deps = new Set<string>();\n for (const depTagName of tagNames) {\n if (depTagName !== tagName && depTagName in this.sourceFiles) {\n deps.add(depTagName);\n }\n }\n return Array.from(deps);\n }\n}\n\n/**\n * Returns a map of all the element file definitions in the project.\n */\nexport async function getElements(\n rootConfig: RootConfig\n): Promise<ElementGraph> {\n const rootDir = rootConfig.rootDir;\n\n const elementsDirs = getElementsDirs(rootConfig);\n const excludePatterns = rootConfig.elements?.exclude || [];\n const excludeElement = (moduleId: string) => {\n return excludePatterns.some((pattern) => Boolean(moduleId.match(pattern)));\n };\n\n const elementFilePaths: {[tagName: string]: ElementSourceFile} = {};\n for (const dirPath of elementsDirs) {\n if (await isDirectory(dirPath)) {\n const files = await glob('**/*', {cwd: dirPath});\n files.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base) && isValidTagName(parts.name)) {\n const tagName = parts.name;\n const filePath = path.join(dirPath, file);\n const relPath = path.relative(rootDir, filePath);\n if (!excludeElement(relPath)) {\n elementFilePaths[tagName] = {filePath, relPath};\n }\n }\n });\n }\n }\n\n const graph = new ElementGraph(elementFilePaths);\n return graph;\n}\n\n/**\n * Get all element dirs.\n */\nexport function getElementsDirs(rootConfig: RootConfig) {\n const rootDir = rootConfig.rootDir;\n const workspaceRoot = searchForWorkspaceRoot(rootDir);\n\n const elementsDirs = [path.join(rootDir, 'elements')];\n const elementsInclude = rootConfig.elements?.include || [];\n\n for (const dirPath of elementsInclude) {\n const elementsDir = path.resolve(rootDir, dirPath);\n if (!directoryContains(rootDir, elementsDir)) {\n throw new Error(\n `the elements dir (${dirPath}) should be within the project's workspace (${workspaceRoot})`\n );\n }\n elementsDirs.push(elementsDir);\n }\n\n return elementsDirs;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport {Manifest} from 'vite';\n\nimport {RootConfig} from '../../core/config';\nimport {ElementGraph} from '../../node/element-graph';\nimport {isJsFile} from '../../utils/fsutils';\n\nimport {Asset, AssetMap} from './asset-map';\n\nexport type BuildAssetManifest = Record<\n string,\n {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n>;\n\nexport class BuildAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private srcToAsset: Map<string, BuildAsset>;\n\n constructor(rootConfig: RootConfig) {\n this.rootConfig = rootConfig;\n this.srcToAsset = new Map();\n }\n\n async get(src: string): Promise<Asset | null> {\n const asset = this.srcToAsset.get(src);\n if (asset) {\n return asset;\n }\n // Try resolving the realpath of the asset, following symlinks.\n const realSrc = realPathRelativeTo(this.rootConfig.rootDir, src);\n if (realSrc !== src) {\n const asset = this.srcToAsset.get(realSrc);\n if (asset) {\n return asset;\n }\n }\n console.log(`could not find build asset: ${src}`);\n return null;\n }\n\n private add(asset: BuildAsset) {\n this.srcToAsset.set(asset.src, asset);\n }\n\n toJson(): BuildAssetManifest {\n const result: BuildAssetManifest = {};\n for (const src of this.srcToAsset.keys()) {\n result[src] = this.srcToAsset.get(src)!.toJson();\n }\n return result;\n }\n\n static fromViteManifest(\n rootConfig: RootConfig,\n clientManifest: Manifest,\n elementsGraph: ElementGraph\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n\n const elementFiles = new Set();\n Object.values(elementsGraph.sourceFiles).forEach((elementSource) => {\n elementFiles.add(elementSource.relPath);\n // Vite will resolve symlinks, so we need to follow the src and add the\n // realpath to the element files.\n const realSrc = realPathRelativeTo(\n rootConfig.rootDir,\n elementSource.relPath\n );\n if (realSrc !== elementSource.filePath) {\n elementFiles.add(realSrc);\n }\n });\n\n Object.keys(clientManifest).forEach((manifestKey) => {\n const src = manifestKey;\n const manifestChunk = clientManifest[manifestKey];\n const isElement = elementFiles.has(src);\n // NOTES(stevenle): routes/ files are included in the manifest so for\n // their CSS deps, but do not have an asset URL.\n const assetUrl =\n src.startsWith('routes/') && isJsFile(src)\n ? ''\n : `/${manifestChunk.file}`;\n const assetData = {\n src: src,\n assetUrl: assetUrl,\n importedModules: manifestChunk.imports || [],\n importedCss: (manifestChunk.css || []).map((relPath) => `/${relPath}`),\n isElement: isElement,\n };\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n\n return assetMap;\n }\n\n static fromRootManifest(\n rootConfig: RootConfig,\n rootManifest: BuildAssetManifest\n ) {\n const assetMap = new BuildAssetMap(rootConfig);\n Object.keys(rootManifest).forEach((moduleId) => {\n const assetData = rootManifest[moduleId];\n assetMap.add(new BuildAsset(assetMap, assetData));\n });\n return assetMap;\n }\n}\n\n/**\n * Returns the realpath of a src file, relative to the rootDir.\n */\nfunction realPathRelativeTo(rootDir: string, src: string) {\n const fullPath = path.resolve(rootDir, src);\n if (!fs.existsSync(fullPath)) {\n return src;\n }\n const realpath = fs.realpathSync(path.resolve(rootDir, src));\n return path.relative(rootDir, realpath);\n}\n\nexport class BuildAsset {\n src: string;\n assetUrl: string;\n private assetMap: BuildAssetMap;\n private importedModules: string[];\n private importedCss: string[];\n isElement: boolean;\n\n constructor(\n assetMap: BuildAssetMap,\n assetData: {\n src: string;\n assetUrl: string;\n importedModules: string[];\n importedCss: string[];\n isElement: boolean;\n }\n ) {\n this.assetMap = assetMap;\n this.src = assetData.src;\n this.assetUrl = assetData.assetUrl;\n this.importedModules = assetData.importedModules;\n this.importedCss = assetData.importedCss;\n this.isElement = assetData.isElement;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n await this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n private async collectJs(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.isElement) {\n urls.add(asset.assetUrl);\n }\n await Promise.all(\n asset.importedModules.map(async (src) => {\n const importedAsset = (await this.assetMap.get(src)) as BuildAsset;\n this.collectJs(importedAsset, urls, visited);\n })\n );\n }\n\n private async collectCss(\n asset: BuildAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.src) {\n return;\n }\n if (visited.has(asset.src)) {\n return;\n }\n visited.add(asset.src);\n if (asset.importedCss) {\n asset.importedCss.forEach((cssUrl) => urls.add(cssUrl));\n }\n await Promise.all(\n asset.importedModules.map(async (moduleId) => {\n const importedAsset = (await this.assetMap.get(moduleId)) as BuildAsset;\n this.collectCss(importedAsset, urls, visited);\n })\n );\n }\n\n toJson() {\n return {\n src: this.src,\n assetUrl: this.assetUrl,\n importedModules: this.importedModules,\n importedCss: this.importedCss,\n isElement: this.isElement,\n };\n }\n}\n","export async function batchAsyncCalls<T, U>(\n data: T[],\n batchSize: number,\n asyncFunction: (item: T) => Promise<U>\n): Promise<U[]> {\n const result: U[] = [];\n const batches = Math.ceil(data.length / batchSize);\n for (let i = 0; i < batches; i++) {\n const batch = data.slice(i * batchSize, (i + 1) * batchSize);\n const batchResults = await Promise.all(batch.map(asyncFunction));\n result.push(...batchResults);\n }\n return result;\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\nimport glob from 'tiny-glob';\n\nimport {RootConfig} from '../../core/config.js';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../core/middleware.js';\nimport {configureServerPlugins} from '../../core/plugin.js';\nimport {Server, Request, Response, NextFunction} from '../../core/types.js';\nimport {getElements, getElementsDirs} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config.js';\nimport {createViteServer} from '../../node/vite.js';\nimport {DevServerAssetMap} from '../../render/asset-map/dev-asset-map.js';\nimport {dirExists, isDirectory, isJsFile} from '../../utils/fsutils.js';\nimport {findOpenPort} from '../../utils/ports.js';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface DevOptions {\n host?: string;\n}\n\nexport async function dev(rootProjectDir?: string, options?: DevOptions) {\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const defaultPort = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n const port = await findOpenPort(defaultPort, defaultPort + 10);\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: development`);\n console.log();\n const server = await createDevServer({rootDir, port});\n server.listen(port, host);\n}\n\nexport async function createDevServer(options?: {\n rootDir?: string;\n port?: number;\n}): Promise<Server> {\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n const rootConfig = await loadRootConfig(rootDir, {command: 'dev'});\n const port = options?.port;\n\n const server = express();\n server.disable('x-powered-by');\n\n // Inject req context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await viteServerMiddleware({rootConfig, port}));\n\n const plugins = rootConfig.plugins || [];\n await configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n for (const middleware of userMiddlewares) {\n server.use(middleware);\n }\n\n // Add static file middleware.\n const publicDir = path.join(rootDir, 'public');\n if (await dirExists(publicDir)) {\n server.use(sirv(publicDir, {dev: false}));\n }\n\n // Add the root.js dev server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootDevServerMiddleware());\n server.use(rootDevServer404Middleware());\n server.use(rootDevServer500Middleware());\n },\n plugins,\n {type: 'dev', rootConfig}\n );\n\n return server;\n}\n\n/**\n * Middleware that initializes a vite server and injects it into the request\n * context.\n */\nasync function viteServerMiddleware(options: {\n rootConfig: RootConfig;\n port?: number;\n}) {\n const rootConfig = options.rootConfig;\n const rootDir = rootConfig.rootDir;\n\n let elementGraph = await getElements(rootConfig);\n const elements = Object.values(elementGraph.sourceFiles).map((sourceFile) => {\n return sourceFile.relPath;\n });\n\n const bundleScripts: string[] = [];\n if (await isDirectory(path.join(rootDir, 'bundles'))) {\n const bundleFiles = await glob('bundles/*', {cwd: rootDir});\n bundleFiles.forEach((file) => {\n const parts = path.parse(file);\n if (isJsFile(parts.base)) {\n bundleScripts.push(file);\n }\n });\n }\n\n const optimizeDeps = [...elements, ...bundleScripts];\n const viteServer = await createViteServer(rootConfig, {\n port: options.port,\n optimizeDeps: optimizeDeps,\n });\n\n // Watch for file changes and re-generate the elements graph if any elements\n // are added or deleted.\n function isInElementsDir(changedFilePath: string) {\n const filePath = path.resolve(changedFilePath);\n const elementsDirs = getElementsDirs(rootConfig);\n return elementsDirs.some((dirPath) => filePath.startsWith(dirPath));\n }\n viteServer.watcher.on('add', async (filePath: string) => {\n if (isInElementsDir(filePath)) {\n // Re-generate the elements graph.\n elementGraph = await getElements(rootConfig);\n console.log(`element added: ${filePath}`);\n }\n });\n viteServer.watcher.on('unlink', async (filePath: string) => {\n if (isInElementsDir(filePath)) {\n // Re-generate the elements graph.\n elementGraph = await getElements(rootConfig);\n console.log(`element deleted: ${filePath}`);\n }\n });\n\n return async (req: Request, res: Response, next: NextFunction) => {\n try {\n // Add the viteServer to the req.\n req.viteServer = viteServer;\n // Dynamically import the render.js module using vite's SSR import loader.\n const renderModulePath = path.resolve(__dirname, './render.js');\n const render = (await viteServer.ssrLoadModule(\n renderModulePath\n )) as RenderModule;\n // Create a dev asset map using Vite dev server's module graph.\n const assetMap = new DevServerAssetMap(\n rootConfig,\n viteServer.moduleGraph\n );\n // Add a renderer object to the req for plugins and other middleware to\n // use.\n req.renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n // Run the viteServer middlewares to handle vite-specific endpoints.\n viteServer.middlewares(req, res, next);\n } catch (e) {\n next(e);\n }\n };\n}\n\nfunction rootDevServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n const viteServer = req.viteServer!;\n try {\n await renderer.handle(req, res, next);\n } catch (err) {\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(err);\n next(err);\n }\n };\n}\n\nfunction rootDevServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer404(req);\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootDevServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer500(req, err);\n const html = data.html || '';\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n next(err);\n };\n}\n","import path from 'node:path';\nimport {RootConfig} from './config';\nimport {Request, Response, NextFunction} from './types';\n\n/**\n * Middleware that injects the root.js project config into the request context.\n */\nexport function rootProjectMiddleware(options: {rootConfig: RootConfig}) {\n return (req: Request, _: Response, next: NextFunction) => {\n req.rootConfig = options.rootConfig;\n next();\n };\n}\n\n/**\n * Trailing slash middleware. Handles trailing slash redirects (preserving any\n * query params) using the `server.trailingSlash` config in root.config.ts.\n */\nexport function trailingSlashMiddleware(options: {rootConfig: RootConfig}) {\n const trailingSlash = options.rootConfig.server?.trailingSlash;\n\n return (req: Request, res: Response, next: NextFunction) => {\n // If `trailingSlash: false`, force a trailing slash in the URL.\n if (\n trailingSlash === true &&\n !path.extname(req.path) &&\n !req.path.endsWith('/')\n ) {\n const redirectPath = `${req.path}/`;\n redirectWithQuery(req, res, 301, redirectPath);\n return;\n }\n\n // If `trailingSlash: false`, remove any trailing slash from the URL.\n if (\n trailingSlash === false &&\n !path.extname(req.path) &&\n req.path !== '/' &&\n req.path.endsWith('/')\n ) {\n const redirectPath = removeTrailingSlashes(req.path);\n redirectWithQuery(req, res, 301, redirectPath);\n return;\n }\n\n next();\n };\n}\n\n/**\n * Issues an HTTP redirect, preserving any query params from the original req.\n */\nfunction redirectWithQuery(\n req: Request,\n res: Response,\n redirectCode: number,\n redirectPath: string\n) {\n const queryStr = getQueryStr(req);\n const redirectUrl = queryStr ? `${redirectPath}?${queryStr}` : redirectPath;\n res.redirect(redirectCode, redirectUrl);\n}\n\n/**\n * Returns the query string for a request, or empty string if no query.\n */\nfunction getQueryStr(req: Request): string {\n const qIndex = req.originalUrl.indexOf('?');\n if (qIndex === -1) {\n return '';\n }\n return req.originalUrl.slice(qIndex + 1);\n}\n\n/**\n * Removes trailing slashes from a URL path.\n * Note: A path with only slashes (e.g. `///`) returns `/`.\n */\nfunction removeTrailingSlashes(urlPath: string) {\n while (urlPath.endsWith('/') && urlPath !== '/') {\n urlPath = urlPath.slice(0, -1);\n }\n return urlPath;\n}\n","import path from 'node:path';\n\nimport {ModuleGraph, ModuleNode, searchForWorkspaceRoot} from 'vite';\n\nimport {RootConfig} from '../../core/config';\nimport {directoryContains} from '../../utils/fsutils';\n\nimport {Asset, AssetMap} from './asset-map';\n\nexport class DevServerAssetMap implements AssetMap {\n private rootConfig: RootConfig;\n private moduleGraph: ModuleGraph;\n\n constructor(rootConfig: RootConfig, moduleGraph: ModuleGraph) {\n this.rootConfig = rootConfig;\n this.moduleGraph = moduleGraph;\n }\n\n async get(src: string): Promise<Asset | null> {\n const file = path.resolve(this.rootConfig.rootDir, src);\n\n const viteModules = this.moduleGraph.getModulesByFile(file);\n if (viteModules && viteModules.size > 0) {\n const [viteModule] = viteModules;\n return new DevServerAsset(src, {\n assetMap: this,\n viteModule: viteModule,\n });\n }\n\n // On dev, in some cases the module doesn't make it into the module graph\n // so return a generic asset.\n if (file.startsWith(this.rootConfig.rootDir)) {\n const assetUrl = file.slice(this.rootConfig.rootDir.length);\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n const workspaceRoot = searchForWorkspaceRoot(this.rootConfig.rootDir);\n if (await directoryContains(workspaceRoot, file)) {\n const assetUrl = `/@fs/${file}`;\n return {\n src: src,\n assetUrl: assetUrl,\n getCssDeps: async () => [],\n getJsDeps: async () => [assetUrl],\n };\n }\n\n console.log(`could not find asset in asset map: ${src}`);\n return null;\n }\n\n filePathToSrc(file: string) {\n return path.relative(this.rootConfig.rootDir, file);\n }\n}\n\nexport class DevServerAsset implements Asset {\n src: string;\n moduleId: string;\n assetUrl: string;\n private assetMap: DevServerAssetMap;\n private viteModule: ModuleNode;\n\n constructor(\n src: string,\n options: {\n assetMap: DevServerAssetMap;\n viteModule: ModuleNode;\n }\n ) {\n this.src = src;\n this.assetMap = options.assetMap;\n this.viteModule = options.viteModule;\n this.moduleId = this.viteModule.id!;\n this.assetUrl = this.viteModule.url;\n }\n\n async getCssDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectCss(this, deps, visited);\n return Array.from(deps);\n }\n\n async getJsDeps(): Promise<string[]> {\n const visited = new Set<string>();\n const deps = new Set<string>();\n this.collectJs(this, deps, visited);\n return Array.from(deps);\n }\n\n getImportedModules() {\n return this.viteModule.importedModules;\n }\n\n private collectJs(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.moduleId) {\n return;\n }\n if (visited.has(asset.moduleId)) {\n return;\n }\n visited.add(asset.moduleId);\n const parts = path.parse(asset.assetUrl);\n if (\n ['.js', '.jsx', '.ts', '.tsx'].includes(parts.ext) &&\n asset.moduleId.includes('/elements/')\n ) {\n urls.add(asset.assetUrl);\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\n this.collectJs(importedAsset, urls, visited);\n }\n });\n }\n\n private collectCss(\n asset: DevServerAsset | null,\n urls: Set<string>,\n visited: Set<string>\n ) {\n if (!asset) {\n return;\n }\n if (!asset.assetUrl) {\n return;\n }\n if (visited.has(asset.assetUrl)) {\n return;\n }\n visited.add(asset.assetUrl);\n if (asset.src.endsWith('.scss')) {\n const parts = path.parse(asset.src);\n if (!parts.name.startsWith('_')) {\n urls.add(asset.assetUrl);\n }\n }\n asset.getImportedModules().forEach((viteModule) => {\n if (viteModule.file) {\n const src = this.assetMap.filePathToSrc(viteModule.file);\n const importedAsset = new DevServerAsset(src, {\n assetMap: this.assetMap,\n viteModule: viteModule,\n });\n this.collectCss(importedAsset, urls, visited);\n }\n });\n }\n}\n","import {createServer} from 'node:net';\n\n/**\n * Checks whether a port is open.\n */\nexport function isPortOpen(port: number): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const server = createServer();\n server.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n resolve(false);\n return;\n }\n reject(err);\n });\n server.on('close', () => {\n resolve(true);\n });\n server.listen(port, () => {\n server.close((err) => {\n if (err) {\n console.log(`error closing server: ${err}`);\n reject(err);\n }\n });\n });\n });\n}\n\n/**\n * Finds the first open port between two values.\n */\nexport async function findOpenPort(min: number, max: number): Promise<number> {\n let port = min;\n while (port <= max) {\n const isOpen = await isPortOpen(port);\n if (isOpen) {\n return port;\n }\n port += 1;\n }\n throw new Error(`no ports open between ${min} and ${max}`);\n}\n","import path from 'node:path';\n\nimport compression from 'compression';\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\n\nimport {RootConfig} from '../../core/config';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../core/middleware';\nimport {configureServerPlugins} from '../../core/plugin';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {ElementGraph} from '../../node/element-graph.js';\nimport {loadRootConfig} from '../../node/load-config';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {fileExists, loadJson} from '../../utils/fsutils';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface PreviewOptions {\n host?: string;\n}\n\nexport async function preview(\n rootProjectDir?: string,\n options?: PreviewOptions\n) {\n // TODO(stevenle): figure out standard practice for NODE_ENV when using the\n // preview command.\n process.env.NODE_ENV = 'development';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createPreviewServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: preview`);\n console.log();\n server.listen(port, host);\n}\n\nexport async function createPreviewServer(options: {\n rootDir: string;\n}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir, {command: 'preview'});\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await rootPreviewRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootPreviewServerMiddleware());\n\n // Add error handlers.\n server.use(rootPreviewServer404Middleware());\n server.use(rootPreviewServer500Middleware());\n },\n plugins,\n {type: 'preview', rootConfig}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootPreviewRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root preview\\`.`\n );\n }\n const elementGraphJsonPath = path.join(\n distDir,\n 'client/root-element-graph.json'\n );\n if (!(await fileExists(elementGraphJsonPath))) {\n throw new Error(\n `could not find ${elementGraphJsonPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootConfig, rootManifest);\n const elementGraphJson = await loadJson<any>(elementGraphJsonPath);\n const elementGraph = ElementGraph.fromJson(elementGraphJson);\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Preview server request handler.\n */\nfunction rootPreviewServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n try {\n await renderer.handle(req, res, next);\n } catch (e) {\n try {\n console.error(`error rendering ${req.originalUrl}`);\n console.error(e.stack || e);\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\nfunction rootPreviewServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.render404({currentPath: url});\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootPreviewServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderDevServer500(req, err);\n const html = data.html || '';\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n next(err);\n };\n}\n","import path from 'node:path';\n\nimport compression from 'compression';\nimport {default as express} from 'express';\nimport {dim} from 'kleur/colors';\nimport sirv from 'sirv';\n\nimport {RootConfig} from '../../core/config';\nimport {\n rootProjectMiddleware,\n trailingSlashMiddleware,\n} from '../../core/middleware';\nimport {configureServerPlugins} from '../../core/plugin';\nimport {Request, Response, NextFunction, Server} from '../../core/types.js';\nimport {ElementGraph} from '../../node/element-graph';\nimport {loadRootConfig} from '../../node/load-config';\nimport {\n BuildAssetManifest,\n BuildAssetMap,\n} from '../../render/asset-map/build-asset-map';\nimport {fileExists, loadJson} from '../../utils/fsutils';\n\ntype RenderModule = typeof import('../../render/render.js');\n\nexport interface StartOptions {\n host?: string;\n}\n\nexport async function start(rootProjectDir?: string, options?: StartOptions) {\n process.env.NODE_ENV = 'production';\n const rootDir = path.resolve(rootProjectDir || process.cwd());\n const server = await createProdServer({rootDir});\n const port = parseInt(process.env.PORT || '4007');\n const host = options?.host || 'localhost';\n console.log();\n console.log(`${dim('┃')} project: ${rootDir}`);\n console.log(`${dim('┃')} server: http://${host}:${port}`);\n console.log(`${dim('┃')} mode: production`);\n console.log();\n server.listen(port, host);\n}\n\nexport async function createProdServer(options: {\n rootDir: string;\n}): Promise<Server> {\n const rootDir = options.rootDir;\n const rootConfig = await loadRootConfig(rootDir, {command: 'start'});\n const distDir = path.join(rootDir, 'dist');\n\n const server = express();\n server.disable('x-powered-by');\n server.use(compression());\n\n // Inject request context vars.\n server.use(rootProjectMiddleware({rootConfig}));\n server.use(await rootProdRendererMiddleware({rootConfig, distDir}));\n\n const plugins = rootConfig.plugins || [];\n configureServerPlugins(\n server,\n async () => {\n // Add user-configured middlewares from `root.config.ts`.\n const userMiddlewares = rootConfig.server?.middlewares || [];\n userMiddlewares.forEach((middleware) => {\n server.use(middleware);\n });\n\n // Add static file middleware.\n const publicDir = path.join(distDir, 'html');\n server.use(sirv(publicDir, {dev: false}));\n\n // Add the root.js preview server middlewares.\n server.use(trailingSlashMiddleware({rootConfig}));\n server.use(rootProdServerMiddleware());\n\n // Add error handlers.\n server.use(rootProdServer404Middleware());\n server.use(rootProdServer500Middleware());\n },\n plugins,\n {type: 'prod', rootConfig}\n );\n return server;\n}\n\n/**\n * Injects a renderer into the request.\n */\nasync function rootProdRendererMiddleware(options: {\n rootConfig: RootConfig;\n distDir: string;\n}) {\n const {distDir, rootConfig} = options;\n const render: RenderModule = await import(\n path.join(distDir, 'server/render.js')\n );\n const manifestPath = path.join(distDir, 'client/root-manifest.json');\n if (!(await fileExists(manifestPath))) {\n throw new Error(\n `could not find ${manifestPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const elementGraphJsonPath = path.join(\n distDir,\n 'client/root-element-graph.json'\n );\n if (!(await fileExists(elementGraphJsonPath))) {\n throw new Error(\n `could not find ${elementGraphJsonPath}. run \\`root build\\` before \\`root start\\`.`\n );\n }\n const rootManifest = await loadJson<BuildAssetManifest>(manifestPath);\n const assetMap = BuildAssetMap.fromRootManifest(rootConfig, rootManifest);\n const elementGraphJson = await loadJson<any>(elementGraphJsonPath);\n const elementGraph = ElementGraph.fromJson(elementGraphJson);\n const renderer = new render.Renderer(rootConfig, {assetMap, elementGraph});\n return async (req: Request, _: Response, next: NextFunction) => {\n req.renderer = renderer;\n next();\n };\n}\n\n/**\n * Prod server request handler.\n */\nfunction rootProdServerMiddleware() {\n return async (req: Request, res: Response, next: NextFunction) => {\n const renderer = req.renderer!;\n try {\n await renderer.handle(req, res, next);\n } catch (e) {\n try {\n console.error(`error rendering ${req.originalUrl}`);\n console.error(e.stack || e);\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\nfunction rootProdServer404Middleware() {\n return async (req: Request, res: Response) => {\n console.error(`❓ 404 ${req.originalUrl}`);\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.render404({currentPath: url});\n const html = data.html || '';\n res.status(404).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n res.status(404).set({'Content-Type': 'text/plain'}).end('404');\n };\n}\n\nfunction rootProdServer500Middleware() {\n return async (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(`❗ 500 ${req.originalUrl}`);\n console.error(String(err.stack || err));\n if (req.renderer) {\n const url = req.path;\n const ext = path.extname(url);\n if (!ext) {\n const renderer = req.renderer;\n const data = await renderer.renderError(err);\n const html = data.html || '';\n res.status(500).set({'Content-Type': 'text/html'}).end(html);\n return;\n }\n }\n next(err);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAOA,WAAU;AACjB,SAAQ,qBAAoB;AAE5B,OAAO,aAAa;AACpB,SAAQ,KAAK,YAAW;AACxB,OAAOC,WAAU;AACjB,SAAQ,SAAS,iBAAqD;;;ACPtE,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,OAAO,UAAU;AACjB,SAAQ,8BAA6B;AAiB9B,IAAM,eAAN,MAAmB;AAAA,EAWxB,YAAY,aAAqD;AAPjE,SAAS,cAAsD,CAAC;AAKhE,SAAQ,OAAiC,CAAC;AAGxC,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,SAAS;AACP,eAAW,WAAW,KAAK,aAAa;AACtC,WAAK,KAAK,aAAa,KAAK,oBAAoB,OAAO;AAAA,IACzD;AACA,WAAO;AAAA,MACL,aAAa,KAAK;AAAA,MAClB,MAAM,KAAK;AAAA,IACb;AAAA,EACF;AAAA,EAEA,OAAO,SAAS,MAAqC;AACnD,UAAM,QAAQ,IAAI,aAAa,KAAK,WAAW;AAC/C,UAAM,OAAO,KAAK;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,SAAiB,SAAiC;AACxD,gBAAY,oBAAI,IAAI;AACpB,QAAI,QAAQ,IAAI,OAAO,GAAG;AACxB,aAAO,CAAC;AAAA,IACV;AAEA,YAAQ,IAAI,OAAO;AACnB,SAAK,KAAK,aAAa,KAAK,oBAAoB,OAAO;AAEvD,UAAM,OAAO,IAAI,IAAI,KAAK,KAAK,QAAQ;AACvC,eAAW,cAAc,KAAK,KAAK,UAAU;AAC3C,iBAAW,YAAY,KAAK,QAAQ,YAAY,OAAO,GAAG;AACxD,aAAK,IAAI,QAAQ;AAAA,MACnB;AAAA,IACF;AACA,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AAAA,EAKQ,oBAAoB,S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EAAE,IAAI,EAAC,gBAAgB,YAAW,CAAC,EAAE,IAAI,IAAI;AAC3D;AAAA,MACF;AAAA,IACF;AACA,SAAK,GAAG;AAAA,EACV;AACF;","names":["path","glob","fs","path","asset","path","fs","path","glob","fileSize","path","fileURLToPath","dim","glob","path","path","searchForWorkspaceRoot","path","searchForWorkspaceRoot","__dirname","path","fileURLToPath","dim","glob","path","express","dim","sirv","path","dim","express","sirv","path","compression","express","dim","sirv","path","dim","express","compression","sirv"]}
|