From aed3e0fc50c4ff560dd8d412256565c928c0398d Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 14:46:39 -0400 Subject: [PATCH 1/6] Adding missing method signatures and fixing incorrect method signatures. The following missing methods were added: * fs.readlinkSync * fs.ftruncate * fs.ftruncateSync The following method signatures were fixed: * path.resolve: Takes an array of arbitrary length. This does not necessarily need to be a string array; resolve skips any non-string elements. * process.cwd: Returns a string, not void. --- node/node.d.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/node/node.d.ts b/node/node.d.ts index 9ae2d75aed..341b63c469 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -106,7 +106,7 @@ interface NodeProcess extends EventEmitter { execPath: string; abort(): void; chdir(directory: string): void; - cwd(): void; + cwd(): string; env: any; exit(code?: number): void; getgid(): number; @@ -725,8 +725,10 @@ declare module "fs" { export function rename(oldPath: string, newPath: string, callback?: Function): void; export function renameSync(oldPath: string, newPath: string): void; - export function truncate(fd: string, len: number, callback?: Function): void; - export function truncateSync(fd: string, len: number): void; + export function truncate(path: string, len: number, callback?: Function): void; + export function truncateSync(path: string, len: number): void; + export function ftruncate(fd: number, len: number, callback?: Function): void; + export function ftruncateSync(fd: number, len: number): void; export function chown(path: string, uid: number, gid: number, callback?: Function): void; export function chownSync(path: string, uid: number, gid: number): void; export function fchown(fd: string, uid: number, gid: number, callback?: Function): void; @@ -750,6 +752,7 @@ declare module "fs" { export function symlink(srcpath: string, dstpath: string, type?: string, callback?: Function): void; export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; export function readlink(path: string, callback?: (err: Error, linkString: string) =>any): void; + export function readlinkSync(path: string): string; export function realpath(path: string, callback?: (err: Error, resolvedPath: string) =>any): void; export function realpath(path: string, cache: string, callback: (err: Error, resolvedPath: string) =>any): void; export function realpathSync(path: string, cache?: string): void; @@ -808,12 +811,7 @@ declare module "fs" { declare module "path" { export function normalize(p: string): string; export function join(...paths: any[]): string; - export function resolve(to: string): string; - export function resolve(from: string, to: string): string; - export function resolve(from: string, from2: string, to: string): string; - export function resolve(from: string, from2: string, from3: string, to: string): string; - export function resolve(from: string, from2: string, from3: string, from4: string, to: string): string; - export function resolve(from: string, from2: string, from3: string, from4: string, from5: string, to: string): string; + export function resolve(...pathSegments: any[]): string; export function relative(from: string, to: string): string; export function dirname(p: string): string; export function basename(p: string, ext?: string): string; From e442870348a2193a1e2b94d82b3c3cea560eb8a5 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 14:51:25 -0400 Subject: [PATCH 2/6] Whoops. fd is a *string*, not a *number*. --- node/node.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/node.d.ts b/node/node.d.ts index 341b63c469..3c93a9bf30 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -727,8 +727,8 @@ declare module "fs" { export function renameSync(oldPath: string, newPath: string): void; export function truncate(path: string, len: number, callback?: Function): void; export function truncateSync(path: string, len: number): void; - export function ftruncate(fd: number, len: number, callback?: Function): void; - export function ftruncateSync(fd: number, len: number): void; + export function ftruncate(fd: string, len: number, callback?: Function): void; + export function ftruncateSync(fd: string, len: number): void; export function chown(path: string, uid: number, gid: number, callback?: Function): void; export function chownSync(path: string, uid: number, gid: number): void; export function fchown(fd: string, uid: number, gid: number, callback?: Function): void; From b6874ee01473292f485b68a2a0488441495067ae Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 15:00:04 -0400 Subject: [PATCH 3/6] fs.realpath's cache is an *object literal*, not a string or a boolean. --- node/node.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/node.d.ts b/node/node.d.ts index 3c93a9bf30..0512935646 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -754,8 +754,8 @@ declare module "fs" { export function readlink(path: string, callback?: (err: Error, linkString: string) =>any): void; export function readlinkSync(path: string): string; export function realpath(path: string, callback?: (err: Error, resolvedPath: string) =>any): void; - export function realpath(path: string, cache: string, callback: (err: Error, resolvedPath: string) =>any): void; - export function realpathSync(path: string, cache?: string): void; + export function realpath(path: string, cache: {[path: string]: string}, callback: (err: Error, resolvedPath: string) =>any): void; + export function realpathSync(path: string, cache?: {[path: string]: string}): void; export function unlink(path: string, callback?: Function): void; export function unlinkSync(path: string): void; export function rmdir(path: string, callback?: Function): void; From d39e7a312593c58defa266cd5f1d7e438a30f37c Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 15:20:58 -0400 Subject: [PATCH 4/6] In fs's truncate functions, 'len' is optional (and defaults to 0). --- node/node.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/node.d.ts b/node/node.d.ts index 0512935646..62eed025af 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -725,10 +725,12 @@ declare module "fs" { export function rename(oldPath: string, newPath: string, callback?: Function): void; export function renameSync(oldPath: string, newPath: string): void; + export function truncate(path: string, callback?: Function): void; export function truncate(path: string, len: number, callback?: Function): void; - export function truncateSync(path: string, len: number): void; + export function truncateSync(path: string, len?: number): void; + export function ftruncate(fd: string, callback?: Function): void; export function ftruncate(fd: string, len: number, callback?: Function): void; - export function ftruncateSync(fd: string, len: number): void; + export function ftruncateSync(fd: string, len?: number): void; export function chown(path: string, uid: number, gid: number, callback?: Function): void; export function chownSync(path: string, uid: number, gid: number): void; export function fchown(fd: string, uid: number, gid: number, callback?: Function): void; From 666cd33fe81e9eefdfb9017cf5e00a7e7b1f10a8 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 15:43:28 -0400 Subject: [PATCH 5/6] In many fs functions, mode is optional, which means that the argument that takes its slot becomes the callback. Adding alternative definitions to account for this. --- node/node.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/node.d.ts b/node/node.d.ts index 62eed025af..9ec03907ba 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -762,13 +762,15 @@ declare module "fs" { export function unlinkSync(path: string): void; export function rmdir(path: string, callback?: Function): void; export function rmdirSync(path: string): void; - export function mkdir(path: string, mode?: string, callback?: Function): void; + export function mkdir(path: string, callback?: Function): void; + export function mkdir(path: string, mode: string, callback?: Function): void; export function mkdirSync(path: string, mode?: string): void; export function readdir(path: string, callback?: (err: Error, files: string[]) => void): void; export function readdirSync(path: string): string[]; export function close(fd: string, callback?: Function): void; export function closeSync(fd: string): void; - export function open(path: string, flags: string, mode?: string, callback?: (err: Error, fd: string) =>any): void; + export function open(path: string, flags: string, callback?: (err: Error, fd: string) => any): void; + export function open(path: string, flags: string, mode: string, callback?: (err: Error, fd: string) => any): void; export function openSync(path: string, flags: string, mode?: string): void; export function utimes(path: string, atime: number, mtime: number, callback?: Function): void; export function utimesSync(path: string, atime: number, mtime: number): void; From 0b306aaef6538c874bea83382c933b8b0c628e14 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Fri, 27 Sep 2013 15:50:03 -0400 Subject: [PATCH 6/6] 'mode' can be a number or a string. I realize this could be considered pedantic, but the typings do not even consistently use one or the other. Previously, certain functions assumed string, others assumed number. This way, you can use either. --- node/node.d.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/node/node.d.ts b/node/node.d.ts index 9ec03907ba..e0a3092ca5 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -737,11 +737,17 @@ declare module "fs" { export function fchownSync(fd: string, uid: number, gid: number): void; export function lchown(path: string, uid: number, gid: number, callback?: Function): void; export function lchownSync(path: string, uid: number, gid: number): void; + export function chmod(path: string, mode: number, callback?: Function): void; export function chmod(path: string, mode: string, callback?: Function): void; + export function chmodSync(path: string, mode: number): void; export function chmodSync(path: string, mode: string): void; + export function fchmod(fd: string, mode: number, callback?: Function): void; export function fchmod(fd: string, mode: string, callback?: Function): void; + export function fchmodSync(fd: string, mode: number): void; export function fchmodSync(fd: string, mode: string): void; + export function lchmod(path: string, mode: number, callback?: Function): void; export function lchmod(path: string, mode: string, callback?: Function): void; + export function lchmodSync(path: string, mode: number): void; export function lchmodSync(path: string, mode: string): void; export function stat(path: string, callback?: (err: Error, stats: Stats) =>any): Stats; export function lstat(path: string, callback?: (err: Error, stats: Stats) =>any): Stats; @@ -763,14 +769,18 @@ declare module "fs" { export function rmdir(path: string, callback?: Function): void; export function rmdirSync(path: string): void; export function mkdir(path: string, callback?: Function): void; + export function mkdir(path: string, mode: number, callback?: Function): void; export function mkdir(path: string, mode: string, callback?: Function): void; + export function mkdirSync(path: string, mode?: number): void; export function mkdirSync(path: string, mode?: string): void; export function readdir(path: string, callback?: (err: Error, files: string[]) => void): void; export function readdirSync(path: string): string[]; export function close(fd: string, callback?: Function): void; export function closeSync(fd: string): void; export function open(path: string, flags: string, callback?: (err: Error, fd: string) => any): void; + export function open(path: string, flags: string, mode: number, callback?: (err: Error, fd: string) => any): void; export function open(path: string, flags: string, mode: string, callback?: (err: Error, fd: string) => any): void; + export function openSync(path: string, flags: string, mode?: number): void; export function openSync(path: string, flags: string, mode?: string): void; export function utimes(path: string, atime: number, mtime: number, callback?: Function): void; export function utimesSync(path: string, atime: number, mtime: number): void; @@ -788,10 +798,14 @@ declare module "fs" { export function readFileSync(filename: string, options: { encoding?: string; flag?: string; }): any; export function writeFile(filename: string, data: any, callback?: (err: Error) => void): void; export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: Error) => void): void; export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: Error) => void): void; export function appendFile(filename: string, data: any, callback?: (err: Error) => void): void; export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; export function watchFile(filename: string, listener: { curr: Stats; prev: Stats; }): void; export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: { curr: Stats; prev: Stats; }): void; export function unwatchFile(filename: string, listener?: Stats): void; @@ -805,6 +819,13 @@ declare module "fs" { mode?: number; bufferSize?: number; }): ReadStream; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: string; + bufferSize?: number; + }): ReadStream; export function createWriteStream(path: string, options?: { flags?: string; encoding?: string;