Skip to content

Commit b40778b

Browse files
authored
fix(turbopack): Backport sourcemap bugfix (#78881)
#78453 is a bugfix for sourcemap on windows
1 parent 20f3120 commit b40778b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,10 @@ impl FileSystemPath {
12781278
/// None when the joined path would leave the filesystem root.
12791279
#[turbo_tasks::function]
12801280
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+
12811285
if let Some(path) = join_path(&self.path, &path) {
12821286
Ok(Vc::cell(Some(
12831287
Self::new_normalized(*self.fs, path.into())

turbopack/crates/turbo-tasks-fs/src/util.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub fn extract_disk_access<T>(value: io::Result<T>, path: &Path) -> Result<Optio
138138
}
139139
}
140140

141+
#[cfg(not(target_os = "windows"))]
141142
pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Result<String> {
142143
let root_fs = root.fs();
143144
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
162163
.join("/")
163164
))
164165
}
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+
}

0 commit comments

Comments
 (0)