Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: PathReference -> PathRef #102

Merged
merged 2 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ pb.with(() => {

## Path API

The path API offers an immutable `PathReference` class, which is a similar concept to Rust's `PathBuf` struct.
The path API offers an immutable `PathRef` class, which is a similar concept to Rust's `PathBuf` struct.

```ts
// create a `PathReference`
// create a `PathRef`
let srcDir = $.path("src");
// get information about the path
srcDir.isDir(); // false
Expand Down Expand Up @@ -509,7 +509,7 @@ const srcDir = $.path("src").resolve();
await $`echo ${srcDir}`;
```

There are a lot of helper methods here, so check the [documentation on PathReference](https://deno.land/x/dax/src/path.ts?s=PathReference) for more details.
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.

## Helper functions

Expand Down
8 changes: 4 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
import { colors, fs, outdent, path as stdPath, which, whichSync } from "./src/deps.ts";
import { wasmInstance } from "./src/lib/mod.ts";
import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts";
import { createPathReference } from "./src/path.ts";
import { createPathRef } from "./src/path.ts";

export { FsFileWrapper, PathReference } from "./src/path.ts";
export { FsFileWrapper, PathRef } from "./src/path.ts";
export { CommandBuilder, CommandResult } from "./src/command.ts";
export type { CommandContext, CommandHandler, CommandPipeReader, CommandPipeWriter } from "./src/command_handler.ts";
export type {
Expand Down Expand Up @@ -221,7 +221,7 @@ export interface $BuiltInProperties<TExtras extends ExtrasObject = {}> {
/** Helper function for creating path references, which provide an easier way for
* working with paths, directories, and files on the file system. Also, a re-export
* of deno_std's `path` module as properties on this object. */
path: typeof createPathReference & typeof stdPath;
path: typeof createPathRef & typeof stdPath;
/**
* Logs with potential indentation (`$.logIndent`)
* and output of commands or request responses.
Expand Down Expand Up @@ -531,7 +531,7 @@ function buildInitial$State<TExtras extends ExtrasObject>(

const helperObject = {
fs,
path: Object.assign(createPathReference, stdPath),
path: Object.assign(createPathRef, stdPath),
cd,
escapeArg,
stripAnsi(text: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { parseCommand, spawn } from "./shell.ts";
import { cpCommand, mvCommand } from "./commands/cp_mv.ts";
import { isShowingProgressBars } from "./console/progress/interval.ts";
import { touchCommand } from "./commands/touch.ts";
import { PathReference } from "./path.ts";
import { PathRef } from "./path.ts";

type BufferStdio = "inherit" | "null" | "streamed" | Buffer;

Expand Down Expand Up @@ -293,11 +293,11 @@ export class CommandBuilder implements PromiseLike<CommandResult> {
}

/** Sets the current working directory to use when executing this command. */
cwd(dirPath: string | URL | PathReference) {
cwd(dirPath: string | URL | PathRef) {
return this.#newWithState((state) => {
state.cwd = dirPath instanceof URL
? path.fromFileUrl(dirPath)
: dirPath instanceof PathReference
: dirPath instanceof PathRef
? dirPath.resolve().toString()
: path.resolve(dirPath);
});
Expand Down
6 changes: 3 additions & 3 deletions src/deps.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPathReference, PathReference } from "./path.ts";
import { createPathRef, PathRef } from "./path.ts";

export {
assert,
Expand All @@ -14,12 +14,12 @@ export { serve } from "https://deno.land/[email protected]/http/server.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: PathReference) => Promise<void> | void) {
export async function withTempDir(action: (path: PathRef) => Promise<void> | void) {
const originalDirPath = Deno.cwd();
const dirPath = Deno.makeTempDirSync();
Deno.chdir(dirPath);
try {
await action(createPathReference(dirPath).resolve());
await action(createPathRef(dirPath).resolve());
} finally {
try {
await Deno.remove(dirPath, { recursive: true });
Expand Down
Loading