dinou 9.0.2 → 9.0.3
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 +54 -0
- package/README.md +503 -9883
- package/dinou/bun/build.js +38 -1
- package/{cli.js → dinou/cli.js} +8 -7
- package/dinou/cloudflare/build.js +37 -0
- package/dinou/core/build-static-pages.js +15 -7
- package/dinou/core/cache-revalidate.js +909 -151
- package/dinou/core/cache-slot.js +728 -97
- package/dinou/core/client-webpack.jsx +60 -9
- package/dinou/core/client.jsx +60 -9
- package/dinou/core/edge-ssr.js +33 -5
- package/dinou/core/generate-static.js +109 -47
- package/dinou/core/get-jsx.js +333 -329
- package/dinou/core/handler.js +2983 -2343
- package/dinou/core/layout-functions.js +102 -1
- package/dinou/core/ppr-context.js +256 -105
- package/dinou/core/ppr-runtime.js +540 -267
- package/dinou/core/render-jsx-to-client-jsx.js +131 -71
- package/dinou/core/slot.js +246 -33
- package/dinou/core/storage-adapter.js +117 -11
- package/dinou/deno/build.js +38 -1
- package/dinou/deno/seed-kv.js +43 -11
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -225
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -226
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
- package/dinou/node/build.js +2 -2
- package/dinou/node/bundle-dual-engine.js +2 -0
- package/dinou/node/dev.js +2853 -2704
- package/dinou/package.json +5 -2
- package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -160
- package/dinou/server.d.ts +25 -11
- package/dinou/server.js +5 -0
- package/dinou/webpack/loaders/server-functions-loader.js +101 -94
- package/dinou/webpack/webpack.config.js +9 -4
- package/eject.js +219 -223
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { existsSync } from "./vfs.js";
|
|
3
3
|
import importModule from "./import-module.js";
|
|
4
4
|
import { resolveModulePpr } from "./resolve-module-ppr.js";
|
|
5
|
+
import { getFilePathAndDynamicParams } from "./get-file-path-and-dynamic-params.js";
|
|
5
6
|
|
|
6
7
|
const LAYOUT_FUNCTIONS_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs"];
|
|
7
8
|
const LAYOUT_FUNCTIONS_NAMES = ["layout_functions", "layout.functions"];
|
|
@@ -175,14 +176,114 @@ async function resolveLayoutFunctionsConfig(layoutPath, dParams = {}) {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Returns the active layout chain for a route from innermost (leaf) to outermost (root),
|
|
181
|
+
* honoring `no_layout` and stopping at `reset_layout`.
|
|
182
|
+
*/
|
|
183
|
+
function getActiveLayoutChain(
|
|
184
|
+
reqSegments,
|
|
185
|
+
queryObj = {},
|
|
186
|
+
srcFolder = path.resolve(process.cwd(), "src"),
|
|
187
|
+
options = {}
|
|
188
|
+
) {
|
|
189
|
+
if (
|
|
190
|
+
!options.ignoreNoLayout &&
|
|
191
|
+
getFilePathAndDynamicParams(reqSegments, queryObj, srcFolder, "no_layout", false)[0]
|
|
192
|
+
) {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const allLayouts = getFilePathAndDynamicParams(
|
|
197
|
+
reqSegments,
|
|
198
|
+
queryObj,
|
|
199
|
+
srcFolder,
|
|
200
|
+
"layout",
|
|
201
|
+
true,
|
|
202
|
+
false,
|
|
203
|
+
undefined,
|
|
204
|
+
0,
|
|
205
|
+
{},
|
|
206
|
+
true
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (!allLayouts || !Array.isArray(allLayouts) || allLayouts.length === 0) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const normSrc = srcFolder.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
214
|
+
const activeChain = [];
|
|
215
|
+
|
|
216
|
+
for (const [layoutPath, dParams, slots] of [...allLayouts].reverse()) {
|
|
217
|
+
const layoutFolderPath = path.dirname(layoutPath);
|
|
218
|
+
const resetLayoutPath = getFilePathAndDynamicParams(
|
|
219
|
+
[],
|
|
220
|
+
{},
|
|
221
|
+
layoutFolderPath,
|
|
222
|
+
"reset_layout",
|
|
223
|
+
false
|
|
224
|
+
)[0];
|
|
225
|
+
|
|
226
|
+
const normFolder = layoutFolderPath.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
227
|
+
let relFromSrc = "";
|
|
228
|
+
if (normFolder === normSrc) {
|
|
229
|
+
relFromSrc = "";
|
|
230
|
+
} else if (normFolder.startsWith(normSrc + "/")) {
|
|
231
|
+
relFromSrc = normFolder.slice(normSrc.length + 1);
|
|
232
|
+
} else {
|
|
233
|
+
const srcIdx = normFolder.lastIndexOf("/src/");
|
|
234
|
+
if (srcIdx !== -1) {
|
|
235
|
+
relFromSrc = normFolder.slice(srcIdx + 5);
|
|
236
|
+
} else if (normFolder.endsWith("/src")) {
|
|
237
|
+
relFromSrc = "";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const rawFolderSegs = relFromSrc.split("/").filter(Boolean);
|
|
242
|
+
let urlSegCount = 0;
|
|
243
|
+
for (const seg of rawFolderSegs) {
|
|
244
|
+
if (seg.startsWith("(") && seg.endsWith(")")) continue;
|
|
245
|
+
if (seg.startsWith("[[...") && seg.endsWith("]]")) {
|
|
246
|
+
const pName = seg.slice(5, -2);
|
|
247
|
+
const val = dParams?.[pName];
|
|
248
|
+
urlSegCount += Array.isArray(val) ? val.length : val ? 1 : 0;
|
|
249
|
+
} else if (seg.startsWith("[...") && seg.endsWith("]")) {
|
|
250
|
+
const pName = seg.slice(4, -1);
|
|
251
|
+
const val = dParams?.[pName];
|
|
252
|
+
urlSegCount += Array.isArray(val) ? val.length : val ? 1 : 0;
|
|
253
|
+
} else {
|
|
254
|
+
urlSegCount += 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const cleanLayoutKey = reqSegments.slice(0, urlSegCount).join("/");
|
|
259
|
+
const layoutRoutePath = cleanLayoutKey ? "/" + cleanLayoutKey : "/";
|
|
260
|
+
|
|
261
|
+
activeChain.push({
|
|
262
|
+
layoutPath,
|
|
263
|
+
dParams: dParams || {},
|
|
264
|
+
slots: slots || {},
|
|
265
|
+
cleanLayoutKey,
|
|
266
|
+
layoutRoutePath,
|
|
267
|
+
hasResetLayout: Boolean(resetLayoutPath),
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if (resetLayoutPath) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return activeChain;
|
|
276
|
+
}
|
|
277
|
+
|
|
178
278
|
export {
|
|
179
279
|
getLayoutFunctionsPath,
|
|
180
280
|
getLayoutProps,
|
|
181
281
|
resolveLayoutFunctionsConfig,
|
|
282
|
+
getActiveLayoutChain,
|
|
182
283
|
};
|
|
183
284
|
export default {
|
|
184
285
|
getLayoutFunctionsPath,
|
|
185
286
|
getLayoutProps,
|
|
186
287
|
resolveLayoutFunctionsConfig,
|
|
288
|
+
getActiveLayoutChain,
|
|
187
289
|
};
|
|
188
|
-
|
|
@@ -1,105 +1,256 @@
|
|
|
1
|
-
// dinou/core/ppr-context.js
|
|
2
|
-
// PPR Pre-rendering Context and Suspense Hole Tracker for Dinou
|
|
3
|
-
|
|
4
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
-
|
|
6
|
-
const pprStorage = new AsyncLocalStorage();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
1
|
+
// dinou/core/ppr-context.js
|
|
2
|
+
// PPR Pre-rendering Context and Suspense Hole Tracker for Dinou.
|
|
3
|
+
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
const pprStorage = new AsyncLocalStorage();
|
|
7
|
+
const pageSegmentStorage = new AsyncLocalStorage();
|
|
8
|
+
const layoutSegmentStorage = new AsyncLocalStorage();
|
|
9
|
+
const pageRootElements = new WeakSet();
|
|
10
|
+
|
|
11
|
+
export function markPageRootElement(el) {
|
|
12
|
+
if (el && typeof el === "object") {
|
|
13
|
+
pageRootElements.add(el);
|
|
14
|
+
}
|
|
15
|
+
return el;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isPageRootElement(el) {
|
|
19
|
+
return Boolean(el && typeof el === "object" && pageRootElements.has(el));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function runInPageSegment(callback) {
|
|
23
|
+
return pageSegmentStorage.run({ active: true }, callback);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isInsidePageSegment() {
|
|
27
|
+
return Boolean(pageSegmentStorage.getStore()?.active);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function runInLayoutSegment(callback) {
|
|
31
|
+
return layoutSegmentStorage.run({ active: true }, callback);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isInsideLayoutSegment() {
|
|
35
|
+
return Boolean(layoutSegmentStorage.getStore()?.active);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Executes a function within a PPR pre-render context.
|
|
40
|
+
* @param {object} options
|
|
41
|
+
* @param {Function} callback
|
|
42
|
+
* @returns {Promise<any>}
|
|
43
|
+
*/
|
|
44
|
+
export function runWithPprContext(options, callback) {
|
|
45
|
+
const sharedCounter = { nextHoleIndex: 0 };
|
|
46
|
+
const sharedHoles = new Map();
|
|
47
|
+
const store = {
|
|
48
|
+
isPpr: Boolean(options?.isPpr),
|
|
49
|
+
suspenseDepth: 0,
|
|
50
|
+
currentHoleId: null,
|
|
51
|
+
holeStack: [],
|
|
52
|
+
holes: sharedHoles,
|
|
53
|
+
counter: sharedCounter,
|
|
54
|
+
get nextHoleIndex() {
|
|
55
|
+
return sharedCounter.nextHoleIndex;
|
|
56
|
+
},
|
|
57
|
+
set nextHoleIndex(val) {
|
|
58
|
+
sharedCounter.nextHoleIndex = val;
|
|
59
|
+
},
|
|
60
|
+
...options,
|
|
61
|
+
};
|
|
62
|
+
return pprStorage.run(store, callback);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getPprStore() {
|
|
66
|
+
return pprStorage.getStore() || null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isPprBuildActive() {
|
|
70
|
+
const store = getPprStore();
|
|
71
|
+
return Boolean(store && store.isPpr);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isInsideSuspense() {
|
|
75
|
+
const store = getPprStore();
|
|
76
|
+
return Boolean(store && store.suspenseDepth > 0);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function resetPprHoles(startIndex = 0) {
|
|
80
|
+
const store = getPprStore();
|
|
81
|
+
if (store) {
|
|
82
|
+
const startVal = Number(startIndex) || 0;
|
|
83
|
+
if (store.counter) {
|
|
84
|
+
store.counter.nextHoleIndex = startVal;
|
|
85
|
+
} else {
|
|
86
|
+
store.nextHoleIndex = startVal;
|
|
87
|
+
}
|
|
88
|
+
if (store.holes && typeof store.holes.clear === "function") {
|
|
89
|
+
store.holes.clear();
|
|
90
|
+
}
|
|
91
|
+
store.suspenseDepth = 0;
|
|
92
|
+
store.currentHoleId = null;
|
|
93
|
+
if (Array.isArray(store.holeStack)) {
|
|
94
|
+
store.holeStack.length = 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getPprHoleCounter() {
|
|
100
|
+
const store = getPprStore();
|
|
101
|
+
if (store) {
|
|
102
|
+
return store.counter ? store.counter.nextHoleIndex : store.nextHoleIndex || 0;
|
|
103
|
+
}
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function runInSuspense(callback, explicitHoleId = null) {
|
|
108
|
+
const store = getPprStore();
|
|
109
|
+
if (!store) {
|
|
110
|
+
return callback(null, null);
|
|
111
|
+
}
|
|
112
|
+
let holeId = explicitHoleId;
|
|
113
|
+
if (!holeId) {
|
|
114
|
+
if (store.counter) {
|
|
115
|
+
store.counter.nextHoleIndex++;
|
|
116
|
+
holeId = `ppr-hole-${store.counter.nextHoleIndex}`;
|
|
117
|
+
} else {
|
|
118
|
+
store.nextHoleIndex++;
|
|
119
|
+
holeId = `ppr-hole-${store.nextHoleIndex}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const nextStack = Array.isArray(store.holeStack)
|
|
123
|
+
? [...store.holeStack, holeId]
|
|
124
|
+
: [holeId];
|
|
125
|
+
const pendingEffects = [];
|
|
126
|
+
const childStore = {
|
|
127
|
+
...store,
|
|
128
|
+
suspenseDepth: store.suspenseDepth + 1,
|
|
129
|
+
currentHoleId: holeId,
|
|
130
|
+
holeStack: nextStack,
|
|
131
|
+
pendingEffects,
|
|
132
|
+
parentPendingEffects: Array.isArray(store.pendingEffects)
|
|
133
|
+
? store.pendingEffects
|
|
134
|
+
: null,
|
|
135
|
+
};
|
|
136
|
+
return pprStorage.run(childStore, () => callback(holeId, childStore));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function deferPprSuspenseEffect(effectFn) {
|
|
140
|
+
const store = getPprStore();
|
|
141
|
+
if (
|
|
142
|
+
store &&
|
|
143
|
+
store.isPpr &&
|
|
144
|
+
store.suspenseDepth > 0 &&
|
|
145
|
+
Array.isArray(store.pendingEffects) &&
|
|
146
|
+
typeof effectFn === "function"
|
|
147
|
+
) {
|
|
148
|
+
store.pendingEffects.push(effectFn);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function commitPprSuspenseEffects(childStore) {
|
|
155
|
+
if (!childStore || !Array.isArray(childStore.pendingEffects)) return;
|
|
156
|
+
const effects = childStore.pendingEffects.splice(0);
|
|
157
|
+
if (effects.length === 0) return;
|
|
158
|
+
if (Array.isArray(childStore.parentPendingEffects)) {
|
|
159
|
+
childStore.parentPendingEffects.push(...effects);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
for (const fn of effects) {
|
|
163
|
+
await fn();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function enterSuspense(holeId = null) {
|
|
168
|
+
const store = getPprStore();
|
|
169
|
+
if (store) {
|
|
170
|
+
store.suspenseDepth++;
|
|
171
|
+
if (!holeId) {
|
|
172
|
+
if (store.counter) {
|
|
173
|
+
store.counter.nextHoleIndex++;
|
|
174
|
+
holeId = `ppr-hole-${store.counter.nextHoleIndex}`;
|
|
175
|
+
} else {
|
|
176
|
+
store.nextHoleIndex++;
|
|
177
|
+
holeId = `ppr-hole-${store.nextHoleIndex}`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (Array.isArray(store.holeStack)) {
|
|
181
|
+
store.holeStack.push(holeId);
|
|
182
|
+
}
|
|
183
|
+
store.currentHoleId = holeId;
|
|
184
|
+
return holeId;
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function exitSuspense() {
|
|
190
|
+
const store = getPprStore();
|
|
191
|
+
if (store) {
|
|
192
|
+
store.suspenseDepth = Math.max(0, store.suspenseDepth - 1);
|
|
193
|
+
if (Array.isArray(store.holeStack) && store.holeStack.length > 0) {
|
|
194
|
+
store.holeStack.pop();
|
|
195
|
+
store.currentHoleId =
|
|
196
|
+
store.holeStack.length > 0
|
|
197
|
+
? store.holeStack[store.holeStack.length - 1]
|
|
198
|
+
: null;
|
|
199
|
+
} else if (store.suspenseDepth === 0) {
|
|
200
|
+
store.currentHoleId = null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function markDynamicAccess(type = "dynamic") {
|
|
206
|
+
const store = getPprStore();
|
|
207
|
+
if (store && store.isPpr && store.suspenseDepth > 0) {
|
|
208
|
+
const idx = store.counter ? store.counter.nextHoleIndex : store.nextHoleIndex;
|
|
209
|
+
const holeId = store.currentHoleId || `ppr-hole-${idx}`;
|
|
210
|
+
const error = new Error(
|
|
211
|
+
`[Dinou PPR] Dynamic access to '${type}' postponed inside Suspense`
|
|
212
|
+
);
|
|
213
|
+
error.$$typeof = Symbol.for("dinou.ppr.postpone");
|
|
214
|
+
error.pprType = type;
|
|
215
|
+
error.holeId = holeId;
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function registerHole(holeId, meta = {}) {
|
|
221
|
+
const store = getPprStore();
|
|
222
|
+
if (store && holeId) {
|
|
223
|
+
store.holes.set(holeId, {
|
|
224
|
+
id: holeId,
|
|
225
|
+
registeredAt: Date.now(),
|
|
226
|
+
...meta,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function getRegisteredHoles() {
|
|
232
|
+
const store = getPprStore();
|
|
233
|
+
if (store) {
|
|
234
|
+
return Array.from(store.holes.keys());
|
|
235
|
+
}
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export default {
|
|
240
|
+
runInPageSegment,
|
|
241
|
+
isInsidePageSegment,
|
|
242
|
+
runWithPprContext,
|
|
243
|
+
getPprStore,
|
|
244
|
+
isPprBuildActive,
|
|
245
|
+
isInsideSuspense,
|
|
246
|
+
resetPprHoles,
|
|
247
|
+
getPprHoleCounter,
|
|
248
|
+
runInSuspense,
|
|
249
|
+
deferPprSuspenseEffect,
|
|
250
|
+
commitPprSuspenseEffects,
|
|
251
|
+
enterSuspense,
|
|
252
|
+
exitSuspense,
|
|
253
|
+
markDynamicAccess,
|
|
254
|
+
registerHole,
|
|
255
|
+
getRegisteredHoles,
|
|
256
|
+
};
|