@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
package/src/server/build.ts
CHANGED
|
@@ -1,295 +1,304 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
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
|
-
|
|
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
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
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
|
-
const
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
await
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
await
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
],
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, join } from "node:path";
|
|
3
|
+
import { setKnownRoutes, setStaticEnv } from "@sigil-dev/compiler";
|
|
4
|
+
import { sigil } from "@sigil-dev/compiler/bun";
|
|
5
|
+
import { filterPrivate, filterPublic } from "../env";
|
|
6
|
+
import { generateManifest } from "../routing/manifest-gen";
|
|
7
|
+
import { linkableRoutes, routeId } from "../routing/route-ids";
|
|
8
|
+
import type { RouteTree } from "../routing/scanner";
|
|
9
|
+
import { scanRoutes } from "../routing/scanner";
|
|
10
|
+
import { transformRoutes } from "../routing/transform-routes";
|
|
11
|
+
import { generateTypes } from "../typegen";
|
|
12
|
+
import type { BuildResult, GrimoireConfig, GrimoirePlugin } from "../types";
|
|
13
|
+
import {
|
|
14
|
+
clientDir,
|
|
15
|
+
pruneClientDir,
|
|
16
|
+
RUNTIME_URL,
|
|
17
|
+
resetClientDir,
|
|
18
|
+
} from "./client-dir";
|
|
19
|
+
import { recordClientEntry } from "./client-entry";
|
|
20
|
+
import { runHook } from "./plugins";
|
|
21
|
+
import { projectAliases, resolverPlugin } from "./resolver";
|
|
22
|
+
|
|
23
|
+
const makeRoutesPlugin = (manifestPath: string) => ({
|
|
24
|
+
name: "grimoire-routes",
|
|
25
|
+
setup(build: any) {
|
|
26
|
+
build.onResolve({ filter: /^#grimoire-routes$/ }, () => ({
|
|
27
|
+
path: manifestPath,
|
|
28
|
+
}));
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Dev only: the client bundles import the runtime from RUNTIME_URL, the file
|
|
34
|
+
* HMR-swapped modules import, instead of each carrying a copy.
|
|
35
|
+
*
|
|
36
|
+
* Two copies are two sets of module state. The one that broke: the router
|
|
37
|
+
* collects a re-render's effects with `collectEffects`, which sets a flag on
|
|
38
|
+
* globalThis that every copy reads, but queues into its own module. A swapped
|
|
39
|
+
* layout's effects (`{children}`, any prop in text) went into the other copy's
|
|
40
|
+
* queue, which nothing flushes, so the page vanished from the layout. Signals,
|
|
41
|
+
* context and effect scopes don't cross copies either.
|
|
42
|
+
*
|
|
43
|
+
* Production has no swapped modules, so it keeps bundling the runtime.
|
|
44
|
+
*/
|
|
45
|
+
const sharedDevRuntime = {
|
|
46
|
+
name: "grimoire-shared-dev-runtime",
|
|
47
|
+
setup(build: any) {
|
|
48
|
+
build.onResolve({ filter: /^@sigil-dev\/runtime$/ }, () => ({
|
|
49
|
+
path: RUNTIME_URL,
|
|
50
|
+
external: true,
|
|
51
|
+
}));
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Rebuild the client bundles in dev.
|
|
57
|
+
*
|
|
58
|
+
* `hydrate.js` and the dom bundle are produced once at startup, so any full
|
|
59
|
+
* reload after an edit would otherwise hand the browser pre-edit code. Route
|
|
60
|
+
* files are re-transformed (Bun.build only ever sees plain JS) and the
|
|
61
|
+
* manifests regenerated, which also picks up routes added since startup.
|
|
62
|
+
* Returns the freshly scanned tree so the server can adopt it.
|
|
63
|
+
*/
|
|
64
|
+
export async function rebuildClient(
|
|
65
|
+
config: GrimoireConfig,
|
|
66
|
+
plugins: GrimoirePlugin[] = [],
|
|
67
|
+
): Promise<{ result: BuildResult; tree: RouteTree }> {
|
|
68
|
+
const { routes = "src/routes" } = config;
|
|
69
|
+
const isDev = config.dev ?? false;
|
|
70
|
+
const routesDir = isAbsolute(routes) ? routes : join(process.cwd(), routes);
|
|
71
|
+
|
|
72
|
+
const tree = await scanRoutes(routesDir, process.cwd());
|
|
73
|
+
setKnownRoutes(linkableRoutes(tree).map(routeId));
|
|
74
|
+
setStaticEnv(filterPublic(process.env), filterPrivate(process.env));
|
|
75
|
+
const compiledDir = join(process.cwd(), ".grimoire/compiled");
|
|
76
|
+
const clientRoutes = [
|
|
77
|
+
...tree.routes.filter((r) => r.type === "page" || r.type === "simple"),
|
|
78
|
+
...tree.layouts.filter((r) => r.type === "layout"),
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const hydrateManifest = join(process.cwd(), ".grimoire/_routes.hydrate.js");
|
|
82
|
+
const domManifest = join(process.cwd(), ".grimoire/_routes.dom.js");
|
|
83
|
+
const [hydrateFiles, domFiles] = await Promise.all([
|
|
84
|
+
transformRoutes(clientRoutes, compiledDir, "hydrate", plugins),
|
|
85
|
+
transformRoutes(clientRoutes, compiledDir, "dom", plugins),
|
|
86
|
+
]);
|
|
87
|
+
await Promise.all([
|
|
88
|
+
Bun.write(
|
|
89
|
+
hydrateManifest,
|
|
90
|
+
generateManifest(clientRoutes, hydrateFiles, tree.paramMatcherFiles),
|
|
91
|
+
),
|
|
92
|
+
Bun.write(
|
|
93
|
+
domManifest,
|
|
94
|
+
generateManifest(clientRoutes, domFiles, tree.paramMatcherFiles),
|
|
95
|
+
),
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
const bundleDir = clientDir();
|
|
99
|
+
|
|
100
|
+
const [hydrateResult, domResult] = await Promise.all([
|
|
101
|
+
Bun.build({
|
|
102
|
+
entrypoints: [join(import.meta.dir, "../rendering/hydrate.ts")],
|
|
103
|
+
outdir: bundleDir,
|
|
104
|
+
naming: { entry: "[name]-[hash].[ext]" },
|
|
105
|
+
// report failures in result.logs instead of throwing past them
|
|
106
|
+
throw: false,
|
|
107
|
+
// lazy route entries in the manifest use dynamic import()
|
|
108
|
+
splitting: true,
|
|
109
|
+
plugins: [
|
|
110
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
111
|
+
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
112
|
+
makeRoutesPlugin(hydrateManifest),
|
|
113
|
+
resolverPlugin(config, "browser"),
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
Bun.build({
|
|
117
|
+
entrypoints: [join(import.meta.dir, "../client/index.ts")],
|
|
118
|
+
outdir: bundleDir,
|
|
119
|
+
naming: { entry: "[name]-[hash].[ext]" },
|
|
120
|
+
// report failures in result.logs instead of throwing past them
|
|
121
|
+
throw: false,
|
|
122
|
+
splitting: true,
|
|
123
|
+
plugins: [
|
|
124
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
125
|
+
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
126
|
+
makeRoutesPlugin(domManifest),
|
|
127
|
+
resolverPlugin(config, "browser"),
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
const outputs = [...hydrateResult.outputs, ...domResult.outputs].map(
|
|
133
|
+
(o) => o.path,
|
|
134
|
+
);
|
|
135
|
+
const success = hydrateResult.success && domResult.success;
|
|
136
|
+
// a failed build keeps the last good bundle in place
|
|
137
|
+
if (success) {
|
|
138
|
+
recordClientEntry([...hydrateResult.outputs, ...domResult.outputs]);
|
|
139
|
+
await pruneClientDir(outputs);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
tree,
|
|
144
|
+
result: {
|
|
145
|
+
success,
|
|
146
|
+
outputs,
|
|
147
|
+
errors: [...hydrateResult.logs, ...domResult.logs].map(String),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function buildProject(
|
|
153
|
+
config: GrimoireConfig,
|
|
154
|
+
plugins: GrimoirePlugin[] = [],
|
|
155
|
+
): Promise<{ result: BuildResult; tree: RouteTree }> {
|
|
156
|
+
await runHook(plugins, "onBuildStart");
|
|
157
|
+
|
|
158
|
+
const { routes = "src/routes" } = config;
|
|
159
|
+
const isDev = config.dev ?? false;
|
|
160
|
+
|
|
161
|
+
const routesDir = isAbsolute(routes)
|
|
162
|
+
? routes.replace(/\0/g, "")
|
|
163
|
+
: join(process.cwd(), routes).replace(/\0/g, "");
|
|
164
|
+
const tree = await scanRoutes(routesDir, process.cwd());
|
|
165
|
+
// the compiler checks literal <a href="/…"> against these
|
|
166
|
+
setKnownRoutes(linkableRoutes(tree).map(routeId));
|
|
167
|
+
// and writes $env/static values into the code, read now, as documented
|
|
168
|
+
setStaticEnv(filterPublic(process.env), filterPrivate(process.env));
|
|
169
|
+
|
|
170
|
+
const outDir = join(process.cwd(), ".grimoire");
|
|
171
|
+
await mkdir(outDir, { recursive: true });
|
|
172
|
+
|
|
173
|
+
await generateTypes(tree, {
|
|
174
|
+
projectRoot: process.cwd(),
|
|
175
|
+
routesDir,
|
|
176
|
+
outDir: join(outDir, "types"),
|
|
177
|
+
aliases: projectAliases(config),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const { generateEnvTypes } = await import("../env/typegen");
|
|
181
|
+
const envTypeDir = join(outDir, "types");
|
|
182
|
+
await mkdir(envTypeDir, { recursive: true });
|
|
183
|
+
await generateEnvTypes(process.cwd(), envTypeDir);
|
|
184
|
+
|
|
185
|
+
const compiledDir = join(outDir, "compiled");
|
|
186
|
+
await mkdir(compiledDir, { recursive: true });
|
|
187
|
+
|
|
188
|
+
const clientRoutes = [
|
|
189
|
+
...tree.routes.filter((r) => r.type === "page" || r.type === "simple"),
|
|
190
|
+
...tree.layouts.filter((r) => r.type === "layout"),
|
|
191
|
+
];
|
|
192
|
+
|
|
193
|
+
const [hydrateFiles, domFiles] = await Promise.all([
|
|
194
|
+
transformRoutes(clientRoutes, compiledDir, "hydrate", plugins),
|
|
195
|
+
transformRoutes(clientRoutes, compiledDir, "dom", plugins),
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const hydrateManifest = join(process.cwd(), ".grimoire/_routes.hydrate.js");
|
|
199
|
+
const domManifest = join(process.cwd(), ".grimoire/_routes.dom.js");
|
|
200
|
+
await Promise.all([
|
|
201
|
+
Bun.write(
|
|
202
|
+
hydrateManifest,
|
|
203
|
+
generateManifest(clientRoutes, hydrateFiles, tree.paramMatcherFiles),
|
|
204
|
+
),
|
|
205
|
+
Bun.write(
|
|
206
|
+
domManifest,
|
|
207
|
+
generateManifest(clientRoutes, domFiles, tree.paramMatcherFiles),
|
|
208
|
+
),
|
|
209
|
+
]);
|
|
210
|
+
|
|
211
|
+
const bundleStrategy = config.bundleStrategy ?? "split";
|
|
212
|
+
const bundleDir = clientDir();
|
|
213
|
+
await resetClientDir();
|
|
214
|
+
|
|
215
|
+
if (bundleStrategy === "single") {
|
|
216
|
+
const singleResult = await Bun.build({
|
|
217
|
+
entrypoints: [
|
|
218
|
+
join(import.meta.dir, "../rendering/hydrate.ts"),
|
|
219
|
+
join(import.meta.dir, "../client/index.ts"),
|
|
220
|
+
],
|
|
221
|
+
outdir: bundleDir,
|
|
222
|
+
naming: { entry: "[name]-[hash].[ext]" },
|
|
223
|
+
// report failures in result.logs instead of throwing past them
|
|
224
|
+
throw: false,
|
|
225
|
+
// lazy route entries in the manifest use dynamic import()
|
|
226
|
+
splitting: true,
|
|
227
|
+
plugins: [
|
|
228
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
229
|
+
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
230
|
+
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
231
|
+
makeRoutesPlugin(hydrateManifest),
|
|
232
|
+
makeRoutesPlugin(domManifest),
|
|
233
|
+
resolverPlugin(config, "browser"),
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (!singleResult.success) {
|
|
238
|
+
for (const log of singleResult.logs) console.error(log);
|
|
239
|
+
} else {
|
|
240
|
+
recordClientEntry(singleResult.outputs);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const result: BuildResult = {
|
|
244
|
+
success: singleResult.success,
|
|
245
|
+
outputs: singleResult.outputs.map((o) => o.path),
|
|
246
|
+
errors: singleResult.logs.map(String),
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
await runHook(plugins, "onBuildEnd", result);
|
|
250
|
+
return { result, tree };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const [hydrateResult, domResult] = await Promise.all([
|
|
254
|
+
Bun.build({
|
|
255
|
+
entrypoints: [join(import.meta.dir, "../rendering/hydrate.ts")],
|
|
256
|
+
outdir: bundleDir,
|
|
257
|
+
naming: { entry: "[name]-[hash].[ext]" },
|
|
258
|
+
// report failures in result.logs instead of throwing past them
|
|
259
|
+
throw: false,
|
|
260
|
+
// lazy route entries in the manifest use dynamic import()
|
|
261
|
+
splitting: true,
|
|
262
|
+
plugins: [
|
|
263
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
264
|
+
sigil({ mode: "hydrate", dev: isDev, aliases: projectAliases(config) }),
|
|
265
|
+
makeRoutesPlugin(hydrateManifest),
|
|
266
|
+
resolverPlugin(config, "browser"),
|
|
267
|
+
],
|
|
268
|
+
}),
|
|
269
|
+
Bun.build({
|
|
270
|
+
entrypoints: [join(import.meta.dir, "../client/index.ts")],
|
|
271
|
+
outdir: bundleDir,
|
|
272
|
+
naming: { entry: "[name]-[hash].[ext]" },
|
|
273
|
+
// report failures in result.logs instead of throwing past them
|
|
274
|
+
throw: false,
|
|
275
|
+
splitting: true,
|
|
276
|
+
plugins: [
|
|
277
|
+
...(isDev ? [sharedDevRuntime] : []),
|
|
278
|
+
sigil({ mode: "dom", dev: isDev, aliases: projectAliases(config) }),
|
|
279
|
+
makeRoutesPlugin(domManifest),
|
|
280
|
+
resolverPlugin(config, "browser"),
|
|
281
|
+
],
|
|
282
|
+
}),
|
|
283
|
+
]);
|
|
284
|
+
|
|
285
|
+
if (!hydrateResult.success) {
|
|
286
|
+
for (const log of hydrateResult.logs) console.error(log);
|
|
287
|
+
} else {
|
|
288
|
+
recordClientEntry(hydrateResult.outputs);
|
|
289
|
+
}
|
|
290
|
+
if (!domResult.success) {
|
|
291
|
+
for (const log of domResult.logs) console.error(log);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const result: BuildResult = {
|
|
295
|
+
success: hydrateResult.success && domResult.success,
|
|
296
|
+
outputs: [...hydrateResult.outputs, ...domResult.outputs].map(
|
|
297
|
+
(o) => o.path,
|
|
298
|
+
),
|
|
299
|
+
errors: [...hydrateResult.logs, ...domResult.logs].map(String),
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
await runHook(plugins, "onBuildEnd", result);
|
|
303
|
+
return { result, tree };
|
|
304
|
+
}
|