Skip to content

Commit

Permalink
feat: support absolute path in cd
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 13, 2021
1 parent 251add4 commit c8d8f72
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/cd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { error } from "../_utils.ts";
import { path } from "./mod.ts";

const cwd = Deno.cwd();

Expand All @@ -7,7 +8,10 @@ export function cd(dir: string) {
console.log($.brightBlue("$ %s"), `cd ${dir}`);
}
try {
Deno.chdir(new URL(dir, path.toFileUrl(cwd + path.sep)).pathname);
if (dir[0] !== path.sep) {
dir = new URL(dir, path.toFileUrl(cwd + path.sep)).pathname;
}
Deno.chdir(dir);
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
const stack: string = (new Error().stack!.split("at ")[2]).trim();
Expand Down

0 comments on commit c8d8f72

Please sign in to comment.