Compare commits

...

2 Commits

Author SHA1 Message Date
Dylan Conway
7756307dcc fix test 2025-12-18 19:39:21 -08:00
Dylan Conway
96860991fc fix: $....cwd('.') no longer throws "undefined" path error (#25579)
The `defaultCwd` variable was `undefined`, causing `.cwd('.')` to pass
`undefined` to `setCwd()`, which the Zig code converted to the literal
string "undefined" and appended to the path.

Fix by removing the unused `defaultCwd` variable and using empty string
instead. Empty string is handled correctly by the Zig code - it joins
with the current cwd, effectively meaning "use process.cwd()".

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-18 14:57:19 -08:00
2 changed files with 52 additions and 4 deletions

View File

@@ -149,7 +149,7 @@ export function createBunShellTemplateFunction(createShellInterpreter_, createPa
cwd(newCwd?: string): this {
this.#throwIfRunning();
if (typeof newCwd === "undefined" || newCwd === "." || newCwd === "" || newCwd === "./") {
newCwd = defaultCwd;
newCwd = "";
}
this.#args!.setCwd(newCwd);
return this;
@@ -251,7 +251,6 @@ export function createBunShellTemplateFunction(createShellInterpreter_, createPa
var defaultEnv = process.env || {};
const originalDefaultEnv = defaultEnv;
var defaultCwd: string | undefined = undefined;
const cwdSymbol = Symbol("cwd");
const envSymbol = Symbol("env");
@@ -277,7 +276,7 @@ export function createBunShellTemplateFunction(createShellInterpreter_, createPa
cwd(newCwd: string | undefined) {
if (typeof newCwd === "undefined" || typeof newCwd === "string") {
if (newCwd === "." || newCwd === "" || newCwd === "./") {
newCwd = defaultCwd;
newCwd = "";
}
this[cwdSymbol] = newCwd;
@@ -344,7 +343,6 @@ export function createBunShellTemplateFunction(createShellInterpreter_, createPa
Object.setPrototypeOf(Shell, ShellPrototype);
Object.setPrototypeOf(BunShell, ShellPrototype.prototype);
BunShell[cwdSymbol] = defaultCwd;
BunShell[envSymbol] = defaultEnv;
BunShell[throwsSymbol] = true;

View File

@@ -786,6 +786,56 @@ booga"
const { stdout } = await $`cd ${temp_dir} && pwd && cd - && pwd`;
expect(stdout.toString()).toEqual(`${temp_dir}\n${process.cwd().replaceAll("\\", "/")}\n`);
});
test(".cwd('.') uses current working directory", async () => {
const result = await $`pwd`.cwd(".").text();
expect(result.trim()).toBe(process.cwd());
});
test(".cwd('') uses current working directory", async () => {
const result = await $`pwd`.cwd("").text();
expect(result.trim()).toBe(process.cwd());
});
test(".cwd('./') uses current working directory", async () => {
const result = await $`pwd`.cwd("./").text();
expect(result.trim()).toBe(process.cwd());
});
test(".cwd(undefined) uses current working directory", async () => {
// @ts-expect-error
const result = await $`pwd`.cwd(undefined).text();
expect(result.trim()).toBe(process.cwd());
});
test(".cwd(temp_dir).cwd('.') resets to current working directory", async () => {
const tmpResult = await $`pwd`.cwd(temp_dir).text();
expect(tmpResult.trim()).toBe(temp_dir);
const resetResult = await $`pwd`.cwd(temp_dir).cwd(".").text();
expect(resetResult.trim()).toBe(process.cwd());
});
test("$.cwd('.') sets default cwd to current working directory", async () => {
$.cwd(".");
const result = await $`pwd`.text();
expect(result.trim()).toBe(process.cwd());
});
test("$.cwd(temp_dir) then $.cwd('.') resets default cwd", async () => {
$.cwd(temp_dir);
const tmpResult = await $`pwd`.text();
expect(tmpResult.trim()).toBe(temp_dir);
$.cwd(".");
const resetResult = await $`pwd`.text();
expect(resetResult.trim()).toBe(process.cwd());
// Reset to original cwd for other tests
$.cwd(process.cwd().replaceAll("\\", "/"));
const finalResult = await $`pwd`.text();
expect(finalResult.trim()).toBe(process.cwd().replaceAll("\\", "/"));
});
});
test("which", async () => {