koguma 2.3.1 → 2.3.2
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 +1 -1
- package/src/admin/_bundle.ts +1 -1
- package/src/vite.js +17 -8
- package/src/vite.ts +23 -11
package/src/vite.js
CHANGED
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
// src/vite.ts
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
4
|
-
import {
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
function kogumaHMR() {
|
|
6
|
-
const
|
|
6
|
+
const HASH_FILENAME = "dbhash";
|
|
7
|
+
const HASH_DIR = ".koguma";
|
|
8
|
+
const HASH_SUBPATH = `${HASH_DIR}/${HASH_FILENAME}`;
|
|
9
|
+
const SQLITE_GLOB = "**/.koguma/.wrangler/state/v3/d1/**/*.sqlite";
|
|
7
10
|
return {
|
|
8
11
|
name: "koguma-hmr",
|
|
9
12
|
configureServer(server) {
|
|
10
13
|
const root = server.config.root;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
server.watcher.add(
|
|
14
|
+
const hashDir = join(root, HASH_DIR);
|
|
15
|
+
const hashPath = join(root, HASH_SUBPATH);
|
|
16
|
+
server.watcher.add(SQLITE_GLOB);
|
|
14
17
|
server.watcher.on("change", (file) => {
|
|
15
|
-
if (!file.includes(".wrangler/state/v3/d1") || !file.endsWith(".sqlite"))
|
|
18
|
+
if (!file.includes(".koguma/.wrangler/state/v3/d1") || !file.endsWith(".sqlite"))
|
|
16
19
|
return;
|
|
17
20
|
try {
|
|
18
21
|
const hash = createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
19
|
-
if (!existsSync(
|
|
20
|
-
mkdirSync(
|
|
22
|
+
if (!existsSync(hashDir))
|
|
23
|
+
mkdirSync(hashDir, { recursive: true });
|
|
21
24
|
writeFileSync(hashPath, hash);
|
|
22
25
|
} catch {}
|
|
23
26
|
});
|
|
24
27
|
server.watcher.add(hashPath);
|
|
25
28
|
},
|
|
29
|
+
handleHotUpdate({ file, server }) {
|
|
30
|
+
if (file.endsWith(HASH_FILENAME) && file.includes(HASH_DIR)) {
|
|
31
|
+
server.ws.send({ type: "full-reload" });
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
},
|
|
26
35
|
config() {
|
|
27
36
|
return {
|
|
28
37
|
server: {
|
package/src/vite.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { createHash } from 'node:crypto';
|
|
14
14
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
15
|
-
import {
|
|
15
|
+
import { join } from 'node:path';
|
|
16
16
|
import type { Plugin } from 'vite';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -28,22 +28,27 @@ import type { Plugin } from 'vite';
|
|
|
28
28
|
* browser refetches fresh content on each reload.
|
|
29
29
|
*/
|
|
30
30
|
export function kogumaHMR(): Plugin {
|
|
31
|
-
const
|
|
31
|
+
const HASH_FILENAME = 'dbhash';
|
|
32
|
+
const HASH_DIR = '.koguma';
|
|
33
|
+
const HASH_SUBPATH = `${HASH_DIR}/${HASH_FILENAME}`;
|
|
34
|
+
|
|
35
|
+
// Glob passed to chokidar — must NOT go through path.resolve or the ** breaks
|
|
36
|
+
const SQLITE_GLOB = '**/.koguma/.wrangler/state/v3/d1/**/*.sqlite';
|
|
32
37
|
|
|
33
38
|
return {
|
|
34
39
|
name: 'koguma-hmr',
|
|
35
40
|
|
|
36
41
|
configureServer(server) {
|
|
37
42
|
const root = server.config.root;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
43
|
+
const hashDir = join(root, HASH_DIR);
|
|
44
|
+
const hashPath = join(root, HASH_SUBPATH);
|
|
40
45
|
|
|
41
|
-
//
|
|
42
|
-
server.watcher.add(
|
|
46
|
+
// Add the wrangler SQLite glob directly (no resolve — globs need literal **)
|
|
47
|
+
server.watcher.add(SQLITE_GLOB);
|
|
43
48
|
|
|
44
49
|
server.watcher.on('change', (file: string) => {
|
|
45
50
|
if (
|
|
46
|
-
!file.includes('.wrangler/state/v3/d1') ||
|
|
51
|
+
!file.includes('.koguma/.wrangler/state/v3/d1') ||
|
|
47
52
|
!file.endsWith('.sqlite')
|
|
48
53
|
)
|
|
49
54
|
return;
|
|
@@ -51,19 +56,26 @@ export function kogumaHMR(): Plugin {
|
|
|
51
56
|
const hash = createHash('sha256')
|
|
52
57
|
.update(readFileSync(file))
|
|
53
58
|
.digest('hex');
|
|
54
|
-
if (!existsSync(
|
|
59
|
+
if (!existsSync(hashDir)) mkdirSync(hashDir, { recursive: true });
|
|
55
60
|
writeFileSync(hashPath, hash);
|
|
56
61
|
} catch {
|
|
57
62
|
// SQLite may be locked mid-write — the next write will succeed
|
|
58
63
|
}
|
|
59
64
|
});
|
|
60
65
|
|
|
61
|
-
// Watch the hash file
|
|
62
|
-
//
|
|
63
|
-
// is a full-reload — no handleHotUpdate override needed.
|
|
66
|
+
// Watch the hash file — Vite does NOT auto-reload non-module files,
|
|
67
|
+
// so handleHotUpdate below is required to send the full-reload signal.
|
|
64
68
|
server.watcher.add(hashPath);
|
|
65
69
|
},
|
|
66
70
|
|
|
71
|
+
handleHotUpdate({ file, server }) {
|
|
72
|
+
// When the hash file changes, the DB has new content → reload the page
|
|
73
|
+
if (file.endsWith(HASH_FILENAME) && file.includes(HASH_DIR)) {
|
|
74
|
+
server.ws.send({ type: 'full-reload' });
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
67
79
|
config() {
|
|
68
80
|
return {
|
|
69
81
|
server: {
|