@mandujs/core 0.54.17 → 0.54.19
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/package.json +3 -1
- package/src/agent/__tests__/context.test.ts +94 -25
- package/src/agent/context.ts +17 -0
- package/src/agent/types.ts +32 -12
- package/src/agent/verify.ts +55 -24
- package/src/bundler/__snapshots__/build.test.ts.snap +5 -0
- package/src/bundler/__tests__/build-runner.ts +130 -17
- package/src/bundler/__tests__/client-boundary-transform.test.ts +524 -0
- package/src/bundler/__tests__/reverse-import-graph.test.ts +42 -33
- package/src/bundler/build.test.ts +478 -9
- package/src/bundler/build.ts +424 -746
- package/src/bundler/client-boundary-transform.ts +977 -0
- package/src/bundler/dev.ts +39 -112
- package/src/bundler/fast-refresh-preamble.ts +47 -0
- package/src/bundler/index.ts +3 -2
- package/src/bundler/manifest-schema.ts +10 -0
- package/src/bundler/types.ts +20 -2
- package/src/client/__tests__/props-serialization.test.ts +37 -0
- package/src/client/hydrate.ts +2 -2
- package/src/client/index.ts +1 -1
- package/src/client/props-serialization.ts +233 -0
- package/src/client/runtime-entry.ts +567 -0
- package/src/client/runtime.ts +1 -1
- package/src/client/serialize.ts +50 -404
- package/src/diagnose/__tests__/checks.test.ts +132 -17
- package/src/diagnose/checks.ts +184 -3
- package/src/diagnose/run.ts +10 -8
- package/src/generator/templates.test.ts +48 -5
- package/src/generator/templates.ts +10 -1
- package/src/internal/client-boundary.ts +266 -0
- package/src/internal/index.ts +2 -1
- package/src/router/client-entry.test.ts +154 -29
- package/src/router/client-entry.ts +111 -313
- package/src/router/fs-routes.test.ts +443 -1
- package/src/router/fs-routes.ts +16 -3
- package/src/router/fs-scanner.ts +176 -57
- package/src/router/fs-types.ts +11 -2
- package/src/router/route-source-analyzer.ts +521 -0
- package/src/runtime/__tests__/inline-client-hydration.test.ts +104 -1
- package/src/runtime/__tests__/page-render-response.test.ts +218 -0
- package/src/runtime/handlers.ts +50 -26
- package/src/runtime/page-render-response.ts +24 -1
- package/src/runtime/server.ts +14 -0
- package/src/runtime/ssr.ts +16 -5
- package/src/runtime/streaming-ssr.ts +119 -76
- package/src/spec/schema.ts +31 -5
|
@@ -2,6 +2,11 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
|
2
2
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { pathToFileURL } from "url";
|
|
5
|
+
import { serializeProps } from "../client/serialize";
|
|
6
|
+
import { toMatchSnapshot } from "../testing/snapshot";
|
|
7
|
+
import { setupHappyDom } from "../../tests/setup";
|
|
8
|
+
|
|
9
|
+
setupHappyDom();
|
|
5
10
|
|
|
6
11
|
// 모든 테스트가 하나의 빌드 결과를 공유 — 병렬 Bun.build 충돌 방지
|
|
7
12
|
let rootDir: string;
|
|
@@ -13,10 +18,78 @@ async function mkRepoTempDir(prefix: string): Promise<string> {
|
|
|
13
18
|
return mkdtemp(path.join(repoTempRoot, prefix));
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
async function importBuiltModule(relativePath: string): Promise<Record<string, unknown>> {
|
|
17
|
-
const fileUrl = pathToFileURL(path.join(rootDir, relativePath)).href;
|
|
18
|
-
return import(`${fileUrl}?t=${Date.now()}`);
|
|
19
|
-
}
|
|
21
|
+
async function importBuiltModule(relativePath: string): Promise<Record<string, unknown>> {
|
|
22
|
+
const fileUrl = pathToFileURL(path.join(rootDir, relativePath)).href;
|
|
23
|
+
return import(`${fileUrl}?t=${Date.now()}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function evaluateGeneratedHydrationRuntime(): Promise<{ hydrateIslands: () => void }> {
|
|
27
|
+
const sourcePath = path.join(rootDir, ".mandu", "client", "_runtime.src.js");
|
|
28
|
+
const bundledPath = path.join(rootDir, ".mandu", "client", "_runtime.js");
|
|
29
|
+
const runtimeSource = await readFile(await Bun.file(sourcePath).exists() ? sourcePath : bundledPath, "utf-8");
|
|
30
|
+
const instrumented = runtimeSource
|
|
31
|
+
.replace(
|
|
32
|
+
/import\s+React,\s*\{[^}]*\}\s+from\s+['"]react['"];?/,
|
|
33
|
+
"const React = globalThis.__MANDU_TEST_REACT__; const { useState, useEffect, Component } = React;",
|
|
34
|
+
)
|
|
35
|
+
.replace(
|
|
36
|
+
/import\s+\{[^}]*\}\s+from\s+['"]react-dom\/client['"];?/,
|
|
37
|
+
"const { hydrateRoot, createRoot } = globalThis.__MANDU_TEST_REACT_DOM_CLIENT__;",
|
|
38
|
+
)
|
|
39
|
+
.replace(
|
|
40
|
+
/export\s*\{[^}]*\};?/g,
|
|
41
|
+
"globalThis.__MANDU_TEST_RUNTIME__ = { hydrateIslands, unmountIsland, hydratedRoots };",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const reactStub = {
|
|
45
|
+
Component: class {},
|
|
46
|
+
createElement(type: unknown, props: Record<string, unknown> | null, ...children: unknown[]) {
|
|
47
|
+
if (
|
|
48
|
+
typeof type === "function" &&
|
|
49
|
+
!(typeof type === "function" && "prototype" in type && (type as { prototype?: { render?: unknown } }).prototype?.render)
|
|
50
|
+
) {
|
|
51
|
+
return (type as (props: Record<string, unknown>) => unknown)({
|
|
52
|
+
...(props ?? {}),
|
|
53
|
+
children: children.length <= 1 ? children[0] : children,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return { type, props: props ?? {}, children };
|
|
57
|
+
},
|
|
58
|
+
isValidElement(value: unknown) {
|
|
59
|
+
return !!value && typeof value === "object" && "type" in value;
|
|
60
|
+
},
|
|
61
|
+
useEffect(effect: () => void) {
|
|
62
|
+
effect();
|
|
63
|
+
},
|
|
64
|
+
useState<T>(initial: T) {
|
|
65
|
+
return [initial, () => {}] as const;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const rootStub = {
|
|
69
|
+
render() {},
|
|
70
|
+
unmount() {},
|
|
71
|
+
};
|
|
72
|
+
Object.assign(globalThis, {
|
|
73
|
+
__MANDU_TEST_REACT__: reactStub,
|
|
74
|
+
__MANDU_TEST_REACT_DOM_CLIENT__: {
|
|
75
|
+
createRoot: () => rootStub,
|
|
76
|
+
hydrateRoot: () => rootStub,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
new Function(instrumented)();
|
|
81
|
+
return (globalThis as typeof globalThis & {
|
|
82
|
+
__MANDU_TEST_RUNTIME__: { hydrateIslands: () => void };
|
|
83
|
+
}).__MANDU_TEST_RUNTIME__;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function waitForRuntimeAssertion(assertion: () => boolean): Promise<void> {
|
|
87
|
+
for (let attempt = 0; attempt < 25; attempt++) {
|
|
88
|
+
if (assertion()) return;
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
90
|
+
}
|
|
91
|
+
expect(assertion()).toBe(true);
|
|
92
|
+
}
|
|
20
93
|
|
|
21
94
|
/**
|
|
22
95
|
* Run `buildClientBundles` in an isolated `bun` subprocess.
|
|
@@ -34,7 +107,31 @@ async function runBuildInSubprocess(root: string, mode?: string): Promise<{
|
|
|
34
107
|
success: boolean;
|
|
35
108
|
errors: string[];
|
|
36
109
|
manifest?: {
|
|
110
|
+
routes?: Array<{
|
|
111
|
+
id?: string;
|
|
112
|
+
module?: string;
|
|
113
|
+
componentModule?: string;
|
|
114
|
+
boundaries?: Array<{
|
|
115
|
+
id?: string;
|
|
116
|
+
routeId?: string;
|
|
117
|
+
module?: string;
|
|
118
|
+
importSpecifier?: string;
|
|
119
|
+
exportName?: string;
|
|
120
|
+
localName?: string;
|
|
121
|
+
hydrate?: string;
|
|
122
|
+
ordinal?: number;
|
|
123
|
+
propsSource?: string;
|
|
124
|
+
propsKeys?: string[];
|
|
125
|
+
hasSpreadProps?: boolean;
|
|
126
|
+
source?: {
|
|
127
|
+
file?: string;
|
|
128
|
+
line?: number;
|
|
129
|
+
column?: number;
|
|
130
|
+
};
|
|
131
|
+
}>;
|
|
132
|
+
}>;
|
|
37
133
|
bundles?: Record<string, { js?: string }>;
|
|
134
|
+
boundaries?: Record<string, { js?: string; route?: string; module?: string; exportName?: string; hydrate?: string }>;
|
|
38
135
|
} | null;
|
|
39
136
|
}> {
|
|
40
137
|
const runner = path.join(
|
|
@@ -127,7 +224,7 @@ afterAll(async () => {
|
|
|
127
224
|
// is now sidestepped by running `buildClientBundles` in a spawned `bun`
|
|
128
225
|
// subprocess via `__tests__/build-runner.ts`. In-process retry does not
|
|
129
226
|
// recover from that one; a fresh module graph does.
|
|
130
|
-
describe("buildClientBundles vendor shims", () => {
|
|
227
|
+
describe("buildClientBundles vendor shims", () => {
|
|
131
228
|
test("build succeeds", () => {
|
|
132
229
|
if (!result.success) {
|
|
133
230
|
console.error("[build.test] errors:", result.errors);
|
|
@@ -209,11 +306,174 @@ describe("buildClientBundles vendor shims", () => {
|
|
|
209
306
|
expect(runtimeSource).toContain("document.getElementById(\"__MANDU_DATA__\")");
|
|
210
307
|
expect(runtimeSource).toContain("function parsePropsScript");
|
|
211
308
|
expect(runtimeSource).toContain("data-mandu-props");
|
|
212
|
-
expect(runtimeSource).toContain("
|
|
309
|
+
expect(runtimeSource).toContain("Missing boundary-local props for transformed client boundary");
|
|
310
|
+
expect(runtimeSource).toContain("warnedBoundaryPropFallbacks");
|
|
311
|
+
expect(runtimeSource).toContain("deserializeProps");
|
|
213
312
|
expect(runtimeSource).toContain("new Date");
|
|
214
313
|
expect(runtimeSource).toContain("new Map");
|
|
215
314
|
});
|
|
216
|
-
|
|
315
|
+
|
|
316
|
+
test("runtime hydrates named client boundary from boundary-local props before route data", async () => {
|
|
317
|
+
const modulePath = path.join(rootDir, ".mandu", "client", "runtime-named-boundary.js");
|
|
318
|
+
await writeFile(
|
|
319
|
+
modulePath,
|
|
320
|
+
`
|
|
321
|
+
export default function WrongDefault(props) {
|
|
322
|
+
globalThis.__MANDU_TEST_DEFAULT_PROPS__ = props;
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
export function NamedBoundary(props) {
|
|
326
|
+
globalThis.__MANDU_TEST_NAMED_PROPS__ = props;
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
`,
|
|
330
|
+
"utf-8",
|
|
331
|
+
);
|
|
332
|
+
Object.assign(globalThis, {
|
|
333
|
+
__MANDU_TEST_NAMED_PROPS__: undefined,
|
|
334
|
+
__MANDU_TEST_DEFAULT_PROPS__: undefined,
|
|
335
|
+
});
|
|
336
|
+
document.body.innerHTML = `
|
|
337
|
+
<div
|
|
338
|
+
data-mandu-island="named--0"
|
|
339
|
+
data-mandu-boundary-id="named--0"
|
|
340
|
+
data-mandu-route-id="named-route"
|
|
341
|
+
data-mandu-client-export="NamedBoundary"
|
|
342
|
+
data-mandu-src="${pathToFileURL(modulePath).href}?t=${Date.now()}"
|
|
343
|
+
data-hydrate="load"
|
|
344
|
+
></div>
|
|
345
|
+
<script type="application/json" data-mandu-props="named--0">${serializeProps({ label: "boundary-local" })}</script>
|
|
346
|
+
`;
|
|
347
|
+
(window as typeof window & { __MANDU_DATA__?: unknown; __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_DATA__ = {
|
|
348
|
+
"named-route": { serverData: { label: "route-data" } },
|
|
349
|
+
};
|
|
350
|
+
(window as typeof window & { __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_ROOTS__ = new Map();
|
|
351
|
+
|
|
352
|
+
const runtime = await evaluateGeneratedHydrationRuntime();
|
|
353
|
+
runtime.hydrateIslands();
|
|
354
|
+
|
|
355
|
+
await waitForRuntimeAssertion(() =>
|
|
356
|
+
(globalThis as typeof globalThis & { __MANDU_TEST_NAMED_PROPS__?: { label?: string } }).__MANDU_TEST_NAMED_PROPS__?.label === "boundary-local"
|
|
357
|
+
);
|
|
358
|
+
expect((globalThis as typeof globalThis & { __MANDU_TEST_DEFAULT_PROPS__?: unknown }).__MANDU_TEST_DEFAULT_PROPS__).toBeUndefined();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test("runtime hydrates default client boundary from boundary-local props", async () => {
|
|
362
|
+
const modulePath = path.join(rootDir, ".mandu", "client", "runtime-default-boundary.js");
|
|
363
|
+
await writeFile(
|
|
364
|
+
modulePath,
|
|
365
|
+
`
|
|
366
|
+
export default function DefaultBoundary(props) {
|
|
367
|
+
globalThis.__MANDU_TEST_DEFAULT_BOUNDARY_PROPS__ = props;
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
`,
|
|
371
|
+
"utf-8",
|
|
372
|
+
);
|
|
373
|
+
Object.assign(globalThis, {
|
|
374
|
+
__MANDU_TEST_DEFAULT_BOUNDARY_PROPS__: undefined,
|
|
375
|
+
});
|
|
376
|
+
document.body.innerHTML = `
|
|
377
|
+
<div
|
|
378
|
+
data-mandu-island="default--0"
|
|
379
|
+
data-mandu-boundary-id="default--0"
|
|
380
|
+
data-mandu-route-id="default-route"
|
|
381
|
+
data-mandu-client-export="default"
|
|
382
|
+
data-mandu-src="${pathToFileURL(modulePath).href}?t=${Date.now()}"
|
|
383
|
+
data-hydrate="load"
|
|
384
|
+
></div>
|
|
385
|
+
<script type="application/json" data-mandu-props="default--0">${serializeProps({ label: "default-boundary" })}</script>
|
|
386
|
+
`;
|
|
387
|
+
(window as typeof window & { __MANDU_DATA__?: unknown; __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_DATA__ = {};
|
|
388
|
+
(window as typeof window & { __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_ROOTS__ = new Map();
|
|
389
|
+
|
|
390
|
+
const runtime = await evaluateGeneratedHydrationRuntime();
|
|
391
|
+
runtime.hydrateIslands();
|
|
392
|
+
|
|
393
|
+
await waitForRuntimeAssertion(() =>
|
|
394
|
+
(globalThis as typeof globalThis & { __MANDU_TEST_DEFAULT_BOUNDARY_PROPS__?: { label?: string } }).__MANDU_TEST_DEFAULT_BOUNDARY_PROPS__?.label === "default-boundary"
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("runtime keeps explicit island API data-props fallback working", async () => {
|
|
399
|
+
const modulePath = path.join(rootDir, ".mandu", "client", "runtime-explicit-island.js");
|
|
400
|
+
await writeFile(
|
|
401
|
+
modulePath,
|
|
402
|
+
`
|
|
403
|
+
export default {
|
|
404
|
+
__mandu_island: true,
|
|
405
|
+
definition: {
|
|
406
|
+
setup(data) {
|
|
407
|
+
globalThis.__MANDU_TEST_EXPLICIT_ISLAND_DATA__ = data;
|
|
408
|
+
return data;
|
|
409
|
+
},
|
|
410
|
+
render() {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
`,
|
|
416
|
+
"utf-8",
|
|
417
|
+
);
|
|
418
|
+
Object.assign(globalThis, {
|
|
419
|
+
__MANDU_TEST_EXPLICIT_ISLAND_DATA__: undefined,
|
|
420
|
+
});
|
|
421
|
+
document.body.innerHTML = `
|
|
422
|
+
<div
|
|
423
|
+
data-mandu-island="explicit-island"
|
|
424
|
+
data-mandu-src="${pathToFileURL(modulePath).href}?t=${Date.now()}"
|
|
425
|
+
data-props="${serializeProps({ label: "data-props" }).replace(/"/g, """)}"
|
|
426
|
+
data-hydrate="load"
|
|
427
|
+
></div>
|
|
428
|
+
`;
|
|
429
|
+
(window as typeof window & { __MANDU_DATA__?: unknown; __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_DATA__ = {};
|
|
430
|
+
(window as typeof window & { __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_ROOTS__ = new Map();
|
|
431
|
+
|
|
432
|
+
const runtime = await evaluateGeneratedHydrationRuntime();
|
|
433
|
+
runtime.hydrateIslands();
|
|
434
|
+
|
|
435
|
+
await waitForRuntimeAssertion(() =>
|
|
436
|
+
(globalThis as typeof globalThis & { __MANDU_TEST_EXPLICIT_ISLAND_DATA__?: { label?: string } }).__MANDU_TEST_EXPLICIT_ISLAND_DATA__?.label === "data-props"
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test("runtime falls back to route-level server data when boundary-local props are absent", async () => {
|
|
441
|
+
const modulePath = path.join(rootDir, ".mandu", "client", "runtime-route-data-fallback.js");
|
|
442
|
+
await writeFile(
|
|
443
|
+
modulePath,
|
|
444
|
+
`
|
|
445
|
+
export default function RouteFallbackBoundary(props) {
|
|
446
|
+
globalThis.__MANDU_TEST_ROUTE_DATA_FALLBACK_PROPS__ = props;
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
`,
|
|
450
|
+
"utf-8",
|
|
451
|
+
);
|
|
452
|
+
Object.assign(globalThis, {
|
|
453
|
+
__MANDU_TEST_ROUTE_DATA_FALLBACK_PROPS__: undefined,
|
|
454
|
+
});
|
|
455
|
+
document.body.innerHTML = `
|
|
456
|
+
<div
|
|
457
|
+
data-mandu-island="route-fallback--0"
|
|
458
|
+
data-mandu-boundary-id="route-fallback--0"
|
|
459
|
+
data-mandu-route-id="route-fallback"
|
|
460
|
+
data-mandu-src="${pathToFileURL(modulePath).href}?t=${Date.now()}"
|
|
461
|
+
data-hydrate="load"
|
|
462
|
+
></div>
|
|
463
|
+
`;
|
|
464
|
+
(window as typeof window & { __MANDU_DATA__?: unknown; __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_DATA__ = {
|
|
465
|
+
"route-fallback": { serverData: { label: "route-level" } },
|
|
466
|
+
};
|
|
467
|
+
(window as typeof window & { __MANDU_ROOTS__?: Map<string, unknown> }).__MANDU_ROOTS__ = new Map();
|
|
468
|
+
|
|
469
|
+
const runtime = await evaluateGeneratedHydrationRuntime();
|
|
470
|
+
runtime.hydrateIslands();
|
|
471
|
+
|
|
472
|
+
await waitForRuntimeAssertion(() =>
|
|
473
|
+
(globalThis as typeof globalThis & { __MANDU_TEST_ROUTE_DATA_FALLBACK_PROPS__?: { label?: string } }).__MANDU_TEST_ROUTE_DATA_FALLBACK_PROPS__?.label === "route-level"
|
|
474
|
+
);
|
|
475
|
+
});
|
|
476
|
+
|
|
217
477
|
test("does not bundle a server page when stale manifest marks page.tsx as clientModule", async () => {
|
|
218
478
|
const staleRoot = await mkRepoTempDir("stale-client-module-");
|
|
219
479
|
try {
|
|
@@ -404,5 +664,214 @@ describe("buildClientBundles vendor shims", () => {
|
|
|
404
664
|
} finally {
|
|
405
665
|
await rm(missingRoot, { recursive: true, force: true });
|
|
406
666
|
}
|
|
407
|
-
});
|
|
408
|
-
});
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
describe("buildClientBundles client boundaries", () => {
|
|
671
|
+
async function createBoundaryFixture(prefix: string): Promise<string> {
|
|
672
|
+
const boundaryRoot = await mkRepoTempDir(prefix);
|
|
673
|
+
await mkdir(path.join(boundaryRoot, "app", "boundary"), { recursive: true });
|
|
674
|
+
await mkdir(path.join(boundaryRoot, "src", "client"), { recursive: true });
|
|
675
|
+
await writeFile(
|
|
676
|
+
path.join(boundaryRoot, "package.json"),
|
|
677
|
+
JSON.stringify({ name: "mandu-boundary-test", type: "module" }, null, 2),
|
|
678
|
+
"utf-8",
|
|
679
|
+
);
|
|
680
|
+
await writeFile(
|
|
681
|
+
path.join(boundaryRoot, "app", "boundary", "page.tsx"),
|
|
682
|
+
"export default function Page() { return null; }\n",
|
|
683
|
+
"utf-8",
|
|
684
|
+
);
|
|
685
|
+
await writeFile(
|
|
686
|
+
path.join(boundaryRoot, "src", "client", "BoundaryWidget.client.tsx"),
|
|
687
|
+
`
|
|
688
|
+
import React from "react";
|
|
689
|
+
|
|
690
|
+
export default function WrongDefault({ label }) {
|
|
691
|
+
return React.createElement("p", null, "default:" + label);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export function BoundaryWidget({ label }) {
|
|
695
|
+
return React.createElement("button", null, "named:" + label);
|
|
696
|
+
}
|
|
697
|
+
`,
|
|
698
|
+
"utf-8",
|
|
699
|
+
);
|
|
700
|
+
return boundaryRoot;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
test("emits boundary bundle manifest entries", async () => {
|
|
704
|
+
const boundaryRoot = await createBoundaryFixture("bundler-boundary-");
|
|
705
|
+
try {
|
|
706
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary");
|
|
707
|
+
|
|
708
|
+
if (!boundaryResult.success) {
|
|
709
|
+
console.error("[build.test boundary] errors:", boundaryResult.errors);
|
|
710
|
+
}
|
|
711
|
+
expect(boundaryResult.success).toBe(true);
|
|
712
|
+
expect(boundaryResult.manifest?.boundaries?.["boundary-demo--0"]).toMatchObject({
|
|
713
|
+
route: "boundary-demo",
|
|
714
|
+
module: "src/client/BoundaryWidget.client.tsx",
|
|
715
|
+
exportName: "BoundaryWidget",
|
|
716
|
+
hydrate: "visible",
|
|
717
|
+
});
|
|
718
|
+
expect(boundaryResult.manifest?.boundaries?.["boundary-demo--0"]?.js).toMatch(
|
|
719
|
+
/^\/\.mandu\/client\/boundary-demo--0\.boundary\.js$/,
|
|
720
|
+
);
|
|
721
|
+
expect(boundaryResult.manifest?.bundles?.["boundary-demo"]).toBeUndefined();
|
|
722
|
+
|
|
723
|
+
const refreshGlobal = globalThis as typeof globalThis & {
|
|
724
|
+
$RefreshReg$?: unknown;
|
|
725
|
+
$RefreshSig$?: unknown;
|
|
726
|
+
};
|
|
727
|
+
refreshGlobal.$RefreshReg$ = () => {};
|
|
728
|
+
refreshGlobal.$RefreshSig$ = () => (type: unknown) => type;
|
|
729
|
+
try {
|
|
730
|
+
const boundaryBundle = await import(
|
|
731
|
+
`${pathToFileURL(path.join(boundaryRoot, ".mandu", "client", "boundary-demo--0.boundary.js")).href}?t=${Date.now()}`
|
|
732
|
+
);
|
|
733
|
+
const React = await import("react");
|
|
734
|
+
const { renderToStaticMarkup } = await import("react-dom/server");
|
|
735
|
+
|
|
736
|
+
expect(typeof boundaryBundle.default).toBe("function");
|
|
737
|
+
expect(typeof boundaryBundle.BoundaryWidget).toBe("function");
|
|
738
|
+
expect(renderToStaticMarkup(React.createElement(boundaryBundle.default, { label: "ok" }))).toContain("named:ok");
|
|
739
|
+
expect(renderToStaticMarkup(React.createElement(boundaryBundle.BoundaryWidget, { label: "ok" }))).toContain("named:ok");
|
|
740
|
+
} finally {
|
|
741
|
+
delete refreshGlobal.$RefreshReg$;
|
|
742
|
+
delete refreshGlobal.$RefreshSig$;
|
|
743
|
+
}
|
|
744
|
+
} finally {
|
|
745
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
test("snapshots route and bundle boundary metadata", async () => {
|
|
750
|
+
const boundaryRoot = await createBoundaryFixture("bundler-boundary-snapshot-");
|
|
751
|
+
try {
|
|
752
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary");
|
|
753
|
+
expect(boundaryResult.success).toBe(true);
|
|
754
|
+
|
|
755
|
+
toMatchSnapshot(
|
|
756
|
+
{
|
|
757
|
+
routes: boundaryResult.manifest?.routes?.map((route) => ({
|
|
758
|
+
id: route.id,
|
|
759
|
+
module: route.module,
|
|
760
|
+
componentModule: route.componentModule,
|
|
761
|
+
boundaries: route.boundaries,
|
|
762
|
+
})),
|
|
763
|
+
bundleBoundaries: boundaryResult.manifest?.boundaries,
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
testFile: path.join(import.meta.dir, "build.test.ts"),
|
|
767
|
+
name: "client boundary manifest metadata",
|
|
768
|
+
},
|
|
769
|
+
);
|
|
770
|
+
} finally {
|
|
771
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
test("updates boundary manifest entries in target-route builds", async () => {
|
|
776
|
+
const boundaryRoot = await createBoundaryFixture("bundler-boundary-target-");
|
|
777
|
+
try {
|
|
778
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary-target");
|
|
779
|
+
expect(boundaryResult.success).toBe(true);
|
|
780
|
+
expect(boundaryResult.manifest?.boundaries?.["boundary-demo--0"]?.js).toBe(
|
|
781
|
+
"/.mandu/client/boundary-demo--0.boundary.js",
|
|
782
|
+
);
|
|
783
|
+
} finally {
|
|
784
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
test("fails before manifest generation when boundary ids are duplicated", async () => {
|
|
789
|
+
const boundaryRoot = await createBoundaryFixture("bundler-boundary-duplicate-");
|
|
790
|
+
try {
|
|
791
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary-duplicate-id");
|
|
792
|
+
|
|
793
|
+
expect(boundaryResult.success).toBe(false);
|
|
794
|
+
expect(boundaryResult.errors.join("\n")).toContain("MANDU_BOUNDARY_DUPLICATE_ID");
|
|
795
|
+
expect(boundaryResult.errors.join("\n")).toContain("boundary-demo--0");
|
|
796
|
+
} finally {
|
|
797
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
test("updates boundary manifest entries when framework bundles are skipped", async () => {
|
|
802
|
+
const boundaryRoot = await createBoundaryFixture("bundler-boundary-skip-");
|
|
803
|
+
try {
|
|
804
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary-skip-framework");
|
|
805
|
+
expect(boundaryResult.success).toBe(true);
|
|
806
|
+
expect(boundaryResult.manifest?.boundaries?.["boundary-demo--0"]?.js).toBe(
|
|
807
|
+
"/.mandu/client/boundary-demo--0.boundary.js",
|
|
808
|
+
);
|
|
809
|
+
} finally {
|
|
810
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
test("builds manifest-generated boundaries from route-owned server wrappers", async () => {
|
|
815
|
+
const boundaryRoot = await mkRepoTempDir("bundler-boundary-generated-wrapper-");
|
|
816
|
+
try {
|
|
817
|
+
await mkdir(path.join(boundaryRoot, "app", "account", "components"), { recursive: true });
|
|
818
|
+
await writeFile(
|
|
819
|
+
path.join(boundaryRoot, "package.json"),
|
|
820
|
+
JSON.stringify({ name: "mandu-boundary-generated-wrapper-test", type: "module" }, null, 2),
|
|
821
|
+
"utf-8",
|
|
822
|
+
);
|
|
823
|
+
await writeFile(
|
|
824
|
+
path.join(boundaryRoot, "app", "account", "page.tsx"),
|
|
825
|
+
`
|
|
826
|
+
import { AccountShell } from "./components/AccountShell";
|
|
827
|
+
|
|
828
|
+
export default function Page() {
|
|
829
|
+
return <main><AccountShell name="Ada" /></main>;
|
|
830
|
+
}
|
|
831
|
+
`,
|
|
832
|
+
"utf-8",
|
|
833
|
+
);
|
|
834
|
+
await writeFile(
|
|
835
|
+
path.join(boundaryRoot, "app", "account", "components", "AccountShell.tsx"),
|
|
836
|
+
`
|
|
837
|
+
import { AccountCard } from "./AccountCard.client";
|
|
838
|
+
|
|
839
|
+
export function AccountShell({ name }) {
|
|
840
|
+
return <AccountCard name={name} />;
|
|
841
|
+
}
|
|
842
|
+
`,
|
|
843
|
+
"utf-8",
|
|
844
|
+
);
|
|
845
|
+
await writeFile(
|
|
846
|
+
path.join(boundaryRoot, "app", "account", "components", "AccountCard.client.tsx"),
|
|
847
|
+
`
|
|
848
|
+
import React from "react";
|
|
849
|
+
export function AccountCard({ name }) {
|
|
850
|
+
return React.createElement("button", null, name);
|
|
851
|
+
}
|
|
852
|
+
`,
|
|
853
|
+
"utf-8",
|
|
854
|
+
);
|
|
855
|
+
|
|
856
|
+
const boundaryResult = await runBuildInSubprocess(boundaryRoot, "client-boundary-generated-transitive");
|
|
857
|
+
|
|
858
|
+
if (!boundaryResult.success) {
|
|
859
|
+
console.error("[build.test generated boundary] errors:", boundaryResult.errors);
|
|
860
|
+
}
|
|
861
|
+
expect(boundaryResult.success).toBe(true);
|
|
862
|
+
expect(boundaryResult.manifest?.boundaries?.["account--0"]).toMatchObject({
|
|
863
|
+
route: "account",
|
|
864
|
+
module: "app/account/components/AccountCard.client.tsx",
|
|
865
|
+
exportName: "AccountCard",
|
|
866
|
+
hydrate: "visible",
|
|
867
|
+
});
|
|
868
|
+
expect(boundaryResult.manifest?.boundaries?.["account--0"]?.js).toBe(
|
|
869
|
+
"/.mandu/client/account--0.boundary.js",
|
|
870
|
+
);
|
|
871
|
+
expect(boundaryResult.manifest?.bundles?.account).toBeUndefined();
|
|
872
|
+
expect(await Bun.file(path.join(boundaryRoot, ".mandu", "client", "account--0.boundary.js")).exists()).toBe(true);
|
|
873
|
+
} finally {
|
|
874
|
+
await rm(boundaryRoot, { recursive: true, force: true });
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
});
|