@yarnpkg/fslib
A TypeScript library abstracting the Node filesystem APIs. We use it for three main reasons:
Type-safe paths
Our library has two path types, NativePath
and PortablePath
. Most interfaces only accept the later, and instances of the former need to be transformed back and forth using our type-safe utilities before being usable.
Custom filesystems
The FSLib implements various transparent filesystem layers for a variety of purposes. For instance we use it in Yarn in order to abstract away the zip archive manipulation logic, which is implemented in ZipFS
and exposed through a Node-like interface (called FakeFS
).
All FakeFS
implementations can be transparently layered on top of the builtin Node fs
module, and that's for instance how we can add support for in-zip package loading without you having to care about the exact package format.
Promisified API
All methods from the FakeFS
interface are promisified by default (and suffixed for greater clarity, for instance we offer both readFileSync
and readFilePromise
).
Index
Classes
Functions
Interfaces
Namespaces
Type Aliases
- BigIntStats
- BufferEncodingOrBuffer
- CreateReadStreamOptions
- CreateWriteStreamOptions
- Dir
- Dirent
- DirentNoPath
- ExtractHintOptions
- FSPath
- Filename
- GetMountPointFn
- LinkStrategy
- MkdirOptions
- MountFSOptions
- NativePath
- OpendirOptions
- Path
- PortablePath
- ReaddirOptions
- RmOptions
- RmdirOptions
- StatWatcher
- Stats
- SymlinkType
- WatchCallback
- WatchFileCallback
- WatchFileOptions
- WatchOptions
- Watcher
- WriteFileOptions
- XFS
Variables
Functions
extendFs
Parameters
realFs: __module
fakeFs: FakeFS<NativePath>
Returns typeof fs
normalizeLineEndings
Parameters
originalContent: string
newContent: string
Returns string
opendir
patchFs
Parameters
patchedFs: __module
fakeFs: FakeFS<NativePath>
Returns void
setupCopyIndex
unwatchAllFiles
unwatchFile
Type parameters
- P: Path
Parameters
fakeFs: FakeFS<P>
path: P
optionalcb: WatchFileCallback
Returns void
watchFile
Type parameters
- P: Path
Parameters
fakeFs: FakeFS<P>
path: P
a: WatchFileCallback | Partial<{ bigint: boolean; interval: number; persistent: boolean }>
optionalb: WatchFileCallback
Returns CustomStatWatcher<P>
Type Aliases
BigIntStats
BufferEncodingOrBuffer
CreateReadStreamOptions
CreateWriteStreamOptions
Dir
Type parameters
- P: Path
Type declaration
readonlypath: P
[asyncIterator]: function
Returns AsyncIterableIterator<DirentNoPath>
close: function
Returns Promise<void>
closeSync: function
Returns void
read: function
Returns Promise<null | DirentNoPath>
readSync: function
Returns null | DirentNoPath
Dirent
Type parameters
- T: Path
DirentNoPath
ExtractHintOptions
Type declaration
relevantExtensions: Set<string>
FSPath
Type parameters
- T: Path
Filename
GetMountPointFn
Type declaration
Parameters
path: PortablePath
prefixPath: PortablePath
Returns PortablePath | null
LinkStrategy
Type parameters
- P
MkdirOptions
MountFSOptions
Type parameters
- MountedFS: MountableFS
Type declaration
optionalbaseFs?: FakeFS<PortablePath>
factoryPromise: (baseFs: FakeFS<PortablePath>, path: PortablePath) => Promise<() => MountedFS>
Parameters
baseFs: FakeFS<PortablePath>
path: PortablePath
Returns Promise<() => MountedFS>
factorySync: (baseFs: FakeFS<PortablePath>, path: PortablePath) => MountedFS
Functions used to create the sub-filesystem to use when accessing specific paths.
Parameters
baseFs: FakeFS<PortablePath>
path: PortablePath
Returns MountedFS
optionalfilter?: RegExp | null
getMountPoint: GetMountPointFn
A function that will be called to figure out the segment of a path that represents a mount point.
It must return a strict prefix of the original path, or
null
if the path isn't part of a mount archive.optionalmagicByte?: number
optionalmaxAge?: number
Maximum age of the child filesystem, after which they will be discarded. Each new access resets this time.
Only used if
useCache
is set totrue
.optionalmaxOpenFiles?: number
optionaltypeCheck?: number | null
optionaluseCache?: boolean
NativePath
OpendirOptions
Path
PortablePath
ReaddirOptions
RmOptions
RmdirOptions
StatWatcher
Stats
SymlinkType
WatchCallback
Type declaration
Parameters
eventType: string
filename: string
Returns void
WatchFileCallback
WatchFileOptions
WatchOptions
Watcher
Type declaration
close: () => void
Returns void
on: any
WriteFileOptions
XFS
Variables
Filename
PortablePath
Type declaration
dot: PortablePath
parent: PortablePath
root: PortablePath
Functions used to create the sub-filesystem to use when accessing specific paths.