Skip to content

Commit c42d0e3

Browse files
authored
Turbopack: decode url encoding and relative paths in source maps (#86342)
### What? decode url encoding and relative paths in source maps
1 parent 2300bb2 commit c42d0e3

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/bundle-analyzer/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"**/*.ts",
2828
"**/*.tsx",
2929
".next/types/**/*.ts",
30-
".next/dev/types/**/*.ts"
30+
".next/dev/types/**/*.ts",
31+
"dist/types/**/*.ts",
32+
"dist/dev/types/**/*.ts"
3133
],
3234
"exclude": ["node_modules"]
3335
}

crates/next-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ turbopack-ecmascript = { workspace = true }
4040
turbopack-node = { workspace = true }
4141
turbopack-nodejs = { workspace = true }
4242
turbopack-wasm = { workspace = true }
43+
urlencoding = { workspace = true }
4344

4445
[dev-dependencies]
4546
turbo-tasks-malloc = { workspace = true }

crates/next-api/src/analyze.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::Write;
1+
use std::{borrow::Cow, io::Write};
22

33
use anyhow::Result;
44
use byteorder::{BE, WriteBytesExt};
@@ -23,7 +23,7 @@ use turbopack_core::{
2323
reference::all_assets_from_entries,
2424
};
2525

26-
use crate::route::{Endpoint, ModuleGraphs};
26+
use crate::route::ModuleGraphs;
2727

2828
#[derive(
2929
Default, Clone, Debug, Deserialize, Eq, NonLocalValue, PartialEq, Serialize, TraceRawVcs,
@@ -371,9 +371,16 @@ pub async fn analyze_output_assets(output_assets: Vc<OutputAssets>) -> Result<Vc
371371
let output_file_index = builder.add_output_file(AnalyzeOutputFile { filename });
372372
let chunk_parts = split_output_asset_into_parts(*asset).await?;
373373
for chunk_part in chunk_parts {
374-
let source_index = builder
375-
.ensure_source(chunk_part.source.trim_start_matches(&prefix))
376-
.1;
374+
let decoded_source = urlencoding::decode(&chunk_part.source)?;
375+
let source = if let Some(stripped) = decoded_source.strip_prefix(&prefix) {
376+
Cow::Borrowed(stripped)
377+
} else {
378+
Cow::Owned(format!(
379+
"[project]/{}",
380+
decoded_source.trim_start_matches("../")
381+
))
382+
};
383+
let source_index = builder.ensure_source(&source).1;
377384
let chunk_part_index = builder.add_chunk_part(AnalyzeChunkPart {
378385
source_index,
379386
output_file_index,
@@ -533,13 +540,6 @@ pub async fn analyze_module_graphs(module_graphs: Vc<ModuleGraphs>) -> Result<Vc
533540
Ok(FileContent::Content(File::from(rope)).cell())
534541
}
535542

536-
#[turbo_tasks::function]
537-
pub async fn analyze_endpoint(endpoint: Vc<Box<dyn Endpoint>>) -> Result<Vc<FileContent>> {
538-
Ok(analyze_output_assets(
539-
*endpoint.output().await?.output_assets,
540-
))
541-
}
542-
543543
#[turbo_tasks::value]
544544
pub struct AnalyzeDataOutputAsset {
545545
pub path: FileSystemPath,
@@ -549,10 +549,13 @@ pub struct AnalyzeDataOutputAsset {
549549
#[turbo_tasks::value_impl]
550550
impl AnalyzeDataOutputAsset {
551551
#[turbo_tasks::function]
552-
pub async fn new(path: FileSystemPath, output_assets: Vc<OutputAssets>) -> Result<Vc<Self>> {
552+
pub async fn new(
553+
path: FileSystemPath,
554+
output_assets: ResolvedVc<OutputAssets>,
555+
) -> Result<Vc<Self>> {
553556
Ok(Self {
554557
path,
555-
output_assets: output_assets.to_resolved().await?,
558+
output_assets,
556559
}
557560
.cell())
558561
}

0 commit comments

Comments
 (0)