import type { IsomorphicRollupFs, Stats } from "../fs-iface"; import nodeFs from "fs"; const nodeFsAdapter: IsomorphicRollupFs = { access: async function (path: string): Promise { try { return !!(await nodeFs.promises.stat(path)); } catch (_) { return false; } }, readFile: function ( path: string, encoding?: "utf8", ): Promise { const options: { encoding: "utf-8" } | undefined = encoding ? { encoding: "utf-8" } : undefined; return nodeFs.promises.readFile(path, options) as Promise< string | Uint8Array >; }, realpath: function (path: string): Promise { return nodeFs.promises.realpath(path); }, realpathSync: function (path: string): string { return nodeFs.realpathSync(path); }, stat: function (path: string): Promise { return nodeFs.promises.stat(path) as unknown as Promise; }, mkdir: async function ( path: string, options?: { recursive?: boolean }, ): Promise { await nodeFs.promises.mkdir(path, options); }, writeFile: function ( path: string, data: string | Uint8Array, encoding?: "utf8", ): Promise { return nodeFs.promises.writeFile(path, data, encoding); }, promises: { lstat(path: string) { return nodeFs.promises.stat(path); }, readdir(path: string, options: { withFileTypes: true }) { return nodeFs.promises.readdir(path, options); }, readlink(path) { return nodeFs.promises.realpath(path); }, realpath(path) { return nodeFs.promises.realpath(path); }, }, }; export default nodeFsAdapter;