Skip to content

Commit

Permalink
refactor(utils::removeDir): remove nodejs 12 workaround
Browse files Browse the repository at this point in the history
should likely have been done for 9.x
  • Loading branch information
hasezoey committed Jun 5, 2024
1 parent 501ada4 commit a852513
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions packages/mongodb-memory-server-core/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,6 @@ export async function createTmpDir(prefix: string, atPath?: string): Promise<str
return fspromises.mkdtemp(path.join(tmpPath, prefix));
}

// outsourced instead of () or without, because prettier cant decide which it wants
type tfsPromises = typeof fspromises;

// workaround for already using @types/node 14 (instead of 12)
interface RmDir {
rmdir: tfsPromises['rmdir'];
}

/**
* Removes the given "path", if it is a directory, and does not throw a error if not existing
* @param dirPath The Directory Path to delete
Expand All @@ -342,16 +334,7 @@ export async function removeDir(dirPath: string): Promise<void> {
throw new Error(`Given Path is not a directory! (Path: "${dirPath}")`);
}

if ('rm' in fspromises) {
// only since NodeJS 14
await fspromises.rm(dirPath, { force: true, recursive: true });
} else {
// before NodeJS 14
// needs the bridge via the interface, because we are using @types/node 14, where this if evaluates to a always "true" in typescript's eyes
await (fspromises as RmDir).rmdir(dirPath, {
recursive: true,
});
}
await fspromises.rm(dirPath, { force: true, recursive: true });
}

/**
Expand Down

0 comments on commit a852513

Please sign in to comment.