import { Dirent, ReadStream, WriteStream } from 'fs'; import { CaseSensitivityDetector } from '../../../common/caseSensitivityDetector'; import { FileSystem, MkDirOptions, TempFile, TmpfileOptions } from '../../../common/fileSystem'; import { FileWatcher, FileWatcherEventHandler, FileWatcherEventType } from '../../../common/fileWatcher'; import { Uri } from '../../../common/uri/uri'; import { Metadata } from './../utils'; import { Disposable } from 'vscode-jsonrpc'; export declare const MODULE_PATH: string; export interface DiffOptions { includeChangedFileWithSameContent?: boolean; } export declare class TestFileSystemWatcher implements FileWatcher { readonly paths: Uri[]; private _listener; constructor(paths: Uri[], _listener: FileWatcherEventHandler); close(): void; fireFileChange(path: Uri, eventType: FileWatcherEventType): boolean; } /** * Represents a virtual POSIX-like file system. */ export declare class TestFileSystem implements FileSystem, TempFile, CaseSensitivityDetector { /** Indicates whether the file system is case-sensitive (`false`) or case-insensitive (`true`). */ readonly ignoreCase: boolean; /** Gets the comparison function used to compare two paths. */ readonly stringComparer: (a: string, b: string) => number; private _lazy; private _cwd; private _time; private _shadowRoot; private _dirStack; private _tmpfileCounter; private _watchers; private _id; private static _nextId; constructor(ignoreCase: boolean, options?: FileSystemOptions); /** * Gets metadata for this `FileSystem`. */ get meta(): Metadata; /** * Gets a value indicating whether the file system is read-only. */ get isReadonly(): boolean; /** * Gets the file system shadowed by this file system. */ get shadowRoot(): TestFileSystem | undefined; get fileWatchers(): TestFileSystemWatcher[]; /** * Makes the file system read-only. */ makeReadonly(): this; /** * Snapshots the current file system, effectively shadowing itself. This is useful for * generating file system patches using `.diff()` from one snapshot to the next. Performs * no action if this file system is read-only. */ snapshot(): void; /** * Gets a shadow copy of this file system. Changes to the shadow copy do not affect the * original, allowing multiple copies of the same core file system without multiple copies * of the same data. */ shadow(ignoreCase?: boolean): TestFileSystem; /** * Gets or sets the timestamp (in milliseconds) used for file status, returning the previous timestamp. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html */ time(value?: number | Date | (() => number | Date)): number; /** * Gets the metadata object for a path. * @param path */ filemeta(path: string): Metadata; /** * Get the pathname of the current working directory. * * @link - http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html */ cwd(): string; /** * Changes the current working directory. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html */ chdir(uri: Uri): void; /** * Pushes the current directory onto the directory stack and changes the current working directory to the supplied path. */ pushd(path?: string): void; /** * Pops the previous directory from the location stack and changes the current directory to that directory. */ popd(): void; /** * Update the file system with a set of files. */ apply(files: FileSet): void; /** * Scan file system entries along a path. If `path` is a symbolic link, it is dereferenced. * @param path The path at which to start the scan. * @param axis The axis along which to traverse. * @param traversal The traversal scheme to use. */ scanSync(path: string, axis: Axis, traversal: Traversal): string[]; /** * Scan file system entries along a path. * @param path The path at which to start the scan. * @param axis The axis along which to traverse. * @param traversal The traversal scheme to use. */ lscanSync(path: string, axis: Axis, traversal: Traversal): string[]; createFileSystemWatcher(paths: Uri[], listener: FileWatcherEventHandler): FileWatcher; fireFileWatcherEvent(path: string, event: FileWatcherEventType): void; getModulePath(): Uri; isCaseSensitive(uri: string): boolean; isLocalFileSystemCaseSensitive(): boolean; tmpdir(): Uri; tmpfile(options?: TmpfileOptions): Uri; realCasePath(path: Uri): Uri; isMappedUri(filepath: Uri): boolean; getOriginalUri(mappedFilePath: Uri): Uri; getMappedUri(originalFilepath: Uri): Uri; /** * Mounts a physical or virtual file system at a location in this virtual file system. * * @param source The path in the physical (or other virtual) file system. * @param target The path in this virtual file system. * @param resolver An object used to resolve files in `source`. */ mountSync(source: string, target: string, resolver: FileSystemResolver): void; /** * Recursively remove all files and directories underneath the provided path. */ rimrafSync(path: string): void; /** * Make a directory and all of its parent paths (if they don't exist). */ mkdirpSync(path: string): void; getFileListing(filter?: (p: string) => boolean): string; /** * Print diagnostic information about the structure of the file system to the console. */ debugPrint(filter?: (p: string) => boolean): void; /** * Determines whether a path exists. */ existsSync(path: Uri): boolean; /** * Get file status. If `path` is a symbolic link, it is dereferenced. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/stat.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ statSync(path: Uri): Stats; /** * Change file access times * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ utimesSync(path: string, atime: Date, mtime: Date): void; /** * Get file status. If `path` is a symbolic link, it is dereferenced. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/lstat.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ lstatSync(path: string): Stats; /** * Read a directory. If `path` is a symbolic link, it is dereferenced. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ readdirSync(path: Uri): string[]; /** * Read a directory. If `path` is a symbolic link, it is dereferenced. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ readdirEntriesSync(path: Uri): Dirent[]; /** * Make a directory. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ mkdirSync(path: Uri, options?: MkDirOptions): void; /** * Remove a directory. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ rmdirSync(uri: Uri): void; /** * Link one file to another file (also known as a "hard link"). * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ linkSync(oldpath: string, newpath: string): void; /** * Remove a directory entry. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ unlinkSync(path: Uri): void; /** * Rename a file. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ renameSync(oldpath: string, newpath: string): void; /** * Make a symbolic link. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ symlinkSync(target: string, linkpath: string): void; /** * Resolve a pathname. * * @link http://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ realpathSync(path: Uri): Uri; /** * Read from a file. * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ readFileSync(path: Uri, encoding?: null): Buffer; /** * Read from a file. * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ readFileSync(path: Uri, encoding: BufferEncoding): string; /** * Read from a file. * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ readFileSync(path: Uri, encoding?: BufferEncoding | null): string | Buffer; /** * Write to a file. * * NOTE: do not rename this method as it is intended to align with the same named export of the "fs" module. */ writeFileSync(uri: Uri, data: string | Buffer, encoding?: BufferEncoding | null): void; readFile(fileUri: Uri): Promise; readFileText(fileUri: Uri, encoding?: BufferEncoding): Promise; createReadStream(path: Uri): ReadStream; createWriteStream(path: Uri): WriteStream; copyFileSync(src: Uri, dst: Uri): void; mapDirectory(mappedUri: Uri, originalUri: Uri, filter?: (originalUri: Uri, fs: FileSystem) => boolean): Disposable; /** * Generates a `FileSet` patch containing all the entries in this `FileSystem` that are not in `base`. * @param base The base file system. If not provided, this file system's `shadowRoot` is used (if present). */ diff(base?: TestFileSystem | undefined, options?: DiffOptions): FileSet | undefined; /** * Generates a `FileSet` patch containing all the entries in `changed` that are not in `base`. */ static diff(changed: TestFileSystem, base: TestFileSystem, options?: DiffOptions): FileSet | undefined; isInZip(path: Uri): boolean; dispose(): void; private _mkdir; private _filemeta; private _scan; private _stat; private static _diffWorker; private static _rootDiff; private static _directoryDiff; private static _fileDiff; private static _symlinkDiff; private static _trackCreatedInode; private static _trackCreatedInodes; private static _trackDeletedInodes; private _mknod; private _addLink; private _removeLink; private _replaceLink; private _getRootLinks; private _getLinks; private _getShadow; private _copyShadowLinks; private _getSize; private _getBuffer; /** * Walk a path to its end. * * @param path The path to follow. * @param noFollow A value indicating whether to *not* dereference a symbolic link at the * end of a path. * * @link http://man7.org/linux/man-pages/man7/path_resolution.7.html */ private _walk; /** * Resolve a path relative to the current working directory. */ private _resolve; private _applyFiles; private _applyFileExtendedOptions; private _applyFilesWorker; } export interface FileSystemOptions { time?: number | Date | (() => number | Date) | undefined; files?: FileSet | undefined; cwd?: string | undefined; meta?: Record | undefined; } export type Axis = 'ancestors' | 'ancestors-or-self' | 'self' | 'descendants-or-self' | 'descendants'; export interface Traversal { /** A function called to choose whether to continue to traverse to either ancestors or descendants. */ traverse?(path: string, stats: Stats): boolean; /** A function called to choose whether to accept a path as part of the result. */ accept?(path: string, stats: Stats): boolean; } export interface FileSystemResolver { statSync(path: string): { mode: number; size: number; }; readdirSync(path: string): string[]; readFileSync(path: string): Buffer; } /** * A template used to populate files, directories, links, etc. in a virtual file system. */ export interface FileSet { [name: string]: DirectoryLike | FileLike | Link | Symlink | Mount | Rmdir | Unlink | null | undefined; } export type DirectoryLike = FileSet | Directory; export type FileLike = File | Buffer | string; /** Extended options for a directory in a `FileSet` */ export declare class Directory { readonly files: FileSet; readonly meta: Record | undefined; constructor(files: FileSet, { meta }?: { meta?: Record; }); } /** Extended options for a file in a `FileSet` */ export declare class File { readonly data: Buffer | string; readonly encoding: BufferEncoding | undefined; readonly meta: Record | undefined; constructor(data: Buffer | string, { meta, encoding }?: { encoding?: BufferEncoding; meta?: Record; }); } export declare class SameFileContentFile extends File { constructor(data: Buffer | string, metaAndEncoding?: { encoding?: BufferEncoding; meta?: Record; }); } /** Extended options for a hard link in a `FileSet` */ export declare class Link { readonly path: string; constructor(path: string); } /** Removes a directory in a `FileSet` */ export declare class Rmdir { ' rmdirBrand'?: never; } /** Unlinks a file in a `FileSet` */ export declare class Unlink { ' unlinkBrand'?: never; } /** Extended options for a symbolic link in a `FileSet` */ export declare class Symlink { readonly symlink: string; readonly meta: Record | undefined; constructor(symlink: string, { meta }?: { meta?: Record; }); } export declare const S_IFMT = 61440; export declare const S_IFSOCK = 49152; export declare const S_IFLNK = 40960; export declare const S_IFREG = 32768; export declare const S_IFBLK = 24576; export declare const S_IFDIR = 16384; export declare const S_IFCHR = 8192; export declare const S_IFIFO = 4096; /** Extended options for mounting a virtual copy of an external file system via a `FileSet` */ export declare class Mount { readonly source: string; readonly resolver: FileSystemResolver; readonly meta: Record | undefined; constructor(source: string, resolver: FileSystemResolver, { meta }?: { meta?: Record; }); } export declare function formatPatch(patch: FileSet): string; export declare function formatPatch(patch: FileSet | undefined): string | null; declare class Stats { dev: number; ino: number; mode: number; nlink: number; uid: number; gid: number; rdev: number; size: number; blksize: number; blocks: number; atimeMs: number; mtimeMs: number; ctimeMs: number; birthtimeMs: number; atime: Date; mtime: Date; ctime: Date; birthtime: Date; constructor(); constructor(dev: number, ino: number, mode: number, nlink: number, rdev: number, size: number, blksize: number, blocks: number, atimeMs: number, mtimeMs: number, ctimeMs: number, birthtimeMs: number); isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; isBlockDevice(): boolean; isCharacterDevice(): boolean; isFIFO(): boolean; isSocket(): boolean; } export {};