From 9ce1260ed7f0cc11886f2f35f93196dedc38c150 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 4 Feb 2024 17:01:19 -0500 Subject: [PATCH] feat: deprecate `PathRef` in favour of `Path` --- README.md | 12 +-- mod.test.ts | 19 ++++- mod.ts | 23 +++--- src/command.ts | 14 ++-- src/deps.test.ts | 12 +-- src/path.test.ts | 204 +++++++++++++++++++++++------------------------ src/path.ts | 138 ++++++++++++++++---------------- src/pipes.ts | 6 +- src/request.ts | 28 +++---- 9 files changed, 237 insertions(+), 219 deletions(-) diff --git a/README.md b/README.md index a7ec284..7228f2e 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ await $`echo 1 && (echo 2 > ${buffer}) && echo 3`; // 1\n3\n console.log(buffer); // Uint8Array(2) [ 50, 10 ] (2\n) ``` -Supported objects: `Uint8Array`, `PathRef`, `WritableStream`, function that returns a `WritableStream`, any object that implements `[$.symbols.writable](): WritableStream` +Supported objects: `Uint8Array`, `Path`, `WritableStream`, function that returns a `WritableStream`, any object that implements `[$.symbols.writable](): WritableStream` Or input redirects: @@ -208,7 +208,7 @@ const request = $.request("https://plugins.dprint.dev/info.json") const bytes = await $`sleep 5 && gzip < ${request}`.bytes(); ``` -Supported objects: `string`, `Uint8Array`, `PathRef`, `RequestBuilder`, `ReadableStream`, function that returns a `ReadableStream`, any object that implements `[$.symbols.readable](): ReadableStream` +Supported objects: `string`, `Uint8Array`, `Path`, `RequestBuilder`, `ReadableStream`, function that returns a `ReadableStream`, any object that implements `[$.symbols.readable](): ReadableStream` ### Providing stdin @@ -573,10 +573,10 @@ pb.with(() => { ## Path API -The path API offers an immutable [`PathRef`](https://deno.land/x/dax/src/path.ts?s=PathRef) class, which is a similar concept to Rust's `PathBuf` struct. +The path API offers an immutable [`Path`](https://deno.land/x/dax/src/path.ts?s=Path) class, which is a similar concept to Rust's `PathBuf` struct. ```ts -// create a `PathRef` +// create a `Path` let srcDir = $.path("src"); // get information about the path srcDir.isDirSync(); // false @@ -610,7 +610,7 @@ const srcDir = $.path("src").resolve(); await $`echo ${srcDir}`; ``` -`PathRef`s can be created in the following ways: +`Path`s can be created in the following ways: ```ts const pathRelative = $.path("./relative"); @@ -620,7 +620,7 @@ const pathStringFileUrl = $.path("file:///tmp"); // converts to /tmp const pathImportMeta = $.path(import.meta); // the path for the current module ``` -There are a lot of helper methods here, so check the [documentation on PathRef](https://deno.land/x/dax/src/path.ts?s=PathRef) for more details. +There are a lot of helper methods here, so check the [documentation on Path](https://deno.land/x/dax/src/path.ts?s=Path) for more details. ## Helper functions diff --git a/mod.test.ts b/mod.test.ts index fadb5df..39c13c9 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -1,5 +1,14 @@ import { readAll, readerFromStreamReader } from "./src/deps.ts"; -import $, { build$, CommandBuilder, CommandContext, CommandHandler, KillSignal, KillSignalController } from "./mod.ts"; +import $, { + build$, + CommandBuilder, + CommandContext, + CommandHandler, + KillSignal, + KillSignalController, + Path, + PathRef, +} from "./mod.ts"; import { assert, assertEquals, @@ -810,7 +819,7 @@ Deno.test("piping to stdin", async (t) => { assertEquals(result, "1\n2"); }); - await t.step("PathRef", async () => { + await t.step("Path", async () => { await using tempDir = usingTempDir(); const tempFile = tempDir.join("temp_file.txt"); const fileText = "1 testing this out\n".repeat(1_000); @@ -2099,6 +2108,12 @@ Deno.test("should support empty quoted string", async () => { assertEquals(output, " test "); }); +Deno.test("esnure deprecated PathRef export still works", () => { + const path = new PathRef("hello"); + assert(path instanceof Path); + assert(path instanceof PathRef); +}); + function ensurePromiseNotResolved(promise: Promise) { return new Promise((resolve, reject) => { promise.then(() => reject(new Error("Promise was resolved"))); diff --git a/mod.ts b/mod.ts index 62d03b5..e484ad3 100644 --- a/mod.ts +++ b/mod.ts @@ -36,11 +36,14 @@ import { import { colors, outdent, which, whichSync } from "./src/deps.ts"; import { wasmInstance } from "./src/lib/mod.ts"; import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts"; -import { createPathRef, PathRef } from "./src/path.ts"; +import { createPath, Path } from "./src/path.ts"; export type { Delay, DelayIterator } from "./src/common.ts"; export { TimeoutError } from "./src/common.ts"; -export { FsFileWrapper, PathRef } from "./src/path.ts"; +export { FsFileWrapper, Path } from "./src/path.ts"; +/** @deprecated Import `Path` instead. */ +const PathRef = Path; +export { PathRef }; export type { ExpandGlobOptions, PathSymlinkOptions, SymlinkOptions, WalkEntry, WalkOptions } from "./src/path.ts"; export { CommandBuilder, @@ -201,7 +204,7 @@ export interface $BuiltInProperties { options?: Create$Options, ): $Type & TNewExtras>; /** Changes the directory of the current process. */ - cd(path: string | URL | ImportMeta | PathRef): void; + cd(path: string | URL | ImportMeta | Path): void; /** * Escapes an argument for the shell when NOT using the template * literal. @@ -259,9 +262,9 @@ export interface $BuiltInProperties { /** Helper function for creating path references, which provide an easier way for * working with paths, directories, and files on the file system. * - * The function creates a new `PathRef` from a path or URL string, file URL, or for the current module. + * The function creates a new `Path` from a path or URL string, file URL, or for the current module. */ - path: typeof createPathRef; + path: typeof createPath; /** * Logs with potential indentation (`$.logIndent`) * and output of commands or request responses. @@ -541,11 +544,11 @@ async function withRetries( throw new Error(`Failed after ${opts.count} attempts.`); } -function cd(path: string | URL | ImportMeta | PathRef) { +function cd(path: string | URL | ImportMeta | Path) { if (typeof path === "string" || path instanceof URL) { - path = new PathRef(path); - } else if (!(path instanceof PathRef)) { - path = new PathRef(path satisfies ImportMeta).parentOrThrow(); + path = new Path(path); + } else if (!(path instanceof Path)) { + path = new Path(path satisfies ImportMeta).parentOrThrow(); } Deno.chdir(path.toString()); } @@ -581,7 +584,7 @@ function buildInitial$State( } const helperObject = { - path: createPathRef, + path: createPath, cd, escapeArg, stripAnsi(text: string) { diff --git a/src/command.ts b/src/command.ts index 65c4818..13cfc0b 100644 --- a/src/command.ts +++ b/src/command.ts @@ -31,7 +31,7 @@ import { } from "./pipes.ts"; import { parseCommand, spawn } from "./shell.ts"; import { isShowingProgressBars } from "./console/progress/interval.ts"; -import { PathRef } from "./path.ts"; +import { Path } from "./path.ts"; import { RequestBuilder } from "./request.ts"; import { StreamFds } from "./shell.ts"; import { symbols } from "./common.ts"; @@ -305,7 +305,7 @@ export class CommandBuilder implements PromiseLike { state.stdin = reader; } else if (reader instanceof Uint8Array) { state.stdin = new Deferred(() => new Buffer(reader)); - } else if (reader instanceof PathRef) { + } else if (reader instanceof Path) { state.stdin = new Deferred(async () => { const file = await reader.open(); return file.readable; @@ -416,11 +416,11 @@ export class CommandBuilder implements PromiseLike { } /** Sets the current working directory to use when executing this command. */ - cwd(dirPath: string | URL | PathRef): CommandBuilder { + cwd(dirPath: string | URL | Path): CommandBuilder { return this.#newWithState((state) => { state.cwd = dirPath instanceof URL ? path.fromFileUrl(dirPath) - : dirPath instanceof PathRef + : dirPath instanceof Path ? dirPath.resolve().toString() : path.resolve(dirPath); }); @@ -869,7 +869,7 @@ export function parseAndSpawnCommand(state: CommandBuilderState) { function getOutputBuffer(inheritWriter: WriterSync, { kind, options }: ShellPipeWriterKindWithOptions) { if (typeof kind === "object") { - if (kind instanceof PathRef) { + if (kind instanceof Path) { const file = kind.openSync({ write: true, truncate: true, create: true }); disposables.push(file); return file; @@ -1252,7 +1252,7 @@ function templateInner( const expr = exprs[i]; const inputOrOutputRedirect = detectInputOrOutputRedirect(text); if (inputOrOutputRedirect === "<") { - if (expr instanceof PathRef) { + if (expr instanceof Path) { text += templateLiteralExprToString(expr, escape); } else if (typeof expr === "string") { handleReadableStream(() => @@ -1312,7 +1312,7 @@ function templateInner( throw new Error("Unsupported object provided to input redirect."); } } else if (inputOrOutputRedirect === ">") { - if (expr instanceof PathRef) { + if (expr instanceof Path) { text += templateLiteralExprToString(expr, escape); } else if (expr instanceof WritableStream) { handleWritableStream(() => expr); diff --git a/src/deps.test.ts b/src/deps.test.ts index 9530214..9fdc4e1 100644 --- a/src/deps.test.ts +++ b/src/deps.test.ts @@ -1,4 +1,4 @@ -import { createPathRef, PathRef } from "./path.ts"; +import { createPath, Path } from "./path.ts"; export { assert, @@ -16,16 +16,16 @@ export { isNode } from "https://deno.land/x/which_runtime@0.2.0/mod.ts"; * Creates a temporary directory, changes the cwd to this directory, * then cleans up and restores the cwd when complete. */ -export async function withTempDir(action: (path: PathRef) => Promise | void) { +export async function withTempDir(action: (path: Path) => Promise | void) { await using dirPath = usingTempDir(); - await action(createPathRef(dirPath).resolve()); + await action(createPath(dirPath).resolve()); } -export function usingTempDir(): PathRef & AsyncDisposable { +export function usingTempDir(): Path & AsyncDisposable { const originalDirPath = Deno.cwd(); const dirPath = Deno.makeTempDirSync(); Deno.chdir(dirPath); - const pathRef = createPathRef(dirPath).resolve(); + const pathRef = createPath(dirPath).resolve(); (pathRef as any)[Symbol.asyncDispose] = async () => { try { await Deno.remove(dirPath, { recursive: true }); @@ -34,5 +34,5 @@ export function usingTempDir(): PathRef & AsyncDisposable { } Deno.chdir(originalDirPath); }; - return pathRef as PathRef & AsyncDisposable; + return pathRef as Path & AsyncDisposable; } diff --git a/src/path.test.ts b/src/path.test.ts index fc5f6c3..35392a7 100644 --- a/src/path.test.ts +++ b/src/path.test.ts @@ -1,41 +1,41 @@ import { assert, assertEquals, assertRejects, assertThrows, isNode, withTempDir } from "./deps.test.ts"; -import { createPathRef, PathRef } from "./path.ts"; +import { createPath, Path } from "./path.ts"; import { path as stdPath } from "./deps.ts"; Deno.test("create from path ref", () => { - const path = createPathRef("src"); - const path2 = createPathRef(path); - const path3 = new PathRef(path); + const path = createPath("src"); + const path2 = createPath(path); + const path3 = new Path(path); assertEquals(path, path2); assertEquals(path.toString(), path3.toString()); }); Deno.test("custom inspect", () => { - const path = createPathRef("src"); - assertEquals(Deno.inspect(path), 'PathRef("src")'); + const path = createPath("src"); + assertEquals(Deno.inspect(path), 'Path("src")'); }); Deno.test("equals", () => { - const path = createPathRef("src"); - assert(path.equals(createPathRef("src"))); - assert(!path.equals(createPathRef("src2"))); - assert(path.equals(createPathRef("src").resolve())); + const path = createPath("src"); + assert(path.equals(createPath("src"))); + assert(!path.equals(createPath("src2"))); + assert(path.equals(createPath("src").resolve())); }); Deno.test("join", () => { - const path = createPathRef("src"); + const path = createPath("src"); const newPath = path.join("other", "test"); assertEquals(path.toString(), "src"); assertEquals(newPath.toString(), stdPath.join("src", "other", "test")); }); Deno.test("resolve", () => { - const path = createPathRef("src").resolve(); + const path = createPath("src").resolve(); assertEquals(path.toString(), stdPath.resolve("src")); }); Deno.test("normalize", () => { - const path = createPathRef("src").normalize(); + const path = createPath("src").normalize(); assertEquals(path.toString(), stdPath.normalize("src")); }); @@ -61,8 +61,8 @@ Deno.test("isFile", async () => { Deno.test("isSymlink", async () => { await withTempDir(() => { - const file = createPathRef("file.txt").writeTextSync(""); - const symlinkFile = createPathRef("test.txt"); + const file = createPath("file.txt").writeTextSync(""); + const symlinkFile = createPath("test.txt"); symlinkFile.createSymlinkToSync(file, { kind: "absolute" }); assert(symlinkFile.isSymlinkSync()); assert(!file.isSymlinkSync()); @@ -70,31 +70,31 @@ Deno.test("isSymlink", async () => { }); Deno.test("isAbsolute", () => { - assert(!createPathRef("src").isAbsolute()); - assert(createPathRef("src").resolve().isAbsolute()); + assert(!createPath("src").isAbsolute()); + assert(createPath("src").resolve().isAbsolute()); }); Deno.test("isRelative", () => { - assert(createPathRef("src").isRelative()); - assert(!createPathRef("src").resolve().isRelative()); + assert(createPath("src").isRelative()); + assert(!createPath("src").resolve().isRelative()); }); Deno.test("parent", () => { - const parent = createPathRef("src").parent()!; + const parent = createPath("src").parent()!; assertEquals(parent.toString(), Deno.cwd()); const lastParent = Array.from(parent.ancestors()).at(-1)!; assertEquals(lastParent.parent(), undefined); }); Deno.test("parentOrThrow", () => { - const parent = createPathRef("src").parentOrThrow(); + const parent = createPath("src").parentOrThrow(); assertEquals(parent.toString(), Deno.cwd()); const lastParent = Array.from(parent.ancestors()).at(-1)!; assertThrows(() => lastParent.parentOrThrow(), Error); }); Deno.test("ancestors", () => { - const srcDir = createPathRef("src").resolve(); + const srcDir = createPath("src").resolve(); let lastDir = srcDir; for (const ancestor of srcDir.ancestors()) { assert(ancestor.toString().length < lastDir.toString().length); @@ -104,7 +104,7 @@ Deno.test("ancestors", () => { Deno.test("components", () => { { - const srcDir = createPathRef("src").resolve(); + const srcDir = createPath("src").resolve(); const components = Array.from(srcDir.components()); for (const component of components) { assert(!component.includes("/")); @@ -117,25 +117,25 @@ Deno.test("components", () => { assertEquals(components.length, expectedLength); } { - const srcDir = createPathRef("../src"); + const srcDir = createPath("../src"); const components = Array.from(srcDir.components()); assertEquals(components, ["..", "src"]); } { - const srcDir = createPathRef("./src"); + const srcDir = createPath("./src"); const components = Array.from(srcDir.components()); assertEquals(components, ["src"]); } // trailing slash { - const srcDir = createPathRef("./src/"); + const srcDir = createPath("./src/"); const components = Array.from(srcDir.components()); assertEquals(components, ["src"]); } // current dir { - const srcDir = createPathRef("."); + const srcDir = createPath("."); const components = Array.from(srcDir.components()); // todo: is this correct? assertEquals(components, ["."]); @@ -143,14 +143,14 @@ Deno.test("components", () => { // empty dir { - const srcDir = createPathRef("src/test//asdf"); + const srcDir = createPath("src/test//asdf"); const components = Array.from(srcDir.components()); assertEquals(components, ["src", "test", "asdf"]); // does the same as rust } // windows prefix { - const prefixed = createPathRef("\\\\?\\testing\\this\\out"); + const prefixed = createPath("\\\\?\\testing\\this\\out"); const components = Array.from(prefixed.components()); // todo: is this correct? assertEquals(components, ["\\\\?\\testing", "this", "out"]); @@ -159,8 +159,8 @@ Deno.test("components", () => { Deno.test("startsWith", () => { { - const srcDir = createPathRef("src").resolve(); - const thisDir = createPathRef(".").resolve(); + const srcDir = createPath("src").resolve(); + const thisDir = createPath(".").resolve(); assert(srcDir.startsWith(thisDir)); assert(!thisDir.startsWith(srcDir)); } @@ -168,33 +168,33 @@ Deno.test("startsWith", () => { Deno.test("endsWith", () => { { - const srcDir = createPathRef("src").resolve(); - const thisDir = createPathRef(".").resolve(); + const srcDir = createPath("src").resolve(); + const thisDir = createPath(".").resolve(); assert(!srcDir.endsWith(thisDir)); assert(!thisDir.endsWith(srcDir)); assert(srcDir.endsWith("src")); } // nested { - const nestedDir = createPathRef("src/nested"); + const nestedDir = createPath("src/nested"); assert(nestedDir.endsWith("src/nested")); } // trailing slash { - const nestedDir = createPathRef("src/nested/"); + const nestedDir = createPath("src/nested/"); assert(nestedDir.endsWith("src/nested")); assert(nestedDir.endsWith("src/nested/")); } // the same, then not { - const nestedDir = createPathRef("src/nested").resolve(); + const nestedDir = createPath("src/nested").resolve(); assert(!nestedDir.endsWith("test/src/nested")); } }); Deno.test("resolve", () => { // there are more tests elsewhere - const srcDir = createPathRef("src").resolve(); + const srcDir = createPath("src").resolve(); const assetsDir = srcDir.resolve("assets"); assert(assetsDir.toString().endsWith("assets")); @@ -204,22 +204,22 @@ Deno.test("resolve", () => { Deno.test("known resolved", () => { // there are more tests elsewhere - const srcDir = createPathRef("src").resolve(); - const newPath = createPathRef(srcDir.toString()); + const srcDir = createPath("src").resolve(); + const newPath = createPath(srcDir.toString()); // should be the same object since the existing path was resolved assert(newPath === newPath.resolve()); }); Deno.test("stat", async () => { - const stat1 = await createPathRef("src").stat(); + const stat1 = await createPath("src").stat(); assertEquals(stat1?.isDirectory, true); - const stat2 = await createPathRef("nonExistent").stat(); + const stat2 = await createPath("nonExistent").stat(); assertEquals(stat2, undefined); await withTempDir(async () => { - const tempFile = createPathRef("temp.txt").writeTextSync(""); - const symlinkFile = createPathRef("other.txt"); + const tempFile = createPath("temp.txt").writeTextSync(""); + const symlinkFile = createPath("other.txt"); await symlinkFile.createSymlinkTo(tempFile, { kind: "absolute" }); const stat3 = await symlinkFile.stat(); assertEquals(stat3!.isFile, true); @@ -228,14 +228,14 @@ Deno.test("stat", async () => { }); Deno.test("statSync", async () => { - const stat1 = createPathRef("src").statSync(); + const stat1 = createPath("src").statSync(); assertEquals(stat1?.isDirectory, true); - const stat2 = createPathRef("nonExistent").statSync(); + const stat2 = createPath("nonExistent").statSync(); assertEquals(stat2, undefined); await withTempDir(() => { - const tempFile = createPathRef("temp.txt").writeTextSync(""); - const symlinkFile = createPathRef("other.txt"); + const tempFile = createPath("temp.txt").writeTextSync(""); + const symlinkFile = createPath("other.txt"); symlinkFile.createSymlinkToSync(tempFile, { kind: "absolute" }); const stat3 = symlinkFile.statSync(); assertEquals(stat3!.isFile, true); @@ -244,14 +244,14 @@ Deno.test("statSync", async () => { }); Deno.test("lstat", async () => { - const stat1 = await createPathRef("src").lstat(); + const stat1 = await createPath("src").lstat(); assertEquals(stat1?.isDirectory, true); - const stat2 = await createPathRef("nonExistent").lstat(); + const stat2 = await createPath("nonExistent").lstat(); assertEquals(stat2, undefined); await withTempDir(async () => { - const symlinkFile = createPathRef("temp.txt"); - const otherFile = createPathRef("other.txt").writeTextSync(""); + const symlinkFile = createPath("temp.txt"); + const otherFile = createPath("other.txt").writeTextSync(""); // path ref await symlinkFile.createSymlinkTo(otherFile, { kind: "absolute" }); const stat3 = await symlinkFile.lstat(); @@ -260,21 +260,21 @@ Deno.test("lstat", async () => { }); Deno.test("lstatSync", async () => { - const stat1 = createPathRef("src").lstatSync(); + const stat1 = createPath("src").lstatSync(); assertEquals(stat1?.isDirectory, true); - const stat2 = createPathRef("nonExistent").lstatSync(); + const stat2 = createPath("nonExistent").lstatSync(); assertEquals(stat2, undefined); await withTempDir(() => { - const symlinkFile = createPathRef("temp.txt"); - const otherFile = createPathRef("other.txt").writeTextSync(""); + const symlinkFile = createPath("temp.txt"); + const otherFile = createPath("other.txt").writeTextSync(""); symlinkFile.createSymlinkToSync(otherFile, { kind: "absolute" }); assertEquals(symlinkFile.lstatSync()!.isSymlink, true); }); }); Deno.test("withExtname", () => { - let path = createPathRef("src").resolve(); + let path = createPath("src").resolve(); path = path.join("temp", "other"); assertEquals(path.basename(), "other"); assertEquals(path.extname(), undefined); @@ -295,7 +295,7 @@ Deno.test("withExtname", () => { }); Deno.test("withBasename", () => { - let path = createPathRef("src").resolve(); + let path = createPath("src").resolve(); path = path.join("temp", "other"); assertEquals(path.basename(), "other"); path = path.withBasename("test"); @@ -305,8 +305,8 @@ Deno.test("withBasename", () => { }); Deno.test("relative", () => { - const path1 = createPathRef("src"); - const path2 = createPathRef(".github"); + const path1 = createPath("src"); + const path2 = createPath(".github"); assertEquals( path1.relative(path2), Deno.build.os === "windows" ? "..\\.github" : "../.github", @@ -315,7 +315,7 @@ Deno.test("relative", () => { Deno.test("exists", async () => { await withTempDir(async () => { - const file = createPathRef("file"); + const file = createPath("file"); assert(!await file.exists()); assert(!file.existsSync()); file.writeTextSync(""); @@ -333,9 +333,9 @@ Deno.test("realpath", async () => { // for the comparison, node doesn't canonicalize // RUNNER~1 to runneradmin for some reason if (isNode && Deno.build.os === "windows") { - file = createPathRef(file.toString().replace("\\RUNNER~1\\", "\\runneradmin\\")); + file = createPath(file.toString().replace("\\RUNNER~1\\", "\\runneradmin\\")); } - const symlink = createPathRef("other"); + const symlink = createPath("other"); symlink.createSymlinkToSync(file, { kind: "absolute" }); assertEquals( (await symlink.realPath()).toString(), @@ -350,7 +350,7 @@ Deno.test("realpath", async () => { Deno.test("mkdir", async () => { await withTempDir(async () => { - const path = createPathRef("dir"); + const path = createPath("dir"); await path.mkdir(); assert(path.isDirSync()); path.removeSync(); @@ -372,7 +372,7 @@ Deno.test("mkdir", async () => { Deno.test("createSymlinkTo", async () => { await withTempDir(async () => { - const destFile = createPathRef("temp.txt").writeTextSync(""); + const destFile = createPath("temp.txt").writeTextSync(""); const symlinkFile = destFile.parentOrThrow().join("other.txt"); await symlinkFile.createSymlinkTo(destFile, { kind: "absolute", @@ -396,7 +396,7 @@ Deno.test("createSymlinkTo", async () => { Deno.test("createSymlinkToSync", async () => { await withTempDir(() => { - const destFile = createPathRef("temp.txt").writeTextSync(""); + const destFile = createPath("temp.txt").writeTextSync(""); const symlinkFile = destFile.parentOrThrow().join("other.txt"); // path ref @@ -435,7 +435,7 @@ Deno.test("createSymlinkToSync", async () => { Deno.test("readDir", async () => { await withTempDir(async () => { - const dir = createPathRef(".").resolve(); + const dir = createPath(".").resolve(); dir.join("file1").writeTextSync(""); dir.join("file2").writeTextSync(""); @@ -468,7 +468,7 @@ Deno.test("readDir", async () => { Deno.test("expandGlob", async () => { await withTempDir(async () => { - const dir = createPathRef(".").resolve(); + const dir = createPath(".").resolve(); dir.join("file1").writeTextSync(""); dir.join("file2").writeTextSync(""); const subDir = dir.join("dir").join("subDir"); @@ -495,7 +495,7 @@ Deno.test("expandGlob", async () => { Deno.test("walk", async () => { await withTempDir(async () => { - const dir = createPathRef("rootDir").mkdirSync(); + const dir = createPath("rootDir").mkdirSync(); dir.join("file1").writeTextSync(""); dir.join("file2").writeTextSync(""); const subDir = dir.join("dir").join("subDir"); @@ -532,12 +532,12 @@ Deno.test("walk", async () => { Deno.test("readBytes", async () => { await withTempDir(async () => { - const file = createPathRef("file.txt"); + const file = createPath("file.txt"); const bytes = new TextEncoder().encode("asdf"); file.writeSync(bytes); assertEquals(file.readBytesSync(), bytes); assertEquals(await file.readBytes(), bytes); - const nonExistent = createPathRef("not-exists"); + const nonExistent = createPath("not-exists"); assertThrows(() => nonExistent.readBytesSync()); await assertRejects(() => nonExistent.readBytes()); }); @@ -545,12 +545,12 @@ Deno.test("readBytes", async () => { Deno.test("readMaybeBytes", async () => { await withTempDir(async () => { - const file = createPathRef("file.txt"); + const file = createPath("file.txt"); const bytes = new TextEncoder().encode("asdf"); await file.write(bytes); assertEquals(file.readMaybeBytesSync(), bytes); assertEquals(await file.readMaybeBytes(), bytes); - const nonExistent = createPathRef("not-exists"); + const nonExistent = createPath("not-exists"); assertEquals(await nonExistent.readMaybeText(), undefined); assertEquals(nonExistent.readMaybeTextSync(), undefined); }); @@ -558,11 +558,11 @@ Deno.test("readMaybeBytes", async () => { Deno.test("readText", async () => { await withTempDir(async () => { - const file = createPathRef("file.txt"); + const file = createPath("file.txt"); file.writeTextSync("asdf"); assertEquals(file.readMaybeTextSync(), "asdf"); assertEquals(await file.readMaybeText(), "asdf"); - const nonExistent = createPathRef("not-exists"); + const nonExistent = createPath("not-exists"); assertThrows(() => nonExistent.readTextSync()); await assertRejects(() => nonExistent.readText()); }); @@ -570,11 +570,11 @@ Deno.test("readText", async () => { Deno.test("readMaybeText", async () => { await withTempDir(async () => { - const file = createPathRef("file.txt"); + const file = createPath("file.txt"); file.writeTextSync("asdf"); assertEquals(file.readMaybeTextSync(), "asdf"); assertEquals(await file.readMaybeText(), "asdf"); - const nonExistent = createPathRef("not-exists"); + const nonExistent = createPath("not-exists"); assertEquals(await nonExistent.readMaybeText(), undefined); assertEquals(nonExistent.readMaybeTextSync(), undefined); }); @@ -582,7 +582,7 @@ Deno.test("readMaybeText", async () => { Deno.test("readJson", async () => { await withTempDir(async () => { - const file = createPathRef("file.txt"); + const file = createPath("file.txt"); file.writeJsonSync({ test: 123 }); let data = file.readJsonSync(); assertEquals(data, { test: 123 }); @@ -593,13 +593,13 @@ Deno.test("readJson", async () => { Deno.test("readMaybeJson", async () => { await withTempDir(async () => { - const file = createPathRef("file.json"); + const file = createPath("file.json"); file.writeJsonSync({ test: 123 }); let data = file.readMaybeJsonSync(); assertEquals(data, { test: 123 }); data = await file.readMaybeJson(); assertEquals(data, { test: 123 }); - const nonExistent = createPathRef("not-exists"); + const nonExistent = createPath("not-exists"); data = nonExistent.readMaybeJsonSync(); assertEquals(data, undefined); data = await nonExistent.readMaybeJson(); @@ -644,7 +644,7 @@ Deno.test("write", async () => { Deno.test("writeJson", async () => { await withTempDir(async () => { - const path = createPathRef("file.json"); + const path = createPath("file.json"); await path.writeJson({ prop: "test", }); @@ -669,7 +669,7 @@ Deno.test("writeJson", async () => { Deno.test("writeJsonPretty", async () => { await withTempDir(async () => { - const path = createPathRef("file.json"); + const path = createPath("file.json"); await path.writeJsonPretty({ prop: "test", }); @@ -694,7 +694,7 @@ Deno.test("writeJsonPretty", async () => { Deno.test("create", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync("text"); + const path = createPath("file.txt").writeTextSync("text"); let file = await path.create(); file.writeTextSync("asdf"); file.close(); @@ -712,7 +712,7 @@ Deno.test("create", async () => { Deno.test("createNew", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync("text"); + const path = createPath("file.txt").writeTextSync("text"); await assertRejects(() => path.createNew()); path.removeSync(); let file = await path.createNew(); @@ -726,7 +726,7 @@ Deno.test("createNew", async () => { Deno.test("open", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync("text"); + const path = createPath("file.txt").writeTextSync("text"); let file = await path.open({ write: true }); await file.writeText("1"); file.writeTextSync("2"); @@ -740,7 +740,7 @@ Deno.test("open", async () => { Deno.test("remove", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync("text"); + const path = createPath("file.txt").writeTextSync("text"); assert(path.existsSync()); assert(!path.removeSync().existsSync()); path.writeTextSync("asdf"); @@ -812,7 +812,7 @@ Deno.test("ensureFile", async () => { Deno.test("copyFile", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync("text"); + const path = createPath("file.txt").writeTextSync("text"); const newPath = await path.copyFile("other.txt"); assert(path.existsSync()); assert(newPath.existsSync()); @@ -825,15 +825,15 @@ Deno.test("copyFile", async () => { Deno.test("copyFileToDir", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt") + const path = createPath("file.txt") .writeTextSync("text"); - const dir = createPathRef("dir").mkdirSync(); + const dir = createPath("dir").mkdirSync(); const newPath = await path.copyFileToDir(dir); assert(path.existsSync()); assert(newPath.existsSync()); assertEquals(dir.join("file.txt").toString(), newPath.toString()); assertEquals(newPath.readTextSync(), "text"); - const dir2 = createPathRef("dir2").mkdirSync(); + const dir2 = createPath("dir2").mkdirSync(); const newPath2 = path.copyFileToDirSync(dir2); assert(newPath2.existsSync()); assertEquals(newPath2.readTextSync(), "text"); @@ -843,7 +843,7 @@ Deno.test("copyFileToDir", async () => { Deno.test("rename", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt").writeTextSync(""); + const path = createPath("file.txt").writeTextSync(""); const newPath = path.renameSync("other.txt"); assert(!path.existsSync()); assert(newPath.existsSync()); @@ -856,15 +856,15 @@ Deno.test("rename", async () => { Deno.test("renameToDir", async () => { await withTempDir(async () => { - const path = createPathRef("file.txt") + const path = createPath("file.txt") .writeTextSync("text"); - const dir = createPathRef("dir").mkdirSync(); + const dir = createPath("dir").mkdirSync(); const newPath = await path.renameToDir(dir); assert(!path.existsSync()); assert(newPath.existsSync()); assertEquals(dir.join("file.txt").toString(), newPath.toString()); assertEquals(newPath.readTextSync(), "text"); - const dir2 = createPathRef("dir2").mkdirSync(); + const dir2 = createPath("dir2").mkdirSync(); const newPath2 = newPath.renameToDirSync(dir2); assert(!newPath.existsSync()); assert(newPath2.existsSync()); @@ -886,7 +886,7 @@ Deno.test("renameToDir", async () => { Deno.test("pipeTo", async () => { await withTempDir(async () => { const largeText = "asdf".repeat(100_000); - const textFile = createPathRef("file.txt").writeTextSync(largeText); + const textFile = createPath("file.txt").writeTextSync(largeText); const otherFilePath = textFile.parentOrThrow().join("other.txt"); const otherFile = otherFilePath.openSync({ write: true, create: true }); await textFile.pipeTo(otherFile.writable); @@ -895,23 +895,23 @@ Deno.test("pipeTo", async () => { }); Deno.test("instanceof check", () => { - class OtherPathRef { + class OtherPath { // should match because of this - private static instanceofSymbol = Symbol.for("dax.PathRef"); + private static instanceofSymbol = Symbol.for("dax.Path"); static [Symbol.hasInstance](instance: any) { - return instance?.constructor?.instanceofSymbol === OtherPathRef.instanceofSymbol; + return instance?.constructor?.instanceofSymbol === OtherPath.instanceofSymbol; } } - assert(createPathRef("test") instanceof PathRef); - assert(!(new URL("https://example.com") instanceof PathRef)); - assert(new OtherPathRef() instanceof PathRef); - assert(createPathRef("test") instanceof OtherPathRef); + assert(createPath("test") instanceof Path); + assert(!(new URL("https://example.com") instanceof Path)); + assert(new OtherPath() instanceof Path); + assert(createPath("test") instanceof OtherPath); }); Deno.test("toFileUrl", () => { - const path = createPathRef(import.meta.url); + const path = createPath(import.meta.url); assertEquals(path.toString(), stdPath.fromFileUrl(import.meta.url)); assertEquals(path.toFileUrl(), new URL(import.meta.url)); }); diff --git a/src/path.ts b/src/path.ts index 367e35d..d44c7c2 100644 --- a/src/path.ts +++ b/src/path.ts @@ -31,16 +31,16 @@ export type WalkOptions = DenoStdWalkOptions; const PERIOD_CHAR_CODE = ".".charCodeAt(0); /** @internal */ -export function createPathRef(path: string | URL | ImportMeta | PathRef): PathRef { - if (path instanceof PathRef) { +export function createPath(path: string | URL | ImportMeta | Path): Path { + if (path instanceof Path) { return path; } else { - return new PathRef(path); + return new Path(path); } } export interface WalkEntry extends Deno.DirEntry { - path: PathRef; + path: Path; } export interface PathSymlinkOptions { @@ -56,22 +56,22 @@ export interface SymlinkOptions extends Partial, Partial { + *ancestors(): Generator { let ancestor = this.parent(); while (ancestor != null) { yield ancestor; @@ -325,8 +325,8 @@ export class PathRef { } } - startsWith(path: PathRef | URL | string): boolean { - const startsWithComponents = ensurePathRef(path).components(); + startsWith(path: Path | URL | string): boolean { + const startsWithComponents = ensurePath(path).components(); for (const component of this.components()) { const next = startsWithComponents.next(); if (next.done) { @@ -339,8 +339,8 @@ export class PathRef { return startsWithComponents.next().done ?? true; } - endsWith(path: PathRef | URL | string): boolean { - const endsWithComponents = ensurePathRef(path).#rcomponents(); + endsWith(path: Path | URL | string): boolean { + const endsWithComponents = ensurePath(path).#rcomponents(); for (const component of this.#rcomponents()) { const next = endsWithComponents.next(); if (next.done) { @@ -354,18 +354,18 @@ export class PathRef { } /** Gets the parent directory or returns undefined if the parent is the root directory. */ - parent(): PathRef | undefined { + parent(): Path | undefined { const resolvedPath = this.resolve(); const dirname = resolvedPath.dirname(); if (dirname === resolvedPath.#path) { return undefined; } else { - return new PathRef(dirname); + return new Path(dirname); } } /** Gets the parent or throws if the current directory was the root. */ - parentOrThrow(): PathRef { + parentOrThrow(): Path { const parent = this.parent(); if (parent == null) { throw new Error(`Cannot get the parent directory of '${this.#path}'.`); @@ -383,25 +383,25 @@ export class PathRef { } /** Gets a new path reference with the provided extension. */ - withExtname(ext: string): PathRef { + withExtname(ext: string): Path { const currentExt = this.extname(); const hasLeadingPeriod = ext.charCodeAt(0) === PERIOD_CHAR_CODE; if (!hasLeadingPeriod && ext.length !== 0) { ext = "." + ext; } - return new PathRef(this.#path.substring(0, this.#path.length - (currentExt?.length ?? 0)) + ext); + return new Path(this.#path.substring(0, this.#path.length - (currentExt?.length ?? 0)) + ext); } /** Gets a new path reference with the provided file or directory name. */ - withBasename(basename: string): PathRef { + withBasename(basename: string): Path { const currentBaseName = this.basename(); - return new PathRef(this.#path.substring(0, this.#path.length - currentBaseName.length) + basename); + return new Path(this.#path.substring(0, this.#path.length - currentBaseName.length) + basename); } /** Gets the relative path from this path to the specified path. */ - relative(to: string | URL | PathRef): string { - const toPathRef = ensurePathRef(to); - return stdPath.relative(this.resolve().#path, toPathRef.resolve().#path); + relative(to: string | URL | Path): string { + const toPath = ensurePath(to); + return stdPath.relative(this.resolve().#path, toPath.resolve().#path); } /** Gets if the path exists. Beware of TOCTOU issues. */ @@ -415,13 +415,13 @@ export class PathRef { } /** Resolves to the absolute normalized path, with symbolic links resolved. */ - realPath(): Promise { - return Deno.realPath(this.#path).then((path) => new PathRef(path)); + realPath(): Promise { + return Deno.realPath(this.#path).then((path) => new Path(path)); } /** Synchronously resolves to the absolute normalized path, with symbolic links resolved. */ - realPathSync(): PathRef { - return new PathRef(Deno.realPathSync(this.#path)); + realPathSync(): Path { + return new Path(Deno.realPathSync(this.#path)); } /** Expands the glob using the current path as the root. */ @@ -473,7 +473,7 @@ export class PathRef { #stdWalkEntryToDax(entry: import("./deps.ts").WalkEntry): WalkEntry { return { ...entry, - path: new PathRef(entry.path), + path: new Path(entry.path), }; } @@ -503,7 +503,7 @@ export class PathRef { * Creates a symlink to the provided target path. */ async createSymlinkTo( - targetPath: URL | PathRef, + targetPath: URL | Path, opts: Partial & PathSymlinkOptions, ): Promise; /** @@ -514,7 +514,7 @@ export class PathRef { opts?: SymlinkOptions, ): Promise; async createSymlinkTo( - target: string | URL | PathRef, + target: string | URL | Path, opts?: SymlinkOptions, ): Promise { await createSymlink(this.#resolveCreateSymlinkOpts(target, opts)); @@ -524,7 +524,7 @@ export class PathRef { * Synchronously creates a symlink to the provided target path. */ createSymlinkToSync( - targetPath: URL | PathRef, + targetPath: URL | Path, opts: Partial & PathSymlinkOptions, ): void; /** @@ -534,16 +534,16 @@ export class PathRef { target: string, opts?: SymlinkOptions, ): void; - createSymlinkToSync(target: string | URL | PathRef, opts?: SymlinkOptions): void { + createSymlinkToSync(target: string | URL | Path, opts?: SymlinkOptions): void { createSymlinkSync(this.#resolveCreateSymlinkOpts(target, opts)); } - #resolveCreateSymlinkOpts(target: string | URL | PathRef, opts: SymlinkOptions | undefined): CreateSymlinkOpts { + #resolveCreateSymlinkOpts(target: string | URL | Path, opts: SymlinkOptions | undefined): CreateSymlinkOpts { if (opts?.kind == null) { if (typeof target === "string") { return { fromPath: this.resolve(), - targetPath: ensurePathRef(target), + targetPath: ensurePath(target), text: target, type: opts?.type, }; @@ -551,7 +551,7 @@ export class PathRef { throw new Error("Please specify if this symlink is absolute or relative. Otherwise provide the target text."); } } - const targetPath = ensurePathRef(target).resolve(); + const targetPath = ensurePath(target).resolve(); if (opts?.kind === "relative") { const fromPath = this.resolve(); let relativePath: string; @@ -600,7 +600,7 @@ export class PathRef { } /** Reads only the directory file paths, not including symlinks. */ - async *readDirFilePaths(): AsyncIterable { + async *readDirFilePaths(): AsyncIterable { const dir = this.resolve(); for await (const entry of Deno.readDir(dir.#path)) { if (entry.isFile) { @@ -610,7 +610,7 @@ export class PathRef { } /** Synchronously reads only the directory file paths, not including symlinks. */ - *readDirFilePathsSync(): Iterable { + *readDirFilePathsSync(): Iterable { const dir = this.resolve(); for (const entry of Deno.readDirSync(dir.#path)) { if (entry.isFile) { @@ -1042,8 +1042,8 @@ export class PathRef { * Copies the file to the specified destination path. * @returns The destination file path. */ - copyFile(destinationPath: string | URL | PathRef): Promise { - const pathRef = ensurePathRef(destinationPath); + copyFile(destinationPath: string | URL | Path): Promise { + const pathRef = ensurePath(destinationPath); return Deno.copyFile(this.#path, pathRef.#path) .then(() => pathRef); } @@ -1052,8 +1052,8 @@ export class PathRef { * Copies the file to the destination path synchronously. * @returns The destination file path. */ - copyFileSync(destinationPath: string | URL | PathRef): PathRef { - const pathRef = ensurePathRef(destinationPath); + copyFileSync(destinationPath: string | URL | Path): Path { + const pathRef = ensurePath(destinationPath); Deno.copyFileSync(this.#path, pathRef.#path); return pathRef; } @@ -1062,8 +1062,8 @@ export class PathRef { * Copies the file to the specified directory. * @returns The destination file path. */ - copyFileToDir(destinationDirPath: string | URL | PathRef): Promise { - const destinationPath = ensurePathRef(destinationDirPath) + copyFileToDir(destinationDirPath: string | URL | Path): Promise { + const destinationPath = ensurePath(destinationDirPath) .join(this.basename()); return this.copyFile(destinationPath); } @@ -1072,8 +1072,8 @@ export class PathRef { * Copies the file to the specified directory synchronously. * @returns The destination file path. */ - copyFileToDirSync(destinationDirPath: string | URL | PathRef): PathRef { - const destinationPath = ensurePathRef(destinationDirPath) + copyFileToDirSync(destinationDirPath: string | URL | Path): Path { + const destinationPath = ensurePath(destinationDirPath) .join(this.basename()); return this.copyFileSync(destinationPath); } @@ -1082,16 +1082,16 @@ export class PathRef { * Moves the file or directory returning a promise that resolves to * the renamed path. */ - rename(newPath: string | URL | PathRef): Promise { - const pathRef = ensurePathRef(newPath); + rename(newPath: string | URL | Path): Promise { + const pathRef = ensurePath(newPath); return Deno.rename(this.#path, pathRef.#path).then(() => pathRef); } /** * Moves the file or directory returning the renamed path synchronously. */ - renameSync(newPath: string | URL | PathRef): PathRef { - const pathRef = ensurePathRef(newPath); + renameSync(newPath: string | URL | Path): Path { + const pathRef = ensurePath(newPath); Deno.renameSync(this.#path, pathRef.#path); return pathRef; } @@ -1100,8 +1100,8 @@ export class PathRef { * Moves the file or directory to the specified directory. * @returns The destination file path. */ - renameToDir(destinationDirPath: string | URL | PathRef): Promise { - const destinationPath = ensurePathRef(destinationDirPath) + renameToDir(destinationDirPath: string | URL | Path): Promise { + const destinationPath = ensurePath(destinationDirPath) .join(this.basename()); return this.rename(destinationPath); } @@ -1110,8 +1110,8 @@ export class PathRef { * Moves the file or directory to the specified directory synchronously. * @returns The destination file path. */ - renameToDirSync(destinationDirPath: string | URL | PathRef): PathRef { - const destinationPath = ensurePathRef(destinationDirPath) + renameToDirSync(destinationDirPath: string | URL | Path): Path { + const destinationPath = ensurePath(destinationDirPath) .join(this.basename()); return this.renameSync(destinationPath); } @@ -1132,8 +1132,8 @@ export class PathRef { } } -function ensurePathRef(path: string | URL | PathRef) { - return path instanceof PathRef ? path : new PathRef(path); +function ensurePath(path: string | URL | Path) { + return path instanceof Path ? path : new Path(path); } async function createSymlink(opts: CreateSymlinkOpts) { @@ -1162,8 +1162,8 @@ async function createSymlink(opts: CreateSymlinkOpts) { } interface CreateSymlinkOpts { - fromPath: PathRef; - targetPath: PathRef; + fromPath: Path; + targetPath: Path; text: string; type: "file" | "dir" | undefined; } diff --git a/src/pipes.ts b/src/pipes.ts index 2c7103f..e77f779 100644 --- a/src/pipes.ts +++ b/src/pipes.ts @@ -1,4 +1,4 @@ -import { type FsFileWrapper, PathRef } from "./path.ts"; +import { type FsFileWrapper, Path } from "./path.ts"; import { logger } from "./console/logger.ts"; import { Buffer, writeAll, writeAllSync } from "./deps.ts"; import type { RequestBuilder } from "./request.ts"; @@ -48,7 +48,7 @@ export type ShellPipeReaderKind = | Uint8Array | CommandBuilder | FsFileWrapper - | PathRef + | Path | RequestBuilder; /** * The behaviour to use for a shell pipe. @@ -65,7 +65,7 @@ export type ShellPipeWriterKind = | WriterSync | WritableStream | FsFileWrapper - | PathRef; + | Path; export class NullPipeReader implements Reader { read(_p: Uint8Array): Promise { diff --git a/src/request.ts b/src/request.ts index 43aafc9..aa7f69d 100644 --- a/src/request.ts +++ b/src/request.ts @@ -2,7 +2,7 @@ import { formatMillis, symbols } from "./common.ts"; import { TimeoutError } from "./common.ts"; import { Delay, delayToMs, filterEmptyRecordValues, getFileNameFromUrl } from "./common.ts"; import { ProgressBar } from "./console/mod.ts"; -import { PathRef } from "./path.ts"; +import { Path } from "./path.ts"; interface RequestBuilderState { noThrow: boolean | number[]; @@ -342,7 +342,7 @@ export class RequestBuilder implements PromiseLike { * * @returns The path reference of the downloaded file. */ - async pipeToPath(options?: Deno.WriteFileOptions): Promise; + async pipeToPath(options?: Deno.WriteFileOptions): Promise; /** * Pipes the response body to a file. * @@ -352,11 +352,11 @@ export class RequestBuilder implements PromiseLike { * @returns The path reference of the downloaded file. */ async pipeToPath( - path?: string | URL | PathRef | undefined, + path?: string | URL | Path | undefined, options?: Deno.WriteFileOptions, - ): Promise; + ): Promise; async pipeToPath( - filePathOrOptions?: string | URL | PathRef | Deno.WriteFileOptions, + filePathOrOptions?: string | URL | Path | Deno.WriteFileOptions, maybeOptions?: Deno.WriteFileOptions, ) { // Do not derive from the response url because that could cause the server @@ -597,7 +597,7 @@ export class RequestResponse { * * @returns The path reference of the downloaded file */ - async pipeToPath(options?: Deno.WriteFileOptions): Promise; + async pipeToPath(options?: Deno.WriteFileOptions): Promise; /** * Pipes the response body to a file. * @@ -610,11 +610,11 @@ export class RequestResponse { * @returns The path reference of the downloaded file */ async pipeToPath( - path?: string | URL | PathRef | undefined, + path?: string | URL | Path | undefined, options?: Deno.WriteFileOptions, - ): Promise; + ): Promise; async pipeToPath( - filePathOrOptions?: string | URL | PathRef | Deno.WriteFileOptions, + filePathOrOptions?: string | URL | Path | Deno.WriteFileOptions, maybeOptions?: Deno.WriteFileOptions, ) { // resolve the file path using the original url because it would be a security issue @@ -763,16 +763,16 @@ export async function makeRequest(state: RequestBuilderState) { } function resolvePipeToPathParams( - pathOrOptions: string | URL | PathRef | Deno.WriteFileOptions | undefined, + pathOrOptions: string | URL | Path | Deno.WriteFileOptions | undefined, maybeOptions: Deno.WriteFileOptions | undefined, originalUrl: string | URL | undefined, ) { - let filePath: PathRef | undefined; + let filePath: Path | undefined; let options: Deno.WriteFileOptions | undefined; if (typeof pathOrOptions === "string" || pathOrOptions instanceof URL) { - filePath = new PathRef(pathOrOptions).resolve(); + filePath = new Path(pathOrOptions).resolve(); options = maybeOptions; - } else if (pathOrOptions instanceof PathRef) { + } else if (pathOrOptions instanceof Path) { filePath = pathOrOptions.resolve(); options = maybeOptions; } else if (typeof pathOrOptions === "object") { @@ -781,7 +781,7 @@ function resolvePipeToPathParams( options = maybeOptions; } if (filePath === undefined) { - filePath = new PathRef(getFileNameFromUrlOrThrow(originalUrl)); + filePath = new Path(getFileNameFromUrlOrThrow(originalUrl)); } else if (filePath.isDirSync()) { filePath = filePath.join(getFileNameFromUrlOrThrow(originalUrl)); }