@sigil-dev/grimoire 0.9.29 → 0.9.30
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/bin/sigil.ts +4 -0
- package/index.ts +16 -10
- package/package.json +14 -6
- package/server.ts +2 -2
- package/src/adapters/bun.ts +17 -17
- package/src/adapters/static.ts +41 -41
- package/src/adapters/types.ts +36 -36
- package/src/base.ts +4 -1
- package/src/client/csrf.ts +47 -47
- package/src/client/deferred.ts +1 -4
- package/src/client/enhance.ts +160 -160
- package/src/client/router.ts +927 -926
- package/src/config-file.ts +84 -0
- package/src/dev/compile-module.ts +199 -193
- package/src/dev/hmr-client.ts +229 -229
- package/src/dev/hmr-server.ts +274 -266
- package/src/dev/loader.ts +144 -144
- package/src/dev/runtime-bundle.ts +5 -3
- package/src/duration.ts +46 -0
- package/src/env/modules.ts +62 -62
- package/src/env/required.ts +42 -42
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +105 -105
- package/src/logger/transports.ts +117 -117
- package/src/plugin-order.ts +88 -0
- package/src/rendering/head.ts +49 -49
- package/src/rendering/hydrate.ts +162 -162
- package/src/rendering/images.ts +43 -43
- package/src/rendering/preload.ts +22 -8
- package/src/rendering/ssrPlugin.ts +107 -107
- package/src/rendering/timing.ts +40 -40
- package/src/routing/route-ids.ts +65 -0
- package/src/routing/route.ts +65 -0
- package/src/routing/router.ts +84 -32
- package/src/routing/scanner.ts +18 -5
- package/src/routing/transform-routes.ts +102 -102
- package/src/server/after-response.ts +206 -206
- package/src/server/asset-cache.ts +57 -57
- package/src/server/build.ts +304 -295
- package/src/server/cached.ts +114 -114
- package/src/server/client-address.ts +82 -82
- package/src/server/client-dir.ts +63 -63
- package/src/server/client-entry.ts +44 -44
- package/src/server/context.ts +18 -10
- package/src/server/cookie-utils.ts +80 -80
- package/src/server/coordinator.ts +476 -476
- package/src/server/hooks.ts +122 -122
- package/src/server/index.ts +8 -0
- package/src/server/plugins.ts +172 -172
- package/src/server/prerender.ts +473 -473
- package/src/server/reserved.ts +17 -17
- package/src/server/resolver.ts +149 -123
- package/src/server/rewrite.ts +28 -28
- package/src/server/warm.ts +9 -3
- package/src/server/with-headers.ts +27 -27
- package/src/server/worker.ts +2 -6
- package/src/server-only.ts +78 -0
- package/src/testing/dom.ts +73 -73
- package/src/testing/index.ts +169 -169
- package/src/testing/server.ts +1 -0
- package/src/typegen/index.ts +97 -2
- package/src/types.ts +140 -19
- package/test/after-response.test.ts +132 -132
- package/test/asset-cache-policy.test.ts +6 -2
- package/test/base.test.ts +20 -6
- package/test/cached.test.ts +126 -126
- package/test/client-address.test.ts +78 -78
- package/test/client-csrf.test.ts +61 -61
- package/test/client-dir.test.ts +101 -101
- package/test/client-router.test.ts +37 -5
- package/test/config-file.test.ts +84 -0
- package/test/coordinator.test.ts +9 -2
- package/test/deferred.test.ts +4 -2
- package/test/dev-loader.test.ts +30 -30
- package/test/env.test.ts +171 -171
- package/test/force-production.test.ts +7 -2
- package/test/images.test.ts +20 -8
- package/test/locals-header.test.ts +61 -61
- package/test/middleware.test.ts +243 -243
- package/test/parser-plugins.test.ts +98 -92
- package/test/plugin-handle.test.ts +62 -62
- package/test/plugin-order.test.ts +98 -0
- package/test/plugin-routes.test.ts +47 -42
- package/test/plugin-services-context.test.ts +7 -2
- package/test/preload.test.ts +4 -1
- package/test/prerender.test.ts +3 -1
- package/test/rendering.test.ts +3 -2
- package/test/required-env.test.ts +32 -32
- package/test/resolver-windows.test.ts +22 -23
- package/test/rewrite-html.test.ts +90 -90
- package/test/route-group-layouts.test.ts +38 -36
- package/test/route.test.ts +103 -0
- package/test/routing.test.ts +225 -197
- package/test/scanning.test.ts +53 -33
- package/test/server-context.test.ts +22 -0
- package/test/server-only.test.ts +110 -0
- package/test/server.test.ts +640 -640
- package/test/services.test.ts +3 -3
- package/test/streaming.test.ts +11 -6
- package/test/testing-helpers.test.ts +166 -166
- package/test/typegen.test.ts +209 -112
- package/test/warm.test.ts +96 -96
- package/test/worker-context.test.ts +59 -59
- package/test/workspace-files.test.ts +26 -10
- package/test/workspace-versions.test.ts +146 -131
|
@@ -1,92 +1,98 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { transformSync } from "@babel/core";
|
|
3
|
-
import type { ParserPlugin } from "@babel/parser";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The parser configuration the SSR plugin uses, pinned here so a change to
|
|
7
|
-
* it has to be made in two places deliberately.
|
|
8
|
-
*
|
|
9
|
-
* Kept in sync by hand rather than imported: the plugin builds its own
|
|
10
|
-
* parserOpts inline, and a test that imported that would be testing the
|
|
11
|
-
* import rather than the behaviour. The failing case is named below, and it
|
|
12
|
-
* was found by a real adapter rather than by reading the config.
|
|
13
|
-
*/
|
|
14
|
-
const parserOptsFor = (path: string): { plugins: ParserPlugin[] } =>
|
|
15
|
-
path.endsWith(".tsx")
|
|
16
|
-
? { plugins: ["typescript", "jsx"] }
|
|
17
|
-
: { plugins: ["typescript"] };
|
|
18
|
-
|
|
19
|
-
const parse = (source: string, filename: string) =>
|
|
20
|
-
transformSync(source, {
|
|
21
|
-
configFile: false,
|
|
22
|
-
babelrc: false,
|
|
23
|
-
parserOpts: parserOptsFor(filename),
|
|
24
|
-
filename,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("the jsx parser plugin is scoped to .tsx", () => {
|
|
28
|
-
test("a generic arrow function compiles in a .ts file", () => {
|
|
29
|
-
// This is the regression. With ["typescript", "jsx"] on every file,
|
|
30
|
-
// Babel reads `<R>(x: R) => x` as the start of a JSX element and
|
|
31
|
-
// fails with "Unexpected token `>`". Generic arrows are ordinary
|
|
32
|
-
// TypeScript, and this is the exact line that lets a Drizzle adapter
|
|
33
|
-
// drop an `as any`:
|
|
34
|
-
//
|
|
35
|
-
// transaction: <R>(db: DrizzleDb, fn: (tx: DrizzleTx) => Promise<R>) =>
|
|
36
|
-
// db.transaction(fn)
|
|
37
|
-
expect(() =>
|
|
38
|
-
parse(
|
|
39
|
-
"const o = { f: <R>(x: R): R => x };\nexport const out = o;",
|
|
40
|
-
"adapter.ts",
|
|
41
|
-
),
|
|
42
|
-
).not.toThrow();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("a generic arrow in an object literal, the failing shape", () => {
|
|
46
|
-
// The minimal repro. Inside a call argument the parser is in a
|
|
47
|
-
// different state, which is why the one above passes and this failed.
|
|
48
|
-
expect(() =>
|
|
49
|
-
parse("define({ f: <R>(x: R): R => x });", "adapter.ts"),
|
|
50
|
-
).not.toThrow();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("JSX still compiles in a .tsx file", () => {
|
|
54
|
-
// The whole reason the jsx plugin exists must keep working.
|
|
55
|
-
expect(() =>
|
|
56
|
-
parse("const a = <div x={1} />;\nexport default a;", "page.tsx"),
|
|
57
|
-
).not.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("a JSX fragment compiles in a .tsx file", () => {
|
|
61
|
-
expect(() =>
|
|
62
|
-
parse("const a = <><b/></>;\nexport default a;", "page.tsx"),
|
|
63
|
-
).not.toThrow();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("a generic arrow in a .tsx file needs the comma, as TypeScript says", () => {
|
|
67
|
-
// Genuinely ambiguous, so the error is correct behaviour rather than a
|
|
68
|
-
// bug — and worth pinning so the fix is not "regressed" later by
|
|
69
|
-
// someone trying to make this pass without the comma.
|
|
70
|
-
expect(() =>
|
|
71
|
-
parse("const o = { f: <R,>(x: R): R => x };\nexport default o;", "a.tsx"),
|
|
72
|
-
).not.toThrow();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("other TypeScript syntax in a .ts file", () => {
|
|
77
|
-
// Dropping jsx from .ts must not cost anything else, which is the risk a
|
|
78
|
-
// one-line parser change carries.
|
|
79
|
-
for (const [label, source] of [
|
|
80
|
-
["as const", "const x = { a: 1 } as const;\nexport default x;"],
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
["a
|
|
86
|
-
["
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { transformSync } from "@babel/core";
|
|
3
|
+
import type { ParserPlugin } from "@babel/parser";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The parser configuration the SSR plugin uses, pinned here so a change to
|
|
7
|
+
* it has to be made in two places deliberately.
|
|
8
|
+
*
|
|
9
|
+
* Kept in sync by hand rather than imported: the plugin builds its own
|
|
10
|
+
* parserOpts inline, and a test that imported that would be testing the
|
|
11
|
+
* import rather than the behaviour. The failing case is named below, and it
|
|
12
|
+
* was found by a real adapter rather than by reading the config.
|
|
13
|
+
*/
|
|
14
|
+
const parserOptsFor = (path: string): { plugins: ParserPlugin[] } =>
|
|
15
|
+
path.endsWith(".tsx")
|
|
16
|
+
? { plugins: ["typescript", "jsx"] }
|
|
17
|
+
: { plugins: ["typescript"] };
|
|
18
|
+
|
|
19
|
+
const parse = (source: string, filename: string) =>
|
|
20
|
+
transformSync(source, {
|
|
21
|
+
configFile: false,
|
|
22
|
+
babelrc: false,
|
|
23
|
+
parserOpts: parserOptsFor(filename),
|
|
24
|
+
filename,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("the jsx parser plugin is scoped to .tsx", () => {
|
|
28
|
+
test("a generic arrow function compiles in a .ts file", () => {
|
|
29
|
+
// This is the regression. With ["typescript", "jsx"] on every file,
|
|
30
|
+
// Babel reads `<R>(x: R) => x` as the start of a JSX element and
|
|
31
|
+
// fails with "Unexpected token `>`". Generic arrows are ordinary
|
|
32
|
+
// TypeScript, and this is the exact line that lets a Drizzle adapter
|
|
33
|
+
// drop an `as any`:
|
|
34
|
+
//
|
|
35
|
+
// transaction: <R>(db: DrizzleDb, fn: (tx: DrizzleTx) => Promise<R>) =>
|
|
36
|
+
// db.transaction(fn)
|
|
37
|
+
expect(() =>
|
|
38
|
+
parse(
|
|
39
|
+
"const o = { f: <R>(x: R): R => x };\nexport const out = o;",
|
|
40
|
+
"adapter.ts",
|
|
41
|
+
),
|
|
42
|
+
).not.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("a generic arrow in an object literal, the failing shape", () => {
|
|
46
|
+
// The minimal repro. Inside a call argument the parser is in a
|
|
47
|
+
// different state, which is why the one above passes and this failed.
|
|
48
|
+
expect(() =>
|
|
49
|
+
parse("define({ f: <R>(x: R): R => x });", "adapter.ts"),
|
|
50
|
+
).not.toThrow();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("JSX still compiles in a .tsx file", () => {
|
|
54
|
+
// The whole reason the jsx plugin exists must keep working.
|
|
55
|
+
expect(() =>
|
|
56
|
+
parse("const a = <div x={1} />;\nexport default a;", "page.tsx"),
|
|
57
|
+
).not.toThrow();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a JSX fragment compiles in a .tsx file", () => {
|
|
61
|
+
expect(() =>
|
|
62
|
+
parse("const a = <><b/></>;\nexport default a;", "page.tsx"),
|
|
63
|
+
).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("a generic arrow in a .tsx file needs the comma, as TypeScript says", () => {
|
|
67
|
+
// Genuinely ambiguous, so the error is correct behaviour rather than a
|
|
68
|
+
// bug — and worth pinning so the fix is not "regressed" later by
|
|
69
|
+
// someone trying to make this pass without the comma.
|
|
70
|
+
expect(() =>
|
|
71
|
+
parse("const o = { f: <R,>(x: R): R => x };\nexport default o;", "a.tsx"),
|
|
72
|
+
).not.toThrow();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("other TypeScript syntax in a .ts file", () => {
|
|
77
|
+
// Dropping jsx from .ts must not cost anything else, which is the risk a
|
|
78
|
+
// one-line parser change carries.
|
|
79
|
+
for (const [label, source] of [
|
|
80
|
+
["as const", "const x = { a: 1 } as const;\nexport default x;"],
|
|
81
|
+
[
|
|
82
|
+
"satisfies",
|
|
83
|
+
"const x = { a: 1 } satisfies Record<string, number>;\nexport default x;",
|
|
84
|
+
],
|
|
85
|
+
["a generic interface", "interface I<T> { v: T }\nexport default I;"],
|
|
86
|
+
["an enum", "enum E { A }\nexport default E;"],
|
|
87
|
+
["optional chaining", "const x = a?.b?.c;\nexport default x;"],
|
|
88
|
+
[
|
|
89
|
+
"a type-only import",
|
|
90
|
+
'import type { A } from "./a.ts";\nexport default A;',
|
|
91
|
+
],
|
|
92
|
+
["decorators-free classes", "class C { x = 1 }\nexport default C;"],
|
|
93
|
+
] as Array<[string, string]>) {
|
|
94
|
+
test(label, () => {
|
|
95
|
+
expect(() => parse(source, "file.ts")).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import type { Handle, RequestEvent } from "../src/server/hooks.ts";
|
|
3
|
-
import { composeHandle } from "../src/server/plugins.ts";
|
|
4
|
-
import type { GrimoirePlugin } from "../src/types.ts";
|
|
5
|
-
|
|
6
|
-
const event = () => ({ locals: {} }) as unknown as RequestEvent;
|
|
7
|
-
const ok = () => new Response("page");
|
|
8
|
-
const named = (name: string, handle?: Handle): GrimoirePlugin => ({
|
|
9
|
-
name,
|
|
10
|
-
handle,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe("composeHandle", () => {
|
|
14
|
-
test("is undefined when nobody has a handle", () => {
|
|
15
|
-
expect(composeHandle([named("a")], undefined)).toBeUndefined();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("plugins run in order, then the app's handle, which sees their locals", async () => {
|
|
19
|
-
const seen: string[] = [];
|
|
20
|
-
const a = named("a", ({ event, resolve }) => {
|
|
21
|
-
(event.locals as unknown as Record<string, unknown>).user = "ada";
|
|
22
|
-
seen.push("a");
|
|
23
|
-
return resolve(event);
|
|
24
|
-
});
|
|
25
|
-
const b = named("b", ({ event, resolve }) => {
|
|
26
|
-
seen.push("b");
|
|
27
|
-
return resolve(event);
|
|
28
|
-
});
|
|
29
|
-
const app: Handle = ({ event, resolve }) => {
|
|
30
|
-
seen.push(
|
|
31
|
-
`app:${(event.locals as unknown as Record<string, unknown>).user}`,
|
|
32
|
-
);
|
|
33
|
-
return resolve(event);
|
|
34
|
-
};
|
|
35
|
-
const res = await composeHandle([a, b], app)!({
|
|
36
|
-
event: event(),
|
|
37
|
-
resolve: ok,
|
|
38
|
-
});
|
|
39
|
-
expect(await res.text()).toBe("page");
|
|
40
|
-
expect(seen).toEqual(["a", "b", "app:ada"]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("a plugin can answer without calling resolve", async () => {
|
|
44
|
-
let reached = false;
|
|
45
|
-
const stop = named("stop", () => new Response("no", { status: 401 }));
|
|
46
|
-
const res = await composeHandle([stop], () => {
|
|
47
|
-
reached = true;
|
|
48
|
-
return ok();
|
|
49
|
-
})!({ event: event(), resolve: ok });
|
|
50
|
-
expect(res.status).toBe(401);
|
|
51
|
-
expect(reached).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("a lone plugin handle is used as is", async () => {
|
|
55
|
-
const only = named("only", ({ resolve, event }) => resolve(event));
|
|
56
|
-
const res = await composeHandle([only], undefined)!({
|
|
57
|
-
event: event(),
|
|
58
|
-
resolve: ok,
|
|
59
|
-
});
|
|
60
|
-
expect(await res.text()).toBe("page");
|
|
61
|
-
});
|
|
62
|
-
});
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { Handle, RequestEvent } from "../src/server/hooks.ts";
|
|
3
|
+
import { composeHandle } from "../src/server/plugins.ts";
|
|
4
|
+
import type { GrimoirePlugin } from "../src/types.ts";
|
|
5
|
+
|
|
6
|
+
const event = () => ({ locals: {} }) as unknown as RequestEvent;
|
|
7
|
+
const ok = () => new Response("page");
|
|
8
|
+
const named = (name: string, handle?: Handle): GrimoirePlugin => ({
|
|
9
|
+
name,
|
|
10
|
+
handle,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe("composeHandle", () => {
|
|
14
|
+
test("is undefined when nobody has a handle", () => {
|
|
15
|
+
expect(composeHandle([named("a")], undefined)).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("plugins run in order, then the app's handle, which sees their locals", async () => {
|
|
19
|
+
const seen: string[] = [];
|
|
20
|
+
const a = named("a", ({ event, resolve }) => {
|
|
21
|
+
(event.locals as unknown as Record<string, unknown>).user = "ada";
|
|
22
|
+
seen.push("a");
|
|
23
|
+
return resolve(event);
|
|
24
|
+
});
|
|
25
|
+
const b = named("b", ({ event, resolve }) => {
|
|
26
|
+
seen.push("b");
|
|
27
|
+
return resolve(event);
|
|
28
|
+
});
|
|
29
|
+
const app: Handle = ({ event, resolve }) => {
|
|
30
|
+
seen.push(
|
|
31
|
+
`app:${(event.locals as unknown as Record<string, unknown>).user}`,
|
|
32
|
+
);
|
|
33
|
+
return resolve(event);
|
|
34
|
+
};
|
|
35
|
+
const res = await composeHandle([a, b], app)!({
|
|
36
|
+
event: event(),
|
|
37
|
+
resolve: ok,
|
|
38
|
+
});
|
|
39
|
+
expect(await res.text()).toBe("page");
|
|
40
|
+
expect(seen).toEqual(["a", "b", "app:ada"]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a plugin can answer without calling resolve", async () => {
|
|
44
|
+
let reached = false;
|
|
45
|
+
const stop = named("stop", () => new Response("no", { status: 401 }));
|
|
46
|
+
const res = await composeHandle([stop], () => {
|
|
47
|
+
reached = true;
|
|
48
|
+
return ok();
|
|
49
|
+
})!({ event: event(), resolve: ok });
|
|
50
|
+
expect(res.status).toBe(401);
|
|
51
|
+
expect(reached).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("a lone plugin handle is used as is", async () => {
|
|
55
|
+
const only = named("only", ({ resolve, event }) => resolve(event));
|
|
56
|
+
const res = await composeHandle([only], undefined)!({
|
|
57
|
+
event: event(),
|
|
58
|
+
resolve: ok,
|
|
59
|
+
});
|
|
60
|
+
expect(await res.text()).toBe("page");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { orderPlugins } from "../src/plugin-order";
|
|
3
|
+
import type { GrimoirePlugin } from "../src/types";
|
|
4
|
+
|
|
5
|
+
const p = (
|
|
6
|
+
name: string,
|
|
7
|
+
extra: Partial<GrimoirePlugin> = {},
|
|
8
|
+
): GrimoirePlugin => ({ name, ...extra });
|
|
9
|
+
const names = (list: GrimoirePlugin[]) => list.map((x) => x.name);
|
|
10
|
+
|
|
11
|
+
describe("plugin order", () => {
|
|
12
|
+
test("a list that already works is left as written", () => {
|
|
13
|
+
const list = [
|
|
14
|
+
p("sql:db"),
|
|
15
|
+
p("tome", { after: ["sql:db"] }),
|
|
16
|
+
p("auth", { after: ["tome"] }),
|
|
17
|
+
];
|
|
18
|
+
expect(names(orderPlugins(list))).toEqual(["sql:db", "tome", "auth"]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("after moves a plugin behind what it needs, whatever the list says", () => {
|
|
22
|
+
const list = [
|
|
23
|
+
p("auth", { after: ["tome"] }),
|
|
24
|
+
p("tome", { after: ["sql:db"] }),
|
|
25
|
+
p("sql:db"),
|
|
26
|
+
];
|
|
27
|
+
expect(names(orderPlugins(list))).toEqual(["sql:db", "tome", "auth"]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("unrelated plugins keep their listed order", () => {
|
|
31
|
+
const list = [
|
|
32
|
+
p("a"),
|
|
33
|
+
p("jobs", { after: ["sql:*"] }),
|
|
34
|
+
p("b"),
|
|
35
|
+
p("sql:db"),
|
|
36
|
+
p("c"),
|
|
37
|
+
];
|
|
38
|
+
expect(names(orderPlugins(list))).toEqual([
|
|
39
|
+
"a",
|
|
40
|
+
"b",
|
|
41
|
+
"sql:db",
|
|
42
|
+
"jobs",
|
|
43
|
+
"c",
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("before is the mirror of after", () => {
|
|
48
|
+
const list = [p("x"), p("first", { before: ["x"] })];
|
|
49
|
+
expect(names(orderPlugins(list))).toEqual(["first", "x"]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("a * pattern matches every plugin with that prefix", () => {
|
|
53
|
+
const list = [
|
|
54
|
+
p("jobs", { after: ["sql:*"] }),
|
|
55
|
+
p("sql:db"),
|
|
56
|
+
p("sql:viewer"),
|
|
57
|
+
];
|
|
58
|
+
expect(names(orderPlugins(list))).toEqual(["sql:db", "sql:viewer", "jobs"]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a name that is not registered is ignored", () => {
|
|
62
|
+
expect(names(orderPlugins([p("auth", { after: ["tome"] })]))).toEqual([
|
|
63
|
+
"auth",
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a cycle names the plugins in it", () => {
|
|
68
|
+
const list = [p("ok"), p("a", { after: ["b"] }), p("b", { after: ["a"] })];
|
|
69
|
+
expect(() => orderPlugins(list)).toThrow(/"a", "b"/);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("included plugins", () => {
|
|
74
|
+
test("come before the plugin that includes them", () => {
|
|
75
|
+
const sql = p("sql:db");
|
|
76
|
+
const tome = p("tome", { after: ["sql:db"], includes: [sql] });
|
|
77
|
+
expect(names(orderPlugins([p("auth", { after: ["tome"] }), tome]))).toEqual(
|
|
78
|
+
["sql:db", "tome", "auth"],
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("a listed plugin with the same name wins over an included one", () => {
|
|
83
|
+
const mine = p("sql:db");
|
|
84
|
+
const tome = p("tome", { after: ["sql:db"], includes: [p("sql:db")] });
|
|
85
|
+
const out = orderPlugins([tome, mine]);
|
|
86
|
+
expect(names(out)).toEqual(["sql:db", "tome"]);
|
|
87
|
+
expect(out[0]).toBe(mine);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("one object included twice is registered once", () => {
|
|
91
|
+
const shared = p("shared");
|
|
92
|
+
const out = orderPlugins([
|
|
93
|
+
p("a", { includes: [shared] }),
|
|
94
|
+
p("b", { includes: [shared] }),
|
|
95
|
+
]);
|
|
96
|
+
expect(names(out)).toEqual(["shared", "a", "b"]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -1,42 +1,47 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { scanRoutes } from "../src/routing/scanner";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
])
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { scanRoutes } from "../src/routing/scanner";
|
|
6
|
+
import {
|
|
7
|
+
shadowedRouteMessage,
|
|
8
|
+
shadowedRoutes,
|
|
9
|
+
} from "../src/server/plugin-routes";
|
|
10
|
+
|
|
11
|
+
async function treeWith(files: string[]) {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), "grimoire-shadow-"));
|
|
13
|
+
const routes = join(root, "src/routes");
|
|
14
|
+
for (const f of files) {
|
|
15
|
+
mkdirSync(join(routes, f, ".."), { recursive: true });
|
|
16
|
+
writeFileSync(join(routes, f), "export default () => null;");
|
|
17
|
+
}
|
|
18
|
+
return scanRoutes(routes, root);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test("an app route on a path a plugin answers is reported, by file", async () => {
|
|
22
|
+
const tree = await treeWith([
|
|
23
|
+
"+page.tsx",
|
|
24
|
+
"auth/github/callback/+page.tsx",
|
|
25
|
+
"auth/[provider]/+page.tsx",
|
|
26
|
+
]);
|
|
27
|
+
const found = shadowedRoutes(
|
|
28
|
+
[
|
|
29
|
+
{ name: "tome", routes: ["/auth/github", "/auth/github/callback"] },
|
|
30
|
+
{ name: "quiet" },
|
|
31
|
+
],
|
|
32
|
+
tree,
|
|
33
|
+
);
|
|
34
|
+
expect(found.map((f) => [f.plugin, f.path])).toEqual([
|
|
35
|
+
["tome", "/auth/github"],
|
|
36
|
+
["tome", "/auth/github/callback"],
|
|
37
|
+
]);
|
|
38
|
+
expect(found[1]!.file).toContain("auth/github/callback/+page.tsx");
|
|
39
|
+
expect(shadowedRouteMessage(found[1]!)).toContain("hooks.server.ts");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("no overlap, no warning", async () => {
|
|
43
|
+
const tree = await treeWith(["+page.tsx", "login/+page.tsx"]);
|
|
44
|
+
expect(
|
|
45
|
+
shadowedRoutes([{ name: "tome", routes: ["/auth/github"] }], tree),
|
|
46
|
+
).toEqual([]);
|
|
47
|
+
});
|
|
@@ -57,10 +57,15 @@ describe("plugin services", () => {
|
|
|
57
57
|
|
|
58
58
|
test("the client a consumer reads is the same object the sql plugin owns", async () => {
|
|
59
59
|
const client = { tag: "client" };
|
|
60
|
-
const owner = {
|
|
60
|
+
const owner = {
|
|
61
|
+
name: "sql",
|
|
62
|
+
services: () => ({ db: client }),
|
|
63
|
+
} as unknown as AnyPlugin;
|
|
61
64
|
const consumer = {
|
|
62
65
|
name: "consumer",
|
|
63
|
-
services: (ctx: { services: Record<string, unknown> }) => ({
|
|
66
|
+
services: (ctx: { services: Record<string, unknown> }) => ({
|
|
67
|
+
used: ctx.services.db,
|
|
68
|
+
}),
|
|
64
69
|
} as unknown as AnyPlugin;
|
|
65
70
|
|
|
66
71
|
const collected = await collectServices([owner, consumer]);
|
package/test/preload.test.ts
CHANGED
|
@@ -20,7 +20,10 @@ describe("chunk graph", () => {
|
|
|
20
20
|
test("routes map to chunks and closures include shared imports", () => {
|
|
21
21
|
const g = parseChunkGraph(SOURCE)!;
|
|
22
22
|
expect(g.routes.get("/")).toBe("home");
|
|
23
|
-
expect(chunksFor(g, "/").sort()).toEqual([
|
|
23
|
+
expect(chunksFor(g, "/").sort()).toEqual([
|
|
24
|
+
"chunk-home.js",
|
|
25
|
+
"chunk-shared.js",
|
|
26
|
+
]);
|
|
24
27
|
expect(chunksFor(g, "/cards/:id").sort()).toEqual([
|
|
25
28
|
"chunk-cards.js",
|
|
26
29
|
"chunk-leaf.js",
|
package/test/prerender.test.ts
CHANGED
|
@@ -217,7 +217,9 @@ describe("prerenderSite", () => {
|
|
|
217
217
|
expect(await readFile(join(out, "hydrate-abcd1234.js"), "utf8")).toBe(
|
|
218
218
|
"hydrate",
|
|
219
219
|
);
|
|
220
|
-
expect(await readFile(join(out, "chunk-efgh5678.js"), "utf8")).toBe(
|
|
220
|
+
expect(await readFile(join(out, "chunk-efgh5678.js"), "utf8")).toBe(
|
|
221
|
+
"chunk",
|
|
222
|
+
);
|
|
221
223
|
expect(await exists(join(out, "runtime.js"))).toBe(false);
|
|
222
224
|
});
|
|
223
225
|
|
package/test/rendering.test.ts
CHANGED
|
@@ -534,8 +534,9 @@ describe("renderRoute", () => {
|
|
|
534
534
|
expect(html).toContain("My Blog");
|
|
535
535
|
// the state JSON embeds data under the data key
|
|
536
536
|
const stateJson = JSON.parse(
|
|
537
|
-
html.match(
|
|
538
|
-
"
|
|
537
|
+
html.match(
|
|
538
|
+
/<script id="__grimoire_state__"[^>]*>([^<]+)<\/script>/,
|
|
539
|
+
)?.[1] ?? "{}",
|
|
539
540
|
);
|
|
540
541
|
expect(stateJson.data?.title).toBe("My Blog");
|
|
541
542
|
expect(html).not.toContain("[object Object]");
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { assertRequiredEnv, missingEnv } from "../src/env/required";
|
|
3
|
-
|
|
4
|
-
describe("required env", () => {
|
|
5
|
-
test("nothing declared, nothing missing", () => {
|
|
6
|
-
expect(missingEnv({}, {})).toEqual([]);
|
|
7
|
-
expect(() => assertRequiredEnv({}, {})).not.toThrow();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("lists every missing name once, with who asked for it", () => {
|
|
11
|
-
const config = {
|
|
12
|
-
env: { required: ["DB_URL", "SESSION_SECRET"] },
|
|
13
|
-
plugins: [{ name: "mailer", requiredEnv: ["SMTP_URL", "DB_URL"] }],
|
|
14
|
-
};
|
|
15
|
-
const err = (() => {
|
|
16
|
-
try {
|
|
17
|
-
assertRequiredEnv(config, { SESSION_SECRET: "x" });
|
|
18
|
-
} catch (e) {
|
|
19
|
-
return e as Error;
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
expect(err?.message).toContain("DB_URL (required by sigil.config.ts)");
|
|
23
|
-
expect(err?.message).toContain('SMTP_URL (required by plugin "mailer")');
|
|
24
|
-
expect(err?.message).not.toContain("SESSION_SECRET");
|
|
25
|
-
expect(err?.message.match(/DB_URL/g)).toHaveLength(1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("an empty value counts as missing", () => {
|
|
29
|
-
expect(missingEnv({ env: { required: ["A"] } }, { A: "" })).toHaveLength(1);
|
|
30
|
-
expect(missingEnv({ env: { required: ["A"] } }, { A: "1" })).toEqual([]);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { assertRequiredEnv, missingEnv } from "../src/env/required";
|
|
3
|
+
|
|
4
|
+
describe("required env", () => {
|
|
5
|
+
test("nothing declared, nothing missing", () => {
|
|
6
|
+
expect(missingEnv({}, {})).toEqual([]);
|
|
7
|
+
expect(() => assertRequiredEnv({}, {})).not.toThrow();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("lists every missing name once, with who asked for it", () => {
|
|
11
|
+
const config = {
|
|
12
|
+
env: { required: ["DB_URL", "SESSION_SECRET"] },
|
|
13
|
+
plugins: [{ name: "mailer", requiredEnv: ["SMTP_URL", "DB_URL"] }],
|
|
14
|
+
};
|
|
15
|
+
const err = (() => {
|
|
16
|
+
try {
|
|
17
|
+
assertRequiredEnv(config, { SESSION_SECRET: "x" });
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return e as Error;
|
|
20
|
+
}
|
|
21
|
+
})();
|
|
22
|
+
expect(err?.message).toContain("DB_URL (required by sigil.config.ts)");
|
|
23
|
+
expect(err?.message).toContain('SMTP_URL (required by plugin "mailer")');
|
|
24
|
+
expect(err?.message).not.toContain("SESSION_SECRET");
|
|
25
|
+
expect(err?.message.match(/DB_URL/g)).toHaveLength(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("an empty value counts as missing", () => {
|
|
29
|
+
expect(missingEnv({ env: { required: ["A"] } }, { A: "" })).toHaveLength(1);
|
|
30
|
+
expect(missingEnv({ env: { required: ["A"] } }, { A: "1" })).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
});
|