@farm.js/core 0.1.64 → 0.1.65
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/dist/analyzer-GHWK46LX.cjs +16 -0
- package/dist/{analyzer-Q3QXC6PD.mjs → analyzer-PE33SK5W.mjs} +2 -2
- package/dist/{chunk-O4FWNLQK.mjs → chunk-2L54YV25.mjs} +10 -8
- package/dist/{chunk-S25BQIFW.cjs → chunk-32RPJAAS.cjs} +2 -2
- package/dist/{chunk-FAP7CX7C.cjs → chunk-3KJPIO5D.cjs} +526 -3018
- package/dist/{chunk-OYF23QLG.mjs → chunk-6X5NKNBE.mjs} +36 -32
- package/dist/{chunk-LQDLEWPO.mjs → chunk-72JSHQQQ.mjs} +1 -1
- package/dist/{chunk-WNYRYI4D.mjs → chunk-7GYCZRTH.mjs} +379 -2871
- package/dist/chunk-7QVRWGBL.cjs +3704 -0
- package/dist/{chunk-O2XFIPNL.cjs → chunk-A3G5IY2W.cjs} +1 -1
- package/dist/{chunk-NXFA7G3Y.cjs → chunk-C7DCMGC4.cjs} +4 -4
- package/dist/chunk-CJNAUEVC.mjs +34 -0
- package/dist/{chunk-O7IEMY55.cjs → chunk-CZF4XIRZ.cjs} +3 -3
- package/dist/{chunk-SLYDIHLW.mjs → chunk-E2TSYUHV.mjs} +2 -2
- package/dist/{chunk-VVTJTMGQ.cjs → chunk-GL7N5UHF.cjs} +4 -4
- package/dist/{chunk-6NHSGVVA.mjs → chunk-GRBJ7VKH.mjs} +1 -1
- package/dist/{chunk-UR25Z5Z6.mjs → chunk-HCGWDRZO.mjs} +1 -1
- package/dist/{chunk-FH45OB37.mjs → chunk-HKNYNSOK.mjs} +1 -1
- package/dist/{chunk-DUSHDZQL.cjs → chunk-IMK32ERL.cjs} +15 -13
- package/dist/{chunk-XVWSDSUM.mjs → chunk-IP2KHSGF.mjs} +4 -2
- package/dist/{chunk-MG356ROI.cjs → chunk-OSFIUSYK.cjs} +3 -3
- package/dist/{chunk-SNFTMSHX.mjs → chunk-Q75QPLBA.mjs} +1 -1
- package/dist/{chunk-WFNAOWH4.mjs → chunk-QHRCR44V.mjs} +2 -2
- package/dist/{chunk-JCPSA4X5.cjs → chunk-T4M52BA5.cjs} +116 -112
- package/dist/{chunk-PAKCHVUS.mjs → chunk-TPA2PV5J.mjs} +3 -35
- package/dist/{chunk-N3Z3PLHC.cjs → chunk-TRIDJQ6A.cjs} +6 -6
- package/dist/{chunk-3EBHJET2.cjs → chunk-TZOGZKI7.cjs} +380 -269
- package/dist/{chunk-BPNOYILC.cjs → chunk-UVV3I5QA.cjs} +3 -35
- package/dist/{chunk-RAH5MT53.mjs → chunk-VHHLKIDZ.mjs} +153 -42
- package/dist/{chunk-S7ZW72JH.cjs → chunk-WNXVWXG3.cjs} +2 -2
- package/dist/{chunk-XZLZ6YPP.cjs → chunk-YD4J37RN.cjs} +90 -33
- package/dist/{chunk-NNLFW3P4.mjs → chunk-YUW7F6SK.mjs} +1 -1
- package/dist/chunk-ZAUOOGER.mjs +3704 -0
- package/dist/chunk-ZIHWAN55.cjs +34 -0
- package/dist/{chunk-EL4364S2.cjs → chunk-ZQQK4U66.cjs} +4 -2
- package/dist/{chunk-6NNYPY5W.mjs → chunk-ZX2JHEWW.mjs} +59 -2
- package/dist/{devtools-MX3FE733.mjs → devtools-PUVZB3F2.mjs} +4 -3
- package/dist/{devtools-WET5NAKO.cjs → devtools-SGYOG36E.cjs} +5 -4
- package/dist/docs.cjs +6 -5
- package/dist/docs.mjs +5 -4
- package/dist/environment/vite.cjs +9 -2
- package/dist/environment/vite.d.mts +3 -0
- package/dist/environment/vite.d.ts +3 -0
- package/dist/environment/vite.mjs +8 -1
- package/dist/index.cjs +20 -19
- package/dist/index.mjs +19 -18
- package/dist/internal/build-runtime.cjs +18 -17
- package/dist/internal/build-runtime.mjs +17 -16
- package/dist/internal/cli-runtime.cjs +6 -5
- package/dist/internal/cli-runtime.mjs +5 -4
- package/dist/internal/client-error-overlay.cjs +4 -4
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/config-runtime.cjs +6 -5
- package/dist/internal/config-runtime.mjs +5 -4
- package/dist/internal/infra-analytics-runtime.cjs +6 -6
- package/dist/internal/infra-analytics-runtime.mjs +4 -4
- package/dist/internal/native-server-fns.cjs +4 -4
- package/dist/internal/native-server-fns.mjs +3 -3
- package/dist/internal/product-telemetry-runtime.cjs +3 -3
- package/dist/internal/product-telemetry-runtime.mjs +2 -2
- package/dist/internal/production-runtime.cjs +5 -5
- package/dist/internal/production-runtime.d.mts +7 -0
- package/dist/internal/production-runtime.d.ts +7 -0
- package/dist/internal/production-runtime.mjs +4 -4
- package/dist/{native-tree-WOX3JMBG.cjs → native-tree-HE2FLS72.cjs} +2 -2
- package/dist/{native-tree-BPEE2LAL.mjs → native-tree-YF2DSPKM.mjs} +1 -1
- package/dist/plugin.cjs +11 -10
- package/dist/plugin.mjs +10 -9
- package/dist/{rsc-pipeline-3LNVP2OO.mjs → rsc-pipeline-T3PWURLJ.mjs} +6 -5
- package/dist/{rsc-pipeline-G5WELVW3.cjs → rsc-pipeline-V4ANLRAA.cjs} +7 -6
- package/dist/{runtime-DMEULPE7.cjs → runtime-5AROV2C3.cjs} +12 -11
- package/dist/{runtime-HQJ2LLQL.mjs → runtime-LRIQ3XH7.mjs} +9 -8
- package/dist/server.cjs +36 -35
- package/dist/server.mjs +19 -18
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +14 -12
- package/dist/vite.mjs +13 -11
- package/package.json +1 -1
- package/dist/analyzer-ODLF2Z6O.cjs +0 -16
- package/dist/chunk-NK2VWS7P.cjs +0 -954
- package/dist/chunk-ZQ5BDNKW.mjs +0 -954
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
} from "./chunk-MK5E44WP.mjs";
|
|
42
42
|
import {
|
|
43
43
|
listFarmMCPLlmsTxtLinks
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-E2TSYUHV.mjs";
|
|
45
45
|
import {
|
|
46
46
|
FARM_DEFAULT_MCP_PATH,
|
|
47
47
|
collectFarmDefaultMCPPages,
|
|
@@ -55,41 +55,37 @@ import {
|
|
|
55
55
|
uninstallFarmIslandValues
|
|
56
56
|
} from "./chunk-A4PWGL46.mjs";
|
|
57
57
|
import {
|
|
58
|
-
|
|
59
|
-
isFarmIslandStrategy
|
|
60
|
-
} from "./chunk-S32PDOLO.mjs";
|
|
61
|
-
import {
|
|
58
|
+
collectFarmRenderedClientModules,
|
|
62
59
|
createEvaluatedRouteGraph,
|
|
60
|
+
createMarkdownPageHydrationPlanner,
|
|
61
|
+
describeSuppressedAsyncHydration,
|
|
62
|
+
enforceFarmIsolatedHydrationRouteBudget,
|
|
63
|
+
getClientModuleHydrationPlan,
|
|
64
|
+
getClientModuleMetadata,
|
|
65
|
+
getFarmClientHydrationPlanOptions,
|
|
66
|
+
getIslandStrategyExport,
|
|
63
67
|
mergeProgrammaticClientRoutes,
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
resolveFarmIsolatedClientHydrationMode,
|
|
69
|
+
resolveImportedModule,
|
|
70
|
+
resolveProgrammaticClientRoutes,
|
|
71
|
+
usesFarmServerTree
|
|
72
|
+
} from "./chunk-ZAUOOGER.mjs";
|
|
73
|
+
import {
|
|
74
|
+
FARM_ISLAND_REPLAYABLE_SELECTOR
|
|
75
|
+
} from "./chunk-S32PDOLO.mjs";
|
|
66
76
|
import {
|
|
67
77
|
isSecretDocsConfigKey
|
|
68
78
|
} from "./chunk-EJCVG25Z.mjs";
|
|
69
79
|
import {
|
|
70
|
-
getFarmProjectSourceDir,
|
|
71
80
|
resolveFarmAuthConfig,
|
|
72
|
-
resolveFarmDevIndicatorsConfig
|
|
73
|
-
|
|
74
|
-
} from "./chunk-PAKCHVUS.mjs";
|
|
81
|
+
resolveFarmDevIndicatorsConfig
|
|
82
|
+
} from "./chunk-TPA2PV5J.mjs";
|
|
75
83
|
import {
|
|
76
84
|
normalizeRouteRules
|
|
77
85
|
} from "./chunk-X3XUZWRB.mjs";
|
|
78
86
|
import {
|
|
79
87
|
resolveFarmDevtoolsConfig
|
|
80
88
|
} from "./chunk-CU5SYTJG.mjs";
|
|
81
|
-
import {
|
|
82
|
-
assertFarmRendererStreamingRuntime,
|
|
83
|
-
getFarmRendererCapabilities,
|
|
84
|
-
getFarmRendererComponentExtensions,
|
|
85
|
-
getFarmRendererStreamingCapabilitiesForRuntime,
|
|
86
|
-
isReactRenderer,
|
|
87
|
-
readFarmRendererWebStream,
|
|
88
|
-
resolveFarmComponentExtensions,
|
|
89
|
-
resolveFarmRenderer,
|
|
90
|
-
resolveFarmRendererAppSetup,
|
|
91
|
-
resolveFarmRendererModule
|
|
92
|
-
} from "./chunk-ES2LD2YD.mjs";
|
|
93
89
|
import {
|
|
94
90
|
createFarmAgentRobots,
|
|
95
91
|
createFarmDefaultSitemap,
|
|
@@ -112,2707 +108,244 @@ import {
|
|
|
112
108
|
renderFarmLlmsFullTxt,
|
|
113
109
|
resolveFarmLlmsTxtConfig
|
|
114
110
|
} from "./chunk-KL7SHLQB.mjs";
|
|
111
|
+
import {
|
|
112
|
+
resolveFarmServerComponentsMode
|
|
113
|
+
} from "./chunk-CJNAUEVC.mjs";
|
|
115
114
|
import {
|
|
116
115
|
getFarmAppDirectories,
|
|
117
116
|
getFarmSourceRoots
|
|
118
117
|
} from "./chunk-52Y3C3HG.mjs";
|
|
119
118
|
import {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
} from "./chunk-
|
|
145
|
-
import {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} from "./chunk-
|
|
170
|
-
import {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
} from "./chunk-
|
|
213
|
-
import {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
} from "./chunk-
|
|
311
|
-
import {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
} from "./chunk-
|
|
323
|
-
import {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
} from "./chunk-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
]);
|
|
342
|
-
var SERVER_CONDITIONS = ["react-server", "node", "import", "module", "default"];
|
|
343
|
-
var DEFAULT_CONDITIONS = ["node", "import", "module", "default"];
|
|
344
|
-
var SCRIPT_EXTENSIONS = ["", ".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx", ".mts"];
|
|
345
|
-
var INDEX_FILES = ["index.js", "index.mjs", "index.cjs", "index.ts", "index.tsx"];
|
|
346
|
-
function packageNameOf(specifier) {
|
|
347
|
-
if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("#") || specifier.includes(":") || specifier.includes("\0")) {
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
const parts = specifier.split("/");
|
|
351
|
-
const name = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
352
|
-
if (!name || specifier.startsWith("@") && parts.length < 2) return null;
|
|
353
|
-
return { name, subpath: parts.slice(name.startsWith("@") ? 2 : 1).join("/") };
|
|
354
|
-
}
|
|
355
|
-
function findPackageDirectory(importer, name) {
|
|
356
|
-
for (let current = path.dirname(importer); ; current = path.dirname(current)) {
|
|
357
|
-
const directory = path.join(current, "node_modules", name);
|
|
358
|
-
if (fs.existsSync(path.join(directory, "package.json"))) return fs.realpathSync(directory);
|
|
359
|
-
if (path.dirname(current) === current) return null;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
function pickTarget(value, conditions) {
|
|
363
|
-
if (typeof value === "string") return value;
|
|
364
|
-
if (Array.isArray(value)) {
|
|
365
|
-
for (const entry of value) {
|
|
366
|
-
const target = pickTarget(entry, conditions);
|
|
367
|
-
if (target) return target;
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
if (!value || typeof value !== "object") return null;
|
|
372
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
373
|
-
if (key === "types" || !conditions.includes(key)) continue;
|
|
374
|
-
const target = pickTarget(entry, conditions);
|
|
375
|
-
if (target) return target;
|
|
376
|
-
}
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
function exportEntry(exportsField, subpath) {
|
|
380
|
-
const key = subpath ? `./${subpath}` : ".";
|
|
381
|
-
if (typeof exportsField === "string" || Array.isArray(exportsField)) {
|
|
382
|
-
return key === "." ? exportsField : void 0;
|
|
383
|
-
}
|
|
384
|
-
if (!exportsField || typeof exportsField !== "object") return void 0;
|
|
385
|
-
const entries = exportsField;
|
|
386
|
-
if (!Object.keys(entries).some((entry) => entry.startsWith("."))) {
|
|
387
|
-
return key === "." ? entries : void 0;
|
|
388
|
-
}
|
|
389
|
-
if (entries[key] !== void 0) return entries[key];
|
|
390
|
-
for (const [pattern, value] of Object.entries(entries)) {
|
|
391
|
-
const star = pattern.indexOf("*");
|
|
392
|
-
if (star === -1) continue;
|
|
393
|
-
const prefix = pattern.slice(0, star);
|
|
394
|
-
const suffix = pattern.slice(star + 1);
|
|
395
|
-
if (key.startsWith(prefix) && key.endsWith(suffix)) {
|
|
396
|
-
const match = key.slice(prefix.length, key.length - suffix.length);
|
|
397
|
-
const replace = (target) => typeof target === "string" ? target.replace("*", match) : target && typeof target === "object" && !Array.isArray(target) ? Object.fromEntries(
|
|
398
|
-
Object.entries(target).map(([k, v]) => [k, replace(v)])
|
|
399
|
-
) : target;
|
|
400
|
-
return replace(value);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return void 0;
|
|
404
|
-
}
|
|
405
|
-
var cache = /* @__PURE__ */ new Map();
|
|
406
|
-
function resolveFarmReactServerExport(importer, specifier) {
|
|
407
|
-
const parsed = packageNameOf(specifier);
|
|
408
|
-
if (!parsed || REACT_PACKAGES.has(parsed.name) || parsed.name.startsWith("@farm.js/"))
|
|
409
|
-
return null;
|
|
410
|
-
const directory = findPackageDirectory(importer, parsed.name);
|
|
411
|
-
if (!directory) return null;
|
|
412
|
-
const key = `${directory}\0${parsed.subpath}`;
|
|
413
|
-
if (cache.has(key)) return cache.get(key);
|
|
414
|
-
let resolved = null;
|
|
415
|
-
try {
|
|
416
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"));
|
|
417
|
-
const entry = exportEntry(manifest.exports, parsed.subpath);
|
|
418
|
-
const server = pickTarget(entry, SERVER_CONDITIONS);
|
|
419
|
-
const fallback = pickTarget(entry, DEFAULT_CONDITIONS);
|
|
420
|
-
if (server && server !== fallback && server.startsWith("./")) {
|
|
421
|
-
const file = path.resolve(directory, server);
|
|
422
|
-
if (fs.existsSync(file)) resolved = file;
|
|
423
|
-
}
|
|
424
|
-
} catch {
|
|
425
|
-
resolved = null;
|
|
426
|
-
}
|
|
427
|
-
cache.set(key, resolved);
|
|
428
|
-
return resolved;
|
|
429
|
-
}
|
|
430
|
-
function readModule(file) {
|
|
431
|
-
try {
|
|
432
|
-
const code = fs.readFileSync(file, "utf8");
|
|
433
|
-
const extension = path.extname(file).slice(1);
|
|
434
|
-
const lang = extension === "ts" || extension === "mts" || extension === "cts" ? "ts" : "tsx";
|
|
435
|
-
return parseAst(code, { lang });
|
|
436
|
-
} catch {
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function isClientModule(program) {
|
|
441
|
-
for (const node of program.body ?? []) {
|
|
442
|
-
if (node.type !== "ExpressionStatement" || typeof node.directive !== "string") break;
|
|
443
|
-
if (node.directive === "use client") return true;
|
|
444
|
-
}
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
function resolveRelative(from, specifier) {
|
|
448
|
-
const base = path.resolve(path.dirname(from), specifier);
|
|
449
|
-
for (const extension of SCRIPT_EXTENSIONS) {
|
|
450
|
-
const file = `${base}${extension}`;
|
|
451
|
-
if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
|
|
452
|
-
}
|
|
453
|
-
for (const index of INDEX_FILES) {
|
|
454
|
-
const file = path.join(base, index);
|
|
455
|
-
if (fs.existsSync(file)) return file;
|
|
456
|
-
}
|
|
457
|
-
return null;
|
|
458
|
-
}
|
|
459
|
-
function exportedName(node) {
|
|
460
|
-
return node?.type === "Identifier" ? node.name : node?.value;
|
|
461
|
-
}
|
|
462
|
-
function isFarmClientExport(file, name, depth = 0) {
|
|
463
|
-
if (depth > 6) return false;
|
|
464
|
-
const program = readModule(file);
|
|
465
|
-
if (!program) return false;
|
|
466
|
-
if (isClientModule(program)) return true;
|
|
467
|
-
const stars = [];
|
|
468
|
-
for (const node of program.body ?? []) {
|
|
469
|
-
if (node.type === "ExportNamedDeclaration" && node.source) {
|
|
470
|
-
for (const specifier of node.specifiers ?? []) {
|
|
471
|
-
if (exportedName(specifier.exported) !== name) continue;
|
|
472
|
-
const target = resolveRelative(file, node.source.value);
|
|
473
|
-
return target ? isFarmClientExport(target, exportedName(specifier.local) ?? name, depth + 1) : false;
|
|
474
|
-
}
|
|
475
|
-
} else if (node.type === "ExportAllDeclaration" && node.source && !node.exported) {
|
|
476
|
-
stars.push(node.source.value);
|
|
477
|
-
} else if (node.type === "ExportNamedDeclaration" && !node.source) {
|
|
478
|
-
const names = [
|
|
479
|
-
...(node.specifiers ?? []).map((specifier) => exportedName(specifier.exported)),
|
|
480
|
-
...node.declaration?.id ? [node.declaration.id.name] : [],
|
|
481
|
-
...(node.declaration?.declarations ?? []).map((declarator) => declarator.id?.name)
|
|
482
|
-
];
|
|
483
|
-
if (names.includes(name)) return false;
|
|
484
|
-
} else if (node.type === "ExportDefaultDeclaration" && name === "default") {
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
for (const source of stars) {
|
|
489
|
-
const target = resolveRelative(file, source);
|
|
490
|
-
if (target && isFarmClientExport(target, name, depth + 1)) return true;
|
|
491
|
-
}
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
function parseCode(code, file) {
|
|
495
|
-
const extension = path.extname(file).slice(1);
|
|
496
|
-
const lang = extension === "ts" || extension === "mts" || extension === "cts" ? "ts" : "tsx";
|
|
497
|
-
try {
|
|
498
|
-
return parseAst(code, { lang });
|
|
499
|
-
} catch {
|
|
500
|
-
return null;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
function namespaceMembers(program, local) {
|
|
504
|
-
const members = /* @__PURE__ */ new Set();
|
|
505
|
-
let opaque = false;
|
|
506
|
-
const visit = (node, parent) => {
|
|
507
|
-
if (opaque || !node || typeof node !== "object") return;
|
|
508
|
-
if (Array.isArray(node)) {
|
|
509
|
-
for (const child of node) visit(child, parent);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
const current = node;
|
|
513
|
-
if (typeof current.type !== "string") return;
|
|
514
|
-
if ((current.type === "Identifier" || current.type === "JSXIdentifier") && current.name === local && parent?.type !== "ImportNamespaceSpecifier") {
|
|
515
|
-
const property2 = (parent?.type === "MemberExpression" || parent?.type === "JSXMemberExpression") && parent.object === current && !parent.computed ? parent.property?.name : void 0;
|
|
516
|
-
if (property2) members.add(property2);
|
|
517
|
-
else opaque = true;
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
for (const [key, value] of Object.entries(current)) {
|
|
521
|
-
if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
|
|
522
|
-
if (value && typeof value === "object") visit(value, current);
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
visit(program, null);
|
|
526
|
-
return opaque ? null : [...members];
|
|
527
|
-
}
|
|
528
|
-
function findPackageImports(program, accept) {
|
|
529
|
-
const found = [];
|
|
530
|
-
for (const node of program.body ?? []) {
|
|
531
|
-
if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
|
|
532
|
-
const specifier = node.source?.value;
|
|
533
|
-
if (typeof specifier !== "string" || !accept(specifier)) continue;
|
|
534
|
-
const specifiers = (node.specifiers ?? []).filter(
|
|
535
|
-
(entry2) => entry2.importKind !== "type"
|
|
536
|
-
);
|
|
537
|
-
if ((node.specifiers ?? []).length > 0 && specifiers.length === 0) continue;
|
|
538
|
-
const entry = {
|
|
539
|
-
start: node.start,
|
|
540
|
-
end: node.end,
|
|
541
|
-
specifier,
|
|
542
|
-
sideEffect: specifiers.length === 0,
|
|
543
|
-
named: []
|
|
544
|
-
};
|
|
545
|
-
for (const binding of specifiers) {
|
|
546
|
-
if (binding.type === "ImportDefaultSpecifier") entry.defaultLocal = binding.local.name;
|
|
547
|
-
else if (binding.type === "ImportNamespaceSpecifier") {
|
|
548
|
-
entry.namespace = {
|
|
549
|
-
local: binding.local.name,
|
|
550
|
-
members: namespaceMembers(program, binding.local.name)
|
|
551
|
-
};
|
|
552
|
-
} else {
|
|
553
|
-
const imported = exportedName(binding.imported);
|
|
554
|
-
if (imported) entry.named.push({ imported, local: binding.local.name });
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
found.push(entry);
|
|
558
|
-
}
|
|
559
|
-
return found;
|
|
560
|
-
}
|
|
561
|
-
function findFarmReactServerClientNames(code, file, specifier) {
|
|
562
|
-
const target = resolveFarmReactServerExport(file, specifier);
|
|
563
|
-
if (!target) return null;
|
|
564
|
-
const program = parseCode(code, file);
|
|
565
|
-
if (!program) return null;
|
|
566
|
-
const names = /* @__PURE__ */ new Set();
|
|
567
|
-
for (const entry of findPackageImports(program, (candidate) => candidate === specifier)) {
|
|
568
|
-
const wanted = [
|
|
569
|
-
...entry.defaultLocal ? ["default"] : [],
|
|
570
|
-
...entry.named.map((binding) => binding.imported),
|
|
571
|
-
...entry.namespace?.members ?? []
|
|
572
|
-
];
|
|
573
|
-
for (const name of wanted) if (isFarmClientExport(target, name)) names.add(name);
|
|
574
|
-
}
|
|
575
|
-
return [...names];
|
|
576
|
-
}
|
|
577
|
-
function rewriteFarmReactServerImports(options) {
|
|
578
|
-
if (!options.code.includes("import")) return null;
|
|
579
|
-
const program = parseCode(options.code, options.file);
|
|
580
|
-
if (!program) return null;
|
|
581
|
-
const targets = /* @__PURE__ */ new Map();
|
|
582
|
-
const imports = findPackageImports(program, (specifier) => {
|
|
583
|
-
const target = resolveFarmReactServerExport(options.file, specifier);
|
|
584
|
-
if (target) targets.set(specifier, target);
|
|
585
|
-
return target !== null;
|
|
586
|
-
});
|
|
587
|
-
if (imports.length === 0) return null;
|
|
588
|
-
let output = options.code;
|
|
589
|
-
let next = 0;
|
|
590
|
-
for (const entry of [...imports].sort((left, right) => right.start - left.start)) {
|
|
591
|
-
const target = targets.get(entry.specifier);
|
|
592
|
-
options.onServerFile?.(target);
|
|
593
|
-
const server = JSON.stringify(target);
|
|
594
|
-
const lines = [];
|
|
595
|
-
const bind = (name, local) => {
|
|
596
|
-
if (isFarmClientExport(target, name)) {
|
|
597
|
-
lines.push(
|
|
598
|
-
`import { ${name} as ${local} } from ${JSON.stringify(options.reference(entry.specifier, name))};`
|
|
599
|
-
);
|
|
600
|
-
} else lines.push(`import { ${name} as ${local} } from ${server};`);
|
|
601
|
-
};
|
|
602
|
-
if (entry.sideEffect) lines.push(`import ${server};`);
|
|
603
|
-
if (entry.defaultLocal) bind("default", entry.defaultLocal);
|
|
604
|
-
for (const binding of entry.named) bind(binding.imported, binding.local);
|
|
605
|
-
if (entry.namespace) {
|
|
606
|
-
if (entry.namespace.members === null) {
|
|
607
|
-
lines.push(`import * as ${entry.namespace.local} from ${server};`);
|
|
608
|
-
} else {
|
|
609
|
-
const fields = [];
|
|
610
|
-
for (const member of entry.namespace.members) {
|
|
611
|
-
const local = `__farm_react_server_${next++}__`;
|
|
612
|
-
bind(member, local);
|
|
613
|
-
fields.push(`${member}: ${local}`);
|
|
614
|
-
}
|
|
615
|
-
lines.push(`const ${entry.namespace.local} = Object.freeze({ ${fields.join(", ")} });`);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
output = output.slice(0, entry.start) + lines.join("\n") + output.slice(entry.end);
|
|
619
|
-
}
|
|
620
|
-
return output;
|
|
621
|
-
}
|
|
622
|
-
function farmRelativeImportFiles(code, file) {
|
|
623
|
-
const program = parseCode(code, file);
|
|
624
|
-
if (!program) return [];
|
|
625
|
-
const files = [];
|
|
626
|
-
for (const node of program.body ?? []) {
|
|
627
|
-
const source = (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration" && node.source) && node.source?.value;
|
|
628
|
-
if (typeof source !== "string" || !source.startsWith(".")) continue;
|
|
629
|
-
const resolved = resolveRelative(file, source);
|
|
630
|
-
if (resolved) files.push(resolved);
|
|
631
|
-
}
|
|
632
|
-
return files;
|
|
633
|
-
}
|
|
634
|
-
function farmReactServerBuildReachesClientModules(importer, specifier) {
|
|
635
|
-
const target = resolveFarmReactServerExport(importer, specifier);
|
|
636
|
-
if (!target) return false;
|
|
637
|
-
const seen = /* @__PURE__ */ new Set();
|
|
638
|
-
const reaches = (file, depth) => {
|
|
639
|
-
if (depth > 6 || seen.has(file)) return false;
|
|
640
|
-
seen.add(file);
|
|
641
|
-
const program = readModule(file);
|
|
642
|
-
if (!program) return false;
|
|
643
|
-
if (depth > 0 && isClientModule(program)) return true;
|
|
644
|
-
for (const node of program.body ?? []) {
|
|
645
|
-
const source = (node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration" && node.source || node.type === "ImportDeclaration") && node.source?.value;
|
|
646
|
-
if (typeof source !== "string" || !source.startsWith(".")) continue;
|
|
647
|
-
const child = resolveRelative(file, source);
|
|
648
|
-
if (child && reaches(child, depth + 1)) return true;
|
|
649
|
-
}
|
|
650
|
-
return false;
|
|
651
|
-
};
|
|
652
|
-
return reaches(target, 0);
|
|
653
|
-
}
|
|
654
|
-
var IMPORT_SPECIFIER = /(?:\bfrom\s*|\bimport\s*\(?\s*)["']([^"'./][^"']*)["']/g;
|
|
655
|
-
var MAX_SCANNED_FILES = 2e3;
|
|
656
|
-
function packageImportSpecifiers(directory) {
|
|
657
|
-
const found = /* @__PURE__ */ new Set();
|
|
658
|
-
const pending = [directory];
|
|
659
|
-
let scanned = 0;
|
|
660
|
-
while (pending.length > 0 && scanned < MAX_SCANNED_FILES) {
|
|
661
|
-
const current = pending.pop();
|
|
662
|
-
let entries;
|
|
663
|
-
try {
|
|
664
|
-
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
665
|
-
} catch {
|
|
666
|
-
continue;
|
|
667
|
-
}
|
|
668
|
-
for (const entry of entries) {
|
|
669
|
-
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
670
|
-
const file = path.join(current, entry.name);
|
|
671
|
-
if (entry.isDirectory()) pending.push(file);
|
|
672
|
-
else if (/\.(?:m?js|jsx)$/.test(entry.name) && scanned++ < MAX_SCANNED_FILES) {
|
|
673
|
-
let code;
|
|
674
|
-
try {
|
|
675
|
-
code = fs.readFileSync(file, "utf8");
|
|
676
|
-
} catch {
|
|
677
|
-
continue;
|
|
678
|
-
}
|
|
679
|
-
for (const match of code.matchAll(IMPORT_SPECIFIER)) found.add(match[1]);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
return found;
|
|
684
|
-
}
|
|
685
|
-
function findFarmPackageManifest(importer, specifier) {
|
|
686
|
-
const parsed = packageNameOf(specifier);
|
|
687
|
-
if (!parsed) return null;
|
|
688
|
-
const directory = findPackageDirectory(importer, parsed.name);
|
|
689
|
-
if (!directory) return null;
|
|
690
|
-
let names;
|
|
691
|
-
try {
|
|
692
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"));
|
|
693
|
-
names = new Set(Object.keys(manifest.dependencies ?? {}));
|
|
694
|
-
} catch {
|
|
695
|
-
return null;
|
|
696
|
-
}
|
|
697
|
-
const dependencies = [...packageImportSpecifiers(directory)].filter((imported) => {
|
|
698
|
-
const name = packageNameOf(imported)?.name;
|
|
699
|
-
return name !== void 0 && names.has(name);
|
|
700
|
-
});
|
|
701
|
-
return { name: parsed.name, dependencies: dependencies.sort() };
|
|
702
|
-
}
|
|
703
|
-
function listFarmPackageExports(importer, specifier) {
|
|
704
|
-
const parsed = packageNameOf(specifier);
|
|
705
|
-
if (!parsed) return null;
|
|
706
|
-
const directory = findPackageDirectory(importer, parsed.name);
|
|
707
|
-
if (!directory) return null;
|
|
708
|
-
let entry = null;
|
|
709
|
-
try {
|
|
710
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"));
|
|
711
|
-
const target = pickTarget(exportEntry(manifest.exports, parsed.subpath), [
|
|
712
|
-
"browser",
|
|
713
|
-
...DEFAULT_CONDITIONS
|
|
714
|
-
]) ?? (!parsed.subpath ? manifest.module ?? manifest.main ?? "index.js" : parsed.subpath);
|
|
715
|
-
entry = resolveRelative(
|
|
716
|
-
path.join(directory, "package.json"),
|
|
717
|
-
`./${String(target).replace(/^\.\//, "")}`
|
|
718
|
-
);
|
|
719
|
-
} catch {
|
|
720
|
-
return null;
|
|
721
|
-
}
|
|
722
|
-
if (!entry) return null;
|
|
723
|
-
const names = /* @__PURE__ */ new Set();
|
|
724
|
-
const seen = /* @__PURE__ */ new Set();
|
|
725
|
-
const collect = (file, depth) => {
|
|
726
|
-
if (depth > 8 || seen.has(file)) return true;
|
|
727
|
-
seen.add(file);
|
|
728
|
-
const program = readModule(file);
|
|
729
|
-
if (!program) return false;
|
|
730
|
-
let esm = false;
|
|
731
|
-
for (const node of program.body ?? []) {
|
|
732
|
-
if (node.type === "ExportAllDeclaration" && node.source && !node.exported) {
|
|
733
|
-
esm = true;
|
|
734
|
-
const child = resolveRelative(file, node.source.value);
|
|
735
|
-
if (!child || !collect(child, depth + 1)) return false;
|
|
736
|
-
} else if (node.type === "ExportAllDeclaration" && node.exported) {
|
|
737
|
-
esm = true;
|
|
738
|
-
const name = exportedName(node.exported);
|
|
739
|
-
if (name) names.add(name);
|
|
740
|
-
} else if (node.type === "ExportNamedDeclaration") {
|
|
741
|
-
esm = true;
|
|
742
|
-
for (const specifier2 of node.specifiers ?? []) {
|
|
743
|
-
const name = exportedName(specifier2.exported);
|
|
744
|
-
if (name) names.add(name);
|
|
745
|
-
}
|
|
746
|
-
if (node.declaration?.id?.name) names.add(node.declaration.id.name);
|
|
747
|
-
for (const declarator of node.declaration?.declarations ?? []) {
|
|
748
|
-
if (declarator.id?.type === "Identifier") names.add(declarator.id.name);
|
|
749
|
-
}
|
|
750
|
-
} else if (node.type === "ExportDefaultDeclaration") {
|
|
751
|
-
esm = true;
|
|
752
|
-
names.add("default");
|
|
753
|
-
} else if (node.type === "ImportDeclaration") {
|
|
754
|
-
esm = true;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
return esm || depth > 0;
|
|
758
|
-
};
|
|
759
|
-
if (!collect(entry, 0)) return null;
|
|
760
|
-
return [...names].filter((name) => /^[A-Za-z_$][\w$]*$/.test(name)).sort();
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// src/islands-package-references.ts
|
|
764
|
-
import fs2 from "fs";
|
|
765
|
-
import path2 from "path";
|
|
766
|
-
import { parseAst as parseAst2 } from "rolldown/parseAst";
|
|
767
|
-
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
768
|
-
function parse(code, file) {
|
|
769
|
-
const extension = path2.extname(file).slice(1);
|
|
770
|
-
const lang = extension === "ts" || extension === "mts" || extension === "cts" ? "ts" : "tsx";
|
|
771
|
-
try {
|
|
772
|
-
return parseAst2(code, { lang });
|
|
773
|
-
} catch {
|
|
774
|
-
return null;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
function walk(node, visit, parent = null) {
|
|
778
|
-
if (!node || typeof node !== "object") return;
|
|
779
|
-
if (Array.isArray(node)) {
|
|
780
|
-
for (const child of node) walk(child, visit, parent);
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
const current = node;
|
|
784
|
-
if (typeof current.type !== "string") return;
|
|
785
|
-
visit(current, parent);
|
|
786
|
-
for (const [key, value] of Object.entries(current)) {
|
|
787
|
-
if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
|
|
788
|
-
if (value && typeof value === "object") walk(value, visit, current);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
function namespaceMembers2(program, local, declaration) {
|
|
792
|
-
const members = /* @__PURE__ */ new Set();
|
|
793
|
-
let opaque = false;
|
|
794
|
-
walk(program, (node, parent) => {
|
|
795
|
-
if (opaque || node === declaration) return;
|
|
796
|
-
const name = node.type === "Identifier" || node.type === "JSXIdentifier" ? node.name : null;
|
|
797
|
-
if (name !== local) return;
|
|
798
|
-
if (parent?.type === "ImportNamespaceSpecifier") return;
|
|
799
|
-
const member = (parent?.type === "MemberExpression" || parent?.type === "JSXMemberExpression") && parent.object === node ? parent.property : null;
|
|
800
|
-
const property2 = member && !parent.computed && (member.type === "Identifier" || member.type === "JSXIdentifier") ? member.name : null;
|
|
801
|
-
if (property2) members.add(property2);
|
|
802
|
-
else opaque = true;
|
|
803
|
-
});
|
|
804
|
-
return opaque ? null : [...members];
|
|
805
|
-
}
|
|
806
|
-
function findFarmPackageClientImports(code, file, isClientPackage) {
|
|
807
|
-
if (!code.includes("import")) return [];
|
|
808
|
-
const program = parse(code, file);
|
|
809
|
-
if (!program) return [];
|
|
810
|
-
const found = [];
|
|
811
|
-
for (const node of program.body ?? []) {
|
|
812
|
-
if (node.type !== "ImportDeclaration" || node.importKind === "type") continue;
|
|
813
|
-
const specifier = node.source?.value;
|
|
814
|
-
if (typeof specifier !== "string" || specifier.startsWith(".") || specifier.startsWith("/"))
|
|
815
|
-
continue;
|
|
816
|
-
const specifiers = (node.specifiers ?? []).filter(
|
|
817
|
-
(entry2) => entry2.importKind !== "type"
|
|
818
|
-
);
|
|
819
|
-
if (specifiers.length === 0 || !isClientPackage(specifier)) continue;
|
|
820
|
-
const entry = {
|
|
821
|
-
start: node.start,
|
|
822
|
-
end: node.end,
|
|
823
|
-
specifier,
|
|
824
|
-
named: []
|
|
825
|
-
};
|
|
826
|
-
let supported = true;
|
|
827
|
-
for (const binding of specifiers) {
|
|
828
|
-
if (binding.type === "ImportDefaultSpecifier") entry.defaultLocal = binding.local.name;
|
|
829
|
-
else if (binding.type === "ImportNamespaceSpecifier") {
|
|
830
|
-
const read = namespaceMembers2(program, binding.local.name, node);
|
|
831
|
-
const members = read ?? listFarmPackageExports(file, specifier);
|
|
832
|
-
if (!members || members.some((member) => !IDENTIFIER.test(member))) supported = false;
|
|
833
|
-
else if (read) entry.namespace = { local: binding.local.name, members };
|
|
834
|
-
else {
|
|
835
|
-
const component = (name) => name === "default" || /^[A-Z]/.test(name);
|
|
836
|
-
entry.namespace = {
|
|
837
|
-
local: binding.local.name,
|
|
838
|
-
members: members.filter(component),
|
|
839
|
-
values: members.filter((name) => !component(name))
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
} else {
|
|
843
|
-
const imported = binding.imported?.type === "Identifier" ? binding.imported.name : binding.imported?.value;
|
|
844
|
-
if (typeof imported !== "string" || !IDENTIFIER.test(imported)) supported = false;
|
|
845
|
-
else entry.named.push({ imported, local: binding.local.name });
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
if (supported) found.push(entry);
|
|
849
|
-
}
|
|
850
|
-
return found;
|
|
851
|
-
}
|
|
852
|
-
function farmPackageClientImportExports(entry) {
|
|
853
|
-
return [
|
|
854
|
-
...entry.defaultLocal ? ["default"] : [],
|
|
855
|
-
...entry.named.map((binding) => binding.imported),
|
|
856
|
-
...entry.namespace?.members ?? []
|
|
857
|
-
];
|
|
858
|
-
}
|
|
859
|
-
function farmPackageClientReferencePath(root, specifier, exportName) {
|
|
860
|
-
const directory = specifier.replace(/^@/, "").replace(/[^A-Za-z0-9._-]/g, "+");
|
|
861
|
-
return path2.join(root, ".farm", "client-references", directory, `${exportName}.tsx`);
|
|
862
|
-
}
|
|
863
|
-
function ensureFarmPackageClientReference(root, specifier, exportName) {
|
|
864
|
-
const file = farmPackageClientReferencePath(root, specifier, exportName);
|
|
865
|
-
const source = [
|
|
866
|
-
`// Generated by Farm: ${specifier}'s ${exportName} export, as a client reference for server components.`,
|
|
867
|
-
'"use client";',
|
|
868
|
-
`export { ${exportName} } from ${JSON.stringify(specifier)};`,
|
|
869
|
-
""
|
|
870
|
-
].join("\n");
|
|
871
|
-
let current = null;
|
|
872
|
-
try {
|
|
873
|
-
current = fs2.readFileSync(file, "utf8");
|
|
874
|
-
} catch {
|
|
875
|
-
}
|
|
876
|
-
if (current !== source) {
|
|
877
|
-
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
878
|
-
fs2.writeFileSync(file, source);
|
|
879
|
-
}
|
|
880
|
-
return file;
|
|
881
|
-
}
|
|
882
|
-
function rewriteFarmPackageClientImports(options) {
|
|
883
|
-
const imports = findFarmPackageClientImports(options.code, options.file, options.isClientPackage);
|
|
884
|
-
if (imports.length === 0) return null;
|
|
885
|
-
const reference = (specifier, exportName) => JSON.stringify(ensureFarmPackageClientReference(options.root, specifier, exportName));
|
|
886
|
-
let output = options.code;
|
|
887
|
-
let next = 0;
|
|
888
|
-
for (const entry of [...imports].sort((left, right) => right.start - left.start)) {
|
|
889
|
-
const lines = [];
|
|
890
|
-
if (entry.defaultLocal) {
|
|
891
|
-
lines.push(`import ${entry.defaultLocal} from ${reference(entry.specifier, "default")};`);
|
|
892
|
-
}
|
|
893
|
-
for (const binding of entry.named) {
|
|
894
|
-
lines.push(
|
|
895
|
-
`import { ${binding.imported} as ${binding.local} } from ${reference(entry.specifier, binding.imported)};`
|
|
896
|
-
);
|
|
897
|
-
}
|
|
898
|
-
if (entry.namespace) {
|
|
899
|
-
const fields = [];
|
|
900
|
-
for (const member of entry.namespace.members) {
|
|
901
|
-
const local = `__farm_package_reference_${next++}__`;
|
|
902
|
-
lines.push(`import { ${member} as ${local} } from ${reference(entry.specifier, member)};`);
|
|
903
|
-
fields.push(`${member}: ${local}`);
|
|
904
|
-
}
|
|
905
|
-
if (entry.namespace.values?.length) {
|
|
906
|
-
const local = `__farm_package_values_${next++}__`;
|
|
907
|
-
lines.push(`import * as ${local} from ${JSON.stringify(entry.specifier)};`);
|
|
908
|
-
for (const value of entry.namespace.values) fields.push(`${value}: ${local}.${value}`);
|
|
909
|
-
}
|
|
910
|
-
lines.push(`const ${entry.namespace.local} = Object.freeze({ ${fields.join(", ")} });`);
|
|
911
|
-
}
|
|
912
|
-
output = output.slice(0, entry.start) + lines.join("\n") + output.slice(entry.end);
|
|
913
|
-
}
|
|
914
|
-
return output;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
// src/utils/client-component.ts
|
|
918
|
-
import fs4 from "fs";
|
|
919
|
-
import path4 from "path";
|
|
920
|
-
import { fileURLToPath } from "url";
|
|
921
|
-
|
|
922
|
-
// src/utils/package-client-boundary-cache.ts
|
|
923
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
924
|
-
import fs3 from "fs";
|
|
925
|
-
import path3 from "path";
|
|
926
|
-
var SCHEMA_VERSION = 1;
|
|
927
|
-
var NODE_MODULES_SEGMENT = `${path3.sep}node_modules${path3.sep}`;
|
|
928
|
-
var PackageInspectionTrace = class {
|
|
929
|
-
constructor() {
|
|
930
|
-
this.files = /* @__PURE__ */ new Set();
|
|
931
|
-
this.stops = /* @__PURE__ */ new Set();
|
|
932
|
-
this.fileStamps = [];
|
|
933
|
-
this.directoryStamps = /* @__PURE__ */ new Map();
|
|
934
|
-
}
|
|
935
|
-
visit(file) {
|
|
936
|
-
this.files.add(file);
|
|
937
|
-
const directory = path3.dirname(file);
|
|
938
|
-
if (!this.directoryStamps.has(directory)) {
|
|
939
|
-
this.directoryStamps.set(directory, stampPackagePath(directory, "directory"));
|
|
940
|
-
}
|
|
941
|
-
this.fileStamps.push(stampPackagePath(file, "file"));
|
|
942
|
-
}
|
|
943
|
-
/** The inspection reached `file` after it was already visited. */
|
|
944
|
-
stop(file) {
|
|
945
|
-
if (!this.files.has(file)) this.stops.add(file);
|
|
946
|
-
}
|
|
947
|
-
toEntry(result) {
|
|
948
|
-
const entry = {
|
|
949
|
-
result: { ...result },
|
|
950
|
-
files: Array.from(this.files),
|
|
951
|
-
stops: Array.from(this.stops)
|
|
952
|
-
};
|
|
953
|
-
const files = this.fileStamps.filter((stamp) => stamp !== void 0);
|
|
954
|
-
const directories = Array.from(this.directoryStamps.values()).filter(
|
|
955
|
-
(stamp) => stamp !== void 0
|
|
956
|
-
);
|
|
957
|
-
if (files.length === this.fileStamps.length && directories.length === this.directoryStamps.size) {
|
|
958
|
-
entry.stamps = { files, directories };
|
|
959
|
-
}
|
|
960
|
-
return entry;
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
function stampPackagePath(target, kind) {
|
|
964
|
-
if (!`${target}${path3.sep}`.includes(NODE_MODULES_SEGMENT)) return void 0;
|
|
965
|
-
try {
|
|
966
|
-
const stat = fs3.statSync(target, { throwIfNoEntry: false });
|
|
967
|
-
if (!stat || (kind === "file" ? !stat.isFile() : !stat.isDirectory())) return void 0;
|
|
968
|
-
return [target, stat.size, stat.mtimeMs, stat.ctimeMs];
|
|
969
|
-
} catch {
|
|
970
|
-
return void 0;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
var PackageClientBoundaryCache = class {
|
|
974
|
-
constructor() {
|
|
975
|
-
this.entries = /* @__PURE__ */ new Map();
|
|
976
|
-
this.stored = /* @__PURE__ */ new Map();
|
|
977
|
-
this.storedPaths = [];
|
|
978
|
-
this.unchangedPaths = /* @__PURE__ */ new Map();
|
|
979
|
-
this.dirty = false;
|
|
980
|
-
}
|
|
981
|
-
load(file) {
|
|
982
|
-
this.file = file;
|
|
983
|
-
const stored = readStoredCache(file);
|
|
984
|
-
if (!stored) {
|
|
985
|
-
this.dirty = true;
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
this.storedPaths = stored.paths;
|
|
989
|
-
this.stored = new Map(Object.entries(stored.entries));
|
|
990
|
-
}
|
|
991
|
-
/** An inspection of `key` that applies to `visited`. */
|
|
992
|
-
find(key, visited) {
|
|
993
|
-
let entries = this.entries.get(key);
|
|
994
|
-
const stored = this.stored.get(key);
|
|
995
|
-
if (stored) {
|
|
996
|
-
this.stored.delete(key);
|
|
997
|
-
entries ?? (entries = []);
|
|
998
|
-
this.entries.set(key, entries);
|
|
999
|
-
for (const entry of stored) {
|
|
1000
|
-
const restored = this.restore(entry);
|
|
1001
|
-
if (restored) entries.push(restored);
|
|
1002
|
-
else this.dirty = true;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
return entries?.find(
|
|
1006
|
-
(entry) => entry.stops.every((file) => visited.has(file)) && !entry.files.some((file) => visited.has(file))
|
|
1007
|
-
);
|
|
1008
|
-
}
|
|
1009
|
-
add(key, entry) {
|
|
1010
|
-
const entries = this.entries.get(key);
|
|
1011
|
-
if (entries) entries.push(entry);
|
|
1012
|
-
else this.entries.set(key, [entry]);
|
|
1013
|
-
if (entry.stamps) this.dirty = true;
|
|
1014
|
-
}
|
|
1015
|
-
async persist() {
|
|
1016
|
-
const file = this.file;
|
|
1017
|
-
if (!file || !this.dirty && this.stored.size === 0) return;
|
|
1018
|
-
const paths = [];
|
|
1019
|
-
const pathIndexes = /* @__PURE__ */ new Map();
|
|
1020
|
-
const indexOf = (stamp) => {
|
|
1021
|
-
let index = pathIndexes.get(stamp[0]);
|
|
1022
|
-
if (index === void 0) {
|
|
1023
|
-
index = paths.push(stamp) - 1;
|
|
1024
|
-
pathIndexes.set(stamp[0], index);
|
|
1025
|
-
}
|
|
1026
|
-
return index;
|
|
1027
|
-
};
|
|
1028
|
-
const entries = {};
|
|
1029
|
-
for (const [key, variants] of this.entries) {
|
|
1030
|
-
const persisted = variants.flatMap(
|
|
1031
|
-
({ result, stops, stamps }) => stamps ? [
|
|
1032
|
-
{
|
|
1033
|
-
result,
|
|
1034
|
-
files: stamps.files.map(indexOf),
|
|
1035
|
-
directories: stamps.directories.map(indexOf),
|
|
1036
|
-
stops
|
|
1037
|
-
}
|
|
1038
|
-
] : []
|
|
1039
|
-
);
|
|
1040
|
-
if (persisted.length > 0) entries[key] = persisted;
|
|
1041
|
-
}
|
|
1042
|
-
const contents = JSON.stringify({
|
|
1043
|
-
schema: SCHEMA_VERSION,
|
|
1044
|
-
farm: FARM_VERSION,
|
|
1045
|
-
paths,
|
|
1046
|
-
entries
|
|
1047
|
-
});
|
|
1048
|
-
const temporary = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
1049
|
-
try {
|
|
1050
|
-
await fs3.promises.mkdir(path3.dirname(file), { recursive: true });
|
|
1051
|
-
await fs3.promises.writeFile(temporary, contents);
|
|
1052
|
-
await fs3.promises.rename(temporary, file);
|
|
1053
|
-
} catch {
|
|
1054
|
-
await fs3.promises.rm(temporary, { force: true }).catch(() => {
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
restore(entry) {
|
|
1059
|
-
const files = this.restoreStamps(entry.files, "file");
|
|
1060
|
-
const directories = this.restoreStamps(entry.directories, "directory");
|
|
1061
|
-
if (!files || !directories) return void 0;
|
|
1062
|
-
return {
|
|
1063
|
-
result: entry.result,
|
|
1064
|
-
files: files.map(([file]) => file),
|
|
1065
|
-
stops: entry.stops,
|
|
1066
|
-
stamps: { files, directories }
|
|
1067
|
-
};
|
|
1068
|
-
}
|
|
1069
|
-
restoreStamps(indexes, kind) {
|
|
1070
|
-
const stamps = [];
|
|
1071
|
-
for (const index of indexes) {
|
|
1072
|
-
const stamp = this.storedPaths[index];
|
|
1073
|
-
let unchanged = this.unchangedPaths.get(index);
|
|
1074
|
-
if (unchanged === void 0) {
|
|
1075
|
-
const current = stampPackagePath(stamp[0], kind);
|
|
1076
|
-
unchanged = current !== void 0 && current[1] === stamp[1] && current[2] === stamp[2] && current[3] === stamp[3];
|
|
1077
|
-
this.unchangedPaths.set(index, unchanged);
|
|
1078
|
-
}
|
|
1079
|
-
if (!unchanged) return void 0;
|
|
1080
|
-
stamps.push(stamp);
|
|
1081
|
-
}
|
|
1082
|
-
return stamps;
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
function readStoredCache(file) {
|
|
1086
|
-
let value;
|
|
1087
|
-
try {
|
|
1088
|
-
value = JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
1089
|
-
} catch {
|
|
1090
|
-
return null;
|
|
1091
|
-
}
|
|
1092
|
-
if (!isRecord(value) || value.schema !== SCHEMA_VERSION || value.farm !== FARM_VERSION) {
|
|
1093
|
-
return null;
|
|
1094
|
-
}
|
|
1095
|
-
const { paths, entries } = value;
|
|
1096
|
-
if (!Array.isArray(paths) || !paths.every(isPathStamp) || !isRecord(entries)) return null;
|
|
1097
|
-
const valid = {};
|
|
1098
|
-
for (const [key, variants] of Object.entries(entries)) {
|
|
1099
|
-
if (!Array.isArray(variants)) continue;
|
|
1100
|
-
const usable = variants.filter((entry) => isStoredEntry(entry, paths.length));
|
|
1101
|
-
if (usable.length > 0) valid[key] = usable;
|
|
1102
|
-
}
|
|
1103
|
-
return { schema: SCHEMA_VERSION, farm: FARM_VERSION, paths, entries: valid };
|
|
1104
|
-
}
|
|
1105
|
-
function isRecord(value) {
|
|
1106
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1107
|
-
}
|
|
1108
|
-
function isPathStamp(value) {
|
|
1109
|
-
return Array.isArray(value) && value.length === 4 && typeof value[0] === "string" && path3.isAbsolute(value[0]) && value.slice(1).every((part) => typeof part === "number" && Number.isFinite(part));
|
|
1110
|
-
}
|
|
1111
|
-
function isPathIndexList(value, pathCount) {
|
|
1112
|
-
return Array.isArray(value) && value.length > 0 && value.every((index) => Number.isSafeInteger(index) && index >= 0 && index < pathCount);
|
|
1113
|
-
}
|
|
1114
|
-
function isStoredEntry(value, pathCount) {
|
|
1115
|
-
if (!isRecord(value) || !isRecord(value.result)) return false;
|
|
1116
|
-
const { isClientComponent, shouldHydrate, islandStrategy } = value.result;
|
|
1117
|
-
return isPathIndexList(value.files, pathCount) && isPathIndexList(value.directories, pathCount) && Array.isArray(value.stops) && value.stops.every((file) => typeof file === "string" && path3.isAbsolute(file)) && typeof isClientComponent === "boolean" && typeof shouldHydrate === "boolean" && (islandStrategy === null || isFarmIslandStrategy(islandStrategy)) && Object.keys(value.result).length === 3;
|
|
1118
|
-
}
|
|
1119
|
-
var STORAGE_KEY = /* @__PURE__ */ Symbol.for("@farm.js/core/package-client-boundary-cache");
|
|
1120
|
-
function getStorage() {
|
|
1121
|
-
const runtime = globalThis;
|
|
1122
|
-
const existing = runtime[STORAGE_KEY];
|
|
1123
|
-
if (existing instanceof AsyncLocalStorage) {
|
|
1124
|
-
return existing;
|
|
1125
|
-
}
|
|
1126
|
-
const storage = new AsyncLocalStorage();
|
|
1127
|
-
runtime[STORAGE_KEY] = storage;
|
|
1128
|
-
return storage;
|
|
1129
|
-
}
|
|
1130
|
-
function getPackageClientBoundaryCache() {
|
|
1131
|
-
return getStorage().getStore();
|
|
1132
|
-
}
|
|
1133
|
-
async function withPackageClientBoundaryCache(operation) {
|
|
1134
|
-
const cache3 = new PackageClientBoundaryCache();
|
|
1135
|
-
try {
|
|
1136
|
-
return await getStorage().run(cache3, operation);
|
|
1137
|
-
} finally {
|
|
1138
|
-
await cache3.persist();
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
function usePackageClientBoundaryCacheFile(file) {
|
|
1142
|
-
getPackageClientBoundaryCache()?.load(file);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
// src/utils/client-component.ts
|
|
1146
|
-
function readIfExists(filePath) {
|
|
1147
|
-
try {
|
|
1148
|
-
if (!filePath || !fs4.existsSync(filePath)) {
|
|
1149
|
-
return null;
|
|
1150
|
-
}
|
|
1151
|
-
return fs4.readFileSync(filePath, "utf-8");
|
|
1152
|
-
} catch {
|
|
1153
|
-
return null;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
function resolveModuleSourcePath(modulePath, root) {
|
|
1157
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
1158
|
-
const withoutQuery = modulePath.split("?")[0];
|
|
1159
|
-
if (modulePath) {
|
|
1160
|
-
candidates.add(modulePath);
|
|
1161
|
-
candidates.add(withoutQuery);
|
|
1162
|
-
if (modulePath.startsWith("file://")) {
|
|
1163
|
-
try {
|
|
1164
|
-
candidates.add(fileURLToPath(modulePath));
|
|
1165
|
-
} catch {
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
if (modulePath.startsWith("/@fs/")) {
|
|
1169
|
-
const fsPath = withoutQuery.slice("/@fs/".length);
|
|
1170
|
-
candidates.add(path4.normalize(/^[A-Za-z]:/.test(fsPath) ? fsPath : `/${fsPath}`));
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
if (root && modulePath) {
|
|
1174
|
-
const normalized = withoutQuery.replace(/^\/+/, "");
|
|
1175
|
-
candidates.add(path4.join(root, normalized));
|
|
1176
|
-
candidates.add(path4.resolve(root, normalized));
|
|
1177
|
-
}
|
|
1178
|
-
if (withoutQuery?.startsWith("/src/")) {
|
|
1179
|
-
const normalized = withoutQuery.replace(/^\/+/, "");
|
|
1180
|
-
candidates.add(path4.join(process.cwd(), normalized));
|
|
1181
|
-
candidates.add(path4.resolve(process.cwd(), normalized));
|
|
1182
|
-
}
|
|
1183
|
-
for (const candidate of candidates) {
|
|
1184
|
-
if (fs4.existsSync(candidate)) {
|
|
1185
|
-
return candidate;
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
return null;
|
|
1189
|
-
}
|
|
1190
|
-
function getFarmClientHydrationPlanOptions(renderer, hasUnsupportedIntegrationProvider) {
|
|
1191
|
-
return { asyncOwnerIslands: isReactRenderer(renderer) && !hasUnsupportedIntegrationProvider };
|
|
1192
|
-
}
|
|
1193
|
-
function describeSuppressedAsyncHydration(subject, reason) {
|
|
1194
|
-
const remediation = reason ? "Fix the reason above, or render the interactive UI from a synchronous owner." : 'Move the interactive UI into an eligible "use client" boundary, or render it from a synchronous owner.';
|
|
1195
|
-
return `${subject} is an async server component with client-side hydration enabled. React cannot hydrate an async component, and that hydration could not be moved to isolated islands${reason ? ` (${reason})` : ""}, so it stays server-rendered without client-side interactivity. ${remediation}`;
|
|
1196
|
-
}
|
|
1197
|
-
var FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES = 4;
|
|
1198
|
-
function isolatedHydrationBoundaryLimit() {
|
|
1199
|
-
const benchmarkRoot = process.env.FARM_INTERNAL_ISOLATED_HYDRATION_BENCHMARK_ROOT;
|
|
1200
|
-
const benchmarkLimit = Number(process.env.FARM_INTERNAL_ISOLATED_HYDRATION_BENCHMARK_LIMIT);
|
|
1201
|
-
const resolvedBenchmarkRoot = benchmarkRoot ? path4.resolve(benchmarkRoot) : null;
|
|
1202
|
-
const isBenchmarkFixture = process.env.FARM_INTERNAL_BENCHMARK === "isolated-hydration" && resolvedBenchmarkRoot !== null && (process.cwd() === resolvedBenchmarkRoot || process.cwd().startsWith(`${resolvedBenchmarkRoot}${path4.sep}`));
|
|
1203
|
-
return isBenchmarkFixture && Number.isSafeInteger(benchmarkLimit) && benchmarkLimit > FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES ? benchmarkLimit : FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES;
|
|
1204
|
-
}
|
|
1205
|
-
var RESOLVABLE_SOURCE_EXTENSIONS = [
|
|
1206
|
-
".svelte",
|
|
1207
|
-
".vue",
|
|
1208
|
-
".tsx",
|
|
1209
|
-
".ts",
|
|
1210
|
-
".jsx",
|
|
1211
|
-
".js",
|
|
1212
|
-
".mts",
|
|
1213
|
-
".mjs",
|
|
1214
|
-
".cts",
|
|
1215
|
-
".cjs"
|
|
1216
|
-
];
|
|
1217
|
-
function resolveFarmIsolatedClientHydrationMode(mode, options = {}) {
|
|
1218
|
-
if (options.serverComponents) return "off";
|
|
1219
|
-
if (mode === "enabled" && options.hasUnsupportedIntegrationProvider) return "off";
|
|
1220
|
-
return mode ?? "off";
|
|
1221
|
-
}
|
|
1222
|
-
function hasUseClientDirective(content) {
|
|
1223
|
-
if (!content) {
|
|
1224
|
-
return false;
|
|
1225
|
-
}
|
|
1226
|
-
const normalized = content.trimStart();
|
|
1227
|
-
if (normalized.startsWith("'use client'") || normalized.startsWith('"use client"')) {
|
|
1228
|
-
return true;
|
|
1229
|
-
}
|
|
1230
|
-
if (!normalized.includes("use client")) {
|
|
1231
|
-
return false;
|
|
1232
|
-
}
|
|
1233
|
-
for (const token of tokenizeModuleSource(content)) {
|
|
1234
|
-
if (token.kind === "string") {
|
|
1235
|
-
if (token.value === "use client") {
|
|
1236
|
-
return true;
|
|
1237
|
-
}
|
|
1238
|
-
continue;
|
|
1239
|
-
}
|
|
1240
|
-
if (token.kind === "punctuation" && token.value === ";") {
|
|
1241
|
-
continue;
|
|
1242
|
-
}
|
|
1243
|
-
return false;
|
|
1244
|
-
}
|
|
1245
|
-
return false;
|
|
1246
|
-
}
|
|
1247
|
-
function hasHydrateExport(content) {
|
|
1248
|
-
if (!content) {
|
|
1249
|
-
return false;
|
|
1250
|
-
}
|
|
1251
|
-
if (/\bexport\s+const\s+hydrate\s*=\s*true\b/.test(content)) {
|
|
1252
|
-
return true;
|
|
1253
|
-
}
|
|
1254
|
-
for (const match of content.matchAll(/\bexport\s*\{([^}]*)\}/g)) {
|
|
1255
|
-
for (const specifier of match[1].split(",")) {
|
|
1256
|
-
const parts = specifier.trim().split(/\s+as\s+/);
|
|
1257
|
-
const exportedName2 = (parts[1] ?? parts[0])?.trim();
|
|
1258
|
-
if (exportedName2 === "hydrate") {
|
|
1259
|
-
return true;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
return false;
|
|
1264
|
-
}
|
|
1265
|
-
var REGEXP_PREFIX_PUNCTUATION = /* @__PURE__ */ new Set([
|
|
1266
|
-
"(",
|
|
1267
|
-
"[",
|
|
1268
|
-
"{",
|
|
1269
|
-
",",
|
|
1270
|
-
";",
|
|
1271
|
-
":",
|
|
1272
|
-
"=",
|
|
1273
|
-
"!",
|
|
1274
|
-
"?",
|
|
1275
|
-
"&",
|
|
1276
|
-
"|",
|
|
1277
|
-
"+",
|
|
1278
|
-
"-",
|
|
1279
|
-
"*",
|
|
1280
|
-
"%",
|
|
1281
|
-
"^",
|
|
1282
|
-
"~",
|
|
1283
|
-
">"
|
|
1284
|
-
]);
|
|
1285
|
-
var REGEXP_PREFIX_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1286
|
-
"await",
|
|
1287
|
-
"case",
|
|
1288
|
-
"delete",
|
|
1289
|
-
"do",
|
|
1290
|
-
"else",
|
|
1291
|
-
"in",
|
|
1292
|
-
"instanceof",
|
|
1293
|
-
"new",
|
|
1294
|
-
"of",
|
|
1295
|
-
"return",
|
|
1296
|
-
"throw",
|
|
1297
|
-
"typeof",
|
|
1298
|
-
"void",
|
|
1299
|
-
"yield"
|
|
1300
|
-
]);
|
|
1301
|
-
function canStartRegularExpression(previous) {
|
|
1302
|
-
if (!previous) return true;
|
|
1303
|
-
return previous.kind === "identifier" ? REGEXP_PREFIX_KEYWORDS.has(previous.value) : REGEXP_PREFIX_PUNCTUATION.has(previous.value);
|
|
1304
|
-
}
|
|
1305
|
-
function skipRegularExpression(content, startIndex) {
|
|
1306
|
-
let index = startIndex + 1;
|
|
1307
|
-
let inCharacterClass = false;
|
|
1308
|
-
while (index < content.length) {
|
|
1309
|
-
const character = content[index];
|
|
1310
|
-
if (character === "\n" || character === "\r") return null;
|
|
1311
|
-
if (character === "\\") {
|
|
1312
|
-
index += 2;
|
|
1313
|
-
continue;
|
|
1314
|
-
}
|
|
1315
|
-
if (character === "[") {
|
|
1316
|
-
inCharacterClass = true;
|
|
1317
|
-
index++;
|
|
1318
|
-
continue;
|
|
1319
|
-
}
|
|
1320
|
-
if (character === "]" && inCharacterClass) {
|
|
1321
|
-
inCharacterClass = false;
|
|
1322
|
-
index++;
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
if (character === "/" && !inCharacterClass) {
|
|
1326
|
-
index++;
|
|
1327
|
-
while (index < content.length && /[A-Za-z]/.test(content[index])) index++;
|
|
1328
|
-
return index;
|
|
1329
|
-
}
|
|
1330
|
-
index++;
|
|
1331
|
-
}
|
|
1332
|
-
return null;
|
|
1333
|
-
}
|
|
1334
|
-
function tokenizeModuleSource(content) {
|
|
1335
|
-
const tokens = [];
|
|
1336
|
-
let index = 0;
|
|
1337
|
-
let line = 1;
|
|
1338
|
-
while (index < content.length) {
|
|
1339
|
-
const character = content[index];
|
|
1340
|
-
if (/\s/.test(character)) {
|
|
1341
|
-
if (character === "\n") line++;
|
|
1342
|
-
index++;
|
|
1343
|
-
continue;
|
|
1344
|
-
}
|
|
1345
|
-
if (character === "/" && content[index + 1] === "/") {
|
|
1346
|
-
index += 2;
|
|
1347
|
-
while (index < content.length && content[index] !== "\n") index++;
|
|
1348
|
-
continue;
|
|
1349
|
-
}
|
|
1350
|
-
if (character === "/" && content[index + 1] === "*") {
|
|
1351
|
-
index += 2;
|
|
1352
|
-
while (index < content.length) {
|
|
1353
|
-
if (content[index] === "\n") line++;
|
|
1354
|
-
if (content[index] === "*" && content[index + 1] === "/") {
|
|
1355
|
-
index += 2;
|
|
1356
|
-
break;
|
|
1357
|
-
}
|
|
1358
|
-
index++;
|
|
1359
|
-
}
|
|
1360
|
-
continue;
|
|
1361
|
-
}
|
|
1362
|
-
if (character === "/" && canStartRegularExpression(tokens[tokens.length - 1])) {
|
|
1363
|
-
const endIndex = skipRegularExpression(content, index);
|
|
1364
|
-
if (endIndex !== null) {
|
|
1365
|
-
index = endIndex;
|
|
1366
|
-
continue;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
if (character === '"' || character === "'") {
|
|
1370
|
-
const quote = character;
|
|
1371
|
-
const tokenLine = line;
|
|
1372
|
-
let value = "";
|
|
1373
|
-
index++;
|
|
1374
|
-
while (index < content.length) {
|
|
1375
|
-
const next = content[index];
|
|
1376
|
-
if (next === "\\") {
|
|
1377
|
-
value += next;
|
|
1378
|
-
if (index + 1 < content.length) value += content[index + 1];
|
|
1379
|
-
index += 2;
|
|
1380
|
-
continue;
|
|
1381
|
-
}
|
|
1382
|
-
if (next === quote) {
|
|
1383
|
-
index++;
|
|
1384
|
-
break;
|
|
1385
|
-
}
|
|
1386
|
-
if (next === "\n") line++;
|
|
1387
|
-
value += next;
|
|
1388
|
-
index++;
|
|
1389
|
-
}
|
|
1390
|
-
tokens.push({ kind: "string", value, line: tokenLine });
|
|
1391
|
-
continue;
|
|
1392
|
-
}
|
|
1393
|
-
if (character === "`") {
|
|
1394
|
-
index++;
|
|
1395
|
-
while (index < content.length) {
|
|
1396
|
-
const next = content[index];
|
|
1397
|
-
if (next === "\\") {
|
|
1398
|
-
index += 2;
|
|
1399
|
-
continue;
|
|
1400
|
-
}
|
|
1401
|
-
if (next === "`") {
|
|
1402
|
-
index++;
|
|
1403
|
-
break;
|
|
1404
|
-
}
|
|
1405
|
-
if (next === "\n") line++;
|
|
1406
|
-
index++;
|
|
1407
|
-
}
|
|
1408
|
-
continue;
|
|
1409
|
-
}
|
|
1410
|
-
if (/[A-Za-z_$]/.test(character)) {
|
|
1411
|
-
const start = index++;
|
|
1412
|
-
while (index < content.length && /[\w$]/.test(content[index])) index++;
|
|
1413
|
-
tokens.push({ kind: "identifier", value: content.slice(start, index), line });
|
|
1414
|
-
continue;
|
|
1415
|
-
}
|
|
1416
|
-
tokens.push({ kind: "punctuation", value: character, line });
|
|
1417
|
-
index++;
|
|
1418
|
-
}
|
|
1419
|
-
return tokens;
|
|
1420
|
-
}
|
|
1421
|
-
function isIslandExportStart(tokens, index) {
|
|
1422
|
-
const token = tokens[index];
|
|
1423
|
-
const previous = tokens[index - 1];
|
|
1424
|
-
const startsStatement = !previous || previous.value === ";" || previous.value === "{" || previous.value === "}" || token.line > previous.line;
|
|
1425
|
-
return startsStatement && token.value === "export" && tokens[index + 1]?.value === "const" && tokens[index + 2]?.value === "island";
|
|
1426
|
-
}
|
|
1427
|
-
function getIslandStrategyExport(content) {
|
|
1428
|
-
if (!content) return null;
|
|
1429
|
-
const tokens = tokenizeModuleSource(content);
|
|
1430
|
-
for (let index = 0; index < tokens.length - 2; index++) {
|
|
1431
|
-
if (!isIslandExportStart(tokens, index)) continue;
|
|
1432
|
-
let valueIndex = index + 3;
|
|
1433
|
-
if (tokens[valueIndex]?.value === ":") {
|
|
1434
|
-
while (valueIndex < tokens.length && tokens[valueIndex].value !== "=") valueIndex++;
|
|
1435
|
-
}
|
|
1436
|
-
if (tokens[valueIndex]?.value !== "=") break;
|
|
1437
|
-
valueIndex++;
|
|
1438
|
-
const literal = tokens[valueIndex];
|
|
1439
|
-
if (!literal || literal.kind !== "string" || !isFarmIslandStrategy(literal.value)) break;
|
|
1440
|
-
let trailingIndex = valueIndex + 1;
|
|
1441
|
-
if (tokens[trailingIndex]?.value === "as" && tokens[trailingIndex + 1]?.value === "const") {
|
|
1442
|
-
trailingIndex += 2;
|
|
1443
|
-
}
|
|
1444
|
-
const trailing = tokens[trailingIndex];
|
|
1445
|
-
if (trailing && trailing.value !== ";" && trailing.line === literal.line) break;
|
|
1446
|
-
return literal.value;
|
|
1447
|
-
}
|
|
1448
|
-
if (tokens.some((_token, index) => isIslandExportStart(tokens, index))) {
|
|
1449
|
-
throw new Error(
|
|
1450
|
-
'Farm island configuration must be a static "load", "interaction", "visible", or "idle" string literal.'
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
return null;
|
|
1454
|
-
}
|
|
1455
|
-
function stripUseClientDirective(content) {
|
|
1456
|
-
return content.replace(
|
|
1457
|
-
/^((?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/|(?:"[^"\n]*"|'[^'\n]*')\s*;?)*)(["'])use client\2\s*;?\s*/,
|
|
1458
|
-
(match, prefix) => prefix + match.slice(prefix.length).replace(/[^\r\n]/g, " ")
|
|
1459
|
-
);
|
|
1460
|
-
}
|
|
1461
|
-
function hasAsyncDefaultExport(content) {
|
|
1462
|
-
if (!content) return false;
|
|
1463
|
-
const tokens = tokenizeModuleSource(content);
|
|
1464
|
-
for (let index = 0; index < tokens.length - 2; index++) {
|
|
1465
|
-
const token = tokens[index];
|
|
1466
|
-
if (token.kind !== "identifier" || token.value !== "export") continue;
|
|
1467
|
-
if (tokens[index - 1]?.value === ".") continue;
|
|
1468
|
-
if (tokens[index + 1]?.value !== "default") continue;
|
|
1469
|
-
const exported = tokens[index + 2];
|
|
1470
|
-
if (exported.kind === "identifier" && exported.value === "async") {
|
|
1471
|
-
return true;
|
|
1472
|
-
}
|
|
1473
|
-
if (exported.kind === "identifier" && !["function", "class"].includes(exported.value) && tokens[index + 3]?.value !== "(" && isAsyncLocalDeclaration(tokens, exported.value)) {
|
|
1474
|
-
return true;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
return false;
|
|
1478
|
-
}
|
|
1479
|
-
function isAsyncLocalDeclaration(tokens, name) {
|
|
1480
|
-
for (let index = 0; index < tokens.length - 2; index++) {
|
|
1481
|
-
if (tokens[index].value === "async" && tokens[index + 1]?.value === "function" && tokens[index + 2]?.value === name) {
|
|
1482
|
-
return true;
|
|
1483
|
-
}
|
|
1484
|
-
if (tokens[index].value === name && tokens[index + 1]?.value === "=" && tokens[index + 2]?.value === "async") {
|
|
1485
|
-
return true;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
return false;
|
|
1489
|
-
}
|
|
1490
|
-
function parseClientModuleMetadata(content, inspectIslandExport) {
|
|
1491
|
-
if (!content) {
|
|
1492
|
-
return {
|
|
1493
|
-
isClientComponent: false,
|
|
1494
|
-
hasHydrateExport: false,
|
|
1495
|
-
islandStrategy: null
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
const isClientComponent = hasUseClientDirective(content);
|
|
1499
|
-
const hasHydrate = hasHydrateExport(content);
|
|
1500
|
-
return {
|
|
1501
|
-
isClientComponent,
|
|
1502
|
-
hasHydrateExport: hasHydrate,
|
|
1503
|
-
islandStrategy: inspectIslandExport || isClientComponent || hasHydrate ? getIslandStrategyExport(content) : null
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
var DEFAULT_REEXPORT = /export\s*\{\s*default(?:\s+as\s+default)?\s*\}\s*from\s*(["'])([^"']+)\1/;
|
|
1507
|
-
function resolveDefaultReexport(ownerPath, content, root) {
|
|
1508
|
-
const match = content ? DEFAULT_REEXPORT.exec(content) : null;
|
|
1509
|
-
if (!match) return null;
|
|
1510
|
-
const imported = resolveImportedModule(ownerPath, match[2], root);
|
|
1511
|
-
return imported.local ? imported.path : null;
|
|
1512
|
-
}
|
|
1513
|
-
function resolveOwnerSourcePath(resolvedPath, root) {
|
|
1514
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1515
|
-
let current = resolvedPath;
|
|
1516
|
-
while (current && !seen.has(current)) {
|
|
1517
|
-
seen.add(current);
|
|
1518
|
-
const target = resolveDefaultReexport(current, readIfExists(current), root);
|
|
1519
|
-
if (!target) return current;
|
|
1520
|
-
current = target;
|
|
1521
|
-
}
|
|
1522
|
-
return current;
|
|
1523
|
-
}
|
|
1524
|
-
function collectFarmRenderedClientModules(modulePath, root) {
|
|
1525
|
-
const resolvedPath = resolveOwnerSourcePath(resolveModuleSourcePath(modulePath, root), root);
|
|
1526
|
-
if (!resolvedPath) return null;
|
|
1527
|
-
if (hasUseClientDirective(readIfExists(resolvedPath))) return [resolvedPath];
|
|
1528
|
-
const collected = collectIsolatedClientBoundaries(resolvedPath, root, {
|
|
1529
|
-
allowDynamicCardinality: true,
|
|
1530
|
-
allowElementProps: true
|
|
1531
|
-
});
|
|
1532
|
-
if (collected.fallbackReason || collected.costGuardExceeded) return null;
|
|
1533
|
-
return collected.boundaries.map((boundary) => boundary.modulePath);
|
|
1534
|
-
}
|
|
1535
|
-
var SERVER_MODULE_SOURCE = /\.[cm]?[jt]sx?$/;
|
|
1536
|
-
var STYLESHEET_SOURCE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)$/;
|
|
1537
|
-
function collectFarmServerStylesheets(modulePaths, root) {
|
|
1538
|
-
const stylesheets = /* @__PURE__ */ new Set();
|
|
1539
|
-
const visited = /* @__PURE__ */ new Set();
|
|
1540
|
-
const visit = (file) => {
|
|
1541
|
-
if (visited.has(file) || !SERVER_MODULE_SOURCE.test(file)) return;
|
|
1542
|
-
visited.add(file);
|
|
1543
|
-
const content = readIfExists(file);
|
|
1544
|
-
if (!content || hasUseClientDirective(content)) return;
|
|
1545
|
-
for (const specifier of getImportSpecifiers(content)) {
|
|
1546
|
-
if (specifier.includes("?")) continue;
|
|
1547
|
-
const imported = resolveImportedModule(file, specifier, root);
|
|
1548
|
-
if (!imported.path) continue;
|
|
1549
|
-
if (STYLESHEET_SOURCE.test(imported.path)) stylesheets.add(imported.path);
|
|
1550
|
-
else if (imported.local) visit(imported.path);
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
for (const modulePath of modulePaths) {
|
|
1554
|
-
const resolved = resolveOwnerSourcePath(resolveModuleSourcePath(modulePath, root), root);
|
|
1555
|
-
if (resolved) visit(resolved);
|
|
1556
|
-
}
|
|
1557
|
-
return [...stylesheets];
|
|
1558
|
-
}
|
|
1559
|
-
function getClientModuleMetadata(modulePath, root) {
|
|
1560
|
-
const resolvedPath = resolveModuleSourcePath(modulePath, root);
|
|
1561
|
-
return inspectClientModuleMetadata(resolvedPath, root, /* @__PURE__ */ new Set(), true);
|
|
1562
|
-
}
|
|
1563
|
-
function getClientModuleHydrationPlan(modulePath, root, mode = "off", options = {}) {
|
|
1564
|
-
const plan = planClientModuleHydration(modulePath, root, mode, options);
|
|
1565
|
-
if (options.serverTreeLayouts !== true || options.asyncOwnerIslands !== true || !plan.shouldHydrate || plan.isClientComponent || plan.asyncOwnerIslands) {
|
|
1566
|
-
return plan;
|
|
1567
|
-
}
|
|
1568
|
-
const resolvedPath = resolveOwnerSourcePath(resolveModuleSourcePath(modulePath, root), root);
|
|
1569
|
-
const owner = parseClientModuleMetadata(readIfExists(resolvedPath ?? ""), true);
|
|
1570
|
-
if (!resolvedPath || owner.isClientComponent || owner.hasHydrateExport) return plan;
|
|
1571
|
-
const layout = collectIsolatedClientBoundaries(resolvedPath, root, {
|
|
1572
|
-
allowDynamicCardinality: true,
|
|
1573
|
-
allowElementProps: true,
|
|
1574
|
-
packageReferences: true
|
|
1575
|
-
});
|
|
1576
|
-
const routeWide = {
|
|
1577
|
-
...plan,
|
|
1578
|
-
shouldHydrate: plan.legacyShouldHydrate,
|
|
1579
|
-
islandStrategy: plan.legacyIslandStrategy,
|
|
1580
|
-
hasIsolatedClientBoundaries: false,
|
|
1581
|
-
isolatedBoundaries: []
|
|
1582
|
-
};
|
|
1583
|
-
if (layout.fallbackReason) {
|
|
1584
|
-
return {
|
|
1585
|
-
...routeWide,
|
|
1586
|
-
shouldHydrate: false,
|
|
1587
|
-
islandStrategy: null,
|
|
1588
|
-
fallbackReason: layout.fallbackReason,
|
|
1589
|
-
islandsError: layout.fallbackHint ? `${layout.fallbackReason}. ${layout.fallbackHint}` : layout.fallbackReason
|
|
1590
|
-
};
|
|
1591
|
-
}
|
|
1592
|
-
const staticPackages = layout.staticPackages.length > 0 ? { staticPackageBoundaries: layout.staticPackages } : {};
|
|
1593
|
-
if (layout.boundaries.length === 0) {
|
|
1594
|
-
return { ...routeWide, shouldHydrate: false, islandStrategy: null, ...staticPackages };
|
|
1595
|
-
}
|
|
1596
|
-
return {
|
|
1597
|
-
...routeWide,
|
|
1598
|
-
serverTreeLayout: true,
|
|
1599
|
-
isolatedBoundaries: layout.boundaries,
|
|
1600
|
-
...staticPackages
|
|
1601
|
-
};
|
|
1602
|
-
}
|
|
1603
|
-
function planClientModuleHydration(modulePath, root, mode, options) {
|
|
1604
|
-
const metadata = getClientModuleMetadata(modulePath, root);
|
|
1605
|
-
const emptyPlan = (fallbackReason, costGuardExceeded = false, estimatedIsolatedRootCount = 0) => ({
|
|
1606
|
-
...metadata,
|
|
1607
|
-
mode,
|
|
1608
|
-
legacyShouldHydrate: metadata.shouldHydrate,
|
|
1609
|
-
legacyIslandStrategy: metadata.islandStrategy,
|
|
1610
|
-
estimatedIsolatedRootCount,
|
|
1611
|
-
isolatedHydrationEligible: false,
|
|
1612
|
-
hasIsolatedClientBoundaries: false,
|
|
1613
|
-
isolatedBoundaries: [],
|
|
1614
|
-
...costGuardExceeded ? { costGuardExceeded: true } : {},
|
|
1615
|
-
...fallbackReason ? { fallbackReason } : {}
|
|
1616
|
-
});
|
|
1617
|
-
const asyncOwner = (metadata.suppressedAsyncHydration === true || options.serverOwners === true) && options.asyncOwnerIslands === true;
|
|
1618
|
-
if (mode === "off" && !asyncOwner) return emptyPlan();
|
|
1619
|
-
const resolvedPath = resolveOwnerSourcePath(resolveModuleSourcePath(modulePath, root), root);
|
|
1620
|
-
const content = readIfExists(resolvedPath ?? "");
|
|
1621
|
-
const parsed = parseClientModuleMetadata(content, true);
|
|
1622
|
-
if (!resolvedPath) return emptyPlan("the owner source could not be resolved");
|
|
1623
|
-
if (parsed.isClientComponent) {
|
|
1624
|
-
return emptyPlan("the owner is already a client component");
|
|
1625
|
-
}
|
|
1626
|
-
if (parsed.hasHydrateExport) {
|
|
1627
|
-
return emptyPlan("the owner explicitly exports `hydrate = true`");
|
|
1628
|
-
}
|
|
1629
|
-
const inspection = collectIsolatedClientBoundaries(resolvedPath, root, {
|
|
1630
|
-
allowDynamicCardinality: asyncOwner,
|
|
1631
|
-
allowElementProps: asyncOwner,
|
|
1632
|
-
staticPackageBoundaries: asyncOwner,
|
|
1633
|
-
staticPackageLeaves: options.serverTreeLayouts === true && options.asyncOwnerIslands === true,
|
|
1634
|
-
// Islands mode: pages carry `serverOwners`, layouts `serverTreeLayouts`.
|
|
1635
|
-
packageReferences: options.serverOwners === true || options.serverTreeLayouts === true
|
|
1636
|
-
});
|
|
1637
|
-
if (inspection.fallbackReason && asyncOwner && options.serverOwners === true) {
|
|
1638
|
-
return {
|
|
1639
|
-
...emptyPlan(inspection.fallbackReason),
|
|
1640
|
-
shouldHydrate: false,
|
|
1641
|
-
islandStrategy: null,
|
|
1642
|
-
islandsError: inspection.fallbackHint ? `${inspection.fallbackReason}. ${inspection.fallbackHint}` : inspection.fallbackReason
|
|
1643
|
-
};
|
|
1644
|
-
}
|
|
1645
|
-
if (inspection.boundaries.length === 0) {
|
|
1646
|
-
return emptyPlan(inspection.fallbackReason);
|
|
1647
|
-
}
|
|
1648
|
-
if (inspection.fallbackReason) {
|
|
1649
|
-
return emptyPlan(
|
|
1650
|
-
inspection.fallbackReason,
|
|
1651
|
-
inspection.costGuardExceeded,
|
|
1652
|
-
inspection.estimatedBoundaryCount
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1655
|
-
const boundaryLimit = isolatedHydrationBoundaryLimit();
|
|
1656
|
-
if (!asyncOwner && inspection.estimatedBoundaryCount > boundaryLimit) {
|
|
1657
|
-
return emptyPlan(
|
|
1658
|
-
`the client graph can create ${inspection.estimatedBoundaryCount} isolated roots, above the measured limit of ${boundaryLimit}`,
|
|
1659
|
-
true,
|
|
1660
|
-
inspection.estimatedBoundaryCount
|
|
1661
|
-
);
|
|
1662
|
-
}
|
|
1663
|
-
const enabled = mode === "enabled" || asyncOwner;
|
|
1664
|
-
const plan = {
|
|
1665
|
-
...metadata,
|
|
1666
|
-
shouldHydrate: enabled ? false : metadata.shouldHydrate,
|
|
1667
|
-
islandStrategy: enabled ? null : metadata.islandStrategy,
|
|
1668
|
-
mode,
|
|
1669
|
-
legacyShouldHydrate: metadata.shouldHydrate,
|
|
1670
|
-
legacyIslandStrategy: metadata.islandStrategy,
|
|
1671
|
-
estimatedIsolatedRootCount: inspection.estimatedBoundaryCount,
|
|
1672
|
-
isolatedHydrationEligible: true,
|
|
1673
|
-
hasIsolatedClientBoundaries: enabled,
|
|
1674
|
-
isolatedBoundaries: inspection.boundaries
|
|
1675
|
-
};
|
|
1676
|
-
if (asyncOwner) {
|
|
1677
|
-
delete plan.suppressedAsyncHydration;
|
|
1678
|
-
plan.asyncOwnerIslands = true;
|
|
1679
|
-
}
|
|
1680
|
-
if (inspection.staticPackages.length > 0)
|
|
1681
|
-
plan.staticPackageBoundaries = inspection.staticPackages;
|
|
1682
|
-
return plan;
|
|
1683
|
-
}
|
|
1684
|
-
function usesFarmServerTree(plan) {
|
|
1685
|
-
return plan?.asyncOwnerIslands === true && plan.isolatedBoundaries.length > 0 && plan.isolatedBoundaries.every((boundary) => boundary.islandStrategy === "load");
|
|
1686
|
-
}
|
|
1687
|
-
function getMarkdownPageHydrationPlan(componentsModulePath, root, mode = "off", options = {}) {
|
|
1688
|
-
const plan = {
|
|
1689
|
-
isClientComponent: false,
|
|
1690
|
-
shouldHydrate: false,
|
|
1691
|
-
islandStrategy: null,
|
|
1692
|
-
mode,
|
|
1693
|
-
legacyShouldHydrate: false,
|
|
1694
|
-
legacyIslandStrategy: null,
|
|
1695
|
-
estimatedIsolatedRootCount: 0,
|
|
1696
|
-
isolatedHydrationEligible: false,
|
|
1697
|
-
hasIsolatedClientBoundaries: false,
|
|
1698
|
-
isolatedBoundaries: []
|
|
1699
|
-
};
|
|
1700
|
-
if (!componentsModulePath || options.asyncOwnerIslands !== true) return plan;
|
|
1701
|
-
const resolvedPath = resolveModuleSourcePath(componentsModulePath, root);
|
|
1702
|
-
if (!resolvedPath) {
|
|
1703
|
-
return { ...plan, fallbackReason: "the MDX components module could not be resolved" };
|
|
1704
|
-
}
|
|
1705
|
-
const inspection = collectIsolatedClientBoundaries(resolvedPath, root, {
|
|
1706
|
-
allowDynamicCardinality: true,
|
|
1707
|
-
staticPackageBoundaries: true,
|
|
1708
|
-
packageReferences: options.packageReferences === true
|
|
1709
|
-
});
|
|
1710
|
-
if (inspection.fallbackReason) return { ...plan, fallbackReason: inspection.fallbackReason };
|
|
1711
|
-
if (inspection.staticPackages.length > 0)
|
|
1712
|
-
plan.staticPackageBoundaries = inspection.staticPackages;
|
|
1713
|
-
if (inspection.boundaries.length === 0) return plan;
|
|
1714
|
-
return {
|
|
1715
|
-
...plan,
|
|
1716
|
-
estimatedIsolatedRootCount: inspection.estimatedBoundaryCount,
|
|
1717
|
-
isolatedHydrationEligible: true,
|
|
1718
|
-
hasIsolatedClientBoundaries: true,
|
|
1719
|
-
isolatedBoundaries: inspection.boundaries,
|
|
1720
|
-
asyncOwnerIslands: true
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1723
|
-
function createMarkdownPageHydrationPlanner(componentsModulePath, root, mode = "off", options = {}) {
|
|
1724
|
-
let plan;
|
|
1725
|
-
return () => ({
|
|
1726
|
-
...plan ?? (plan = getMarkdownPageHydrationPlan(componentsModulePath, root, mode, options))
|
|
1727
|
-
});
|
|
1728
|
-
}
|
|
1729
|
-
function restoreRouteWideHydration(metadata, fallbackReason) {
|
|
1730
|
-
metadata.shouldHydrate = metadata.legacyShouldHydrate;
|
|
1731
|
-
metadata.islandStrategy = metadata.legacyIslandStrategy;
|
|
1732
|
-
metadata.hasIsolatedClientBoundaries = false;
|
|
1733
|
-
metadata.isolatedBoundaries = [];
|
|
1734
|
-
if (metadata.asyncOwnerIslands) {
|
|
1735
|
-
delete metadata.asyncOwnerIslands;
|
|
1736
|
-
metadata.suppressedAsyncHydration = true;
|
|
1737
|
-
metadata.fallbackReason = fallbackReason ?? "a parent layout hydrates the whole route";
|
|
1738
|
-
return;
|
|
1739
|
-
}
|
|
1740
|
-
if (fallbackReason) {
|
|
1741
|
-
metadata.costGuardExceeded = true;
|
|
1742
|
-
metadata.fallbackReason = fallbackReason;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
function enforceFarmIsolatedHydrationRouteBudget(layouts, routes, layoutAppliesToRoute, options = {}) {
|
|
1746
|
-
const boundaryLimit = isolatedHydrationBoundaryLimit();
|
|
1747
|
-
const sortedLayouts = [...layouts].sort((left, right) => left.depth - right.depth);
|
|
1748
|
-
for (const route of options.serverOwners ? [] : routes) {
|
|
1749
|
-
if (route.metadata.mode !== "enabled") continue;
|
|
1750
|
-
const applicableLayouts = sortedLayouts.filter(
|
|
1751
|
-
(layout) => layoutAppliesToRoute(layout.pattern, route.pattern)
|
|
1752
|
-
);
|
|
1753
|
-
const layoutRootCount = applicableLayouts.reduce(
|
|
1754
|
-
(count, layout) => count + (layout.metadata.hasIsolatedClientBoundaries ? layout.metadata.estimatedIsolatedRootCount : 0),
|
|
1755
|
-
0
|
|
1756
|
-
);
|
|
1757
|
-
const routeRootCount = route.metadata.hasIsolatedClientBoundaries ? route.metadata.estimatedIsolatedRootCount : 0;
|
|
1758
|
-
const totalRootCount = layoutRootCount + routeRootCount;
|
|
1759
|
-
if (totalRootCount <= boundaryLimit) continue;
|
|
1760
|
-
const fallbackReason = `the matched route ${route.pattern} can create ${totalRootCount} isolated roots, above the measured limit of ${boundaryLimit}`;
|
|
1761
|
-
const remainingRootCount = () => applicableLayouts.reduce(
|
|
1762
|
-
(count, layout) => count + (layout.metadata.hasIsolatedClientBoundaries ? layout.metadata.estimatedIsolatedRootCount : 0),
|
|
1763
|
-
0
|
|
1764
|
-
) + (route.metadata.hasIsolatedClientBoundaries ? route.metadata.estimatedIsolatedRootCount : 0);
|
|
1765
|
-
while (remainingRootCount() > boundaryLimit) {
|
|
1766
|
-
let accumulatedLayoutRoots = 0;
|
|
1767
|
-
const overflowingLayout = applicableLayouts.find((layout) => {
|
|
1768
|
-
if (layout.metadata.hasIsolatedClientBoundaries) {
|
|
1769
|
-
accumulatedLayoutRoots += layout.metadata.estimatedIsolatedRootCount;
|
|
1770
|
-
}
|
|
1771
|
-
return accumulatedLayoutRoots > boundaryLimit;
|
|
1772
|
-
});
|
|
1773
|
-
if (overflowingLayout) {
|
|
1774
|
-
restoreRouteWideHydration(overflowingLayout.metadata, fallbackReason);
|
|
1775
|
-
continue;
|
|
1776
|
-
}
|
|
1777
|
-
if (route.metadata.hasIsolatedClientBoundaries) {
|
|
1778
|
-
restoreRouteWideHydration(route.metadata, fallbackReason);
|
|
1779
|
-
continue;
|
|
1780
|
-
}
|
|
1781
|
-
break;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
for (const layout of sortedLayouts) {
|
|
1785
|
-
const hasRouteWideAncestor = sortedLayouts.some(
|
|
1786
|
-
(ancestor) => ancestor !== layout && ancestor.depth < layout.depth && ancestor.metadata.shouldHydrate && layoutAppliesToRoute(ancestor.pattern, layout.pattern)
|
|
1787
|
-
);
|
|
1788
|
-
if (hasRouteWideAncestor && layout.metadata.hasIsolatedClientBoundaries) {
|
|
1789
|
-
restoreRouteWideHydration(layout.metadata);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
function isIsolatableClientBoundarySource(content) {
|
|
1794
|
-
if (!content || !hasUseClientDirective(content)) return false;
|
|
1795
|
-
if (/\bexport\s*\*/.test(content)) return false;
|
|
1796
|
-
return /\bexport\s+default\s+(?!(?:type|interface)\b)/.test(content) || /\bexport\s+(?:async\s+)?function\s+[A-Z][$\w]*/.test(content) || /\bexport\s+(?:const|let|var|class)\s+[A-Z][$\w]*/.test(content) || exportListNames(content).some((name) => name === "default" || /^[A-Z]/.test(name));
|
|
1797
|
-
}
|
|
1798
|
-
function exportListNames(content) {
|
|
1799
|
-
const names = [];
|
|
1800
|
-
for (const match of content.matchAll(/\bexport\s*(type\s*)?\{([^}]*)\}/g)) {
|
|
1801
|
-
if (match[1]) continue;
|
|
1802
|
-
for (const entry of match[2].split(",")) {
|
|
1803
|
-
const parts = entry.trim().split(/\s+/);
|
|
1804
|
-
if (parts[0] === "type" || !parts[0]) continue;
|
|
1805
|
-
names.push(parts[parts.length - 1].replace(/^["']|["']$/g, ""));
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
return names;
|
|
1809
|
-
}
|
|
1810
|
-
function getStaticImportBindings(content) {
|
|
1811
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
1812
|
-
if (!content) return bindings;
|
|
1813
|
-
const tokens = tokenizeModuleSource(content);
|
|
1814
|
-
for (let index = 0; index < tokens.length; index++) {
|
|
1815
|
-
if (tokens[index].value !== "import" || tokens[index - 1]?.value === ".") continue;
|
|
1816
|
-
const first = tokens[index + 1];
|
|
1817
|
-
if (!first || first.value === "type" || first.value === "(" || first.kind === "string") {
|
|
1818
|
-
continue;
|
|
1819
|
-
}
|
|
1820
|
-
let fromIndex = -1;
|
|
1821
|
-
for (let cursor = index + 1; cursor < tokens.length; cursor++) {
|
|
1822
|
-
if (tokens[cursor].value === ";") break;
|
|
1823
|
-
if (tokens[cursor].value === "from" && tokens[cursor + 1]?.kind === "string") {
|
|
1824
|
-
fromIndex = cursor;
|
|
1825
|
-
break;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
if (fromIndex === -1) continue;
|
|
1829
|
-
const specifier = tokens[fromIndex + 1].value;
|
|
1830
|
-
const clause = tokens.slice(index + 1, fromIndex);
|
|
1831
|
-
const localNames = [];
|
|
1832
|
-
if (clause[0]?.kind === "identifier" && clause[0].value !== "type") {
|
|
1833
|
-
localNames.push(clause[0].value);
|
|
1834
|
-
}
|
|
1835
|
-
const namespaceAs = clause.findIndex(
|
|
1836
|
-
(token, clauseIndex) => token.value === "*" && clause[clauseIndex + 1]?.value === "as"
|
|
1837
|
-
);
|
|
1838
|
-
if (namespaceAs !== -1 && clause[namespaceAs + 2]?.kind === "identifier") {
|
|
1839
|
-
localNames.push(clause[namespaceAs + 2].value);
|
|
1840
|
-
}
|
|
1841
|
-
const openingBrace = clause.findIndex((token) => token.value === "{");
|
|
1842
|
-
const closingBrace = clause.findIndex(
|
|
1843
|
-
(token, clauseIndex) => clauseIndex > openingBrace && token.value === "}"
|
|
1844
|
-
);
|
|
1845
|
-
if (openingBrace !== -1 && closingBrace !== -1) {
|
|
1846
|
-
let entryStart = openingBrace + 1;
|
|
1847
|
-
for (let cursor = entryStart; cursor <= closingBrace; cursor++) {
|
|
1848
|
-
if (cursor !== closingBrace && clause[cursor]?.value !== ",") continue;
|
|
1849
|
-
const entry = clause.slice(entryStart, cursor).filter((token) => token.value !== "type");
|
|
1850
|
-
const asIndex = entry.findIndex((token) => token.value === "as");
|
|
1851
|
-
const local = asIndex === -1 ? entry[0] : entry[asIndex + 1];
|
|
1852
|
-
if (local?.kind === "identifier") localNames.push(local.value);
|
|
1853
|
-
entryStart = cursor + 1;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
bindings.set(
|
|
1857
|
-
specifier,
|
|
1858
|
-
Array.from(/* @__PURE__ */ new Set([...bindings.get(specifier) ?? [], ...localNames]))
|
|
1859
|
-
);
|
|
1860
|
-
}
|
|
1861
|
-
return bindings;
|
|
1862
|
-
}
|
|
1863
|
-
var PARSER_SENSITIVE_JSX_CONTAINERS = /* @__PURE__ */ new Set([
|
|
1864
|
-
"table",
|
|
1865
|
-
"thead",
|
|
1866
|
-
"tbody",
|
|
1867
|
-
"tfoot",
|
|
1868
|
-
"tr",
|
|
1869
|
-
"select",
|
|
1870
|
-
"optgroup",
|
|
1871
|
-
"svg"
|
|
1872
|
-
]);
|
|
1873
|
-
var PARSER_FLOW_CONTENT_ELEMENTS = /* @__PURE__ */ new Set(["td", "th", "caption", "foreignObject"]);
|
|
1874
|
-
var PARSER_SENSITIVE_FLOW_HINTS = {
|
|
1875
|
-
table: ", or render it inside a <td>, <th> or <caption>",
|
|
1876
|
-
thead: ", or render it inside a <td> or <th>",
|
|
1877
|
-
tbody: ", or render it inside a <td> or <th>",
|
|
1878
|
-
tfoot: ", or render it inside a <td> or <th>",
|
|
1879
|
-
tr: ", or render it inside a <td> or <th>",
|
|
1880
|
-
svg: ", or render it inside a <foreignObject>"
|
|
1881
|
-
};
|
|
1882
|
-
function findParserSensitiveJsxContainer(content, localBindings) {
|
|
1883
|
-
if (!content || localBindings.length === 0) return void 0;
|
|
1884
|
-
const names = new Set(localBindings);
|
|
1885
|
-
const tokens = tokenizeModuleSource(content);
|
|
1886
|
-
const open = [];
|
|
1887
|
-
const isSelfClosing = (openingIndex) => {
|
|
1888
|
-
for (let index = openingIndex; index < tokens.length; index++) {
|
|
1889
|
-
if (tokens[index].value === ">") return tokens[index - 1]?.value === "/";
|
|
1890
|
-
}
|
|
1891
|
-
return false;
|
|
1892
|
-
};
|
|
1893
|
-
for (let index = 0; index < tokens.length - 1; index++) {
|
|
1894
|
-
if (tokens[index].value !== "<") continue;
|
|
1895
|
-
if (tokens[index + 1].value === "/") {
|
|
1896
|
-
const closing = tokens[index + 2]?.value;
|
|
1897
|
-
const at = closing ? open.lastIndexOf(closing) : -1;
|
|
1898
|
-
if (at !== -1) open.length = at;
|
|
1899
|
-
continue;
|
|
1900
|
-
}
|
|
1901
|
-
const tag = tokens[index + 1].value;
|
|
1902
|
-
if (names.has(tag)) {
|
|
1903
|
-
let container;
|
|
1904
|
-
for (let depth = open.length - 1; depth >= 0; depth--) {
|
|
1905
|
-
if (PARSER_FLOW_CONTENT_ELEMENTS.has(open[depth])) break;
|
|
1906
|
-
container = open[depth];
|
|
1907
|
-
}
|
|
1908
|
-
if (container) return container;
|
|
1909
|
-
continue;
|
|
1910
|
-
}
|
|
1911
|
-
if ((PARSER_SENSITIVE_JSX_CONTAINERS.has(tag) || open.length > 0 && PARSER_FLOW_CONTENT_ELEMENTS.has(tag)) && !isSelfClosing(index)) {
|
|
1912
|
-
open.push(tag);
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
return void 0;
|
|
1916
|
-
}
|
|
1917
|
-
function countStaticJsxUses(content, localBindings) {
|
|
1918
|
-
if (!content || localBindings.length === 0) return 0;
|
|
1919
|
-
const names = new Set(localBindings);
|
|
1920
|
-
const tokens = tokenizeModuleSource(content);
|
|
1921
|
-
let count = 0;
|
|
1922
|
-
for (let index = 0; index < tokens.length - 1; index++) {
|
|
1923
|
-
if (tokens[index].value === "<" && names.has(tokens[index + 1].value)) count++;
|
|
1924
|
-
}
|
|
1925
|
-
return count;
|
|
1926
|
-
}
|
|
1927
|
-
function findMatchingToken(tokens, openingIndex, opening, closing) {
|
|
1928
|
-
let depth = 0;
|
|
1929
|
-
for (let index = openingIndex; index < tokens.length; index++) {
|
|
1930
|
-
if (tokens[index].value === opening) depth++;
|
|
1931
|
-
if (tokens[index].value !== closing) continue;
|
|
1932
|
-
depth--;
|
|
1933
|
-
if (depth === 0) return index;
|
|
1934
|
-
}
|
|
1935
|
-
return tokens.length - 1;
|
|
1936
|
-
}
|
|
1937
|
-
function containsClientJsx(tokens, start, end, clientBindings) {
|
|
1938
|
-
for (let index = start; index < end; index++) {
|
|
1939
|
-
if (tokens[index].value === "<" && clientBindings.has(tokens[index + 1]?.value)) return true;
|
|
1940
|
-
}
|
|
1941
|
-
return false;
|
|
1942
|
-
}
|
|
1943
|
-
function findStatementEnd(tokens, start) {
|
|
1944
|
-
let parentheses = 0;
|
|
1945
|
-
let brackets = 0;
|
|
1946
|
-
let braces = 0;
|
|
1947
|
-
const statementStarters = /* @__PURE__ */ new Set([
|
|
1948
|
-
"class",
|
|
1949
|
-
"const",
|
|
1950
|
-
"export",
|
|
1951
|
-
"function",
|
|
1952
|
-
"import",
|
|
1953
|
-
"let",
|
|
1954
|
-
"var"
|
|
1955
|
-
]);
|
|
1956
|
-
for (let index = start; index < tokens.length; index++) {
|
|
1957
|
-
const value = tokens[index].value;
|
|
1958
|
-
if (index > start && parentheses === 0 && brackets === 0 && braces === 0 && tokens[index].line > tokens[index - 1].line && statementStarters.has(value)) {
|
|
1959
|
-
return index;
|
|
1960
|
-
}
|
|
1961
|
-
if (value === ";" && parentheses === 0 && brackets === 0 && braces === 0) return index;
|
|
1962
|
-
if (value === "(") parentheses++;
|
|
1963
|
-
if (value === ")") parentheses--;
|
|
1964
|
-
if (value === "[") brackets++;
|
|
1965
|
-
if (value === "]") brackets--;
|
|
1966
|
-
if (value === "{") braces++;
|
|
1967
|
-
if (value === "}") braces--;
|
|
1968
|
-
}
|
|
1969
|
-
return tokens.length;
|
|
1970
|
-
}
|
|
1971
|
-
function getClientRenderingHelpers(tokens, clientBindings) {
|
|
1972
|
-
const helperBodies = /* @__PURE__ */ new Map();
|
|
1973
|
-
for (let index = 0; index < tokens.length; index++) {
|
|
1974
|
-
let helperName;
|
|
1975
|
-
let bodyStart = -1;
|
|
1976
|
-
let bodyEnd = -1;
|
|
1977
|
-
if (tokens[index].value === "function" && tokens[index + 1]?.kind === "identifier") {
|
|
1978
|
-
helperName = tokens[index + 1].value;
|
|
1979
|
-
const parametersStart = tokens.findIndex(
|
|
1980
|
-
(token, tokenIndex) => tokenIndex > index + 1 && token.value === "("
|
|
1981
|
-
);
|
|
1982
|
-
const parametersEnd = parametersStart === -1 ? index + 1 : findMatchingToken(tokens, parametersStart, "(", ")");
|
|
1983
|
-
bodyStart = tokens.findIndex(
|
|
1984
|
-
(token, tokenIndex) => tokenIndex > parametersEnd && token.value === "{"
|
|
1985
|
-
);
|
|
1986
|
-
if (bodyStart !== -1) bodyEnd = findMatchingToken(tokens, bodyStart, "{", "}");
|
|
1987
|
-
} else if ((tokens[index].value === "const" || tokens[index].value === "let" || tokens[index].value === "var") && tokens[index + 1]?.kind === "identifier") {
|
|
1988
|
-
helperName = tokens[index + 1].value;
|
|
1989
|
-
let assignmentIndex = -1;
|
|
1990
|
-
let arrowIndex = -1;
|
|
1991
|
-
for (let cursor = index + 2; cursor < tokens.length; cursor++) {
|
|
1992
|
-
if (tokens[cursor].value === ";") break;
|
|
1993
|
-
if (assignmentIndex === -1 && tokens[cursor].value === "=") assignmentIndex = cursor;
|
|
1994
|
-
if (tokens[cursor].value === "=" && tokens[cursor + 1]?.value === ">") {
|
|
1995
|
-
arrowIndex = cursor;
|
|
1996
|
-
break;
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
if (arrowIndex !== -1) {
|
|
2000
|
-
bodyStart = arrowIndex + 2;
|
|
2001
|
-
bodyEnd = tokens[bodyStart]?.value === "{" ? findMatchingToken(tokens, bodyStart, "{", "}") : findStatementEnd(tokens, bodyStart);
|
|
2002
|
-
} else if (assignmentIndex !== -1) {
|
|
2003
|
-
bodyStart = assignmentIndex + 1;
|
|
2004
|
-
bodyEnd = findStatementEnd(tokens, bodyStart);
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
if (helperName && bodyStart !== -1 && bodyEnd !== -1) {
|
|
2008
|
-
helperBodies.set(helperName, [bodyStart, bodyEnd]);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
const helpers = /* @__PURE__ */ new Set();
|
|
2012
|
-
let addedHelper = true;
|
|
2013
|
-
while (addedHelper) {
|
|
2014
|
-
addedHelper = false;
|
|
2015
|
-
for (const [helperName, [bodyStart, bodyEnd]] of helperBodies) {
|
|
2016
|
-
if (helpers.has(helperName)) continue;
|
|
2017
|
-
const rendersClientBoundary = containsClientJsx(tokens, bodyStart, bodyEnd, clientBindings) || tokens.slice(bodyStart, bodyEnd).some((token) => helpers.has(token.value));
|
|
2018
|
-
if (!rendersClientBoundary) continue;
|
|
2019
|
-
helpers.add(helperName);
|
|
2020
|
-
addedHelper = true;
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
return helpers;
|
|
2024
|
-
}
|
|
2025
|
-
function passesElementValuedProps(content, localBindings) {
|
|
2026
|
-
if (!content || localBindings.length === 0) return false;
|
|
2027
|
-
const names = new Set(localBindings);
|
|
2028
|
-
const tokens = tokenizeModuleSource(content);
|
|
2029
|
-
for (let index = 0; index < tokens.length - 1; index++) {
|
|
2030
|
-
if (tokens[index].value !== "<" || !names.has(tokens[index + 1].value)) continue;
|
|
2031
|
-
const name = tokens[index + 1].value;
|
|
2032
|
-
let cursor = index + 2;
|
|
2033
|
-
let braceDepth = 0;
|
|
2034
|
-
let selfClosing = false;
|
|
2035
|
-
for (; cursor < tokens.length; cursor++) {
|
|
2036
|
-
const value = tokens[cursor].value;
|
|
2037
|
-
if (value === "{") braceDepth++;
|
|
2038
|
-
else if (value === "}") braceDepth--;
|
|
2039
|
-
else if (value === "<" && braceDepth > 0) return true;
|
|
2040
|
-
else if (value === ">" && braceDepth === 0) {
|
|
2041
|
-
selfClosing = tokens[cursor - 1]?.value === "/";
|
|
2042
|
-
break;
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
if (selfClosing || cursor >= tokens.length) continue;
|
|
2046
|
-
for (let child = cursor + 1; child < tokens.length; child++) {
|
|
2047
|
-
if (tokens[child].value !== "<") continue;
|
|
2048
|
-
const closesBoundary = tokens[child + 1]?.value === "/" && tokens[child + 2]?.value === name;
|
|
2049
|
-
if (!closesBoundary) return true;
|
|
2050
|
-
break;
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
return false;
|
|
2054
|
-
}
|
|
2055
|
-
function rendersOnlyLeafElements(content, localBindings) {
|
|
2056
|
-
if (!content) return false;
|
|
2057
|
-
const names = new Set(localBindings);
|
|
2058
|
-
const tokens = tokenizeModuleSource(content);
|
|
2059
|
-
for (let index = 0; index < tokens.length - 1; index++) {
|
|
2060
|
-
if (tokens[index].value !== "<" || !names.has(tokens[index + 1].value)) continue;
|
|
2061
|
-
let braceDepth = 0;
|
|
2062
|
-
let cursor = index + 2;
|
|
2063
|
-
for (; cursor < tokens.length; cursor++) {
|
|
2064
|
-
const value = tokens[cursor].value;
|
|
2065
|
-
if (value === "{") braceDepth++;
|
|
2066
|
-
else if (value === "}") braceDepth--;
|
|
2067
|
-
else if (value === "<" && braceDepth > 0) return false;
|
|
2068
|
-
else if (value === ">" && braceDepth === 0) break;
|
|
2069
|
-
}
|
|
2070
|
-
if (cursor >= tokens.length || tokens[cursor - 1]?.value !== "/") return false;
|
|
2071
|
-
}
|
|
2072
|
-
return true;
|
|
2073
|
-
}
|
|
2074
|
-
function hasDynamicJsxCardinality(content, localBindings) {
|
|
2075
|
-
if (!content || localBindings.length === 0) return false;
|
|
2076
|
-
const clientBindings = new Set(localBindings);
|
|
2077
|
-
const tokens = tokenizeModuleSource(content);
|
|
2078
|
-
const renderingHelpers = getClientRenderingHelpers(tokens, clientBindings);
|
|
2079
|
-
const containsDynamicRenderer = (start, end) => containsClientJsx(tokens, start, end, clientBindings) || tokens.slice(start, end).some((token) => renderingHelpers.has(token.value));
|
|
2080
|
-
for (let index = 0; index < tokens.length; index++) {
|
|
2081
|
-
let callStart = -1;
|
|
2082
|
-
if (tokens[index].value === "." && (tokens[index + 1]?.value === "map" || tokens[index + 1]?.value === "flatMap") && tokens[index + 2]?.value === "(") {
|
|
2083
|
-
callStart = index + 2;
|
|
2084
|
-
} else if (tokens[index].value === "Array" && tokens[index + 1]?.value === "." && tokens[index + 2]?.value === "from" && tokens[index + 3]?.value === "(") {
|
|
2085
|
-
callStart = index + 3;
|
|
2086
|
-
}
|
|
2087
|
-
if (callStart !== -1) {
|
|
2088
|
-
const callEnd = findMatchingToken(tokens, callStart, "(", ")");
|
|
2089
|
-
if (containsDynamicRenderer(callStart + 1, callEnd)) return true;
|
|
2090
|
-
index = callEnd;
|
|
2091
|
-
continue;
|
|
2092
|
-
}
|
|
2093
|
-
if ((tokens[index].value === "for" || tokens[index].value === "while") && tokens[index + 1]?.value === "(") {
|
|
2094
|
-
const conditionEnd = findMatchingToken(tokens, index + 1, "(", ")");
|
|
2095
|
-
const bodyStart = conditionEnd + 1;
|
|
2096
|
-
const bodyEnd = tokens[bodyStart]?.value === "{" ? findMatchingToken(tokens, bodyStart, "{", "}") : tokens.findIndex((token, tokenIndex) => tokenIndex > bodyStart && token.value === ";");
|
|
2097
|
-
if (containsDynamicRenderer(bodyStart, bodyEnd === -1 ? tokens.length : bodyEnd)) return true;
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
return false;
|
|
2101
|
-
}
|
|
2102
|
-
function collectIsolatedClientBoundaries(ownerPath, root, options = {}) {
|
|
2103
|
-
const boundaries = /* @__PURE__ */ new Map();
|
|
2104
|
-
const staticPackages = /* @__PURE__ */ new Set();
|
|
2105
|
-
const estimates = /* @__PURE__ */ new Map();
|
|
2106
|
-
const visiting = /* @__PURE__ */ new Set();
|
|
2107
|
-
let fallbackReason;
|
|
2108
|
-
let fallbackHint;
|
|
2109
|
-
let costGuardExceeded = false;
|
|
2110
|
-
const projectRoot = root ? path4.resolve(root) : void 0;
|
|
2111
|
-
const visit = (moduleSourcePath) => {
|
|
2112
|
-
if (fallbackReason) return 0;
|
|
2113
|
-
const cached = estimates.get(moduleSourcePath);
|
|
2114
|
-
if (cached !== void 0) return cached;
|
|
2115
|
-
if (visiting.has(moduleSourcePath)) return 0;
|
|
2116
|
-
visiting.add(moduleSourcePath);
|
|
2117
|
-
const content = readIfExists(moduleSourcePath);
|
|
2118
|
-
const parsed = parseClientModuleMetadata(content, false);
|
|
2119
|
-
if (parsed.isClientComponent) {
|
|
2120
|
-
if (projectRoot && !path4.resolve(moduleSourcePath).startsWith(`${projectRoot}${path4.sep}`)) {
|
|
2121
|
-
fallbackReason = `client boundary ${moduleSourcePath} is outside the application root`;
|
|
2122
|
-
fallbackHint = "Move the component into the application, or publish it as a package (package client components render as static HTML)";
|
|
2123
|
-
return 0;
|
|
2124
|
-
}
|
|
2125
|
-
if (!isIsolatableClientBoundarySource(content)) {
|
|
2126
|
-
fallbackReason = `client boundary ${moduleSourcePath} uses an unsupported export shape`;
|
|
2127
|
-
fallbackHint = "Export each component by name (`export function Name`, `export { Name }`, or `export default`) instead of `export *`";
|
|
2128
|
-
return 0;
|
|
2129
|
-
}
|
|
2130
|
-
boundaries.set(moduleSourcePath, {
|
|
2131
|
-
modulePath: moduleSourcePath,
|
|
2132
|
-
islandStrategy: parsed.islandStrategy ?? "load"
|
|
2133
|
-
});
|
|
2134
|
-
estimates.set(moduleSourcePath, 1);
|
|
2135
|
-
visiting.delete(moduleSourcePath);
|
|
2136
|
-
return 1;
|
|
2137
|
-
}
|
|
2138
|
-
if (parsed.hasHydrateExport) {
|
|
2139
|
-
fallbackReason = `imported module ${moduleSourcePath} explicitly exports hydrate = true`;
|
|
2140
|
-
fallbackHint = "Islands mode never hydrates a whole page; remove `hydrate = true`";
|
|
2141
|
-
return 0;
|
|
2142
|
-
}
|
|
2143
|
-
const importedBindings = getStaticImportBindings(content);
|
|
2144
|
-
let estimatedBoundaryCount2 = 0;
|
|
2145
|
-
for (const specifier of new Set(getImportSpecifiers(content))) {
|
|
2146
|
-
const imported = resolveImportedModule(moduleSourcePath, specifier, root);
|
|
2147
|
-
const importedPath = imported.path;
|
|
2148
|
-
if (!importedPath) continue;
|
|
2149
|
-
let importedBoundaryCount;
|
|
2150
|
-
if (imported.local) {
|
|
2151
|
-
importedBoundaryCount = visit(importedPath);
|
|
2152
|
-
} else {
|
|
2153
|
-
const reactServerClientNames = options.packageReferences && projectRoot ? findFarmReactServerClientNames(content ?? "", moduleSourcePath, specifier) : null;
|
|
2154
|
-
if (reactServerClientNames) {
|
|
2155
|
-
importedBoundaryCount = 0;
|
|
2156
|
-
for (const exportName of reactServerClientNames) {
|
|
2157
|
-
importedBoundaryCount += visit(
|
|
2158
|
-
ensureFarmPackageClientReference(projectRoot, specifier, exportName)
|
|
2159
|
-
);
|
|
2160
|
-
}
|
|
2161
|
-
} else {
|
|
2162
|
-
const packageMetadata = inspectPackageClientBoundary(importedPath, root, /* @__PURE__ */ new Set());
|
|
2163
|
-
if (!packageMetadata.shouldHydrate) continue;
|
|
2164
|
-
const references = options.packageReferences && projectRoot ? findFarmPackageClientImports(
|
|
2165
|
-
content ?? "",
|
|
2166
|
-
moduleSourcePath,
|
|
2167
|
-
(candidate) => candidate === specifier
|
|
2168
|
-
) : [];
|
|
2169
|
-
if (references.length > 0) {
|
|
2170
|
-
importedBoundaryCount = 0;
|
|
2171
|
-
for (const reference of references) {
|
|
2172
|
-
for (const exportName of farmPackageClientImportExports(reference)) {
|
|
2173
|
-
importedBoundaryCount += visit(
|
|
2174
|
-
ensureFarmPackageClientReference(projectRoot, specifier, exportName)
|
|
2175
|
-
);
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
} else if (options.staticPackageBoundaries || options.staticPackageLeaves && rendersOnlyLeafElements(content, importedBindings.get(specifier) ?? [])) {
|
|
2179
|
-
staticPackages.add(specifier);
|
|
2180
|
-
continue;
|
|
2181
|
-
} else {
|
|
2182
|
-
fallbackReason = `package client boundary ${specifier} cannot yet be isolated`;
|
|
2183
|
-
fallbackHint = `Render it from a local "use client" module (a providers.tsx that renders the ${specifier} component)`;
|
|
2184
|
-
return 0;
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
if (fallbackReason || importedBoundaryCount === 0) continue;
|
|
2189
|
-
const localBindings = importedBindings.get(specifier) ?? [];
|
|
2190
|
-
const staticUses = countStaticJsxUses(content, localBindings);
|
|
2191
|
-
if (staticUses > 0) {
|
|
2192
|
-
const container = findParserSensitiveJsxContainer(content, localBindings);
|
|
2193
|
-
if (container) {
|
|
2194
|
-
fallbackReason = `the client boundary imported from ${specifier} renders inside <${container}>, where the HTML parser relocates its hydration marker`;
|
|
2195
|
-
fallbackHint = `Move "use client" up to a component that renders the whole <${container}>${PARSER_SENSITIVE_FLOW_HINTS[container] ?? ""}`;
|
|
2196
|
-
return 0;
|
|
2197
|
-
}
|
|
2198
|
-
if (!options.allowElementProps && passesElementValuedProps(content, localBindings)) {
|
|
2199
|
-
fallbackReason = `the client boundary imported from ${specifier} receives React elements, which cannot cross the boundary as serialized props`;
|
|
2200
|
-
return 0;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
if (staticUses > 0 && !options.allowDynamicCardinality && hasDynamicJsxCardinality(content, localBindings)) {
|
|
2204
|
-
fallbackReason = `the client boundary count imported from ${specifier} is data-dependent`;
|
|
2205
|
-
costGuardExceeded = true;
|
|
2206
|
-
return 0;
|
|
2207
|
-
}
|
|
2208
|
-
estimatedBoundaryCount2 += importedBoundaryCount * Math.max(1, staticUses);
|
|
2209
|
-
}
|
|
2210
|
-
estimates.set(moduleSourcePath, estimatedBoundaryCount2);
|
|
2211
|
-
visiting.delete(moduleSourcePath);
|
|
2212
|
-
return estimatedBoundaryCount2;
|
|
2213
|
-
};
|
|
2214
|
-
const estimatedBoundaryCount = visit(ownerPath);
|
|
2215
|
-
return {
|
|
2216
|
-
boundaries: Array.from(boundaries.values()),
|
|
2217
|
-
estimatedBoundaryCount,
|
|
2218
|
-
staticPackages: Array.from(staticPackages),
|
|
2219
|
-
costGuardExceeded,
|
|
2220
|
-
fallbackReason,
|
|
2221
|
-
fallbackHint
|
|
2222
|
-
};
|
|
2223
|
-
}
|
|
2224
|
-
function inspectClientModuleMetadata(resolvedPath, root, visited, inspectIslandExport) {
|
|
2225
|
-
if (!resolvedPath || visited.has(resolvedPath)) {
|
|
2226
|
-
return {
|
|
2227
|
-
isClientComponent: false,
|
|
2228
|
-
shouldHydrate: false,
|
|
2229
|
-
islandStrategy: null
|
|
2230
|
-
};
|
|
2231
|
-
}
|
|
2232
|
-
visited.add(resolvedPath);
|
|
2233
|
-
const content = readIfExists(resolvedPath);
|
|
2234
|
-
if (inspectIslandExport) {
|
|
2235
|
-
const target = resolveDefaultReexport(resolvedPath, content, root);
|
|
2236
|
-
if (target) return inspectClientModuleMetadata(target, root, visited, true);
|
|
2237
|
-
}
|
|
2238
|
-
const parsed = parseClientModuleMetadata(content, inspectIslandExport);
|
|
2239
|
-
if (parsed.isClientComponent) {
|
|
2240
|
-
return {
|
|
2241
|
-
isClientComponent: true,
|
|
2242
|
-
shouldHydrate: true,
|
|
2243
|
-
islandStrategy: parsed.islandStrategy ?? "load"
|
|
2244
|
-
};
|
|
2245
|
-
}
|
|
2246
|
-
let importsClientBoundary = false;
|
|
2247
|
-
let importsAsyncOwner = false;
|
|
2248
|
-
let importedIslandStrategy = null;
|
|
2249
|
-
for (const specifier of getImportSpecifiers(content)) {
|
|
2250
|
-
const imported = resolveImportedModule(resolvedPath, specifier, root);
|
|
2251
|
-
const importedMetadata = imported.local ? inspectClientModuleMetadata(imported.path, root, visited, false) : inspectPackageClientBoundary(imported.path, root, visited);
|
|
2252
|
-
if (importedMetadata.suppressedAsyncHydration) importsAsyncOwner = true;
|
|
2253
|
-
if (importedMetadata.isClientComponent || importedMetadata.shouldHydrate) {
|
|
2254
|
-
importsClientBoundary = true;
|
|
2255
|
-
if (importedIslandStrategy === null) {
|
|
2256
|
-
importedIslandStrategy = importedMetadata.islandStrategy;
|
|
2257
|
-
} else if (importedIslandStrategy !== importedMetadata.islandStrategy) {
|
|
2258
|
-
importedIslandStrategy = "load";
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
const shouldHydrate = parsed.hasHydrateExport || importsClientBoundary;
|
|
2263
|
-
if (shouldHydrate && hasAsyncDefaultExport(content) || importsAsyncOwner) {
|
|
2264
|
-
return {
|
|
2265
|
-
isClientComponent: false,
|
|
2266
|
-
shouldHydrate: false,
|
|
2267
|
-
islandStrategy: null,
|
|
2268
|
-
suppressedAsyncHydration: true
|
|
2269
|
-
};
|
|
2270
|
-
}
|
|
2271
|
-
return {
|
|
2272
|
-
isClientComponent: false,
|
|
2273
|
-
shouldHydrate,
|
|
2274
|
-
islandStrategy: shouldHydrate ? parsed.islandStrategy ?? importedIslandStrategy ?? "load" : null
|
|
2275
|
-
};
|
|
2276
|
-
}
|
|
2277
|
-
function inspectPackageClientBoundary(resolvedPath, root, visited) {
|
|
2278
|
-
const cache3 = getPackageClientBoundaryCache();
|
|
2279
|
-
if (!cache3 || !resolvedPath || visited.has(resolvedPath)) {
|
|
2280
|
-
return traversePackageClientBoundary(resolvedPath, root, visited);
|
|
2281
|
-
}
|
|
2282
|
-
const key = `${root ?? ""}\0${resolvedPath}`;
|
|
2283
|
-
const cached = cache3.find(key, visited);
|
|
2284
|
-
if (cached) {
|
|
2285
|
-
for (const file of cached.files) visited.add(file);
|
|
2286
|
-
return { ...cached.result };
|
|
2287
|
-
}
|
|
2288
|
-
const trace = new PackageInspectionTrace();
|
|
2289
|
-
const result = traversePackageClientBoundary(resolvedPath, root, visited, trace);
|
|
2290
|
-
cache3.add(key, trace.toEntry(result));
|
|
2291
|
-
return result;
|
|
2292
|
-
}
|
|
2293
|
-
function traversePackageClientBoundary(resolvedPath, root, visited, trace) {
|
|
2294
|
-
if (!resolvedPath || visited.has(resolvedPath)) {
|
|
2295
|
-
if (resolvedPath) trace?.stop(resolvedPath);
|
|
2296
|
-
return {
|
|
2297
|
-
isClientComponent: false,
|
|
2298
|
-
shouldHydrate: false,
|
|
2299
|
-
islandStrategy: null
|
|
2300
|
-
};
|
|
2301
|
-
}
|
|
2302
|
-
visited.add(resolvedPath);
|
|
2303
|
-
trace?.visit(resolvedPath);
|
|
2304
|
-
const content = readIfExists(resolvedPath);
|
|
2305
|
-
const parsed = parseClientModuleMetadata(content, false);
|
|
2306
|
-
let importsClientBoundary = false;
|
|
2307
|
-
let importedIslandStrategy = null;
|
|
2308
|
-
for (const specifier of getImportSpecifiers(content)) {
|
|
2309
|
-
if (!specifier.startsWith(".") && !specifier.startsWith("/")) continue;
|
|
2310
|
-
const importedPath = resolveImportedModuleSourcePath(resolvedPath, specifier, root);
|
|
2311
|
-
const importedMetadata = traversePackageClientBoundary(importedPath, root, visited, trace);
|
|
2312
|
-
if (!importedMetadata.shouldHydrate) continue;
|
|
2313
|
-
importsClientBoundary = true;
|
|
2314
|
-
if (importedIslandStrategy === null) {
|
|
2315
|
-
importedIslandStrategy = importedMetadata.islandStrategy;
|
|
2316
|
-
} else if (importedIslandStrategy !== importedMetadata.islandStrategy) {
|
|
2317
|
-
importedIslandStrategy = "load";
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
const shouldHydrate = parsed.isClientComponent || parsed.hasHydrateExport || importsClientBoundary;
|
|
2321
|
-
return {
|
|
2322
|
-
isClientComponent: parsed.isClientComponent,
|
|
2323
|
-
shouldHydrate,
|
|
2324
|
-
islandStrategy: shouldHydrate ? parsed.islandStrategy ?? importedIslandStrategy ?? "load" : null
|
|
2325
|
-
};
|
|
2326
|
-
}
|
|
2327
|
-
function getImportSpecifiers(content) {
|
|
2328
|
-
if (!content) return [];
|
|
2329
|
-
const tokens = tokenizeModuleSource(content);
|
|
2330
|
-
const matches = /* @__PURE__ */ new Set();
|
|
2331
|
-
let braceDepth = 0;
|
|
2332
|
-
for (let index = 0; index < tokens.length; index++) {
|
|
2333
|
-
const keyword = tokens[index];
|
|
2334
|
-
if (keyword.value === "{") {
|
|
2335
|
-
braceDepth++;
|
|
2336
|
-
continue;
|
|
2337
|
-
}
|
|
2338
|
-
if (keyword.value === "}") {
|
|
2339
|
-
braceDepth = Math.max(0, braceDepth - 1);
|
|
2340
|
-
continue;
|
|
2341
|
-
}
|
|
2342
|
-
if (braceDepth !== 0) continue;
|
|
2343
|
-
if (keyword.kind !== "identifier" || !["import", "export"].includes(keyword.value)) {
|
|
2344
|
-
continue;
|
|
2345
|
-
}
|
|
2346
|
-
const previous = tokens[index - 1];
|
|
2347
|
-
if (previous?.value === ".") continue;
|
|
2348
|
-
const first = tokens[index + 1];
|
|
2349
|
-
if (!first || first.value === "type" || first.value === "(" || first.value === ".") {
|
|
2350
|
-
continue;
|
|
2351
|
-
}
|
|
2352
|
-
let specifier;
|
|
2353
|
-
if (keyword.value === "import" && first.kind === "string") {
|
|
2354
|
-
specifier = first.value;
|
|
2355
|
-
} else {
|
|
2356
|
-
if (keyword.value === "export" && first.value !== "{" && first.value !== "*") {
|
|
2357
|
-
continue;
|
|
2358
|
-
}
|
|
2359
|
-
let fromIndex = -1;
|
|
2360
|
-
for (let cursor = index + 1; cursor < tokens.length; cursor++) {
|
|
2361
|
-
const token = tokens[cursor];
|
|
2362
|
-
if (token.value === ";") break;
|
|
2363
|
-
if (token.value === "from" && tokens[cursor + 1]?.kind === "string") {
|
|
2364
|
-
fromIndex = cursor;
|
|
2365
|
-
break;
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
if (fromIndex === -1 || isTypeOnlyNamedClause(tokens, index + 1, fromIndex)) {
|
|
2369
|
-
continue;
|
|
2370
|
-
}
|
|
2371
|
-
specifier = tokens[fromIndex + 1].value;
|
|
2372
|
-
}
|
|
2373
|
-
if (!specifier || specifier.startsWith("node:") || specifier.includes("?")) {
|
|
2374
|
-
continue;
|
|
2375
|
-
}
|
|
2376
|
-
matches.add(specifier);
|
|
2377
|
-
}
|
|
2378
|
-
return Array.from(matches);
|
|
2379
|
-
}
|
|
2380
|
-
function isTypeOnlyNamedClause(tokens, startIndex, endIndex) {
|
|
2381
|
-
if (tokens[startIndex]?.value !== "{") return false;
|
|
2382
|
-
const closingBraceIndex = tokens.findIndex(
|
|
2383
|
-
(token, index) => index > startIndex && index < endIndex && token.value === "}"
|
|
2384
|
-
);
|
|
2385
|
-
if (closingBraceIndex === -1) return false;
|
|
2386
|
-
let entryStartsAt = startIndex + 1;
|
|
2387
|
-
for (let index = entryStartsAt; index <= closingBraceIndex; index++) {
|
|
2388
|
-
if (index !== closingBraceIndex && tokens[index]?.value !== ",") continue;
|
|
2389
|
-
const entry = tokens.slice(entryStartsAt, index);
|
|
2390
|
-
if (entry.length > 0 && entry[0].value !== "type") return false;
|
|
2391
|
-
entryStartsAt = index + 1;
|
|
2392
|
-
}
|
|
2393
|
-
return true;
|
|
2394
|
-
}
|
|
2395
|
-
function resolveImportedModule(importerPath, specifier, root) {
|
|
2396
|
-
if (specifier.startsWith(".") || specifier.startsWith("/")) {
|
|
2397
|
-
return { path: resolveImportedModuleSourcePath(importerPath, specifier, root), local: true };
|
|
2398
|
-
}
|
|
2399
|
-
const aliased = resolveProjectAliasSourcePath(specifier, root);
|
|
2400
|
-
if (aliased) return { path: aliased, local: true };
|
|
2401
|
-
const packagePath = resolvePackageModuleSourcePath(importerPath, specifier, root);
|
|
2402
|
-
if (!packagePath) warnUnresolvedAliasImport(importerPath, specifier, root);
|
|
2403
|
-
return { path: packagePath, local: false };
|
|
2404
|
-
}
|
|
2405
|
-
var warnedUnresolvedAliasImports = /* @__PURE__ */ new Set();
|
|
2406
|
-
var ALIAS_IMPORT = /^(?:@\/|~\/|#)/;
|
|
2407
|
-
function warnUnresolvedAliasImport(importerPath, specifier, root) {
|
|
2408
|
-
if (!ALIAS_IMPORT.test(specifier) || warnedUnresolvedAliasImports.has(specifier)) return;
|
|
2409
|
-
warnedUnresolvedAliasImports.add(specifier);
|
|
2410
|
-
const importer = root ? path4.relative(root, importerPath) : importerPath;
|
|
2411
|
-
logger.warn(
|
|
2412
|
-
`Could not resolve "${specifier}" (imported by ${importer}) while checking which pages need client JavaScript. If it holds client components, they will not hydrate. Map the alias in tsconfig.json "paths" or package.json "imports".`
|
|
2413
|
-
);
|
|
2414
|
-
}
|
|
2415
|
-
var projectImportAliasCache = /* @__PURE__ */ new Map();
|
|
2416
|
-
var PROJECT_ALIAS_FILES = ["tsconfig.json", "jsconfig.json", "package.json"];
|
|
2417
|
-
function resolveProjectAliasSourcePath(specifier, root) {
|
|
2418
|
-
if (!root) return void 0;
|
|
2419
|
-
const projectRoot = path4.resolve(root);
|
|
2420
|
-
let match;
|
|
2421
|
-
for (const alias of getProjectImportAliases(projectRoot)) {
|
|
2422
|
-
const captured = matchProjectImportAlias(alias, specifier);
|
|
2423
|
-
if (captured === null) continue;
|
|
2424
|
-
if (!match || alias.prefix.length > match.alias.prefix.length) match = { alias, captured };
|
|
2425
|
-
}
|
|
2426
|
-
if (!match) return void 0;
|
|
2427
|
-
const resolved = resolveSourceCandidate(
|
|
2428
|
-
match.alias.targets.map(
|
|
2429
|
-
(target) => path4.normalize(match.alias.wildcard ? target.replace("*", match.captured) : target)
|
|
2430
|
-
)
|
|
2431
|
-
);
|
|
2432
|
-
return resolved && /\.d\.[cm]?ts$/.test(resolved) ? null : resolved;
|
|
2433
|
-
}
|
|
2434
|
-
function matchProjectImportAlias(alias, specifier) {
|
|
2435
|
-
if (!alias.wildcard) return specifier === alias.prefix ? "" : null;
|
|
2436
|
-
if (specifier.length < alias.prefix.length + alias.suffix.length || !specifier.startsWith(alias.prefix) || !specifier.endsWith(alias.suffix)) {
|
|
2437
|
-
return null;
|
|
2438
|
-
}
|
|
2439
|
-
return specifier.slice(alias.prefix.length, specifier.length - alias.suffix.length);
|
|
2440
|
-
}
|
|
2441
|
-
function getProjectImportAliases(projectRoot) {
|
|
2442
|
-
const stamp = PROJECT_ALIAS_FILES.map((file) => {
|
|
2443
|
-
try {
|
|
2444
|
-
return String(fs4.statSync(path4.join(projectRoot, file)).mtimeMs);
|
|
2445
|
-
} catch {
|
|
2446
|
-
return "-";
|
|
2447
|
-
}
|
|
2448
|
-
}).join(":");
|
|
2449
|
-
const sourceDir = getFarmProjectSourceDir(projectRoot);
|
|
2450
|
-
const cacheStamp = `${stamp}:${sourceDir}`;
|
|
2451
|
-
const cached = projectImportAliasCache.get(projectRoot);
|
|
2452
|
-
if (cached?.stamp === cacheStamp) return cached.aliases;
|
|
2453
|
-
const aliases = [
|
|
2454
|
-
...readTsconfigPathAliases(projectRoot),
|
|
2455
|
-
...readPackageImportAliases(projectRoot)
|
|
2456
|
-
];
|
|
2457
|
-
if (!aliases.some((alias) => alias.prefix === "@/")) {
|
|
2458
|
-
aliases.push({
|
|
2459
|
-
prefix: "@/",
|
|
2460
|
-
suffix: "",
|
|
2461
|
-
wildcard: true,
|
|
2462
|
-
targets: [path4.join(projectRoot, sourceDir, "*")]
|
|
2463
|
-
});
|
|
2464
|
-
}
|
|
2465
|
-
projectImportAliasCache.set(projectRoot, { stamp: cacheStamp, aliases });
|
|
2466
|
-
return aliases;
|
|
2467
|
-
}
|
|
2468
|
-
function readTsconfigPathAliases(projectRoot) {
|
|
2469
|
-
for (const name of ["tsconfig.json", "jsconfig.json"]) {
|
|
2470
|
-
const configPath = path4.join(projectRoot, name);
|
|
2471
|
-
if (!fs4.existsSync(configPath)) continue;
|
|
2472
|
-
const resolved = readTsconfigPaths(configPath, /* @__PURE__ */ new Set());
|
|
2473
|
-
if (!resolved?.paths) return [];
|
|
2474
|
-
const base = resolved.baseUrl ?? resolved.pathsDirectory;
|
|
2475
|
-
return Object.entries(resolved.paths).flatMap(([pattern, targets]) => {
|
|
2476
|
-
if (!Array.isArray(targets)) return [];
|
|
2477
|
-
const wildcardIndex = pattern.indexOf("*");
|
|
2478
|
-
return [
|
|
2479
|
-
{
|
|
2480
|
-
prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
|
|
2481
|
-
suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
|
|
2482
|
-
wildcard: wildcardIndex !== -1,
|
|
2483
|
-
targets: targets.filter((target) => typeof target === "string").map((target) => path4.resolve(base, target))
|
|
2484
|
-
}
|
|
2485
|
-
];
|
|
2486
|
-
});
|
|
2487
|
-
}
|
|
2488
|
-
return [];
|
|
2489
|
-
}
|
|
2490
|
-
function readTsconfigPaths(configPath, visited) {
|
|
2491
|
-
if (visited.has(configPath)) return null;
|
|
2492
|
-
visited.add(configPath);
|
|
2493
|
-
const config = readJsonWithComments(configPath);
|
|
2494
|
-
if (!config) return null;
|
|
2495
|
-
const directory = path4.dirname(configPath);
|
|
2496
|
-
const parents = (Array.isArray(config.extends) ? config.extends : [config.extends]).filter(
|
|
2497
|
-
(parent) => typeof parent === "string" && parent.startsWith(".")
|
|
2498
|
-
);
|
|
2499
|
-
let inherited = null;
|
|
2500
|
-
for (const parent of parents) {
|
|
2501
|
-
const parentPath = path4.resolve(
|
|
2502
|
-
directory,
|
|
2503
|
-
parent.endsWith(".json") ? parent : `${parent}.json`
|
|
2504
|
-
);
|
|
2505
|
-
inherited = readTsconfigPaths(parentPath, visited) ?? inherited;
|
|
2506
|
-
}
|
|
2507
|
-
const options = config.compilerOptions ?? {};
|
|
2508
|
-
const baseUrl = typeof options.baseUrl === "string" ? path4.resolve(directory, options.baseUrl) : inherited?.baseUrl;
|
|
2509
|
-
if (options.paths && typeof options.paths === "object") {
|
|
2510
|
-
return { paths: options.paths, pathsDirectory: directory, baseUrl };
|
|
2511
|
-
}
|
|
2512
|
-
return inherited ? { ...inherited, baseUrl } : { pathsDirectory: directory, baseUrl };
|
|
2513
|
-
}
|
|
2514
|
-
function readPackageImportAliases(projectRoot) {
|
|
2515
|
-
const imports = readPackageJson(path4.join(projectRoot, "package.json"))?.imports;
|
|
2516
|
-
if (!imports || typeof imports !== "object") return [];
|
|
2517
|
-
return Object.entries(imports).flatMap(([pattern, value]) => {
|
|
2518
|
-
const target = resolveConditionalExportTarget(value);
|
|
2519
|
-
if (!pattern.startsWith("#") || !target?.startsWith("./")) return [];
|
|
2520
|
-
const wildcardIndex = pattern.indexOf("*");
|
|
2521
|
-
return [
|
|
2522
|
-
{
|
|
2523
|
-
prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
|
|
2524
|
-
suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
|
|
2525
|
-
wildcard: wildcardIndex !== -1,
|
|
2526
|
-
targets: [path4.resolve(projectRoot, target)]
|
|
2527
|
-
}
|
|
2528
|
-
];
|
|
2529
|
-
});
|
|
2530
|
-
}
|
|
2531
|
-
function readJsonWithComments(filePath) {
|
|
2532
|
-
let source;
|
|
2533
|
-
try {
|
|
2534
|
-
source = fs4.readFileSync(filePath, "utf8");
|
|
2535
|
-
} catch {
|
|
2536
|
-
return null;
|
|
2537
|
-
}
|
|
2538
|
-
let output = "";
|
|
2539
|
-
let inString = false;
|
|
2540
|
-
for (let index = 0; index < source.length; index++) {
|
|
2541
|
-
const char = source[index];
|
|
2542
|
-
if (inString) {
|
|
2543
|
-
output += char;
|
|
2544
|
-
if (char === "\\") output += source[++index] ?? "";
|
|
2545
|
-
else if (char === '"') inString = false;
|
|
2546
|
-
continue;
|
|
2547
|
-
}
|
|
2548
|
-
if (char === '"') {
|
|
2549
|
-
inString = true;
|
|
2550
|
-
output += char;
|
|
2551
|
-
} else if (char === "/" && source[index + 1] === "/") {
|
|
2552
|
-
while (index < source.length && source[index] !== "\n") index++;
|
|
2553
|
-
output += "\n";
|
|
2554
|
-
} else if (char === "/" && source[index + 1] === "*") {
|
|
2555
|
-
const end = source.indexOf("*/", index + 2);
|
|
2556
|
-
index = end === -1 ? source.length : end + 1;
|
|
2557
|
-
} else {
|
|
2558
|
-
output += char;
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
try {
|
|
2562
|
-
return JSON.parse(output.replace(/,(\s*[}\]])/g, "$1"));
|
|
2563
|
-
} catch {
|
|
2564
|
-
return null;
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
function resolveImportedModuleSourcePath(importerPath, specifier, root) {
|
|
2568
|
-
if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
|
|
2569
|
-
return resolvePackageModuleSourcePath(importerPath, specifier, root);
|
|
2570
|
-
}
|
|
2571
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2572
|
-
const basePath = specifier.startsWith(".") ? path4.resolve(path4.dirname(importerPath), specifier) : root ? path4.resolve(root, specifier.replace(/^\/+/, "")) : path4.resolve(specifier);
|
|
2573
|
-
candidates.add(basePath);
|
|
2574
|
-
return resolveSourceCandidate(candidates);
|
|
2575
|
-
}
|
|
2576
|
-
function resolvePackageModuleSourcePath(importerPath, specifier, root) {
|
|
2577
|
-
const packageParts = specifier.split("/");
|
|
2578
|
-
const packageName = specifier.startsWith("@") ? packageParts.slice(0, 2).join("/") : packageParts[0];
|
|
2579
|
-
const packageSubpath = packageParts.slice(packageName.startsWith("@") ? 2 : 1).join("/");
|
|
2580
|
-
const packageDirectory = findPackageDirectory2(importerPath, packageName, root);
|
|
2581
|
-
if (!packageDirectory) return null;
|
|
2582
|
-
const packageJsonPath = path4.join(packageDirectory, "package.json");
|
|
2583
|
-
const packageJson = readPackageJson(packageJsonPath);
|
|
2584
|
-
const exportKey = packageSubpath ? `./${packageSubpath}` : ".";
|
|
2585
|
-
const exportTarget = resolvePackageExport(packageJson?.exports, exportKey);
|
|
2586
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2587
|
-
if (exportTarget?.startsWith("./")) {
|
|
2588
|
-
candidates.add(path4.resolve(packageDirectory, exportTarget));
|
|
2589
|
-
}
|
|
2590
|
-
if (packageSubpath) {
|
|
2591
|
-
candidates.add(path4.join(packageDirectory, packageSubpath));
|
|
2592
|
-
} else {
|
|
2593
|
-
for (const entry of [packageJson?.browser, packageJson?.module, packageJson?.main]) {
|
|
2594
|
-
if (typeof entry === "string") candidates.add(path4.resolve(packageDirectory, entry));
|
|
2595
|
-
}
|
|
2596
|
-
candidates.add(path4.join(packageDirectory, "index"));
|
|
2597
|
-
}
|
|
2598
|
-
return resolveSourceCandidate(candidates);
|
|
2599
|
-
}
|
|
2600
|
-
function findPackageDirectory2(importerPath, packageName, root) {
|
|
2601
|
-
const searchRoots = /* @__PURE__ */ new Set();
|
|
2602
|
-
let current = path4.dirname(importerPath);
|
|
2603
|
-
while (true) {
|
|
2604
|
-
searchRoots.add(current);
|
|
2605
|
-
const parent = path4.dirname(current);
|
|
2606
|
-
if (parent === current) break;
|
|
2607
|
-
current = parent;
|
|
2608
|
-
}
|
|
2609
|
-
if (root) {
|
|
2610
|
-
current = path4.resolve(root);
|
|
2611
|
-
while (true) {
|
|
2612
|
-
searchRoots.add(current);
|
|
2613
|
-
const parent = path4.dirname(current);
|
|
2614
|
-
if (parent === current) break;
|
|
2615
|
-
current = parent;
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
for (const searchRoot of searchRoots) {
|
|
2619
|
-
const packageDirectory = path4.join(searchRoot, "node_modules", packageName);
|
|
2620
|
-
if (fs4.existsSync(path4.join(packageDirectory, "package.json"))) {
|
|
2621
|
-
return packageDirectory;
|
|
2622
|
-
}
|
|
2623
|
-
}
|
|
2624
|
-
return null;
|
|
2625
|
-
}
|
|
2626
|
-
function readPackageJson(packageJsonPath) {
|
|
2627
|
-
try {
|
|
2628
|
-
return JSON.parse(fs4.readFileSync(packageJsonPath, "utf8"));
|
|
2629
|
-
} catch {
|
|
2630
|
-
return null;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
function resolvePackageExport(exportsField, exportKey) {
|
|
2634
|
-
if (typeof exportsField === "string") {
|
|
2635
|
-
return exportKey === "." ? exportsField : null;
|
|
2636
|
-
}
|
|
2637
|
-
if (Array.isArray(exportsField)) {
|
|
2638
|
-
for (const candidate of exportsField) {
|
|
2639
|
-
const resolved = resolvePackageExport(candidate, exportKey);
|
|
2640
|
-
if (resolved) return resolved;
|
|
2641
|
-
}
|
|
2642
|
-
return null;
|
|
2643
|
-
}
|
|
2644
|
-
if (!exportsField || typeof exportsField !== "object") return null;
|
|
2645
|
-
const entries = Object.entries(exportsField);
|
|
2646
|
-
const subpathExports = entries.some(([key]) => key.startsWith("."));
|
|
2647
|
-
if (subpathExports) {
|
|
2648
|
-
const exact = exportsField[exportKey];
|
|
2649
|
-
if (exact !== void 0) return resolveConditionalExportTarget(exact);
|
|
2650
|
-
for (const [key, value] of entries) {
|
|
2651
|
-
const wildcardIndex = key.indexOf("*");
|
|
2652
|
-
if (wildcardIndex === -1) continue;
|
|
2653
|
-
const prefix = key.slice(0, wildcardIndex);
|
|
2654
|
-
const suffix = key.slice(wildcardIndex + 1);
|
|
2655
|
-
if (!exportKey.startsWith(prefix) || !exportKey.endsWith(suffix)) continue;
|
|
2656
|
-
const wildcard = exportKey.slice(prefix.length, exportKey.length - suffix.length);
|
|
2657
|
-
const target = resolveConditionalExportTarget(value);
|
|
2658
|
-
return target?.replace("*", wildcard) ?? null;
|
|
2659
|
-
}
|
|
2660
|
-
return null;
|
|
2661
|
-
}
|
|
2662
|
-
return exportKey === "." ? resolveConditionalExportTarget(exportsField) : null;
|
|
2663
|
-
}
|
|
2664
|
-
function resolveConditionalExportTarget(value) {
|
|
2665
|
-
if (typeof value === "string") return value;
|
|
2666
|
-
if (Array.isArray(value)) {
|
|
2667
|
-
for (const candidate of value) {
|
|
2668
|
-
const resolved = resolveConditionalExportTarget(candidate);
|
|
2669
|
-
if (resolved) return resolved;
|
|
2670
|
-
}
|
|
2671
|
-
return null;
|
|
2672
|
-
}
|
|
2673
|
-
if (!value || typeof value !== "object") return null;
|
|
2674
|
-
const conditions = value;
|
|
2675
|
-
for (const condition of ["browser", "import", "module", "node", "default", "require"]) {
|
|
2676
|
-
if (conditions[condition] === void 0) continue;
|
|
2677
|
-
const resolved = resolveConditionalExportTarget(conditions[condition]);
|
|
2678
|
-
if (resolved) return resolved;
|
|
2679
|
-
}
|
|
2680
|
-
return null;
|
|
2681
|
-
}
|
|
2682
|
-
function resolveSourceCandidate(candidates) {
|
|
2683
|
-
for (const candidate of candidates) {
|
|
2684
|
-
const paths = [candidate];
|
|
2685
|
-
for (const extension of RESOLVABLE_SOURCE_EXTENSIONS) {
|
|
2686
|
-
paths.push(`${candidate}${extension}`, path4.join(candidate, `index${extension}`));
|
|
2687
|
-
}
|
|
2688
|
-
for (const sourcePath of paths) {
|
|
2689
|
-
try {
|
|
2690
|
-
if (fs4.statSync(sourcePath).isFile()) return sourcePath;
|
|
2691
|
-
} catch {
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
return null;
|
|
2696
|
-
}
|
|
2697
|
-
function isFarmPackageClientBoundary(importerPath, specifier, root) {
|
|
2698
|
-
const imported = resolveImportedModule(importerPath, specifier, root);
|
|
2699
|
-
if (imported.local || !imported.path) return false;
|
|
2700
|
-
return inspectPackageClientBoundary(imported.path, root, /* @__PURE__ */ new Set()).shouldHydrate;
|
|
2701
|
-
}
|
|
2702
|
-
var CLIENT_PACKAGE_SCAN_EXTENSIONS = /\.(?:[cm]?[jt]sx?)$/;
|
|
2703
|
-
var CLIENT_PACKAGE_SCAN_SKIP = /* @__PURE__ */ new Set(["node_modules", ".farm", ".git", "dist", ".output"]);
|
|
2704
|
-
function bareSpecifierPackage(specifier) {
|
|
2705
|
-
if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("#") || specifier.startsWith("node:") || specifier.startsWith("virtual:") || specifier.includes("\0") || // A package's stylesheet or asset is not a module for the optimizer.
|
|
2706
|
-
/\.(?:css|scss|sass|less|styl|svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|json|wasm)$/.test(
|
|
2707
|
-
specifier
|
|
2708
|
-
)) {
|
|
2709
|
-
return null;
|
|
2710
|
-
}
|
|
2711
|
-
return specifier;
|
|
2712
|
-
}
|
|
2713
|
-
function collectFarmClientPackageImports(directory, root) {
|
|
2714
|
-
const found = /* @__PURE__ */ new Set();
|
|
2715
|
-
const walk2 = (current) => {
|
|
2716
|
-
let entries;
|
|
2717
|
-
try {
|
|
2718
|
-
entries = fs4.readdirSync(current, { withFileTypes: true });
|
|
2719
|
-
} catch {
|
|
2720
|
-
return;
|
|
2721
|
-
}
|
|
2722
|
-
for (const entry of entries) {
|
|
2723
|
-
if (entry.name.startsWith(".") && entry.isDirectory()) continue;
|
|
2724
|
-
const file = path4.join(current, entry.name);
|
|
2725
|
-
if (entry.isDirectory()) {
|
|
2726
|
-
if (!CLIENT_PACKAGE_SCAN_SKIP.has(entry.name)) walk2(file);
|
|
2727
|
-
continue;
|
|
2728
|
-
}
|
|
2729
|
-
if (!CLIENT_PACKAGE_SCAN_EXTENSIONS.test(entry.name) || entry.name.endsWith(".d.ts"))
|
|
2730
|
-
continue;
|
|
2731
|
-
const content = readIfExists(file);
|
|
2732
|
-
if (!content) continue;
|
|
2733
|
-
const client = hasUseClientDirective(content);
|
|
2734
|
-
for (const specifier of new Set(getImportSpecifiers(content))) {
|
|
2735
|
-
const name = bareSpecifierPackage(specifier);
|
|
2736
|
-
if (!name || found.has(name)) continue;
|
|
2737
|
-
if (client || isFarmPackageClientBoundary(file, name, root)) found.add(name);
|
|
2738
|
-
}
|
|
2739
|
-
}
|
|
2740
|
-
};
|
|
2741
|
-
walk2(directory);
|
|
2742
|
-
return [...found].sort();
|
|
2743
|
-
}
|
|
2744
|
-
var clientReachableModules = /* @__PURE__ */ new Map();
|
|
2745
|
-
function invalidateFarmClientReachableModules() {
|
|
2746
|
-
clientReachableModules.clear();
|
|
2747
|
-
}
|
|
2748
|
-
function getFarmClientReachableModules(directory, root) {
|
|
2749
|
-
const key = `${path4.resolve(root)}\0${path4.resolve(directory)}`;
|
|
2750
|
-
const cached = clientReachableModules.get(key);
|
|
2751
|
-
if (cached) return cached;
|
|
2752
|
-
const reachable = /* @__PURE__ */ new Set();
|
|
2753
|
-
const queue = [];
|
|
2754
|
-
const walk2 = (current) => {
|
|
2755
|
-
let entries;
|
|
2756
|
-
try {
|
|
2757
|
-
entries = fs4.readdirSync(current, { withFileTypes: true });
|
|
2758
|
-
} catch {
|
|
2759
|
-
return;
|
|
2760
|
-
}
|
|
2761
|
-
for (const entry of entries) {
|
|
2762
|
-
const file = path4.join(current, entry.name);
|
|
2763
|
-
if (entry.isDirectory()) {
|
|
2764
|
-
if (!entry.name.startsWith(".") && !CLIENT_PACKAGE_SCAN_SKIP.has(entry.name)) walk2(file);
|
|
2765
|
-
} else if (CLIENT_PACKAGE_SCAN_EXTENSIONS.test(entry.name) && !entry.name.endsWith(".d.ts") && hasUseClientDirective(readIfExists(file))) {
|
|
2766
|
-
queue.push(file);
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
};
|
|
2770
|
-
walk2(directory);
|
|
2771
|
-
while (queue.length > 0) {
|
|
2772
|
-
const file = path4.resolve(queue.pop());
|
|
2773
|
-
if (reachable.has(file)) continue;
|
|
2774
|
-
reachable.add(file);
|
|
2775
|
-
for (const specifier of getImportSpecifiers(readIfExists(file))) {
|
|
2776
|
-
const imported = resolveImportedModule(file, specifier, root);
|
|
2777
|
-
if (imported.local && imported.path && !reachable.has(path4.resolve(imported.path))) {
|
|
2778
|
-
queue.push(imported.path);
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
clientReachableModules.set(key, reachable);
|
|
2783
|
-
return reachable;
|
|
2784
|
-
}
|
|
2785
|
-
function resolveFarmClientOptimizeDeps(directory, root) {
|
|
2786
|
-
const importer = path4.join(path4.resolve(root), "package.json");
|
|
2787
|
-
const include = /* @__PURE__ */ new Set();
|
|
2788
|
-
const exclude = /* @__PURE__ */ new Set();
|
|
2789
|
-
for (const specifier of collectFarmClientPackageImports(directory, root)) {
|
|
2790
|
-
const manifest = findFarmPackageManifest(importer, specifier);
|
|
2791
|
-
if (manifest && farmReactServerBuildReachesClientModules(importer, manifest.name)) {
|
|
2792
|
-
exclude.add(manifest.name);
|
|
2793
|
-
for (const dependency of manifest.dependencies) {
|
|
2794
|
-
include.add(`${manifest.name} > ${dependency}`);
|
|
2795
|
-
}
|
|
2796
|
-
} else {
|
|
2797
|
-
include.add(specifier);
|
|
2798
|
-
}
|
|
2799
|
-
}
|
|
2800
|
-
for (const name of exclude) {
|
|
2801
|
-
for (const entry of include) {
|
|
2802
|
-
if (entry === name || entry.startsWith(`${name}/`)) include.delete(entry);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
return { include: [...include].sort(), exclude: [...exclude].sort() };
|
|
2806
|
-
}
|
|
119
|
+
assertFarmRendererStreamingRuntime,
|
|
120
|
+
getFarmRendererCapabilities,
|
|
121
|
+
getFarmRendererComponentExtensions,
|
|
122
|
+
getFarmRendererStreamingCapabilitiesForRuntime,
|
|
123
|
+
isReactRenderer,
|
|
124
|
+
readFarmRendererWebStream,
|
|
125
|
+
resolveFarmComponentExtensions,
|
|
126
|
+
resolveFarmRenderer,
|
|
127
|
+
resolveFarmRendererAppSetup,
|
|
128
|
+
resolveFarmRendererModule
|
|
129
|
+
} from "./chunk-ES2LD2YD.mjs";
|
|
130
|
+
import {
|
|
131
|
+
resolveFarmImageConfig
|
|
132
|
+
} from "./chunk-2NGZFOKG.mjs";
|
|
133
|
+
import {
|
|
134
|
+
createFarmMarkdownRouteModuleFromFile,
|
|
135
|
+
loadFarmMdxComponents
|
|
136
|
+
} from "./chunk-FIR62CR3.mjs";
|
|
137
|
+
import {
|
|
138
|
+
isFarmMarkdownPageFile
|
|
139
|
+
} from "./chunk-RVGSVQWT.mjs";
|
|
140
|
+
import {
|
|
141
|
+
resolveFarmMdxComponentsModulePath,
|
|
142
|
+
resolveMdxConfig
|
|
143
|
+
} from "./chunk-UIJOLBUL.mjs";
|
|
144
|
+
import {
|
|
145
|
+
FARM_MARKDOWN_CONTENT_TYPE,
|
|
146
|
+
FARM_MARKDOWN_PAGE_CHECK_HEADER,
|
|
147
|
+
_isFarmMarkdownPageCheck,
|
|
148
|
+
createFarmMarkdownErrorBody,
|
|
149
|
+
farmRequestWantsMarkdown,
|
|
150
|
+
getFarmMarkdownAlternatePath,
|
|
151
|
+
resolveMarkdownConfig
|
|
152
|
+
} from "./chunk-K7OZAVOI.mjs";
|
|
153
|
+
import {
|
|
154
|
+
resolveWorkflowsConfig
|
|
155
|
+
} from "./chunk-TZVUF5JJ.mjs";
|
|
156
|
+
import {
|
|
157
|
+
resolveCronConfig
|
|
158
|
+
} from "./chunk-DQF3QLOH.mjs";
|
|
159
|
+
import {
|
|
160
|
+
resolveServerActionsConfig
|
|
161
|
+
} from "./chunk-E46NXBNJ.mjs";
|
|
162
|
+
import {
|
|
163
|
+
_setDefaultFarmThemeConfig,
|
|
164
|
+
getTheme
|
|
165
|
+
} from "./chunk-EMDGXYUD.mjs";
|
|
166
|
+
import {
|
|
167
|
+
resolveFarmThemeConfig
|
|
168
|
+
} from "./chunk-YWPNIYUP.mjs";
|
|
169
|
+
import {
|
|
170
|
+
initStorage
|
|
171
|
+
} from "./chunk-TJVUTGED.mjs";
|
|
172
|
+
import {
|
|
173
|
+
resolveFarmRouteContext,
|
|
174
|
+
withFarmRouteContext
|
|
175
|
+
} from "./chunk-BMQAPZXD.mjs";
|
|
176
|
+
import {
|
|
177
|
+
getIntegrationProviders,
|
|
178
|
+
getRegisteredIntegrationAPIManifest,
|
|
179
|
+
isFarmIntegrationProviderComponentReference
|
|
180
|
+
} from "./chunk-TGULJSHD.mjs";
|
|
181
|
+
import {
|
|
182
|
+
createRouteSlotContainerId,
|
|
183
|
+
parseRouteSlotFile
|
|
184
|
+
} from "./chunk-K3RU5MOR.mjs";
|
|
185
|
+
import {
|
|
186
|
+
_clearCurrentMiddlewareContext,
|
|
187
|
+
_clearCurrentMiddlewareData,
|
|
188
|
+
_runWithMiddlewareContext,
|
|
189
|
+
_runWithMiddlewareData
|
|
190
|
+
} from "./chunk-6ZFRWRHO.mjs";
|
|
191
|
+
import {
|
|
192
|
+
findProgrammaticRouteFiles,
|
|
193
|
+
loadProgrammaticRouteManifests
|
|
194
|
+
} from "./chunk-FSXSQQTV.mjs";
|
|
195
|
+
import {
|
|
196
|
+
_runWithFarmI18nRequest,
|
|
197
|
+
_setDefaultFarmI18nRuntime,
|
|
198
|
+
createFarmI18nRuntime,
|
|
199
|
+
getFarmI18nClientSnapshot
|
|
200
|
+
} from "./chunk-CV6MFQ4Y.mjs";
|
|
201
|
+
import {
|
|
202
|
+
formatOptionalPeerInstallHint,
|
|
203
|
+
isOptionalPeerInstalled
|
|
204
|
+
} from "./chunk-NR63PD3P.mjs";
|
|
205
|
+
import {
|
|
206
|
+
createProgrammaticRouteModuleId,
|
|
207
|
+
getProgrammaticRouteSearchClientOptions,
|
|
208
|
+
normalizeProgrammaticRoutePath,
|
|
209
|
+
parseProgrammaticRoutePath,
|
|
210
|
+
trackProgrammaticRouteSources
|
|
211
|
+
} from "./chunk-6YFC3ZFX.mjs";
|
|
212
|
+
import {
|
|
213
|
+
getFarmRouteRuntimeConfig,
|
|
214
|
+
mergeFarmRouteRuntimeConfigs,
|
|
215
|
+
normalizeFarmRouteRuntimeConfig,
|
|
216
|
+
resolveFarmRouteRuleRuntimeConfig,
|
|
217
|
+
resolveFarmRouteRuntimeConfig
|
|
218
|
+
} from "./chunk-EVMXPJCB.mjs";
|
|
219
|
+
import {
|
|
220
|
+
configureFarmCache,
|
|
221
|
+
getFarmDataCache,
|
|
222
|
+
normalizeRevalidatePath
|
|
223
|
+
} from "./chunk-RLEALQEN.mjs";
|
|
224
|
+
import {
|
|
225
|
+
toFileModuleUrl
|
|
226
|
+
} from "./chunk-VHIXGZYH.mjs";
|
|
227
|
+
import {
|
|
228
|
+
loadFarmDevModule
|
|
229
|
+
} from "./chunk-TUOO6IK3.mjs";
|
|
230
|
+
import {
|
|
231
|
+
resolveFarmI18nConfig
|
|
232
|
+
} from "./chunk-MU5V7XHL.mjs";
|
|
233
|
+
import {
|
|
234
|
+
fileExists,
|
|
235
|
+
globFiles,
|
|
236
|
+
logger,
|
|
237
|
+
matchRoute,
|
|
238
|
+
matchRouteParts,
|
|
239
|
+
matchRoutePrefix,
|
|
240
|
+
matchRoutePrefixParts,
|
|
241
|
+
parseRoutePath,
|
|
242
|
+
resolveAppPath,
|
|
243
|
+
splitRoutePath,
|
|
244
|
+
toRootRelativeUrlPath,
|
|
245
|
+
toViteModuleId
|
|
246
|
+
} from "./chunk-JSDV2NUN.mjs";
|
|
247
|
+
import {
|
|
248
|
+
createFarmSearchParams,
|
|
249
|
+
searchParamsToObject
|
|
250
|
+
} from "./chunk-H3ASZDT7.mjs";
|
|
251
|
+
import {
|
|
252
|
+
configureFarmObservability,
|
|
253
|
+
emitFarmEvent
|
|
254
|
+
} from "./chunk-2DA7CLY7.mjs";
|
|
255
|
+
import {
|
|
256
|
+
sendWebResponse
|
|
257
|
+
} from "./chunk-CO6UYM2D.mjs";
|
|
258
|
+
import {
|
|
259
|
+
resolveFarmAPIServerBasePath
|
|
260
|
+
} from "./chunk-2I6PUKWJ.mjs";
|
|
261
|
+
import {
|
|
262
|
+
matchesFarmIfNoneMatch,
|
|
263
|
+
resolveFarmServerConfig
|
|
264
|
+
} from "./chunk-QDWMCFTH.mjs";
|
|
265
|
+
import {
|
|
266
|
+
getRequestContextSnapshot
|
|
267
|
+
} from "./chunk-D2LCAV6L.mjs";
|
|
268
|
+
import {
|
|
269
|
+
FARM_VERSION
|
|
270
|
+
} from "./chunk-72JSHQQQ.mjs";
|
|
271
|
+
import {
|
|
272
|
+
resolveFarmTrailingSlashRedirect,
|
|
273
|
+
setFarmTrailingSlashPreference
|
|
274
|
+
} from "./chunk-RFKTJTWZ.mjs";
|
|
275
|
+
import {
|
|
276
|
+
normalizeFarmAPIConfig
|
|
277
|
+
} from "./chunk-W6QLRQ3V.mjs";
|
|
278
|
+
import {
|
|
279
|
+
createFarmLocaleCookie,
|
|
280
|
+
getFarmLocaleVaryHeaders
|
|
281
|
+
} from "./chunk-K76CBYQM.mjs";
|
|
282
|
+
import {
|
|
283
|
+
addMetadataImageReference,
|
|
284
|
+
addMetadataMarkdownAlternate,
|
|
285
|
+
mergeMetadata,
|
|
286
|
+
mergeModuleViewport,
|
|
287
|
+
renderMetadataHead,
|
|
288
|
+
renderViewportHead,
|
|
289
|
+
resolveFarmNotFoundMetadata
|
|
290
|
+
} from "./chunk-S6O2L47H.mjs";
|
|
291
|
+
import {
|
|
292
|
+
FARM_DEPLOYMENT_ID_HEADER,
|
|
293
|
+
createFarmDeploymentCookie
|
|
294
|
+
} from "./chunk-UAQD67HM.mjs";
|
|
295
|
+
import {
|
|
296
|
+
prepareDeferredData,
|
|
297
|
+
snapshotDeferredData
|
|
298
|
+
} from "./chunk-K5EW7GUU.mjs";
|
|
299
|
+
import {
|
|
300
|
+
createFarmCacheKey
|
|
301
|
+
} from "./chunk-GLOICKDO.mjs";
|
|
302
|
+
import {
|
|
303
|
+
appendFarmRedirectQuery
|
|
304
|
+
} from "./chunk-XQ4DPO4G.mjs";
|
|
305
|
+
import {
|
|
306
|
+
getFarmRedirectError,
|
|
307
|
+
isFarmNotFoundError,
|
|
308
|
+
isFarmRedirectError
|
|
309
|
+
} from "./chunk-JNYFXL7X.mjs";
|
|
310
|
+
import {
|
|
311
|
+
_getRequestReadCount,
|
|
312
|
+
_runWithCurrentRequest,
|
|
313
|
+
_runWithFarmCspNonce,
|
|
314
|
+
createWebRequestFromFarmRequest,
|
|
315
|
+
getCurrentRequestOrNull,
|
|
316
|
+
resolveFarmRequestURL
|
|
317
|
+
} from "./chunk-6HRAK7I5.mjs";
|
|
318
|
+
import {
|
|
319
|
+
_peekCurrentRequest,
|
|
320
|
+
_resolveCurrentCspNonce
|
|
321
|
+
} from "./chunk-VIXTAVEA.mjs";
|
|
322
|
+
import {
|
|
323
|
+
localizeFarmHref,
|
|
324
|
+
localizeFarmPathname,
|
|
325
|
+
resolveFarmLocalePath,
|
|
326
|
+
stripFarmLocaleFromPathname
|
|
327
|
+
} from "./chunk-7S7AAK2D.mjs";
|
|
328
|
+
import {
|
|
329
|
+
applyFarmBasePath,
|
|
330
|
+
normalizeFarmConfigBasePath,
|
|
331
|
+
setFarmBasePath,
|
|
332
|
+
stripFarmBasePath
|
|
333
|
+
} from "./chunk-SF3JB56B.mjs";
|
|
334
|
+
import {
|
|
335
|
+
AmbiguousRouteError,
|
|
336
|
+
assertUniqueRouteParameters,
|
|
337
|
+
compareRouteSpecificity,
|
|
338
|
+
getRoutePatternShape
|
|
339
|
+
} from "./chunk-AYP2YFVN.mjs";
|
|
2807
340
|
|
|
2808
341
|
// src/routing/route-manager.ts
|
|
2809
342
|
import { realpathSync } from "fs";
|
|
2810
|
-
import
|
|
343
|
+
import path2 from "path";
|
|
2811
344
|
|
|
2812
345
|
// src/static-metadata-image.ts
|
|
2813
346
|
import { createHash } from "crypto";
|
|
2814
347
|
import { readFile } from "fs/promises";
|
|
2815
|
-
import
|
|
348
|
+
import path from "path";
|
|
2816
349
|
import { imageSize } from "image-size";
|
|
2817
350
|
var STATIC_METADATA_IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"];
|
|
2818
351
|
var CONTENT_TYPES = {
|
|
@@ -2853,13 +386,13 @@ async function inspectStaticMetadataImage(filePath) {
|
|
|
2853
386
|
};
|
|
2854
387
|
}
|
|
2855
388
|
function getStaticMetadataImageAltPath(filePath) {
|
|
2856
|
-
return
|
|
2857
|
-
|
|
2858
|
-
`${
|
|
389
|
+
return path.join(
|
|
390
|
+
path.dirname(filePath),
|
|
391
|
+
`${path.basename(filePath, path.extname(filePath))}.alt.txt`
|
|
2859
392
|
);
|
|
2860
393
|
}
|
|
2861
394
|
function getStaticMetadataImageExtension(filePath) {
|
|
2862
|
-
const extension =
|
|
395
|
+
const extension = path.extname(filePath).slice(1).toLowerCase();
|
|
2863
396
|
return STATIC_METADATA_IMAGE_EXTENSIONS.includes(extension) ? extension : null;
|
|
2864
397
|
}
|
|
2865
398
|
async function readAltText(filePath) {
|
|
@@ -3187,14 +720,14 @@ var RouteManager = class {
|
|
|
3187
720
|
* Requests still fetch route data, but never inspect component source.
|
|
3188
721
|
*/
|
|
3189
722
|
generateClientManifest(projectRoot = this.config.root) {
|
|
3190
|
-
const normalizedProjectRoot =
|
|
723
|
+
const normalizedProjectRoot = path2.resolve(projectRoot);
|
|
3191
724
|
if (this.clientManifestCache?.projectRoot === normalizedProjectRoot) {
|
|
3192
725
|
return this.clientManifestCache.manifest;
|
|
3193
726
|
}
|
|
3194
727
|
const toUrlPath = (absolutePath) => {
|
|
3195
728
|
const rootRelative = toRootRelativeUrlPath(absolutePath, normalizedProjectRoot);
|
|
3196
729
|
if (rootRelative !== void 0) return rootRelative;
|
|
3197
|
-
if (
|
|
730
|
+
if (path2.isAbsolute(absolutePath)) {
|
|
3198
731
|
const normalized = absolutePath.replace(/\\/g, "/");
|
|
3199
732
|
return normalized.startsWith("/") ? `/@fs${normalized}` : `/@fs/${normalized}`;
|
|
3200
733
|
}
|
|
@@ -3374,7 +907,7 @@ var RouteManager = class {
|
|
|
3374
907
|
for (const { metadata } of [...layoutEntries, ...routeEntries]) {
|
|
3375
908
|
if (!metadata.hasIsolatedClientBoundaries && !metadata.serverTreeLayout) continue;
|
|
3376
909
|
for (const boundary of metadata.isolatedBoundaries) {
|
|
3377
|
-
isolatedClientBoundaryModules.add(
|
|
910
|
+
isolatedClientBoundaryModules.add(path2.resolve(boundary.modulePath));
|
|
3378
911
|
}
|
|
3379
912
|
}
|
|
3380
913
|
const islandsErrors = [
|
|
@@ -3425,7 +958,7 @@ var RouteManager = class {
|
|
|
3425
958
|
}
|
|
3426
959
|
/** @internal Client modules selected by the compiled hydration ownership plan. */
|
|
3427
960
|
getIsolatedClientBoundaryModules(projectRoot = this.config.root) {
|
|
3428
|
-
const normalizedProjectRoot =
|
|
961
|
+
const normalizedProjectRoot = path2.resolve(projectRoot);
|
|
3429
962
|
this.generateClientManifest(normalizedProjectRoot);
|
|
3430
963
|
return this.clientManifestCache?.isolatedClientBoundaryModules ?? /* @__PURE__ */ new Set();
|
|
3431
964
|
}
|
|
@@ -3434,7 +967,7 @@ var RouteManager = class {
|
|
|
3434
967
|
* such a page whole would ship its server code to the browser, so it stays static instead.
|
|
3435
968
|
*/
|
|
3436
969
|
getIslandsErrors(projectRoot = this.config.root) {
|
|
3437
|
-
this.generateClientManifest(
|
|
970
|
+
this.generateClientManifest(path2.resolve(projectRoot));
|
|
3438
971
|
return this.clientManifestCache?.islandsErrors ?? [];
|
|
3439
972
|
}
|
|
3440
973
|
/**
|
|
@@ -3565,19 +1098,19 @@ var RouteManager = class {
|
|
|
3565
1098
|
const markdownFiles = group.files.filter(isFarmMarkdownPageFile);
|
|
3566
1099
|
if (componentFiles.length > 1) {
|
|
3567
1100
|
throw new Error(
|
|
3568
|
-
`Duplicate page route "${pattern}". Found ${componentFiles.map((file) =>
|
|
1101
|
+
`Duplicate page route "${pattern}". Found ${componentFiles.map((file) => path2.join(appDir, file)).join(" and ")}.`
|
|
3569
1102
|
);
|
|
3570
1103
|
}
|
|
3571
1104
|
if (markdownFiles.length > 1) {
|
|
3572
1105
|
throw new Error(
|
|
3573
|
-
`Duplicate markdown representation for page route "${pattern}". Found ${markdownFiles.map((file) =>
|
|
1106
|
+
`Duplicate markdown representation for page route "${pattern}". Found ${markdownFiles.map((file) => path2.join(appDir, file)).join(" and ")}.`
|
|
3574
1107
|
);
|
|
3575
1108
|
}
|
|
3576
1109
|
const componentFile = componentFiles[0];
|
|
3577
1110
|
const markdownFile = markdownFiles[0];
|
|
3578
1111
|
const primaryFile = componentFile || markdownFile;
|
|
3579
1112
|
if (!primaryFile) continue;
|
|
3580
|
-
const modulePath =
|
|
1113
|
+
const modulePath = path2.join(appDir, primaryFile);
|
|
3581
1114
|
const existing = this.routes.get(pattern);
|
|
3582
1115
|
if (existing?.sourceRoot === source.root) {
|
|
3583
1116
|
throw new Error(
|
|
@@ -3588,7 +1121,7 @@ var RouteManager = class {
|
|
|
3588
1121
|
route: group.route,
|
|
3589
1122
|
modulePath,
|
|
3590
1123
|
...markdownFile ? {
|
|
3591
|
-
markdownSourcePath:
|
|
1124
|
+
markdownSourcePath: path2.join(appDir, markdownFile)
|
|
3592
1125
|
} : {},
|
|
3593
1126
|
pattern,
|
|
3594
1127
|
...getPageDirectoryField(group.route, pattern),
|
|
@@ -3603,7 +1136,7 @@ var RouteManager = class {
|
|
|
3603
1136
|
]) {
|
|
3604
1137
|
for (const file of files) {
|
|
3605
1138
|
const route = parseRoutePath(file);
|
|
3606
|
-
const modulePath =
|
|
1139
|
+
const modulePath = path2.join(appDir, file);
|
|
3607
1140
|
const pattern = createRouteDirectoryPattern(route);
|
|
3608
1141
|
const existing = target.get(pattern);
|
|
3609
1142
|
if (existing?.sourceRoot === source.root) {
|
|
@@ -3623,7 +1156,7 @@ var RouteManager = class {
|
|
|
3623
1156
|
for (const file of [...pageFiles, ...slotDefaultFiles]) {
|
|
3624
1157
|
const slot = parseRouteSlotFile(file);
|
|
3625
1158
|
if (!slot) continue;
|
|
3626
|
-
const modulePath =
|
|
1159
|
+
const modulePath = path2.join(appDir, file);
|
|
3627
1160
|
const pattern = this.createRoutePattern(slot.route);
|
|
3628
1161
|
const ownerPattern = this.createRoutePattern(slot.ownerRoute);
|
|
3629
1162
|
const ownerDirectory = createRouteDirectoryPattern(slot.ownerRoute);
|
|
@@ -3649,11 +1182,11 @@ var RouteManager = class {
|
|
|
3649
1182
|
});
|
|
3650
1183
|
}
|
|
3651
1184
|
for (const file of metadataImageFiles) {
|
|
3652
|
-
const fileBase =
|
|
1185
|
+
const fileBase = path2.basename(file, path2.extname(file));
|
|
3653
1186
|
const kind = fileBase === "twitter-image" ? "twitter" : "opengraph";
|
|
3654
1187
|
const fileName = kind === "twitter" ? "twitter-image" : "opengraph-image";
|
|
3655
1188
|
const route = parseRoutePath(file);
|
|
3656
|
-
const modulePath =
|
|
1189
|
+
const modulePath = path2.join(appDir, file);
|
|
3657
1190
|
const pattern = this.createRoutePattern(route);
|
|
3658
1191
|
const key = `${kind}:${pattern}`;
|
|
3659
1192
|
const existing = this.metadataImages.get(key);
|
|
@@ -3678,11 +1211,11 @@ var RouteManager = class {
|
|
|
3678
1211
|
}
|
|
3679
1212
|
for (const file of metadataRouteFiles) {
|
|
3680
1213
|
const descriptor = getApplicationMetadataRouteDescriptor(
|
|
3681
|
-
|
|
1214
|
+
path2.basename(file, path2.extname(file))
|
|
3682
1215
|
);
|
|
3683
1216
|
if (!descriptor) continue;
|
|
3684
1217
|
const route = parseRoutePath(file);
|
|
3685
|
-
const modulePath =
|
|
1218
|
+
const modulePath = path2.join(appDir, file);
|
|
3686
1219
|
const pattern = this.createRoutePattern(route);
|
|
3687
1220
|
const key = `${descriptor.kind}:${pattern}`;
|
|
3688
1221
|
const existing = this.metadataRoutes.get(key);
|
|
@@ -4093,12 +1626,12 @@ function toRealPath(filePath) {
|
|
|
4093
1626
|
}
|
|
4094
1627
|
|
|
4095
1628
|
// src/server/dev-styles.ts
|
|
4096
|
-
import * as
|
|
4097
|
-
import * as
|
|
1629
|
+
import * as fs from "fs";
|
|
1630
|
+
import * as path3 from "path";
|
|
4098
1631
|
function resolveDevGlobalStylesheetHref(root, srcDir = "src") {
|
|
4099
|
-
const file =
|
|
4100
|
-
if (!
|
|
4101
|
-
return `/${
|
|
1632
|
+
const file = path3.join(root, srcDir, "app", "globals.css");
|
|
1633
|
+
if (!fs.existsSync(file)) return void 0;
|
|
1634
|
+
return `/${path3.relative(root, file).split(path3.sep).join("/")}`;
|
|
4102
1635
|
}
|
|
4103
1636
|
var STYLE_EXTENSIONS = /\.(css|scss|sass|less|styl|stylus)(?:$|\?)/;
|
|
4104
1637
|
var ALREADY_LINKED = "/src/app/globals.css";
|
|
@@ -4122,7 +1655,7 @@ function collectDevStylesheetUrls(modules, alreadyLinked = ALREADY_LINKED, optio
|
|
|
4122
1655
|
import { createHash as createHash2, timingSafeEqual } from "crypto";
|
|
4123
1656
|
import { existsSync as existsSync2 } from "fs";
|
|
4124
1657
|
import { readFile as readFile2 } from "fs/promises";
|
|
4125
|
-
import
|
|
1658
|
+
import path4 from "path";
|
|
4126
1659
|
import { createRequire } from "module";
|
|
4127
1660
|
import { pathToFileURL } from "url";
|
|
4128
1661
|
var FONT_IMPORTS = /* @__PURE__ */ new Set(["@farm.js/core", "@farm.js/core/font"]);
|
|
@@ -4479,7 +2012,7 @@ ${FONT_SECTION_END}
|
|
|
4479
2012
|
return resource;
|
|
4480
2013
|
}
|
|
4481
2014
|
const bytes2 = await fetchRemoteFont(url, input.integrity);
|
|
4482
|
-
return this.createSelfHostedResource(bytes2, extension,
|
|
2015
|
+
return this.createSelfHostedResource(bytes2, extension, path4.basename(url.pathname));
|
|
4483
2016
|
}
|
|
4484
2017
|
if (input.source.startsWith("/")) {
|
|
4485
2018
|
return this.createPublicResource(input.moduleId, input.source);
|
|
@@ -4502,8 +2035,8 @@ ${FONT_SECTION_END}
|
|
|
4502
2035
|
}
|
|
4503
2036
|
return this.createSelfHostedResource(
|
|
4504
2037
|
bytes,
|
|
4505
|
-
|
|
4506
|
-
|
|
2038
|
+
path4.extname(resolvedPath),
|
|
2039
|
+
path4.basename(resolvedPath)
|
|
4507
2040
|
);
|
|
4508
2041
|
}
|
|
4509
2042
|
async createPublicResource(moduleId, source) {
|
|
@@ -4514,7 +2047,7 @@ ${FONT_SECTION_END}
|
|
|
4514
2047
|
);
|
|
4515
2048
|
}
|
|
4516
2049
|
const publicPath = normalizePublicFontPath(source, moduleId);
|
|
4517
|
-
const resolvedPath =
|
|
2050
|
+
const resolvedPath = path4.resolve(this.publicDir, `.${publicPath}`);
|
|
4518
2051
|
if (!isPathInside(this.publicDir, resolvedPath)) {
|
|
4519
2052
|
throw fontError(moduleId, `public font path must stay inside publicDir`);
|
|
4520
2053
|
}
|
|
@@ -4530,7 +2063,7 @@ ${FONT_SECTION_END}
|
|
|
4530
2063
|
`could not read ${JSON.stringify(source)} from publicDir: ${error.message}`
|
|
4531
2064
|
);
|
|
4532
2065
|
}
|
|
4533
|
-
const extension =
|
|
2066
|
+
const extension = path4.extname(resolvedPath).toLowerCase();
|
|
4534
2067
|
const hash = createHash2("sha256").update(bytes).digest("hex").slice(0, 12);
|
|
4535
2068
|
const resource = {
|
|
4536
2069
|
extension,
|
|
@@ -4545,7 +2078,7 @@ ${FONT_SECTION_END}
|
|
|
4545
2078
|
createSelfHostedResource(bytes, extension, fileName) {
|
|
4546
2079
|
const normalizedExtension = extension.toLowerCase();
|
|
4547
2080
|
const hash = createHash2("sha256").update(bytes).digest("hex").slice(0, 12);
|
|
4548
|
-
const baseName = sanitizeFileName(
|
|
2081
|
+
const baseName = sanitizeFileName(path4.basename(fileName, extension)) || "font";
|
|
4549
2082
|
const outputFileName = `assets/fonts/${baseName}-h${hash}${normalizedExtension}`;
|
|
4550
2083
|
const key = `${hash}${normalizedExtension}`;
|
|
4551
2084
|
const existing = this.resources.get(key);
|
|
@@ -4898,24 +2431,24 @@ function verifyIntegrity(bytes, integrity) {
|
|
|
4898
2431
|
if (!matches) throw new Error("downloaded font did not match its integrity value");
|
|
4899
2432
|
}
|
|
4900
2433
|
function resolveLocalFontPath(source, importer, root) {
|
|
4901
|
-
if (source.startsWith(".")) return
|
|
4902
|
-
if (
|
|
2434
|
+
if (source.startsWith(".")) return path4.resolve(path4.dirname(importer), source);
|
|
2435
|
+
if (path4.isAbsolute(source)) {
|
|
4903
2436
|
return source;
|
|
4904
2437
|
}
|
|
4905
2438
|
try {
|
|
4906
2439
|
return createRequire(pathToFileURL(importer)).resolve(source);
|
|
4907
2440
|
} catch {
|
|
4908
2441
|
const segments = source.replace(/\\/g, "/").split("/");
|
|
4909
|
-
if (segments.includes("..")) return
|
|
4910
|
-
let current =
|
|
4911
|
-
const filesystemRoot =
|
|
2442
|
+
if (segments.includes("..")) return path4.resolve(root, source);
|
|
2443
|
+
let current = path4.dirname(importer);
|
|
2444
|
+
const filesystemRoot = path4.parse(current).root;
|
|
4912
2445
|
while (true) {
|
|
4913
|
-
const candidate =
|
|
2446
|
+
const candidate = path4.join(current, "node_modules", ...segments);
|
|
4914
2447
|
if (existsSync2(candidate)) return candidate;
|
|
4915
2448
|
if (current === filesystemRoot) break;
|
|
4916
|
-
current =
|
|
2449
|
+
current = path4.dirname(current);
|
|
4917
2450
|
}
|
|
4918
|
-
return
|
|
2451
|
+
return path4.resolve(root, "node_modules", ...segments);
|
|
4919
2452
|
}
|
|
4920
2453
|
}
|
|
4921
2454
|
function replaceFontSection(css, section) {
|
|
@@ -4948,11 +2481,11 @@ function getGlobalMap(key) {
|
|
|
4948
2481
|
return created;
|
|
4949
2482
|
}
|
|
4950
2483
|
function normalizeRoot(root) {
|
|
4951
|
-
return
|
|
2484
|
+
return path4.resolve(root).replace(/\\/g, "/");
|
|
4952
2485
|
}
|
|
4953
2486
|
function normalizePublicDir(root, publicDir) {
|
|
4954
2487
|
if (publicDir === false || publicDir === "") return false;
|
|
4955
|
-
return
|
|
2488
|
+
return path4.resolve(root, publicDir || "public");
|
|
4956
2489
|
}
|
|
4957
2490
|
function normalizePublicFontPath(source, moduleId) {
|
|
4958
2491
|
if (source.includes("?") || source.includes("#")) {
|
|
@@ -4961,8 +2494,8 @@ function normalizePublicFontPath(source, moduleId) {
|
|
|
4961
2494
|
return `/${source.replace(/\\/g, "/").replace(/^\/+/, "")}`;
|
|
4962
2495
|
}
|
|
4963
2496
|
function isPathInside(parent, child) {
|
|
4964
|
-
const relative3 =
|
|
4965
|
-
return relative3 === "" || !relative3.startsWith("..") && !
|
|
2497
|
+
const relative3 = path4.relative(parent, child);
|
|
2498
|
+
return relative3 === "" || !relative3.startsWith("..") && !path4.isAbsolute(relative3);
|
|
4966
2499
|
}
|
|
4967
2500
|
function normalizeBasePath(value) {
|
|
4968
2501
|
if (!value || value === "/") return "/";
|
|
@@ -4972,7 +2505,7 @@ function joinBasePath(basePath, value) {
|
|
|
4972
2505
|
return basePath === "/" ? value : `${basePath.replace(/\/$/, "")}${value}`;
|
|
4973
2506
|
}
|
|
4974
2507
|
function extensionFromPath(pathname) {
|
|
4975
|
-
const extension =
|
|
2508
|
+
const extension = path4.extname(pathname).toLowerCase();
|
|
4976
2509
|
if (!FONT_EXTENSION_RE.test(extension)) {
|
|
4977
2510
|
throw new Error(`[Farm fonts] Remote font URL must end in .woff2, .woff, .ttf, or .otf`);
|
|
4978
2511
|
}
|
|
@@ -5112,7 +2645,7 @@ function fontError(id, message) {
|
|
|
5112
2645
|
}
|
|
5113
2646
|
|
|
5114
2647
|
// src/integration-provider-build.ts
|
|
5115
|
-
import
|
|
2648
|
+
import path5 from "path";
|
|
5116
2649
|
function isRendererCompiledComponent(moduleId, rendererComponentExtensions) {
|
|
5117
2650
|
const lowered = moduleId.toLowerCase();
|
|
5118
2651
|
return rendererComponentExtensions.some((extension) => lowered.endsWith(extension.toLowerCase()));
|
|
@@ -5214,14 +2747,14 @@ function generateFarmIntegrationProviderServerModules(providers, root, rendererC
|
|
|
5214
2747
|
}
|
|
5215
2748
|
function resolveProviderModule(moduleId, root) {
|
|
5216
2749
|
if (!moduleId.startsWith(".")) return moduleId;
|
|
5217
|
-
return toViteModuleId(
|
|
2750
|
+
return toViteModuleId(path5.resolve(root, moduleId), root);
|
|
5218
2751
|
}
|
|
5219
2752
|
|
|
5220
2753
|
// src/island-inference.ts
|
|
5221
|
-
import
|
|
5222
|
-
import
|
|
2754
|
+
import fs2 from "fs";
|
|
2755
|
+
import path6 from "path";
|
|
5223
2756
|
import { inferStrategy } from "@farm.js/islx/compiler";
|
|
5224
|
-
import { parseAst
|
|
2757
|
+
import { parseAst } from "rolldown/parseAst";
|
|
5225
2758
|
var PARSE_LANGS = /* @__PURE__ */ new Map([
|
|
5226
2759
|
[".tsx", "tsx"],
|
|
5227
2760
|
[".ts", "ts"],
|
|
@@ -5230,29 +2763,29 @@ var PARSE_LANGS = /* @__PURE__ */ new Map([
|
|
|
5230
2763
|
[".mjs", "js"]
|
|
5231
2764
|
]);
|
|
5232
2765
|
function parseFarmIslandSource(file, code) {
|
|
5233
|
-
const lang = PARSE_LANGS.get(
|
|
5234
|
-
if (!lang) throw new Error(`${
|
|
5235
|
-
return
|
|
2766
|
+
const lang = PARSE_LANGS.get(path6.extname(file));
|
|
2767
|
+
if (!lang) throw new Error(`${path6.basename(file)} is not a script module`);
|
|
2768
|
+
return parseAst(code, { lang });
|
|
5236
2769
|
}
|
|
5237
2770
|
function modifiedAt(file) {
|
|
5238
2771
|
try {
|
|
5239
|
-
return
|
|
2772
|
+
return fs2.statSync(file).mtimeMs;
|
|
5240
2773
|
} catch {
|
|
5241
2774
|
return -1;
|
|
5242
2775
|
}
|
|
5243
2776
|
}
|
|
5244
2777
|
var inferences = /* @__PURE__ */ new Map();
|
|
5245
2778
|
function inferFarmIslandStrategy(filePath, root) {
|
|
5246
|
-
const file =
|
|
2779
|
+
const file = path6.resolve(filePath);
|
|
5247
2780
|
const cached = inferences.get(file);
|
|
5248
2781
|
if (cached && cached.stamps.every(([read, stamp]) => modifiedAt(read) === stamp)) {
|
|
5249
2782
|
return cached.result;
|
|
5250
2783
|
}
|
|
5251
2784
|
let code;
|
|
5252
2785
|
try {
|
|
5253
|
-
code =
|
|
2786
|
+
code = fs2.readFileSync(file, "utf8");
|
|
5254
2787
|
} catch {
|
|
5255
|
-
return { strategy: null, files: [file], reason: `${
|
|
2788
|
+
return { strategy: null, files: [file], reason: `${path6.basename(file)} could not be read` };
|
|
5256
2789
|
}
|
|
5257
2790
|
const result = inferStrategy(file, code, {
|
|
5258
2791
|
parse: parseFarmIslandSource,
|
|
@@ -5276,7 +2809,7 @@ function inferFarmRouteRootStrategy(owners, root) {
|
|
|
5276
2809
|
return {
|
|
5277
2810
|
strategy: null,
|
|
5278
2811
|
files,
|
|
5279
|
-
reason: `${
|
|
2812
|
+
reason: `${path6.basename(owner)}: its client components could not be listed`
|
|
5280
2813
|
};
|
|
5281
2814
|
}
|
|
5282
2815
|
modules.push(...rendered);
|
|
@@ -5284,7 +2817,7 @@ function inferFarmRouteRootStrategy(owners, root) {
|
|
|
5284
2817
|
for (const module of modules) {
|
|
5285
2818
|
let source = null;
|
|
5286
2819
|
try {
|
|
5287
|
-
source =
|
|
2820
|
+
source = fs2.readFileSync(module, "utf8");
|
|
5288
2821
|
} catch {
|
|
5289
2822
|
}
|
|
5290
2823
|
if (getIslandStrategyExport(source) !== null) return { strategy: null, files, declared: true };
|
|
@@ -5320,8 +2853,8 @@ function resolveFarmRouteRootStrategy(route, page, layouts, root, islandsMode) {
|
|
|
5320
2853
|
}
|
|
5321
2854
|
|
|
5322
2855
|
// src/client-plugin-build.ts
|
|
5323
|
-
import
|
|
5324
|
-
import
|
|
2856
|
+
import fs3 from "fs";
|
|
2857
|
+
import path7 from "path";
|
|
5325
2858
|
var CLIENT_KEYS = [
|
|
5326
2859
|
"public",
|
|
5327
2860
|
"setup",
|
|
@@ -5341,10 +2874,10 @@ var MOBILE_SHELL_CLIENT_REGISTRATION = ` {
|
|
|
5341
2874
|
}`;
|
|
5342
2875
|
var APP_CLIENT_EXTENSIONS = ["ts", "tsx", "js", "jsx", "mts", "mjs"];
|
|
5343
2876
|
function resolveFarmAppClientEntry(root = process.cwd(), srcDir = "src") {
|
|
5344
|
-
const sourceRoot =
|
|
2877
|
+
const sourceRoot = path7.resolve(root, srcDir);
|
|
5345
2878
|
for (const extension of APP_CLIENT_EXTENSIONS) {
|
|
5346
|
-
const candidate =
|
|
5347
|
-
if (
|
|
2879
|
+
const candidate = path7.join(sourceRoot, `client.${extension}`);
|
|
2880
|
+
if (fs3.existsSync(candidate) && fs3.statSync(candidate).isFile()) return candidate;
|
|
5348
2881
|
}
|
|
5349
2882
|
return void 0;
|
|
5350
2883
|
}
|
|
@@ -5586,27 +3119,27 @@ function isArrayIndex(key) {
|
|
|
5586
3119
|
}
|
|
5587
3120
|
|
|
5588
3121
|
// src/server/renderer.ts
|
|
5589
|
-
import * as
|
|
3122
|
+
import * as fs6 from "fs";
|
|
5590
3123
|
import * as https from "https";
|
|
5591
3124
|
import { isIP } from "net";
|
|
5592
|
-
import * as
|
|
3125
|
+
import * as path10 from "path";
|
|
5593
3126
|
import * as tls from "tls";
|
|
5594
3127
|
import { Readable, Writable } from "stream";
|
|
5595
3128
|
|
|
5596
3129
|
// src/not-found.ts
|
|
5597
|
-
import
|
|
5598
|
-
import
|
|
3130
|
+
import fs4 from "fs";
|
|
3131
|
+
import path8 from "path";
|
|
5599
3132
|
function resolveFarmNotFoundComponentPath(config, appDirs) {
|
|
5600
3133
|
const extensions = getFarmRendererComponentExtensions(config.renderer);
|
|
5601
3134
|
const configuredPath = config.notFound?.component?.trim();
|
|
5602
3135
|
if (configuredPath) {
|
|
5603
|
-
const componentPath =
|
|
3136
|
+
const componentPath = path8.isAbsolute(configuredPath) ? path8.normalize(configuredPath) : path8.resolve(config.root, configuredPath);
|
|
5604
3137
|
if (!extensions.some((extension) => componentPath.endsWith(extension))) {
|
|
5605
3138
|
throw new Error(
|
|
5606
3139
|
`notFound.component must use one of the configured renderer extensions: ${extensions.join(", ")}`
|
|
5607
3140
|
);
|
|
5608
3141
|
}
|
|
5609
|
-
if (!
|
|
3142
|
+
if (!fs4.existsSync(componentPath) || !fs4.statSync(componentPath).isFile()) {
|
|
5610
3143
|
throw new Error(`notFound.component was not found: ${componentPath}`);
|
|
5611
3144
|
}
|
|
5612
3145
|
return componentPath;
|
|
@@ -5614,8 +3147,8 @@ function resolveFarmNotFoundComponentPath(config, appDirs) {
|
|
|
5614
3147
|
let discoveredPath = null;
|
|
5615
3148
|
for (const appDir of appDirs) {
|
|
5616
3149
|
for (const extension of extensions) {
|
|
5617
|
-
const candidate =
|
|
5618
|
-
if (
|
|
3150
|
+
const candidate = path8.join(appDir, `not-found${extension}`);
|
|
3151
|
+
if (fs4.existsSync(candidate) && fs4.statSync(candidate).isFile()) {
|
|
5619
3152
|
discoveredPath = candidate;
|
|
5620
3153
|
break;
|
|
5621
3154
|
}
|
|
@@ -5811,22 +3344,22 @@ body {
|
|
|
5811
3344
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
5812
3345
|
|
|
5813
3346
|
// src/server/error-diagnostics.ts
|
|
5814
|
-
import * as
|
|
5815
|
-
import * as
|
|
5816
|
-
import { fileURLToPath
|
|
3347
|
+
import * as fs5 from "fs";
|
|
3348
|
+
import * as path9 from "path";
|
|
3349
|
+
import { fileURLToPath } from "url";
|
|
5817
3350
|
var SECRET_VALUE_PATTERN = /\b(api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|secret[_-]?key|token|password|secret)\s*[:=]\s*([^\s,;]+)/gi;
|
|
5818
3351
|
var BEARER_PATTERN = /\b(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi;
|
|
5819
3352
|
function redactErrorText(value) {
|
|
5820
3353
|
return value.replace(BEARER_PATTERN, "$1[REDACTED]").replace(SECRET_VALUE_PATTERN, "$1=[REDACTED]");
|
|
5821
3354
|
}
|
|
5822
3355
|
function isPathInsideRoot(root, filePath) {
|
|
5823
|
-
const relative3 =
|
|
5824
|
-
return relative3 === "" || !relative3.startsWith("..") && !
|
|
3356
|
+
const relative3 = path9.relative(root, filePath);
|
|
3357
|
+
return relative3 === "" || !relative3.startsWith("..") && !path9.isAbsolute(relative3);
|
|
5825
3358
|
}
|
|
5826
3359
|
function normalizeStackPath(value) {
|
|
5827
3360
|
const withoutQuery = value.replace(/[?#].*$/, "");
|
|
5828
3361
|
try {
|
|
5829
|
-
return withoutQuery.startsWith("file://") ?
|
|
3362
|
+
return withoutQuery.startsWith("file://") ? fileURLToPath(withoutQuery) : withoutQuery;
|
|
5830
3363
|
} catch {
|
|
5831
3364
|
return void 0;
|
|
5832
3365
|
}
|
|
@@ -5838,13 +3371,13 @@ function findStackLocation(stack, root) {
|
|
|
5838
3371
|
);
|
|
5839
3372
|
if (!match) continue;
|
|
5840
3373
|
const candidate = normalizeStackPath(match[1]);
|
|
5841
|
-
if (!candidate || candidate.includes(`${
|
|
5842
|
-
const absolutePath =
|
|
5843
|
-
if (!isPathInsideRoot(root, absolutePath) || !
|
|
5844
|
-
const relativePath =
|
|
3374
|
+
if (!candidate || candidate.includes(`${path9.sep}node_modules${path9.sep}`)) continue;
|
|
3375
|
+
const absolutePath = path9.resolve(candidate);
|
|
3376
|
+
if (!isPathInsideRoot(root, absolutePath) || !fs5.existsSync(absolutePath)) continue;
|
|
3377
|
+
const relativePath = path9.relative(root, absolutePath).split(path9.sep).join("/");
|
|
5845
3378
|
return {
|
|
5846
3379
|
absolutePath,
|
|
5847
|
-
displayPath: relativePath ||
|
|
3380
|
+
displayPath: relativePath || path9.basename(absolutePath),
|
|
5848
3381
|
line: Number(match[2]),
|
|
5849
3382
|
column: Number(match[3])
|
|
5850
3383
|
};
|
|
@@ -5853,7 +3386,7 @@ function findStackLocation(stack, root) {
|
|
|
5853
3386
|
}
|
|
5854
3387
|
function createSourceFrame(location) {
|
|
5855
3388
|
try {
|
|
5856
|
-
const sourceLines =
|
|
3389
|
+
const sourceLines = fs5.readFileSync(location.absolutePath, "utf8").split(/\r?\n/);
|
|
5857
3390
|
if (location.line < 1 || location.line > sourceLines.length) return void 0;
|
|
5858
3391
|
const start = Math.max(1, location.line - 2);
|
|
5859
3392
|
const end = Math.min(sourceLines.length, location.line + 2);
|
|
@@ -5876,13 +3409,13 @@ function createSourceFrame(location) {
|
|
|
5876
3409
|
}
|
|
5877
3410
|
}
|
|
5878
3411
|
function sanitizeStack(stack, root) {
|
|
5879
|
-
const normalizedRoot =
|
|
3412
|
+
const normalizedRoot = path9.resolve(root);
|
|
5880
3413
|
return redactErrorText(stack).split(normalizedRoot).join("<project>").replace(/<project>[^\s)]*/g, (segment) => segment.split("\\").join("/")).split("\n").filter((line, index) => index === 0 || !line.includes("node:internal")).slice(0, 14).join("\n");
|
|
5881
3414
|
}
|
|
5882
3415
|
function createDefaultErrorDiagnostics(error, root) {
|
|
5883
3416
|
const normalizedError = error instanceof Error ? error : new Error(typeof error === "string" ? error : "Unknown server rendering error");
|
|
5884
3417
|
const rawStack = normalizedError.stack || `${normalizedError.name}: ${normalizedError.message}`;
|
|
5885
|
-
const location = findStackLocation(rawStack,
|
|
3418
|
+
const location = findStackLocation(rawStack, path9.resolve(root));
|
|
5886
3419
|
return {
|
|
5887
3420
|
name: redactErrorText(normalizedError.name || "Error"),
|
|
5888
3421
|
message: redactErrorText(normalizedError.message || "Unknown server rendering error"),
|
|
@@ -6151,7 +3684,7 @@ function createRouteStateProps(input) {
|
|
|
6151
3684
|
function readAppPackageIdentity(root) {
|
|
6152
3685
|
try {
|
|
6153
3686
|
return JSON.parse(
|
|
6154
|
-
|
|
3687
|
+
fs6.readFileSync(path10.join(root || process.cwd(), "package.json"), "utf8")
|
|
6155
3688
|
);
|
|
6156
3689
|
} catch {
|
|
6157
3690
|
return {};
|
|
@@ -6458,10 +3991,10 @@ var ServerRenderer = class {
|
|
|
6458
3991
|
* Load SSG manifest from build output
|
|
6459
3992
|
*/
|
|
6460
3993
|
loadSSGManifest() {
|
|
6461
|
-
const manifestPath =
|
|
3994
|
+
const manifestPath = path10.join(this.config.root, this.config.outDir, "__ssg_manifest.json");
|
|
6462
3995
|
let content;
|
|
6463
3996
|
try {
|
|
6464
|
-
content =
|
|
3997
|
+
content = fs6.readFileSync(manifestPath, "utf-8");
|
|
6465
3998
|
} catch (error) {
|
|
6466
3999
|
if (error.code === "ENOENT") {
|
|
6467
4000
|
return;
|
|
@@ -6680,10 +4213,10 @@ var ServerRenderer = class {
|
|
|
6680
4213
|
return true;
|
|
6681
4214
|
}
|
|
6682
4215
|
try {
|
|
6683
|
-
const htmlPath = page.urlPath === "/" ?
|
|
6684
|
-
if (
|
|
6685
|
-
const stat =
|
|
6686
|
-
const html =
|
|
4216
|
+
const htmlPath = page.urlPath === "/" ? path10.join(this.config.root, this.config.outDir, "client", "index.html") : path10.join(this.config.root, this.config.outDir, "client", page.urlPath + ".html");
|
|
4217
|
+
if (fs6.existsSync(htmlPath)) {
|
|
4218
|
+
const stat = fs6.statSync(htmlPath);
|
|
4219
|
+
const html = fs6.readFileSync(htmlPath, "utf-8");
|
|
6687
4220
|
await this.cacheSSGPage(page, html, {
|
|
6688
4221
|
document: true,
|
|
6689
4222
|
createdAt: stat.mtimeMs
|
|
@@ -7446,11 +4979,11 @@ var ServerRenderer = class {
|
|
|
7446
4979
|
if (isFarmIntegrationProviderComponentReference(provider.component)) {
|
|
7447
4980
|
providerSourceModule = provider.component.module;
|
|
7448
4981
|
const providerModuleId = provider.component.module.startsWith(".") ? toViteModuleId(
|
|
7449
|
-
|
|
4982
|
+
path10.resolve(this.config.root, provider.component.module),
|
|
7450
4983
|
this.config.root
|
|
7451
4984
|
) : provider.component.module;
|
|
7452
4985
|
const providerModule = this.viteServer ? await loadFarmDevModule(this.viteServer, providerModuleId) : await importRuntimeModule(
|
|
7453
|
-
provider.component.module.startsWith(".") ? pathToFileURL2(
|
|
4986
|
+
provider.component.module.startsWith(".") ? pathToFileURL2(path10.resolve(this.config.root, provider.component.module)).href : provider.component.module
|
|
7454
4987
|
);
|
|
7455
4988
|
ProviderComponent = providerModule[provider.component.export || "default"];
|
|
7456
4989
|
} else if (typeof provider.component === "function") {
|
|
@@ -7717,7 +5250,7 @@ var ServerRenderer = class {
|
|
|
7717
5250
|
logger.warn(`Could not read metadata for ${pattern} in sitemap.xml: ${error}`);
|
|
7718
5251
|
return void 0;
|
|
7719
5252
|
}),
|
|
7720
|
-
|
|
5253
|
+
fs6.promises.stat(route.modulePath).catch(() => void 0)
|
|
7721
5254
|
]);
|
|
7722
5255
|
return { pattern, module, lastModified: stat?.mtime.toISOString() };
|
|
7723
5256
|
})
|
|
@@ -7968,7 +5501,7 @@ var ServerRenderer = class {
|
|
|
7968
5501
|
res.end();
|
|
7969
5502
|
return;
|
|
7970
5503
|
}
|
|
7971
|
-
res.write(await
|
|
5504
|
+
res.write(await fs6.promises.readFile(image.modulePath));
|
|
7972
5505
|
res.end();
|
|
7973
5506
|
}
|
|
7974
5507
|
async renderRouteErrorBoundary(req, res, options) {
|
|
@@ -8789,13 +6322,13 @@ window.__FARM_I18N__ = ${getFarmI18nClientSnapshot() ? serializeInlineValue(getF
|
|
|
8789
6322
|
res.end(createFarmMarkdownErrorBody(404, pathname, this.config.basePath || "/"));
|
|
8790
6323
|
return;
|
|
8791
6324
|
}
|
|
8792
|
-
const appDir =
|
|
6325
|
+
const appDir = path10.join(this.config.root, this.config.srcDir, "app");
|
|
8793
6326
|
const notFoundExtensions = getFarmRendererComponentExtensions(this.config.renderer);
|
|
8794
6327
|
let layoutModule = null;
|
|
8795
6328
|
try {
|
|
8796
6329
|
for (const ext of notFoundExtensions) {
|
|
8797
|
-
const layoutPath =
|
|
8798
|
-
if (
|
|
6330
|
+
const layoutPath = path10.join(appDir, `layout${ext}`);
|
|
6331
|
+
if (fs6.existsSync(layoutPath)) {
|
|
8799
6332
|
layoutModule = await this.routeManager.loadLayoutModule(layoutPath);
|
|
8800
6333
|
break;
|
|
8801
6334
|
}
|
|
@@ -9008,7 +6541,7 @@ ${clientScript}
|
|
|
9008
6541
|
};
|
|
9009
6542
|
|
|
9010
6543
|
// src/app.ts
|
|
9011
|
-
import
|
|
6544
|
+
import path11 from "path";
|
|
9012
6545
|
var defaultDocsConfig = {
|
|
9013
6546
|
enabled: false,
|
|
9014
6547
|
entry: "/docs",
|
|
@@ -9148,7 +6681,7 @@ var FarmApp = class {
|
|
|
9148
6681
|
}
|
|
9149
6682
|
const componentExtensions = getFarmRendererComponentExtensions(this.config.renderer);
|
|
9150
6683
|
const rootLayoutPaths = appDirs.flatMap(
|
|
9151
|
-
(appDir) => componentExtensions.map((extension) =>
|
|
6684
|
+
(appDir) => componentExtensions.map((extension) => path11.join(appDir, `layout${extension}`))
|
|
9152
6685
|
);
|
|
9153
6686
|
const hasRootLayout = await Promise.all(rootLayoutPaths.map((p) => fileExists(p))).then(
|
|
9154
6687
|
(results) => results.some(Boolean)
|
|
@@ -9212,13 +6745,13 @@ function resolveFarmImageServerRuntime(images, preset) {
|
|
|
9212
6745
|
}
|
|
9213
6746
|
|
|
9214
6747
|
// src/app-manifest-packages.ts
|
|
9215
|
-
import
|
|
9216
|
-
import
|
|
6748
|
+
import fs7 from "fs";
|
|
6749
|
+
import path12 from "path";
|
|
9217
6750
|
var FARM_PACKAGE = /^@(?:farm\.js|farming-labs)\/[a-z0-9._-]+$/;
|
|
9218
6751
|
function resolveFarmAppPackages(root) {
|
|
9219
6752
|
let manifest;
|
|
9220
6753
|
try {
|
|
9221
|
-
manifest = JSON.parse(
|
|
6754
|
+
manifest = JSON.parse(fs7.readFileSync(path12.join(root, "package.json"), "utf8"));
|
|
9222
6755
|
} catch {
|
|
9223
6756
|
return {};
|
|
9224
6757
|
}
|
|
@@ -9233,13 +6766,13 @@ function resolveFarmAppPackages(root) {
|
|
|
9233
6766
|
for (let dir = root; ; ) {
|
|
9234
6767
|
try {
|
|
9235
6768
|
const { version } = JSON.parse(
|
|
9236
|
-
|
|
6769
|
+
fs7.readFileSync(path12.join(dir, "node_modules", name, "package.json"), "utf8")
|
|
9237
6770
|
);
|
|
9238
6771
|
if (typeof version === "string" && /^[0-9A-Za-z.+-]{1,64}$/.test(version))
|
|
9239
6772
|
versions[name] = version;
|
|
9240
6773
|
break;
|
|
9241
6774
|
} catch {
|
|
9242
|
-
const parent =
|
|
6775
|
+
const parent = path12.dirname(dir);
|
|
9243
6776
|
if (parent === dir) break;
|
|
9244
6777
|
dir = parent;
|
|
9245
6778
|
}
|
|
@@ -9249,9 +6782,9 @@ function resolveFarmAppPackages(root) {
|
|
|
9249
6782
|
}
|
|
9250
6783
|
|
|
9251
6784
|
// src/app-manifest-webmcp.ts
|
|
9252
|
-
import
|
|
6785
|
+
import fs8 from "fs";
|
|
9253
6786
|
import { createRequire as createRequire2 } from "module";
|
|
9254
|
-
import
|
|
6787
|
+
import path13 from "path";
|
|
9255
6788
|
import { globSync } from "tinyglobby";
|
|
9256
6789
|
var WEBMCP_CLIENT = "@farm.js/webmcp/client";
|
|
9257
6790
|
var DEFINERS = /* @__PURE__ */ new Set(["defineWebMCPTool", "registerWebMCPTool", "registerWebMCPTools"]);
|
|
@@ -9269,7 +6802,7 @@ var LANGS = {
|
|
|
9269
6802
|
cjs: "jsx",
|
|
9270
6803
|
jsx: "jsx"
|
|
9271
6804
|
};
|
|
9272
|
-
var
|
|
6805
|
+
var parseAst2;
|
|
9273
6806
|
function staticValue(node) {
|
|
9274
6807
|
if (!node) return NOT_STATIC;
|
|
9275
6808
|
switch (node.type) {
|
|
@@ -9346,13 +6879,13 @@ function toolFromObject(object) {
|
|
|
9346
6879
|
}
|
|
9347
6880
|
function findFarmWebMCPTools(code, filename = "module.tsx") {
|
|
9348
6881
|
if (!code.includes(WEBMCP_CLIENT)) return [];
|
|
9349
|
-
const lang = LANGS[
|
|
9350
|
-
|
|
6882
|
+
const lang = LANGS[path13.extname(filename).slice(1)] ?? "tsx";
|
|
6883
|
+
parseAst2 ?? (parseAst2 = createRequire2(typeof __filename === "string" ? __filename : import.meta.url)(
|
|
9351
6884
|
"rolldown/parseAst"
|
|
9352
6885
|
).parseAst);
|
|
9353
6886
|
let program;
|
|
9354
6887
|
try {
|
|
9355
|
-
program =
|
|
6888
|
+
program = parseAst2(code, { lang });
|
|
9356
6889
|
} catch {
|
|
9357
6890
|
return [];
|
|
9358
6891
|
}
|
|
@@ -9391,9 +6924,9 @@ function findFarmWebMCPTools(code, filename = "module.tsx") {
|
|
|
9391
6924
|
visit(program.body);
|
|
9392
6925
|
return found.sort((a, b) => a.start - b.start).map(({ tool }) => tool);
|
|
9393
6926
|
}
|
|
9394
|
-
var
|
|
6927
|
+
var cache = /* @__PURE__ */ new Map();
|
|
9395
6928
|
function collectFarmWebMCPTools(root, srcDir = "src") {
|
|
9396
|
-
const base =
|
|
6929
|
+
const base = path13.resolve(root, srcDir);
|
|
9397
6930
|
let files;
|
|
9398
6931
|
try {
|
|
9399
6932
|
files = globSync("**/*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}", {
|
|
@@ -9410,19 +6943,19 @@ function collectFarmWebMCPTools(root, srcDir = "src") {
|
|
|
9410
6943
|
for (const file of files.sort()) {
|
|
9411
6944
|
let mtimeMs;
|
|
9412
6945
|
try {
|
|
9413
|
-
mtimeMs =
|
|
6946
|
+
mtimeMs = fs8.statSync(file).mtimeMs;
|
|
9414
6947
|
} catch {
|
|
9415
6948
|
continue;
|
|
9416
6949
|
}
|
|
9417
|
-
let entry =
|
|
6950
|
+
let entry = cache.get(file);
|
|
9418
6951
|
if (!entry || entry.mtimeMs !== mtimeMs) {
|
|
9419
6952
|
let code = "";
|
|
9420
6953
|
try {
|
|
9421
|
-
code =
|
|
6954
|
+
code = fs8.readFileSync(file, "utf8");
|
|
9422
6955
|
} catch {
|
|
9423
6956
|
}
|
|
9424
6957
|
entry = { mtimeMs, tools: findFarmWebMCPTools(code, file) };
|
|
9425
|
-
|
|
6958
|
+
cache.set(file, entry);
|
|
9426
6959
|
}
|
|
9427
6960
|
for (const tool of entry.tools) {
|
|
9428
6961
|
if (seen.has(tool.name) || tools.length >= MAX_TOOLS) continue;
|
|
@@ -9434,11 +6967,11 @@ function collectFarmWebMCPTools(root, srcDir = "src") {
|
|
|
9434
6967
|
}
|
|
9435
6968
|
|
|
9436
6969
|
// src/client-cache-persistence-build.ts
|
|
9437
|
-
import
|
|
9438
|
-
import
|
|
6970
|
+
import fs9 from "fs";
|
|
6971
|
+
import path14 from "path";
|
|
9439
6972
|
var ADAPTER_EXTENSIONS = ["ts", "tsx", "js", "jsx", "mts", "mjs"];
|
|
9440
|
-
function resolveFarmClientCacheAdapterEntry(root,
|
|
9441
|
-
const client =
|
|
6973
|
+
function resolveFarmClientCacheAdapterEntry(root, cache2) {
|
|
6974
|
+
const client = cache2?.client;
|
|
9442
6975
|
const adapter = client?.adapter;
|
|
9443
6976
|
if (adapter === void 0) return void 0;
|
|
9444
6977
|
if (typeof adapter !== "string" || adapter.trim().length === 0) {
|
|
@@ -9446,7 +6979,7 @@ function resolveFarmClientCacheAdapterEntry(root, cache3) {
|
|
|
9446
6979
|
'cache.client.adapter must be a module path string, for example "./src/cache-adapter".'
|
|
9447
6980
|
);
|
|
9448
6981
|
}
|
|
9449
|
-
const resolved =
|
|
6982
|
+
const resolved = path14.resolve(root, adapter);
|
|
9450
6983
|
const found = resolveAdapterFile(resolved);
|
|
9451
6984
|
if (!found) {
|
|
9452
6985
|
throw new Error(
|
|
@@ -9459,10 +6992,10 @@ function resolveFarmClientCacheAdapterEntry(root, cache3) {
|
|
|
9459
6992
|
return { importPath: found.replace(/\\/g, "/"), options };
|
|
9460
6993
|
}
|
|
9461
6994
|
function resolveAdapterFile(resolved) {
|
|
9462
|
-
if (
|
|
6995
|
+
if (fs9.existsSync(resolved) && fs9.statSync(resolved).isFile()) return resolved;
|
|
9463
6996
|
for (const extension of ADAPTER_EXTENSIONS) {
|
|
9464
6997
|
const candidate = `${resolved}.${extension}`;
|
|
9465
|
-
if (
|
|
6998
|
+
if (fs9.existsSync(candidate) && fs9.statSync(candidate).isFile()) return candidate;
|
|
9466
6999
|
}
|
|
9467
7000
|
return void 0;
|
|
9468
7001
|
}
|
|
@@ -9672,8 +7205,8 @@ async function readFarmNavigationStream(body, flushToken) {
|
|
|
9672
7205
|
// src/docs/client-config.ts
|
|
9673
7206
|
import { realpathSync as realpathSync2 } from "fs";
|
|
9674
7207
|
import { createRequire as createRequire3 } from "module";
|
|
9675
|
-
import
|
|
9676
|
-
var
|
|
7208
|
+
import path15 from "path";
|
|
7209
|
+
var parseAst3;
|
|
9677
7210
|
function propertyKeyName(property2) {
|
|
9678
7211
|
if (property2.computed) return void 0;
|
|
9679
7212
|
const key = property2.key;
|
|
@@ -9682,11 +7215,11 @@ function propertyKeyName(property2) {
|
|
|
9682
7215
|
return void 0;
|
|
9683
7216
|
}
|
|
9684
7217
|
function redactFarmDocsClientConfig(code, filename) {
|
|
9685
|
-
|
|
7218
|
+
parseAst3 ?? (parseAst3 = createRequire3(typeof __filename === "string" ? __filename : import.meta.url)(
|
|
9686
7219
|
"rolldown/parseAst"
|
|
9687
7220
|
).parseAst);
|
|
9688
|
-
const extension =
|
|
9689
|
-
const program =
|
|
7221
|
+
const extension = path15.extname(filename);
|
|
7222
|
+
const program = parseAst3(code, {
|
|
9690
7223
|
lang: extension === ".tsx" || extension === ".jsx" ? "tsx" : "ts"
|
|
9691
7224
|
});
|
|
9692
7225
|
const edits = [];
|
|
@@ -9747,7 +7280,7 @@ function farmDocsClientConfigPlugin(configModule) {
|
|
|
9747
7280
|
}
|
|
9748
7281
|
|
|
9749
7282
|
// src/server/vite-config.ts
|
|
9750
|
-
import
|
|
7283
|
+
import path16 from "path";
|
|
9751
7284
|
var FARM_CLIENT_ENTRY_PATTERN = "**/{page,layout,loading,error,not-found,default}.{js,jsx,ts,tsx}";
|
|
9752
7285
|
var FARM_CLIENT_OPTIMIZE_DEPS_INCLUDE = [
|
|
9753
7286
|
"react",
|
|
@@ -9774,9 +7307,9 @@ function getFarmClientOptimizeDepsInclude(renderer) {
|
|
|
9774
7307
|
);
|
|
9775
7308
|
}
|
|
9776
7309
|
function createFarmClientOptimizeDepsEntries(projectRoot, appDirectories) {
|
|
9777
|
-
const resolvedProjectRoot =
|
|
7310
|
+
const resolvedProjectRoot = path16.resolve(projectRoot);
|
|
9778
7311
|
return appDirectories.map((appDirectory) => {
|
|
9779
|
-
const relativeAppDirectory =
|
|
7312
|
+
const relativeAppDirectory = path16.relative(resolvedProjectRoot, path16.resolve(appDirectory)).replace(/\\/g, "/");
|
|
9780
7313
|
const prefix = relativeAppDirectory || ".";
|
|
9781
7314
|
return `${prefix}/${FARM_CLIENT_ENTRY_PATTERN}`;
|
|
9782
7315
|
});
|
|
@@ -9798,7 +7331,7 @@ function createFarmClientOptimizeDepsConfig(entries, renderer) {
|
|
|
9798
7331
|
}
|
|
9799
7332
|
function createFarmSourceAlias(projectRoot, srcDir = "src") {
|
|
9800
7333
|
return {
|
|
9801
|
-
"@":
|
|
7334
|
+
"@": path16.resolve(projectRoot, srcDir)
|
|
9802
7335
|
};
|
|
9803
7336
|
}
|
|
9804
7337
|
function mergeNoExternal(farmValue, userValue) {
|
|
@@ -9946,31 +7479,6 @@ ${FARM_DARK_VARIANT}
|
|
|
9946
7479
|
}
|
|
9947
7480
|
|
|
9948
7481
|
export {
|
|
9949
|
-
rewriteFarmReactServerImports,
|
|
9950
|
-
farmRelativeImportFiles,
|
|
9951
|
-
ensureFarmPackageClientReference,
|
|
9952
|
-
rewriteFarmPackageClientImports,
|
|
9953
|
-
withPackageClientBoundaryCache,
|
|
9954
|
-
usePackageClientBoundaryCacheFile,
|
|
9955
|
-
resolveModuleSourcePath,
|
|
9956
|
-
getFarmClientHydrationPlanOptions,
|
|
9957
|
-
describeSuppressedAsyncHydration,
|
|
9958
|
-
resolveFarmIsolatedClientHydrationMode,
|
|
9959
|
-
hasUseClientDirective,
|
|
9960
|
-
getIslandStrategyExport,
|
|
9961
|
-
stripUseClientDirective,
|
|
9962
|
-
collectFarmServerStylesheets,
|
|
9963
|
-
getClientModuleMetadata,
|
|
9964
|
-
getClientModuleHydrationPlan,
|
|
9965
|
-
usesFarmServerTree,
|
|
9966
|
-
createMarkdownPageHydrationPlanner,
|
|
9967
|
-
enforceFarmIsolatedHydrationRouteBudget,
|
|
9968
|
-
isIsolatableClientBoundarySource,
|
|
9969
|
-
isFarmPackageClientBoundary,
|
|
9970
|
-
collectFarmClientPackageImports,
|
|
9971
|
-
invalidateFarmClientReachableModules,
|
|
9972
|
-
getFarmClientReachableModules,
|
|
9973
|
-
resolveFarmClientOptimizeDeps,
|
|
9974
7482
|
RouteManager,
|
|
9975
7483
|
resolveDevGlobalStylesheetHref,
|
|
9976
7484
|
collectDevStylesheetUrls,
|