Skip to content

Commit

Permalink
refactor(BREAKING): Path - rename createSymlinkTo to symlinkTo (#267
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsherret authored May 4, 2024
1 parent b90efa9 commit c9eb52f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
30 changes: 15 additions & 15 deletions src/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Deno.test("isSymlink", async () => {
await withTempDir(() => {
const file = createPath("file.txt").writeTextSync("");
const symlinkFile = createPath("test.txt");
symlinkFile.createSymlinkToSync(file, { kind: "absolute" });
symlinkFile.symlinkToSync(file, { kind: "absolute" });
assert(symlinkFile.isSymlinkSync());
assert(!file.isSymlinkSync());
});
Expand Down Expand Up @@ -222,7 +222,7 @@ Deno.test("stat", async () => {
await withTempDir(async () => {
const tempFile = createPath("temp.txt").writeTextSync("");
const symlinkFile = createPath("other.txt");
await symlinkFile.createSymlinkTo(tempFile, { kind: "absolute" });
await symlinkFile.symlinkTo(tempFile, { kind: "absolute" });
const stat3 = await symlinkFile.stat();
assertEquals(stat3!.isFile, true);
assertEquals(stat3!.isSymlink, false);
Expand All @@ -238,7 +238,7 @@ Deno.test("statSync", async () => {
await withTempDir(() => {
const tempFile = createPath("temp.txt").writeTextSync("");
const symlinkFile = createPath("other.txt");
symlinkFile.createSymlinkToSync(tempFile, { kind: "absolute" });
symlinkFile.symlinkToSync(tempFile, { kind: "absolute" });
const stat3 = symlinkFile.statSync();
assertEquals(stat3!.isFile, true);
assertEquals(stat3!.isSymlink, false);
Expand All @@ -255,7 +255,7 @@ Deno.test("lstat", async () => {
const symlinkFile = createPath("temp.txt");
const otherFile = createPath("other.txt").writeTextSync("");
// path ref
await symlinkFile.createSymlinkTo(otherFile, { kind: "absolute" });
await symlinkFile.symlinkTo(otherFile, { kind: "absolute" });
const stat3 = await symlinkFile.lstat();
assertEquals(stat3!.isSymlink, true);
});
Expand All @@ -270,7 +270,7 @@ Deno.test("lstatSync", async () => {
await withTempDir(() => {
const symlinkFile = createPath("temp.txt");
const otherFile = createPath("other.txt").writeTextSync("");
symlinkFile.createSymlinkToSync(otherFile, { kind: "absolute" });
symlinkFile.symlinkToSync(otherFile, { kind: "absolute" });
assertEquals(symlinkFile.lstatSync()!.isSymlink, true);
});
});
Expand Down Expand Up @@ -338,7 +338,7 @@ Deno.test("realpath", async () => {
file = createPath(file.toString().replace("\\RUNNER~1\\", "\\runneradmin\\"));
}
const symlink = createPath("other");
symlink.createSymlinkToSync(file, { kind: "absolute" });
symlink.symlinkToSync(file, { kind: "absolute" });
assertEquals(
(await symlink.realPath()).toString(),
file.toString(),
Expand Down Expand Up @@ -372,11 +372,11 @@ Deno.test("mkdir", async () => {
});
});

Deno.test("createSymlinkTo", async () => {
Deno.test("symlinkTo", async () => {
await withTempDir(async () => {
const destFile = createPath("temp.txt").writeTextSync("");
const symlinkFile = destFile.parentOrThrow().join("other.txt");
await symlinkFile.createSymlinkTo(destFile, {
await symlinkFile.symlinkTo(destFile, {
kind: "absolute",
});
const stat = await symlinkFile.stat();
Expand All @@ -388,46 +388,46 @@ Deno.test("createSymlinkTo", async () => {
await assertRejects(
async () => {
// @ts-expect-error should require an options bag
await symlinkFile.createSymlinkTo(destFile);
await symlinkFile.symlinkTo(destFile);
},
Error,
"Please specify if this symlink is absolute or relative. Otherwise provide the target text.",
);
});
});

Deno.test("createSymlinkToSync", async () => {
Deno.test("symlinkToSync", async () => {
await withTempDir(() => {
const destFile = createPath("temp.txt").writeTextSync("");
const symlinkFile = destFile.parentOrThrow().join("other.txt");

// path ref
symlinkFile.createSymlinkToSync(destFile, { kind: "absolute" });
symlinkFile.symlinkToSync(destFile, { kind: "absolute" });
const stat = symlinkFile.statSync();
assertEquals(stat!.isFile, true);
assertEquals(stat!.isSymlink, false);
assert(symlinkFile.isSymlinkSync());

// path ref absolute
symlinkFile.removeSync();
symlinkFile.createSymlinkToSync(destFile, { kind: "absolute" });
symlinkFile.symlinkToSync(destFile, { kind: "absolute" });
assertEquals(symlinkFile.statSync()!.isFile, true);

// path ref relative
symlinkFile.removeSync();
symlinkFile.createSymlinkToSync(destFile, { kind: "relative" });
symlinkFile.symlinkToSync(destFile, { kind: "relative" });
assertEquals(symlinkFile.statSync()!.isFile, true);

// relative text
symlinkFile.removeSync();
symlinkFile.createSymlinkToSync("temp.txt");
symlinkFile.symlinkToSync("temp.txt");
assertEquals(symlinkFile.statSync()!.isFile, true);

// invalid
assertThrows(
() => {
// @ts-expect-error should require an options bag
symlinkFile.createSymlinkToSync(destFile);
symlinkFile.symlinkToSync(destFile);
},
Error,
"Please specify if this symlink is absolute or relative. Otherwise provide the target text.",
Expand Down
12 changes: 6 additions & 6 deletions src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,18 @@ export class Path {
/**
* Creates a symlink to the provided target path.
*/
async createSymlinkTo(
async symlinkTo(
targetPath: URL | Path,
opts: Partial<Deno.SymlinkOptions> & PathSymlinkOptions,
): Promise<void>;
/**
* Creates a symlink at the provided path with the provided target text.
*/
async createSymlinkTo(
async symlinkTo(
target: string,
opts?: SymlinkOptions,
): Promise<void>;
async createSymlinkTo(
async symlinkTo(
target: string | URL | Path,
opts?: SymlinkOptions,
): Promise<void> {
Expand All @@ -517,18 +517,18 @@ export class Path {
/**
* Synchronously creates a symlink to the provided target path.
*/
createSymlinkToSync(
symlinkToSync(
targetPath: URL | Path,
opts: Partial<Deno.SymlinkOptions> & PathSymlinkOptions,
): void;
/**
* Synchronously creates a symlink at the provided path with the provided target text.
*/
createSymlinkToSync(
symlinkToSync(
target: string,
opts?: SymlinkOptions,
): void;
createSymlinkToSync(target: string | URL | Path, opts?: SymlinkOptions): void {
symlinkToSync(target: string | URL | Path, opts?: SymlinkOptions): void {
createSymlinkSync(this.#resolveCreateSymlinkOpts(target, opts));
}

Expand Down

0 comments on commit c9eb52f

Please sign in to comment.