崮生(子虚) 5a7c6a9913 fix: LLRT readdir 不兼容 withFileTypes 导致临时字体清理失效
根因:LLRT 的 fs.readdir 返回字符串数组而非 Dirent 对象,
entry.isFile() 抛 TypeError 被 catch 静默吞掉,
导致 evictIfNeeded 和 temp_cleaner 从未执行(线上堆积 108 个文件 992M)。

修复:
- node.ts: readdir 改为先拿文件名再 stat 判断
- temp_cleaner.ts: catch 块加日志不再静默吞错误

同时包含:
- font-config.json homepage 链接修复(删除 3 个 404,修正 2 个)
- FontDetail 字符预览改为可实时编辑
- 添加 scripts/bench.mjs 压测脚本
2026-08-01 08:03:33 +08:00

42 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { implInterface } from "../interface";
import { stat as fsStat, readFile, writeFile, readdir as fsReaddir, mkdir, unlink } from "fs/promises";
implInterface({
async stat(path) {
const r = await fsStat(path);
return r;
},
readFile(path) {
return readFile(path);
},
writeFile(path, data) {
return writeFile(path, data);
},
/**
* readdir 返回 { name, isFile } 适配对象
*
* 不用 withFileTypesLLRT 的 fs.readdir 不支持该选项,
* 返回的是纯字符串数组而非 Dirent 对象,调用 entry.isFile() 会抛 TypeError。
* 统一用 stat 判断Node 和 LLRT 都兼容。
*/
async readdir(path) {
const names = await fsReaddir(path);
const results: { isFile: () => boolean; name: string }[] = [];
for (const name of names) {
try {
const s = await fsStat(path + "/" + name);
results.push({ name, isFile: () => s.isFile() });
} catch {
/** stat 失败(符号链接断裂等)跳过 */
}
}
return results;
},
async mkdir(path) {
await mkdir(path, { recursive: true });
},
unlink(path) {
return unlink(path);
},
});