Skip to content

Commit

Permalink
refactor: remove $.cwd and use Deno.chdir for cd
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 13, 2021
1 parent fd5f8b5 commit 33e097a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/runtime/cd.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { error } from "../_utils.ts";

export function cd(path: string) {
export function cd(dir: string) {
if ($.verbose) {
console.log($.brightBlue("$ %s"), `cd ${path}`);
console.log($.brightBlue("$ %s"), `cd ${dir}`);
}

try {
Deno.lstatSync(path);
Deno.chdir(new URL(dir, $.mainModule).pathname);
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
const stack: string = (new Error().stack!.split("at ")[2]).trim();
error(`cd: ${path}: No such directory\n at ${stack}`);
error(`cd: ${dir}: No such directory\n at ${stack}`);
} else if (err instanceof Deno.errors.PermissionDenied) {
const stack: string = (new Error().stack!.split("at ")[2]).trim();
error(`cd: ${path}: Permission denied\n at ${stack}`);
error(`cd: ${dir}: Permission denied\n at ${stack}`);
}
error(err);
}

$.cwd = path;
}
1 change: 0 additions & 1 deletion src/runtime/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function exec(
const combined: Array<string> = [];
const process = Deno.run({
cmd: [$.shell, "-c", cmd],
cwd: $.cwd,
env: Deno.env.toObject(),
stdout: "piped",
stderr: "piped",
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type $ = typeof exec & typeof colors & {
shell: string;
mainModule: string;
verbose: boolean;
cwd: string;
quote: typeof shq;
throwErors: boolean;
};
Expand All @@ -20,7 +19,6 @@ $._stack = [];
$.shell = "/bin/sh";
$.mainModule = "";
$.verbose = false;
$.cwd = Deno.cwd();
$.quote = shq;
$.throwErors = false;

Expand Down

0 comments on commit 33e097a

Please sign in to comment.