Skip to content

Commit

Permalink
Check process.cwd before calling it
Browse files Browse the repository at this point in the history
Some runtimes (like React Native) has a `process` global, but doesn't provide a `cwd` function. Instead of assuming the `cwd` function is available, just because the `process` global is, merging this PR will update the check to actually verify the `process.cwd` is a callable function before relying on it.
  • Loading branch information
kraenhansen authored Nov 14, 2023
1 parent b7ff533 commit 3cf48e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const join: typeof path.join = function (...arguments_) {
};

function cwd() {
if (typeof process !== "undefined") {
if (typeof process !== "undefined" && typeof process.cwd === "function") {
return process.cwd().replace(/\\/g, "/");
}
return "/";
Expand Down

0 comments on commit 3cf48e3

Please sign in to comment.