Skip to content

Commit c9da8a4

Browse files
committed
fix(win32): use optional win32 for apis where it is not available
1 parent b2dff0e commit c9da8a4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/util/url.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import convertPathToPosix from "./convert-path-to-posix";
2-
import path, { win32 } from "path";
3-
2+
import path from "path";
43
const forwardSlashPattern = /\//g;
54
const protocolPattern = /^(\w{2,}):\/\//i;
65
const jsonPointerSlash = /~1/g;
@@ -9,7 +8,6 @@ const jsonPointerTilde = /~0/g;
98
import { join } from "path";
109
import { isWindows } from "./is-windows";
1110

12-
const projectDir = join(__dirname, "..", "..");
1311
// RegExp patterns to URL-encode special characters in local filesystem paths
1412
const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
1513

@@ -183,12 +181,13 @@ export function fromFileSystemPath(path: any) {
183181
// Step 1: On Windows, replace backslashes with forward slashes,
184182
// rather than encoding them as "%5C"
185183
if (isWindows()) {
184+
const projectDir = join(__dirname, "..", "..");
186185
const upperPath = path.toUpperCase();
187186
const projectDirPosixPath = convertPathToPosix(projectDir);
188187
const posixUpper = projectDirPosixPath.toUpperCase();
189188
const hasProjectDir = upperPath.includes(posixUpper);
190189
const hasProjectUri = upperPath.includes(posixUpper);
191-
const isAbsolutePath = win32.isAbsolute(path);
190+
const isAbsolutePath = path?.win32?.isAbsolute(path);
192191

193192
if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
194193
path = join(projectDir, path);

0 commit comments

Comments
 (0)