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,209 +1,209 @@
1
- /**
2
- * esm-hmr/client.js
3
- * A client-side implementation of the ESM-HMR spec, for reference.
4
- */
5
-
6
- function debug(...args) {
7
- console.log("[ESM-HMR]", ...args);
8
- }
9
-
10
- function reload() {
11
- location.reload(true);
12
- }
13
-
14
- let SOCKET_MESSAGE_QUEUE = [];
15
-
16
- function _sendSocketMessage(msg) {
17
- socket.send(JSON.stringify(msg));
18
- }
19
-
20
- function sendSocketMessage(msg) {
21
- if (socket.readyState !== socket.OPEN) {
22
- SOCKET_MESSAGE_QUEUE.push(msg);
23
- } else {
24
- _sendSocketMessage(msg);
25
- }
26
- }
27
-
28
- const socketURL =
29
- window.HMR_WEBSOCKET_URL ||
30
- (location.protocol === "http:" ? "ws://" : "wss://") + location.host + "/";
31
- const socket = new WebSocket(socketURL, "esm-hmr");
32
-
33
- socket.addEventListener("open", () => {
34
- SOCKET_MESSAGE_QUEUE.forEach(_sendSocketMessage);
35
- SOCKET_MESSAGE_QUEUE = [];
36
- });
37
-
38
- const REGISTERED_MODULES = {};
39
- class HotModuleState {
40
- constructor(id) {
41
- this.id = id;
42
- this.data = {};
43
- this.isLocked = false;
44
- this.isDeclined = false;
45
- this.isAccepted = false;
46
- this.acceptCallbacks = [];
47
- this.disposeCallbacks = [];
48
- }
49
-
50
- lock() {
51
- this.isLocked = true;
52
- }
53
-
54
- dispose(callback) {
55
- this.disposeCallbacks.push(callback);
56
- }
57
-
58
- invalidate() {
59
- reload();
60
- }
61
-
62
- decline() {
63
- this.isDeclined = true;
64
- }
65
-
66
- accept(_deps = [], callback = true) {
67
- if (this.isLocked) {
68
- return;
69
- }
70
- if (!this.isAccepted) {
71
- sendSocketMessage({ id: this.id, type: "hotAccept" });
72
- this.isAccepted = true;
73
- }
74
- if (!Array.isArray(_deps)) {
75
- callback = _deps || callback;
76
- _deps = [];
77
- }
78
- if (callback === true) {
79
- callback = () => {};
80
- }
81
- const deps = _deps.map((dep) => {
82
- const ext = dep.split(".").pop();
83
- if (!ext) {
84
- dep += ".js";
85
- } else if (ext !== "js") {
86
- dep += ".proxy.js";
87
- }
88
- return new URL(dep, `${window.location.origin}${this.id}`).pathname;
89
- });
90
- this.acceptCallbacks.push({
91
- deps,
92
- callback,
93
- });
94
- }
95
- }
96
-
97
- export function createHotContext(id) {
98
- const normId = id.startsWith("/") ? id : "/" + id;
99
- const existing = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
100
- if (existing) {
101
- existing.isLocked = false;
102
- return existing;
103
- }
104
- const state = new HotModuleState(normId);
105
- REGISTERED_MODULES[normId] = state;
106
- REGISTERED_MODULES[id] = state;
107
- return state;
108
- }
109
-
110
- async function applyUpdate(id) {
111
- const normId = id.startsWith("/") ? id : "/" + id;
112
- const state = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
113
- if (!state) {
114
- return true;
115
- }
116
- if (state.isDeclined) {
117
- return false;
118
- }
119
-
120
- const acceptCallbacks = state.acceptCallbacks;
121
- const disposeCallbacks = state.disposeCallbacks;
122
- state.disposeCallbacks = [];
123
- state.data = {};
124
-
125
- disposeCallbacks.forEach((callback) => callback());
126
-
127
- const updateID = Date.now();
128
- for (const { deps, callback: acceptCallback } of acceptCallbacks) {
129
- const [module, ...depModules] = await Promise.all([
130
- import(normId + `?mtime=${updateID}`),
131
- ...deps.map((d) => {
132
- const depId = d.startsWith("/") ? d : "/" + d;
133
- return import(depId + `?mtime=${updateID}`);
134
- }),
135
- ]);
136
- acceptCallback({ module, deps: depModules });
137
- }
138
-
139
- return true;
140
- }
141
-
142
- socket.addEventListener("message", ({ data: _data }) => {
143
- if (!_data) return;
144
-
145
- const data = JSON.parse(_data);
146
- if (data.type === "reload") {
147
- reload();
148
- return;
149
- }
150
-
151
- if (data.type === "rsc-update") {
152
- if (typeof window !== "undefined" && typeof window.__DINOU_ROUTER_REFRESH__ === "function") {
153
- window.__DINOU_ROUTER_REFRESH__();
154
- return;
155
- }
156
- reload();
157
- return;
158
- }
159
-
160
- if (
161
- data.type === "style-update" ||
162
- (data.type === "update" && data.url && (data.url.endsWith(".css") || data.url.includes("styles.css")))
163
- ) {
164
- const targetUrl = data.url ? data.url.split("?")[0] : "";
165
- const links = document.querySelectorAll('link[rel="stylesheet"]');
166
- for (const link of links) {
167
- const rawHref = link.getAttribute("href");
168
- if (!rawHref) continue;
169
- const cleanHref = rawHref.split("?")[0];
170
- if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
171
- const nextUrl = new URL(link.href, window.location.origin);
172
- nextUrl.searchParams.set("t", String(Date.now()));
173
- link.href = nextUrl.href;
174
- }
175
- }
176
- return;
177
- }
178
-
179
- if (data.type !== "update") {
180
- return;
181
- }
182
-
183
- const tRecv = Date.now();
184
- const isDebug = typeof window !== "undefined" && Boolean(window.__DINOU_DEBUG__);
185
-
186
- if (isDebug) {
187
- console.log(`⏱️ [BROWSER HMR] Received update for ${data.url} at ${new Date().toTimeString().slice(0, 8)}.${String(Date.now() % 1000).padStart(3, '0')}`);
188
- }
189
-
190
- applyUpdate(data.url)
191
- .then((ok) => {
192
- if (!ok) {
193
- if (isDebug) console.warn(`⏱️ [BROWSER HMR] applyUpdate returned false, falling back to full reload!`);
194
- reload();
195
- } else {
196
- if (isDebug) {
197
- console.log(`⏱️ [BROWSER HMR] Fast Refresh finished applying in ${Date.now() - tRecv}ms!`);
198
- } else {
199
- console.log(`[ESM-HMR] hot updated: ${data.url}`);
200
- }
201
- }
202
- })
203
- .catch((err) => {
204
- console.error(`[ESM-HMR] applyUpdate error:`, err);
205
- reload();
206
- });
207
- });
208
-
209
- debug("listening for file changes...");
1
+ /**
2
+ * esm-hmr/client.js
3
+ * A client-side implementation of the ESM-HMR spec, for reference.
4
+ */
5
+
6
+ function debug(...args) {
7
+ console.log("[ESM-HMR]", ...args);
8
+ }
9
+
10
+ function reload() {
11
+ location.reload(true);
12
+ }
13
+
14
+ let SOCKET_MESSAGE_QUEUE = [];
15
+
16
+ function _sendSocketMessage(msg) {
17
+ socket.send(JSON.stringify(msg));
18
+ }
19
+
20
+ function sendSocketMessage(msg) {
21
+ if (socket.readyState !== socket.OPEN) {
22
+ SOCKET_MESSAGE_QUEUE.push(msg);
23
+ } else {
24
+ _sendSocketMessage(msg);
25
+ }
26
+ }
27
+
28
+ const socketURL =
29
+ window.HMR_WEBSOCKET_URL ||
30
+ (location.protocol === "http:" ? "ws://" : "wss://") + location.host + "/";
31
+ const socket = new WebSocket(socketURL, "esm-hmr");
32
+
33
+ socket.addEventListener("open", () => {
34
+ SOCKET_MESSAGE_QUEUE.forEach(_sendSocketMessage);
35
+ SOCKET_MESSAGE_QUEUE = [];
36
+ });
37
+
38
+ const REGISTERED_MODULES = {};
39
+ class HotModuleState {
40
+ constructor(id) {
41
+ this.id = id;
42
+ this.data = {};
43
+ this.isLocked = false;
44
+ this.isDeclined = false;
45
+ this.isAccepted = false;
46
+ this.acceptCallbacks = [];
47
+ this.disposeCallbacks = [];
48
+ }
49
+
50
+ lock() {
51
+ this.isLocked = true;
52
+ }
53
+
54
+ dispose(callback) {
55
+ this.disposeCallbacks.push(callback);
56
+ }
57
+
58
+ invalidate() {
59
+ reload();
60
+ }
61
+
62
+ decline() {
63
+ this.isDeclined = true;
64
+ }
65
+
66
+ accept(_deps = [], callback = true) {
67
+ if (this.isLocked) {
68
+ return;
69
+ }
70
+ if (!this.isAccepted) {
71
+ sendSocketMessage({ id: this.id, type: "hotAccept" });
72
+ this.isAccepted = true;
73
+ }
74
+ if (!Array.isArray(_deps)) {
75
+ callback = _deps || callback;
76
+ _deps = [];
77
+ }
78
+ if (callback === true) {
79
+ callback = () => {};
80
+ }
81
+ const deps = _deps.map((dep) => {
82
+ const ext = dep.split(".").pop();
83
+ if (!ext) {
84
+ dep += ".js";
85
+ } else if (ext !== "js") {
86
+ dep += ".proxy.js";
87
+ }
88
+ return new URL(dep, `${window.location.origin}${this.id}`).pathname;
89
+ });
90
+ this.acceptCallbacks.push({
91
+ deps,
92
+ callback,
93
+ });
94
+ }
95
+ }
96
+
97
+ export function createHotContext(id) {
98
+ const normId = id.startsWith("/") ? id : "/" + id;
99
+ const existing = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
100
+ if (existing) {
101
+ existing.isLocked = false;
102
+ return existing;
103
+ }
104
+ const state = new HotModuleState(normId);
105
+ REGISTERED_MODULES[normId] = state;
106
+ REGISTERED_MODULES[id] = state;
107
+ return state;
108
+ }
109
+
110
+ async function applyUpdate(id) {
111
+ const normId = id.startsWith("/") ? id : "/" + id;
112
+ const state = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
113
+ if (!state) {
114
+ return true;
115
+ }
116
+ if (state.isDeclined) {
117
+ return false;
118
+ }
119
+
120
+ const acceptCallbacks = state.acceptCallbacks;
121
+ const disposeCallbacks = state.disposeCallbacks;
122
+ state.disposeCallbacks = [];
123
+ state.data = {};
124
+
125
+ disposeCallbacks.forEach((callback) => callback());
126
+
127
+ const updateID = Date.now();
128
+ for (const { deps, callback: acceptCallback } of acceptCallbacks) {
129
+ const [module, ...depModules] = await Promise.all([
130
+ import(normId + `?mtime=${updateID}`),
131
+ ...deps.map((d) => {
132
+ const depId = d.startsWith("/") ? d : "/" + d;
133
+ return import(depId + `?mtime=${updateID}`);
134
+ }),
135
+ ]);
136
+ acceptCallback({ module, deps: depModules });
137
+ }
138
+
139
+ return true;
140
+ }
141
+
142
+ socket.addEventListener("message", ({ data: _data }) => {
143
+ if (!_data) return;
144
+
145
+ const data = JSON.parse(_data);
146
+ if (data.type === "reload") {
147
+ reload();
148
+ return;
149
+ }
150
+
151
+ if (data.type === "rsc-update") {
152
+ if (typeof window !== "undefined" && typeof window.__DINOU_ROUTER_REFRESH__ === "function") {
153
+ window.__DINOU_ROUTER_REFRESH__();
154
+ return;
155
+ }
156
+ reload();
157
+ return;
158
+ }
159
+
160
+ if (
161
+ data.type === "style-update" ||
162
+ (data.type === "update" && data.url && (data.url.endsWith(".css") || data.url.includes("styles.css")))
163
+ ) {
164
+ const targetUrl = data.url ? data.url.split("?")[0] : "";
165
+ const links = document.querySelectorAll('link[rel="stylesheet"]');
166
+ for (const link of links) {
167
+ const rawHref = link.getAttribute("href");
168
+ if (!rawHref) continue;
169
+ const cleanHref = rawHref.split("?")[0];
170
+ if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
171
+ const nextUrl = new URL(link.href, window.location.origin);
172
+ nextUrl.searchParams.set("t", String(Date.now()));
173
+ link.href = nextUrl.href;
174
+ }
175
+ }
176
+ return;
177
+ }
178
+
179
+ if (data.type !== "update") {
180
+ return;
181
+ }
182
+
183
+ const tRecv = Date.now();
184
+ const isDebug = typeof window !== "undefined" && Boolean(window.__DINOU_DEBUG__);
185
+
186
+ if (isDebug) {
187
+ console.log(`⏱️ [BROWSER HMR] Received update for ${data.url} at ${new Date().toTimeString().slice(0, 8)}.${String(Date.now() % 1000).padStart(3, '0')}`);
188
+ }
189
+
190
+ applyUpdate(data.url)
191
+ .then((ok) => {
192
+ if (!ok) {
193
+ if (isDebug) console.warn(`⏱️ [BROWSER HMR] applyUpdate returned false, falling back to full reload!`);
194
+ reload();
195
+ } else {
196
+ if (isDebug) {
197
+ console.log(`⏱️ [BROWSER HMR] Fast Refresh finished applying in ${Date.now() - tRecv}ms!`);
198
+ } else {
199
+ console.log(`[ESM-HMR] hot updated: ${data.url}`);
200
+ }
201
+ }
202
+ })
203
+ .catch((err) => {
204
+ console.error(`[ESM-HMR] applyUpdate error:`, err);
205
+ reload();
206
+ });
207
+ });
208
+
209
+ debug("listening for file changes...");
package/dinou/index.d.ts CHANGED
@@ -327,6 +327,16 @@ export declare function defineConfig(config: DinouConfig): DinouConfig;
327
327
  */
328
328
  export declare function getContext(): RequestContextStore | undefined;
329
329
 
330
+ /**
331
+ * Opts the enclosing `<Suspense>` boundary out of becoming a Dynamic PPR Hole
332
+ * when wrapping an async Server Component on a PPR route (`ppr = true`).
333
+ *
334
+ * Call `noDynamic()` synchronously at the top of your async Server Component
335
+ * (before its first `await`) so Dinou resolves its promise at build time and
336
+ * bakes the rendered output directly into the Static Shell (`shell.html`).
337
+ */
338
+ export declare function noDynamic(): void;
339
+
330
340
  import type { ReactNode } from "react";
331
341
 
332
342
  // ====================================================================
package/dinou/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineConfig } from "./core/config.js";
2
2
  import { getContext } from "./core/request-context.js";
3
+ import { noDynamic } from "./core/no-dynamic.js";
3
4
  import {
4
5
  usePathname,
5
6
  useSearchParams,
@@ -14,6 +15,7 @@ import { Link } from "./core/link.jsx";
14
15
  const dinou = {
15
16
  defineConfig,
16
17
  getContext,
18
+ noDynamic,
17
19
  usePathname,
18
20
  useSearchParams,
19
21
  useRouter,
@@ -27,6 +29,7 @@ const dinou = {
27
29
  export {
28
30
  defineConfig,
29
31
  getContext,
32
+ noDynamic,
30
33
  usePathname,
31
34
  useSearchParams,
32
35
  useRouter,
@@ -125,7 +125,7 @@ const PORT = Number(process.env.PORT || 3000);
125
125
 
126
126
  const nodeMiddlewares = [];
127
127
 
128
- export async function startServer(port = PORT, host = "0.0.0.0") {
128
+ export async function startServer(port = PORT, host = process.env.HOST || undefined) {
129
129
  const server = http.createServer(async (req, res) => {
130
130
  try {
131
131
  if (res.writableEnded || res.headersSent) {
@@ -184,7 +184,7 @@ export async function startServer(port = PORT, host = "0.0.0.0") {
184
184
 
185
185
  return new Promise((resolve, reject) => {
186
186
  server.on("error", reject);
187
- server.listen(port, () => {
187
+ server.listen(port, host, () => {
188
188
  console.log(\`🚀 Dinou (Node.js AOT Dual-Bundle) server running on http://localhost:\${port}\`);
189
189
  resolve(server);
190
190
  });
@@ -411,6 +411,8 @@ export async function bundleDualEngine(options = {}) {
411
411
  findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
412
412
  } else if (/^layout\.[jt]sx?$/.test(entry.name)) {
413
413
  discoveredLayouts.push(rel);
414
+ } else if (entry.name === "no_layout") {
415
+ discoveredLayouts.push("!" + rel);
414
416
  }
415
417
  }
416
418
  }