Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion ext/node/polyfills/_process/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { nextTick as _nextTick } from "ext:deno_node/_next_tick.ts";
import { _exiting } from "ext:deno_node/_process/exiting.ts";
import * as fs from "ext:deno_fs/30_fs.js";
import {
denoErrorToNodeError,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_OBJECT_DEFINE_PROPERTY,
} from "ext:deno_node/internal/errors.ts";
Expand All @@ -51,7 +52,19 @@ export function chdir(directory: string): void {
if (typeof directory !== "string") {
throw new ERR_INVALID_ARG_TYPE("directory", "string", directory);
}
fs.chdir(directory);
// Node's chdir error carries `path` (the cwd before chdir), `dest` (the
// target), and `syscall: 'chdir'`. Snapshot the cwd before attempting the
// change so the error's `path` matches Node's behaviour.
const fromPath = fs.cwd();
try {
fs.chdir(directory);
} catch (err) {
throw denoErrorToNodeError(err as Error, {
syscall: "chdir",
path: fromPath,
dest: directory,
});
}
}

/** https://nodejs.org/api/process.html#process_process_cwd */
Expand Down
1 change: 1 addition & 0 deletions tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,7 @@
"parallel/test-process-beforeexit-throw-exit.js": {},
"parallel/test-process-binding-internalbinding-allowlist.js": {},
"parallel/test-process-binding.js": {},
"parallel/test-process-chdir-errormessage.js": {},
"parallel/test-process-chdir.js": {},
"parallel/test-process-config.js": {},
"parallel/test-process-constants-noatime.js": {
Expand Down
Loading