Options
All
  • Public
  • Public/Protected
  • All
Menu

Package yarnpkg-fslib

@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).

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

AliasFSOptions

AliasFSOptions<P>: object

Type parameters

Type declaration

BigIntStats

BigIntStats: NodeBigIntStats & object

ChangeFileOptions

ChangeFileOptions: Partial<object>

CopyOptions

CopyOptions: object

Type declaration

  • linkStrategy: LinkStrategy | null
  • 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

Type declaration

Dir

Dir<P>: object

Type parameters

Type declaration

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

Type declaration

LUTimes

LUTimes<P>: Array<[]>

Type parameters

LazyFSFactory

LazyFSFactory<P>: function

Type parameters

Type declaration

ListenerOptions

ListenerOptions: Omit<Required<WatchFileOptions>, "bigint">

MkdirOptions

MkdirOptions: Partial<object>

NativePath

NativePath: string & object

OpendirOptions

OpendirOptions: Partial<object>

Operations

Operations: Array<function>

Path

PortablePath

PortablePath: string & object

RmdirOptions

RmdirOptions: Partial<object>

StatWatcher

StatWatcher: EventEmitter & object

Stats

Stats: NodeStats & object

SymlinkType

SymlinkType: "file" | "dir" | "junction"

VirtualFSOptions

VirtualFSOptions: object

Type declaration

WatchCallback

WatchCallback: function

Type declaration

    • (eventType: string, filename: string): void
    • Parameters

      • eventType: string
      • filename: string

      Returns void

WatchFileCallback

WatchFileCallback: function

Type declaration

WatchFileOptions

WatchFileOptions: Partial<object>

WatchOptions

WatchOptions: Partial<object> | string

Watcher

Watcher: object

Type declaration

  • close: function
      • (): void
      • Returns void

  • on: any

WriteFileOptions

WriteFileOptions: Partial<object> | string

XFS

XFS: NodeFS & object

ZipBufferOptions

ZipBufferOptions: object

Type declaration

ZipCompression

ZipCompression: "mixed" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

ZipOpenFSOptions

ZipOpenFSOptions: object

Type declaration

  • Optional baseFs?: FakeFS<PortablePath>
  • Optional fileExtensions?: Array<string> | null

    Which file extensions will be interpreted as zip files. Useful for supporting other formats packaged as zips, such as .docx.

    If not provided, defaults to only accepting .zip.

    If not provided, defaults to only accepting .zip.

  • Optional filter?: RegExp | null
  • libzip: Libzip | function
  • Optional maxAge?: undefined | number

    Maximum age in ms. ZipFS instances are pruned from the cache if they aren't accessed within this amount of time.

  • Optional maxOpenFiles?: undefined | number
  • Optional readOnlyArchives?: undefined | false | true
  • Optional useCache?: undefined | false | true

ZipPathOptions

ZipPathOptions: ZipBufferOptions & object

Variables

Const ASYNC_IMPLEMENTATIONS

ASYNC_IMPLEMENTATIONS: Set<string> = new Set([`accessPromise`,`appendFilePromise`,`chmodPromise`,`chownPromise`,`closePromise`,`copyFilePromise`,`linkPromise`,`fstatPromise`,`lstatPromise`,`lutimesPromise`,`mkdirPromise`,`openPromise`,`opendirPromise`,`readdirPromise`,`realpathPromise`,`readFilePromise`,`readdirPromise`,`readlinkPromise`,`renamePromise`,`rmdirPromise`,`statPromise`,`symlinkPromise`,`truncatePromise`,`unlinkPromise`,`utimesPromise`,`writeFilePromise`,`writeSync`,])

Const DEFAULT_COMPRESSION_LEVEL

DEFAULT_COMPRESSION_LEVEL: ZipCompression = `mixed`

Const DEFAULT_MODE

DEFAULT_MODE: number = S_IFREG | 0o644

Const FILEHANDLE_IMPLEMENTATIONS

FILEHANDLE_IMPLEMENTATIONS: Set<string> = new Set([`appendFilePromise`,`chmodPromise`,`chownPromise`,`closePromise`,`readPromise`,`readFilePromise`,`statPromise`,`truncatePromise`,`utimesPromise`,`writePromise`,`writeFilePromise`,])

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

Unix timestamp for 1984-06-22T21:50:00.000Z

It needs to be after 1980-01-01 because that's what Zip supports, and it needs to have a slight offset to account for different timezones (because zip assumes that all times are local to whoever writes the file, which is really silly).

It needs to be after 1980-01-01 because that's what Zip supports, and it needs to have a slight offset to account for different timezones (because zip assumes that all times are local to whoever writes the file, which is really silly).

Const SYNC_IMPLEMENTATIONS

SYNC_IMPLEMENTATIONS: Set<string> = new Set([`accessSync`,`appendFileSync`,`createReadStream`,`createWriteStream`,`chmodSync`,`chownSync`,`closeSync`,`copyFileSync`,`linkSync`,`lstatSync`,`fstatSync`,`lutimesSync`,`mkdirSync`,`openSync`,`opendirSync`,`readSync`,`readlinkSync`,`readFileSync`,`readdirSync`,`readlinkSync`,`realpathSync`,`renameSync`,`rmdirSync`,`statSync`,`symlinkSync`,`truncateSync`,`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_FD

ZIP_FD: 2147483648 = 2147483648

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)

Let cleanExitRegistered

cleanExitRegistered: boolean = false

Const defaultTime

defaultTime: Date = new Date(constants.SAFE_TIME * 1000)

Const ifNotWin32It

ifNotWin32It: any = isNotWin32? it: it.skip

Const isCloneSupportedCache

isCloneSupportedCache: WeakMap<object, any> = new WeakMap()

Const isNotWin32

isNotWin32: boolean = process.platform !== `win32`

Const nodeFs

nodeFs: NodeFS = new NodeFS()

Const npath

npath: PathUtils<NativePath> & ConvertUtils = Object.create(path) as any

Const ppath

ppath: PathUtils<PortablePath> = Object.create(path.posix) as any

Const statWatchersByFakeFS

statWatchersByFakeFS: WeakMap<FakeFS<string & object | string & object>, Map<string & object | string & object, CustomStatWatcher<string & object | string & object>>> = new WeakMap<FakeFS<Path>, Map<Path, CustomStatWatcher<Path>>>()

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) {registerCleanExit();while (true) {const p = getTempName(`xfs-`);try {this.mkdirSync(p);} catch (error) {if (error.code === `EEXIST`) {continue;} else {throw error;}}const realP = this.realpathSync(p);tmpdirs.add(realP);if (typeof cb !== `undefined`) {try {return cb(realP);} finally {if (tmpdirs.has(realP)) {tmpdirs.delete(realP);try {this.removeSync(realP);} catch {// Too bad if there's an error}}}} else {return realP;}}},async mktempPromise<T>(this: XFS, cb?: (p: PortablePath) => Promise<T>) {registerCleanExit();while (true) {const p = getTempName(`xfs-`);try {await this.mkdirPromise(p);} catch (error) {if (error.code === `EEXIST`) {continue;} else {throw error;}}const realP = await this.realpathPromise(p);tmpdirs.add(realP);if (typeof cb !== `undefined`) {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}}}} else {return realP;}}},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}}},})

Functions

EBADF

  • EBADF(reason: string): Error & object

EBUSY

  • EBUSY(message: string): Error & object

EEXIST

  • EEXIST(reason: string): Error & object

EINVAL

  • EINVAL(reason: string): Error & object

EISDIR

  • EISDIR(reason: string): Error & object

ENOENT

  • ENOENT(reason: string): Error & object

ENOSYS

  • ENOSYS(message: string, reason: string): Error & object

ENOTDIR

  • ENOTDIR(reason: string): Error & object

ENOTEMPTY

  • ENOTEMPTY(reason: string): Error & object

EOPNOTSUPP

  • EOPNOTSUPP(reason: string): Error & object

EROFS

  • EROFS(reason: string): Error & object

ERR_DIR_CLOSED

  • ERR_DIR_CLOSED(): Error & object

areStatsEqual

assertStatus

  • assertStatus<T>(current: Status, expected: T): current

clearStats

  • clearStats(stats: Stats | BigIntStats): Stats | BigIntStats

Const contains

  • contains<T>(pathUtils: PathUtils<T>, from: T, to: T): null | T

convertPath

  • convertPath<P>(targetPathUtils: PathUtils<P>, sourcePath: Path): P

convertToBigIntStats

  • convertToBigIntStats(stats: Stats): BigIntStats

copyFile

  • copyFile<P1, P2>(prelayout: Operations, postlayout: Operations, updateTime: typeof utimesPromise, destinationFs: FakeFS<P1>, destination: P1, destinationStat: Stats | null, sourceFs: FakeFS<P2>, source: P2, sourceStat: Stats, opts: CopyOptions): Promise<boolean>

copyFolder

  • copyFolder<P1, P2>(prelayout: Operations, postlayout: Operations, updateTime: typeof utimesPromise, destinationFs: FakeFS<P1>, destination: P1, destinationStat: Stats | null, sourceFs: FakeFS<P2>, source: P2, sourceStat: Stats, opts: CopyOptions): Promise<boolean>

copyImpl

copyPromise

  • copyPromise<P1, P2>(destinationFs: FakeFS<P1>, destination: P1, sourceFs: FakeFS<P2>, source: P2, opts: CopyOptions): Promise<void>

copySymlink

  • copySymlink<P1, P2>(prelayout: Operations, postlayout: Operations, updateTime: typeof utimesPromise, destinationFs: FakeFS<P1>, destination: P1, destinationStat: Stats | null, sourceFs: FakeFS<P2>, source: P2, sourceStat: Stats, opts: CopyOptions): Promise<boolean>

extendFs

fromPortablePath

Const getArchivePart

  • getArchivePart(path: string, extension: string): null | string & object
  • Extracts the archive part (ending in the first instance of extension) from a path.

    The indexOf-based implementation is ~3.7x faster than a RegExp-based implementation.

    The indexOf-based implementation is ~3.7x faster than a RegExp-based implementation.

    Parameters

    • path: string
    • extension: string

    Returns null | string & object

getEndOfLine

  • getEndOfLine(content: string): string

getTempName

  • getTempName(prefix: string): string & object

makeCloneLinkOperation

  • makeCloneLinkOperation<P>(opFs: FakeFS<P>, destination: P, source: P, sourceStat: Stats, linkStrategy: LinkStrategy): (Anonymous function)

makeDefaultStats

makeEmptyArchive

  • makeEmptyArchive(): Buffer

makeEmptyStats

  • makeEmptyStats(): Stats | BigIntStats

makeError

  • makeError(code: string, message: string): Error & object

Const makeError

  • makeError(): Error & object

makeLinkOperation

  • makeLinkOperation<P>(opFs: FakeFS<P>, destination: P, source: P, sourceStat: Stats, linkStrategy: LinkStrategy): (Anonymous function)

maybeLStat

  • maybeLStat<P>(baseFs: FakeFS<P>, p: P): Promise<null | Stats & object>

normalizeLineEndings

  • normalizeLineEndings(originalContent: string, newContent: string): string

opendir

patchFs

registerCleanExit

  • registerCleanExit(): void

toFilename

  • toFilename(filename: string): Filename

toPortablePath

toUnixTimestamp

  • toUnixTimestamp(time: Date | string | number): string | number | Date

unwatchAllFiles

unwatchFile

useFakeTime

  • useFakeTime(cb: function): Promise<void>
  • Parameters

    • cb: function
        • (advanceTimeBy: function): void | Promise<void>
        • Parameters

          • advanceTimeBy: function
              • (ms: number): void
              • Parameters

                • ms: number

                Returns void

          Returns void | Promise<void>

    Returns Promise<void>

watchFile

Object literals

Const Filename

Filename: object

lockfile

lockfile: string & object = `yarn.lock` as Filename

manifest

manifest: string & object = `package.json` as Filename

nodeModules

nodeModules: string & object = `node_modules` as Filename

pnpCjs

pnpCjs: string & object = `.pnp.cjs` as Filename

pnpJs

pnpJs: string & object = `.pnp.js` as Filename
deprecated

rc

rc: string & object = `.yarnrc.yml` as Filename

virtual

virtual: string & object = `__virtual__` as Filename

Const PortablePath

PortablePath: object

dot

dot: string & object = `.` as PortablePath

root

root: string & object = `/` as PortablePath

Generated using TypeDoc