@webtypen/webframez-react 0.0.34 → 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.
@@ -6,11 +6,20 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  throw Error('Dynamic require of "' + x + '" is not supported');
7
7
  });
8
8
 
9
+ // src/webframez-core.ts
10
+ import path4 from "node:path";
11
+
9
12
  // src/http.ts
10
13
  import fs2 from "node:fs";
11
14
  import path3 from "node:path";
12
15
  import { fileURLToPath, pathToFileURL } from "node:url";
13
16
  import { spawn } from "node:child_process";
17
+ import {
18
+ brotliCompressSync,
19
+ createBrotliCompress,
20
+ createGzip,
21
+ gzipSync
22
+ } from "node:zlib";
14
23
 
15
24
  // src/server.ts
16
25
  import path from "node:path";
@@ -767,7 +776,77 @@ function parseSearchParams(query) {
767
776
  function createInitialHtmlErrorMarkup(message) {
768
777
  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>`;
769
778
  }
779
+ function createClientAssetVersion(distRootDir) {
780
+ try {
781
+ const stat = fs2.statSync(path3.join(distRootDir, "client.js"));
782
+ return `${Math.floor(stat.mtimeMs)}-${stat.size}`;
783
+ } catch {
784
+ return "";
785
+ }
786
+ }
787
+ function appendAssetVersion(url, version) {
788
+ if (!version) {
789
+ return url;
790
+ }
791
+ const separator = url.includes("?") ? "&" : "?";
792
+ return `${url}${separator}v=${encodeURIComponent(version)}`;
793
+ }
794
+ function isWithinDirectory(filePath, directory) {
795
+ return filePath === directory || filePath.startsWith(`${directory}${path3.sep}`);
796
+ }
797
+ function isCompressibleAsset(ext) {
798
+ return [".js", ".mjs", ".json", ".css", ".svg", ".txt", ".html"].includes(ext);
799
+ }
800
+ function isHashedAssetPath(filePath) {
801
+ return /-[a-f0-9]{12,}\.[cm]?js$/i.test(path3.basename(filePath));
802
+ }
803
+ function setAssetContentType(res, ext) {
804
+ if (ext === ".js" || ext === ".mjs") {
805
+ res.setHeader("Content-Type", "text/javascript; charset=utf-8");
806
+ } else if (ext === ".json") {
807
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
808
+ } else if (ext === ".css") {
809
+ res.setHeader("Content-Type", "text/css; charset=utf-8");
810
+ } else if (ext === ".svg") {
811
+ res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
812
+ }
813
+ }
814
+ function getPreferredContentEncoding(req, ext, fileSize) {
815
+ if (!isCompressibleAsset(ext) || fileSize < 1024) {
816
+ return "";
817
+ }
818
+ const acceptEncoding = String(req.headers["accept-encoding"] || "");
819
+ if (/\bbr\b/.test(acceptEncoding)) {
820
+ return "br";
821
+ }
822
+ if (/\bgzip\b/.test(acceptEncoding)) {
823
+ return "gzip";
824
+ }
825
+ return "";
826
+ }
827
+ function sendTextResponse(req, res, body, options) {
828
+ const bodyBuffer = Buffer.from(body);
829
+ const contentEncoding = options.compress === false ? "" : getPreferredContentEncoding(req, ".html", bodyBuffer.length);
830
+ res.statusCode = options.statusCode ?? 200;
831
+ res.setHeader("Content-Type", options.contentType);
832
+ if (options.cacheControl) {
833
+ res.setHeader("Cache-Control", options.cacheControl);
834
+ }
835
+ res.setHeader("Vary", "Accept-Encoding");
836
+ if (contentEncoding === "br") {
837
+ res.setHeader("Content-Encoding", "br");
838
+ res.end(brotliCompressSync(bodyBuffer));
839
+ return;
840
+ }
841
+ if (contentEncoding === "gzip") {
842
+ res.setHeader("Content-Encoding", "gzip");
843
+ res.end(gzipSync(bodyBuffer));
844
+ return;
845
+ }
846
+ res.end(bodyBuffer);
847
+ }
770
848
  var INITIAL_HTML_WORKER_SCRIPT = `
849
+ const fs = require("node:fs");
771
850
  const path = require("node:path");
772
851
  const Module = require("node:module");
773
852
  const { Readable, Writable } = require("node:stream");
@@ -817,11 +896,42 @@ const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node
817
896
  globalThis.__webpack_chunk_load__ = function __webframezNoopChunkLoad() {
818
897
  return Promise.resolve();
819
898
  };
899
+ function normalizeWebframezRequireCandidate(candidate) {
900
+ const stagingMarker = path.join(".webframez-build", "");
901
+ const appMarker = path.join("app", "");
902
+ const stagingIndex = candidate.indexOf(stagingMarker);
903
+ const appIndex = candidate.indexOf(appMarker, stagingIndex >= 0 ? stagingIndex : 0);
904
+ if (stagingIndex >= 0 && appIndex >= 0) {
905
+ const runtimeCandidate = path.resolve(process.cwd(), candidate.slice(appIndex));
906
+ if (fs.existsSync(runtimeCandidate)) {
907
+ return runtimeCandidate;
908
+ }
909
+ }
910
+
911
+ const frameworkDistDir = path.join("node_modules", "@webtypen", "webframez-react", "dist");
912
+ const shouldUseCjs =
913
+ candidate.includes(frameworkDistDir) &&
914
+ (candidate.endsWith(path.join("dist", "navigation.js")) ||
915
+ candidate.endsWith(path.join("dist", "route-slot.js")));
916
+
917
+ if (!shouldUseCjs) {
918
+ return candidate;
919
+ }
920
+
921
+ const cjsCandidate = candidate.slice(0, -3) + ".cjs";
922
+ return fs.existsSync(cjsCandidate) ? cjsCandidate : candidate;
923
+ }
924
+
820
925
  globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
821
926
  if (typeof id !== "string") {
822
927
  return require(id);
823
928
  }
824
929
 
930
+ const directRequireTarget = normalizeWebframezRequireCandidate(id);
931
+ if (directRequireTarget !== id) {
932
+ return require(directRequireTarget);
933
+ }
934
+
825
935
  if (id.startsWith("./")) {
826
936
  const relativeId = id.slice(2);
827
937
  const candidates = [
@@ -829,10 +939,16 @@ globalThis.__webpack_require__ = function __webframezNodeRequire(id) {
829
939
  path.resolve(process.cwd(), "..", relativeId)
830
940
  ];
831
941
  for (const candidate of candidates) {
942
+ const requireTarget = normalizeWebframezRequireCandidate(candidate);
832
943
  try {
833
- return require(candidate);
944
+ return require(requireTarget);
834
945
  } catch (error) {
835
- const missingCandidate = error && error.code === "MODULE_NOT_FOUND" && typeof error.message === "string" && error.message.includes("'" + candidate + "'");
946
+ const missingCandidate =
947
+ error &&
948
+ error.code === "MODULE_NOT_FOUND" &&
949
+ typeof error.message === "string" &&
950
+ (error.message.includes("'" + candidate + "'") ||
951
+ error.message.includes("'" + requireTarget + "'"));
836
952
  if (!missingCandidate) {
837
953
  throw error;
838
954
  }
@@ -1054,6 +1170,14 @@ function joinRuntimeBasePath(basePath, pathname) {
1054
1170
  }
1055
1171
  return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
1056
1172
  }
1173
+ function joinRuntimeAssetPath(basePath, pathname) {
1174
+ const normalizedBasePath = normalizeRuntimeBasePath(basePath) ?? "";
1175
+ const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
1176
+ if (normalizedBasePath && (normalizedPath === normalizedBasePath || normalizedPath.startsWith(`${normalizedBasePath}/`))) {
1177
+ return normalizedPath;
1178
+ }
1179
+ return joinRuntimeBasePath(normalizedBasePath, normalizedPath);
1180
+ }
1057
1181
  function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
1058
1182
  if (!rawNodeOptions || rawNodeOptions.trim() === "") {
1059
1183
  return "";
@@ -1248,6 +1372,18 @@ function createServerConsumerManifest(manifest) {
1248
1372
  const consumerManifest = {};
1249
1373
  const normalizeWorkerModuleId = (requestKey, rawModuleId) => {
1250
1374
  if (typeof rawModuleId === "string" && rawModuleId.trim() !== "") {
1375
+ const isStagingModuleId = rawModuleId.startsWith("./.webframez-build/") || rawModuleId.includes(`${path3.sep}.webframez-build${path3.sep}`);
1376
+ const isRuntimeBuildKey = requestKey.startsWith("file://") || requestKey.startsWith("/") && requestKey.includes(`${path3.sep}build${path3.sep}app${path3.sep}`);
1377
+ if (isStagingModuleId && isRuntimeBuildKey) {
1378
+ if (requestKey.startsWith("file://")) {
1379
+ try {
1380
+ return fileURLToPath(requestKey);
1381
+ } catch {
1382
+ return rawModuleId;
1383
+ }
1384
+ }
1385
+ return requestKey;
1386
+ }
1251
1387
  return rawModuleId;
1252
1388
  }
1253
1389
  if (typeof rawModuleId !== "number" || !Number.isFinite(rawModuleId)) {
@@ -1329,6 +1465,14 @@ function createServerConsumerManifest(manifest) {
1329
1465
  name: exportName
1330
1466
  });
1331
1467
  }
1468
+ } else if (typeof entry.id === "string" && entry.id.trim() !== "") {
1469
+ addReference(entry.id, "*", reference);
1470
+ for (const exportName of exportNames) {
1471
+ addReference(entry.id, exportName, {
1472
+ ...reference,
1473
+ name: exportName
1474
+ });
1475
+ }
1332
1476
  }
1333
1477
  }
1334
1478
  return consumerManifest;
@@ -1443,24 +1587,49 @@ function createNodeRequestHandler(options) {
1443
1587
  if (url.pathname.startsWith(assetsPrefix)) {
1444
1588
  const relative = url.pathname.slice(assetsPrefix.length);
1445
1589
  const filePath = path3.resolve(distRootDir, relative);
1446
- if (!filePath.startsWith(distRootDir)) {
1590
+ if (!isWithinDirectory(filePath, distRootDir)) {
1447
1591
  res.statusCode = 400;
1448
1592
  res.end("Invalid path");
1449
1593
  return;
1450
1594
  }
1451
1595
  const ext = path3.extname(filePath);
1452
- if (ext === ".js" || ext === ".mjs") {
1453
- res.setHeader("Content-Type", "text/javascript; charset=utf-8");
1454
- } else if (ext === ".json") {
1455
- res.setHeader("Content-Type", "application/json; charset=utf-8");
1596
+ let stat;
1597
+ try {
1598
+ stat = fs2.statSync(filePath);
1599
+ if (!stat.isFile()) {
1600
+ throw new Error("Asset path is not a file");
1601
+ }
1602
+ } catch {
1603
+ res.statusCode = 404;
1604
+ res.end("Not found");
1605
+ return;
1456
1606
  }
1457
- res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
1607
+ setAssetContentType(res, ext);
1608
+ const isDevelopmentAsset = nodeEnv !== "production";
1609
+ const isVersionedClientAsset = path3.basename(filePath) === "client.js" && url.searchParams.has("v");
1610
+ const canCacheLongTerm = !isDevelopmentAsset && (isHashedAssetPath(filePath) || isVersionedClientAsset);
1611
+ res.setHeader(
1612
+ "Cache-Control",
1613
+ canCacheLongTerm ? "public, max-age=31536000, immutable" : "no-store, no-cache, must-revalidate, proxy-revalidate"
1614
+ );
1615
+ res.setHeader("Vary", "Accept-Encoding");
1616
+ const contentEncoding = !isDevelopmentAsset ? getPreferredContentEncoding(req, ext, stat.size) : "";
1458
1617
  const stream = fs2.createReadStream(filePath);
1459
1618
  stream.on("error", () => {
1460
- res.statusCode = 404;
1619
+ if (!res.headersSent) {
1620
+ res.statusCode = 404;
1621
+ }
1461
1622
  res.end("Not found");
1462
1623
  });
1463
- stream.pipe(res);
1624
+ if (contentEncoding === "br") {
1625
+ res.setHeader("Content-Encoding", "br");
1626
+ stream.pipe(createBrotliCompress()).pipe(res);
1627
+ } else if (contentEncoding === "gzip") {
1628
+ res.setHeader("Content-Encoding", "gzip");
1629
+ stream.pipe(createGzip()).pipe(res);
1630
+ } else {
1631
+ stream.pipe(res);
1632
+ }
1464
1633
  return;
1465
1634
  }
1466
1635
  const resolved = await withRequestBasename(
@@ -1478,22 +1647,23 @@ function createNodeRequestHandler(options) {
1478
1647
  );
1479
1648
  const initialPayload = {
1480
1649
  model: resolved.model,
1481
- contextModel: resolved.contextModel,
1482
- pageModel: resolved.pageModel,
1483
1650
  head: resolved.head
1484
1651
  };
1485
1652
  const initialFlightData = await renderRSCToString(initialPayload, {
1486
1653
  moduleMap
1487
1654
  });
1488
1655
  const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
1489
- const shellClientScriptUrl = joinRuntimeBasePath(
1490
- transportBasePath,
1491
- "/assets/client.js"
1656
+ const shellClientScriptUrl = appendAssetVersion(
1657
+ joinRuntimeAssetPath(
1658
+ transportBasePath,
1659
+ clientScriptUrl
1660
+ ),
1661
+ createClientAssetVersion(distRootDir)
1492
1662
  );
1493
1663
  const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
1494
1664
  const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
1495
1665
  const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
1496
- let rootHtml = "";
1666
+ let rootHtml;
1497
1667
  try {
1498
1668
  rootHtml = await initialHtmlWorker.renderFromFlightData({
1499
1669
  flightData: initialFlightData,
@@ -1517,29 +1687,23 @@ function createNodeRequestHandler(options) {
1517
1687
  });
1518
1688
  } catch (flightRenderError) {
1519
1689
  console.error("[webframez-react] Flight-to-HTML render failed", flightRenderError);
1520
- res.statusCode = 500;
1521
- res.setHeader("Content-Type", "text/html");
1522
- res.end(
1523
- createHTMLShell({
1524
- title: "500 - Initial HTML render failed",
1525
- headTags: "",
1526
- clientScriptUrl: shellClientScriptUrl,
1527
- rscEndpoint: shellRscEndpoint,
1528
- rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
1529
- initialFlightData,
1530
- basename: shellBasename,
1531
- routeBasePath: shellRouteBasePath,
1532
- liveReloadPath: liveReloadPath || void 0,
1533
- liveReloadServerId: liveReloadPath ? devServerId : void 0
1534
- })
1690
+ sendTextResponse(
1691
+ req,
1692
+ res,
1693
+ createInitialHtmlErrorMarkup("Failed to render initial React HTML."),
1694
+ {
1695
+ statusCode: 500,
1696
+ contentType: "text/html; charset=utf-8",
1697
+ compress: nodeEnv === "production"
1698
+ }
1535
1699
  );
1536
1700
  return;
1537
1701
  }
1538
1702
  }
1539
1703
  }
1540
- res.statusCode = resolved.statusCode;
1541
- res.setHeader("Content-Type", "text/html");
1542
- res.end(
1704
+ sendTextResponse(
1705
+ req,
1706
+ res,
1543
1707
  createHTMLShell({
1544
1708
  title: resolved.head.title || "Webframez React",
1545
1709
  headTags: renderHeadToString(resolved.head),
@@ -1551,14 +1715,20 @@ function createNodeRequestHandler(options) {
1551
1715
  routeBasePath: shellRouteBasePath,
1552
1716
  liveReloadPath: liveReloadPath || void 0,
1553
1717
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1554
- })
1718
+ }),
1719
+ {
1720
+ statusCode: resolved.statusCode,
1721
+ contentType: "text/html; charset=utf-8",
1722
+ cacheControl: "no-store, no-cache, must-revalidate, proxy-revalidate",
1723
+ compress: nodeEnv === "production"
1724
+ }
1555
1725
  );
1556
1726
  };
1557
1727
  }
1558
1728
 
1559
1729
  // src/webframez-core.ts
1560
- function normalizeMountPath(path4) {
1561
- const trimmed = (path4 || "").trim();
1730
+ function normalizeMountPath(path5) {
1731
+ const trimmed = (path5 || "").trim();
1562
1732
  let normalized = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
1563
1733
  if (normalized.endsWith("/**")) {
1564
1734
  normalized = normalized.slice(0, -3);
@@ -1570,12 +1740,57 @@ function normalizeMountPath(path4) {
1570
1740
  }
1571
1741
  return normalized || "/";
1572
1742
  }
1573
- function buildRenderDefaults(path4) {
1574
- const mountPath = normalizeMountPath(path4);
1743
+ var REGISTRY_KEY = "__WEBFRAMEZ_REACT_BUILD_TARGETS__";
1744
+ function getBuildTargetsRegistry() {
1745
+ const globalWithRegistry = globalThis;
1746
+ if (!globalWithRegistry[REGISTRY_KEY]) {
1747
+ globalWithRegistry[REGISTRY_KEY] = [];
1748
+ }
1749
+ return globalWithRegistry[REGISTRY_KEY];
1750
+ }
1751
+ function toRouteKey(mountPath) {
1752
+ const trimmed = mountPath.replace(/^\/+|\/+$/g, "");
1753
+ return trimmed || "root";
1754
+ }
1755
+ function toPascalCase(value) {
1756
+ return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
1757
+ }
1758
+ function getOutputRoot() {
1759
+ const configured = process.env.WEBFRAMEZ_REACT_OUT_DIR;
1760
+ if (configured) {
1761
+ return path4.resolve(process.cwd(), configured);
1762
+ }
1763
+ 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";
1764
+ if (isTsNodeRuntime && path4.basename(process.cwd()) !== "build") {
1765
+ return path4.resolve(process.cwd(), "build");
1766
+ }
1767
+ return process.cwd();
1768
+ }
1769
+ function resolveFromProjectRoot(value) {
1770
+ return path4.resolve(process.cwd(), value);
1771
+ }
1772
+ function resolveFromOutputRoot(value) {
1773
+ return path4.resolve(getOutputRoot(), value);
1774
+ }
1775
+ function buildRenderDefaults(routePathValue) {
1776
+ const mountPath = normalizeMountPath(routePathValue);
1777
+ const routeKey = toRouteKey(mountPath);
1778
+ const routeDirName = toPascalCase(routeKey) || routeKey;
1575
1779
  const routePath = mountPath === "/" ? "/*" : `${mountPath}/*`;
1780
+ const srcPath = path4.join("app", routeDirName, "react");
1781
+ const pagesDir = srcPath;
1782
+ const distRootDir = path4.join("webframez-react", routeKey);
1783
+ const styleSrcPath = path4.join("app", routeDirName, "assets", "scss");
1576
1784
  if (mountPath === "/") {
1577
1785
  return {
1786
+ path: mountPath,
1578
1787
  routePath,
1788
+ routeKey,
1789
+ srcPath: resolveFromProjectRoot(srcPath),
1790
+ distRootDir: resolveFromOutputRoot(distRootDir),
1791
+ pagesDir: resolveFromOutputRoot(pagesDir),
1792
+ manifestPath: resolveFromOutputRoot(path4.join(distRootDir, "react-client-manifest.json")),
1793
+ styleSrcPath: resolveFromProjectRoot(styleSrcPath),
1579
1794
  basePath: void 0,
1580
1795
  assetsPrefix: void 0,
1581
1796
  rscPath: void 0,
@@ -1583,7 +1798,14 @@ function buildRenderDefaults(path4) {
1583
1798
  };
1584
1799
  }
1585
1800
  return {
1801
+ path: mountPath,
1586
1802
  routePath,
1803
+ routeKey,
1804
+ srcPath: resolveFromProjectRoot(srcPath),
1805
+ distRootDir: resolveFromOutputRoot(distRootDir),
1806
+ pagesDir: resolveFromOutputRoot(pagesDir),
1807
+ manifestPath: resolveFromOutputRoot(path4.join(distRootDir, "react-client-manifest.json")),
1808
+ styleSrcPath: resolveFromProjectRoot(styleSrcPath),
1587
1809
  basePath: mountPath,
1588
1810
  assetsPrefix: `${mountPath}/assets/`,
1589
1811
  rscPath: `${mountPath}/rsc`,
@@ -1623,41 +1845,66 @@ function normalizeMethods(method) {
1623
1845
  }
1624
1846
  return Array.isArray(method) ? method : [method];
1625
1847
  }
1626
- function registerByMethod(route, method, path4, component, routeOptions) {
1848
+ function registerByMethod(route, method, path5, component, routeOptions) {
1627
1849
  if (method === "GET") {
1628
- route.get(path4, component, routeOptions);
1850
+ route.get(path5, component, routeOptions);
1629
1851
  return;
1630
1852
  }
1631
1853
  if (method === "POST") {
1632
- route.post(path4, component, routeOptions);
1854
+ route.post(path5, component, routeOptions);
1633
1855
  return;
1634
1856
  }
1635
1857
  if (method === "PUT") {
1636
- route.put(path4, component, routeOptions);
1858
+ route.put(path5, component, routeOptions);
1637
1859
  return;
1638
1860
  }
1639
- route.delete(path4, component, routeOptions);
1861
+ route.delete(path5, component, routeOptions);
1640
1862
  }
1641
1863
  function registerRouteRenderer(route, methodName) {
1642
1864
  route.extend(methodName, () => {
1643
- return (path4, options) => {
1644
- if (!options || !options.distRootDir) {
1645
- throw new Error(
1646
- `Route.${methodName} requires at least { distRootDir }`
1647
- );
1648
- }
1649
- const defaults = buildRenderDefaults(path4);
1865
+ return (routePathValue, options = {}) => {
1866
+ const defaults = buildRenderDefaults(routePathValue);
1650
1867
  const {
1651
1868
  method,
1652
1869
  routeOptions,
1870
+ srcPath,
1871
+ distRootDir,
1872
+ pagesDir,
1873
+ manifestPath,
1653
1874
  basePath,
1654
1875
  assetsPrefix,
1655
1876
  rscPath,
1656
1877
  clientScriptUrl,
1878
+ clientEntryPath,
1879
+ styleSrcPath,
1657
1880
  ...nodeHandlerOptions
1658
1881
  } = options;
1882
+ const resolvedDistRootDir = distRootDir ?? defaults.distRootDir;
1883
+ const resolvedPagesDir = pagesDir ?? defaults.pagesDir;
1884
+ const resolvedManifestPath = manifestPath ?? path4.join(resolvedDistRootDir, "react-client-manifest.json");
1885
+ const resolvedTarget = {
1886
+ path: defaults.path,
1887
+ routePath: defaults.routePath,
1888
+ routeKey: defaults.routeKey,
1889
+ srcPath: srcPath ? resolveFromProjectRoot(srcPath) : defaults.srcPath,
1890
+ distRootDir: resolvedDistRootDir,
1891
+ pagesDir: resolvedPagesDir,
1892
+ manifestPath: resolvedManifestPath,
1893
+ assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
1894
+ rscPath: rscPath ?? defaults.rscPath,
1895
+ clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl,
1896
+ clientEntryPath: clientEntryPath ? resolveFromProjectRoot(clientEntryPath) : void 0,
1897
+ styleSrcPath: styleSrcPath ? resolveFromProjectRoot(styleSrcPath) : defaults.styleSrcPath
1898
+ };
1899
+ getBuildTargetsRegistry().push(resolvedTarget);
1900
+ if (process.env.WEBFRAMEZ_REACT_CAPTURE_ROUTES === "1") {
1901
+ return;
1902
+ }
1659
1903
  const handleNodeRequest = createNodeRequestHandler({
1660
1904
  ...nodeHandlerOptions,
1905
+ distRootDir: resolvedTarget.distRootDir,
1906
+ pagesDir: resolvedTarget.pagesDir,
1907
+ manifestPath: resolvedTarget.manifestPath,
1661
1908
  basePath: basePath ?? defaults.basePath,
1662
1909
  assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
1663
1910
  rscPath: rscPath ?? defaults.rscPath,
@@ -1684,6 +1931,34 @@ function registerRouteRenderer(route, methodName) {
1684
1931
  };
1685
1932
  });
1686
1933
  }
1934
+ function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
1935
+ const defaults = buildRenderDefaults(routePathValue);
1936
+ const distRootDir = options.distRootDir ?? defaults.distRootDir;
1937
+ const pagesDir = options.pagesDir ?? defaults.pagesDir;
1938
+ const manifestPath = options.manifestPath ?? path4.join(distRootDir, "react-client-manifest.json");
1939
+ return {
1940
+ path: defaults.path,
1941
+ routePath: defaults.routePath,
1942
+ routeKey: defaults.routeKey,
1943
+ srcPath: options.srcPath ? resolveFromProjectRoot(options.srcPath) : defaults.srcPath,
1944
+ distRootDir,
1945
+ pagesDir,
1946
+ manifestPath,
1947
+ assetsPrefix: options.assetsPrefix ?? defaults.assetsPrefix,
1948
+ rscPath: options.rscPath ?? defaults.rscPath,
1949
+ clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
1950
+ clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
1951
+ styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
1952
+ basePath: options.basePath ?? defaults.basePath,
1953
+ liveReloadPath: options.liveReloadPath
1954
+ };
1955
+ }
1956
+ function getRegisteredReactBuildTargets() {
1957
+ return [...getBuildTargetsRegistry()];
1958
+ }
1959
+ function clearRegisteredReactBuildTargets() {
1960
+ getBuildTargetsRegistry().length = 0;
1961
+ }
1687
1962
  function initWebframezReact(route) {
1688
1963
  if (!route || typeof route.extend !== "function") {
1689
1964
  throw new Error(
@@ -1700,6 +1975,9 @@ function initWebframezReact(route) {
1700
1975
  }
1701
1976
  var setupWebframezCoreReactRoute = initWebframezReact;
1702
1977
  export {
1978
+ clearRegisteredReactBuildTargets,
1979
+ getRegisteredReactBuildTargets,
1703
1980
  initWebframezReact,
1981
+ resolveWebframezReactRouteOptions,
1704
1982
  setupWebframezCoreReactRoute
1705
1983
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {
@@ -63,6 +63,12 @@
63
63
  "import": "./dist/webframez-core.js",
64
64
  "require": "./dist/webframez-core.cjs"
65
65
  },
66
+ "./build-plugin": {
67
+ "types": "./dist/build-plugin.d.ts",
68
+ "import": "./dist/build-plugin.js",
69
+ "require": "./dist/build-plugin.cjs"
70
+ },
71
+ "./default-client": "./defaults/default-client.js",
66
72
  "./register": "./register.cjs",
67
73
  "./defaults/webpack.client": "./defaults/webpack.client.cjs",
68
74
  "./defaults/webpack.server": "./defaults/webpack.server.cjs",
@@ -76,6 +82,9 @@
76
82
  "bin",
77
83
  "register.cjs"
78
84
  ],
85
+ "webframez": {
86
+ "plugin": "./dist/build-plugin.cjs"
87
+ },
79
88
  "scripts": {
80
89
  "clean": "rm -rf dist",
81
90
  "build": "npm run clean && node scripts/build.mjs",