dinou 9.0.2 → 9.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +379 -9742
  3. package/dinou/bun/build.js +38 -1
  4. package/{cli.js → dinou/cli.js} +8 -7
  5. package/dinou/cloudflare/build.js +37 -0
  6. package/dinou/core/bailout-proxy.js +2 -2
  7. package/dinou/core/build-static-pages.js +17 -7
  8. package/dinou/core/cache-revalidate.js +977 -152
  9. package/dinou/core/cache-slot.js +848 -103
  10. package/dinou/core/client-webpack.jsx +60 -9
  11. package/dinou/core/client.jsx +60 -9
  12. package/dinou/core/edge-ssr.js +33 -5
  13. package/dinou/core/generate-static.js +109 -47
  14. package/dinou/core/get-jsx.js +35 -27
  15. package/dinou/core/handler.js +786 -54
  16. package/dinou/core/layout-functions.js +102 -1
  17. package/dinou/core/no-dynamic.js +25 -0
  18. package/dinou/core/ppr-context.js +293 -10
  19. package/dinou/core/ppr-runtime.js +373 -37
  20. package/dinou/core/render-jsx-to-client-jsx.js +205 -74
  21. package/dinou/core/slot.js +246 -33
  22. package/dinou/core/storage-adapter.js +117 -11
  23. package/dinou/deno/build.js +38 -1
  24. package/dinou/deno/seed-kv.js +43 -11
  25. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -225
  26. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -226
  27. package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
  28. package/dinou/index.d.ts +10 -0
  29. package/dinou/index.js +3 -0
  30. package/dinou/node/build.js +2 -2
  31. package/dinou/node/bundle-dual-engine.js +2 -0
  32. package/dinou/node/dev.js +2853 -2704
  33. package/dinou/package.json +4 -1
  34. package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
  35. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -160
  36. package/dinou/server.d.ts +65 -12
  37. package/dinou/server.js +11 -0
  38. package/dinou/webpack/loaders/server-functions-loader.js +101 -94
  39. package/dinou/webpack/webpack.config.js +9 -4
  40. package/eject.js +219 -223
  41. package/package.json +2 -2
@@ -1,94 +1,101 @@
1
- import path from "node:path";
2
- import { normalizePathCase } from "../../core/path-utils.js";
3
- import parseExports from "../../core/parse-exports.js";
4
- import { useServerRegex } from "../../constants.js";
5
-
6
- export default function (source) {
7
- const options = this.getOptions ? this.getOptions() : {};
8
- const norm = path.resolve(this.resourcePath).replace(/\\/g, "/").toLowerCase();
9
-
10
- if (options.serverFiles) {
11
- if (!options.serverFiles.has(norm)) {
12
- if (!source.includes("use server")) {
13
- return source;
14
- }
15
- if (useServerRegex.test(source)) {
16
- options.serverFiles.add(norm);
17
- } else {
18
- return source;
19
- }
20
- }
21
- }
22
-
23
- let hasUseServer = false;
24
-
25
- if (useServerRegex.test(source)) {
26
- hasUseServer = true;
27
- }
28
-
29
- if (!hasUseServer) {
30
- if (options.serverFiles) {
31
- options.serverFiles.delete(norm);
32
- }
33
- return source;
34
- }
35
-
36
- const exports = parseExports(source);
37
- if (exports.length === 0) return source;
38
-
39
- // Build IDs
40
- const moduleId = this.resourcePath;
41
- const relativePath = path.relative(
42
- normalizePathCase(process.cwd()),
43
- normalizePathCase(moduleId)
44
- );
45
- const normalizedPath = relativePath.replace(/\\/g, "/");
46
-
47
- const fileUrl = `file:///${normalizedPath}`;
48
-
49
- //
50
- // IMPORTANT: dynamic import instead of static import
51
- //
52
- // Webpack will NOT try to resolve "__SERVER_FUNCTION_PROXY__"
53
- // as a module → it will remain a string → replaced later → browser loads it.
54
-
55
- let proxyCode = `
56
- const loadProxy = new Function('return import("/"+"__SERVER_FUNCTION_PROXY__")');
57
- `;
58
-
59
- for (const exp of exports) {
60
- const key = exp === "default" ? `${fileUrl}#default` : `${fileUrl}#${exp}`;
61
-
62
- if (exp === "default") {
63
- proxyCode += `
64
- export default (...args) =>
65
- loadProxy().then(mod =>
66
- (mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
67
- key,
68
- )})(...args)
69
- );
70
- `;
71
- } else {
72
- proxyCode += `
73
- export const ${exp} = (...args) =>
74
- loadProxy().then(mod => (mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
75
- key,
76
- )})(...args)
77
- );
78
- `;
79
- }
80
- }
81
-
82
- // Emit manifest entry
83
- const manifestEntry = {
84
- path: normalizedPath,
85
- exports: exports,
86
- };
87
-
88
- this.emitFile(
89
- `server-functions/${normalizedPath}.json`,
90
- JSON.stringify(manifestEntry, null, 2),
91
- );
92
-
93
- return proxyCode;
94
- };
1
+ import path from "node:path";
2
+ import { normalizePathCase } from "../../core/path-utils.js";
3
+ import parseExports from "../../core/parse-exports.js";
4
+ import { useClientRegex, useServerRegex } from "../../constants.js";
5
+ import { extractServerFunctions, hasServerFunctions } from "../../core/transform-server-functions.js";
6
+
7
+ export default function (source) {
8
+ const options = this.getOptions ? this.getOptions() : {};
9
+ const trimmed = source.trim();
10
+
11
+ if (useClientRegex.test(trimmed)) {
12
+ return source;
13
+ }
14
+
15
+ const norm = path.resolve(this.resourcePath).replace(/\\/g, "/").toLowerCase();
16
+
17
+ const isModuleLevel = useServerRegex.test(trimmed);
18
+ const hasBodyUseServer = !isModuleLevel && hasServerFunctions(source);
19
+
20
+ if (options.serverFiles) {
21
+ if (!options.serverFiles.has(norm)) {
22
+ if (!isModuleLevel && !hasBodyUseServer) {
23
+ return source;
24
+ }
25
+ options.serverFiles.add(norm);
26
+ }
27
+ }
28
+
29
+ if (!isModuleLevel && !hasBodyUseServer) {
30
+ if (options.serverFiles) {
31
+ options.serverFiles.delete(norm);
32
+ }
33
+ return source;
34
+ }
35
+
36
+ const exports = isModuleLevel
37
+ ? parseExports(source)
38
+ : extractServerFunctions(source, this.resourcePath);
39
+ if (!exports || exports.length === 0) {
40
+ if (options.serverFiles) {
41
+ options.serverFiles.delete(norm);
42
+ }
43
+ return source;
44
+ }
45
+
46
+ // Build IDs
47
+ const moduleId = this.resourcePath;
48
+ const relativePath = path.relative(
49
+ normalizePathCase(process.cwd()),
50
+ normalizePathCase(moduleId)
51
+ );
52
+ const normalizedPath = relativePath.replace(/\\/g, "/");
53
+
54
+ const fileUrl = `file:///${normalizedPath}`;
55
+
56
+ //
57
+ // IMPORTANT: dynamic import instead of static import
58
+ //
59
+ // Webpack will NOT try to resolve "__SERVER_FUNCTION_PROXY__"
60
+ // as a module → it will remain a string → replaced later → browser loads it.
61
+
62
+ let proxyCode = `
63
+ const loadProxy = new Function('return import("/"+"__SERVER_FUNCTION_PROXY__")');
64
+ `;
65
+
66
+ for (const exp of exports) {
67
+ const key = exp === "default" ? `${fileUrl}#default` : `${fileUrl}#${exp}`;
68
+
69
+ if (exp === "default") {
70
+ proxyCode += `
71
+ export default (...args) =>
72
+ loadProxy().then(mod =>
73
+ (mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
74
+ key,
75
+ )})(...args)
76
+ );
77
+ `;
78
+ } else {
79
+ proxyCode += `
80
+ export const ${exp} = (...args) =>
81
+ loadProxy().then(mod => (mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
82
+ key,
83
+ )})(...args)
84
+ );
85
+ `;
86
+ }
87
+ }
88
+
89
+ // Emit manifest entry
90
+ const manifestEntry = {
91
+ path: normalizedPath,
92
+ exports: exports,
93
+ };
94
+
95
+ this.emitFile(
96
+ `server-functions/${normalizedPath}.json`,
97
+ JSON.stringify(manifestEntry, null, 2),
98
+ );
99
+
100
+ return proxyCode;
101
+ };
@@ -292,6 +292,12 @@ export default async () => {
292
292
  const NormalModule = compiler.webpack ? compiler.webpack.NormalModule : webpack.NormalModule;
293
293
  const hooks = NormalModule.getCompilationHooks(compilation);
294
294
  hooks.needBuild.tap("DinouReactServerWatchPlugin", (module) => {
295
+ if (module.resource) {
296
+ const normRes = path.resolve(module.resource).replace(/\\/g, "/").toLowerCase();
297
+ if (globalThis.__DINOU_WEBPACK_MODIFIED_FILES__?.has(normRes)) {
298
+ return true;
299
+ }
300
+ }
295
301
  if (
296
302
  module.resource &&
297
303
  (module.resource.includes("client.browser") ||
@@ -408,6 +414,7 @@ export default async () => {
408
414
  },
409
415
  },
410
416
  watchOptions: {
417
+ aggregateTimeout: 20,
411
418
  ignored: [
412
419
  "**/node_modules/**",
413
420
  "**/.git/**",
@@ -425,7 +432,7 @@ export default async () => {
425
432
  devServer: {
426
433
  port: Number(process.env.HMR_PORT || (Number(process.env.PORT || 3000) + 1)),
427
434
  hot: false,
428
- liveReload: true,
435
+ liveReload: process.env.DINOU_STANDALONE_SERVER === "true",
429
436
  client: {
430
437
  webSocketURL: `ws://localhost:${process.env.HMR_PORT || (Number(process.env.PORT || 3000) + 1)}/ws`,
431
438
  overlay: false,
@@ -434,9 +441,7 @@ export default async () => {
434
441
  index: false,
435
442
  writeToDisk: process.env.DINOU_WRITE_TO_DISK === "true",
436
443
  },
437
- watchFiles: [
438
- path.resolve(process.cwd(), "src/**/*"),
439
- ],
444
+ watchFiles: [],
440
445
  proxy: [
441
446
  {
442
447
  context: () => true,