Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Feb 7, 2025
1 parent 0ac3071 commit 59f5845
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
29 changes: 20 additions & 9 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ use turbo_tasks::{
UpdateInfo, Vc,
};
use turbo_tasks_fs::{
get_relative_path_to, util::uri_from_file, DiskFileSystem, FileContent, FileSystem,
get_relative_path_to, rope::Rope, util::uri_from_file, DiskFileSystem, FileContent, FileSystem,
FileSystemPath,
};
use turbopack_core::{
diagnostics::PlainDiagnostic,
error::PrettyPrintError,
issue::PlainIssue,
source_map::{SourceMap, Token},
source_map::{OptionSourceMap, OptionStringifiedSourceMap, SourceMap, Token},
version::{PartialUpdate, TotalUpdate, Update, VersionState},
SOURCE_MAP_PREFIX,
};
Expand Down Expand Up @@ -1113,10 +1113,10 @@ pub struct StackFrame {
pub method_name: Option<String>,
}

pub async fn get_source_map(
pub async fn get_source_map_rope(
container: Vc<ProjectContainer>,
file_path: String,
) -> Result<Option<ResolvedVc<SourceMap>>> {
) -> Result<Option<Rope>> {
let (file, module) = match Url::parse(&file_path) {
Ok(url) => match url.scheme() {
"file" => {
Expand Down Expand Up @@ -1165,8 +1165,20 @@ pub async fn get_source_map(
map = container.get_source_map(client_path, module).await?;
}

let map = map.context("chunk/module is missing a sourcemap")?;
Ok(Some(
map.clone_value()
.context("chunk/module is missing a sourcemap")?,
))
}

pub async fn get_source_map(
container: Vc<ProjectContainer>,
file_path: String,
) -> Result<Option<SourceMap>> {
let Some(map) = get_source_map_rope(container, file_path).await? else {
return Ok(None);
};
let map = SourceMap::new_from_rope(&map)?.context("chunk/module is missing a sourcemap")?;
Ok(Some(map))
}

Expand Down Expand Up @@ -1195,7 +1207,7 @@ pub async fn project_trace_source(
)
.await?;

let (original_file, line, column, name) = match &*token {
let (original_file, line, column, name) = match token {
Token::Original(token) => (
urlencoding::decode(&token.original_file)?.into_owned(),
// JS stack frames are 1-indexed, source map tokens are 0-indexed
Expand Down Expand Up @@ -1307,11 +1319,10 @@ pub async fn project_get_source_map(

let source_map = turbo_tasks
.run_once(async move {
let Some(map) = get_source_map(container, file_path).await? else {
let Some(map) = get_source_map_rope(container, file_path).await? else {
return Ok(None);
};

Ok(Some(map.to_rope().await?.to_str()?.into_owned()))
Ok(Some(map.to_str()?.to_string()))
})
.await
.map_err(|e| napi::Error::from_reason(PrettyPrintError(&e).to_string()))?;
Expand Down
6 changes: 3 additions & 3 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use turbopack_core::{
module_graph::{ModuleGraph, SingleModuleGraph, VisitedModules},
output::{OutputAsset, OutputAssets},
resolve::{find_context_file, FindContextFileResult},
source_map::OptionSourceMap,
source_map::{OptionSourceMap, OptionStringifiedSourceMap},
version::{
NotFoundVersion, OptionVersionedContent, Update, Version, VersionState, VersionedContent,
},
Expand Down Expand Up @@ -493,11 +493,11 @@ impl ProjectContainer {
&self,
file_path: Vc<FileSystemPath>,
section: Option<RcStr>,
) -> Vc<OptionSourceMap> {
) -> Vc<OptionStringifiedSourceMap> {
if let Some(map) = self.versioned_content_map {
map.get_source_map(file_path, section)
} else {
OptionSourceMap::none()
OptionStringifiedSourceMap::none()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/versioned_content_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
asset::Asset,
output::{OptionOutputAsset, OutputAsset, OutputAssets},
source_map::{GenerateSourceMap, OptionSourceMap},
source_map::{GenerateSourceMap, OptionSourceMap, OptionStringifiedSourceMap},
version::OptionVersionedContent,
};

Expand Down Expand Up @@ -189,7 +189,7 @@ impl VersionedContentMap {
self: Vc<Self>,
path: Vc<FileSystemPath>,
section: Option<RcStr>,
) -> Result<Vc<OptionSourceMap>> {
) -> Result<Vc<OptionStringifiedSourceMap>> {
let Some(asset) = &*self.get_asset(path).await? else {
return Ok(Vc::cell(None));
};
Expand Down

0 comments on commit 59f5845

Please sign in to comment.