@@ -74,14 +74,42 @@ export function dirContains(dir: string, file: string): boolean {
74
74
}
75
75
76
76
const WIN_DRIVE_LETTER = / ^ ( [ a - z A - Z ] ) : /
77
+ const POSIX_DRIVE_LETTER = / ^ \/ ( [ a - z A - Z ] ) : /
77
78
78
79
/**
79
80
* Windows drive letters are case-insensitive and we may get them as either
80
81
* lower or upper case. This function normalizes the drive letter to uppercase
81
82
* to be consistent with the rest of the codebase.
82
83
*/
83
84
export function normalizeDriveLetter ( filepath : string ) {
84
- return filepath . replace ( WIN_DRIVE_LETTER , ( _ , letter ) => letter . toUpperCase ( ) + ':' )
85
+ return filepath
86
+ . replace ( WIN_DRIVE_LETTER , ( _ , letter ) => `${ letter . toUpperCase ( ) } :` )
87
+ . replace ( POSIX_DRIVE_LETTER , ( _ , letter ) => `/${ letter . toUpperCase ( ) } :` )
88
+ }
89
+
90
+ /**
91
+ * Windows drive letters are case-insensitive and we may get them as either
92
+ * lower or upper case.
93
+ *
94
+ * Yarn PnP only works when requests have the correct case for the drive letter
95
+ * that matches the drive letter of the current working directory.
96
+ *
97
+ * Even using makeApi with a custom base path doesn't work around this.
98
+ */
99
+ export function normalizeYarnPnPDriveLetter ( filepath : string ) {
100
+ let cwdDriveLetter = process . cwd ( ) . match ( WIN_DRIVE_LETTER ) ?. [ 1 ]
101
+
102
+ return filepath
103
+ . replace ( WIN_DRIVE_LETTER , ( _ , letter ) => {
104
+ return letter . toUpperCase ( ) === cwdDriveLetter . toUpperCase ( )
105
+ ? `${ cwdDriveLetter } :`
106
+ : `${ letter . toUpperCase ( ) } :`
107
+ } )
108
+ . replace ( POSIX_DRIVE_LETTER , ( _ , letter ) => {
109
+ return letter . toUpperCase ( ) === cwdDriveLetter . toUpperCase ( )
110
+ ? `/${ cwdDriveLetter } :`
111
+ : `/${ letter . toUpperCase ( ) } :`
112
+ } )
85
113
}
86
114
87
115
export function changeAffectsFile ( change : string , files : Iterable < string > ) : boolean {
0 commit comments