From 9e1af7d14d1ec2702ebb516df48735d5d38c5b30 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Wed, 1 May 2019 17:26:33 +1200 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20accept=20`null`=20as?= =?UTF-8?q?=20value=20in=20`fromJSON`=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/volume.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/volume.ts b/src/volume.ts index 3c377c5f5..383ecb993 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -518,11 +518,13 @@ function validateGid(gid: number) { let promisesWarn = !process.env.MEMFS_DONT_WARN; +type DirectoryJSON = Record; + /** * `Volume` represents a file system. */ export class Volume { - static fromJSON(json: { [filename: string]: string }, cwd?: string): Volume { + static fromJSON(json: DirectoryJSON, cwd?: string): Volume { const vol = new Volume(); vol.fromJSON(json, cwd); return vol; @@ -855,7 +857,7 @@ export class Volume { } // fromJSON(json: {[filename: string]: string}, cwd: string = '/') { - fromJSON(json: { [filename: string]: string }, cwd: string = process.cwd()) { + fromJSON(json: DirectoryJSON, cwd: string = process.cwd()) { for (let filename in json) { const data = json[filename]; @@ -886,7 +888,7 @@ export class Volume { } // Legacy interface - mountSync(mountpoint: string, json: { [filename: string]: string }) { + mountSync(mountpoint: string, json: DirectoryJSON) { this.fromJSON(json, mountpoint); } From 66098408fc4245c01f72f033bdc7d8a6b2fc4480 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 2 May 2019 10:24:49 +1200 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20annotate=20return=20t?= =?UTF-8?q?ype=20of=20`toJSON`=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/volume.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/volume.ts b/src/volume.ts index 383ecb993..fa27a9351 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -808,7 +808,7 @@ export class Volume { }); } - private _toJSON(link = this.root, json = {}, path?: string) { + private _toJSON(link = this.root, json = {}, path?: string): DirectoryJSON { let isEmpty = true; for (const name in link.children) { @@ -836,7 +836,7 @@ export class Volume { return json; } - toJSON(paths?: TFilePath | TFilePath[], json = {}, isRelative = false) { + toJSON(paths?: TFilePath | TFilePath[], json = {}, isRelative = false): DirectoryJSON { const links: Link[] = []; if (paths) { From 07d8ea1ea94f0c7c4758c65802c0acab85690096 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 2 May 2019 10:53:38 +1200 Subject: [PATCH 3/3] chore: export `DirectoryJSON` type --- src/volume.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume.ts b/src/volume.ts index fa27a9351..fe81fd6b7 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -518,7 +518,7 @@ function validateGid(gid: number) { let promisesWarn = !process.env.MEMFS_DONT_WARN; -type DirectoryJSON = Record; +export type DirectoryJSON = Record; /** * `Volume` represents a file system.