dinou 8.0.3 → 8.1.1

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -1
  3. package/dinou/bun/build.js +15 -6
  4. package/dinou/cloudflare/build.js +15 -6
  5. package/dinou/core/route-generator.js +1 -1
  6. package/dinou/core/transform-server-functions.js +291 -0
  7. package/dinou/deno/build.js +15 -6
  8. package/dinou/esbuild/build.js +7 -2
  9. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +3 -3
  10. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +17 -6
  11. package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +4 -2
  12. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +43 -29
  13. package/dinou/index.js +1 -4
  14. package/dinou/node/bundle-dual-engine.js +15 -6
  15. package/dinou/node/dev.js +49 -9
  16. package/dinou/node_modules/ws/LICENSE +20 -0
  17. package/dinou/node_modules/ws/README.md +548 -0
  18. package/dinou/node_modules/ws/browser.js +8 -0
  19. package/dinou/node_modules/ws/index.js +22 -0
  20. package/dinou/node_modules/ws/lib/buffer-util.js +131 -0
  21. package/dinou/node_modules/ws/lib/constants.js +19 -0
  22. package/dinou/node_modules/ws/lib/event-target.js +292 -0
  23. package/dinou/node_modules/ws/lib/extension.js +203 -0
  24. package/dinou/node_modules/ws/lib/limiter.js +55 -0
  25. package/dinou/node_modules/ws/lib/permessage-deflate.js +530 -0
  26. package/dinou/node_modules/ws/lib/receiver.js +743 -0
  27. package/dinou/node_modules/ws/lib/sender.js +607 -0
  28. package/dinou/node_modules/ws/lib/stream.js +161 -0
  29. package/dinou/node_modules/ws/lib/subprotocol.js +62 -0
  30. package/dinou/node_modules/ws/lib/validation.js +152 -0
  31. package/dinou/node_modules/ws/lib/websocket-server.js +562 -0
  32. package/dinou/node_modules/ws/lib/websocket.js +1421 -0
  33. package/dinou/node_modules/ws/package.json +74 -0
  34. package/dinou/node_modules/ws/wrapper.mjs +21 -0
  35. package/dinou/package.json +48 -48
  36. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +32 -7
  37. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +44 -6
  38. package/dinou/webpack/helpers/get-webpack-entries.js +24 -4
  39. package/dinou/webpack/helpers/patch-webpack-internals.js +35 -0
  40. package/dinou/webpack/plugins/server-functions-plugin.js +44 -2
  41. package/dinou/webpack/webpack.config.js +2 -0
  42. package/package.json +48 -48
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "ws",
3
+ "version": "8.22.0",
4
+ "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
5
+ "keywords": [
6
+ "HyBi",
7
+ "Push",
8
+ "RFC-6455",
9
+ "WebSocket",
10
+ "WebSockets",
11
+ "real-time"
12
+ ],
13
+ "homepage": "https://github.com/websockets/ws",
14
+ "bugs": "https://github.com/websockets/ws/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/websockets/ws.git"
18
+ },
19
+ "author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
20
+ "license": "MIT",
21
+ "main": "index.js",
22
+ "exports": {
23
+ ".": {
24
+ "browser": "./browser.js",
25
+ "import": "./wrapper.mjs",
26
+ "require": "./index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "browser": "browser.js",
31
+ "engines": {
32
+ "node": ">=10.0.0"
33
+ },
34
+ "files": [
35
+ "browser.js",
36
+ "index.js",
37
+ "lib/*.js",
38
+ "wrapper.mjs"
39
+ ],
40
+ "scripts": {
41
+ "test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js",
42
+ "integration": "mocha --throw-deprecation test/*.integration.js",
43
+ "lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
44
+ },
45
+ "peerDependencies": {
46
+ "bufferutil": "^4.0.1",
47
+ "utf-8-validate": ">=5.0.2"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "bufferutil": {
51
+ "optional": true
52
+ },
53
+ "utf-8-validate": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@eslint/js": "^10.0.1",
59
+ "benchmark": "^2.1.4",
60
+ "bufferutil": "^4.0.1",
61
+ "eslint": "^10.0.1",
62
+ "eslint-config-prettier": "^10.0.1",
63
+ "eslint-plugin-prettier": "^5.0.0",
64
+ "globals": "^17.0.0",
65
+ "mocha": "^8.4.0",
66
+ "nyc": "^15.0.0",
67
+ "prettier": "^3.0.0",
68
+ "utf-8-validate": "^6.0.0"
69
+ },
70
+ "allowScripts": {
71
+ "bufferutil": true,
72
+ "utf-8-validate": true
73
+ }
74
+ }
@@ -0,0 +1,21 @@
1
+ import createWebSocketStream from './lib/stream.js';
2
+ import extension from './lib/extension.js';
3
+ import PerMessageDeflate from './lib/permessage-deflate.js';
4
+ import Receiver from './lib/receiver.js';
5
+ import Sender from './lib/sender.js';
6
+ import subprotocol from './lib/subprotocol.js';
7
+ import WebSocket from './lib/websocket.js';
8
+ import WebSocketServer from './lib/websocket-server.js';
9
+
10
+ export {
11
+ createWebSocketStream,
12
+ extension,
13
+ PerMessageDeflate,
14
+ Receiver,
15
+ Sender,
16
+ subprotocol,
17
+ WebSocket,
18
+ WebSocketServer
19
+ };
20
+
21
+ export default WebSocket;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "8.0.3",
3
+ "version": "8.1.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "private": true,
@@ -34,54 +34,54 @@
34
34
  "test": "echo \"Error: no test specified\" && exit 1"
35
35
  },
36
36
  "dependencies": {
37
- "@babel/core": "^7.27.4",
38
- "@babel/parser": "^7.28.3",
39
- "@babel/plugin-syntax-import-meta": "^7.10.4",
40
- "@babel/preset-react": "^7.27.1",
41
- "@babel/preset-typescript": "^7.27.1",
42
- "@babel/traverse": "^7.28.3",
43
- "@esbuild-plugins/tsconfig-paths": "^0.1.2",
44
- "@roggc/react-server-dom-esm": "^19.3.0",
45
- "@rollup/plugin-babel": "^6.0.4",
46
- "@rollup/plugin-commonjs": "^28.0.6",
47
- "@rollup/plugin-json": "^6.1.0",
48
- "@rollup/plugin-node-resolve": "^16.0.1",
49
- "@rollup/plugin-replace": "^6.0.2",
50
- "@swc/core": "^1.15.10",
51
- "@tailwindcss/postcss": "^4.1.10",
52
- "autoprefixer": "^10.4.21",
53
- "babel-loader": "^10.0.0",
54
- "babel-plugin-react-compiler": "^1.0.0",
55
- "chokidar": "^4.0.3",
56
- "commander": "^14.0.0",
57
- "copy-webpack-plugin": "^14.0.0",
58
- "cross-env": "^7.0.3",
59
- "css-loader": "^7.1.2",
60
- "dotenv": "^16.5.0",
61
- "esbuild": "^0.27.0",
62
- "esbuild-copy-static-files": "^0.1.0",
63
- "generic-names": "^4.0.0",
64
- "mini-css-extract-plugin": "^2.9.4",
65
- "postcss": "^8.5.5",
66
- "postcss-import": "^16.1.1",
67
- "postcss-loader": "^8.2.0",
68
- "postcss-modules": "^6.0.1",
69
- "react-refresh": "^0.17.0",
70
- "react-server-dom-webpack": "^19.3.0",
71
- "rollup": "^4.46.2",
72
- "rollup-plugin-copy": "^3.5.0",
73
- "rollup-plugin-delete": "^3.0.1",
74
- "rollup-plugin-postcss": "^4.0.2",
75
- "rollup-plugin-tsconfig-paths": "^1.5.2",
76
- "tailwindcss": "^4.1.10",
77
- "tsconfig-paths-webpack-plugin": "^4.2.0",
78
- "webpack": "^5.103.0",
79
- "webpack-cli": "^6.0.1",
80
- "webpack-dev-server": "^5.2.2",
81
- "ws": "^8.18.3"
37
+ "@babel/core": "7.29.7",
38
+ "@babel/parser": "7.29.11",
39
+ "@babel/plugin-syntax-import-meta": "7.10.4",
40
+ "@babel/preset-react": "7.29.7",
41
+ "@babel/preset-typescript": "7.29.7",
42
+ "@babel/traverse": "7.29.10",
43
+ "@esbuild-plugins/tsconfig-paths": "0.1.2",
44
+ "@roggc/react-server-dom-esm": "19.3.1",
45
+ "@rollup/plugin-babel": "6.1.0",
46
+ "@rollup/plugin-commonjs": "28.0.9",
47
+ "@rollup/plugin-json": "6.1.0",
48
+ "@rollup/plugin-node-resolve": "16.0.3",
49
+ "@rollup/plugin-replace": "6.0.3",
50
+ "@swc/core": "1.16.20",
51
+ "@tailwindcss/postcss": "4.3.3",
52
+ "autoprefixer": "10.6.1",
53
+ "babel-loader": "10.1.1",
54
+ "babel-plugin-react-compiler": "1.0.0",
55
+ "chokidar": "4.0.3",
56
+ "commander": "14.0.3",
57
+ "copy-webpack-plugin": "14.0.0",
58
+ "cross-env": "7.0.3",
59
+ "css-loader": "7.1.5",
60
+ "dotenv": "16.6.1",
61
+ "esbuild": "0.27.7",
62
+ "esbuild-copy-static-files": "0.1.0",
63
+ "generic-names": "4.0.0",
64
+ "mini-css-extract-plugin": "2.10.2",
65
+ "postcss": "8.5.31",
66
+ "postcss-import": "16.2.0",
67
+ "postcss-loader": "8.2.1",
68
+ "postcss-modules": "6.0.1",
69
+ "react-refresh": "0.17.0",
70
+ "react-server-dom-webpack": "19.3.1",
71
+ "rollup": "4.65.0",
72
+ "rollup-plugin-copy": "3.5.0",
73
+ "rollup-plugin-delete": "3.0.2",
74
+ "rollup-plugin-postcss": "4.0.2",
75
+ "rollup-plugin-tsconfig-paths": "1.5.2",
76
+ "tailwindcss": "4.3.3",
77
+ "tsconfig-paths-webpack-plugin": "4.2.0",
78
+ "webpack": "5.112.2",
79
+ "webpack-cli": "6.0.1",
80
+ "webpack-dev-server": "5.2.7",
81
+ "ws": "8.22.0"
82
82
  },
83
83
  "peerDependencies": {
84
- "react": ">=19.3.0",
85
- "react-dom": ">=19.3.0"
84
+ "react": ">=19.3.1",
85
+ "react-dom": ">=19.3.1"
86
86
  }
87
87
  }
@@ -9,6 +9,7 @@ import { regex } from "../../core/asset-extensions.js";
9
9
  import createScopedName from "../../core/createScopedName.js";
10
10
  import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
11
11
  import { useClientRegex, useServerRegex } from "../../constants.js";
12
+ import { hasServerFunctions } from "../../core/transform-server-functions.js";
12
13
  import parseExports from "../../core/parse-exports.js";
13
14
 
14
15
  const require = createRequire(import.meta.url);
@@ -87,7 +88,8 @@ const urlToManifestKeys = new Map();
87
88
  const defaultExportCache = new Map();
88
89
 
89
90
  function normalizeFsPath(p) {
90
- return path.resolve(p).replace(/\\/g, "/").toLowerCase();
91
+ const resolved = path.resolve(p).replace(/\\/g, "/");
92
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
91
93
  }
92
94
 
93
95
  function alignDrive(p) {
@@ -289,6 +291,13 @@ function setManifestEntry(fileUrl, expName, entry) {
289
291
  continue;
290
292
  }
291
293
 
294
+ if (useServerRegex.test(importCode.trim())) {
295
+ serverFiles.add(normalizeFsPath(absImportPathWithExt));
296
+ continue;
297
+ } else if (hasServerFunctions(importCode)) {
298
+ serverFiles.add(normalizeFsPath(absImportPathWithExt));
299
+ }
300
+
292
301
  const nested = await getImportsAndAssetsAndCsss(
293
302
  importCode,
294
303
  absImportPathWithExt,
@@ -337,7 +346,12 @@ function setManifestEntry(fileUrl, expName, entry) {
337
346
 
338
347
  function isPageOrLayout(absPath) {
339
348
  const fileName = path.basename(absPath);
340
- return fileName.startsWith("page.") || fileName.startsWith("layout.");
349
+ return (
350
+ fileName.startsWith("page.") ||
351
+ fileName.startsWith("layout.") ||
352
+ fileName.startsWith("page_functions.") ||
353
+ fileName.startsWith("layout_functions.")
354
+ );
341
355
  }
342
356
 
343
357
  let isInitial = true;
@@ -435,10 +449,6 @@ function setManifestEntry(fileUrl, expName, entry) {
435
449
  const normKey = normalizeFsPath(normAbs);
436
450
  const code = readFileSync(normAbs, "utf8");
437
451
  const isClientModule = useClientRegex.test(code.trim());
438
- const isServerModule = useServerRegex.test(code.trim());
439
- if (isServerModule) {
440
- serverFiles.add(normKey);
441
- }
442
452
 
443
453
  if (isClientModule) {
444
454
  clientModules.add(normKey);
@@ -454,8 +464,20 @@ function setManifestEntry(fileUrl, expName, entry) {
454
464
  name: chunkName,
455
465
  });
456
466
  }
467
+ try {
468
+ await getImportsAndAssetsAndCsss(
469
+ code,
470
+ normAbs,
471
+ new Set(),
472
+ this,
473
+ sharedAstCache
474
+ );
475
+ } catch (e) {}
457
476
  } else if (isPageOrLayout(normAbs)) {
458
477
  serverModules.add(normKey);
478
+ if (useServerRegex.test(code.trim()) || hasServerFunctions(code)) {
479
+ serverFiles.add(normKey);
480
+ }
459
481
  this.addWatchFile(normAbs);
460
482
  const { imports, assets, csss } = await getImportsAndAssetsAndCsss(
461
483
  code,
@@ -550,7 +572,7 @@ function setManifestEntry(fileUrl, expName, entry) {
550
572
  }
551
573
  const code = readFileSync(normAbs, "utf8");
552
574
  const isClientModule = useClientRegex.test(code.trim());
553
- const isServerModule = useServerRegex.test(code.trim());
575
+ const isServerModule = useServerRegex.test(code.trim()) || hasServerFunctions(code);
554
576
  if (isServerModule) {
555
577
  serverFiles.add(normId);
556
578
  } else {
@@ -565,6 +587,9 @@ function setManifestEntry(fileUrl, expName, entry) {
565
587
  knownClientChunks.set(normId, { id: normAbs, name: chunkName });
566
588
  serverModules.delete(normId);
567
589
  this.addWatchFile(normAbs);
590
+ try {
591
+ await getImportsAndAssetsAndCsss(code, normAbs, new Set(), this);
592
+ } catch (e) {}
568
593
  } else {
569
594
  clientModules.delete(normId);
570
595
  knownClientChunks.delete(normId);
@@ -4,6 +4,7 @@ import fs from "node:fs/promises";
4
4
  import manifestGeneratorPlugin from "./manifest-generator-plugin.js";
5
5
  import parseExports from "../../core/parse-exports.js";
6
6
  import { useServerRegex } from "../../constants.js";
7
+ import { extractServerFunctions, hasServerFunctions } from "../../core/transform-server-functions.js";
7
8
 
8
9
  function serverFunctionsPlugin(manifestData = {}, options = {}) {
9
10
  const opts =
@@ -18,18 +19,24 @@ function serverFunctionsPlugin(manifestData = {}, options = {}) {
18
19
  const serverFunctions = new Map(); // Collect here: Map<relativePath, Set<exports>>
19
20
 
20
21
  function normalizeFsPath(p) {
21
- return path.resolve(p).replace(/\\/g, "/").toLowerCase();
22
+ const resolved = path.resolve(p).replace(/\\/g, "/");
23
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
22
24
  }
23
25
 
24
26
  return {
25
27
  name: "server-functions-proxy",
26
28
  transform(code, id) {
27
29
  if (id.includes("node_modules") || id.includes("\0")) return null;
28
- if (serverFiles && !serverFiles.has(normalizeFsPath(id))) return null;
29
- if (!useServerRegex.test(code)) return null;
30
+ if (serverFiles && !serverFiles.has(normalizeFsPath(id))) {
31
+ if (!useServerRegex.test(code.trim()) && !hasServerFunctions(code)) return null;
32
+ serverFiles.add(normalizeFsPath(id));
33
+ } else if (!useServerRegex.test(code.trim()) && !hasServerFunctions(code)) {
34
+ return null;
35
+ }
30
36
 
31
- const exports = parseExports(code);
32
- if (exports.length === 0) return null;
37
+ const isModuleLevel = useServerRegex.test(code.trim());
38
+ const exports = isModuleLevel ? parseExports(code) : extractServerFunctions(code, id);
39
+ if (!exports || exports.length === 0) return null;
33
40
 
34
41
  const relativePath = path.relative(root, id).replace(/\\/g, "/");
35
42
  serverFunctions.set(relativePath, new Set(exports)); // Save exports as a Set for uniqueness
@@ -62,15 +69,46 @@ function serverFunctionsPlugin(manifestData = {}, options = {}) {
62
69
  },
63
70
  // 🪄 After manifest exists, replace the placeholder with the final URL
64
71
  async generateBundle(options, bundle) {
72
+ if (serverFiles && serverFiles.size > 0) {
73
+ for (const filePath of serverFiles) {
74
+ const rel = path.relative(root, filePath).replace(/\\/g, "/");
75
+ if (!serverFunctions.has(rel)) {
76
+ try {
77
+ const fileCode = await fs.readFile(filePath, "utf8");
78
+ if (useServerRegex.test(fileCode.trim())) {
79
+ const exports = parseExports(fileCode);
80
+ if (exports && exports.length > 0) {
81
+ serverFunctions.set(rel, new Set(exports));
82
+ }
83
+ } else if (hasServerFunctions(fileCode)) {
84
+ const actions = extractServerFunctions(fileCode, filePath);
85
+ if (actions && actions.length > 0) {
86
+ serverFunctions.set(rel, new Set(actions));
87
+ }
88
+ }
89
+ } catch (e) {}
90
+ }
91
+ }
92
+ }
93
+
65
94
  if (serverFunctions.size === 0) {
66
95
  if (typeof globalThis !== "undefined") {
67
96
  globalThis.__DINOU_RAW_SERVER_FUNCTIONS_MANIFEST__ = {};
68
97
  }
69
98
  return;
70
99
  }
100
+ const isProd =
101
+ process.env.NODE_ENV === "production" &&
102
+ process.env.DINOU_DEV !== "true";
71
103
  const manifest = manifestGeneratorPlugin.manifestData;
104
+ const proxyName = manifest["serverFunctionProxy.js"];
105
+ if (isProd && !proxyName) {
106
+ throw new Error(
107
+ "[Dinou] rollup-plugin-server-functions: could not find hashed 'serverFunctionProxy.js' in manifest during production build."
108
+ );
109
+ }
72
110
  const hashedPath =
73
- "/" + (manifest["serverFunctionProxy.js"] || "serverFunctionProxy.js");
111
+ "/" + (proxyName || "serverFunctionProxy.js");
74
112
 
75
113
  for (const file of Object.keys(bundle)) {
76
114
  const chunk = bundle[file];
@@ -8,6 +8,7 @@ import crypto from "node:crypto";
8
8
  import { regex as assetRegex } from "../../core/asset-extensions.js";
9
9
  import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
10
10
  import { useClientRegex, useServerRegex } from "../../constants.js";
11
+ import { hasServerFunctions } from "../../core/transform-server-functions.js";
11
12
 
12
13
  const traverse = typeof _traverseRaw === "function" ? _traverseRaw : (_traverseRaw.default || _traverseRaw);
13
14
 
@@ -85,11 +86,22 @@ async function getCSSEntries({
85
86
  if (isImportedFileClient) {
86
87
  continue; // Do not recursively process client components
87
88
  }
89
+
90
+ const isImportedFileServer = useServerRegex.test(importedCode.trim());
91
+ if (isImportedFileServer) {
92
+ serverFiles.add(path.resolve(absImportPathWithExt).replace(/\\/g, "/").toLowerCase());
93
+ continue;
94
+ } else if (hasServerFunctions(importedCode)) {
95
+ serverFiles.add(path.resolve(absImportPathWithExt).replace(/\\/g, "/").toLowerCase());
96
+ }
88
97
  } else {
89
98
  const isImportedFileServer = useServerRegex.test(importedCode.trim());
90
99
 
91
100
  if (isImportedFileServer) {
101
+ serverFiles.add(path.resolve(absImportPathWithExt).replace(/\\/g, "/").toLowerCase());
92
102
  continue;
103
+ } else if (hasServerFunctions(importedCode)) {
104
+ serverFiles.add(path.resolve(absImportPathWithExt).replace(/\\/g, "/").toLowerCase());
93
105
  }
94
106
  }
95
107
 
@@ -138,7 +150,12 @@ async function getCSSEntries({
138
150
 
139
151
  function isPageOrLayout(absPath) {
140
152
  const fileName = path.basename(absPath);
141
- return fileName.startsWith("page.") || fileName.startsWith("layout.");
153
+ return (
154
+ fileName.startsWith("page.") ||
155
+ fileName.startsWith("layout.") ||
156
+ fileName.startsWith("page_functions.") ||
157
+ fileName.startsWith("layout_functions.")
158
+ );
142
159
  }
143
160
 
144
161
 
@@ -157,9 +174,6 @@ async function getCSSEntries({
157
174
  }
158
175
  const code = readFileSync(absPath, "utf8");
159
176
  const trimmed = code.trim();
160
- if (useServerRegex.test(trimmed)) {
161
- serverFiles.add(path.resolve(absPath).replace(/\\/g, "/").toLowerCase());
162
- }
163
177
  const isClientModule = useClientRegex.test(trimmed);
164
178
  const normalizedPath = normalizePath(absPath);
165
179
 
@@ -170,7 +184,13 @@ async function getCSSEntries({
170
184
  absPath: normalizedPath,
171
185
  name,
172
186
  });
187
+ try {
188
+ await getImportsAndAssetsAndCsss(code, absPath, new Set(), true);
189
+ } catch (err) {}
173
190
  } else if (isPageOrLayout(absPath)) {
191
+ if (hasServerFunctions(code)) {
192
+ serverFiles.add(path.resolve(absPath).replace(/\\/g, "/").toLowerCase());
193
+ }
174
194
  try {
175
195
  const { csss } = await getImportsAndAssetsAndCsss(code, absPath);
176
196
 
@@ -0,0 +1,35 @@
1
+ import module from "node:module";
2
+
3
+ // Compatibility shim for Webpack 5.112+ internal file reorganization with react-server-dom-webpack
4
+ const originalResolveFilename = module._resolveFilename;
5
+ if (originalResolveFilename) {
6
+ module._resolveFilename = function (request, parent, isMain, options) {
7
+ if (request === "webpack/lib/dependencies/ModuleDependency") {
8
+ try {
9
+ return originalResolveFilename.call(this, request, parent, isMain, options);
10
+ } catch {
11
+ return originalResolveFilename.call(
12
+ this,
13
+ "webpack/lib/dependencies/core/ModuleDependency",
14
+ parent,
15
+ isMain,
16
+ options
17
+ );
18
+ }
19
+ }
20
+ if (request === "webpack/lib/Template") {
21
+ try {
22
+ return originalResolveFilename.call(this, request, parent, isMain, options);
23
+ } catch {
24
+ return originalResolveFilename.call(
25
+ this,
26
+ "webpack/lib/template/Template",
27
+ parent,
28
+ isMain,
29
+ options
30
+ );
31
+ }
32
+ }
33
+ return originalResolveFilename.call(this, request, parent, isMain, options);
34
+ };
35
+ }
@@ -1,9 +1,14 @@
1
1
  import path from "node:path";
2
+ import fs from "node:fs";
2
3
  import manifestGeneratorPlugin from "./manifest-generator-plugin.js";
4
+ import parseExports from "../../core/parse-exports.js";
5
+ import { useServerRegex } from "../../constants.js";
6
+ import { extractServerFunctions, hasServerFunctions } from "../../core/transform-server-functions.js";
3
7
 
4
8
  class WebpackServerFunctionsPluginSimple {
5
- constructor() {
9
+ constructor(options = {}) {
6
10
  this.serverFunctions = new Map();
11
+ this.serverFiles = options.serverFiles || null;
7
12
  }
8
13
 
9
14
  apply(compiler) {
@@ -45,6 +50,34 @@ class WebpackServerFunctionsPluginSimple {
45
50
  }
46
51
  }
47
52
 
53
+ if (this.serverFiles && this.serverFiles.size > 0) {
54
+ for (const filePath of this.serverFiles) {
55
+ const rel = path.relative(process.cwd(), filePath).replace(/\\/g, "/");
56
+ if (!serverFunctionsManifest[rel]) {
57
+ try {
58
+ const fileCode = fs.readFileSync(filePath, "utf8");
59
+ if (useServerRegex.test(fileCode.trim())) {
60
+ const exports = parseExports(fileCode);
61
+ if (exports && exports.length > 0) {
62
+ serverFunctionsManifest[rel] = exports;
63
+ serverFunctionPaths.add(
64
+ path.resolve(process.cwd(), rel).replace(/\\/g, "/").toLowerCase()
65
+ );
66
+ }
67
+ } else if (hasServerFunctions(fileCode)) {
68
+ const actions = extractServerFunctions(fileCode, filePath);
69
+ if (actions && actions.length > 0) {
70
+ serverFunctionsManifest[rel] = actions;
71
+ serverFunctionPaths.add(
72
+ path.resolve(process.cwd(), rel).replace(/\\/g, "/").toLowerCase()
73
+ );
74
+ }
75
+ }
76
+ } catch (e) {}
77
+ }
78
+ }
79
+ }
80
+
48
81
  // 2. Generate final manifest
49
82
  const manifestContent = JSON.stringify(
50
83
  serverFunctionsManifest,
@@ -105,8 +138,17 @@ class WebpackServerFunctionsPluginSimple {
105
138
  }
106
139
 
107
140
  // 5. Replace placeholder ONLY in chunks that actually contain server functions
141
+ const isProd =
142
+ process.env.NODE_ENV === "production" &&
143
+ process.env.DINOU_DEV !== "true";
108
144
  const manifest = manifestGeneratorPlugin.manifestData;
109
- const hashedPath = manifest["serverFunctionProxy.js"] || "serverFunctionProxy.js";
145
+ const proxyName = manifest["serverFunctionProxy.js"];
146
+ if (isProd && !proxyName) {
147
+ throw new Error(
148
+ "[Dinou] webpack serverFunctionsPlugin: could not find hashed 'serverFunctionProxy.js' in manifest during production build."
149
+ );
150
+ }
151
+ const hashedPath = proxyName || "serverFunctionProxy.js";
110
152
 
111
153
  for (const filename of targetAssetFiles) {
112
154
  if (filename.endsWith(".js") && assets[filename]) {
@@ -1,3 +1,4 @@
1
+ import "./helpers/patch-webpack-internals.js";
1
2
  import "dotenv/config";
2
3
  import path from "node:path";
3
4
  import fs from "node:fs";
@@ -336,6 +337,7 @@ export default async () => {
336
337
  }),
337
338
  new ServerFunctionsPlugin({
338
339
  manifest: manifestGeneratorPlugin.manifestData,
340
+ serverFiles,
339
341
  }),
340
342
  isDevelopment && new WebpackMemoryPlugin(),
341
343
  !isDevelopment && {