@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.js
CHANGED
|
@@ -790,10 +790,86 @@ import fs2 from "node:fs";
|
|
|
790
790
|
import path3 from "node:path";
|
|
791
791
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
792
792
|
import { spawn } from "node:child_process";
|
|
793
|
+
import {
|
|
794
|
+
brotliCompressSync,
|
|
795
|
+
createBrotliCompress,
|
|
796
|
+
createGzip,
|
|
797
|
+
gzipSync
|
|
798
|
+
} from "node:zlib";
|
|
793
799
|
function createInitialHtmlErrorMarkup(message) {
|
|
794
800
|
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>`;
|
|
795
801
|
}
|
|
802
|
+
function createClientAssetVersion(distRootDir) {
|
|
803
|
+
try {
|
|
804
|
+
const stat = fs2.statSync(path3.join(distRootDir, "client.js"));
|
|
805
|
+
return `${Math.floor(stat.mtimeMs)}-${stat.size}`;
|
|
806
|
+
} catch {
|
|
807
|
+
return "";
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function appendAssetVersion(url, version) {
|
|
811
|
+
if (!version) {
|
|
812
|
+
return url;
|
|
813
|
+
}
|
|
814
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
815
|
+
return `${url}${separator}v=${encodeURIComponent(version)}`;
|
|
816
|
+
}
|
|
817
|
+
function isWithinDirectory(filePath, directory) {
|
|
818
|
+
return filePath === directory || filePath.startsWith(`${directory}${path3.sep}`);
|
|
819
|
+
}
|
|
820
|
+
function isCompressibleAsset(ext) {
|
|
821
|
+
return [".js", ".mjs", ".json", ".css", ".svg", ".txt", ".html"].includes(ext);
|
|
822
|
+
}
|
|
823
|
+
function isHashedAssetPath(filePath) {
|
|
824
|
+
return /-[a-f0-9]{12,}\.[cm]?js$/i.test(path3.basename(filePath));
|
|
825
|
+
}
|
|
826
|
+
function setAssetContentType(res, ext) {
|
|
827
|
+
if (ext === ".js" || ext === ".mjs") {
|
|
828
|
+
res.setHeader("Content-Type", "text/javascript; charset=utf-8");
|
|
829
|
+
} else if (ext === ".json") {
|
|
830
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
831
|
+
} else if (ext === ".css") {
|
|
832
|
+
res.setHeader("Content-Type", "text/css; charset=utf-8");
|
|
833
|
+
} else if (ext === ".svg") {
|
|
834
|
+
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function getPreferredContentEncoding(req, ext, fileSize) {
|
|
838
|
+
if (!isCompressibleAsset(ext) || fileSize < 1024) {
|
|
839
|
+
return "";
|
|
840
|
+
}
|
|
841
|
+
const acceptEncoding = String(req.headers["accept-encoding"] || "");
|
|
842
|
+
if (/\bbr\b/.test(acceptEncoding)) {
|
|
843
|
+
return "br";
|
|
844
|
+
}
|
|
845
|
+
if (/\bgzip\b/.test(acceptEncoding)) {
|
|
846
|
+
return "gzip";
|
|
847
|
+
}
|
|
848
|
+
return "";
|
|
849
|
+
}
|
|
850
|
+
function sendTextResponse(req, res, body, options) {
|
|
851
|
+
const bodyBuffer = Buffer.from(body);
|
|
852
|
+
const contentEncoding = options.compress === false ? "" : getPreferredContentEncoding(req, ".html", bodyBuffer.length);
|
|
853
|
+
res.statusCode = options.statusCode ?? 200;
|
|
854
|
+
res.setHeader("Content-Type", options.contentType);
|
|
855
|
+
if (options.cacheControl) {
|
|
856
|
+
res.setHeader("Cache-Control", options.cacheControl);
|
|
857
|
+
}
|
|
858
|
+
res.setHeader("Vary", "Accept-Encoding");
|
|
859
|
+
if (contentEncoding === "br") {
|
|
860
|
+
res.setHeader("Content-Encoding", "br");
|
|
861
|
+
res.end(brotliCompressSync(bodyBuffer));
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (contentEncoding === "gzip") {
|
|
865
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
866
|
+
res.end(gzipSync(bodyBuffer));
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
res.end(bodyBuffer);
|
|
870
|
+
}
|
|
796
871
|
var INITIAL_HTML_WORKER_SCRIPT = `
|
|
872
|
+
const fs = require("node:fs");
|
|
797
873
|
const path = require("node:path");
|
|
798
874
|
const Module = require("node:module");
|
|
799
875
|
const { Readable, Writable } = require("node:stream");
|
|
@@ -843,11 +919,42 @@ const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node
|
|
|
843
919
|
globalThis.__webpack_chunk_load__ = function __webframezNoopChunkLoad() {
|
|
844
920
|
return Promise.resolve();
|
|
845
921
|
};
|
|
922
|
+
function normalizeWebframezRequireCandidate(candidate) {
|
|
923
|
+
const stagingMarker = path.join(".webframez-build", "");
|
|
924
|
+
const appMarker = path.join("app", "");
|
|
925
|
+
const stagingIndex = candidate.indexOf(stagingMarker);
|
|
926
|
+
const appIndex = candidate.indexOf(appMarker, stagingIndex >= 0 ? stagingIndex : 0);
|
|
927
|
+
if (stagingIndex >= 0 && appIndex >= 0) {
|
|
928
|
+
const runtimeCandidate = path.resolve(process.cwd(), candidate.slice(appIndex));
|
|
929
|
+
if (fs.existsSync(runtimeCandidate)) {
|
|
930
|
+
return runtimeCandidate;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const frameworkDistDir = path.join("node_modules", "@webtypen", "webframez-react", "dist");
|
|
935
|
+
const shouldUseCjs =
|
|
936
|
+
candidate.includes(frameworkDistDir) &&
|
|
937
|
+
(candidate.endsWith(path.join("dist", "navigation.js")) ||
|
|
938
|
+
candidate.endsWith(path.join("dist", "route-slot.js")));
|
|
939
|
+
|
|
940
|
+
if (!shouldUseCjs) {
|
|
941
|
+
return candidate;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
const cjsCandidate = candidate.slice(0, -3) + ".cjs";
|
|
945
|
+
return fs.existsSync(cjsCandidate) ? cjsCandidate : candidate;
|
|
946
|
+
}
|
|
947
|
+
|
|
846
948
|
globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
|
|
847
949
|
if (typeof id !== "string") {
|
|
848
950
|
return require(id);
|
|
849
951
|
}
|
|
850
952
|
|
|
953
|
+
const directRequireTarget = normalizeWebframezRequireCandidate(id);
|
|
954
|
+
if (directRequireTarget !== id) {
|
|
955
|
+
return require(directRequireTarget);
|
|
956
|
+
}
|
|
957
|
+
|
|
851
958
|
if (id.startsWith("./")) {
|
|
852
959
|
const relativeId = id.slice(2);
|
|
853
960
|
const candidates = [
|
|
@@ -855,10 +962,16 @@ globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
|
|
|
855
962
|
path.resolve(process.cwd(), "..", relativeId)
|
|
856
963
|
];
|
|
857
964
|
for (const candidate of candidates) {
|
|
965
|
+
const requireTarget = normalizeWebframezRequireCandidate(candidate);
|
|
858
966
|
try {
|
|
859
|
-
return require(
|
|
967
|
+
return require(requireTarget);
|
|
860
968
|
} catch (error) {
|
|
861
|
-
const missingCandidate =
|
|
969
|
+
const missingCandidate =
|
|
970
|
+
error &&
|
|
971
|
+
error.code === "MODULE_NOT_FOUND" &&
|
|
972
|
+
typeof error.message === "string" &&
|
|
973
|
+
(error.message.includes("'" + candidate + "'") ||
|
|
974
|
+
error.message.includes("'" + requireTarget + "'"));
|
|
862
975
|
if (!missingCandidate) {
|
|
863
976
|
throw error;
|
|
864
977
|
}
|
|
@@ -1080,6 +1193,14 @@ function joinRuntimeBasePath(basePath, pathname) {
|
|
|
1080
1193
|
}
|
|
1081
1194
|
return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
|
|
1082
1195
|
}
|
|
1196
|
+
function joinRuntimeAssetPath(basePath, pathname) {
|
|
1197
|
+
const normalizedBasePath = normalizeRuntimeBasePath(basePath) ?? "";
|
|
1198
|
+
const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
1199
|
+
if (normalizedBasePath && (normalizedPath === normalizedBasePath || normalizedPath.startsWith(`${normalizedBasePath}/`))) {
|
|
1200
|
+
return normalizedPath;
|
|
1201
|
+
}
|
|
1202
|
+
return joinRuntimeBasePath(normalizedBasePath, normalizedPath);
|
|
1203
|
+
}
|
|
1083
1204
|
function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
1084
1205
|
if (!rawNodeOptions || rawNodeOptions.trim() === "") {
|
|
1085
1206
|
return "";
|
|
@@ -1274,6 +1395,18 @@ function createServerConsumerManifest(manifest) {
|
|
|
1274
1395
|
const consumerManifest = {};
|
|
1275
1396
|
const normalizeWorkerModuleId = (requestKey, rawModuleId) => {
|
|
1276
1397
|
if (typeof rawModuleId === "string" && rawModuleId.trim() !== "") {
|
|
1398
|
+
const isStagingModuleId = rawModuleId.startsWith("./.webframez-build/") || rawModuleId.includes(`${path3.sep}.webframez-build${path3.sep}`);
|
|
1399
|
+
const isRuntimeBuildKey = requestKey.startsWith("file://") || requestKey.startsWith("/") && requestKey.includes(`${path3.sep}build${path3.sep}app${path3.sep}`);
|
|
1400
|
+
if (isStagingModuleId && isRuntimeBuildKey) {
|
|
1401
|
+
if (requestKey.startsWith("file://")) {
|
|
1402
|
+
try {
|
|
1403
|
+
return fileURLToPath(requestKey);
|
|
1404
|
+
} catch {
|
|
1405
|
+
return rawModuleId;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
return requestKey;
|
|
1409
|
+
}
|
|
1277
1410
|
return rawModuleId;
|
|
1278
1411
|
}
|
|
1279
1412
|
if (typeof rawModuleId !== "number" || !Number.isFinite(rawModuleId)) {
|
|
@@ -1355,6 +1488,14 @@ function createServerConsumerManifest(manifest) {
|
|
|
1355
1488
|
name: exportName
|
|
1356
1489
|
});
|
|
1357
1490
|
}
|
|
1491
|
+
} else if (typeof entry.id === "string" && entry.id.trim() !== "") {
|
|
1492
|
+
addReference(entry.id, "*", reference);
|
|
1493
|
+
for (const exportName of exportNames) {
|
|
1494
|
+
addReference(entry.id, exportName, {
|
|
1495
|
+
...reference,
|
|
1496
|
+
name: exportName
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1358
1499
|
}
|
|
1359
1500
|
}
|
|
1360
1501
|
return consumerManifest;
|
|
@@ -1469,24 +1610,49 @@ function createNodeRequestHandler(options) {
|
|
|
1469
1610
|
if (url.pathname.startsWith(assetsPrefix)) {
|
|
1470
1611
|
const relative = url.pathname.slice(assetsPrefix.length);
|
|
1471
1612
|
const filePath = path3.resolve(distRootDir, relative);
|
|
1472
|
-
if (!filePath
|
|
1613
|
+
if (!isWithinDirectory(filePath, distRootDir)) {
|
|
1473
1614
|
res.statusCode = 400;
|
|
1474
1615
|
res.end("Invalid path");
|
|
1475
1616
|
return;
|
|
1476
1617
|
}
|
|
1477
1618
|
const ext = path3.extname(filePath);
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1619
|
+
let stat;
|
|
1620
|
+
try {
|
|
1621
|
+
stat = fs2.statSync(filePath);
|
|
1622
|
+
if (!stat.isFile()) {
|
|
1623
|
+
throw new Error("Asset path is not a file");
|
|
1624
|
+
}
|
|
1625
|
+
} catch {
|
|
1626
|
+
res.statusCode = 404;
|
|
1627
|
+
res.end("Not found");
|
|
1628
|
+
return;
|
|
1482
1629
|
}
|
|
1483
|
-
res
|
|
1630
|
+
setAssetContentType(res, ext);
|
|
1631
|
+
const isDevelopmentAsset = nodeEnv !== "production";
|
|
1632
|
+
const isVersionedClientAsset = path3.basename(filePath) === "client.js" && url.searchParams.has("v");
|
|
1633
|
+
const canCacheLongTerm = !isDevelopmentAsset && (isHashedAssetPath(filePath) || isVersionedClientAsset);
|
|
1634
|
+
res.setHeader(
|
|
1635
|
+
"Cache-Control",
|
|
1636
|
+
canCacheLongTerm ? "public, max-age=31536000, immutable" : "no-store, no-cache, must-revalidate, proxy-revalidate"
|
|
1637
|
+
);
|
|
1638
|
+
res.setHeader("Vary", "Accept-Encoding");
|
|
1639
|
+
const contentEncoding = !isDevelopmentAsset ? getPreferredContentEncoding(req, ext, stat.size) : "";
|
|
1484
1640
|
const stream = fs2.createReadStream(filePath);
|
|
1485
1641
|
stream.on("error", () => {
|
|
1486
|
-
res.
|
|
1642
|
+
if (!res.headersSent) {
|
|
1643
|
+
res.statusCode = 404;
|
|
1644
|
+
}
|
|
1487
1645
|
res.end("Not found");
|
|
1488
1646
|
});
|
|
1489
|
-
|
|
1647
|
+
if (contentEncoding === "br") {
|
|
1648
|
+
res.setHeader("Content-Encoding", "br");
|
|
1649
|
+
stream.pipe(createBrotliCompress()).pipe(res);
|
|
1650
|
+
} else if (contentEncoding === "gzip") {
|
|
1651
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
1652
|
+
stream.pipe(createGzip()).pipe(res);
|
|
1653
|
+
} else {
|
|
1654
|
+
stream.pipe(res);
|
|
1655
|
+
}
|
|
1490
1656
|
return;
|
|
1491
1657
|
}
|
|
1492
1658
|
const resolved = await withRequestBasename(
|
|
@@ -1504,22 +1670,23 @@ function createNodeRequestHandler(options) {
|
|
|
1504
1670
|
);
|
|
1505
1671
|
const initialPayload = {
|
|
1506
1672
|
model: resolved.model,
|
|
1507
|
-
contextModel: resolved.contextModel,
|
|
1508
|
-
pageModel: resolved.pageModel,
|
|
1509
1673
|
head: resolved.head
|
|
1510
1674
|
};
|
|
1511
1675
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
1512
1676
|
moduleMap
|
|
1513
1677
|
});
|
|
1514
1678
|
const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1515
|
-
const shellClientScriptUrl =
|
|
1516
|
-
|
|
1517
|
-
|
|
1679
|
+
const shellClientScriptUrl = appendAssetVersion(
|
|
1680
|
+
joinRuntimeAssetPath(
|
|
1681
|
+
transportBasePath,
|
|
1682
|
+
clientScriptUrl
|
|
1683
|
+
),
|
|
1684
|
+
createClientAssetVersion(distRootDir)
|
|
1518
1685
|
);
|
|
1519
1686
|
const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
|
|
1520
1687
|
const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1521
1688
|
const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
|
|
1522
|
-
let rootHtml
|
|
1689
|
+
let rootHtml;
|
|
1523
1690
|
try {
|
|
1524
1691
|
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
1525
1692
|
flightData: initialFlightData,
|
|
@@ -1543,29 +1710,23 @@ function createNodeRequestHandler(options) {
|
|
|
1543
1710
|
});
|
|
1544
1711
|
} catch (flightRenderError) {
|
|
1545
1712
|
console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
initialFlightData,
|
|
1556
|
-
basename: shellBasename,
|
|
1557
|
-
routeBasePath: shellRouteBasePath,
|
|
1558
|
-
liveReloadPath: liveReloadPath || void 0,
|
|
1559
|
-
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1560
|
-
})
|
|
1713
|
+
sendTextResponse(
|
|
1714
|
+
req,
|
|
1715
|
+
res,
|
|
1716
|
+
createInitialHtmlErrorMarkup("Failed to render initial React HTML."),
|
|
1717
|
+
{
|
|
1718
|
+
statusCode: 500,
|
|
1719
|
+
contentType: "text/html; charset=utf-8",
|
|
1720
|
+
compress: nodeEnv === "production"
|
|
1721
|
+
}
|
|
1561
1722
|
);
|
|
1562
1723
|
return;
|
|
1563
1724
|
}
|
|
1564
1725
|
}
|
|
1565
1726
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1727
|
+
sendTextResponse(
|
|
1728
|
+
req,
|
|
1729
|
+
res,
|
|
1569
1730
|
createHTMLShell({
|
|
1570
1731
|
title: resolved.head.title || "Webframez React",
|
|
1571
1732
|
headTags: renderHeadToString(resolved.head),
|
|
@@ -1577,14 +1738,21 @@ function createNodeRequestHandler(options) {
|
|
|
1577
1738
|
routeBasePath: shellRouteBasePath,
|
|
1578
1739
|
liveReloadPath: liveReloadPath || void 0,
|
|
1579
1740
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1580
|
-
})
|
|
1741
|
+
}),
|
|
1742
|
+
{
|
|
1743
|
+
statusCode: resolved.statusCode,
|
|
1744
|
+
contentType: "text/html; charset=utf-8",
|
|
1745
|
+
cacheControl: "no-store, no-cache, must-revalidate, proxy-revalidate",
|
|
1746
|
+
compress: nodeEnv === "production"
|
|
1747
|
+
}
|
|
1581
1748
|
);
|
|
1582
1749
|
};
|
|
1583
1750
|
}
|
|
1584
1751
|
|
|
1585
1752
|
// src/webframez-core.ts
|
|
1586
|
-
|
|
1587
|
-
|
|
1753
|
+
import path4 from "node:path";
|
|
1754
|
+
function normalizeMountPath(path5) {
|
|
1755
|
+
const trimmed = (path5 || "").trim();
|
|
1588
1756
|
let normalized = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
1589
1757
|
if (normalized.endsWith("/**")) {
|
|
1590
1758
|
normalized = normalized.slice(0, -3);
|
|
@@ -1596,12 +1764,57 @@ function normalizeMountPath(path4) {
|
|
|
1596
1764
|
}
|
|
1597
1765
|
return normalized || "/";
|
|
1598
1766
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1767
|
+
var REGISTRY_KEY = "__WEBFRAMEZ_REACT_BUILD_TARGETS__";
|
|
1768
|
+
function getBuildTargetsRegistry() {
|
|
1769
|
+
const globalWithRegistry = globalThis;
|
|
1770
|
+
if (!globalWithRegistry[REGISTRY_KEY]) {
|
|
1771
|
+
globalWithRegistry[REGISTRY_KEY] = [];
|
|
1772
|
+
}
|
|
1773
|
+
return globalWithRegistry[REGISTRY_KEY];
|
|
1774
|
+
}
|
|
1775
|
+
function toRouteKey(mountPath) {
|
|
1776
|
+
const trimmed = mountPath.replace(/^\/+|\/+$/g, "");
|
|
1777
|
+
return trimmed || "root";
|
|
1778
|
+
}
|
|
1779
|
+
function toPascalCase(value) {
|
|
1780
|
+
return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
1781
|
+
}
|
|
1782
|
+
function getOutputRoot() {
|
|
1783
|
+
const configured = process.env.WEBFRAMEZ_REACT_OUT_DIR;
|
|
1784
|
+
if (configured) {
|
|
1785
|
+
return path4.resolve(process.cwd(), configured);
|
|
1786
|
+
}
|
|
1787
|
+
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";
|
|
1788
|
+
if (isTsNodeRuntime && path4.basename(process.cwd()) !== "build") {
|
|
1789
|
+
return path4.resolve(process.cwd(), "build");
|
|
1790
|
+
}
|
|
1791
|
+
return process.cwd();
|
|
1792
|
+
}
|
|
1793
|
+
function resolveFromProjectRoot(value) {
|
|
1794
|
+
return path4.resolve(process.cwd(), value);
|
|
1795
|
+
}
|
|
1796
|
+
function resolveFromOutputRoot(value) {
|
|
1797
|
+
return path4.resolve(getOutputRoot(), value);
|
|
1798
|
+
}
|
|
1799
|
+
function buildRenderDefaults(routePathValue) {
|
|
1800
|
+
const mountPath = normalizeMountPath(routePathValue);
|
|
1801
|
+
const routeKey = toRouteKey(mountPath);
|
|
1802
|
+
const routeDirName = toPascalCase(routeKey) || routeKey;
|
|
1601
1803
|
const routePath = mountPath === "/" ? "/*" : `${mountPath}/*`;
|
|
1804
|
+
const srcPath = path4.join("app", routeDirName, "react");
|
|
1805
|
+
const pagesDir = srcPath;
|
|
1806
|
+
const distRootDir = path4.join("webframez-react", routeKey);
|
|
1807
|
+
const styleSrcPath = path4.join("app", routeDirName, "assets", "scss");
|
|
1602
1808
|
if (mountPath === "/") {
|
|
1603
1809
|
return {
|
|
1810
|
+
path: mountPath,
|
|
1604
1811
|
routePath,
|
|
1812
|
+
routeKey,
|
|
1813
|
+
srcPath: resolveFromProjectRoot(srcPath),
|
|
1814
|
+
distRootDir: resolveFromOutputRoot(distRootDir),
|
|
1815
|
+
pagesDir: resolveFromOutputRoot(pagesDir),
|
|
1816
|
+
manifestPath: resolveFromOutputRoot(path4.join(distRootDir, "react-client-manifest.json")),
|
|
1817
|
+
styleSrcPath: resolveFromProjectRoot(styleSrcPath),
|
|
1605
1818
|
basePath: void 0,
|
|
1606
1819
|
assetsPrefix: void 0,
|
|
1607
1820
|
rscPath: void 0,
|
|
@@ -1609,7 +1822,14 @@ function buildRenderDefaults(path4) {
|
|
|
1609
1822
|
};
|
|
1610
1823
|
}
|
|
1611
1824
|
return {
|
|
1825
|
+
path: mountPath,
|
|
1612
1826
|
routePath,
|
|
1827
|
+
routeKey,
|
|
1828
|
+
srcPath: resolveFromProjectRoot(srcPath),
|
|
1829
|
+
distRootDir: resolveFromOutputRoot(distRootDir),
|
|
1830
|
+
pagesDir: resolveFromOutputRoot(pagesDir),
|
|
1831
|
+
manifestPath: resolveFromOutputRoot(path4.join(distRootDir, "react-client-manifest.json")),
|
|
1832
|
+
styleSrcPath: resolveFromProjectRoot(styleSrcPath),
|
|
1613
1833
|
basePath: mountPath,
|
|
1614
1834
|
assetsPrefix: `${mountPath}/assets/`,
|
|
1615
1835
|
rscPath: `${mountPath}/rsc`,
|
|
@@ -1649,41 +1869,66 @@ function normalizeMethods(method) {
|
|
|
1649
1869
|
}
|
|
1650
1870
|
return Array.isArray(method) ? method : [method];
|
|
1651
1871
|
}
|
|
1652
|
-
function registerByMethod(route, method,
|
|
1872
|
+
function registerByMethod(route, method, path5, component, routeOptions) {
|
|
1653
1873
|
if (method === "GET") {
|
|
1654
|
-
route.get(
|
|
1874
|
+
route.get(path5, component, routeOptions);
|
|
1655
1875
|
return;
|
|
1656
1876
|
}
|
|
1657
1877
|
if (method === "POST") {
|
|
1658
|
-
route.post(
|
|
1878
|
+
route.post(path5, component, routeOptions);
|
|
1659
1879
|
return;
|
|
1660
1880
|
}
|
|
1661
1881
|
if (method === "PUT") {
|
|
1662
|
-
route.put(
|
|
1882
|
+
route.put(path5, component, routeOptions);
|
|
1663
1883
|
return;
|
|
1664
1884
|
}
|
|
1665
|
-
route.delete(
|
|
1885
|
+
route.delete(path5, component, routeOptions);
|
|
1666
1886
|
}
|
|
1667
1887
|
function registerRouteRenderer(route, methodName) {
|
|
1668
1888
|
route.extend(methodName, () => {
|
|
1669
|
-
return (
|
|
1670
|
-
|
|
1671
|
-
throw new Error(
|
|
1672
|
-
`Route.${methodName} requires at least { distRootDir }`
|
|
1673
|
-
);
|
|
1674
|
-
}
|
|
1675
|
-
const defaults = buildRenderDefaults(path4);
|
|
1889
|
+
return (routePathValue, options = {}) => {
|
|
1890
|
+
const defaults = buildRenderDefaults(routePathValue);
|
|
1676
1891
|
const {
|
|
1677
1892
|
method,
|
|
1678
1893
|
routeOptions,
|
|
1894
|
+
srcPath,
|
|
1895
|
+
distRootDir,
|
|
1896
|
+
pagesDir,
|
|
1897
|
+
manifestPath,
|
|
1679
1898
|
basePath,
|
|
1680
1899
|
assetsPrefix,
|
|
1681
1900
|
rscPath,
|
|
1682
1901
|
clientScriptUrl,
|
|
1902
|
+
clientEntryPath,
|
|
1903
|
+
styleSrcPath,
|
|
1683
1904
|
...nodeHandlerOptions
|
|
1684
1905
|
} = options;
|
|
1906
|
+
const resolvedDistRootDir = distRootDir ?? defaults.distRootDir;
|
|
1907
|
+
const resolvedPagesDir = pagesDir ?? defaults.pagesDir;
|
|
1908
|
+
const resolvedManifestPath = manifestPath ?? path4.join(resolvedDistRootDir, "react-client-manifest.json");
|
|
1909
|
+
const resolvedTarget = {
|
|
1910
|
+
path: defaults.path,
|
|
1911
|
+
routePath: defaults.routePath,
|
|
1912
|
+
routeKey: defaults.routeKey,
|
|
1913
|
+
srcPath: srcPath ? resolveFromProjectRoot(srcPath) : defaults.srcPath,
|
|
1914
|
+
distRootDir: resolvedDistRootDir,
|
|
1915
|
+
pagesDir: resolvedPagesDir,
|
|
1916
|
+
manifestPath: resolvedManifestPath,
|
|
1917
|
+
assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
|
|
1918
|
+
rscPath: rscPath ?? defaults.rscPath,
|
|
1919
|
+
clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl,
|
|
1920
|
+
clientEntryPath: clientEntryPath ? resolveFromProjectRoot(clientEntryPath) : void 0,
|
|
1921
|
+
styleSrcPath: styleSrcPath ? resolveFromProjectRoot(styleSrcPath) : defaults.styleSrcPath
|
|
1922
|
+
};
|
|
1923
|
+
getBuildTargetsRegistry().push(resolvedTarget);
|
|
1924
|
+
if (process.env.WEBFRAMEZ_REACT_CAPTURE_ROUTES === "1") {
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1685
1927
|
const handleNodeRequest = createNodeRequestHandler({
|
|
1686
1928
|
...nodeHandlerOptions,
|
|
1929
|
+
distRootDir: resolvedTarget.distRootDir,
|
|
1930
|
+
pagesDir: resolvedTarget.pagesDir,
|
|
1931
|
+
manifestPath: resolvedTarget.manifestPath,
|
|
1687
1932
|
basePath: basePath ?? defaults.basePath,
|
|
1688
1933
|
assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
|
|
1689
1934
|
rscPath: rscPath ?? defaults.rscPath,
|
|
@@ -1710,6 +1955,34 @@ function registerRouteRenderer(route, methodName) {
|
|
|
1710
1955
|
};
|
|
1711
1956
|
});
|
|
1712
1957
|
}
|
|
1958
|
+
function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
|
|
1959
|
+
const defaults = buildRenderDefaults(routePathValue);
|
|
1960
|
+
const distRootDir = options.distRootDir ?? defaults.distRootDir;
|
|
1961
|
+
const pagesDir = options.pagesDir ?? defaults.pagesDir;
|
|
1962
|
+
const manifestPath = options.manifestPath ?? path4.join(distRootDir, "react-client-manifest.json");
|
|
1963
|
+
return {
|
|
1964
|
+
path: defaults.path,
|
|
1965
|
+
routePath: defaults.routePath,
|
|
1966
|
+
routeKey: defaults.routeKey,
|
|
1967
|
+
srcPath: options.srcPath ? resolveFromProjectRoot(options.srcPath) : defaults.srcPath,
|
|
1968
|
+
distRootDir,
|
|
1969
|
+
pagesDir,
|
|
1970
|
+
manifestPath,
|
|
1971
|
+
assetsPrefix: options.assetsPrefix ?? defaults.assetsPrefix,
|
|
1972
|
+
rscPath: options.rscPath ?? defaults.rscPath,
|
|
1973
|
+
clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
|
|
1974
|
+
clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
|
|
1975
|
+
styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
|
|
1976
|
+
basePath: options.basePath ?? defaults.basePath,
|
|
1977
|
+
liveReloadPath: options.liveReloadPath
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
function getRegisteredReactBuildTargets() {
|
|
1981
|
+
return [...getBuildTargetsRegistry()];
|
|
1982
|
+
}
|
|
1983
|
+
function clearRegisteredReactBuildTargets() {
|
|
1984
|
+
getBuildTargetsRegistry().length = 0;
|
|
1985
|
+
}
|
|
1713
1986
|
function initWebframezReact(route) {
|
|
1714
1987
|
if (!route || typeof route.extend !== "function") {
|
|
1715
1988
|
throw new Error(
|
|
@@ -1727,13 +2000,16 @@ function initWebframezReact(route) {
|
|
|
1727
2000
|
var setupWebframezCoreReactRoute = initWebframezReact;
|
|
1728
2001
|
export {
|
|
1729
2002
|
RouteChildren,
|
|
2003
|
+
clearRegisteredReactBuildTargets,
|
|
1730
2004
|
createFileRouter,
|
|
1731
2005
|
createHTMLShell,
|
|
1732
2006
|
createNodeRequestHandler,
|
|
1733
2007
|
createRSCHandler,
|
|
2008
|
+
getRegisteredReactBuildTargets,
|
|
1734
2009
|
initWebframezReact,
|
|
1735
2010
|
parseSearchParams,
|
|
1736
2011
|
renderHeadToString,
|
|
2012
|
+
resolveWebframezReactRouteOptions,
|
|
1737
2013
|
sendRSC,
|
|
1738
2014
|
setupWebframezCoreReactRoute
|
|
1739
2015
|
};
|
package/dist/types.d.ts
CHANGED