Skip to content

Commit 3de416d

Browse files
committed
fix(location): add better url and window.location checking, fall beck to root path
1 parent 0b60b3a commit 3de416d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/util/url.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,21 @@ export function resolve(from: string, to: string) {
4444
* @returns
4545
*/
4646
export function cwd() {
47-
if (typeof window !== "undefined") {
47+
if (typeof window !== "undefined" && window.location) {
4848
return location.href;
4949
}
5050

51-
const path = process.cwd();
51+
if (typeof process !== "undefined" && process.cwd) {
52+
const path = process.cwd();
5253

53-
const lastChar = path.slice(-1);
54-
if (lastChar === "/" || lastChar === "\\") {
55-
return path;
56-
} else {
57-
return path + "/";
54+
const lastChar = path.slice(-1);
55+
if (lastChar === "/" || lastChar === "\\") {
56+
return path;
57+
} else {
58+
return path + "/";
59+
}
5860
}
61+
return "/";
5962
}
6063

6164
/**

0 commit comments

Comments
 (0)