@webtypen/webframez-react 0.0.41 → 0.0.42

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.
@@ -519,6 +519,84 @@ async function watchRouteTargets(targets, passthroughArgsClean) {
519
519
  });
520
520
  }
521
521
 
522
+ function getManifestChunkAssetsByName(distRootDir) {
523
+ const chunksDir = path.join(distRootDir, "chunks");
524
+ const assetsByName = new Map();
525
+ if (!fileExists(chunksDir)) {
526
+ return assetsByName;
527
+ }
528
+
529
+ for (const fileName of fs.readdirSync(chunksDir)) {
530
+ const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
531
+ if (match && match[1]) {
532
+ assetsByName.set(match[1], path.join("chunks", fileName));
533
+ }
534
+ }
535
+
536
+ return assetsByName;
537
+ }
538
+
539
+ function normalizeRouteManifestChunkFiles(distRootDir) {
540
+ const manifestPath = path.join(distRootDir, "react-client-manifest.json");
541
+ if (!fileExists(manifestPath)) {
542
+ return;
543
+ }
544
+
545
+ const assetsByName = getManifestChunkAssetsByName(distRootDir);
546
+ if (assetsByName.size === 0) {
547
+ return;
548
+ }
549
+
550
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
551
+ let changed = false;
552
+ for (const value of Object.values(manifest)) {
553
+ if (!value || typeof value !== "object" || !Array.isArray(value.chunks)) {
554
+ continue;
555
+ }
556
+
557
+ const nextChunks = value.chunks.map((chunk, index, chunks) => {
558
+ if (index % 2 === 1 && typeof chunks[index - 1] === "string") {
559
+ return assetsByName.get(chunks[index - 1]) || chunk;
560
+ }
561
+
562
+ return chunk;
563
+ });
564
+
565
+ if (nextChunks.some((chunk, index) => chunk !== value.chunks[index])) {
566
+ value.chunks = nextChunks;
567
+ changed = true;
568
+ }
569
+ }
570
+
571
+ if (changed) {
572
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
573
+ }
574
+ }
575
+
576
+ function collectMissingManifestChunks(distRootDir) {
577
+ const manifestPath = path.join(distRootDir, "react-client-manifest.json");
578
+ if (!fileExists(manifestPath)) {
579
+ return [];
580
+ }
581
+
582
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
583
+ const missing = [];
584
+ for (const value of Object.values(manifest)) {
585
+ if (!value || typeof value !== "object" || !Array.isArray(value.chunks)) {
586
+ continue;
587
+ }
588
+
589
+ for (let index = 1; index < value.chunks.length; index += 2) {
590
+ const chunk = value.chunks[index];
591
+ if (typeof chunk === "string" && chunk.includes(".") && !fileExists(path.join(distRootDir, chunk))) {
592
+ missing.push(chunk);
593
+ }
594
+ }
595
+ }
596
+
597
+ return Array.from(new Set(missing));
598
+ }
599
+
522
600
  async function validateRouteBuild(target) {
523
601
  const requiredFiles = [
524
602
  path.join(target.distRootDir, "client.js"),
@@ -532,6 +610,13 @@ async function validateRouteBuild(target) {
532
610
  `Route ${target.path} build is incomplete. Missing: ${missing.join(", ")}`,
533
611
  );
534
612
  }
613
+
614
+ const missingChunks = collectMissingManifestChunks(target.distRootDir);
615
+ if (missingChunks.length > 0) {
616
+ throw new Error(
617
+ `Route ${target.path} client manifest references missing chunks: ${missingChunks.join(", ")}`,
618
+ );
619
+ }
535
620
  }
536
621
 
537
622
  async function main() {
@@ -631,6 +716,7 @@ async function main() {
631
716
  return;
632
717
  }
633
718
 
719
+ normalizeRouteManifestChunkFiles(target.distRootDir);
634
720
  await validateRouteBuild(target);
635
721
  }
636
722
 
@@ -34,6 +34,53 @@ const frameworkCacheVersion = frameworkCacheFiles
34
34
  fs.mkdirSync(distDir, { recursive: true });
35
35
  fs.mkdirSync(pagesDir, { recursive: true });
36
36
 
37
+ function getEmittedChunkAssetsByName() {
38
+ const chunksDir = path.join(distDir, "chunks");
39
+ const assetsByName = new Map();
40
+ if (!fs.existsSync(chunksDir)) {
41
+ return assetsByName;
42
+ }
43
+
44
+ for (const fileName of fs.readdirSync(chunksDir)) {
45
+ const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
46
+ if (match && match[1]) {
47
+ assetsByName.set(match[1], "chunks/" + fileName);
48
+ }
49
+ }
50
+
51
+ return assetsByName;
52
+ }
53
+
54
+ function normalizeManifestChunkFiles(manifest) {
55
+ const assetsByName = getEmittedChunkAssetsByName();
56
+ if (assetsByName.size === 0) {
57
+ return false;
58
+ }
59
+
60
+ let changed = false;
61
+ for (const value of Object.values(manifest)) {
62
+ if (!value || typeof value !== "object" || !Array.isArray(value.chunks)) {
63
+ continue;
64
+ }
65
+
66
+ const nextChunks = value.chunks.map((chunk, index, chunks) => {
67
+ if (index % 2 === 1 && typeof chunks[index - 1] === "string") {
68
+ return assetsByName.get(chunks[index - 1]) || chunk;
69
+ }
70
+
71
+ return chunk;
72
+ });
73
+
74
+ if (nextChunks.some((chunk, index) => chunk !== value.chunks[index])) {
75
+ value.chunks = nextChunks;
76
+ changed = true;
77
+ }
78
+ }
79
+
80
+ return changed;
81
+ }
82
+
83
+
37
84
  class ClientManifestExportAliasesPlugin {
38
85
  apply(compiler) {
39
86
  compiler.hooks.done.tap("ClientManifestExportAliasesPlugin", () => {
@@ -152,6 +199,10 @@ class ClientManifestExportAliasesPlugin {
152
199
  }
153
200
  }
154
201
 
202
+ if (normalizeManifestChunkFiles(manifest)) {
203
+ changed = true;
204
+ }
205
+
155
206
  if (changed) {
156
207
  fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
157
208
  }
@@ -41,6 +41,47 @@ function fileExists(filePath) {
41
41
  function readJson(filePath) {
42
42
  return JSON.parse(import_node_fs.default.readFileSync(filePath, "utf-8"));
43
43
  }
44
+ function getEmittedChunkAssetsByName(distRootDir) {
45
+ const chunksDir = import_node_path.default.join(distRootDir, "chunks");
46
+ const assetsByName = /* @__PURE__ */ new Map();
47
+ if (!fileExists(chunksDir)) {
48
+ return assetsByName;
49
+ }
50
+ for (const fileName of import_node_fs.default.readdirSync(chunksDir)) {
51
+ const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
52
+ if (match?.[1]) {
53
+ assetsByName.set(match[1], import_node_path.default.join("chunks", fileName));
54
+ }
55
+ }
56
+ return assetsByName;
57
+ }
58
+ function normalizeManifestChunkFiles(distRootDir, manifestPath) {
59
+ const manifest = readJson(manifestPath);
60
+ const assetsByName = getEmittedChunkAssetsByName(distRootDir);
61
+ if (assetsByName.size === 0) {
62
+ return;
63
+ }
64
+ let changed = false;
65
+ for (const value of Object.values(manifest)) {
66
+ const entry = value;
67
+ if (!entry || !Array.isArray(entry.chunks)) {
68
+ continue;
69
+ }
70
+ const nextChunks = entry.chunks.map((chunk, index, chunks) => {
71
+ if (index % 2 === 1 && typeof chunks[index - 1] === "string") {
72
+ return assetsByName.get(chunks[index - 1]) || chunk;
73
+ }
74
+ return chunk;
75
+ });
76
+ if (nextChunks.some((chunk, index) => chunk !== entry.chunks?.[index])) {
77
+ entry.chunks = nextChunks;
78
+ changed = true;
79
+ }
80
+ }
81
+ if (changed) {
82
+ import_node_fs.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
83
+ }
84
+ }
44
85
  function collectManifestChunks(manifestPath) {
45
86
  const manifest = readJson(manifestPath);
46
87
  const chunks = /* @__PURE__ */ new Set();
@@ -65,7 +106,9 @@ function validateRouteDist(distRootDir) {
65
106
  throw new Error(`webframez-react build output missing: ${filePath}`);
66
107
  }
67
108
  }
68
- for (const chunk of collectManifestChunks(import_node_path.default.join(distRootDir, "react-client-manifest.json"))) {
109
+ const clientManifestPath = import_node_path.default.join(distRootDir, "react-client-manifest.json");
110
+ normalizeManifestChunkFiles(distRootDir, clientManifestPath);
111
+ for (const chunk of collectManifestChunks(clientManifestPath)) {
69
112
  const chunkPath = import_node_path.default.join(distRootDir, chunk);
70
113
  if (!fileExists(chunkPath)) {
71
114
  throw new Error(`webframez-react manifest references missing chunk: ${chunkPath}`);
@@ -7,6 +7,47 @@ function fileExists(filePath) {
7
7
  function readJson(filePath) {
8
8
  return JSON.parse(fs.readFileSync(filePath, "utf-8"));
9
9
  }
10
+ function getEmittedChunkAssetsByName(distRootDir) {
11
+ const chunksDir = path.join(distRootDir, "chunks");
12
+ const assetsByName = /* @__PURE__ */ new Map();
13
+ if (!fileExists(chunksDir)) {
14
+ return assetsByName;
15
+ }
16
+ for (const fileName of fs.readdirSync(chunksDir)) {
17
+ const match = fileName.match(/^(.*)-[a-f0-9]+\.js$/i);
18
+ if (match?.[1]) {
19
+ assetsByName.set(match[1], path.join("chunks", fileName));
20
+ }
21
+ }
22
+ return assetsByName;
23
+ }
24
+ function normalizeManifestChunkFiles(distRootDir, manifestPath) {
25
+ const manifest = readJson(manifestPath);
26
+ const assetsByName = getEmittedChunkAssetsByName(distRootDir);
27
+ if (assetsByName.size === 0) {
28
+ return;
29
+ }
30
+ let changed = false;
31
+ for (const value of Object.values(manifest)) {
32
+ const entry = value;
33
+ if (!entry || !Array.isArray(entry.chunks)) {
34
+ continue;
35
+ }
36
+ const nextChunks = entry.chunks.map((chunk, index, chunks) => {
37
+ if (index % 2 === 1 && typeof chunks[index - 1] === "string") {
38
+ return assetsByName.get(chunks[index - 1]) || chunk;
39
+ }
40
+ return chunk;
41
+ });
42
+ if (nextChunks.some((chunk, index) => chunk !== entry.chunks?.[index])) {
43
+ entry.chunks = nextChunks;
44
+ changed = true;
45
+ }
46
+ }
47
+ if (changed) {
48
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
49
+ }
50
+ }
10
51
  function collectManifestChunks(manifestPath) {
11
52
  const manifest = readJson(manifestPath);
12
53
  const chunks = /* @__PURE__ */ new Set();
@@ -31,7 +72,9 @@ function validateRouteDist(distRootDir) {
31
72
  throw new Error(`webframez-react build output missing: ${filePath}`);
32
73
  }
33
74
  }
34
- for (const chunk of collectManifestChunks(path.join(distRootDir, "react-client-manifest.json"))) {
75
+ const clientManifestPath = path.join(distRootDir, "react-client-manifest.json");
76
+ normalizeManifestChunkFiles(distRootDir, clientManifestPath);
77
+ for (const chunk of collectManifestChunks(clientManifestPath)) {
35
78
  const chunkPath = path.join(distRootDir, chunk);
36
79
  if (!fileExists(chunkPath)) {
37
80
  throw new Error(`webframez-react manifest references missing chunk: ${chunkPath}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {