@webtypen/webframez-react 0.0.49 → 0.0.51

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.
@@ -1,3 +1,9 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
8
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
9
  }) : x)(function(x) {
@@ -5,11 +11,88 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
5
11
  return require.apply(this, arguments);
6
12
  throw Error('Dynamic require of "' + x + '" is not supported');
7
13
  });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // node_modules/@webtypen/webframez-core/dist/routing.js
35
+ var require_routing = __commonJS({
36
+ "node_modules/@webtypen/webframez-core/dist/routing.js"(exports) {
37
+ "use strict";
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.appRelativePath = exports.appPath = exports.getBasename = exports.normalizeBasename = void 0;
40
+ function normalizeBasename2(value) {
41
+ if (value == null || value === "" || value === "/")
42
+ return "";
43
+ if (typeof value !== "string")
44
+ throw new Error("Router basename must be a string.");
45
+ const base = value.trim().replace(/\/+$/, "");
46
+ if (!base && value.trim().length <= 1)
47
+ return "";
48
+ if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
49
+ throw new Error("Router basename must be empty or an absolute path such as /my-app.");
50
+ }
51
+ return base;
52
+ }
53
+ exports.normalizeBasename = normalizeBasename2;
54
+ function getBasename2() {
55
+ var _a, _b, _c, _d;
56
+ const runtime = globalThis;
57
+ return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
58
+ }
59
+ exports.getBasename = getBasename2;
60
+ function appPath2(value, basename = getBasename2()) {
61
+ const base = normalizeBasename2(basename);
62
+ if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
63
+ return value;
64
+ return base + value;
65
+ }
66
+ exports.appPath = appPath2;
67
+ function appRelativePath2(value, basename = getBasename2()) {
68
+ const base = normalizeBasename2(basename);
69
+ if (!base || !hasBasename(value, base))
70
+ return value;
71
+ const relative = value.slice(base.length);
72
+ return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
73
+ }
74
+ exports.appRelativePath = appRelativePath2;
75
+ function hasBasename(value, base) {
76
+ return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
77
+ }
78
+ }
79
+ });
80
+
81
+ // node_modules/@webtypen/webframez-core/routing.js
82
+ var require_routing2 = __commonJS({
83
+ "node_modules/@webtypen/webframez-core/routing.js"(exports, module) {
84
+ module.exports = require_routing();
85
+ }
86
+ });
87
+
88
+ // src/paths.ts
89
+ var import_routing = __toESM(require_routing2(), 1);
8
90
 
9
91
  // src/webframez-core.ts
10
92
  import path4 from "node:path";
11
93
 
12
94
  // src/http.ts
95
+ import { AsyncLocalStorage } from "node:async_hooks";
13
96
  import fs2 from "node:fs";
14
97
  import path3 from "node:path";
15
98
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -324,8 +407,7 @@ var FORCED_PACKAGE_REQUESTS = [
324
407
  "react-server-dom-webpack",
325
408
  "react-server-dom-webpack/server",
326
409
  "react-server-dom-webpack/client",
327
- "react-server-dom-webpack/client.node",
328
- "scheduler"
410
+ "react-server-dom-webpack/client.node"
329
411
  ];
330
412
  var forcedPackageResolutionInstalled = false;
331
413
  function normalizePathname(pathname) {
@@ -976,6 +1058,7 @@ const rootParent = {
976
1058
  path: process.cwd(),
977
1059
  paths: Module._nodeModulePaths(process.cwd()),
978
1060
  };
1061
+ // Transitive dependencies (e.g. scheduler) must resolve from their importer.
979
1062
  const forcedPackageRequests = [
980
1063
  "@webtypen/webframez-core",
981
1064
  "@webtypen/webframez-react",
@@ -990,7 +1073,6 @@ const forcedPackageRequests = [
990
1073
  "react-server-dom-webpack/server",
991
1074
  "react-server-dom-webpack/client",
992
1075
  "react-server-dom-webpack/client.node",
993
- "scheduler"
994
1076
  ];
995
1077
 
996
1078
  function shouldForcePackageResolution(request) {
@@ -1182,13 +1264,17 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
1182
1264
  ? payload.head.basename
1183
1265
  : "";
1184
1266
 
1185
- const previousBasename = globalThis.__RSC_BASENAME;
1186
- globalThis.__RSC_BASENAME = basename;
1187
- try {
1188
- return await renderHtml(model);
1189
- } finally {
1190
- globalThis.__RSC_BASENAME = previousBasename;
1191
- }
1267
+ const routingContext = globalThis.__WEBFRAMEZ_ROUTING_CONTEXT__ ??=
1268
+ new (require("node:async_hooks").AsyncLocalStorage)();
1269
+ return routingContext.run(basename, async () => {
1270
+ const previousBasename = globalThis.__RSC_BASENAME;
1271
+ globalThis.__RSC_BASENAME = basename;
1272
+ try {
1273
+ return await renderHtml(model);
1274
+ } finally {
1275
+ globalThis.__RSC_BASENAME = previousBasename;
1276
+ }
1277
+ });
1192
1278
  }
1193
1279
 
1194
1280
  process.on("message", async (message) => {
@@ -1424,24 +1510,10 @@ ${stderrBuffer.trim()}` : "";
1424
1510
  }
1425
1511
  };
1426
1512
  }
1513
+ var routingRuntime = globalThis;
1514
+ var basenameContext = routingRuntime.__WEBFRAMEZ_ROUTING_CONTEXT__ ??= new AsyncLocalStorage();
1427
1515
  function withRequestBasename(basename, fn) {
1428
- const target = globalThis;
1429
- const previous = target.__RSC_BASENAME;
1430
- target.__RSC_BASENAME = basename;
1431
- const finish = () => {
1432
- target.__RSC_BASENAME = previous;
1433
- };
1434
- try {
1435
- const result = fn();
1436
- if (result && typeof result.then === "function") {
1437
- return result.finally(finish);
1438
- }
1439
- finish();
1440
- return result;
1441
- } catch (error) {
1442
- finish();
1443
- throw error;
1444
- }
1516
+ return basenameContext.run(basename, fn);
1445
1517
  }
1446
1518
  function parseCookies(rawCookieHeader) {
1447
1519
  const raw = Array.isArray(rawCookieHeader) ? rawCookieHeader.join("; ") : rawCookieHeader ?? "";
@@ -1476,12 +1548,27 @@ function normalizeClientManifest(manifest, options) {
1476
1548
  }
1477
1549
  };
1478
1550
  for (const [key, value] of Object.entries(manifest)) {
1551
+ const hashIndex = key.indexOf("#");
1552
+ const moduleKey = hashIndex < 0 ? key : key.slice(0, hashIndex);
1553
+ const exportSuffix = hashIndex < 0 ? "" : key.slice(hashIndex);
1554
+ if (!path3.isAbsolute(moduleKey) && !moduleKey.includes(":") && !moduleKey.startsWith("file://")) {
1555
+ const runtimePath = path3.resolve(options.cwd, moduleKey);
1556
+ const allowedRoots = [options.distRootDir, ...candidateNodeModulesDirs];
1557
+ const insideArtifact = allowedRoots.some((root) => {
1558
+ const relative = path3.relative(path3.resolve(root), runtimePath);
1559
+ return relative !== "" && relative !== ".." && !relative.startsWith(`..${path3.sep}`) && !path3.isAbsolute(relative);
1560
+ });
1561
+ if (insideArtifact) {
1562
+ addAlias(`${runtimePath}${exportSuffix}`, value);
1563
+ addAlias(`${pathToFileURL(runtimePath).href}${exportSuffix}`, value);
1564
+ }
1565
+ }
1479
1566
  if (!key.startsWith("file://")) {
1480
1567
  continue;
1481
1568
  }
1482
1569
  let absolutePath = "";
1483
1570
  try {
1484
- absolutePath = fileURLToPath(key);
1571
+ absolutePath = fileURLToPath(moduleKey);
1485
1572
  } catch {
1486
1573
  continue;
1487
1574
  }
@@ -1492,13 +1579,13 @@ function normalizeClientManifest(manifest, options) {
1492
1579
  }
1493
1580
  const relativeModulePath = absolutePath.slice(markerIndex + marker.length);
1494
1581
  const relativeModulePathPosix = relativeModulePath.split(path3.sep).join("/");
1495
- addAlias(`./node_modules/${relativeModulePathPosix}`, value);
1496
- addAlias(`node_modules/${relativeModulePathPosix}`, value);
1497
- addAlias(absolutePath, value);
1582
+ addAlias(`./node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
1583
+ addAlias(`node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
1584
+ addAlias(`${absolutePath}${exportSuffix}`, value);
1498
1585
  for (const nodeModulesDir of candidateNodeModulesDirs) {
1499
1586
  const aliasPath = path3.join(nodeModulesDir, relativeModulePath);
1500
- addAlias(aliasPath, value);
1501
- addAlias(pathToFileURL(aliasPath).href, value);
1587
+ addAlias(`${aliasPath}${exportSuffix}`, value);
1588
+ addAlias(`${pathToFileURL(aliasPath).href}${exportSuffix}`, value);
1502
1589
  }
1503
1590
  }
1504
1591
  return normalized;
@@ -1643,10 +1730,10 @@ function createNodeRequestHandler(options) {
1643
1730
  const manifestPath = path3.resolve(
1644
1731
  options.manifestPath ?? path3.join(distRootDir, "react-client-manifest.json")
1645
1732
  );
1646
- const assetsPrefix = options.assetsPrefix ?? "/assets/";
1647
- const rscPath = options.rscPath ?? "/rsc";
1648
- const clientScriptUrl = options.clientScriptUrl ?? "/assets/client.js";
1649
1733
  const basePath = normalizeBasePath(options.basePath);
1734
+ const assetsPrefix = options.assetsPrefix ?? `${basePath}/assets/`;
1735
+ const rscPath = options.rscPath ?? `${basePath}/rsc`;
1736
+ const clientScriptUrl = options.clientScriptUrl ?? `${basePath}/assets/client.js`;
1650
1737
  const nodeEnv = process.env.NODE_ENV || "";
1651
1738
  const runningInWatchMode = Array.isArray(process.execArgv) && process.execArgv.includes("--watch");
1652
1739
  const liveReloadEnabled = options.liveReloadPath !== false && (nodeEnv === "development" || runningInWatchMode);
@@ -1665,7 +1752,7 @@ function createNodeRequestHandler(options) {
1665
1752
  process.once("exit", disposeInitialHtmlWorker);
1666
1753
  process.once("SIGINT", disposeInitialHtmlWorker);
1667
1754
  process.once("SIGTERM", disposeInitialHtmlWorker);
1668
- return async function handleRequest(req, res) {
1755
+ const handleRequest = async (req, res) => {
1669
1756
  if (!req.url) {
1670
1757
  res.statusCode = 400;
1671
1758
  res.end("Bad request");
@@ -1729,6 +1816,7 @@ function createNodeRequestHandler(options) {
1729
1816
  request: requestContext
1730
1817
  })
1731
1818
  );
1819
+ resolved2.head = { ...resolved2.head, basename: resolved2.head.basename ?? basePath };
1732
1820
  attachResolvedContextToCoreRequest(req, resolved2.context);
1733
1821
  const payload = {
1734
1822
  model: resolved2.model,
@@ -1804,6 +1892,7 @@ function createNodeRequestHandler(options) {
1804
1892
  )
1805
1893
  })
1806
1894
  );
1895
+ resolved.head = { ...resolved.head, basename: resolved.head.basename ?? basePath };
1807
1896
  attachResolvedContextToCoreRequest(req, resolved.context);
1808
1897
  const initialPayload = {
1809
1898
  model: resolved.model,
@@ -1889,6 +1978,7 @@ function createNodeRequestHandler(options) {
1889
1978
  }
1890
1979
  );
1891
1980
  };
1981
+ return (req, res) => withRequestBasename(basePath, () => handleRequest(req, res));
1892
1982
  }
1893
1983
 
1894
1984
  // src/webframez-core.ts
@@ -1977,6 +2067,17 @@ function buildRenderDefaults(routePathValue) {
1977
2067
  clientScriptUrl: `${mountPath}/assets/client.js`
1978
2068
  };
1979
2069
  }
2070
+ function runtimeRoutePaths(routePath, options, basename = (0, import_routing.getBasename)(), groupPrefix = "") {
2071
+ const localMount = normalizeMountPath(options.basePath ?? `${groupPrefix}${normalizeMountPath(routePath)}`);
2072
+ const basePath = normalizeMountPath((0, import_routing.appPath)(localMount, basename)).replace(/\/$/, "");
2073
+ return {
2074
+ basePath,
2075
+ assetsPrefix: options.assetsPrefix !== void 0 ? (0, import_routing.appPath)(options.assetsPrefix, basename) : `${basePath}/assets/`,
2076
+ rscPath: options.rscPath !== void 0 ? (0, import_routing.appPath)(options.rscPath, basename) : `${basePath}/rsc`,
2077
+ clientScriptUrl: options.clientScriptUrl !== void 0 ? (0, import_routing.appPath)(options.clientScriptUrl, basename) : `${basePath}/assets/client.js`,
2078
+ ...typeof options.liveReloadPath === "string" ? { liveReloadPath: (0, import_routing.appPath)(options.liveReloadPath, basename) } : {}
2079
+ };
2080
+ }
1980
2081
  async function waitForResponseFinish(res) {
1981
2082
  if (res.writableEnded || res.destroyed) {
1982
2083
  return;
@@ -2070,10 +2171,7 @@ function registerRouteRenderer(route, methodName) {
2070
2171
  distRootDir: resolvedTarget.distRootDir,
2071
2172
  pagesDir: resolvedTarget.pagesDir,
2072
2173
  manifestPath: resolvedTarget.manifestPath,
2073
- basePath: basePath ?? defaults.basePath,
2074
- assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
2075
- rscPath: rscPath ?? defaults.rscPath,
2076
- clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl
2174
+ ...runtimeRoutePaths(routePathValue, options, route.basename ?? (0, import_routing.getBasename)(), route.tempGroupPrefix ?? "")
2077
2175
  });
2078
2176
  const methods = normalizeMethods(method);
2079
2177
  for (const currentMethod of methods) {
@@ -2115,13 +2213,10 @@ function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
2115
2213
  distRootDir,
2116
2214
  pagesDir,
2117
2215
  manifestPath,
2118
- assetsPrefix: options.assetsPrefix ?? defaults.assetsPrefix,
2119
- rscPath: options.rscPath ?? defaults.rscPath,
2120
- clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
2216
+ ...runtimeRoutePaths(routePathValue, options),
2121
2217
  clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
2122
2218
  styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
2123
- basePath: options.basePath ?? defaults.basePath,
2124
- liveReloadPath: options.liveReloadPath,
2219
+ liveReloadPath: typeof options.liveReloadPath === "string" ? (0, import_routing.appPath)(options.liveReloadPath) : options.liveReloadPath,
2125
2220
  onData: options.onData
2126
2221
  };
2127
2222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {
@@ -74,7 +74,12 @@
74
74
  "./defaults/webpack.server": "./defaults/webpack.server.cjs",
75
75
  "./defaults/tsconfig.server": "./defaults/tsconfig.server.json",
76
76
  "./defaults/tsconfig.server.example": "./defaults/tsconfig.server.example.json",
77
- "./cli": "./bin/webframez-react.mjs"
77
+ "./cli": "./bin/webframez-react.mjs",
78
+ "./paths": {
79
+ "types": "./dist/paths.d.ts",
80
+ "import": "./dist/paths.js",
81
+ "require": "./dist/paths.cjs"
82
+ }
78
83
  },
79
84
  "files": [
80
85
  "dist",
@@ -88,10 +93,11 @@
88
93
  "scripts": {
89
94
  "clean": "rm -rf dist",
90
95
  "build": "npm run clean && node scripts/build.mjs",
91
- "build:watch": "node scripts/build.mjs --watch"
96
+ "build:watch": "node scripts/build.mjs --watch",
97
+ "test": "node --test tests/*.test.cjs"
92
98
  },
93
99
  "peerDependencies": {
94
- "@webtypen/webframez-core": "^0.3.30",
100
+ "@webtypen/webframez-core": ">=0.3.69",
95
101
  "react": "^19.0.0 || >=0.0.0-0 <0.0.1",
96
102
  "react-dom": "^19.0.0 || >=0.0.0-0 <0.0.1",
97
103
  "react-server-dom-webpack": "^19.0.0 || >=0.0.0-0 <0.0.1"
@@ -102,9 +108,17 @@
102
108
  }
103
109
  },
104
110
  "devDependencies": {
111
+ "@webtypen/webframez-core": "0.3.69",
105
112
  "esbuild": "^0.20.2",
106
113
  "react": "19.1.1",
107
114
  "react-dom": "19.1.1",
108
115
  "react-server-dom-webpack": "19.1.1"
116
+ },
117
+ "typesVersions": {
118
+ "*": {
119
+ "paths": [
120
+ "dist/paths.d.ts"
121
+ ]
122
+ }
109
123
  }
110
124
  }