Fix typecheck issues

This commit is contained in:
Alex Gleason committed 2025-11-10 09:55:34 -06:00
1 parent cbf18d482d
commit e116f7e9ec
1 file changed
+31 -2
+31 -2
View File
@@ -40,7 +40,10 @@ class MockFS implements JSRuntimeFS {
}
}
async readdir(path: string): Promise<string[]> {
async readdir(path: string): Promise<string[]>;
async readdir(path: string, options: { withFileTypes: true }): Promise<import('./JSRuntime').DirectoryEntry[]>;
async readdir(path: string, options?: { withFileTypes?: boolean }): Promise<string[] | import('./JSRuntime').DirectoryEntry[]>;
async readdir(path: string, options?: { withFileTypes?: boolean }): Promise<string[] | import('./JSRuntime').DirectoryEntry[]> {
if (!this.dirs.has(path)) throw new Error(`ENOENT: ${path}`);
const entries = new Set<string>();
@@ -64,7 +67,21 @@ class MockFS implements JSRuntimeFS {
}
}
return Array.from(entries);
const names = Array.from(entries);
if (options?.withFileTypes) {
return names.map(name => {
const fullPath = path === '/' ? `/${name}` : `${path}/${name}`;
const isDir = this.dirs.has(fullPath);
return {
name,
isDirectory: () => isDir,
isFile: () => !isDir,
};
});
}
return names;
}
async mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {
@@ -125,6 +142,18 @@ class MockFS implements JSRuntimeFS {
this.files.delete(oldPath);
}
}
async lstat(path: string): Promise<{ isDirectory: () => boolean; isFile: () => boolean }> {
return this.stat(path);
}
async readlink(_path: string): Promise<string> {
throw new Error('Symlinks not supported in MockFS');
}
async symlink(_target: string, _path: string): Promise<void> {
throw new Error('Symlinks not supported in MockFS');
}
}
describe('plugins', () => {