Skip to content

Commit 5c80d35

Browse files
committed
refactor: move dir utils to own modules
1 parent ba3334e commit 5c80d35

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { temporaryDirectoryTask } from "tempy";
22
import { expect, test } from "vitest";
3-
import { changeDir, currentDir } from "./process";
4-
5-
test("current directory", () => {
6-
expect(currentDir().isOk()).toBe(true);
7-
});
3+
import { changeDir } from "./change-dir";
84

95
test("change directory", async () => {
106
await temporaryDirectoryTask(async (dir) => {

src/change-dir.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Result } from "neverthrow";
2+
import { OsError } from "./errors";
3+
4+
export const changeDir = Result.fromThrowable(
5+
process.chdir,
6+
(e) => new OsError("failed to change directory", { cause: e }),
7+
);

src/current-dir.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from "vitest";
2+
import { currentDir } from "./current-dir";
3+
4+
test("current directory", () => {
5+
expect(currentDir().isOk()).toBe(true);
6+
});

src/process.ts renamed to src/current-dir.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ export const currentDir = Result.fromThrowable(
55
process.cwd,
66
(e) => new OsError("failed to get current directory", { cause: e }),
77
);
8-
9-
export const changeDir = Result.fromThrowable(
10-
process.chdir,
11-
(e) => new OsError("failed to change directory", { cause: e }),
12-
);

src/extract-package-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ResultAsync, ok, okAsync } from "neverthrow";
22
import { performance } from "node:perf_hooks";
33
import { join } from "pathe";
4+
import { changeDir } from "./change-dir";
45
import { createProject } from "./create-project";
6+
import { currentDir } from "./current-dir";
57
import type { ExtractorError } from "./errors";
68
import type { ExtractedDeclaration } from "./extract-declarations";
79
import { installPackage } from "./install-package";
@@ -10,7 +12,6 @@ import { packageJson } from "./package-json";
1012
import { packageName } from "./package-name";
1113
import { packageOverview } from "./package-overview";
1214
import { packageTypes } from "./package-types";
13-
import { changeDir, currentDir } from "./process";
1415
import { tempDir } from "./temp-dir";
1516

1617
/**

0 commit comments

Comments
 (0)