Skip to content

Commit

Permalink
fix(win32): use optional win32 for apis where it is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Mar 6, 2024
1 parent b2dff0e commit c9da8a4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/util/url.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import convertPathToPosix from "./convert-path-to-posix";
import path, { win32 } from "path";

import path from "path";
const forwardSlashPattern = /\//g;
const protocolPattern = /^(\w{2,}):\/\//i;
const jsonPointerSlash = /~1/g;
Expand All @@ -9,7 +8,6 @@ const jsonPointerTilde = /~0/g;
import { join } from "path";
import { isWindows } from "./is-windows";

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

Expand Down Expand Up @@ -183,12 +181,13 @@ export function fromFileSystemPath(path: any) {
// Step 1: On Windows, replace backslashes with forward slashes,
// rather than encoding them as "%5C"
if (isWindows()) {
const projectDir = join(__dirname, "..", "..");
const upperPath = path.toUpperCase();
const projectDirPosixPath = convertPathToPosix(projectDir);
const posixUpper = projectDirPosixPath.toUpperCase();
const hasProjectDir = upperPath.includes(posixUpper);
const hasProjectUri = upperPath.includes(posixUpper);
const isAbsolutePath = win32.isAbsolute(path);
const isAbsolutePath = path?.win32?.isAbsolute(path);

if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
path = join(projectDir, path);
Expand Down

0 comments on commit c9da8a4

Please sign in to comment.