Skip to content

Commit ba3334e

Browse files
committed
feat: add remove dir
1 parent 554e634 commit ba3334e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/remove-dir.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { temporaryDirectoryTask } from "tempy";
2+
import { expect, test } from "vitest";
3+
import { removeDir } from "./remove-dir";
4+
5+
test("remove directory", async () => {
6+
await temporaryDirectoryTask(async (dir) => {
7+
expect((await removeDir(dir)).isOk()).toBe(true);
8+
});
9+
});

src/remove-dir.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ResultAsync } from "neverthrow";
2+
import fs from "node:fs/promises";
3+
import { FsError } from "./errors";
4+
5+
export const removeDir = (path: string): ResultAsync<void, FsError> =>
6+
ResultAsync.fromPromise(
7+
fs.rm(path, { force: true, recursive: true, maxRetries: 3 }),
8+
(e) => new FsError("failed to remove directory", { cause: e }),
9+
);

0 commit comments

Comments
 (0)