Unverified Commit b40778b3 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

fix(turbopack): Backport sourcemap bugfix (#78881)

https://github.com/vercel/next.js/pull/78453 is a bugfix for sourcemap on windows
parent 20f31203
......@@ -1278,6 +1278,10 @@ impl FileSystemPath {
/// None when the joined path would leave the filesystem root.
#[turbo_tasks::function]
pub async fn try_join(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
// TODO(PACK-3279): Remove this once we do not produce invalid paths at the first place.
#[cfg(target_os = "windows")]
let path = path.replace('\\', "/");
if let Some(path) = join_path(&self.path, &path) {
Ok(Vc::cell(Some(
Self::new_normalized(*self.fs, path.into())
......
......@@ -138,6 +138,7 @@ pub fn extract_disk_access<T>(value: io::Result<T>, path: &Path) -> Result<Optio
}
}
#[cfg(not(target_os = "windows"))]
pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Result<String> {
let root_fs = root.fs();
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
.join("/")
))
}
#[cfg(target_os = "windows")]
pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Result<String> {
let root_fs = root.fs();
let root_fs = &*Vc::try_resolve_downcast_type::<DiskFileSystem>(root_fs)
.await?
.context("Expected root to have a DiskFileSystem")?
.await?;
let sys_path = root_fs
.to_sys_path(match path {
Some(path) => root.join(path.into()),
None => root,
})
.await?;
let raw_path = sys_path.to_string_lossy().to_string();
let normalized_path = raw_path.replace('\\', "/");
let mut segments = normalized_path.split('/');
let first = segments.next().unwrap_or_default(); // e.g., "C:"
let encoded_path = std::iter::once(first.to_string()) // keep "C:" intact
.chain(segments.map(|s| urlencoding::encode(s).into_owned()))
.collect::<Vec<_>>()
.join("/");
let uri = format!("file:///{}", encoded_path);
Ok(uri)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment