dinou 8.0.3 → 8.1.0
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/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dinou/bun/build.js +15 -6
- package/dinou/cloudflare/build.js +15 -6
- package/dinou/core/route-generator.js +1 -1
- package/dinou/core/transform-server-functions.js +291 -0
- package/dinou/deno/build.js +15 -6
- package/dinou/esbuild/build.js +7 -2
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +3 -3
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +17 -6
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +4 -2
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +43 -29
- package/dinou/index.js +1 -4
- package/dinou/node/bundle-dual-engine.js +15 -6
- package/dinou/node/dev.js +16 -7
- package/dinou/package.json +48 -48
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +32 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +44 -6
- package/dinou/webpack/helpers/get-webpack-entries.js +24 -4
- package/dinou/webpack/helpers/patch-webpack-internals.js +35 -0
- package/dinou/webpack/plugins/server-functions-plugin.js +44 -2
- package/dinou/webpack/webpack.config.js +2 -0
- package/package.json +48 -48
|
@@ -2,15 +2,12 @@ import path from "path";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import parseExports from "../../core/parse-exports.js";
|
|
4
4
|
import { useServerRegex } from "../../constants.js";
|
|
5
|
+
import { extractServerFunctions, hasServerFunctions } from "../../core/transform-server-functions.js";
|
|
5
6
|
|
|
6
|
-
export default function serverFunctionsPlugin(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
: options;
|
|
11
|
-
const manifestMap = opts.manifestData || (manifestData.onManifestUpdated ? {} : manifestData) || {};
|
|
12
|
-
const onManifestUpdated = opts.onManifestUpdated;
|
|
13
|
-
const serverFiles = opts.serverFiles || manifestData.serverFiles || options.serverFiles || null;
|
|
7
|
+
export default function serverFunctionsPlugin({
|
|
8
|
+
manifestData = {},
|
|
9
|
+
serverFiles = null,
|
|
10
|
+
} = {}) {
|
|
14
11
|
const normalizeNormPath = (p) => {
|
|
15
12
|
let s = path.resolve(p).replace(/\\/g, "/");
|
|
16
13
|
if (process.platform === "win32") {
|
|
@@ -135,15 +132,42 @@ export default function serverFunctionsPlugin(manifestData = {}, options = {}) {
|
|
|
135
132
|
build.onEnd(async (result) => {
|
|
136
133
|
const tEnd0 = Date.now();
|
|
137
134
|
try {
|
|
135
|
+
if (serverFilesSet && serverFilesSet.size > 0) {
|
|
136
|
+
for (const filePath of serverFilesSet) {
|
|
137
|
+
const rel = path.relative(root, filePath).replace(/\\/g, "/");
|
|
138
|
+
if (!serverFunctions.has(rel)) {
|
|
139
|
+
try {
|
|
140
|
+
const code = await fs.readFile(filePath, "utf8");
|
|
141
|
+
if (useServerRegex.test(code.trim())) {
|
|
142
|
+
const exports = parseExports(code);
|
|
143
|
+
if (exports && exports.length > 0) {
|
|
144
|
+
serverFunctions.set(rel, new Set(exports));
|
|
145
|
+
}
|
|
146
|
+
} else if (hasServerFunctions(code)) {
|
|
147
|
+
const actions = extractServerFunctions(code, filePath);
|
|
148
|
+
if (actions && actions.length > 0) {
|
|
149
|
+
serverFunctions.set(rel, new Set(actions));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
138
157
|
if (serverFunctions.size === 0) {
|
|
139
158
|
if (typeof globalThis !== "undefined") {
|
|
140
159
|
globalThis.__DINOU_RAW_SERVER_FUNCTIONS_MANIFEST__ = {};
|
|
141
160
|
}
|
|
142
161
|
return;
|
|
143
162
|
}
|
|
144
|
-
const
|
|
145
|
-
"
|
|
146
|
-
(
|
|
163
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
164
|
+
const proxyName = manifestData["serverFunctionProxy.js"];
|
|
165
|
+
if (isProd && !proxyName) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"[Dinou] serverFunctionsPlugin: could not find hashed 'serverFunctionProxy.js' in manifestData during production build."
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const hashedProxy = "/" + (proxyName || "serverFunctionProxy.js");
|
|
147
171
|
|
|
148
172
|
const serverFnNormalized = new Set();
|
|
149
173
|
for (const relPath of serverFunctions.keys()) {
|
|
@@ -151,32 +175,22 @@ export default function serverFunctionsPlugin(manifestData = {}, options = {}) {
|
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
let targetOutputFiles = Object.values(result.outputFiles || {});
|
|
154
|
-
if (result.metafile && result.metafile.outputs) {
|
|
155
|
-
const allowedOutputs = new Set();
|
|
156
|
-
for (const [outPath, outMeta] of Object.entries(result.metafile.outputs)) {
|
|
157
|
-
const hasSf = Object.keys(outMeta.inputs || {}).some((inPath) => {
|
|
158
|
-
const norm = path.resolve(root, inPath).replace(/\\/g, "/").toLowerCase();
|
|
159
|
-
return serverFnNormalized.has(norm);
|
|
160
|
-
});
|
|
161
|
-
if (hasSf) {
|
|
162
|
-
allowedOutputs.add(path.resolve(root, outPath).replace(/\\/g, "/").toLowerCase());
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
targetOutputFiles = targetOutputFiles.filter((outputFile) => {
|
|
166
|
-
const norm = path.resolve(outputFile.path).replace(/\\/g, "/").toLowerCase();
|
|
167
|
-
return allowedOutputs.has(norm);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
178
|
|
|
171
179
|
for (const outputFile of targetOutputFiles) {
|
|
172
180
|
const fileCode = new TextDecoder().decode(outputFile.contents);
|
|
173
181
|
|
|
174
182
|
if (!fileCode) continue;
|
|
175
|
-
if (fileCode.includes("/__SERVER_FUNCTION_PROXY__")) {
|
|
176
|
-
|
|
183
|
+
if (fileCode.includes("/__SERVER_FUNCTION_PROXY__") || (proxyName && fileCode.includes("/serverFunctionProxy.js"))) {
|
|
184
|
+
let newCode = fileCode.replace(
|
|
177
185
|
/\/__SERVER_FUNCTION_PROXY__/g,
|
|
178
186
|
hashedProxy
|
|
179
187
|
);
|
|
188
|
+
if (proxyName && proxyName !== "serverFunctionProxy.js") {
|
|
189
|
+
newCode = newCode.replace(
|
|
190
|
+
/\/serverFunctionProxy\.js/g,
|
|
191
|
+
hashedProxy
|
|
192
|
+
);
|
|
193
|
+
}
|
|
180
194
|
outputFile.contents = new TextEncoder().encode(newCode);
|
|
181
195
|
}
|
|
182
196
|
}
|
package/dinou/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defineConfig } from "./core/config.js";
|
|
1
2
|
import { getContext } from "./core/request-context.js";
|
|
2
3
|
import {
|
|
3
4
|
usePathname,
|
|
@@ -10,10 +11,6 @@ import { redirect } from "./core/redirect.jsx";
|
|
|
10
11
|
import { ClientRedirect } from "./core/client-redirect.jsx";
|
|
11
12
|
import { Link } from "./core/link.jsx";
|
|
12
13
|
|
|
13
|
-
function defineConfig(config) {
|
|
14
|
-
return config;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
14
|
const dinou = {
|
|
18
15
|
defineConfig,
|
|
19
16
|
getContext,
|
|
@@ -11,6 +11,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
11
11
|
import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
|
|
12
12
|
import parseExports from "../core/parse-exports.js";
|
|
13
13
|
import { useClientRegex, useServerRegex } from "../constants.js";
|
|
14
|
+
import { transformServerFunctions, hasServerFunctions } from "../core/transform-server-functions.js";
|
|
14
15
|
import createScopedName from "../core/createScopedName.js";
|
|
15
16
|
import { regex as assetRegex } from "../core/asset-extensions.js";
|
|
16
17
|
import {
|
|
@@ -885,14 +886,18 @@ var __webpack_chunk_load__ = function(chunkId) {
|
|
|
885
886
|
}
|
|
886
887
|
let code;
|
|
887
888
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
888
|
-
if (!
|
|
889
|
+
if (!hasServerFunctions(code)) return null;
|
|
889
890
|
|
|
890
|
-
const
|
|
891
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
892
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
893
|
+
|
|
894
|
+
const transformedCode = sfResult.code;
|
|
895
|
+
const exports = sfResult.actions;
|
|
891
896
|
const absPath = path.resolve(args.path);
|
|
892
897
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
893
898
|
const relativeFileUrl = "file:///" + relPath;
|
|
894
899
|
|
|
895
|
-
let transformed =
|
|
900
|
+
let transformed = transformedCode + "\n\n";
|
|
896
901
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
897
902
|
for (const name of exports) {
|
|
898
903
|
if (name !== "default") {
|
|
@@ -925,14 +930,18 @@ var __webpack_chunk_load__ = function(chunkId) {
|
|
|
925
930
|
}
|
|
926
931
|
let code;
|
|
927
932
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
928
|
-
if (!
|
|
933
|
+
if (!hasServerFunctions(code)) return null;
|
|
929
934
|
|
|
930
|
-
const
|
|
935
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
936
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
937
|
+
|
|
938
|
+
const transformedCode = sfResult.code;
|
|
939
|
+
const exports = sfResult.actions;
|
|
931
940
|
const absPath = path.resolve(args.path);
|
|
932
941
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
933
942
|
const relativeFileUrl = "file:///" + relPath;
|
|
934
943
|
|
|
935
|
-
let transformed =
|
|
944
|
+
let transformed = transformedCode + "\n\n";
|
|
936
945
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
937
946
|
for (const name of exports) {
|
|
938
947
|
if (name !== "default") {
|
package/dinou/node/dev.js
CHANGED
|
@@ -30,6 +30,7 @@ import { resolveSetupFiles } from "../core/resolve-setup-files.js";
|
|
|
30
30
|
import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
|
|
31
31
|
import parseExports from "../core/parse-exports.js";
|
|
32
32
|
import { useClientRegex, useServerRegex } from "../constants.js";
|
|
33
|
+
import { transformServerFunctions, hasServerFunctions } from "../core/transform-server-functions.js";
|
|
33
34
|
import { nodeToWebRequest, sendWebResponseToNode } from "../core/http-adapter.js";
|
|
34
35
|
import { setStorageAdapter, FileSystemStorage, MemoryStorage } from "../core/storage-adapter.js";
|
|
35
36
|
import createScopedName from "../core/createScopedName.js";
|
|
@@ -1225,14 +1226,18 @@ const serverReferencesPlugin = {
|
|
|
1225
1226
|
return getCachedFileTransform(args.path, "server-ref-rsc", () => {
|
|
1226
1227
|
let code;
|
|
1227
1228
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
1228
|
-
if (!
|
|
1229
|
+
if (!hasServerFunctions(code)) return null;
|
|
1229
1230
|
|
|
1230
|
-
const
|
|
1231
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
1232
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1233
|
+
|
|
1234
|
+
const transformedCode = sfResult.code;
|
|
1235
|
+
const exports = sfResult.actions;
|
|
1231
1236
|
const absPath = path.resolve(args.path);
|
|
1232
1237
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1233
1238
|
const relativeFileUrl = "file:///" + relPath;
|
|
1234
1239
|
|
|
1235
|
-
let transformed =
|
|
1240
|
+
let transformed = transformedCode + "\n\n";
|
|
1236
1241
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
1237
1242
|
for (const name of exports) {
|
|
1238
1243
|
if (name !== "default") {
|
|
@@ -1255,14 +1260,18 @@ const serverReferencesPluginSsr = {
|
|
|
1255
1260
|
return getCachedFileTransform(args.path, "server-ref-ssr", () => {
|
|
1256
1261
|
let code;
|
|
1257
1262
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
1258
|
-
if (!
|
|
1263
|
+
if (!hasServerFunctions(code)) return null;
|
|
1259
1264
|
|
|
1260
|
-
const
|
|
1265
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
1266
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1267
|
+
|
|
1268
|
+
const transformedCode = sfResult.code;
|
|
1269
|
+
const exports = sfResult.actions;
|
|
1261
1270
|
const absPath = path.resolve(args.path);
|
|
1262
1271
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1263
1272
|
const relativeFileUrl = "file:///" + relPath;
|
|
1264
1273
|
|
|
1265
|
-
let transformed =
|
|
1274
|
+
let transformed = transformedCode + "\n\n";
|
|
1266
1275
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1267
1276
|
for (const name of exports) {
|
|
1268
1277
|
if (name !== "default") {
|
|
@@ -1753,7 +1762,7 @@ async function doRebuildBatch(changesMap) {
|
|
|
1753
1762
|
try {
|
|
1754
1763
|
const content = fs.readFileSync(absFilePath, "utf8");
|
|
1755
1764
|
isClientFile = useClientRegex.test(content.trim());
|
|
1756
|
-
isServerFile = useServerRegex.test(content.trim());
|
|
1765
|
+
isServerFile = useServerRegex.test(content.trim()) || hasServerFunctions(content);
|
|
1757
1766
|
} catch (e) {}
|
|
1758
1767
|
}
|
|
1759
1768
|
|
package/dinou/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dinou-ejected",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
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": "
|
|
38
|
-
"@babel/parser": "
|
|
39
|
-
"@babel/plugin-syntax-import-meta": "
|
|
40
|
-
"@babel/preset-react": "
|
|
41
|
-
"@babel/preset-typescript": "
|
|
42
|
-
"@babel/traverse": "
|
|
43
|
-
"@esbuild-plugins/tsconfig-paths": "
|
|
44
|
-
"@roggc/react-server-dom-esm": "
|
|
45
|
-
"@rollup/plugin-babel": "
|
|
46
|
-
"@rollup/plugin-commonjs": "
|
|
47
|
-
"@rollup/plugin-json": "
|
|
48
|
-
"@rollup/plugin-node-resolve": "
|
|
49
|
-
"@rollup/plugin-replace": "
|
|
50
|
-
"@swc/core": "
|
|
51
|
-
"@tailwindcss/postcss": "
|
|
52
|
-
"autoprefixer": "
|
|
53
|
-
"babel-loader": "
|
|
54
|
-
"babel-plugin-react-compiler": "
|
|
55
|
-
"chokidar": "
|
|
56
|
-
"commander": "
|
|
57
|
-
"copy-webpack-plugin": "
|
|
58
|
-
"cross-env": "
|
|
59
|
-
"css-loader": "
|
|
60
|
-
"dotenv": "
|
|
61
|
-
"esbuild": "
|
|
62
|
-
"esbuild-copy-static-files": "
|
|
63
|
-
"generic-names": "
|
|
64
|
-
"mini-css-extract-plugin": "
|
|
65
|
-
"postcss": "
|
|
66
|
-
"postcss-import": "
|
|
67
|
-
"postcss-loader": "
|
|
68
|
-
"postcss-modules": "
|
|
69
|
-
"react-refresh": "
|
|
70
|
-
"react-server-dom-webpack": "
|
|
71
|
-
"rollup": "
|
|
72
|
-
"rollup-plugin-copy": "
|
|
73
|
-
"rollup-plugin-delete": "
|
|
74
|
-
"rollup-plugin-postcss": "
|
|
75
|
-
"rollup-plugin-tsconfig-paths": "
|
|
76
|
-
"tailwindcss": "
|
|
77
|
-
"tsconfig-paths-webpack-plugin": "
|
|
78
|
-
"webpack": "
|
|
79
|
-
"webpack-cli": "
|
|
80
|
-
"webpack-dev-server": "
|
|
81
|
-
"ws": "
|
|
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.
|
|
85
|
-
"react-dom": ">=19.3.
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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)))
|
|
29
|
-
|
|
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
|
|
32
|
-
|
|
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
|
-
"/" + (
|
|
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
|
|
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
|
+
}
|