Type aliases
AliasFSOptions
AliasFSOptions<P>: object
Type parameters
BigIntStats
BigIntStats: NodeBigIntStats & object
ChangeFileOptions
ChangeFileOptions: Partial<object>
CopyOptions
CopyOptions: object
Type declaration
-
-
overwrite: boolean
-
stableSort: boolean
-
stableTime: boolean
CreateReadStreamOptions
CreateReadStreamOptions: Partial<object>
CreateWriteStreamOptions
CreateWriteStreamOptions: Partial<object>
CustomDirOptions
CustomDirOptions: object
Type declaration
-
Optional onClose?: undefined | function
CustomStatWatcherOptions
CustomStatWatcherOptions: object
Type declaration
-
Optional bigint?: undefined | false | true
CwdFSOptions
CwdFSOptions: object
Dir
Dir<P>: object
Type parameters
Type declaration
-
path: P
-
__computed: function
- __computed(): AsyncIterableIterator<Dirent>
-
Returns AsyncIterableIterator<Dirent>
-
close: function
- close(): Promise<void>
- close(cb: NoParamCallback): void
-
Returns Promise<void>
-
Parameters
Returns void
-
closeSync: function
-
read: function
- read(): Promise<Dirent | null>
- read(cb: function): void
-
Returns Promise<Dirent | null>
-
Parameters
-
cb: function
-
- (err: ErrnoException | null, dirent: Dirent | null): void
-
Parameters
-
err: ErrnoException | null
-
dirent: Dirent | null
Returns void
Returns void
-
readSync: function
Dirent
Dirent: Exclude<NodeDirent, "name"> & object
ExtractHintOptions
ExtractHintOptions: object
Type declaration
-
relevantExtensions: Set<string>
FSPath
FSPath<T>: T | number
Type parameters
Filename
Filename: string & object
JailFSOptions
JailFSOptions: object
LUTimes
LUTimes<P>: Array<[]>
Type parameters
LazyFSFactory
LazyFSFactory<P>: function
Type parameters
MkdirOptions
MkdirOptions: Partial<object>
Mode
Mode: number | string
NativePath
NativePath: string & object
OpenMode
OpenMode: number | string
OpendirOptions
OpendirOptions: Partial<object>
Operations
Operations: Array<function>
PortablePath
PortablePath: string & object
ReadArguments
ReadArguments: []
ReadArgumentsCallback
ReadArgumentsCallback: []
ReadArgumentsOptions
ReadArgumentsOptions: []
ReadCallback
ReadCallback: function
Type declaration
-
- (err: ErrnoException | null, bytesRead: number, buffer: Buffer): void
-
Parameters
-
err: ErrnoException | null
-
bytesRead: number
-
buffer: Buffer
Returns void
ReadSyncArguments
ReadSyncArguments: []
ReadSyncArgumentsOptions
ReadSyncArgumentsOptions: []
RmdirOptions
RmdirOptions: Partial<object>
StatWatcher
StatWatcher: EventEmitter & object
Stats
Stats: NodeStats & object
SymlinkType
SymlinkType: "file" | "dir" | "junction"
VirtualFSOptions
VirtualFSOptions: object
WatchCallback
WatchCallback: function
Type declaration
-
- (eventType: string, filename: string): void
-
Parameters
-
eventType: string
-
filename: string
Returns void
WatchFileCallback
WatchFileCallback: function
WatchFileOptions
WatchFileOptions: Partial<object>
WatchOptions
WatchOptions: Partial<object> | string
WriteArgsBuffer
WriteArgsBuffer<TBuffer>: []
Type parameters
WriteArgsString
WriteArgsString: []
WriteFileOptions
WriteFileOptions: Partial<object> | string
ZipBufferOptions
ZipBufferOptions: object
Type declaration
-
-
-
Optional readOnly?: undefined | false | true
-
Optional stats?: Stats
ZipCompression
ZipCompression: "mixed" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
ZipOpenFSOptions
ZipOpenFSOptions: object
Type declaration
-
-
Optional fileExtensions?: Array<string> | null
-
Optional filter?: RegExp | null
-
libzip: Libzip | function
-
Optional maxAge?: undefined | number
-
Optional maxOpenFiles?: undefined | number
-
Optional readOnlyArchives?: undefined | false | true
-
Optional useCache?: undefined | false | true
Variables
Const ASYNC_IMPLEMENTATIONS
ASYNC_IMPLEMENTATIONS: Set<string> = new Set([`accessPromise`,`appendFilePromise`,`fchmodPromise`,`chmodPromise`,`fchownPromise`,`chownPromise`,`closePromise`,`copyFilePromise`,`linkPromise`,`fstatPromise`,`lstatPromise`,`lutimesPromise`,`mkdirPromise`,`openPromise`,`opendirPromise`,`readdirPromise`,`realpathPromise`,`readFilePromise`,`readdirPromise`,`readlinkPromise`,`renamePromise`,`rmdirPromise`,`statPromise`,`symlinkPromise`,`truncatePromise`,`ftruncatePromise`,`unlinkPromise`,`utimesPromise`,`writeFilePromise`,`writeSync`,])
Const DEFAULT_COMPRESSION_LEVEL
Const DEFAULT_MODE
DEFAULT_MODE: number = S_IFREG | 0o644
Const JAIL_ROOT
JAIL_ROOT: string & object = PortablePath.root
Const NUMBER_REGEXP
NUMBER_REGEXP: RegExp = /^[0-9]+$/
Const PORTABLE_PATH_REGEXP
PORTABLE_PATH_REGEXP: RegExp = /^\/([a-zA-Z]:.*)$/
Const SAFE_TIME
SAFE_TIME: 456789000 = 456789000
Const SYNC_IMPLEMENTATIONS
SYNC_IMPLEMENTATIONS: Set<string> = new Set([`accessSync`,`appendFileSync`,`createReadStream`,`createWriteStream`,`chmodSync`,`fchmodSync`,`chownSync`,`fchownSync`,`closeSync`,`copyFileSync`,`linkSync`,`lstatSync`,`fstatSync`,`lutimesSync`,`mkdirSync`,`openSync`,`opendirSync`,`readlinkSync`,`readFileSync`,`readdirSync`,`readlinkSync`,`realpathSync`,`renameSync`,`rmdirSync`,`statSync`,`symlinkSync`,`truncateSync`,`ftruncateSync`,`unlinkSync`,`unwatchFile`,`utimesSync`,`watch`,`watchFile`,`writeFileSync`,`writeSync`,])
Const S_IFDIR
S_IFDIR: 16384 = 16384
Const S_IFLNK
S_IFLNK: 40960 = 40960
Const S_IFMT
S_IFMT: 61440 = 61440
Const S_IFREG
S_IFREG: 32768 = 32768
Const UNC_PORTABLE_PATH_REGEXP
UNC_PORTABLE_PATH_REGEXP: RegExp = /^\/unc\/(\.dot\/)?(.*)$/
Const UNC_WINDOWS_PATH_REGEXP
UNC_WINDOWS_PATH_REGEXP: RegExp = /^\/\/(\.\/)?(.*)$/
Const VALID_COMPONENT
VALID_COMPONENT: RegExp = /^([^/]+-)?[a-f0-9]+$/
Const VIRTUAL_REGEXP
VIRTUAL_REGEXP: RegExp = /^(\/(?:[^/]+\/)*?(?:\$\$virtual|__virtual__))((?:\/((?:[^/]+-)?[a-f0-9]+)(?:\/([^/]+))?)?((?:\/.*)?))$/
Const WINDOWS_PATH_REGEXP
WINDOWS_PATH_REGEXP: RegExp = /^([a-zA-Z]:.*)$/
Const ZIP_DIR1
ZIP_DIR1: string & object = ppath.join(npath.toPortablePath(__dirname),`fixtures/foo.zip` as Filename,)
Const ZIP_DIR2
ZIP_DIR2: string & object = ppath.join(npath.toPortablePath(__dirname),`fixtures/folder.zip/foo.zip` as Filename,)
Const ZIP_DIR3
ZIP_DIR3: string & object = ppath.join(npath.toPortablePath(__dirname),`fixtures/foo.hiddenzip` as Filename,)
Const ZIP_FILE1
ZIP_FILE1: string & object = ppath.join(ZIP_DIR1, `foo.txt` as Filename)
Const ZIP_FILE2
ZIP_FILE2: string & object = ppath.join(ZIP_DIR2, `foo.txt` as Filename)
Const ZIP_FILE3
ZIP_FILE3: string & object = ppath.join(ZIP_DIR3, `foo.txt` as Filename)
Const ZIP_MAGIC
ZIP_MAGIC: 704643072 = 704643072
Const ZIP_MASK
ZIP_MASK: 4278190080 = 4278190080
Const defaultTime
defaultTime: Date = new Date(constants.SAFE_TIME * 1000)
Const ifNotWin32It
ifNotWin32It: any = process.platform !== `win32` ? it : it.skip
Const ifNotWin32It
ifNotWin32It: any = isNotWin32? it: it.skip
Const ifNotWin32It
ifNotWin32It: any = process.platform !== `win32` ? it : it.skip
Const isCloneSupportedCache
isCloneSupportedCache: WeakMap<symbol | object, any> = new WeakMap()
Const isNotWin32
isNotWin32: boolean = process.platform !== `win32`
Const kBaseFs
kBaseFs: unique symbol = Symbol(`kBaseFs`)
Const kClosePromise
kClosePromise: unique symbol = Symbol(`kClosePromise`)
Const kCloseReject
kCloseReject: unique symbol = Symbol(`kCloseReject`)
Const kCloseResolve
kCloseResolve: unique symbol = Symbol(`kCloseResolve`)
Const kFd
kFd: unique symbol = Symbol(`kFd`)
Const kRef
kRef: unique symbol = Symbol(`kRef`)
Const kRefs
kRefs: unique symbol = Symbol(`kRefs`)
Const kUnref
kUnref: unique symbol = Symbol(`kUnref`)
Const statWatchersByFakeFS
stat
WatchersByFakeFS: WeakMap<FakeFS<string & object | string & object>, Map<string & object | string & object, CustomStatWatcher<string & object | string & object>>> = new WeakMap<FakeFS<Path>, Map<Path, CustomStatWatcher<Path>>>()
Let tmpEnv
tmpEnv: object | null = null
Const tmpdirs
tmpdirs: Set<string & object> = new Set<PortablePath>()
Const xfs
xfs
: XFS = Object.assign(new NodeFS(), {detachTemp(p: PortablePath) {tmpdirs.delete(p);},mktempSync<T>(this: XFS, cb?: (p: PortablePath) => T) {const {tmpdir, realTmpdir} = initTmpEnv();while (true) {const name = getTempName(`xfs-`);try {this.mkdirSync(ppath.join(tmpdir, name));} catch (error) {if (error.code === `EEXIST`) {continue;} else {throw error;}}const realP = ppath.join(realTmpdir, name);tmpdirs.add(realP);if (typeof cb === `undefined`)return realP;try {return cb(realP);} finally {if (tmpdirs.has(realP)) {tmpdirs.delete(realP);try {this.removeSync(realP);} catch {// Too bad if there's an error}}}}},async mktempPromise<T>(this: XFS, cb?: (p: PortablePath) => Promise<T>) {const {tmpdir, realTmpdir} = initTmpEnv();while (true) {const name = getTempName(`xfs-`);try {await this.mkdirPromise(ppath.join(tmpdir, name));} catch (error) {if (error.code === `EEXIST`) {continue;} else {throw error;}}const realP = ppath.join(realTmpdir, name);tmpdirs.add(realP);if (typeof cb === `undefined`)return realP;try {return await cb(realP);} finally {if (tmpdirs.has(realP)) {tmpdirs.delete(realP);try {await this.removePromise(realP);} catch {// Too bad if there's an error}}}}},async rmtempPromise() {await Promise.all(Array.from(tmpdirs.values()).map(async p => {try {await xfs.removePromise(p, {maxRetries: 0});tmpdirs.delete(p);} catch {// Too bad if there's an error}}));},rmtempSync() {for (const p of tmpdirs) {try {xfs.removeSync(p);tmpdirs.delete(p);} catch {// Too bad if there's an error}}},})
@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
andPortablePath
. 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 (calledFakeFS
).All
FakeFS
implementations can be transparently layered on top of the builtin Nodefs
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 bothreadFileSync
andreadFilePromise
).