Skip to content

Commit

Permalink
fix: 🐛 accept null as value in fromJSON functions
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed May 1, 2019
1 parent 558e001 commit 9e1af7d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/volume.ts
Expand Up @@ -518,11 +518,13 @@ function validateGid(gid: number) {

let promisesWarn = !process.env.MEMFS_DONT_WARN;

type DirectoryJSON = Record<string, string | null>;

/**
* `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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 9e1af7d

Please sign in to comment.