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.
- package/CHANGELOG.md +27 -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 +49 -9
- package/dinou/node_modules/ws/LICENSE +20 -0
- package/dinou/node_modules/ws/README.md +548 -0
- package/dinou/node_modules/ws/browser.js +8 -0
- package/dinou/node_modules/ws/index.js +22 -0
- package/dinou/node_modules/ws/lib/buffer-util.js +131 -0
- package/dinou/node_modules/ws/lib/constants.js +19 -0
- package/dinou/node_modules/ws/lib/event-target.js +292 -0
- package/dinou/node_modules/ws/lib/extension.js +203 -0
- package/dinou/node_modules/ws/lib/limiter.js +55 -0
- package/dinou/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/dinou/node_modules/ws/lib/receiver.js +743 -0
- package/dinou/node_modules/ws/lib/sender.js +607 -0
- package/dinou/node_modules/ws/lib/stream.js +161 -0
- package/dinou/node_modules/ws/lib/subprotocol.js +62 -0
- package/dinou/node_modules/ws/lib/validation.js +152 -0
- package/dinou/node_modules/ws/lib/websocket-server.js +562 -0
- package/dinou/node_modules/ws/lib/websocket.js +1421 -0
- package/dinou/node_modules/ws/package.json +74 -0
- package/dinou/node_modules/ws/wrapper.mjs +21 -0
- 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";
|
|
@@ -176,6 +177,15 @@ async function findClientComponents(parsedClientManifest = {}) {
|
|
|
176
177
|
const content = fs.readFileSync(full, "utf8");
|
|
177
178
|
if (useClientRegex.test(content.trim()) && isSupportedClientModule(full, content)) {
|
|
178
179
|
clientFiles.add(path.resolve(full));
|
|
180
|
+
} else if (useServerRegex.test(content.trim())) {
|
|
181
|
+
knownServerFiles.add(path.resolve(full));
|
|
182
|
+
} else if (hasServerFunctions(content)) {
|
|
183
|
+
try {
|
|
184
|
+
const sfRes = transformServerFunctions(content, full);
|
|
185
|
+
if (sfRes?.actions?.length > 0) {
|
|
186
|
+
knownServerFiles.add(path.resolve(full));
|
|
187
|
+
}
|
|
188
|
+
} catch (e) {}
|
|
179
189
|
}
|
|
180
190
|
} catch (e) {}
|
|
181
191
|
}
|
|
@@ -584,7 +594,6 @@ async function updateManifestsState(options = {}) {
|
|
|
584
594
|
}
|
|
585
595
|
}
|
|
586
596
|
|
|
587
|
-
knownServerFiles.clear();
|
|
588
597
|
for (const f of Object.keys(parsedServerFunctionsManifest)) {
|
|
589
598
|
knownServerFiles.add(path.resolve(projectRoot, f));
|
|
590
599
|
}
|
|
@@ -1225,14 +1234,18 @@ const serverReferencesPlugin = {
|
|
|
1225
1234
|
return getCachedFileTransform(args.path, "server-ref-rsc", () => {
|
|
1226
1235
|
let code;
|
|
1227
1236
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
1228
|
-
if (!
|
|
1237
|
+
if (!hasServerFunctions(code)) return null;
|
|
1229
1238
|
|
|
1230
|
-
const
|
|
1239
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
1240
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1241
|
+
|
|
1242
|
+
const transformedCode = sfResult.code;
|
|
1243
|
+
const exports = sfResult.actions;
|
|
1231
1244
|
const absPath = path.resolve(args.path);
|
|
1232
1245
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1233
1246
|
const relativeFileUrl = "file:///" + relPath;
|
|
1234
1247
|
|
|
1235
|
-
let transformed =
|
|
1248
|
+
let transformed = transformedCode + "\n\n";
|
|
1236
1249
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
1237
1250
|
for (const name of exports) {
|
|
1238
1251
|
if (name !== "default") {
|
|
@@ -1255,14 +1268,18 @@ const serverReferencesPluginSsr = {
|
|
|
1255
1268
|
return getCachedFileTransform(args.path, "server-ref-ssr", () => {
|
|
1256
1269
|
let code;
|
|
1257
1270
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
1258
|
-
if (!
|
|
1271
|
+
if (!hasServerFunctions(code)) return null;
|
|
1259
1272
|
|
|
1260
|
-
const
|
|
1273
|
+
const sfResult = transformServerFunctions(code, args.path);
|
|
1274
|
+
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1275
|
+
|
|
1276
|
+
const transformedCode = sfResult.code;
|
|
1277
|
+
const exports = sfResult.actions;
|
|
1261
1278
|
const absPath = path.resolve(args.path);
|
|
1262
1279
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1263
1280
|
const relativeFileUrl = "file:///" + relPath;
|
|
1264
1281
|
|
|
1265
|
-
let transformed =
|
|
1282
|
+
let transformed = transformedCode + "\n\n";
|
|
1266
1283
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1267
1284
|
for (const name of exports) {
|
|
1268
1285
|
if (name !== "default") {
|
|
@@ -1753,7 +1770,16 @@ async function doRebuildBatch(changesMap) {
|
|
|
1753
1770
|
try {
|
|
1754
1771
|
const content = fs.readFileSync(absFilePath, "utf8");
|
|
1755
1772
|
isClientFile = useClientRegex.test(content.trim());
|
|
1756
|
-
|
|
1773
|
+
if (useServerRegex.test(content.trim())) {
|
|
1774
|
+
isServerFile = true;
|
|
1775
|
+
} else if (hasServerFunctions(content)) {
|
|
1776
|
+
try {
|
|
1777
|
+
const sfRes = transformServerFunctions(content, absFilePath);
|
|
1778
|
+
isServerFile = Boolean(sfRes?.actions?.length > 0);
|
|
1779
|
+
} catch (e) {
|
|
1780
|
+
isServerFile = false;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1757
1783
|
} catch (e) {}
|
|
1758
1784
|
}
|
|
1759
1785
|
|
|
@@ -1763,18 +1789,32 @@ async function doRebuildBatch(changesMap) {
|
|
|
1763
1789
|
const wasServerFile = knownServerFiles.has(absFilePath);
|
|
1764
1790
|
const serverDirectiveChanged = isServerFile !== wasServerFile;
|
|
1765
1791
|
|
|
1792
|
+
if (isClientFile) {
|
|
1793
|
+
knownClientFiles.add(absFilePath);
|
|
1794
|
+
} else {
|
|
1795
|
+
knownClientFiles.delete(absFilePath);
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
if (isServerFile) {
|
|
1799
|
+
knownServerFiles.add(absFilePath);
|
|
1800
|
+
} else {
|
|
1801
|
+
knownServerFiles.delete(absFilePath);
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1766
1804
|
const isJsTsSource =
|
|
1767
1805
|
normLower.endsWith(".tsx") ||
|
|
1768
1806
|
normLower.endsWith(".jsx") ||
|
|
1769
1807
|
normLower.endsWith(".ts") ||
|
|
1770
1808
|
normLower.endsWith(".js");
|
|
1771
1809
|
|
|
1810
|
+
const isPageRoute = /(?:^|[\\/])(page|layout)\.[jt]sx?$/i.test(absFilePath);
|
|
1811
|
+
|
|
1772
1812
|
const isClientRelevant =
|
|
1773
1813
|
isClientFile ||
|
|
1774
1814
|
wasClientFile ||
|
|
1775
1815
|
clientDirectiveChanged ||
|
|
1776
1816
|
isCssFile ||
|
|
1777
|
-
isJsTsSource;
|
|
1817
|
+
(isJsTsSource && !isPageRoute);
|
|
1778
1818
|
|
|
1779
1819
|
if (isClientFile) {
|
|
1780
1820
|
getCachedFileExports(absFilePath);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
2
|
+
Copyright (c) 2013 Arnout Kazemier and contributors
|
|
3
|
+
Copyright (c) 2016 Luigi Pinca and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|