@brightchain/brightchain-api-lib 0.23.18 → 0.23.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightchain/brightchain-api-lib",
3
- "version": "0.23.18",
3
+ "version": "0.23.19",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "files": [
@@ -22,12 +22,29 @@ export declare class AppRouter<TID extends PlatformID = DefaultBackendIdType> ex
22
22
  * Useful for wiring services (e.g. setSyncEventSystem) after construction.
23
23
  */
24
24
  getBrightchainApiRouter(): ApiRouter<TID>;
25
+ /**
26
+ * Parses the webpack-generated index.html to extract the hashed script
27
+ * and stylesheet filenames. This is the most reliable way to serve the
28
+ * correct bundles since webpack already resolved the content hashes.
29
+ *
30
+ * Returns { scripts, stylesheets } arrays of filenames (relative paths).
31
+ * Returns empty arrays if index.html is missing or unparseable.
32
+ */
33
+ private parseWebpackIndexHtml;
34
+ /**
35
+ * Finds Nx webpack hashed filenames in reactDistDir matching a pattern
36
+ * like main.{hash}.js or runtime.{hash}.js.
37
+ */
38
+ private findHashedFiles;
25
39
  /**
26
40
  * Override the upstream's renderIndex to inject BrightChain-specific
27
41
  * template locals (fontAwesomeKitId, custom tagline, etc.).
28
42
  *
29
- * Production build: hashed assets/index-[hash].js → jsFile is set
30
- * Dev build: static/js/main.js + runtime.js + vendor.js → devScripts is set
43
+ * Supports three bundle layouts:
44
+ * 1. Vite: hashed assets/index-[hash].js in assets/ dir
45
+ * 2. Nx webpack: hashed main.[hash].js + runtime.[hash].js in reactDistDir
46
+ * (detected by parsing the webpack-generated index.html)
47
+ * 3. Dev fallback: unhashed runtime.js + main.js + vendor.js
31
48
  */
32
49
  renderIndex(req: Request, res: Response, next: NextFunction): void;
33
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/routers/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EACL,YAAY,EACZ,SAAS,IAAI,iBAAiB,EAC/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;GAKG;AACH,qBAAa,SAAS,CACpB,GAAG,SAAS,UAAU,GAAG,oBAAoB,CAC7C,SAAQ,iBAAiB,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IACjD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAiB;gBAE1C,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC;IAKrC;;;OAGG;IACI,uBAAuB,IAAI,SAAS,CAAC,GAAG,CAAC;IAIhD;;;;;;OAMG;IACa,WAAW,CACzB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,GACjB,IAAI;CA6BR"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/routers/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EACL,YAAY,EACZ,SAAS,IAAI,iBAAiB,EAC/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;GAKG;AACH,qBAAa,SAAS,CACpB,GAAG,SAAS,UAAU,GAAG,oBAAoB,CAC7C,SAAQ,iBAAiB,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IACjD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAiB;gBAE1C,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC;IAKrC;;;OAGG;IACI,uBAAuB,IAAI,SAAS,CAAC,GAAG,CAAC;IAIhD;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IA6B7B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;;;;;;;OASG;IACa,WAAW,CACzB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,GACjB,IAAI;CAyDR"}
@@ -22,32 +22,112 @@ class AppRouter extends node_express_suite_1.AppRouter {
22
22
  getBrightchainApiRouter() {
23
23
  return this.brightchainApiRouter;
24
24
  }
25
+ /**
26
+ * Parses the webpack-generated index.html to extract the hashed script
27
+ * and stylesheet filenames. This is the most reliable way to serve the
28
+ * correct bundles since webpack already resolved the content hashes.
29
+ *
30
+ * Returns { scripts, stylesheets } arrays of filenames (relative paths).
31
+ * Returns empty arrays if index.html is missing or unparseable.
32
+ */
33
+ parseWebpackIndexHtml() {
34
+ const indexHtmlPath = (0, path_1.join)(this.reactDistDir, 'index.html');
35
+ if (!(0, fs_1.existsSync)(indexHtmlPath)) {
36
+ return { scripts: [], stylesheets: [] };
37
+ }
38
+ try {
39
+ const html = (0, fs_1.readFileSync)(indexHtmlPath, 'utf8');
40
+ // Match <script ... src="filename.js" ...>
41
+ const scriptRegex = /<script[^>]+src="([^"]+\.js)"[^>]*>/g;
42
+ const scripts = [];
43
+ let match;
44
+ while ((match = scriptRegex.exec(html)) !== null) {
45
+ scripts.push(match[1]);
46
+ }
47
+ // Match <link ... href="filename.css" ...>
48
+ const cssRegex = /<link[^>]+href="([^"]+\.css)"[^>]*>/g;
49
+ const stylesheets = [];
50
+ while ((match = cssRegex.exec(html)) !== null) {
51
+ stylesheets.push(match[1]);
52
+ }
53
+ return { scripts, stylesheets };
54
+ }
55
+ catch {
56
+ return { scripts: [], stylesheets: [] };
57
+ }
58
+ }
59
+ /**
60
+ * Finds Nx webpack hashed filenames in reactDistDir matching a pattern
61
+ * like main.{hash}.js or runtime.{hash}.js.
62
+ */
63
+ findHashedFiles(baseName, ext) {
64
+ try {
65
+ const pattern = new RegExp(`^${baseName}\\.[a-f0-9]+\\.${ext}$`);
66
+ const files = (0, fs_1.readdirSync)(this.reactDistDir, 'utf8');
67
+ // Sort descending by name to get the latest hash if multiple exist
68
+ return files.filter((f) => pattern.test(f)).sort().pop();
69
+ }
70
+ catch {
71
+ return undefined;
72
+ }
73
+ }
25
74
  /**
26
75
  * Override the upstream's renderIndex to inject BrightChain-specific
27
76
  * template locals (fontAwesomeKitId, custom tagline, etc.).
28
77
  *
29
- * Production build: hashed assets/index-[hash].js → jsFile is set
30
- * Dev build: static/js/main.js + runtime.js + vendor.js → devScripts is set
78
+ * Supports three bundle layouts:
79
+ * 1. Vite: hashed assets/index-[hash].js in assets/ dir
80
+ * 2. Nx webpack: hashed main.[hash].js + runtime.[hash].js in reactDistDir
81
+ * (detected by parsing the webpack-generated index.html)
82
+ * 3. Dev fallback: unhashed runtime.js + main.js + vendor.js
31
83
  */
32
84
  renderIndex(req, res, next) {
33
85
  if (req.url.endsWith('.js')) {
34
86
  res.type('application/javascript');
35
87
  }
36
- // Production: hashed bundle in assets/
88
+ // Strategy 1: Vite — hashed bundle in assets/
37
89
  const jsFile = this.getAssetFilename(this.assetsDir, /^index-.*\.js$/);
38
90
  const cssFile = this.getAssetFilename(this.assetsDir, /^index-.*\.css$/);
39
- // Dev: un-hashed files emitted directly into reactDistDir
40
- const devScripts = !jsFile
41
- ? ['runtime.js', 'main.js', 'vendor.js'].filter((f) => (0, fs_1.existsSync)((0, path_1.join)(this.reactDistDir, f)))
42
- : [];
91
+ let devScripts = [];
92
+ let webpackCss = [];
93
+ if (!jsFile) {
94
+ // Strategy 2: Nx webpack — parse the generated index.html for hashed filenames.
95
+ // This is the authoritative source since webpack writes the correct references.
96
+ const { scripts, stylesheets } = this.parseWebpackIndexHtml();
97
+ webpackCss = stylesheets;
98
+ if (scripts.length > 0) {
99
+ // Webpack index.html found with hashed scripts — use them.
100
+ // Scripts are served from reactDistDir via the /static/js/ mount
101
+ // or directly if they're root-relative paths.
102
+ devScripts = scripts;
103
+ }
104
+ else {
105
+ // Strategy 3: Dev fallback — unhashed files.
106
+ // Also try to find hashed files directly in case index.html is missing.
107
+ const hashedRuntime = this.findHashedFiles('runtime', 'js');
108
+ const hashedMain = this.findHashedFiles('main', 'js');
109
+ if (hashedMain) {
110
+ // Prefer hashed files over unhashed
111
+ if (hashedRuntime)
112
+ devScripts.push(hashedRuntime);
113
+ devScripts.push(hashedMain);
114
+ }
115
+ else {
116
+ // True dev fallback: unhashed files
117
+ devScripts = ['runtime.js', 'main.js', 'vendor.js'].filter((f) => (0, fs_1.existsSync)((0, path_1.join)(this.reactDistDir, f)));
118
+ }
119
+ }
120
+ }
43
121
  const environment = this.application.environment;
44
122
  const locals = {
45
123
  ...this.getBaseViewLocals(req, res),
46
124
  fontawesomeKitId: environment.fontAwesomeKitId,
47
125
  jsFile: jsFile ? `assets/${jsFile}` : undefined,
48
126
  cssFile: cssFile ? `assets/${cssFile}` : undefined,
49
- // Dev-mode script list (empty in production)
127
+ // Script list for non-Vite builds (hashed or dev)
50
128
  devScripts,
129
+ // Additional CSS from webpack index.html
130
+ webpackCss,
51
131
  };
52
132
  this.renderTemplate(req, res, next, 'index', locals);
53
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/routers/app.ts"],"names":[],"mappings":";;;AACA,4EAG6C;AAE7C,2BAAgC;AAChC,+BAA4B;AAK5B;;;;;GAKG;AACH,MAAa,SAEX,SAAQ,8BAAyC;IAQjD,YAAY,SAAyB;QACnC,KAAK,CAAC,SAAS,CAAC,CAA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