Refactor file access to use fs-safe primitives (#78255)

* refactor: use fs-safe primitives across file access

* fix: preserve invalid managed npm manifests

* fix: keep fs seams for startup metadata
This commit is contained in:
Peter Steinberger
2026-05-06 05:03:11 +01:00
committed by GitHub
parent 0d73f174a9
commit b85b1c68d1
56 changed files with 409 additions and 568 deletions

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import { createRequire } from "node:module";
import type { ThemeRegistrationResolved } from "@pierre/diffs";
import { RegisteredCustomThemes, ResolvedThemes, ResolvingThemes } from "@pierre/diffs";
import { readJsonFileWithFallback } from "openclaw/plugin-sdk/json-store";
type PierreThemeName = "pierre-dark" | "pierre-light";
const themeRequire = createRequire(import.meta.url);
@@ -20,8 +20,9 @@ function createThemeLoader(
return cachedTheme;
}
const themePath = themeRequire.resolve(themeSpecifier);
const { value: theme } = await readJsonFileWithFallback<Record<string, unknown>>(themePath, {});
cachedTheme = {
...(JSON.parse(await fs.readFile(themePath, "utf8")) as Record<string, unknown>),
...theme,
name: themeName,
} as ThemeRegistrationResolved;
return cachedTheme;

View File

@@ -174,13 +174,13 @@ export class DiffArtifactStore {
}
async cleanupExpired(): Promise<void> {
await this.ensureRoot();
const entries = await fs.readdir(this.rootDir, { withFileTypes: true }).catch(() => []);
const root = await this.artifactRoot();
const entries = await root.list("", { withFileTypes: true }).catch(() => []);
const now = Date.now();
await Promise.all(
entries
.filter((entry) => entry.isDirectory())
.filter((entry) => entry.isDirectory)
.map(async (entry) => {
const id = entry.name;
const meta = await this.readMeta(id);
@@ -199,12 +199,7 @@ export class DiffArtifactStore {
return;
}
const artifactPath = this.artifactDir(id);
const stat = await fs.stat(artifactPath).catch(() => null);
if (!stat) {
return;
}
if (now - stat.mtimeMs > SWEEP_FALLBACK_AGE_MS) {
if (now - entry.mtimeMs > SWEEP_FALLBACK_AGE_MS) {
await this.deleteArtifact(id);
}
}),