index.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Stats, Dirent, Volume, StatWatcher, FSWatcher } from '@jsonjoy.com/fs-node';
  2. import type { IWriteStream } from '@jsonjoy.com/fs-node';
  3. import { DirectoryJSON, NestedDirectoryJSON, type IProcess } from '@jsonjoy.com/fs-core';
  4. import { constants } from '@jsonjoy.com/fs-node-utils';
  5. import type { FsPromisesApi } from '@jsonjoy.com/fs-node-utils';
  6. import type * as misc from '@jsonjoy.com/fs-node-utils/lib/types/misc';
  7. export { DirectoryJSON, NestedDirectoryJSON, Volume };
  8. export type { IProcess };
  9. export declare const vol: Volume;
  10. export interface IFs extends Volume {
  11. constants: typeof constants;
  12. Stats: new (...args: any[]) => Stats;
  13. Dirent: new (...args: any[]) => Dirent;
  14. StatWatcher: new () => StatWatcher;
  15. FSWatcher: new () => FSWatcher;
  16. ReadStream: new (...args: any[]) => misc.IReadStream;
  17. WriteStream: new (...args: any[]) => IWriteStream;
  18. promises: FsPromisesApi;
  19. _toUnixTimestamp: any;
  20. }
  21. export declare function createFsFromVolume(vol: Volume): IFs;
  22. export declare const fs: IFs;
  23. /** Options for creating a memfs instance. */
  24. export interface MemfsOptions {
  25. /** Custom working directory for resolving relative paths. Defaults to `'/'`. */
  26. cwd?: string;
  27. /** Custom `process`-like object for controlling platform, uid, gid, and cwd behavior. */
  28. process?: IProcess;
  29. }
  30. /**
  31. * Creates a new file system instance.
  32. *
  33. * @param json File system structure expressed as a JSON object.
  34. * Use `null` for empty directories and empty string for empty files.
  35. * @param cwdOrOpts Current working directory (string) or options object.
  36. * The JSON structure will be created relative to the cwd path.
  37. * @returns A `memfs` file system instance, which is a drop-in replacement for
  38. * the `fs` module.
  39. */
  40. export declare const memfs: (json?: NestedDirectoryJSON, cwdOrOpts?: string | MemfsOptions) => {
  41. fs: IFs;
  42. vol: Volume;
  43. };
  44. export type IFsWithVolume = IFs & {
  45. __vol: Volume;
  46. };