@sigil-dev/grimoire 0.8.6 → 0.9.0
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/package.json +4 -6
- package/server.ts +5 -1
- package/src/client/deps.ts +13 -0
- package/src/client/head.ts +1 -0
- package/src/client/router.ts +308 -228
- package/src/dev/compile-module.ts +1 -1
- package/src/dev/hmr-client.ts +30 -3
- package/src/dev/hmr-server.ts +187 -187
- package/src/dev/watcher.ts +4 -2
- package/src/env/dynamic-private.ts +19 -0
- package/src/env/dynamic-public.ts +22 -0
- package/src/env/plugin.ts +6 -0
- package/src/env/typegen.ts +10 -0
- package/src/logger/index.ts +0 -2
- package/src/rendering/index.ts +137 -63
- package/src/server/build.ts +199 -219
- package/src/server/coordinator.ts +316 -232
- package/src/server/index.ts +623 -622
- package/src/server/interactive.ts +56 -54
- package/src/server/plugins.ts +2 -1
- package/src/types.ts +282 -272
- package/test/client-router.test.ts +38 -0
- package/test/env.test.ts +90 -0
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
export interface InteractiveOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns a promise that resolves only when explicitly settled.
|
|
9
|
-
* Used to keep the dev/start process alive until the user quits.
|
|
10
|
-
*/
|
|
11
|
-
export function createWaiter() {
|
|
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
|
-
|
|
1
|
+
export interface InteractiveOptions {
|
|
2
|
+
onQuit: () => void | Promise<void>;
|
|
3
|
+
onRestart: () => void | Promise<void>;
|
|
4
|
+
onClear: () => void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns a promise that resolves only when explicitly settled.
|
|
9
|
+
* Used to keep the dev/start process alive until the user quits.
|
|
10
|
+
*/
|
|
11
|
+
export function createWaiter() {
|
|
12
|
+
let resolve!: () => void;
|
|
13
|
+
const promise = new Promise<void>((r) => {
|
|
14
|
+
resolve = r;
|
|
15
|
+
});
|
|
16
|
+
return { promise, resolve };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Listen for interactive keypresses in dev mode.
|
|
21
|
+
* Mirrors Vite's UX: q=quit, r=restart, c=clear.
|
|
22
|
+
* Falls back gracefully if stdin is not a TTY (CI, piped input).
|
|
23
|
+
*/
|
|
24
|
+
export function listenForKeys(opts: InteractiveOptions) {
|
|
25
|
+
if (!process.stdin.isTTY) return;
|
|
26
|
+
|
|
27
|
+
process.stdin.setRawMode(true);
|
|
28
|
+
process.stdin.resume();
|
|
29
|
+
process.stdin.setEncoding("utf8");
|
|
30
|
+
|
|
31
|
+
process.stdin.on("data", async (key: string) => {
|
|
32
|
+
// ctrl+c
|
|
33
|
+
if (key === "\x03") {
|
|
34
|
+
await opts.onQuit();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch (key.toLowerCase()) {
|
|
39
|
+
case "q":
|
|
40
|
+
await opts.onQuit();
|
|
41
|
+
break;
|
|
42
|
+
case "r":
|
|
43
|
+
await opts.onRestart();
|
|
44
|
+
break;
|
|
45
|
+
case "c":
|
|
46
|
+
opts.onClear();
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function stopListening() {
|
|
53
|
+
if (!process.stdin.isTTY) return;
|
|
54
|
+
process.stdin.setRawMode(false);
|
|
55
|
+
process.stdin.pause();
|
|
56
|
+
}
|
package/src/server/plugins.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
BuildResult,
|
|
4
4
|
CoordinatorContext,
|
|
5
5
|
GrimoirePlugin,
|
|
6
|
-
LoadContext,
|
|
6
|
+
LoadContext, PluginContext,
|
|
7
7
|
Route,
|
|
8
8
|
Server,
|
|
9
9
|
WorkerDescriptor,
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
// calling conventions (middleware chain / inline transform loop) handled in index.ts.
|
|
16
16
|
// Keep HookArgs in sync with GrimoirePlugin in types.ts.
|
|
17
17
|
type HookArgs = {
|
|
18
|
+
onPluginsResolved: [ctx: PluginContext];
|
|
18
19
|
onStart: [server: Server];
|
|
19
20
|
onStop: [reason: "shutdown" | "restart"];
|
|
20
21
|
onBuildStart: [];
|