修复:生成绑定校验的目录快照支持子目录并规范化路径
- snapshot() 原来只列目录下一层文件,绑定若放进子目录就两边快照都看不见,陈旧绑定会被漏掉 - 改用 readdirSync 的 recursive 列出全部条目,再按文件过滤并归一到 POSIX 分隔符,键形态与原来保持兼容
This commit is contained in:
@@ -77,14 +77,14 @@ function snapshot(dir) {
|
||||
console.warn(`目录不存在,跳过校验:${dir}`);
|
||||
return new Map();
|
||||
}
|
||||
const entries = fs.readdirSync(absolute, { recursive: true });
|
||||
return new Map(
|
||||
fs
|
||||
.readdirSync(absolute, { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
.map((entry) => [
|
||||
path.posix.join(dir, entry.name),
|
||||
fs.readFileSync(path.join(absolute, entry.name)),
|
||||
]),
|
||||
entries.flatMap((entry) => {
|
||||
const absoluteFile = path.join(absolute, entry);
|
||||
if (!fs.lstatSync(absoluteFile).isFile()) return [];
|
||||
const name = path.posix.join(dir, entry.split(path.sep).join('/'));
|
||||
return [[name, fs.readFileSync(absoluteFile)]];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user