@co0ontty/wand 1.35.2 → 1.37.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.
@@ -2,12 +2,26 @@ import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
- // Cache the CSS content
5
+ // mtime 做缓存键,磁盘上 CSS 一变(npm run build / 手工 edit dist/)下次请求
6
+ // 就会自动 re-read。否则进程启动时缓存的 CSS 会粘住整个生命周期,UI 改动看不到效果,
7
+ // 必须重启 wand 才能生效——开发 / 修 UI 的时候这点尤其难受。
8
+ // 同步 stat 的成本:本地 fs,~几十微秒,相对一次 HTML 渲染可忽略。
6
9
  let _cssCache = null;
10
+ let _cssCacheMtimeMs = 0;
7
11
  export function getCSSStyles() {
8
- if (!_cssCache) {
9
- const cssPath = path.join(__dirname, "content", "styles.css");
10
- _cssCache = fs.readFileSync(cssPath, "utf-8");
12
+ const cssPath = path.join(__dirname, "content", "styles.css");
13
+ try {
14
+ const stat = fs.statSync(cssPath);
15
+ if (_cssCache === null || stat.mtimeMs !== _cssCacheMtimeMs) {
16
+ _cssCache = fs.readFileSync(cssPath, "utf-8");
17
+ _cssCacheMtimeMs = stat.mtimeMs;
18
+ }
19
+ }
20
+ catch {
21
+ // 文件丢了就退化到旧缓存(如果有),还没缓存过就抛出原错误让 server 知道。
22
+ if (_cssCache === null) {
23
+ _cssCache = fs.readFileSync(cssPath, "utf-8");
24
+ }
11
25
  }
12
26
  return _cssCache;
13
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@co0ontty/wand",
3
- "version": "1.35.2",
3
+ "version": "1.37.0",
4
4
  "description": "A web terminal for local CLI tools like Claude.",
5
5
  "type": "module",
6
6
  "bin": {