File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
turbopack/crates/turbo-tasks-fs/src Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1278,6 +1278,10 @@ impl FileSystemPath {
1278
1278
/// None when the joined path would leave the filesystem root.
1279
1279
#[ turbo_tasks:: function]
1280
1280
pub async fn try_join ( & self , path : RcStr ) -> Result < Vc < FileSystemPathOption > > {
1281
+ // TODO(PACK-3279): Remove this once we do not produce invalid paths at the first place.
1282
+ #[ cfg( target_os = "windows" ) ]
1283
+ let path = path. replace ( '\\' , "/" ) ;
1284
+
1281
1285
if let Some ( path) = join_path ( & self . path , & path) {
1282
1286
Ok ( Vc :: cell ( Some (
1283
1287
Self :: new_normalized ( * self . fs , path. into ( ) )
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ pub fn extract_disk_access<T>(value: io::Result<T>, path: &Path) -> Result<Optio
138
138
}
139
139
}
140
140
141
+ #[ cfg( not( target_os = "windows" ) ) ]
141
142
pub async fn uri_from_file ( root : Vc < FileSystemPath > , path : Option < & str > ) -> Result < String > {
142
143
let root_fs = root. fs ( ) ;
143
144
let root_fs = & * Vc :: try_resolve_downcast_type :: < DiskFileSystem > ( root_fs)
@@ -162,3 +163,34 @@ pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Resu
162
163
. join( "/" )
163
164
) )
164
165
}
166
+
167
+ #[ cfg( target_os = "windows" ) ]
168
+ pub async fn uri_from_file ( root : Vc < FileSystemPath > , path : Option < & str > ) -> Result < String > {
169
+ let root_fs = root. fs ( ) ;
170
+ let root_fs = & * Vc :: try_resolve_downcast_type :: < DiskFileSystem > ( root_fs)
171
+ . await ?
172
+ . context ( "Expected root to have a DiskFileSystem" ) ?
173
+ . await ?;
174
+
175
+ let sys_path = root_fs
176
+ . to_sys_path ( match path {
177
+ Some ( path) => root. join ( path. into ( ) ) ,
178
+ None => root,
179
+ } )
180
+ . await ?;
181
+
182
+ let raw_path = sys_path. to_string_lossy ( ) . to_string ( ) ;
183
+ let normalized_path = raw_path. replace ( '\\' , "/" ) ;
184
+
185
+ let mut segments = normalized_path. split ( '/' ) ;
186
+
187
+ let first = segments. next ( ) . unwrap_or_default ( ) ; // e.g., "C:"
188
+ let encoded_path = std:: iter:: once ( first. to_string ( ) ) // keep "C:" intact
189
+ . chain ( segments. map ( |s| urlencoding:: encode ( s) . into_owned ( ) ) )
190
+ . collect :: < Vec < _ > > ( )
191
+ . join ( "/" ) ;
192
+
193
+ let uri = format ! ( "file:///{}" , encoded_path) ;
194
+
195
+ Ok ( uri)
196
+ }
You can’t perform that action at this time.
0 commit comments