@sigil-dev/grimoire 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/index.ts +37 -37
  2. package/package.json +3 -3
  3. package/preload.js +3 -3
  4. package/server.ts +19 -19
  5. package/src/client/deps.ts +36 -36
  6. package/src/client/enhance.ts +102 -102
  7. package/src/client/head.ts +30 -30
  8. package/src/client/index.ts +5 -5
  9. package/src/client/router.ts +42 -20
  10. package/src/client/scope.ts +22 -22
  11. package/src/dev/compile-module.ts +215 -163
  12. package/src/dev/effect-registry.ts +23 -23
  13. package/src/dev/graph.ts +109 -114
  14. package/src/dev/hmr-client.ts +202 -185
  15. package/src/dev/hmr-server.ts +261 -187
  16. package/src/dev/loader.ts +120 -47
  17. package/src/dev/paths.ts +14 -14
  18. package/src/dev/resolve.ts +70 -0
  19. package/src/dev/runtime-bundle.ts +52 -52
  20. package/src/dev/scan.ts +78 -0
  21. package/src/dev/watcher.ts +69 -47
  22. package/src/env/dynamic-private.ts +19 -19
  23. package/src/env/dynamic-public.ts +22 -22
  24. package/src/env/index.ts +25 -25
  25. package/src/env/plugin.ts +19 -19
  26. package/src/env/private.ts +5 -5
  27. package/src/env/public.ts +7 -7
  28. package/src/env/typegen.ts +61 -61
  29. package/src/headers.ts +114 -114
  30. package/src/integrations/vite.ts +73 -73
  31. package/src/logger/index.ts +4 -4
  32. package/src/logger/instance.ts +6 -6
  33. package/src/logger/logger.ts +113 -113
  34. package/src/logger/request-middleware.ts +24 -24
  35. package/src/logger/transports.ts +117 -117
  36. package/src/logger/types.ts +39 -39
  37. package/src/rendering/head.ts +52 -47
  38. package/src/rendering/hydrate.ts +16 -3
  39. package/src/rendering/index.ts +10 -6
  40. package/src/rendering/ssrPlugin.ts +78 -69
  41. package/src/routing/manifest-gen.ts +55 -55
  42. package/src/routing/router.ts +135 -135
  43. package/src/routing/scanner.ts +196 -187
  44. package/src/routing/transform-routes.ts +102 -102
  45. package/src/sentinels/error.ts +52 -52
  46. package/src/sentinels/fail.ts +41 -41
  47. package/src/sentinels/redirect.ts +35 -35
  48. package/src/server/build.ts +250 -255
  49. package/src/server/context.ts +10 -10
  50. package/src/server/cookie-utils.ts +66 -66
  51. package/src/server/coordinator.ts +364 -364
  52. package/src/server/hooks.ts +114 -114
  53. package/src/server/index.ts +711 -677
  54. package/src/server/interactive.ts +56 -56
  55. package/src/server/plugins.ts +121 -121
  56. package/src/server/worker.ts +58 -58
  57. package/src/typegen/index.ts +389 -389
  58. package/src/types.ts +286 -286
  59. package/test/client-router.test.ts +295 -298
  60. package/test/context.test.ts +52 -52
  61. package/test/env.test.ts +90 -90
  62. package/test/exports.test.ts +37 -37
  63. package/test/fail.test.ts +46 -46
  64. package/test/headers.test.ts +100 -100
  65. package/test/hmr.test.ts +426 -0
  66. package/test/hydration.test.ts +119 -119
  67. package/test/middleware.test.ts +223 -223
  68. package/test/preload.ts +5 -5
  69. package/test/redirect-error.test.ts +112 -112
  70. package/test/rendering.test.ts +719 -728
  71. package/test/routing.test.ts +197 -194
  72. package/test/scanning.test.ts +314 -254
  73. package/test/scope.test.ts +195 -195
  74. package/test/server.test.ts +360 -354
  75. package/test/streaming.test.ts +242 -242
  76. package/test/transform-routes.test.ts +87 -87
  77. package/test/typegen.test.ts +697 -697
  78. package/tsconfig.json +10 -10
@@ -1,254 +1,314 @@
1
- import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
- import { mkdir, rm, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { filePathToRoutePath, scanRoutes } from "../src/routing/scanner";
6
-
7
- describe("File scanning", () => {
8
- test("index.tsx → /", () => {
9
- expect(filePathToRoutePath("/app/routes/index.tsx", "/app/routes")).toEqual(
10
- { pattern: "/", params: [], optionalParams: [], paramMatchers: {}, restParams: [] },
11
- );
12
- });
13
-
14
- test("about.tsx → /about", () => {
15
- expect(filePathToRoutePath("/app/routes/about.tsx", "/app/routes")).toEqual(
16
- { pattern: "/about", params: [], optionalParams: [], paramMatchers: {}, restParams: [] },
17
- );
18
- });
19
-
20
- test("[slug].tsx → /:slug", () => {
21
- expect(
22
- filePathToRoutePath("/app/routes/[slug].tsx", "/app/routes"),
23
- ).toEqual({ pattern: "/:slug", params: ["slug"], optionalParams: [], paramMatchers: {}, restParams: [] });
24
- });
25
-
26
- test("blog/+page.tsx → /blog", () => {
27
- expect(
28
- filePathToRoutePath("/app/routes/blog/+page.tsx", "/app/routes"),
29
- ).toEqual({ pattern: "/blog", params: [], optionalParams: [], paramMatchers: {}, restParams: [] });
30
- });
31
-
32
- test("blog/[slug]/+page.tsx → /blog/:slug", () => {
33
- expect(
34
- filePathToRoutePath("/app/routes/blog/[slug]/+page.tsx", "/app/routes"),
35
- ).toEqual({ pattern: "/blog/:slug", params: ["slug"], optionalParams: [], paramMatchers: {}, restParams: [] });
36
- });
37
-
38
- test("blog/[slug]/+page.server.ts → /blog/:slug", () => {
39
- expect(
40
- filePathToRoutePath(
41
- "/app/routes/blog/[slug]/+page.server.ts",
42
- "/app/routes",
43
- ),
44
- ).toEqual({ pattern: "/blog/:slug", params: ["slug"], optionalParams: [], paramMatchers: {}, restParams: [] });
45
- });
46
-
47
- test("+layout.tsx → /", () => {
48
- expect(
49
- filePathToRoutePath("/app/routes/+layout.tsx", "/app/routes"),
50
- ).toEqual({ pattern: "/", params: [], optionalParams: [], paramMatchers: {}, restParams: [] });
51
- });
52
-
53
- test("nested +layout.tsx → /blog", () => {
54
- expect(
55
- filePathToRoutePath("/app/routes/blog/+layout.tsx", "/app/routes"),
56
- ).toEqual({ pattern: "/blog", params: [], optionalParams: [], paramMatchers: {}, restParams: [] });
57
- });
58
-
59
- test("[...rest].tsx → /*rest (catch-all)", () => {
60
- expect(
61
- filePathToRoutePath("/app/routes/[...rest].tsx", "/app/routes"),
62
- ).toEqual({ pattern: "/*rest", params: [], optionalParams: [], paramMatchers: {}, restParams: ["rest"] });
63
- });
64
-
65
- test("docs/[...path]/+server.ts → /docs/*path (nested catch-all)", () => {
66
- expect(
67
- filePathToRoutePath(
68
- "/app/routes/docs/[...path]/+server.ts",
69
- "/app/routes",
70
- ),
71
- ).toEqual({ pattern: "/docs/*path", params: [], optionalParams: [], paramMatchers: {}, restParams: ["path"] });
72
- });
73
-
74
- test("about/index.tsx, about/+page.tsx, and about.tsx all resolve to /about", () => {
75
- const index = filePathToRoutePath(
76
- "/app/routes/about/index.tsx",
77
- "/app/routes",
78
- );
79
- const page = filePathToRoutePath(
80
- "/app/routes/about/+page.tsx",
81
- "/app/routes",
82
- );
83
- const bare = filePathToRoutePath("/app/routes/about.tsx", "/app/routes");
84
- expect(index.pattern).toBe("/about");
85
- expect(page.pattern).toBe("/about");
86
- expect(bare.pattern).toBe("/about");
87
- });
88
-
89
- test("+server.ts resolves to the same path as +page.tsx", () => {
90
- const server = filePathToRoutePath(
91
- "/app/routes/api/items/+server.ts",
92
- "/app/routes",
93
- );
94
- expect(server.pattern).toBe("/api/items");
95
- });
96
-
97
- test("+error.tsx resolves to its directory path", () => {
98
- const root = filePathToRoutePath("/app/routes/+error.tsx", "/app/routes");
99
- const nested = filePathToRoutePath(
100
- "/app/routes/blog/+error.tsx",
101
- "/app/routes",
102
- );
103
- expect(root.pattern).toBe("/");
104
- expect(nested.pattern).toBe("/blog");
105
- });
106
-
107
- test("(group)/page/+page.tsx → /page", () => {
108
- const { pattern } = filePathToRoutePath(
109
- "/routes/(marketing)/about/+page.tsx",
110
- "/routes",
111
- );
112
- expect(pattern).toBe("/about");
113
- });
114
-
115
- test("nested groups collapse correctly", () => {
116
- const { pattern } = filePathToRoutePath(
117
- "/routes/(app)/(auth)/login/+page.tsx",
118
- "/routes",
119
- );
120
- expect(pattern).toBe("/login");
121
- });
122
-
123
- test("[[lang]]/index.tsx → /:lang? (optional)", () => {
124
- const result = filePathToRoutePath(
125
- "/app/routes/[[lang]]/index.tsx",
126
- "/app/routes",
127
- );
128
- expect(result.pattern).toBe("/:lang?");
129
- expect(result.optionalParams).toEqual(["lang"]);
130
- expect(result.params).toEqual([]);
131
- });
132
-
133
- test("optional and required params are collected separately", () => {
134
- const result = filePathToRoutePath(
135
- "/app/routes/[[lang]]/blog/[slug]/+page.tsx",
136
- "/app/routes",
137
- );
138
- expect(result.pattern).toBe("/:lang?/blog/:slug");
139
- expect(result.optionalParams).toEqual(["lang"]);
140
- expect(result.params).toEqual(["slug"]);
141
- });
142
- });
143
-
144
- describe("Custom param matchers", () => {
145
- test("[id=int].tsx → /:id with matcher recorded", () => {
146
- const result = filePathToRoutePath(
147
- "/app/routes/post/[id=int].tsx",
148
- "/app/routes",
149
- );
150
- expect(result.pattern).toBe("/post/:id");
151
- expect(result.paramMatchers).toEqual({ id: "int" });
152
- expect(result.params).toEqual(["id"]);
153
- });
154
-
155
- test("scanRoutes picks up src/params/*.ts beside src/routes", async () => {
156
- const root = join(tmpdir(), `grimoire-matchers-${Date.now()}`);
157
- const routesDir = join(root, "routes");
158
- const paramsDir = join(root, "params");
159
- await mkdir(join(routesDir, "post"), { recursive: true });
160
- await mkdir(paramsDir, { recursive: true });
161
- await writeFile(
162
- join(routesDir, "post", "[id=int].tsx"),
163
- "export default () => null",
164
- );
165
- await writeFile(
166
- join(paramsDir, "int.ts"),
167
- "export function match(v: string) { return /^\\d+$/.test(v); }",
168
- );
169
- const tree = await scanRoutes(routesDir);
170
- expect(tree.paramMatcherFiles).toEqual([
171
- { name: "int", filePath: join(paramsDir, "int.ts") },
172
- ]);
173
- expect(tree.routes[0]?.paramMatchers).toEqual({ id: "int" });
174
- await rm(root, { recursive: true });
175
- });
176
- });
177
-
178
- describe("Duplicate route detection", () => {
179
- let tmpDir: string;
180
-
181
- beforeAll(async () => {
182
- tmpDir = join(tmpdir(), `grimoire-scan-${Date.now()}`);
183
- await mkdir(tmpDir, { recursive: true });
184
- });
185
-
186
- afterAll(async () => {
187
- await rm(tmpDir, { recursive: true });
188
- });
189
-
190
- test("throws when two page files resolve to the same path", async () => {
191
- const dir = join(tmpDir, "dup-pages");
192
- await mkdir(join(dir, "about"), { recursive: true });
193
- await writeFile(join(dir, "about.tsx"), "export default () => null");
194
- await writeFile(
195
- join(dir, "about", "index.tsx"),
196
- "export default () => null",
197
- );
198
- await expect(scanRoutes(dir)).rejects.toThrow('Duplicate page at "/about"');
199
- });
200
-
201
- test("+page.tsx and +page.server.ts at the same path do NOT conflict", async () => {
202
- const dir = join(tmpDir, "no-conflict");
203
- await mkdir(join(dir, "blog"), { recursive: true });
204
- await writeFile(
205
- join(dir, "blog", "+page.tsx"),
206
- "export default () => null",
207
- );
208
- await writeFile(
209
- join(dir, "blog", "+page.server.ts"),
210
- "export async function load() {}",
211
- );
212
- await expect(scanRoutes(dir)).resolves.toBeDefined();
213
- });
214
-
215
- test("throws when two API routes resolve to the same path", async () => {
216
- const dir = join(tmpDir, "dup-server");
217
- await mkdir(join(dir, "api", "items"), { recursive: true });
218
- // Bun glob finds all files; we simulate two +server files at same path via subdirs
219
- // Use two different nesting depths that produce the same URL
220
- await mkdir(join(dir, "api2"), { recursive: true });
221
- await writeFile(
222
- join(dir, "api2", "+server.ts"),
223
- "export async function GET() {}",
224
- );
225
- await mkdir(join(dir, "api2", "index"), { recursive: true });
226
- // Can't easily duplicate +server.ts via nesting — test the named-file vs +server collision instead
227
- // Two +server.ts under different folder structures that map to same URL isn't possible without
228
- // [param] collisions, so verify a simple valid tree is fine
229
- await expect(scanRoutes(dir)).resolves.toBeDefined();
230
- });
231
-
232
- test("throws when two error pages resolve to the same path", async () => {
233
- const dir = join(tmpDir, "dup-error");
234
- await mkdir(join(dir, "blog"), { recursive: true });
235
- // Two +error.tsx at root level isn't possible via filesystem (same filename).
236
- // The real collision scenario is two dynamic segments mapping to the same pattern.
237
- // Test that a single error page is accepted without error.
238
- await writeFile(join(dir, "+error.tsx"), "export default () => null");
239
- await expect(scanRoutes(dir)).resolves.toBeDefined();
240
- });
241
-
242
- test("throws when a simple file and +page.tsx both resolve to the same path", async () => {
243
- const dir = join(tmpDir, "dup-mixed");
244
- await mkdir(join(dir, "contact"), { recursive: true });
245
- await writeFile(join(dir, "contact.tsx"), "export default () => null");
246
- await writeFile(
247
- join(dir, "contact", "+page.tsx"),
248
- "export default () => null",
249
- );
250
- await expect(scanRoutes(dir)).rejects.toThrow(
251
- 'Duplicate page at "/contact"',
252
- );
253
- });
254
- });
1
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
+ import { mkdir, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { filePathToRoutePath, scanRoutes } from "../src/routing/scanner";
6
+
7
+ describe("File scanning", () => {
8
+ test("index.tsx → /", () => {
9
+ expect(filePathToRoutePath("/app/routes/index.tsx", "/app/routes")).toEqual(
10
+ {
11
+ pattern: "/",
12
+ params: [],
13
+ optionalParams: [],
14
+ paramMatchers: {},
15
+ restParams: [],
16
+ },
17
+ );
18
+ });
19
+
20
+ test("about.tsx → /about", () => {
21
+ expect(filePathToRoutePath("/app/routes/about.tsx", "/app/routes")).toEqual(
22
+ {
23
+ pattern: "/about",
24
+ params: [],
25
+ optionalParams: [],
26
+ paramMatchers: {},
27
+ restParams: [],
28
+ },
29
+ );
30
+ });
31
+
32
+ test("[slug].tsx → /:slug", () => {
33
+ expect(
34
+ filePathToRoutePath("/app/routes/[slug].tsx", "/app/routes"),
35
+ ).toEqual({
36
+ pattern: "/:slug",
37
+ params: ["slug"],
38
+ optionalParams: [],
39
+ paramMatchers: {},
40
+ restParams: [],
41
+ });
42
+ });
43
+
44
+ test("blog/+page.tsx → /blog", () => {
45
+ expect(
46
+ filePathToRoutePath("/app/routes/blog/+page.tsx", "/app/routes"),
47
+ ).toEqual({
48
+ pattern: "/blog",
49
+ params: [],
50
+ optionalParams: [],
51
+ paramMatchers: {},
52
+ restParams: [],
53
+ });
54
+ });
55
+
56
+ test("blog/[slug]/+page.tsx → /blog/:slug", () => {
57
+ expect(
58
+ filePathToRoutePath("/app/routes/blog/[slug]/+page.tsx", "/app/routes"),
59
+ ).toEqual({
60
+ pattern: "/blog/:slug",
61
+ params: ["slug"],
62
+ optionalParams: [],
63
+ paramMatchers: {},
64
+ restParams: [],
65
+ });
66
+ });
67
+
68
+ test("blog/[slug]/+page.server.ts → /blog/:slug", () => {
69
+ expect(
70
+ filePathToRoutePath(
71
+ "/app/routes/blog/[slug]/+page.server.ts",
72
+ "/app/routes",
73
+ ),
74
+ ).toEqual({
75
+ pattern: "/blog/:slug",
76
+ params: ["slug"],
77
+ optionalParams: [],
78
+ paramMatchers: {},
79
+ restParams: [],
80
+ });
81
+ });
82
+
83
+ test("+layout.tsx → /", () => {
84
+ expect(
85
+ filePathToRoutePath("/app/routes/+layout.tsx", "/app/routes"),
86
+ ).toEqual({
87
+ pattern: "/",
88
+ params: [],
89
+ optionalParams: [],
90
+ paramMatchers: {},
91
+ restParams: [],
92
+ });
93
+ });
94
+
95
+ test("nested +layout.tsx → /blog", () => {
96
+ expect(
97
+ filePathToRoutePath("/app/routes/blog/+layout.tsx", "/app/routes"),
98
+ ).toEqual({
99
+ pattern: "/blog",
100
+ params: [],
101
+ optionalParams: [],
102
+ paramMatchers: {},
103
+ restParams: [],
104
+ });
105
+ });
106
+
107
+ test("[...rest].tsx → /*rest (catch-all)", () => {
108
+ expect(
109
+ filePathToRoutePath("/app/routes/[...rest].tsx", "/app/routes"),
110
+ ).toEqual({
111
+ pattern: "/*rest",
112
+ params: [],
113
+ optionalParams: [],
114
+ paramMatchers: {},
115
+ restParams: ["rest"],
116
+ });
117
+ });
118
+
119
+ test("docs/[...path]/+server.ts → /docs/*path (nested catch-all)", () => {
120
+ expect(
121
+ filePathToRoutePath(
122
+ "/app/routes/docs/[...path]/+server.ts",
123
+ "/app/routes",
124
+ ),
125
+ ).toEqual({
126
+ pattern: "/docs/*path",
127
+ params: [],
128
+ optionalParams: [],
129
+ paramMatchers: {},
130
+ restParams: ["path"],
131
+ });
132
+ });
133
+
134
+ test("about/index.tsx, about/+page.tsx, and about.tsx all resolve to /about", () => {
135
+ const index = filePathToRoutePath(
136
+ "/app/routes/about/index.tsx",
137
+ "/app/routes",
138
+ );
139
+ const page = filePathToRoutePath(
140
+ "/app/routes/about/+page.tsx",
141
+ "/app/routes",
142
+ );
143
+ const bare = filePathToRoutePath("/app/routes/about.tsx", "/app/routes");
144
+ expect(index.pattern).toBe("/about");
145
+ expect(page.pattern).toBe("/about");
146
+ expect(bare.pattern).toBe("/about");
147
+ });
148
+
149
+ test("+server.ts resolves to the same path as +page.tsx", () => {
150
+ const server = filePathToRoutePath(
151
+ "/app/routes/api/items/+server.ts",
152
+ "/app/routes",
153
+ );
154
+ expect(server.pattern).toBe("/api/items");
155
+ });
156
+
157
+ test("+error.tsx resolves to its directory path", () => {
158
+ const root = filePathToRoutePath("/app/routes/+error.tsx", "/app/routes");
159
+ const nested = filePathToRoutePath(
160
+ "/app/routes/blog/+error.tsx",
161
+ "/app/routes",
162
+ );
163
+ expect(root.pattern).toBe("/");
164
+ expect(nested.pattern).toBe("/blog");
165
+ });
166
+
167
+ test("(group)/page/+page.tsx → /page", () => {
168
+ const { pattern } = filePathToRoutePath(
169
+ "/routes/(marketing)/about/+page.tsx",
170
+ "/routes",
171
+ );
172
+ expect(pattern).toBe("/about");
173
+ });
174
+
175
+ test("nested groups collapse correctly", () => {
176
+ const { pattern } = filePathToRoutePath(
177
+ "/routes/(app)/(auth)/login/+page.tsx",
178
+ "/routes",
179
+ );
180
+ expect(pattern).toBe("/login");
181
+ });
182
+
183
+ test("[[lang]]/index.tsx → /:lang? (optional)", () => {
184
+ const result = filePathToRoutePath(
185
+ "/app/routes/[[lang]]/index.tsx",
186
+ "/app/routes",
187
+ );
188
+ expect(result.pattern).toBe("/:lang?");
189
+ expect(result.optionalParams).toEqual(["lang"]);
190
+ expect(result.params).toEqual([]);
191
+ });
192
+
193
+ test("optional and required params are collected separately", () => {
194
+ const result = filePathToRoutePath(
195
+ "/app/routes/[[lang]]/blog/[slug]/+page.tsx",
196
+ "/app/routes",
197
+ );
198
+ expect(result.pattern).toBe("/:lang?/blog/:slug");
199
+ expect(result.optionalParams).toEqual(["lang"]);
200
+ expect(result.params).toEqual(["slug"]);
201
+ });
202
+ });
203
+
204
+ describe("Custom param matchers", () => {
205
+ test("[id=int].tsx → /:id with matcher recorded", () => {
206
+ const result = filePathToRoutePath(
207
+ "/app/routes/post/[id=int].tsx",
208
+ "/app/routes",
209
+ );
210
+ expect(result.pattern).toBe("/post/:id");
211
+ expect(result.paramMatchers).toEqual({ id: "int" });
212
+ expect(result.params).toEqual(["id"]);
213
+ });
214
+
215
+ test("scanRoutes picks up src/params/*.ts beside src/routes", async () => {
216
+ const root = join(tmpdir(), `grimoire-matchers-${Date.now()}`);
217
+ const routesDir = join(root, "routes");
218
+ const paramsDir = join(root, "params");
219
+ await mkdir(join(routesDir, "post"), { recursive: true });
220
+ await mkdir(paramsDir, { recursive: true });
221
+ await writeFile(
222
+ join(routesDir, "post", "[id=int].tsx"),
223
+ "export default () => null",
224
+ );
225
+ await writeFile(
226
+ join(paramsDir, "int.ts"),
227
+ "export function match(v: string) { return /^\\d+$/.test(v); }",
228
+ );
229
+ const tree = await scanRoutes(routesDir);
230
+ expect(tree.paramMatcherFiles).toEqual([
231
+ { name: "int", filePath: join(paramsDir, "int.ts") },
232
+ ]);
233
+ expect(tree.routes[0]?.paramMatchers).toEqual({ id: "int" });
234
+ await rm(root, { recursive: true });
235
+ });
236
+ });
237
+
238
+ describe("Duplicate route detection", () => {
239
+ let tmpDir: string;
240
+
241
+ beforeAll(async () => {
242
+ tmpDir = join(tmpdir(), `grimoire-scan-${Date.now()}`);
243
+ await mkdir(tmpDir, { recursive: true });
244
+ });
245
+
246
+ afterAll(async () => {
247
+ await rm(tmpDir, { recursive: true });
248
+ });
249
+
250
+ test("throws when two page files resolve to the same path", async () => {
251
+ const dir = join(tmpDir, "dup-pages");
252
+ await mkdir(join(dir, "about"), { recursive: true });
253
+ await writeFile(join(dir, "about.tsx"), "export default () => null");
254
+ await writeFile(
255
+ join(dir, "about", "index.tsx"),
256
+ "export default () => null",
257
+ );
258
+ await expect(scanRoutes(dir)).rejects.toThrow('Duplicate page at "/about"');
259
+ });
260
+
261
+ test("+page.tsx and +page.server.ts at the same path do NOT conflict", async () => {
262
+ const dir = join(tmpDir, "no-conflict");
263
+ await mkdir(join(dir, "blog"), { recursive: true });
264
+ await writeFile(
265
+ join(dir, "blog", "+page.tsx"),
266
+ "export default () => null",
267
+ );
268
+ await writeFile(
269
+ join(dir, "blog", "+page.server.ts"),
270
+ "export async function load() {}",
271
+ );
272
+ await expect(scanRoutes(dir)).resolves.toBeDefined();
273
+ });
274
+
275
+ test("throws when two API routes resolve to the same path", async () => {
276
+ const dir = join(tmpDir, "dup-server");
277
+ await mkdir(join(dir, "api", "items"), { recursive: true });
278
+ // Bun glob finds all files; we simulate two +server files at same path via subdirs
279
+ // Use two different nesting depths that produce the same URL
280
+ await mkdir(join(dir, "api2"), { recursive: true });
281
+ await writeFile(
282
+ join(dir, "api2", "+server.ts"),
283
+ "export async function GET() {}",
284
+ );
285
+ await mkdir(join(dir, "api2", "index"), { recursive: true });
286
+ // Can't easily duplicate +server.ts via nesting — test the named-file vs +server collision instead
287
+ // Two +server.ts under different folder structures that map to same URL isn't possible without
288
+ // [param] collisions, so verify a simple valid tree is fine
289
+ await expect(scanRoutes(dir)).resolves.toBeDefined();
290
+ });
291
+
292
+ test("throws when two error pages resolve to the same path", async () => {
293
+ const dir = join(tmpDir, "dup-error");
294
+ await mkdir(join(dir, "blog"), { recursive: true });
295
+ // Two +error.tsx at root level isn't possible via filesystem (same filename).
296
+ // The real collision scenario is two dynamic segments mapping to the same pattern.
297
+ // Test that a single error page is accepted without error.
298
+ await writeFile(join(dir, "+error.tsx"), "export default () => null");
299
+ await expect(scanRoutes(dir)).resolves.toBeDefined();
300
+ });
301
+
302
+ test("throws when a simple file and +page.tsx both resolve to the same path", async () => {
303
+ const dir = join(tmpDir, "dup-mixed");
304
+ await mkdir(join(dir, "contact"), { recursive: true });
305
+ await writeFile(join(dir, "contact.tsx"), "export default () => null");
306
+ await writeFile(
307
+ join(dir, "contact", "+page.tsx"),
308
+ "export default () => null",
309
+ );
310
+ await expect(scanRoutes(dir)).rejects.toThrow(
311
+ 'Duplicate page at "/contact"',
312
+ );
313
+ });
314
+ });