@yarnpkg/fslib
Advanced tools
Comparing version 2.0.0-rc.11 to 2.0.0-rc.12
/// <reference types="node" /> | ||
import { ReadStream, Stats, WriteStream } from 'fs'; | ||
import { Dirent, ReadStream, Stats, WriteStream } from 'fs'; | ||
import { FSPath, Path, PortablePath, PathUtils, Filename } from './path'; | ||
@@ -52,3 +52,21 @@ export declare type CreateReadStreamOptions = Partial<{ | ||
abstract readdirPromise(p: P): Promise<Array<Filename>>; | ||
abstract readdirPromise(p: P, opts: { | ||
withFileTypes: false; | ||
}): Promise<Array<Filename>>; | ||
abstract readdirPromise(p: P, opts: { | ||
withFileTypes: true; | ||
}): Promise<Array<Dirent>>; | ||
abstract readdirPromise(p: P, opts: { | ||
withFileTypes: boolean; | ||
}): Promise<Array<Filename> | Array<Dirent>>; | ||
abstract readdirSync(p: P): Array<Filename>; | ||
abstract readdirSync(p: P, opts: { | ||
withFileTypes: false; | ||
}): Array<Filename>; | ||
abstract readdirSync(p: P, opts: { | ||
withFileTypes: true; | ||
}): Array<Dirent>; | ||
abstract readdirSync(p: P, opts: { | ||
withFileTypes: boolean; | ||
}): Array<Filename> | Array<Dirent>; | ||
abstract existsPromise(p: P): Promise<boolean>; | ||
@@ -55,0 +73,0 @@ abstract existsSync(p: P): boolean; |
/// <reference types="node" /> | ||
import fs from 'fs'; | ||
import fs, { Dirent } from 'fs'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions } from './FakeFS'; | ||
@@ -57,4 +57,22 @@ import { BasePortableFakeFS, WriteFileOptions } from './FakeFS'; | ||
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer; | ||
readdirPromise(p: PortablePath): Promise<Filename[]>; | ||
readdirSync(p: PortablePath): Filename[]; | ||
readdirPromise(p: PortablePath): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Promise<Array<Dirent>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Promise<Array<Filename> | Array<Dirent>>; | ||
readdirSync(p: PortablePath): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Array<Dirent>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Array<Filename> | Array<Dirent>; | ||
readlinkPromise(p: PortablePath): Promise<PortablePath>; | ||
@@ -61,0 +79,0 @@ readlinkSync(p: PortablePath): PortablePath; |
@@ -232,9 +232,19 @@ "use strict"; | ||
} | ||
async readdirPromise(p) { | ||
async readdirPromise(p, { withFileTypes } = {}) { | ||
return await new Promise((resolve, reject) => { | ||
this.realFs.readdir(path_1.npath.fromPortablePath(p), this.makeCallback(resolve, reject)); | ||
if (withFileTypes) { | ||
this.realFs.readdir(path_1.npath.fromPortablePath(p), { withFileTypes: true }, this.makeCallback(resolve, reject)); | ||
} | ||
else { | ||
this.realFs.readdir(path_1.npath.fromPortablePath(p), this.makeCallback(value => resolve(value), reject)); | ||
} | ||
}); | ||
} | ||
readdirSync(p) { | ||
return this.realFs.readdirSync(path_1.npath.fromPortablePath(p)); | ||
readdirSync(p, { withFileTypes } = {}) { | ||
if (withFileTypes) { | ||
return this.realFs.readdirSync(path_1.npath.fromPortablePath(p), { withFileTypes: true }); | ||
} | ||
else { | ||
return this.realFs.readdirSync(path_1.npath.fromPortablePath(p)); | ||
} | ||
} | ||
@@ -241,0 +251,0 @@ async readlinkPromise(p) { |
@@ -48,6 +48,6 @@ export declare type PortablePath = string & { | ||
export interface ConvertUtils { | ||
fromPortablePath: (p: PortablePath) => NativePath; | ||
toPortablePath: (p: NativePath) => PortablePath; | ||
fromPortablePath: (p: Path) => NativePath; | ||
toPortablePath: (p: Path) => PortablePath; | ||
} | ||
export declare function convertPath<P extends Path>(targetPathUtils: PathUtils<P>, sourcePath: Path): P; | ||
export declare function toFilename(filename: string): Filename; |
/// <reference types="node" /> | ||
import { Dirent } from 'fs'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS } from './FakeFS'; | ||
import { MkdirOptions, WriteFileOptions, WatchCallback, WatchOptions, Watcher } from './FakeFS'; | ||
import { FSPath, Path } from './path'; | ||
import { FSPath, Filename, Path } from './path'; | ||
export declare abstract class ProxiedFS<P extends Path, IP extends Path> extends FakeFS<P> { | ||
@@ -63,4 +64,22 @@ protected abstract readonly baseFs: FakeFS<IP>; | ||
readFileSync(p: FSPath<P>, encoding?: string): Buffer; | ||
readdirPromise(p: P): Promise<import("./path").Filename[]>; | ||
readdirSync(p: P): import("./path").Filename[]; | ||
readdirPromise(p: P): Promise<Array<Filename>>; | ||
readdirPromise(p: P, opts: { | ||
withFileTypes: false; | ||
}): Promise<Array<Filename>>; | ||
readdirPromise(p: P, opts: { | ||
withFileTypes: true; | ||
}): Promise<Array<Dirent>>; | ||
readdirPromise(p: P, opts: { | ||
withFileTypes: boolean; | ||
}): Promise<Array<Filename> | Array<Dirent>>; | ||
readdirSync(p: P): Array<Filename>; | ||
readdirSync(p: P, opts: { | ||
withFileTypes: false; | ||
}): Array<Filename>; | ||
readdirSync(p: P, opts: { | ||
withFileTypes: true; | ||
}): Array<Dirent>; | ||
readdirSync(p: P, opts: { | ||
withFileTypes: boolean; | ||
}): Array<Filename> | Array<Dirent>; | ||
readlinkPromise(p: P): Promise<P>; | ||
@@ -67,0 +86,0 @@ readlinkSync(p: P): P; |
@@ -159,7 +159,7 @@ "use strict"; | ||
} | ||
readdirPromise(p) { | ||
return this.baseFs.readdirPromise(this.mapToBase(p)); | ||
async readdirPromise(p, { withFileTypes } = {}) { | ||
return this.baseFs.readdirPromise(this.mapToBase(p), { withFileTypes: withFileTypes }); | ||
} | ||
readdirSync(p) { | ||
return this.baseFs.readdirSync(this.mapToBase(p)); | ||
readdirSync(p, { withFileTypes } = {}) { | ||
return this.baseFs.readdirSync(this.mapToBase(p), { withFileTypes: withFileTypes }); | ||
} | ||
@@ -166,0 +166,0 @@ async readlinkPromise(p) { |
@@ -7,2 +7,13 @@ /// <reference types="node" /> | ||
import { FSPath, PortablePath, Filename } from './path'; | ||
declare class DirEntry { | ||
name: string; | ||
mode: number; | ||
isBlockDevice(): boolean; | ||
isCharacterDevice(): boolean; | ||
isDirectory(): boolean; | ||
isFIFO(): boolean; | ||
isFile(): boolean; | ||
isSocket(): boolean; | ||
isSymbolicLink(): boolean; | ||
} | ||
export declare type ZipBufferOptions = { | ||
@@ -94,4 +105,22 @@ readOnly?: boolean; | ||
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer; | ||
readdirPromise(p: PortablePath): Promise<Filename[]>; | ||
readdirPromise(p: PortablePath): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Promise<Array<DirEntry>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Promise<Array<Filename> | Array<DirEntry>>; | ||
readdirSync(p: PortablePath): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Array<DirEntry>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Array<Filename> | Array<DirEntry>; | ||
readlinkPromise(p: PortablePath): Promise<PortablePath>; | ||
@@ -102,1 +131,2 @@ readlinkSync(p: PortablePath): PortablePath; | ||
} | ||
export {}; |
@@ -25,2 +25,29 @@ "use strict"; | ||
const S_IFLNK = 0o120000; | ||
class DirEntry { | ||
constructor() { | ||
this.name = ``; | ||
this.mode = 0; | ||
} | ||
isBlockDevice() { | ||
return false; | ||
} | ||
isCharacterDevice() { | ||
return false; | ||
} | ||
isDirectory() { | ||
return (this.mode & S_IFMT) === S_IFDIR; | ||
} | ||
isFIFO() { | ||
return false; | ||
} | ||
isFile() { | ||
return (this.mode & S_IFMT) === S_IFREG; | ||
} | ||
isSocket() { | ||
return false; | ||
} | ||
isSymbolicLink() { | ||
return (this.mode & S_IFMT) === S_IFLNK; | ||
} | ||
} | ||
class StatEntry { | ||
@@ -743,6 +770,6 @@ constructor() { | ||
} | ||
async readdirPromise(p) { | ||
return this.readdirSync(p); | ||
async readdirPromise(p, { withFileTypes } = {}) { | ||
return this.readdirSync(p, { withFileTypes: withFileTypes }); | ||
} | ||
readdirSync(p) { | ||
readdirSync(p, { withFileTypes } = {}) { | ||
const resolvedP = this.resolveFilename(`scandir '${p}'`, p); | ||
@@ -754,3 +781,10 @@ if (!this.entries.has(resolvedP) && !this.listings.has(resolvedP)) | ||
throw errors.ENOTDIR(`scandir '${p}'`); | ||
return Array.from(directoryListing); | ||
const entries = [...directoryListing]; | ||
if (!withFileTypes) | ||
return entries; | ||
return entries.map(name => { | ||
return Object.assign(this.statImpl(`lstat`, path_1.ppath.join(p, name)), { | ||
name, | ||
}); | ||
}); | ||
} | ||
@@ -757,0 +791,0 @@ async readlinkPromise(p) { |
/// <reference types="node" /> | ||
import { Dirent } from 'fs'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, BasePortableFakeFS } from './FakeFS'; | ||
import { FakeFS, MkdirOptions, WriteFileOptions } from './FakeFS'; | ||
import { WatchOptions, WatchCallback, Watcher } from './FakeFS'; | ||
import { FSPath, PortablePath } from './path'; | ||
import { Filename, FSPath, PortablePath } from './path'; | ||
export declare type ZipOpenFSOptions = { | ||
@@ -74,4 +75,22 @@ baseFs?: FakeFS<PortablePath>; | ||
readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer; | ||
readdirPromise(p: PortablePath): Promise<import("./path").Filename[]>; | ||
readdirSync(p: PortablePath): import("./path").Filename[]; | ||
readdirPromise(p: PortablePath): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Promise<Array<Filename>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Promise<Array<Dirent>>; | ||
readdirPromise(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Promise<Array<Filename> | Array<Dirent>>; | ||
readdirSync(p: PortablePath): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: false; | ||
}): Array<Filename>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: true; | ||
}): Array<Dirent>; | ||
readdirSync(p: PortablePath, opts: { | ||
withFileTypes: boolean; | ||
}): Array<Filename> | Array<Dirent>; | ||
readlinkPromise(p: PortablePath): Promise<PortablePath>; | ||
@@ -78,0 +97,0 @@ readlinkSync(p: PortablePath): PortablePath; |
@@ -491,7 +491,7 @@ "use strict"; | ||
} | ||
async readdirPromise(p) { | ||
async readdirPromise(p, { withFileTypes } = {}) { | ||
return await this.makeCallPromise(p, async () => { | ||
return await this.baseFs.readdirPromise(p); | ||
return await this.baseFs.readdirPromise(p, { withFileTypes: withFileTypes }); | ||
}, async (zipFs, { subPath }) => { | ||
return await zipFs.readdirPromise(subPath); | ||
return await zipFs.readdirPromise(subPath, { withFileTypes: withFileTypes }); | ||
}, { | ||
@@ -501,7 +501,7 @@ requireSubpath: false, | ||
} | ||
readdirSync(p) { | ||
readdirSync(p, { withFileTypes } = {}) { | ||
return this.makeCallSync(p, () => { | ||
return this.baseFs.readdirSync(p); | ||
return this.baseFs.readdirSync(p, { withFileTypes: withFileTypes }); | ||
}, (zipFs, { subPath }) => { | ||
return zipFs.readdirSync(subPath); | ||
return zipFs.readdirSync(subPath, { withFileTypes: withFileTypes }); | ||
}, { | ||
@@ -508,0 +508,0 @@ requireSubpath: false, |
{ | ||
"name": "@yarnpkg/fslib", | ||
"version": "2.0.0-rc.11", | ||
"version": "2.0.0-rc.12", | ||
"main": "./lib/index.js", | ||
@@ -28,3 +28,6 @@ "sideEffects": false, | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.12.8" | ||
}, | ||
"typings": "./lib/index.d.ts" | ||
} |
146535
3733
1