1
1
import convertPathToPosix from "./convert-path-to-posix" ;
2
- import path , { win32 } from "path" ;
3
-
2
+ import path from "path" ;
4
3
const forwardSlashPattern = / \/ / g;
5
4
const protocolPattern = / ^ ( \w { 2 , } ) : \/ \/ / i;
6
5
const jsonPointerSlash = / ~ 1 / g;
@@ -9,7 +8,6 @@ const jsonPointerTilde = /~0/g;
9
8
import { join } from "path" ;
10
9
import { isWindows } from "./is-windows" ;
11
10
12
- const projectDir = join ( __dirname , ".." , ".." ) ;
13
11
// RegExp patterns to URL-encode special characters in local filesystem paths
14
12
const urlEncodePatterns = [ / \? / g, "%3F" , / # / g, "%23" ] ;
15
13
@@ -183,12 +181,13 @@ export function fromFileSystemPath(path: any) {
183
181
// Step 1: On Windows, replace backslashes with forward slashes,
184
182
// rather than encoding them as "%5C"
185
183
if ( isWindows ( ) ) {
184
+ const projectDir = join ( __dirname , ".." , ".." ) ;
186
185
const upperPath = path . toUpperCase ( ) ;
187
186
const projectDirPosixPath = convertPathToPosix ( projectDir ) ;
188
187
const posixUpper = projectDirPosixPath . toUpperCase ( ) ;
189
188
const hasProjectDir = upperPath . includes ( posixUpper ) ;
190
189
const hasProjectUri = upperPath . includes ( posixUpper ) ;
191
- const isAbsolutePath = win32 . isAbsolute ( path ) ;
190
+ const isAbsolutePath = path ?. win32 ? .isAbsolute ( path ) ;
192
191
193
192
if ( ! ( hasProjectDir || hasProjectUri || isAbsolutePath ) ) {
194
193
path = join ( projectDir , path ) ;
0 commit comments