@sigil-dev/grimoire 0.9.4 → 0.9.6
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/index.ts +37 -37
- package/package.json +3 -3
- package/preload.js +3 -3
- package/server.ts +19 -19
- package/src/client/deps.ts +36 -36
- package/src/client/enhance.ts +102 -102
- package/src/client/head.ts +30 -30
- package/src/client/index.ts +5 -5
- package/src/client/router.ts +128 -38
- package/src/client/scope.ts +22 -22
- package/src/dev/compile-module.ts +215 -163
- package/src/dev/effect-registry.ts +23 -23
- package/src/dev/graph.ts +109 -114
- package/src/dev/hmr-client.ts +202 -185
- package/src/dev/hmr-server.ts +261 -187
- package/src/dev/loader.ts +120 -47
- package/src/dev/paths.ts +14 -14
- package/src/dev/resolve.ts +70 -0
- package/src/dev/runtime-bundle.ts +52 -52
- package/src/dev/scan.ts +78 -0
- package/src/dev/watcher.ts +69 -47
- package/src/env/dynamic-private.ts +19 -19
- package/src/env/dynamic-public.ts +22 -22
- package/src/env/index.ts +25 -25
- package/src/env/plugin.ts +19 -19
- package/src/env/private.ts +5 -5
- package/src/env/public.ts +7 -7
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +114 -114
- package/src/integrations/vite.ts +73 -73
- package/src/logger/index.ts +4 -4
- package/src/logger/instance.ts +6 -6
- package/src/logger/logger.ts +113 -113
- package/src/logger/request-middleware.ts +24 -24
- package/src/logger/transports.ts +117 -117
- package/src/logger/types.ts +39 -39
- package/src/rendering/head.ts +52 -47
- package/src/rendering/hydrate.ts +16 -3
- package/src/rendering/index.ts +43 -17
- package/src/rendering/ssrPlugin.ts +78 -69
- package/src/routing/manifest-gen.ts +55 -55
- package/src/routing/router.ts +135 -135
- package/src/routing/scanner.ts +196 -187
- package/src/routing/transform-routes.ts +102 -102
- package/src/sentinels/error.ts +52 -52
- package/src/sentinels/fail.ts +41 -41
- package/src/sentinels/redirect.ts +35 -35
- package/src/server/build.ts +250 -255
- package/src/server/context.ts +10 -10
- package/src/server/cookie-utils.ts +66 -66
- package/src/server/coordinator.ts +1 -1
- package/src/server/hooks.ts +114 -114
- package/src/server/index.ts +110 -69
- package/src/server/interactive.ts +56 -56
- package/src/server/plugins.ts +121 -121
- package/src/server/worker.ts +58 -58
- package/src/typegen/index.ts +389 -389
- package/src/types.ts +286 -286
- package/test/client-router.test.ts +76 -8
- package/test/context.test.ts +52 -52
- package/test/env.test.ts +90 -90
- package/test/exports.test.ts +37 -37
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +100 -100
- package/test/hmr.test.ts +426 -0
- package/test/hydration.test.ts +119 -119
- package/test/middleware.test.ts +223 -223
- package/test/preload.ts +5 -5
- package/test/redirect-error.test.ts +112 -112
- package/test/rendering.test.ts +719 -728
- package/test/routing.test.ts +197 -194
- package/test/scanning.test.ts +314 -254
- package/test/scope.test.ts +195 -195
- package/test/server.test.ts +360 -354
- package/test/streaming.test.ts +40 -1
- package/test/transform-routes.test.ts +87 -87
- package/test/typegen.test.ts +697 -697
- package/tsconfig.json +10 -10
package/test/streaming.test.ts
CHANGED
|
@@ -128,6 +128,45 @@ describe("Streaming SSR", () => {
|
|
|
128
128
|
expect(json.data).toBeDefined();
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
+
// The JSON payload and the HTML document share one URL and are picked by a
|
|
132
|
+
// request header. Without Vary any cache may serve the JSON to a plain
|
|
133
|
+
// document request, which rendered the raw state object as the page.
|
|
134
|
+
test("navigation JSON declares Vary on the navigate header", async () => {
|
|
135
|
+
const matched = makeMatched(
|
|
136
|
+
"/nav-vary",
|
|
137
|
+
"data:text/javascript,export default (p) => '<div>nav</div>'",
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const res = await renderRoute(
|
|
141
|
+
matched,
|
|
142
|
+
new Request("http://localhost/nav-vary", {
|
|
143
|
+
headers: { "x-grimoire-navigate": "1" },
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(res.headers.get("content-type")).toContain("application/json");
|
|
148
|
+
expect(res.headers.get("vary")?.toLowerCase()).toContain(
|
|
149
|
+
"x-grimoire-navigate",
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("HTML document declares Vary on the navigate header", async () => {
|
|
154
|
+
const matched = makeMatched(
|
|
155
|
+
"/doc-vary",
|
|
156
|
+
"data:text/javascript,export default (p) => '<div>doc</div>'",
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const res = await renderRoute(
|
|
160
|
+
matched,
|
|
161
|
+
new Request("http://localhost/doc-vary"),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(res.headers.get("content-type")).toContain("text/html");
|
|
165
|
+
expect(res.headers.get("vary")?.toLowerCase()).toContain(
|
|
166
|
+
"x-grimoire-navigate",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
131
170
|
test("state JSON escapes </script> in data (XSS)", async () => {
|
|
132
171
|
const evil = "</script><script>alert(1)</script>";
|
|
133
172
|
const src = [
|
|
@@ -188,7 +227,7 @@ describe("streamed promises (deferred data)", () => {
|
|
|
188
227
|
await writeFile(join(dir, "+page.server.ts"), serverSrc);
|
|
189
228
|
await writeFile(
|
|
190
229
|
join(dir, "+page.tsx"),
|
|
191
|
-
|
|
230
|
+
"export default function P({ data }) { return <div>{data.fast}{String(data.slow)}{String(data.boom)}</div>; }",
|
|
192
231
|
);
|
|
193
232
|
const tree = await scanRoutes(dir);
|
|
194
233
|
const matched = matchRoute(tree, new URL("http://localhost/"));
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import type { RouteFile } from "../src/routing/scanner";
|
|
6
|
-
import { transformRoutes } from "../src/routing/transform-routes";
|
|
7
|
-
|
|
8
|
-
describe("transformRoutes", () => {
|
|
9
|
-
test("pre-transforms TypeScript TSX routes to unique JavaScript files", async () => {
|
|
10
|
-
const root = await mkdtemp(join(tmpdir(), "grimoire-transform-"));
|
|
11
|
-
try {
|
|
12
|
-
const routesDir = join(root, "src", "routes");
|
|
13
|
-
const spellDir = join(routesDir, "spells", "[id]");
|
|
14
|
-
const otherDir = join(routesDir, "other");
|
|
15
|
-
const outDir = join(root, ".grimoire", "compiled");
|
|
16
|
-
await mkdir(spellDir, { recursive: true });
|
|
17
|
-
await mkdir(otherDir, { recursive: true });
|
|
18
|
-
await mkdir(outDir, { recursive: true });
|
|
19
|
-
|
|
20
|
-
const spellRoute = join(spellDir, "+page.tsx");
|
|
21
|
-
const otherRoute = join(otherDir, "+page.tsx");
|
|
22
|
-
const spellData = join(spellDir, "data.ts");
|
|
23
|
-
await writeFile(
|
|
24
|
-
spellData,
|
|
25
|
-
`
|
|
26
|
-
export const SPELLS = { fire: "Fire" } as const;
|
|
27
|
-
`,
|
|
28
|
-
);
|
|
29
|
-
await writeFile(
|
|
30
|
-
spellRoute,
|
|
31
|
-
`
|
|
32
|
-
import { SPELLS } from "./data";
|
|
33
|
-
type PageProps = { params: { id: keyof typeof SPELLS } };
|
|
34
|
-
|
|
35
|
-
export default function Page({ params }: PageProps) {
|
|
36
|
-
const n: number = 1;
|
|
37
|
-
return <h1>{SPELLS[params.id] ?? n}</h1>;
|
|
38
|
-
}
|
|
39
|
-
`,
|
|
40
|
-
);
|
|
41
|
-
await writeFile(
|
|
42
|
-
otherRoute,
|
|
43
|
-
`
|
|
44
|
-
export default function Other({ count }: { count: number }) {
|
|
45
|
-
return <p>{count}</p>;
|
|
46
|
-
}
|
|
47
|
-
`,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const routes: RouteFile[] = [
|
|
51
|
-
route(spellRoute, "/spells/:id"),
|
|
52
|
-
route(otherRoute, "/other"),
|
|
53
|
-
];
|
|
54
|
-
const files = await transformRoutes(routes, outDir, "dom");
|
|
55
|
-
|
|
56
|
-
const spellOut = files.get(spellRoute);
|
|
57
|
-
const otherOut = files.get(otherRoute);
|
|
58
|
-
expect(spellOut).not.toEqual(otherOut);
|
|
59
|
-
expect(spellOut).toContain(".dom.js");
|
|
60
|
-
expect(otherOut).toContain(".dom.js");
|
|
61
|
-
|
|
62
|
-
const code = await readFile(spellOut!, "utf8");
|
|
63
|
-
expect(code).toContain("export default function Page");
|
|
64
|
-
expect(code).toContain(
|
|
65
|
-
spellData.replace(/\.ts$/, "").replace(/\\/g, "\\\\"),
|
|
66
|
-
);
|
|
67
|
-
expect(code).not.toContain(": number");
|
|
68
|
-
expect(code).not.toContain("keyof typeof");
|
|
69
|
-
expect(code).not.toContain("as const");
|
|
70
|
-
} finally {
|
|
71
|
-
await rm(root, { recursive: true, force: true });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
function route(filePath: string, path: string): RouteFile {
|
|
77
|
-
return {
|
|
78
|
-
path,
|
|
79
|
-
filePath,
|
|
80
|
-
clientPath: filePath,
|
|
81
|
-
type: "page",
|
|
82
|
-
paramNames: [],
|
|
83
|
-
optionalParamNames: [],
|
|
84
|
-
restParamNames: [],
|
|
85
|
-
paramMatchers: {},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { RouteFile } from "../src/routing/scanner";
|
|
6
|
+
import { transformRoutes } from "../src/routing/transform-routes";
|
|
7
|
+
|
|
8
|
+
describe("transformRoutes", () => {
|
|
9
|
+
test("pre-transforms TypeScript TSX routes to unique JavaScript files", async () => {
|
|
10
|
+
const root = await mkdtemp(join(tmpdir(), "grimoire-transform-"));
|
|
11
|
+
try {
|
|
12
|
+
const routesDir = join(root, "src", "routes");
|
|
13
|
+
const spellDir = join(routesDir, "spells", "[id]");
|
|
14
|
+
const otherDir = join(routesDir, "other");
|
|
15
|
+
const outDir = join(root, ".grimoire", "compiled");
|
|
16
|
+
await mkdir(spellDir, { recursive: true });
|
|
17
|
+
await mkdir(otherDir, { recursive: true });
|
|
18
|
+
await mkdir(outDir, { recursive: true });
|
|
19
|
+
|
|
20
|
+
const spellRoute = join(spellDir, "+page.tsx");
|
|
21
|
+
const otherRoute = join(otherDir, "+page.tsx");
|
|
22
|
+
const spellData = join(spellDir, "data.ts");
|
|
23
|
+
await writeFile(
|
|
24
|
+
spellData,
|
|
25
|
+
`
|
|
26
|
+
export const SPELLS = { fire: "Fire" } as const;
|
|
27
|
+
`,
|
|
28
|
+
);
|
|
29
|
+
await writeFile(
|
|
30
|
+
spellRoute,
|
|
31
|
+
`
|
|
32
|
+
import { SPELLS } from "./data";
|
|
33
|
+
type PageProps = { params: { id: keyof typeof SPELLS } };
|
|
34
|
+
|
|
35
|
+
export default function Page({ params }: PageProps) {
|
|
36
|
+
const n: number = 1;
|
|
37
|
+
return <h1>{SPELLS[params.id] ?? n}</h1>;
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
);
|
|
41
|
+
await writeFile(
|
|
42
|
+
otherRoute,
|
|
43
|
+
`
|
|
44
|
+
export default function Other({ count }: { count: number }) {
|
|
45
|
+
return <p>{count}</p>;
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const routes: RouteFile[] = [
|
|
51
|
+
route(spellRoute, "/spells/:id"),
|
|
52
|
+
route(otherRoute, "/other"),
|
|
53
|
+
];
|
|
54
|
+
const files = await transformRoutes(routes, outDir, "dom");
|
|
55
|
+
|
|
56
|
+
const spellOut = files.get(spellRoute);
|
|
57
|
+
const otherOut = files.get(otherRoute);
|
|
58
|
+
expect(spellOut).not.toEqual(otherOut);
|
|
59
|
+
expect(spellOut).toContain(".dom.js");
|
|
60
|
+
expect(otherOut).toContain(".dom.js");
|
|
61
|
+
|
|
62
|
+
const code = await readFile(spellOut!, "utf8");
|
|
63
|
+
expect(code).toContain("export default function Page");
|
|
64
|
+
expect(code).toContain(
|
|
65
|
+
spellData.replace(/\.ts$/, "").replace(/\\/g, "\\\\"),
|
|
66
|
+
);
|
|
67
|
+
expect(code).not.toContain(": number");
|
|
68
|
+
expect(code).not.toContain("keyof typeof");
|
|
69
|
+
expect(code).not.toContain("as const");
|
|
70
|
+
} finally {
|
|
71
|
+
await rm(root, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
function route(filePath: string, path: string): RouteFile {
|
|
77
|
+
return {
|
|
78
|
+
path,
|
|
79
|
+
filePath,
|
|
80
|
+
clientPath: filePath,
|
|
81
|
+
type: "page",
|
|
82
|
+
paramNames: [],
|
|
83
|
+
optionalParamNames: [],
|
|
84
|
+
restParamNames: [],
|
|
85
|
+
paramMatchers: {},
|
|
86
|
+
};
|
|
87
|
+
}
|