@webtypen/webframez-react 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/webframez-react.mjs +358 -1
- package/defaults/default-client.js +3 -0
- package/defaults/webpack.client.cjs +177 -10
- package/dist/build-plugin.cjs +111 -0
- package/dist/build-plugin.d.ts +14 -0
- package/dist/build-plugin.js +77 -0
- package/dist/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/dist/http.cjs +197 -35
- package/dist/http.js +202 -35
- package/dist/index.cjs +325 -51
- package/dist/index.js +327 -51
- package/dist/types.d.ts +0 -1
- package/dist/webframez-core.cjs +325 -51
- package/dist/webframez-core.d.ts +27 -3
- package/dist/webframez-core.js +329 -51
- package/package.json +10 -1
package/dist/index.cjs
CHANGED
|
@@ -30,13 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var src_exports = {};
|
|
31
31
|
__export(src_exports, {
|
|
32
32
|
RouteChildren: () => RouteChildren,
|
|
33
|
+
clearRegisteredReactBuildTargets: () => clearRegisteredReactBuildTargets,
|
|
33
34
|
createFileRouter: () => createFileRouter,
|
|
34
35
|
createHTMLShell: () => createHTMLShell,
|
|
35
36
|
createNodeRequestHandler: () => createNodeRequestHandler,
|
|
36
37
|
createRSCHandler: () => createRSCHandler,
|
|
38
|
+
getRegisteredReactBuildTargets: () => getRegisteredReactBuildTargets,
|
|
37
39
|
initWebframezReact: () => initWebframezReact,
|
|
38
40
|
parseSearchParams: () => parseSearchParams,
|
|
39
41
|
renderHeadToString: () => renderHeadToString,
|
|
42
|
+
resolveWebframezReactRouteOptions: () => resolveWebframezReactRouteOptions,
|
|
40
43
|
sendRSC: () => sendRSC,
|
|
41
44
|
setupWebframezCoreReactRoute: () => setupWebframezCoreReactRoute
|
|
42
45
|
});
|
|
@@ -826,10 +829,81 @@ var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
|
826
829
|
var import_node_path3 = __toESM(require("node:path"), 1);
|
|
827
830
|
var import_node_url = require("node:url");
|
|
828
831
|
var import_node_child_process = require("node:child_process");
|
|
832
|
+
var import_node_zlib = require("node:zlib");
|
|
829
833
|
function createInitialHtmlErrorMarkup(message) {
|
|
830
834
|
return `<main style="font-family:system-ui,sans-serif;padding:24px"><h1 style="margin:0 0 12px">500</h1><p style="margin:0">${message}</p></main>`;
|
|
831
835
|
}
|
|
836
|
+
function createClientAssetVersion(distRootDir) {
|
|
837
|
+
try {
|
|
838
|
+
const stat = import_node_fs2.default.statSync(import_node_path3.default.join(distRootDir, "client.js"));
|
|
839
|
+
return `${Math.floor(stat.mtimeMs)}-${stat.size}`;
|
|
840
|
+
} catch {
|
|
841
|
+
return "";
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
function appendAssetVersion(url, version) {
|
|
845
|
+
if (!version) {
|
|
846
|
+
return url;
|
|
847
|
+
}
|
|
848
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
849
|
+
return `${url}${separator}v=${encodeURIComponent(version)}`;
|
|
850
|
+
}
|
|
851
|
+
function isWithinDirectory(filePath, directory) {
|
|
852
|
+
return filePath === directory || filePath.startsWith(`${directory}${import_node_path3.default.sep}`);
|
|
853
|
+
}
|
|
854
|
+
function isCompressibleAsset(ext) {
|
|
855
|
+
return [".js", ".mjs", ".json", ".css", ".svg", ".txt", ".html"].includes(ext);
|
|
856
|
+
}
|
|
857
|
+
function isHashedAssetPath(filePath) {
|
|
858
|
+
return /-[a-f0-9]{12,}\.[cm]?js$/i.test(import_node_path3.default.basename(filePath));
|
|
859
|
+
}
|
|
860
|
+
function setAssetContentType(res, ext) {
|
|
861
|
+
if (ext === ".js" || ext === ".mjs") {
|
|
862
|
+
res.setHeader("Content-Type", "text/javascript; charset=utf-8");
|
|
863
|
+
} else if (ext === ".json") {
|
|
864
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
865
|
+
} else if (ext === ".css") {
|
|
866
|
+
res.setHeader("Content-Type", "text/css; charset=utf-8");
|
|
867
|
+
} else if (ext === ".svg") {
|
|
868
|
+
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
function getPreferredContentEncoding(req, ext, fileSize) {
|
|
872
|
+
if (!isCompressibleAsset(ext) || fileSize < 1024) {
|
|
873
|
+
return "";
|
|
874
|
+
}
|
|
875
|
+
const acceptEncoding = String(req.headers["accept-encoding"] || "");
|
|
876
|
+
if (/\bbr\b/.test(acceptEncoding)) {
|
|
877
|
+
return "br";
|
|
878
|
+
}
|
|
879
|
+
if (/\bgzip\b/.test(acceptEncoding)) {
|
|
880
|
+
return "gzip";
|
|
881
|
+
}
|
|
882
|
+
return "";
|
|
883
|
+
}
|
|
884
|
+
function sendTextResponse(req, res, body, options) {
|
|
885
|
+
const bodyBuffer = Buffer.from(body);
|
|
886
|
+
const contentEncoding = options.compress === false ? "" : getPreferredContentEncoding(req, ".html", bodyBuffer.length);
|
|
887
|
+
res.statusCode = options.statusCode ?? 200;
|
|
888
|
+
res.setHeader("Content-Type", options.contentType);
|
|
889
|
+
if (options.cacheControl) {
|
|
890
|
+
res.setHeader("Cache-Control", options.cacheControl);
|
|
891
|
+
}
|
|
892
|
+
res.setHeader("Vary", "Accept-Encoding");
|
|
893
|
+
if (contentEncoding === "br") {
|
|
894
|
+
res.setHeader("Content-Encoding", "br");
|
|
895
|
+
res.end((0, import_node_zlib.brotliCompressSync)(bodyBuffer));
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
if (contentEncoding === "gzip") {
|
|
899
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
900
|
+
res.end((0, import_node_zlib.gzipSync)(bodyBuffer));
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
res.end(bodyBuffer);
|
|
904
|
+
}
|
|
832
905
|
var INITIAL_HTML_WORKER_SCRIPT = `
|
|
906
|
+
const fs = require("node:fs");
|
|
833
907
|
const path = require("node:path");
|
|
834
908
|
const Module = require("node:module");
|
|
835
909
|
const { Readable, Writable } = require("node:stream");
|
|
@@ -879,11 +953,42 @@ const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node
|
|
|
879
953
|
globalThis.__webpack_chunk_load__ = function __webframezNoopChunkLoad() {
|
|
880
954
|
return Promise.resolve();
|
|
881
955
|
};
|
|
956
|
+
function normalizeWebframezRequireCandidate(candidate) {
|
|
957
|
+
const stagingMarker = path.join(".webframez-build", "");
|
|
958
|
+
const appMarker = path.join("app", "");
|
|
959
|
+
const stagingIndex = candidate.indexOf(stagingMarker);
|
|
960
|
+
const appIndex = candidate.indexOf(appMarker, stagingIndex >= 0 ? stagingIndex : 0);
|
|
961
|
+
if (stagingIndex >= 0 && appIndex >= 0) {
|
|
962
|
+
const runtimeCandidate = path.resolve(process.cwd(), candidate.slice(appIndex));
|
|
963
|
+
if (fs.existsSync(runtimeCandidate)) {
|
|
964
|
+
return runtimeCandidate;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const frameworkDistDir = path.join("node_modules", "@webtypen", "webframez-react", "dist");
|
|
969
|
+
const shouldUseCjs =
|
|
970
|
+
candidate.includes(frameworkDistDir) &&
|
|
971
|
+
(candidate.endsWith(path.join("dist", "navigation.js")) ||
|
|
972
|
+
candidate.endsWith(path.join("dist", "route-slot.js")));
|
|
973
|
+
|
|
974
|
+
if (!shouldUseCjs) {
|
|
975
|
+
return candidate;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
const cjsCandidate = candidate.slice(0, -3) + ".cjs";
|
|
979
|
+
return fs.existsSync(cjsCandidate) ? cjsCandidate : candidate;
|
|
980
|
+
}
|
|
981
|
+
|
|
882
982
|
globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
|
|
883
983
|
if (typeof id !== "string") {
|
|
884
984
|
return require(id);
|
|
885
985
|
}
|
|
886
986
|
|
|
987
|
+
const directRequireTarget = normalizeWebframezRequireCandidate(id);
|
|
988
|
+
if (directRequireTarget !== id) {
|
|
989
|
+
return require(directRequireTarget);
|
|
990
|
+
}
|
|
991
|
+
|
|
887
992
|
if (id.startsWith("./")) {
|
|
888
993
|
const relativeId = id.slice(2);
|
|
889
994
|
const candidates = [
|
|
@@ -891,10 +996,16 @@ globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
|
|
|
891
996
|
path.resolve(process.cwd(), "..", relativeId)
|
|
892
997
|
];
|
|
893
998
|
for (const candidate of candidates) {
|
|
999
|
+
const requireTarget = normalizeWebframezRequireCandidate(candidate);
|
|
894
1000
|
try {
|
|
895
|
-
return require(
|
|
1001
|
+
return require(requireTarget);
|
|
896
1002
|
} catch (error) {
|
|
897
|
-
const missingCandidate =
|
|
1003
|
+
const missingCandidate =
|
|
1004
|
+
error &&
|
|
1005
|
+
error.code === "MODULE_NOT_FOUND" &&
|
|
1006
|
+
typeof error.message === "string" &&
|
|
1007
|
+
(error.message.includes("'" + candidate + "'") ||
|
|
1008
|
+
error.message.includes("'" + requireTarget + "'"));
|
|
898
1009
|
if (!missingCandidate) {
|
|
899
1010
|
throw error;
|
|
900
1011
|
}
|
|
@@ -1116,6 +1227,14 @@ function joinRuntimeBasePath(basePath, pathname) {
|
|
|
1116
1227
|
}
|
|
1117
1228
|
return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
|
|
1118
1229
|
}
|
|
1230
|
+
function joinRuntimeAssetPath(basePath, pathname) {
|
|
1231
|
+
const normalizedBasePath = normalizeRuntimeBasePath(basePath) ?? "";
|
|
1232
|
+
const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
1233
|
+
if (normalizedBasePath && (normalizedPath === normalizedBasePath || normalizedPath.startsWith(`${normalizedBasePath}/`))) {
|
|
1234
|
+
return normalizedPath;
|
|
1235
|
+
}
|
|
1236
|
+
return joinRuntimeBasePath(normalizedBasePath, normalizedPath);
|
|
1237
|
+
}
|
|
1119
1238
|
function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
1120
1239
|
if (!rawNodeOptions || rawNodeOptions.trim() === "") {
|
|
1121
1240
|
return "";
|
|
@@ -1310,6 +1429,18 @@ function createServerConsumerManifest(manifest) {
|
|
|
1310
1429
|
const consumerManifest = {};
|
|
1311
1430
|
const normalizeWorkerModuleId = (requestKey, rawModuleId) => {
|
|
1312
1431
|
if (typeof rawModuleId === "string" && rawModuleId.trim() !== "") {
|
|
1432
|
+
const isStagingModuleId = rawModuleId.startsWith("./.webframez-build/") || rawModuleId.includes(`${import_node_path3.default.sep}.webframez-build${import_node_path3.default.sep}`);
|
|
1433
|
+
const isRuntimeBuildKey = requestKey.startsWith("file://") || requestKey.startsWith("/") && requestKey.includes(`${import_node_path3.default.sep}build${import_node_path3.default.sep}app${import_node_path3.default.sep}`);
|
|
1434
|
+
if (isStagingModuleId && isRuntimeBuildKey) {
|
|
1435
|
+
if (requestKey.startsWith("file://")) {
|
|
1436
|
+
try {
|
|
1437
|
+
return (0, import_node_url.fileURLToPath)(requestKey);
|
|
1438
|
+
} catch {
|
|
1439
|
+
return rawModuleId;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
return requestKey;
|
|
1443
|
+
}
|
|
1313
1444
|
return rawModuleId;
|
|
1314
1445
|
}
|
|
1315
1446
|
if (typeof rawModuleId !== "number" || !Number.isFinite(rawModuleId)) {
|
|
@@ -1391,6 +1522,14 @@ function createServerConsumerManifest(manifest) {
|
|
|
1391
1522
|
name: exportName
|
|
1392
1523
|
});
|
|
1393
1524
|
}
|
|
1525
|
+
} else if (typeof entry.id === "string" && entry.id.trim() !== "") {
|
|
1526
|
+
addReference(entry.id, "*", reference);
|
|
1527
|
+
for (const exportName of exportNames) {
|
|
1528
|
+
addReference(entry.id, exportName, {
|
|
1529
|
+
...reference,
|
|
1530
|
+
name: exportName
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1394
1533
|
}
|
|
1395
1534
|
}
|
|
1396
1535
|
return consumerManifest;
|
|
@@ -1505,24 +1644,49 @@ function createNodeRequestHandler(options) {
|
|
|
1505
1644
|
if (url.pathname.startsWith(assetsPrefix)) {
|
|
1506
1645
|
const relative = url.pathname.slice(assetsPrefix.length);
|
|
1507
1646
|
const filePath = import_node_path3.default.resolve(distRootDir, relative);
|
|
1508
|
-
if (!filePath
|
|
1647
|
+
if (!isWithinDirectory(filePath, distRootDir)) {
|
|
1509
1648
|
res.statusCode = 400;
|
|
1510
1649
|
res.end("Invalid path");
|
|
1511
1650
|
return;
|
|
1512
1651
|
}
|
|
1513
1652
|
const ext = import_node_path3.default.extname(filePath);
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1653
|
+
let stat;
|
|
1654
|
+
try {
|
|
1655
|
+
stat = import_node_fs2.default.statSync(filePath);
|
|
1656
|
+
if (!stat.isFile()) {
|
|
1657
|
+
throw new Error("Asset path is not a file");
|
|
1658
|
+
}
|
|
1659
|
+
} catch {
|
|
1660
|
+
res.statusCode = 404;
|
|
1661
|
+
res.end("Not found");
|
|
1662
|
+
return;
|
|
1518
1663
|
}
|
|
1519
|
-
res
|
|
1664
|
+
setAssetContentType(res, ext);
|
|
1665
|
+
const isDevelopmentAsset = nodeEnv !== "production";
|
|
1666
|
+
const isVersionedClientAsset = import_node_path3.default.basename(filePath) === "client.js" && url.searchParams.has("v");
|
|
1667
|
+
const canCacheLongTerm = !isDevelopmentAsset && (isHashedAssetPath(filePath) || isVersionedClientAsset);
|
|
1668
|
+
res.setHeader(
|
|
1669
|
+
"Cache-Control",
|
|
1670
|
+
canCacheLongTerm ? "public, max-age=31536000, immutable" : "no-store, no-cache, must-revalidate, proxy-revalidate"
|
|
1671
|
+
);
|
|
1672
|
+
res.setHeader("Vary", "Accept-Encoding");
|
|
1673
|
+
const contentEncoding = !isDevelopmentAsset ? getPreferredContentEncoding(req, ext, stat.size) : "";
|
|
1520
1674
|
const stream = import_node_fs2.default.createReadStream(filePath);
|
|
1521
1675
|
stream.on("error", () => {
|
|
1522
|
-
res.
|
|
1676
|
+
if (!res.headersSent) {
|
|
1677
|
+
res.statusCode = 404;
|
|
1678
|
+
}
|
|
1523
1679
|
res.end("Not found");
|
|
1524
1680
|
});
|
|
1525
|
-
|
|
1681
|
+
if (contentEncoding === "br") {
|
|
1682
|
+
res.setHeader("Content-Encoding", "br");
|
|
1683
|
+
stream.pipe((0, import_node_zlib.createBrotliCompress)()).pipe(res);
|
|
1684
|
+
} else if (contentEncoding === "gzip") {
|
|
1685
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
1686
|
+
stream.pipe((0, import_node_zlib.createGzip)()).pipe(res);
|
|
1687
|
+
} else {
|
|
1688
|
+
stream.pipe(res);
|
|
1689
|
+
}
|
|
1526
1690
|
return;
|
|
1527
1691
|
}
|
|
1528
1692
|
const resolved = await withRequestBasename(
|
|
@@ -1540,22 +1704,23 @@ function createNodeRequestHandler(options) {
|
|
|
1540
1704
|
);
|
|
1541
1705
|
const initialPayload = {
|
|
1542
1706
|
model: resolved.model,
|
|
1543
|
-
contextModel: resolved.contextModel,
|
|
1544
|
-
pageModel: resolved.pageModel,
|
|
1545
1707
|
head: resolved.head
|
|
1546
1708
|
};
|
|
1547
1709
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
1548
1710
|
moduleMap
|
|
1549
1711
|
});
|
|
1550
1712
|
const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1551
|
-
const shellClientScriptUrl =
|
|
1552
|
-
|
|
1553
|
-
|
|
1713
|
+
const shellClientScriptUrl = appendAssetVersion(
|
|
1714
|
+
joinRuntimeAssetPath(
|
|
1715
|
+
transportBasePath,
|
|
1716
|
+
clientScriptUrl
|
|
1717
|
+
),
|
|
1718
|
+
createClientAssetVersion(distRootDir)
|
|
1554
1719
|
);
|
|
1555
1720
|
const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
|
|
1556
1721
|
const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1557
1722
|
const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
|
|
1558
|
-
let rootHtml
|
|
1723
|
+
let rootHtml;
|
|
1559
1724
|
try {
|
|
1560
1725
|
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1561
1726
|
flightData: initialFlightData,
|
|
@@ -1579,29 +1744,23 @@ function createNodeRequestHandler(options) {
|
|
|
1579
1744
|
});
|
|
1580
1745
|
} catch (flightRenderError) {
|
|
1581
1746
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
initialFlightData,
|
|
1592
|
-
basename: shellBasename,
|
|
1593
|
-
routeBasePath: shellRouteBasePath,
|
|
1594
|
-
liveReloadPath: liveReloadPath || void 0,
|
|
1595
|
-
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1596
|
-
})
|
|
1747
|
+
sendTextResponse(
|
|
1748
|
+
req,
|
|
1749
|
+
res,
|
|
1750
|
+
createInitialHtmlErrorMarkup("Failed to render initial React HTML."),
|
|
1751
|
+
{
|
|
1752
|
+
statusCode: 500,
|
|
1753
|
+
contentType: "text/html; charset=utf-8",
|
|
1754
|
+
compress: nodeEnv === "production"
|
|
1755
|
+
}
|
|
1597
1756
|
);
|
|
1598
1757
|
return;
|
|
1599
1758
|
}
|
|
1600
1759
|
}
|
|
1601
1760
|
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1761
|
+
sendTextResponse(
|
|
1762
|
+
req,
|
|
1763
|
+
res,
|
|
1605
1764
|
createHTMLShell({
|
|
1606
1765
|
title: resolved.head.title || "Webframez React",
|
|
1607
1766
|
headTags: renderHeadToString(resolved.head),
|
|
@@ -1613,14 +1772,21 @@ function createNodeRequestHandler(options) {
|
|
|
1613
1772
|
routeBasePath: shellRouteBasePath,
|
|
1614
1773
|
liveReloadPath: liveReloadPath || void 0,
|
|
1615
1774
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1616
|
-
})
|
|
1775
|
+
}),
|
|
1776
|
+
{
|
|
1777
|
+
statusCode: resolved.statusCode,
|
|
1778
|
+
contentType: "text/html; charset=utf-8",
|
|
1779
|
+
cacheControl: "no-store, no-cache, must-revalidate, proxy-revalidate",
|
|
1780
|
+
compress: nodeEnv === "production"
|
|
1781
|
+
}
|
|
1617
1782
|
);
|
|
1618
1783
|
};
|
|
1619
1784
|
}
|
|
1620
1785
|
|
|
1621
1786
|
// src/webframez-core.ts
|
|
1622
|
-
|
|
1623
|
-
|
|
1787
|
+
var import_node_path4 = __toESM(require("node:path"), 1);
|
|
1788
|
+
function normalizeMountPath(path5) {
|
|
1789
|
+
const trimmed = (path5 || "").trim();
|
|
1624
1790
|
let normalized = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
1625
1791
|
if (normalized.endsWith("/**")) {
|
|
1626
1792
|
normalized = normalized.slice(0, -3);
|
|
@@ -1632,12 +1798,57 @@ function normalizeMountPath(path4) {
|
|
|
1632
1798
|
}
|
|
1633
1799
|
return normalized || "/";
|
|
1634
1800
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1801
|
+
var REGISTRY_KEY = "__WEBFRAMEZ_REACT_BUILD_TARGETS__";
|
|
1802
|
+
function getBuildTargetsRegistry() {
|
|
1803
|
+
const globalWithRegistry = globalThis;
|
|
1804
|
+
if (!globalWithRegistry[REGISTRY_KEY]) {
|
|
1805
|
+
globalWithRegistry[REGISTRY_KEY] = [];
|
|
1806
|
+
}
|
|
1807
|
+
return globalWithRegistry[REGISTRY_KEY];
|
|
1808
|
+
}
|
|
1809
|
+
function toRouteKey(mountPath) {
|
|
1810
|
+
const trimmed = mountPath.replace(/^\/+|\/+$/g, "");
|
|
1811
|
+
return trimmed || "root";
|
|
1812
|
+
}
|
|
1813
|
+
function toPascalCase(value) {
|
|
1814
|
+
return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
1815
|
+
}
|
|
1816
|
+
function getOutputRoot() {
|
|
1817
|
+
const configured = process.env.WEBFRAMEZ_REACT_OUT_DIR;
|
|
1818
|
+
if (configured) {
|
|
1819
|
+
return import_node_path4.default.resolve(process.cwd(), configured);
|
|
1820
|
+
}
|
|
1821
|
+
const isTsNodeRuntime = process.execArgv.some((arg) => arg.includes("ts-node/register")) || process.env.TS_NODE_FILES === "true" || typeof require !== "undefined" && typeof require.extensions[".ts"] === "function";
|
|
1822
|
+
if (isTsNodeRuntime && import_node_path4.default.basename(process.cwd()) !== "build") {
|
|
1823
|
+
return import_node_path4.default.resolve(process.cwd(), "build");
|
|
1824
|
+
}
|
|
1825
|
+
return process.cwd();
|
|
1826
|
+
}
|
|
1827
|
+
function resolveFromProjectRoot(value) {
|
|
1828
|
+
return import_node_path4.default.resolve(process.cwd(), value);
|
|
1829
|
+
}
|
|
1830
|
+
function resolveFromOutputRoot(value) {
|
|
1831
|
+
return import_node_path4.default.resolve(getOutputRoot(), value);
|
|
1832
|
+
}
|
|
1833
|
+
function buildRenderDefaults(routePathValue) {
|
|
1834
|
+
const mountPath = normalizeMountPath(routePathValue);
|
|
1835
|
+
const routeKey = toRouteKey(mountPath);
|
|
1836
|
+
const routeDirName = toPascalCase(routeKey) || routeKey;
|
|
1637
1837
|
const routePath = mountPath === "/" ? "/*" : `${mountPath}/*`;
|
|
1838
|
+
const srcPath = import_node_path4.default.join("app", routeDirName, "react");
|
|
1839
|
+
const pagesDir = srcPath;
|
|
1840
|
+
const distRootDir = import_node_path4.default.join("webframez-react", routeKey);
|
|
1841
|
+
const styleSrcPath = import_node_path4.default.join("app", routeDirName, "assets", "scss");
|
|
1638
1842
|
if (mountPath === "/") {
|
|
1639
1843
|
return {
|
|
1844
|
+
path: mountPath,
|
|
1640
1845
|
routePath,
|
|
1846
|
+
routeKey,
|
|
1847
|
+
srcPath: resolveFromProjectRoot(srcPath),
|
|
1848
|
+
distRootDir: resolveFromOutputRoot(distRootDir),
|
|
1849
|
+
pagesDir: resolveFromOutputRoot(pagesDir),
|
|
1850
|
+
manifestPath: resolveFromOutputRoot(import_node_path4.default.join(distRootDir, "react-client-manifest.json")),
|
|
1851
|
+
styleSrcPath: resolveFromProjectRoot(styleSrcPath),
|
|
1641
1852
|
basePath: void 0,
|
|
1642
1853
|
assetsPrefix: void 0,
|
|
1643
1854
|
rscPath: void 0,
|
|
@@ -1645,7 +1856,14 @@ function buildRenderDefaults(path4) {
|
|
|
1645
1856
|
};
|
|
1646
1857
|
}
|
|
1647
1858
|
return {
|
|
1859
|
+
path: mountPath,
|
|
1648
1860
|
routePath,
|
|
1861
|
+
routeKey,
|
|
1862
|
+
srcPath: resolveFromProjectRoot(srcPath),
|
|
1863
|
+
distRootDir: resolveFromOutputRoot(distRootDir),
|
|
1864
|
+
pagesDir: resolveFromOutputRoot(pagesDir),
|
|
1865
|
+
manifestPath: resolveFromOutputRoot(import_node_path4.default.join(distRootDir, "react-client-manifest.json")),
|
|
1866
|
+
styleSrcPath: resolveFromProjectRoot(styleSrcPath),
|
|
1649
1867
|
basePath: mountPath,
|
|
1650
1868
|
assetsPrefix: `${mountPath}/assets/`,
|
|
1651
1869
|
rscPath: `${mountPath}/rsc`,
|
|
@@ -1685,41 +1903,66 @@ function normalizeMethods(method) {
|
|
|
1685
1903
|
}
|
|
1686
1904
|
return Array.isArray(method) ? method : [method];
|
|
1687
1905
|
}
|
|
1688
|
-
function registerByMethod(route, method,
|
|
1906
|
+
function registerByMethod(route, method, path5, component, routeOptions) {
|
|
1689
1907
|
if (method === "GET") {
|
|
1690
|
-
route.get(
|
|
1908
|
+
route.get(path5, component, routeOptions);
|
|
1691
1909
|
return;
|
|
1692
1910
|
}
|
|
1693
1911
|
if (method === "POST") {
|
|
1694
|
-
route.post(
|
|
1912
|
+
route.post(path5, component, routeOptions);
|
|
1695
1913
|
return;
|
|
1696
1914
|
}
|
|
1697
1915
|
if (method === "PUT") {
|
|
1698
|
-
route.put(
|
|
1916
|
+
route.put(path5, component, routeOptions);
|
|
1699
1917
|
return;
|
|
1700
1918
|
}
|
|
1701
|
-
route.delete(
|
|
1919
|
+
route.delete(path5, component, routeOptions);
|
|
1702
1920
|
}
|
|
1703
1921
|
function registerRouteRenderer(route, methodName) {
|
|
1704
1922
|
route.extend(methodName, () => {
|
|
1705
|
-
return (
|
|
1706
|
-
|
|
1707
|
-
throw new Error(
|
|
1708
|
-
`Route.${methodName} requires at least { distRootDir }`
|
|
1709
|
-
);
|
|
1710
|
-
}
|
|
1711
|
-
const defaults = buildRenderDefaults(path4);
|
|
1923
|
+
return (routePathValue, options = {}) => {
|
|
1924
|
+
const defaults = buildRenderDefaults(routePathValue);
|
|
1712
1925
|
const {
|
|
1713
1926
|
method,
|
|
1714
1927
|
routeOptions,
|
|
1928
|
+
srcPath,
|
|
1929
|
+
distRootDir,
|
|
1930
|
+
pagesDir,
|
|
1931
|
+
manifestPath,
|
|
1715
1932
|
basePath,
|
|
1716
1933
|
assetsPrefix,
|
|
1717
1934
|
rscPath,
|
|
1718
1935
|
clientScriptUrl,
|
|
1936
|
+
clientEntryPath,
|
|
1937
|
+
styleSrcPath,
|
|
1719
1938
|
...nodeHandlerOptions
|
|
1720
1939
|
} = options;
|
|
1940
|
+
const resolvedDistRootDir = distRootDir ?? defaults.distRootDir;
|
|
1941
|
+
const resolvedPagesDir = pagesDir ?? defaults.pagesDir;
|
|
1942
|
+
const resolvedManifestPath = manifestPath ?? import_node_path4.default.join(resolvedDistRootDir, "react-client-manifest.json");
|
|
1943
|
+
const resolvedTarget = {
|
|
1944
|
+
path: defaults.path,
|
|
1945
|
+
routePath: defaults.routePath,
|
|
1946
|
+
routeKey: defaults.routeKey,
|
|
1947
|
+
srcPath: srcPath ? resolveFromProjectRoot(srcPath) : defaults.srcPath,
|
|
1948
|
+
distRootDir: resolvedDistRootDir,
|
|
1949
|
+
pagesDir: resolvedPagesDir,
|
|
1950
|
+
manifestPath: resolvedManifestPath,
|
|
1951
|
+
assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
|
|
1952
|
+
rscPath: rscPath ?? defaults.rscPath,
|
|
1953
|
+
clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl,
|
|
1954
|
+
clientEntryPath: clientEntryPath ? resolveFromProjectRoot(clientEntryPath) : void 0,
|
|
1955
|
+
styleSrcPath: styleSrcPath ? resolveFromProjectRoot(styleSrcPath) : defaults.styleSrcPath
|
|
1956
|
+
};
|
|
1957
|
+
getBuildTargetsRegistry().push(resolvedTarget);
|
|
1958
|
+
if (process.env.WEBFRAMEZ_REACT_CAPTURE_ROUTES === "1") {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1721
1961
|
const handleNodeRequest = createNodeRequestHandler({
|
|
1722
1962
|
...nodeHandlerOptions,
|
|
1963
|
+
distRootDir: resolvedTarget.distRootDir,
|
|
1964
|
+
pagesDir: resolvedTarget.pagesDir,
|
|
1965
|
+
manifestPath: resolvedTarget.manifestPath,
|
|
1723
1966
|
basePath: basePath ?? defaults.basePath,
|
|
1724
1967
|
assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
|
|
1725
1968
|
rscPath: rscPath ?? defaults.rscPath,
|
|
@@ -1746,6 +1989,34 @@ function registerRouteRenderer(route, methodName) {
|
|
|
1746
1989
|
};
|
|
1747
1990
|
});
|
|
1748
1991
|
}
|
|
1992
|
+
function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
|
|
1993
|
+
const defaults = buildRenderDefaults(routePathValue);
|
|
1994
|
+
const distRootDir = options.distRootDir ?? defaults.distRootDir;
|
|
1995
|
+
const pagesDir = options.pagesDir ?? defaults.pagesDir;
|
|
1996
|
+
const manifestPath = options.manifestPath ?? import_node_path4.default.join(distRootDir, "react-client-manifest.json");
|
|
1997
|
+
return {
|
|
1998
|
+
path: defaults.path,
|
|
1999
|
+
routePath: defaults.routePath,
|
|
2000
|
+
routeKey: defaults.routeKey,
|
|
2001
|
+
srcPath: options.srcPath ? resolveFromProjectRoot(options.srcPath) : defaults.srcPath,
|
|
2002
|
+
distRootDir,
|
|
2003
|
+
pagesDir,
|
|
2004
|
+
manifestPath,
|
|
2005
|
+
assetsPrefix: options.assetsPrefix ?? defaults.assetsPrefix,
|
|
2006
|
+
rscPath: options.rscPath ?? defaults.rscPath,
|
|
2007
|
+
clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
|
|
2008
|
+
clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
|
|
2009
|
+
styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
|
|
2010
|
+
basePath: options.basePath ?? defaults.basePath,
|
|
2011
|
+
liveReloadPath: options.liveReloadPath
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
function getRegisteredReactBuildTargets() {
|
|
2015
|
+
return [...getBuildTargetsRegistry()];
|
|
2016
|
+
}
|
|
2017
|
+
function clearRegisteredReactBuildTargets() {
|
|
2018
|
+
getBuildTargetsRegistry().length = 0;
|
|
2019
|
+
}
|
|
1749
2020
|
function initWebframezReact(route) {
|
|
1750
2021
|
if (!route || typeof route.extend !== "function") {
|
|
1751
2022
|
throw new Error(
|
|
@@ -1764,13 +2035,16 @@ var setupWebframezCoreReactRoute = initWebframezReact;
|
|
|
1764
2035
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1765
2036
|
0 && (module.exports = {
|
|
1766
2037
|
RouteChildren,
|
|
2038
|
+
clearRegisteredReactBuildTargets,
|
|
1767
2039
|
createFileRouter,
|
|
1768
2040
|
createHTMLShell,
|
|
1769
2041
|
createNodeRequestHandler,
|
|
1770
2042
|
createRSCHandler,
|
|
2043
|
+
getRegisteredReactBuildTargets,
|
|
1771
2044
|
initWebframezReact,
|
|
1772
2045
|
parseSearchParams,
|
|
1773
2046
|
renderHeadToString,
|
|
2047
|
+
resolveWebframezReactRouteOptions,
|
|
1774
2048
|
sendRSC,
|
|
1775
2049
|
setupWebframezCoreReactRoute
|
|
1776
2050
|
});
|