Skip to content

Commit

Permalink
fix: process.cwd fallback on non-node env (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 20, 2023
1 parent 77c0ed1 commit 14714c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export const join: typeof path.join = function (...arguments_) {
return normalize(joined.replace(/\/\/+/g, "/"));
};

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

// resolve
export const resolve: typeof path.resolve = function (...arguments_) {
// Normalize windows arguments
Expand All @@ -81,7 +88,7 @@ export const resolve: typeof path.resolve = function (...arguments_) {
let resolvedAbsolute = false;

for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
const path = index >= 0 ? arguments_[index] : process.cwd().replace(/\\/g, "/");
const path = index >= 0 ? arguments_[index] : cwd();

// Skip empty entries
if (!path || path.length === 0) {
Expand Down

0 comments on commit 14714c1

Please sign in to comment.