@sigil-dev/grimoire 0.9.28 → 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/dev/hmr-server.ts
CHANGED
|
@@ -1,266 +1,274 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
|
-
import type { ServerWebSocket } from "bun";
|
|
3
|
-
import { log } from "../logger/instance";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private
|
|
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
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (e
|
|
74
|
-
return String(e);
|
|
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
|
-
async
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
ctx
|
|
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
|
-
const
|
|
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
|
-
const
|
|
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
|
-
}
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import type { ServerWebSocket } from "bun";
|
|
3
|
+
import { log } from "../logger/instance";
|
|
4
|
+
import { serverOnlyReason } from "../server-only";
|
|
5
|
+
import { cacheDevModule, compileForBrowser } from "./compile-module";
|
|
6
|
+
import type { DevGraph } from "./graph";
|
|
7
|
+
import { normalizePath } from "./paths";
|
|
8
|
+
import { isSourceFile } from "./resolve";
|
|
9
|
+
import { crawlFrom } from "./scan";
|
|
10
|
+
import { safeRead } from "./watcher";
|
|
11
|
+
|
|
12
|
+
const logger = log.scope("hmr");
|
|
13
|
+
|
|
14
|
+
export class HmrServer {
|
|
15
|
+
private clients = new Set<ServerWebSocket<unknown>>();
|
|
16
|
+
private v = 0;
|
|
17
|
+
get clientCount() {
|
|
18
|
+
return this.clients.size;
|
|
19
|
+
}
|
|
20
|
+
addClient(ws: ServerWebSocket<unknown>) {
|
|
21
|
+
this.clients.add(ws);
|
|
22
|
+
ws.send(JSON.stringify({ type: "connected" }));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
removeClient(ws: ServerWebSocket<unknown>) {
|
|
26
|
+
this.clients.delete(ws);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
send(msg: object) {
|
|
30
|
+
const s = JSON.stringify(msg);
|
|
31
|
+
for (const c of this.clients) c.send(s);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
batch(payloads: object[]) {
|
|
35
|
+
this.send({ type: "batch", payloads, v: ++this.v });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
reload() {
|
|
39
|
+
logger.info("sending reload to", this.clients.size, "clients");
|
|
40
|
+
this.batch([{ kind: "reload" }]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
error(message: string, loc?: { file: string; line: number; col: number }) {
|
|
44
|
+
this.send({ type: "error", message, loc });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ErrorLoc {
|
|
49
|
+
file: string;
|
|
50
|
+
line: number;
|
|
51
|
+
col: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function extractLoc(e: unknown, filePath: string): ErrorLoc | undefined {
|
|
55
|
+
// Babel errors carry loc.line / loc.column
|
|
56
|
+
if (e && typeof e === "object" && "loc" in e) {
|
|
57
|
+
const loc = e.loc;
|
|
58
|
+
if (loc && typeof loc === "object" && "line" in loc) {
|
|
59
|
+
const line = Number(loc.line);
|
|
60
|
+
const col = "column" in loc ? Number(loc.column) : 0;
|
|
61
|
+
if (Number.isFinite(line))
|
|
62
|
+
return { file: filePath, line, col: Number.isFinite(col) ? col : 0 };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// fallback: parse a trailing "file:line:col" out of the message
|
|
66
|
+
const m = errorMessage(e).match(/:(\d+):(\d+)$/);
|
|
67
|
+
return m
|
|
68
|
+
? { file: filePath, line: Number(m[1]), col: Number(m[2]) }
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function errorMessage(e: unknown): string {
|
|
73
|
+
if (e instanceof Error) return e.message;
|
|
74
|
+
if (e && typeof e === "object" && "message" in e) return String(e.message);
|
|
75
|
+
return String(e);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DevContext {
|
|
79
|
+
graph: DevGraph;
|
|
80
|
+
hmr: HmrServer;
|
|
81
|
+
projectRoot: string;
|
|
82
|
+
/** GrimoireConfig.alias — prefix → project-relative directory. */
|
|
83
|
+
aliases: Record<string, string>;
|
|
84
|
+
/** Route/layout/server files the graph is crawled from. */
|
|
85
|
+
entries: () => string[];
|
|
86
|
+
/**
|
|
87
|
+
* Rescan routes and rebuild the client bundles. Awaited before a full
|
|
88
|
+
* reload: `hydrate.js` is built once at startup, so reloading without a
|
|
89
|
+
* rebuild would serve the browser the code from before the edit.
|
|
90
|
+
*/
|
|
91
|
+
rebuild: () => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Same rebuild, off the critical path. Runs after a hot swap so that a
|
|
94
|
+
* later manual refresh — which loads the prebuilt bundle, not the swapped
|
|
95
|
+
* modules — shows the same code the running page already has.
|
|
96
|
+
*/
|
|
97
|
+
scheduleRebuild: () => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `src/lib/Card.tsx` → the `/__grimoire__/m/` path the client imports. */
|
|
101
|
+
const clientModulePath = (filePath: string, projectRoot: string): string =>
|
|
102
|
+
`${relative(projectRoot, filePath).replace(/\\/g, "/")}.js`;
|
|
103
|
+
|
|
104
|
+
interface RouteEntryPayload {
|
|
105
|
+
pattern: string;
|
|
106
|
+
modUrl: string;
|
|
107
|
+
version: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface LayoutEntryPayload {
|
|
111
|
+
path: string;
|
|
112
|
+
modUrl: string;
|
|
113
|
+
version: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Does an edit to this file change what a `load` returns? Route modules own
|
|
118
|
+
* their data loaders, so a swap alone would re-render the new component
|
|
119
|
+
* against data produced by the old loader.
|
|
120
|
+
*/
|
|
121
|
+
function affectsData(
|
|
122
|
+
filePath: string,
|
|
123
|
+
source: string,
|
|
124
|
+
projectRoot: string,
|
|
125
|
+
): boolean {
|
|
126
|
+
if (serverOnlyReason(filePath, projectRoot)) return true;
|
|
127
|
+
return /\bexport\s+(async\s+)?(function\s+load\b|const\s+load\b|const\s+actions\b|function\s+canMatch\b|const\s+canMatch\b)/.test(
|
|
128
|
+
source,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function fullReload(ctx: DevContext): Promise<void> {
|
|
133
|
+
await ctx.rebuild();
|
|
134
|
+
ctx.hmr.reload();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function handleChange(
|
|
138
|
+
filePath: string,
|
|
139
|
+
ctx: DevContext,
|
|
140
|
+
): Promise<void> {
|
|
141
|
+
const { graph, hmr, projectRoot } = ctx;
|
|
142
|
+
const key = normalizePath(filePath);
|
|
143
|
+
|
|
144
|
+
if (!isSourceFile(filePath)) {
|
|
145
|
+
logger.info("non-source change, reloading:", filePath);
|
|
146
|
+
await fullReload(ctx);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const source = await safeRead(filePath);
|
|
151
|
+
if (source === null) {
|
|
152
|
+
// deleted or unreadable — the module graph can't be trusted any more
|
|
153
|
+
await fullReload(ctx);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!graph.get(key)) {
|
|
158
|
+
// a brand-new file, or one that just became imported: recrawl from the
|
|
159
|
+
// route entries before giving up on a targeted update
|
|
160
|
+
await crawlFrom(ctx.entries(), {
|
|
161
|
+
graph,
|
|
162
|
+
projectRoot,
|
|
163
|
+
aliases: ctx.aliases,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (!graph.get(key)) {
|
|
167
|
+
logger.info("file outside the route graph, reloading:", filePath);
|
|
168
|
+
await fullReload(ctx);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// the edit may have added imports — pick them up before propagating
|
|
173
|
+
await crawlFrom([filePath], { graph, projectRoot, aliases: ctx.aliases });
|
|
174
|
+
|
|
175
|
+
// error pages render on the server only: compiling one for the browser can
|
|
176
|
+
// fail on code that never ships there, and a failure would throw the edit
|
|
177
|
+
// away before the SSR loader ever saw the new version
|
|
178
|
+
const reaches = graph.affectedRoutes(key);
|
|
179
|
+
// server-only code (a server file, src/lib/server/) never ships to the
|
|
180
|
+
// browser, so it is never compiled for it
|
|
181
|
+
const isClient =
|
|
182
|
+
!serverOnlyReason(filePath, projectRoot) &&
|
|
183
|
+
reaches.some((r) => r.type !== "error");
|
|
184
|
+
let css: { hash: string; text: string } | null = null;
|
|
185
|
+
let compiled: string | null = null;
|
|
186
|
+
|
|
187
|
+
if (isClient) {
|
|
188
|
+
// compile the edited source before bumping anything: on a syntax error
|
|
189
|
+
// the overlay goes up and every previous version stays live, in the
|
|
190
|
+
// browser and in SSR alike. Never read the cache here — the whole point
|
|
191
|
+
// is to see what the developer just typed.
|
|
192
|
+
try {
|
|
193
|
+
const result = await compileForBrowser(filePath, {
|
|
194
|
+
projectRoot,
|
|
195
|
+
aliases: ctx.aliases,
|
|
196
|
+
graph,
|
|
197
|
+
});
|
|
198
|
+
compiled = result.js;
|
|
199
|
+
if (result.css) css = { hash: result.cssHash, text: result.css };
|
|
200
|
+
} catch (e: unknown) {
|
|
201
|
+
const message = errorMessage(e);
|
|
202
|
+
logger.error("compile error:", message);
|
|
203
|
+
hmr.error(message, extractLoc(e, filePath));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// bump this module and every importer up to the routes, invalidating the
|
|
209
|
+
// SSR loader's cache and every stamped browser URL along the way
|
|
210
|
+
graph.invalidate(key);
|
|
211
|
+
if (compiled !== null) {
|
|
212
|
+
// dep versions are untouched by the bump, so the output just compiled
|
|
213
|
+
// is exactly what this new version should serve
|
|
214
|
+
cacheDevModule(
|
|
215
|
+
filePath,
|
|
216
|
+
graph.get(key)?.version ?? 0,
|
|
217
|
+
projectRoot,
|
|
218
|
+
compiled,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const affected = reaches;
|
|
223
|
+
if (affected.length === 0) {
|
|
224
|
+
logger.info("no route reaches this module, reloading:", filePath);
|
|
225
|
+
await fullReload(ctx);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const routeEntries: RouteEntryPayload[] = [];
|
|
230
|
+
const layoutEntries: LayoutEntryPayload[] = [];
|
|
231
|
+
let serverTouched = false;
|
|
232
|
+
let needsReload = false;
|
|
233
|
+
|
|
234
|
+
for (const route of affected) {
|
|
235
|
+
const modUrl = clientModulePath(route.filePath, projectRoot);
|
|
236
|
+
const version = graph.get(route.filePath)?.version ?? 0;
|
|
237
|
+
if (route.type === "page" || route.type === "simple") {
|
|
238
|
+
routeEntries.push({ pattern: route.path, modUrl, version });
|
|
239
|
+
} else if (route.type === "layout") {
|
|
240
|
+
layoutEntries.push({ path: route.path, modUrl, version });
|
|
241
|
+
} else if (route.type === "error") {
|
|
242
|
+
// error pages are never in the client route table — only a document
|
|
243
|
+
// request re-renders one
|
|
244
|
+
needsReload = true;
|
|
245
|
+
} else {
|
|
246
|
+
// +page.server / +layout.server / +server: nothing the client can
|
|
247
|
+
// swap, but the data behind the current page just changed
|
|
248
|
+
serverTouched = true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (needsReload) {
|
|
253
|
+
await fullReload(ctx);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const payloads: object[] = [];
|
|
258
|
+
if (css) payloads.push({ kind: "css", ...css });
|
|
259
|
+
if (routeEntries.length)
|
|
260
|
+
payloads.push({ kind: "routes", entries: routeEntries });
|
|
261
|
+
if (layoutEntries.length)
|
|
262
|
+
payloads.push({ kind: "layouts", entries: layoutEntries });
|
|
263
|
+
if (serverTouched || affectsData(filePath, source, projectRoot))
|
|
264
|
+
payloads.push({ kind: "invalidate" });
|
|
265
|
+
|
|
266
|
+
const summary = affected.map((r) => `${r.type} ${r.path}`).join(", ");
|
|
267
|
+
logger.info(
|
|
268
|
+
`changed ${relative(projectRoot, filePath).replace(/\\/g, "/")} → ${summary}`,
|
|
269
|
+
);
|
|
270
|
+
hmr.batch(payloads);
|
|
271
|
+
// the prebuilt bundles still hold pre-edit code; refresh them so a manual
|
|
272
|
+
// reload agrees with the hot-swapped page
|
|
273
|
+
ctx.scheduleRebuild();
|
|
274
|
+
}
|