From 3ff7e25c70b2e4cac8d6dde11fc227d172338681 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 1 May 2017 22:56:02 +0200 Subject: [PATCH] feat(fs-extra): update typings to `3.0.x` (#16218) * feat(fs-extra): update typyings to `3.0.x` * feat(fs-extra): update typings to `3.0.x` * test(fs-extra): add more test coverage * add `pathExists` * fix lint issues * fix lint issues * add `TypeScript Version: 2.2' * add more tests * change `interface` to `type` * add typescript version * add missing semicolon * add universalify fs async methods * add `fs` methods * feat(fs-extra): update typings to `3.0.x` * fix lint issues * fix more lint issues * fs-extra: add `mkdtemp` * remove extra breakline * remove `walk` and overall improvments * fix tests * add options to test * remove `CopyFilterFunction` and `CopyFilter` * remove `CopyFilterFunction` and `CopyFilter` * fix test * re add `CopyFilter` * fs-extra: fix CopyFilter * fs-extra: remove `MkdirOptions` * fs-extra: remove exra interfaces * feat(fs-extra): update typings to --- types/fs-extra-promise/index.d.ts | 8 +- types/fs-extra/fs-extra-tests.ts | 158 +++++++++++--- types/fs-extra/index.d.ts | 328 +++++++++++++++++++++--------- types/fs-extra/tsconfig.json | 42 ++-- types/fs-extra/tslint.json | 3 + 5 files changed, 391 insertions(+), 148 deletions(-) create mode 100644 types/fs-extra/tslint.json diff --git a/types/fs-extra-promise/index.d.ts b/types/fs-extra-promise/index.d.ts index a03512a577..b4c9a648ac 100644 --- a/types/fs-extra-promise/index.d.ts +++ b/types/fs-extra-promise/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/overlookmotel/fs-extra-promise // Definitions by: midknight41 , Jason Swearingen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// /// @@ -10,10 +11,15 @@ import * as stream from 'stream'; import { Stats } from 'fs'; import * as Promise from 'bluebird'; -import { CopyFilter, CopyOptions, ReadOptions, WriteOptions, MkdirOptions, MoveOptions } from 'fs-extra'; +import { CopyFilter, CopyOptions, ReadOptions, WriteOptions, MoveOptions } from 'fs-extra'; export * from 'fs-extra'; +export interface MkdirOptions { + fs?: any; + mode?: number; +} + //promisified versions export declare function copyAsync(src: string, dest: string): Promise; export declare function copyAsync(src: string, dest: string, filter: CopyFilter): Promise; diff --git a/types/fs-extra/fs-extra-tests.ts b/types/fs-extra/fs-extra-tests.ts index d39cae8d6f..005857e48c 100644 --- a/types/fs-extra/fs-extra-tests.ts +++ b/types/fs-extra/fs-extra-tests.ts @@ -1,106 +1,214 @@ import * as fs from 'fs-extra'; import * as Path from 'path'; +const len = 2; const src = ""; const dest = ""; const file = ""; const dir = ""; const path = ""; const data = ""; +const uid = 0; +const gid = 0; +const fd = 0; +const modeNum = 0; +const modeStr = ""; const object = {}; -const errorCallback = (err: Error) => {}; +const errorCallback = (err: Error) => { }; const readOptions: fs.ReadOptions = { - reviver : {} + reviver: {} }; const writeOptions: fs.WriteOptions = { - replacer: {} + replacer: {} }; +fs.moveSync(src, dest, {}); +fs.move(src, dest, {}).then(() => { + // stub +}); +fs.move(src, dest).then(() => { + // stub +}); +fs.move(src, dest, {}, () => { + // stub +}); +fs.move(src, dest, () => { + // stub +}); + +fs.copy(src, dest).then(() => { + // stub +}); +fs.copy(src, dest, { overwrite: true }).then(() => { + // stub +}); fs.copy(src, dest, errorCallback); -fs.copy(src, dest, (src: string) => { - return false; -}, errorCallback); +fs.copy(src, dest, (src: string) => false, errorCallback); fs.copy(src, dest, { - clobber: true, + overwrite: true, preserveTimestamps: true, - filter: (src: string) => { return false; } + filter: (src: string) => false }, errorCallback ); fs.copy(src, dest, { - clobber: true, + overwrite: true, preserveTimestamps: true, filter: /.*/ }, errorCallback ); fs.copySync(src, dest); -fs.copySync(src, dest, (src: string) => { - return false; -}); +fs.copySync(src, dest, (src: string) => false); fs.copySync(src, dest, /.*/); fs.copySync(src, dest, { - clobber: true, + overwrite: true, preserveTimestamps: true, - filter: (src: string) => { return false; } + filter: (src: string) => false } ); fs.copySync(src, dest, { - clobber: true, + overwrite: true, preserveTimestamps: true, filter: /.*/ } ); +fs.createFile(file).then(() => { + // stub +}); fs.createFile(file, errorCallback); fs.createFileSync(file); +fs.mkdirs(dir).then(() => { + // stub +}); +fs.mkdirp(dir).then(() => { + // stub +}); fs.mkdirs(dir, errorCallback); -fs.mkdirs(dir, {}, errorCallback); fs.mkdirsSync(dir); -fs.mkdirsSync(dir, {}); fs.mkdirp(dir, errorCallback); -fs.mkdirp(dir, {}, errorCallback); fs.mkdirpSync(dir); -fs.mkdirpSync(dir, {}); +fs.outputFile(file, data).then(() => { + // stub +}); fs.outputFile(file, data, errorCallback); fs.outputFileSync(file, data); -fs.outputJson(file, data, errorCallback); + +fs.outputJson(file, data, { + spaces: 2 +}).then(() => { + // stub +}); +fs.outputJson(file, data, { + spaces: 2 +}, errorCallback); fs.outputJSON(file, data, errorCallback); +fs.outputJSON(file, data).then(() => { + // stub +}); fs.outputJsonSync(file, data); fs.outputJSONSync(file, data); -fs.readJson(file, (error: Error, jsonObject: any) => {}); -fs.readJson(file, readOptions, (error: Error, jsonObject: any) => {}); -fs.readJSON(file, (error: Error, jsonObject: any) => {}); -fs.readJSON(file, readOptions, (error: Error, jsonObject: any) => {}); +fs.readJson(file).then(() => { + // stub +}); + +fs.readJson(file, readOptions).then(() => { + // stub +}); +fs.readJson(file, (error: Error, jsonObject: any) => { }); +fs.readJson(file, readOptions, (error: Error, jsonObject: any) => { }); +fs.readJSON(file, (error: Error, jsonObject: any) => { }); +fs.readJSON(file, readOptions, (error: Error, jsonObject: any) => { }); fs.readJsonSync(file, readOptions); fs.readJSONSync(file, readOptions); fs.remove(dir, errorCallback); +fs.remove(dir).then(() => { + // stub +}); fs.removeSync(dir); +fs.writeJson(file, object).then(() => { + // stub +}); +fs.writeJSON(file, object).then(() => { + // stub +}); fs.writeJson(file, object, errorCallback); fs.writeJson(file, object, writeOptions, errorCallback); fs.writeJSON(file, object, errorCallback); fs.writeJSON(file, object, writeOptions, errorCallback); - +fs.writeJson(file, object, writeOptions).then(() => { + // stub +}); +fs.writeJSON(file, object, writeOptions).then(() => { + // stub +}); fs.writeJsonSync(file, object, writeOptions); fs.writeJSONSync(file, object, writeOptions); +fs.ensureDir(path).then(() => { + // stub +}); fs.ensureDir(path, errorCallback); fs.ensureDirSync(path); + +fs.ensureFile(path).then(() => { + // stub +}); fs.ensureFile(path, errorCallback); fs.ensureFileSync(path); +fs.ensureLink(path).then(() => { + // stub +}); fs.ensureLink(path, errorCallback); fs.ensureLinkSync(path); +fs.ensureSymlink(path).then(() => { + // stub +}); fs.ensureSymlink(path, errorCallback); fs.ensureSymlinkSync(path); +fs.emptyDir(path).then(() => { + // stub +}); fs.emptyDir(path, errorCallback); fs.emptyDirSync(path); +fs.pathExists(path).then((_exist: boolean) => { + // stub +}); +fs.pathExists(path, (_err: Error, _exists: boolean) => { }); +const x: boolean = fs.pathExistsSync(path); + +fs.rename(src, dest, errorCallback); +fs.renameSync(src, dest); +fs.truncate(path, len, errorCallback); +fs.truncateSync(path, len); +fs.chown(path, uid, gid, errorCallback); +fs.chownSync(path, uid, gid); +fs.fchown(fd, uid, gid, errorCallback); +fs.fchownSync(fd, uid, gid); +fs.lchown(path, uid, gid, errorCallback); +fs.lchownSync(path, uid, gid); +fs.chmod(path, modeNum, errorCallback); +fs.chmod(path, modeStr, errorCallback); +fs.chmodSync(path, modeNum); +fs.chmodSync(path, modeStr); +fs.fchmod(fd, modeNum, errorCallback); +fs.fchmod(fd, modeStr, errorCallback); +fs.fchmodSync(fd, modeNum); +fs.fchmodSync(fd, modeStr); +fs.lchmod(path, modeStr, errorCallback); +fs.lchmod(path, modeNum, errorCallback); +fs.lchmodSync(path, modeNum); +fs.lchmodSync(path, modeStr); +fs.statSync(path); +fs.lstatSync(path); diff --git a/types/fs-extra/index.d.ts b/types/fs-extra/index.d.ts index c46dddba85..3d65d617b0 100644 --- a/types/fs-extra/index.d.ts +++ b/types/fs-extra/index.d.ts @@ -1,9 +1,8 @@ -// Type definitions for fs-extra 2.1 +// Type definitions for fs-extra 3.0 // Project: https://github.com/jprichardson/node-fs-extra -// Definitions by: midknight41 , Brendan Forster +// Definitions by: Alan Agius , midknight41 , Brendan Forster // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -// Imported from: https://github.com/soywiz/typescript-node-definitions/fs-extra.d.ts +// TypeScript Version: 2.2 /// @@ -11,123 +10,255 @@ import { Stats } from "fs"; export * from "fs"; -export declare function copy(src: string, dest: string, callback?: (err: Error) => void): void; -export declare function copy(src: string, dest: string, filter: CopyFilter, callback?: (err: Error) => void): void; -export declare function copy(src: string, dest: string, options: CopyOptions, callback?: (err: Error) => void): void; +export function copy(src: string, dest: string, options?: CopyOptions): Promise; +export function copy(src: string, dest: string, callback: (err: Error) => void): void; +export function copy(src: string, dest: string, options: CopyOptions, callback: (err: Error) => void): void; +export function copySync(src: string, dest: string, options?: CopyOptions): void; -export declare function copySync(src: string, dest: string): void; -export declare function copySync(src: string, dest: string, filter: CopyFilter): void; -export declare function copySync(src: string, dest: string, options: CopyOptions): void; +export function move(src: string, dest: string, options?: MoveOptions): Promise; +export function move(src: string, dest: string, callback: (err: Error) => void): void; +export function move(src: string, dest: string, options: MoveOptions, callback: (err: Error) => void): void; +export function moveSync(src: string, dest: string, options?: MoveOptions): void; -export declare function move(src: string, dest: string, callback?: (err: Error) => void): void; -export declare function move(src: string, dest: string, options: MoveOptions, callback?: (err: Error) => void): void; +export function createFile(file: string): Promise; +export function createFile(file: string, callback: (err: Error) => void): void; +export function createFileSync(file: string): void; -export declare function createFile(file: string, callback?: (err: Error) => void): void; -export declare function createFileSync(file: string): void; +export function ensureDir(path: string): Promise; +export function ensureDir(path: string, callback: (err: Error) => void): void; +export function ensureDirSync(path: string): void; -export declare function mkdirs(dir: string, callback?: (err: Error) => void): void; -export declare function mkdirp(dir: string, callback?: (err: Error) => void): void; -export declare function mkdirs(dir: string, options?: MkdirOptions, callback?: (err: Error) => void): void; -export declare function mkdirp(dir: string, options?: MkdirOptions, callback?: (err: Error) => void): void; -export declare function mkdirsSync(dir: string, options?: MkdirOptions): void; -export declare function mkdirpSync(dir: string, options?: MkdirOptions): void; +export function mkdirs(dir: string): Promise; +export function mkdirs(dir: string, callback: (err: Error) => void): void; +export function mkdirp(dir: string): Promise; +export function mkdirp(dir: string, callback: (err: Error) => void): void; +export function mkdirsSync(dir: string): void; +export function mkdirpSync(dir: string): void; -export declare function outputFile(file: string, data: any, callback?: (err: Error) => void): void; -export declare function outputFileSync(file: string, data: any): void; +export function outputFile(file: string, data: any): Promise; +export function outputFile(file: string, data: any, callback: (err: Error) => void): void; +export function outputFileSync(file: string, data: any): void; -export declare function outputJson(file: string, data: any, callback?: (err: Error) => void): void; -export declare function outputJSON(file: string, data: any, callback?: (err: Error) => void): void; -export declare function outputJsonSync(file: string, data: any): void; -export declare function outputJSONSync(file: string, data: any): void; +export function readJson(file: string, options?: ReadOptions): Promise; +export function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void; +export function readJson(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; +export function readJSON(file: string, options?: ReadOptions): Promise; +export function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void; +export function readJSON(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; -export declare function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void; -export declare function readJson(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; -export declare function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void; -export declare function readJSON(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void; +export function readJsonSync(file: string, options?: ReadOptions): any; +export function readJSONSync(file: string, options?: ReadOptions): any; -export declare function readJsonSync(file: string, options?: ReadOptions): any; -export declare function readJSONSync(file: string, options?: ReadOptions): any; +export function remove(dir: string): Promise; +export function remove(dir: string, callback: (err: Error) => void): void; +export function removeSync(dir: string): void; -export declare function remove(dir: string, callback?: (err: Error) => void): void; -export declare function removeSync(dir: string): void; +export function outputJSON(file: string, data: any, options?: WriteOptions): Promise; +export function outputJSON(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void; +export function outputJSON(file: string, data: any, callback: (err: Error) => void): void; +export function outputJson(file: string, data: any, options?: WriteOptions): Promise; +export function outputJson(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void; +export function outputJson(file: string, data: any, callback: (err: Error) => void): void; +export function outputJsonSync(file: string, data: any, options?: WriteOptions): void; +export function outputJSONSync(file: string, data: any, options?: WriteOptions): void; -export declare function writeJson(file: string, object: any, callback?: (err: Error) => void): void; -export declare function writeJson(file: string, object: any, options?: WriteOptions, callback?: (err: Error) => void): void; -export declare function writeJSON(file: string, object: any, callback?: (err: Error) => void): void; -export declare function writeJSON(file: string, object: any, options?: WriteOptions, callback?: (err: Error) => void): void; +export function writeJSON(file: string, object: any, options?: WriteOptions): Promise; +export function writeJSON(file: string, object: any, callback: (err: Error) => void): void; +export function writeJSON(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void; +export function writeJson(file: string, object: any, options?: WriteOptions): Promise; +export function writeJson(file: string, object: any, callback: (err: Error) => void): void; +export function writeJson(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void; -export declare function writeJsonSync(file: string, object: any, options?: WriteOptions): void; -export declare function writeJSONSync(file: string, object: any, options?: WriteOptions): void; +export function writeJsonSync(file: string, object: any, options?: WriteOptions): void; +export function writeJSONSync(file: string, object: any, options?: WriteOptions): void; -export declare function ensureDir(path: string, callback: (err: Error) => void): void; -export declare function ensureDirSync(path: string): void; +export function ensureFile(path: string): Promise; +export function ensureFile(path: string, callback: (err: Error) => void): void; +export function ensureFileSync(path: string): void; -export declare function ensureFile(path: string, callback: (err: Error) => void): void; -export declare function ensureFileSync(path: string): void; +export function ensureLink(path: string): Promise; +export function ensureLink(path: string, callback: (err: Error) => void): void; +export function ensureLinkSync(path: string): void; -export declare function ensureLink(path: string, callback: (err: Error) => void): void; -export declare function ensureLinkSync(path: string): void; +export function ensureSymlink(path: string): Promise; +export function ensureSymlink(path: string, callback: (err: Error) => void): void; +export function ensureSymlinkSync(path: string): void; -export declare function ensureSymlink(path: string, callback: (err: Error) => void): void; -export declare function ensureSymlinkSync(path: string): void; +export function emptyDir(path: string): Promise; +export function emptyDir(path: string, callback: (err: Error) => void): void; +export function emptyDirSync(path: string): void; -export declare function emptyDir(path: string, callback?: (err: Error) => void): void; -export declare function emptyDirSync(path: string): boolean; +export function pathExists(path: string): Promise; +export function pathExists(path: string, callback: (err: Error, exists: boolean) => void): void; +export function pathExistsSync(path: string): boolean; -export interface WalkEventEmitter extends NodeJS.ReadableStream { - on(event: 'data', callback: (file: WalkEventFile) => void): this; - on(event: 'readable', callback: (this: PathEntryStream) => void): this; - on(event: 'error', callback: (error: Error, item: PathEntry) => void): this; - on(event: 'end', callback: () => void): this; - on(event: string | symbol, callback: Function): this; -} +// fs async methods +// copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v6/index.d.ts -export interface WalkEventFile { +/** Tests a user's permissions for the file specified by path. */ +export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void; +export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; +export function access(path: string | Buffer, mode?: number): Promise; + +export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number | string; flag?: string; }, callback: (err: NodeJS.ErrnoException) => void): void; +export function appendFile(filename: string, data: any, callback: (err: NodeJS.ErrnoException) => void): void; +export function appendFile(filename: string, data: any, options?: { encoding?: string; mode?: number | string; flag?: string; }): Promise; + +export function chmod(path: string | Buffer, mode: string | number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function chmod(path: string | Buffer, mode: string | number): Promise; + +export function chown(path: string | Buffer, uid: number, gid: number): Promise; +export function chown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void; + +export function close(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function close(fd: number): Promise; + +export function fchmod(fd: number, mode: string | number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function fchmod(fd: number, mode: string | number): Promise; + +export function fchown(fd: number, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function fchown(fd: number, uid: number, gid: number): Promise; + +export function fdatasync(fd: number, callback: () => void): void; +export function fdatasync(fd: number): Promise; + +export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; +export function fstat(fd: number): Promise; + +export function fsync(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function fsync(fd: number): Promise; + +export function ftruncate(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function ftruncate(fd: number, len: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function ftruncate(fd: number, len?: number): Promise; + +export function futimes(fd: number, atime: number, mtime: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function futimes(fd: number, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException) => void): void; +export function futimes(fd: number, atime: number, mtime: number): Promise; +export function futimes(fd: number, atime: Date, mtime: Date): Promise; + +export function lchown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function lchown(path: string | Buffer, uid: number, gid: number): Promise; + +export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void; +export function link(srcpath: string | Buffer, dstpath: string | Buffer): Promise; + +export function lstat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; +export function lstat(path: string | Buffer): Promise; + +/** + * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. + * + * @param path + * @param callback No arguments other than a possible exception are given to the completion callback. + */ +export function mkdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void; +/** + * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. + * + * @param path + * @param mode + * @param callback No arguments other than a possible exception are given to the completion callback. + */ +export function mkdir(path: string | Buffer, mode: number | string, callback: (err?: NodeJS.ErrnoException) => void): void; +export function mkdir(path: string | Buffer): Promise; + +export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; +export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; +export function open(path: string | Buffer, flags: string | number, mode?: number): Promise; + +export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; +export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null): Promise<[number, Buffer]>; + +export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; +export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; +export function readFile(filename: string, options: { flag?: string; } | { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; +export function readFile(filename: string, options: { flag?: string; } | { encoding: string; flag?: string; }): Promise; +// tslint:disable-next-line:unified-signatures +export function readFile(filename: string, encoding: string): Promise; +export function readFile(filename: string): Promise; + +export function readdir(path: string | Buffer, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; +export function readdir(path: string | Buffer): Promise; + +export function readlink(path: string | Buffer, callback: (err: NodeJS.ErrnoException, linkString: string) => any): void; +export function readlink(path: string | Buffer): Promise; + +export function realpath(path: string | Buffer, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; +export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; +export function realpath(path: string | Buffer, cache?: { [path: string]: string }): Promise; + +export function rename(oldPath: string, newPath: string, callback: (err?: NodeJS.ErrnoException) => void): void; +export function rename(oldPath: string, newPath: string): Promise; + +/** + * Asynchronous rmdir - removes the directory specified in {path} + * + * @param path + * @param callback No arguments other than a possible exception are given to the completion callback. + */ +export function rmdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void; +export function rmdir(path: string | Buffer): Promise; + +export function stat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void; +export function stat(path: string | Buffer): Promise; + +export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: string, callback: (err?: NodeJS.ErrnoException) => void): void; +export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: string): Promise; + +export function truncate(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void; +export function truncate(path: string | Buffer, len: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function truncate(path: string | Buffer, len?: number): Promise; + +/** + * Asynchronous unlink - deletes the file specified in {path} + * + * @param path + * @param callback No arguments other than a possible exception are given to the completion callback. + */ +export function unlink(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void; +export function unlink(path: string | Buffer): Promise; + +export function utimes(path: string | Buffer, atime: number, mtime: number, callback: (err?: NodeJS.ErrnoException) => void): void; +export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException) => void): void; +export function utimes(path: string | Buffer, atime: number, mtime: number): Promise; +export function utimes(path: string | Buffer, atime: Date, mtime: Date): Promise; + +export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; +export function write(fd: number, buffer: Buffer, offset: number, length: number, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; +export function write(fd: number, data: any, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; +export function write(fd: number, data: any, offset: number, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; +export function write(fd: number, data: any, offset: number, encoding: string, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; +export function write(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): Promise<[number, Buffer]>; +export function write(fd: number, data: any, offset: number, encoding?: string): Promise<[number, string]>; + +export function writeFile(filename: string, data: any, callback: (err: NodeJS.ErrnoException) => void): void; +export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; +export function writeFile(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): Promise; + +/** + * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. + * + * @param prefix + * @param callback The created folder path is passed as a string to the callback's second parameter. + */ +export function mkdtemp(prefix: string, callback?: (err: NodeJS.ErrnoException, folder: string) => void): void; +export function mkdtemp(prefix: string): Promise; + +export interface PathEntry { path: string; stats: Stats; } -export interface WalkOptions { - /** - * Control how results are enumerated from `readdir`: - * - 'shift' will return the first element from the array. - * - 'pop' will return the last element from the array. - * - * If not specified, the default behaviour is 'shift' - */ - queueMethod?: 'pop' | 'shift'; - /** - * Provide a function to sort the paths before they are enumerated - */ - pathSorter?: (left: string, right: string) => number; - /** - * An optional object to override the default `fs` APIs for testing purposes - */ - fs?: Object; - /** - * Provide a function to exclude certain file paths. The function should - * return true when the element should be kept, and false otherwise. - */ - filter?: (path: string, index: number, array: Array) => boolean; +export interface PathEntryStream { + read(): PathEntry | null; } -export type PathEntry = { - path: string; - stats: Stats; -} - -export type PathEntryStream = { - read(): PathEntry | null -} - -export interface CopyFilterFunction { - (src: string): boolean -} +export type CopyFilterFunction = (src: string) => boolean; export type CopyFilter = CopyFilterFunction | RegExp; export interface CopyOptions { - clobber?: boolean; dereference?: boolean; overwrite?: boolean; preserveTimestamps?: boolean; @@ -137,28 +268,23 @@ export interface CopyOptions { } export interface MoveOptions { - clobber? : boolean; + overwrite?: boolean; limit?: number; } export interface ReadOptions { throws?: boolean; - fs?: Object; + fs?: object; reviver?: any; encoding?: string; flag?: string; } export interface WriteOptions { - fs?: Object; + fs?: object; replacer?: any; spaces?: number; encoding?: string; flag?: string; mode?: number; } - -export interface MkdirOptions { - fs?: any; - mode?: number; -} diff --git a/types/fs-extra/tsconfig.json b/types/fs-extra/tsconfig.json index 6337361eed..818b38896c 100644 --- a/types/fs-extra/tsconfig.json +++ b/types/fs-extra/tsconfig.json @@ -1,22 +1,22 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "fs-extra-tests.ts" - ] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fs-extra-tests.ts" + ] +} diff --git a/types/fs-extra/tslint.json b/types/fs-extra/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/fs-extra/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}