@sigil-dev/grimoire 0.9.2 → 0.9.3
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 +35 -35
- package/package.json +8 -8
- package/preload.js +3 -3
- package/server.ts +19 -19
- package/src/client/deps.ts +13 -7
- package/src/client/enhance.ts +98 -98
- package/src/client/head.ts +30 -30
- package/src/client/index.ts +2 -2
- package/src/client/router.ts +445 -371
- package/src/client/scope.ts +22 -22
- package/src/dev/compile-module.ts +163 -163
- package/src/dev/effect-registry.ts +23 -23
- package/src/dev/graph.ts +114 -114
- package/src/dev/hmr-client.ts +185 -185
- package/src/dev/loader.ts +47 -47
- package/src/dev/paths.ts +14 -14
- package/src/dev/runtime-bundle.ts +52 -52
- package/src/dev/watcher.ts +47 -46
- 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 +47 -47
- package/src/rendering/hydrate.ts +98 -79
- package/src/rendering/index.ts +455 -372
- package/src/rendering/ssrPlugin.ts +69 -69
- package/src/routing/manifest-gen.ts +12 -11
- package/src/routing/router.ts +109 -109
- package/src/routing/scanner.ts +141 -141
- 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 +243 -219
- package/src/server/context.ts +10 -10
- package/src/server/cookie-utils.ts +66 -66
- package/src/server/coordinator.ts +364 -356
- package/src/server/hooks.ts +114 -114
- package/src/server/index.ts +655 -658
- package/src/server/interactive.ts +56 -56
- package/src/server/plugins.ts +121 -120
- package/src/server/worker.ts +58 -58
- package/src/typegen/index.ts +356 -356
- package/src/types.ts +4 -4
- package/test/client-router.test.ts +37 -31
- package/test/context.test.ts +52 -52
- package/test/env.test.ts +70 -70
- package/test/exports.test.ts +37 -37
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +100 -100
- 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 +615 -579
- package/test/routing.test.ts +81 -81
- package/test/scanning.test.ts +200 -200
- package/test/scope.test.ts +195 -195
- package/test/server.test.ts +249 -249
- package/test/streaming.test.ts +125 -125
- package/test/transform-routes.test.ts +84 -84
- package/test/typegen.test.ts +682 -682
- package/tsconfig.json +10 -10
- package/.grimoire/_routes.dom.js +0 -8
- package/.grimoire/_routes.hydrate.js +0 -8
- package/.grimoire/tsconfig.generated.json +0 -11
- package/.grimoire/types/ambient.d.ts +0 -59
- package/.grimoire/types/api/hello/$types.d.ts +0 -50
- package/.grimoire/types/api/items/$types.d.ts +0 -50
- package/.grimoire/types/echo/$types.d.ts +0 -50
- package/.grimoire/types/env-private.d.ts +0 -5
- package/.grimoire/types/env-public.d.ts +0 -5
- package/.grimoire/types/mixed/$types.d.ts +0 -50
- package/.grimoire/types/params/[docId]/$types.d.ts +0 -52
- package/.grimoire/types/reject/$types.d.ts +0 -50
- package/public/__grimoire__/hydrate.js +0 -585
- package/public/__grimoire__/index.js +0 -490
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throw a redirect from a load function or form action.
|
|
3
|
-
* The server catches it and returns a 3xx Response.
|
|
4
|
-
*
|
|
5
|
-
* Usage in +page.server.ts:
|
|
6
|
-
*
|
|
7
|
-
* import { redirect } from "@sigil-dev/grimoire";
|
|
8
|
-
*
|
|
9
|
-
* export async function load({ locals }) {
|
|
10
|
-
* if (!locals.user) throw redirect(302, "/login");
|
|
11
|
-
* return { user: locals.user };
|
|
12
|
-
* }
|
|
13
|
-
*
|
|
14
|
-
* export async function POST({ request }) {
|
|
15
|
-
* // ... process form
|
|
16
|
-
* throw redirect(303, "/dashboard");
|
|
17
|
-
* }
|
|
18
|
-
*/
|
|
19
|
-
export interface RedirectResult {
|
|
20
|
-
__redirect: true;
|
|
21
|
-
status: number;
|
|
22
|
-
location: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function redirect(status: number, location: string): never {
|
|
26
|
-
throw { __redirect: true, status, location } as RedirectResult;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function isRedirectResult(value: unknown): value is RedirectResult {
|
|
30
|
-
return (
|
|
31
|
-
typeof value === "object" &&
|
|
32
|
-
value !== null &&
|
|
33
|
-
(value as any).__redirect === true
|
|
34
|
-
);
|
|
35
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Throw a redirect from a load function or form action.
|
|
3
|
+
* The server catches it and returns a 3xx Response.
|
|
4
|
+
*
|
|
5
|
+
* Usage in +page.server.ts:
|
|
6
|
+
*
|
|
7
|
+
* import { redirect } from "@sigil-dev/grimoire";
|
|
8
|
+
*
|
|
9
|
+
* export async function load({ locals }) {
|
|
10
|
+
* if (!locals.user) throw redirect(302, "/login");
|
|
11
|
+
* return { user: locals.user };
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* export async function POST({ request }) {
|
|
15
|
+
* // ... process form
|
|
16
|
+
* throw redirect(303, "/dashboard");
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export interface RedirectResult {
|
|
20
|
+
__redirect: true;
|
|
21
|
+
status: number;
|
|
22
|
+
location: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function redirect(status: number, location: string): never {
|
|
26
|
+
throw { __redirect: true, status, location } as RedirectResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isRedirectResult(value: unknown): value is RedirectResult {
|
|
30
|
+
return (
|
|
31
|
+
typeof value === "object" &&
|
|
32
|
+
value !== null &&
|
|
33
|
+
(value as any).__redirect === true
|
|
34
|
+
);
|
|
35
|
+
}
|
package/src/server/build.ts
CHANGED
|
@@ -1,219 +1,243 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join } from "node:path";
|
|
3
|
-
import { cwd } from "node:process";
|
|
4
|
-
import { sigil } from "@sigil-dev/compiler/bun";
|
|
5
|
-
import { normalizePath } from "../dev/paths";
|
|
6
|
-
import { generateManifest } from "../routing/manifest-gen";
|
|
7
|
-
import type { RouteTree } from "../routing/scanner";
|
|
8
|
-
import { scanRoutes } from "../routing/scanner";
|
|
9
|
-
import { transformRoutes } from "../routing/transform-routes";
|
|
10
|
-
import { generateTypes } from "../typegen";
|
|
11
|
-
import type { BuildResult, GrimoireConfig, GrimoirePlugin } from "../types";
|
|
12
|
-
import { runHook } from "./plugins";
|
|
13
|
-
|
|
14
|
-
function makeAliases(config: GrimoireConfig): Record<string, string> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const makeRoutesPlugin = (manifestPath: string) => ({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export async function rebuildForChange(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
): Promise<{ result: BuildResult }> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, join } from "node:path";
|
|
3
|
+
import { cwd } from "node:process";
|
|
4
|
+
import { sigil } from "@sigil-dev/compiler/bun";
|
|
5
|
+
import { normalizePath } from "../dev/paths";
|
|
6
|
+
import { generateManifest } from "../routing/manifest-gen";
|
|
7
|
+
import type { RouteTree } from "../routing/scanner";
|
|
8
|
+
import { scanRoutes } from "../routing/scanner";
|
|
9
|
+
import { transformRoutes } from "../routing/transform-routes";
|
|
10
|
+
import { generateTypes } from "../typegen";
|
|
11
|
+
import type { BuildResult, GrimoireConfig, GrimoirePlugin } from "../types";
|
|
12
|
+
import { runHook } from "./plugins";
|
|
13
|
+
|
|
14
|
+
function makeAliases(config: GrimoireConfig): Record<string, string> {
|
|
15
|
+
return {
|
|
16
|
+
...Object.fromEntries(
|
|
17
|
+
Object.entries(config.alias ?? {}).map(([k, v]) => [k, join(cwd(), v)]),
|
|
18
|
+
),
|
|
19
|
+
"$env/static/public": join(import.meta.dir, "../env/public.ts"),
|
|
20
|
+
"$env/static/private": join(import.meta.dir, "../env/private.ts"),
|
|
21
|
+
"$env/dynamic/public": join(import.meta.dir, "../env/dynamic-public.ts"),
|
|
22
|
+
"$env/dynamic/private": join(import.meta.dir, "../env/dynamic-private.ts"),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const makeRoutesPlugin = (manifestPath: string) => ({
|
|
27
|
+
name: "grimoire-routes",
|
|
28
|
+
setup(build: any) {
|
|
29
|
+
build.onResolve({ filter: /^#grimoire-routes$/ }, () => ({
|
|
30
|
+
path: manifestPath,
|
|
31
|
+
}));
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export async function rebuildForChange(
|
|
36
|
+
changedFilePath: string,
|
|
37
|
+
config: GrimoireConfig,
|
|
38
|
+
plugins: GrimoirePlugin[] = [],
|
|
39
|
+
): Promise<{ result: BuildResult }> {
|
|
40
|
+
const { routes = "src/routes" } = config;
|
|
41
|
+
const isDev = config.dev ?? false;
|
|
42
|
+
const routesDir = isAbsolute(routes) ? routes : join(process.cwd(), routes);
|
|
43
|
+
|
|
44
|
+
const tree = await scanRoutes(routesDir, process.cwd());
|
|
45
|
+
const changedRoute = [
|
|
46
|
+
...tree.routes.filter((r) => r.type === "page" || r.type === "simple"),
|
|
47
|
+
...tree.layouts.filter((r) => r.type === "layout"),
|
|
48
|
+
].find((r) => normalizePath(r.filePath) === normalizePath(changedFilePath));
|
|
49
|
+
|
|
50
|
+
const compiledDir = join(process.cwd(), ".grimoire/compiled");
|
|
51
|
+
|
|
52
|
+
if (changedRoute) {
|
|
53
|
+
await Promise.all([
|
|
54
|
+
transformRoutes([changedRoute], compiledDir, "hydrate", plugins),
|
|
55
|
+
transformRoutes([changedRoute], compiledDir, "dom", plugins),
|
|
56
|
+
]);
|
|
57
|
+
const allClientRoutes = [
|
|
58
|
+
...tree.routes.filter((r) => r.type === "page" || r.type === "simple"),
|
|
59
|
+
...tree.layouts.filter((r) => r.type === "layout"),
|
|
60
|
+
];
|
|
61
|
+
const hydrateManifest = join(process.cwd(), ".grimoire/_routes.hydrate.js");
|
|
62
|
+
const domManifest = join(process.cwd(), ".grimoire/_routes.dom.js");
|
|
63
|
+
const [allHFiles, allDFiles] = await Promise.all([
|
|
64
|
+
transformRoutes(allClientRoutes, compiledDir, "hydrate", plugins),
|
|
65
|
+
transformRoutes(allClientRoutes, compiledDir, "dom", plugins),
|
|
66
|
+
]);
|
|
67
|
+
await Promise.all([
|
|
68
|
+
Bun.write(hydrateManifest, generateManifest(allClientRoutes, allHFiles)),
|
|
69
|
+
Bun.write(domManifest, generateManifest(allClientRoutes, allDFiles)),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const publicDir = join(process.cwd(), "public/__grimoire__");
|
|
74
|
+
const hydrateManifest = join(process.cwd(), ".grimoire/_routes.hydrate.js");
|
|
75
|
+
const domManifest = join(process.cwd(), ".grimoire/_routes.dom.js");
|
|
76
|
+
const resolvedAlias = makeAliases(config);
|
|
77
|
+
|
|
78
|
+
const [hydrateResult, domResult] = await Promise.all([
|
|
79
|
+
Bun.build({
|
|
80
|
+
entrypoints: [join(import.meta.dir, "../rendering/hydrate.ts")],
|
|
81
|
+
outdir: publicDir,
|
|
82
|
+
// lazy route entries in the manifest use dynamic import()
|
|
83
|
+
splitting: true,
|
|
84
|
+
plugins: [
|
|
85
|
+
sigil({ mode: "hydrate", dev: isDev }),
|
|
86
|
+
makeRoutesPlugin(hydrateManifest),
|
|
87
|
+
],
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
alias: resolvedAlias,
|
|
90
|
+
}),
|
|
91
|
+
Bun.build({
|
|
92
|
+
entrypoints: [join(import.meta.dir, "../client/index.ts")],
|
|
93
|
+
outdir: publicDir,
|
|
94
|
+
splitting: true,
|
|
95
|
+
plugins: [
|
|
96
|
+
sigil({ mode: "dom", dev: isDev }),
|
|
97
|
+
makeRoutesPlugin(domManifest),
|
|
98
|
+
],
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
alias: resolvedAlias,
|
|
101
|
+
}),
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
result: {
|
|
106
|
+
success: hydrateResult.success && domResult.success,
|
|
107
|
+
outputs: [...hydrateResult.outputs, ...domResult.outputs].map(
|
|
108
|
+
(o) => o.path,
|
|
109
|
+
),
|
|
110
|
+
errors: [...hydrateResult.logs, ...domResult.logs].map(String),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function buildProject(
|
|
116
|
+
config: GrimoireConfig,
|
|
117
|
+
plugins: GrimoirePlugin[] = [],
|
|
118
|
+
): Promise<{ result: BuildResult; tree: RouteTree }> {
|
|
119
|
+
await runHook(plugins, "onBuildStart");
|
|
120
|
+
|
|
121
|
+
const { routes = "src/routes" } = config;
|
|
122
|
+
const isDev = config.dev ?? false;
|
|
123
|
+
|
|
124
|
+
const routesDir = isAbsolute(routes)
|
|
125
|
+
? routes.replace(/\0/g, "")
|
|
126
|
+
: join(process.cwd(), routes).replace(/\0/g, "");
|
|
127
|
+
const tree = await scanRoutes(routesDir, process.cwd());
|
|
128
|
+
|
|
129
|
+
const outDir = join(process.cwd(), ".grimoire");
|
|
130
|
+
await mkdir(outDir, { recursive: true });
|
|
131
|
+
|
|
132
|
+
await generateTypes(tree, {
|
|
133
|
+
projectRoot: process.cwd(),
|
|
134
|
+
routesDir,
|
|
135
|
+
outDir: join(outDir, "types"),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const { generateEnvTypes } = await import("../env/typegen");
|
|
139
|
+
const envTypeDir = join(outDir, "types");
|
|
140
|
+
await mkdir(envTypeDir, { recursive: true });
|
|
141
|
+
await generateEnvTypes(process.cwd(), envTypeDir);
|
|
142
|
+
|
|
143
|
+
const compiledDir = join(outDir, "compiled");
|
|
144
|
+
await mkdir(compiledDir, { recursive: true });
|
|
145
|
+
|
|
146
|
+
const clientRoutes = [
|
|
147
|
+
...tree.routes.filter((r) => r.type === "page" || r.type === "simple"),
|
|
148
|
+
...tree.layouts.filter((r) => r.type === "layout"),
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
const [hydrateFiles, domFiles] = await Promise.all([
|
|
152
|
+
transformRoutes(clientRoutes, compiledDir, "hydrate", plugins),
|
|
153
|
+
transformRoutes(clientRoutes, compiledDir, "dom", plugins),
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
const hydrateManifest = join(process.cwd(), ".grimoire/_routes.hydrate.js");
|
|
157
|
+
const domManifest = join(process.cwd(), ".grimoire/_routes.dom.js");
|
|
158
|
+
await Promise.all([
|
|
159
|
+
Bun.write(hydrateManifest, generateManifest(clientRoutes, hydrateFiles)),
|
|
160
|
+
Bun.write(domManifest, generateManifest(clientRoutes, domFiles)),
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
const resolvedAlias = makeAliases(config);
|
|
164
|
+
const bundleStrategy = config.bundleStrategy ?? "split";
|
|
165
|
+
const publicDir = join(process.cwd(), "public/__grimoire__");
|
|
166
|
+
|
|
167
|
+
if (bundleStrategy === "single") {
|
|
168
|
+
const singleResult = await Bun.build({
|
|
169
|
+
entrypoints: [
|
|
170
|
+
join(import.meta.dir, "../rendering/hydrate.ts"),
|
|
171
|
+
join(import.meta.dir, "../client/index.ts"),
|
|
172
|
+
],
|
|
173
|
+
outdir: publicDir,
|
|
174
|
+
// lazy route entries in the manifest use dynamic import()
|
|
175
|
+
splitting: true,
|
|
176
|
+
plugins: [
|
|
177
|
+
sigil({ mode: "hydrate", dev: isDev }),
|
|
178
|
+
sigil({ mode: "dom", dev: isDev }),
|
|
179
|
+
makeRoutesPlugin(hydrateManifest),
|
|
180
|
+
makeRoutesPlugin(domManifest),
|
|
181
|
+
],
|
|
182
|
+
// @ts-expect-error
|
|
183
|
+
alias: resolvedAlias,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
if (!singleResult.success) {
|
|
187
|
+
for (const log of singleResult.logs) console.error(log);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const result: BuildResult = {
|
|
191
|
+
success: singleResult.success,
|
|
192
|
+
outputs: singleResult.outputs.map((o) => o.path),
|
|
193
|
+
errors: singleResult.logs.map(String),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
await runHook(plugins, "onBuildEnd", result);
|
|
197
|
+
return { result, tree };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const [hydrateResult, domResult] = await Promise.all([
|
|
201
|
+
Bun.build({
|
|
202
|
+
entrypoints: [join(import.meta.dir, "../rendering/hydrate.ts")],
|
|
203
|
+
outdir: publicDir,
|
|
204
|
+
// lazy route entries in the manifest use dynamic import()
|
|
205
|
+
splitting: true,
|
|
206
|
+
plugins: [
|
|
207
|
+
sigil({ mode: "hydrate", dev: isDev }),
|
|
208
|
+
makeRoutesPlugin(hydrateManifest),
|
|
209
|
+
],
|
|
210
|
+
// @ts-expect-error
|
|
211
|
+
alias: resolvedAlias,
|
|
212
|
+
}),
|
|
213
|
+
Bun.build({
|
|
214
|
+
entrypoints: [join(import.meta.dir, "../client/index.ts")],
|
|
215
|
+
outdir: publicDir,
|
|
216
|
+
splitting: true,
|
|
217
|
+
plugins: [
|
|
218
|
+
sigil({ mode: "dom", dev: isDev }),
|
|
219
|
+
makeRoutesPlugin(domManifest),
|
|
220
|
+
],
|
|
221
|
+
// @ts-expect-error
|
|
222
|
+
alias: resolvedAlias,
|
|
223
|
+
}),
|
|
224
|
+
]);
|
|
225
|
+
|
|
226
|
+
if (!hydrateResult.success) {
|
|
227
|
+
for (const log of hydrateResult.logs) console.error(log);
|
|
228
|
+
}
|
|
229
|
+
if (!domResult.success) {
|
|
230
|
+
for (const log of domResult.logs) console.error(log);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const result: BuildResult = {
|
|
234
|
+
success: hydrateResult.success && domResult.success,
|
|
235
|
+
outputs: [...hydrateResult.outputs, ...domResult.outputs].map(
|
|
236
|
+
(o) => o.path,
|
|
237
|
+
),
|
|
238
|
+
errors: [...hydrateResult.logs, ...domResult.logs].map(String),
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
await runHook(plugins, "onBuildEnd", result);
|
|
242
|
+
return { result, tree };
|
|
243
|
+
}
|
package/src/server/context.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { __setStoreProvider } from "@sigil-dev/runtime";
|
|
3
|
-
|
|
4
|
-
const storage = new AsyncLocalStorage<Map<symbol, unknown>>();
|
|
5
|
-
|
|
6
|
-
__setStoreProvider(() => storage.getStore() ?? new Map());
|
|
7
|
-
|
|
8
|
-
export function runWithContext<T>(fn: () => Promise<T>): Promise<T> {
|
|
9
|
-
return storage.run(new Map(), fn);
|
|
10
|
-
}
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { __setStoreProvider } from "@sigil-dev/runtime";
|
|
3
|
+
|
|
4
|
+
const storage = new AsyncLocalStorage<Map<symbol, unknown>>();
|
|
5
|
+
|
|
6
|
+
__setStoreProvider(() => storage.getStore() ?? new Map());
|
|
7
|
+
|
|
8
|
+
export function runWithContext<T>(fn: () => Promise<T>): Promise<T> {
|
|
9
|
+
return storage.run(new Map(), fn);
|
|
10
|
+
}
|