Skip to content

Commit a8afbbf

Browse files
committed
merged fixed source map asset into source map asset
1 parent 09a948d commit a8afbbf

File tree

4 files changed

+45
-108
lines changed

4 files changed

+45
-108
lines changed

turbopack/crates/turbopack-core/src/source_map/fixed_source_map_asset.rs

-94
This file was deleted.

turbopack/crates/turbopack-core/src/source_map/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ use crate::{
1818
source_pos::SourcePos, virtual_source::VirtualSource, SOURCE_URL_PROTOCOL,
1919
};
2020

21-
pub(crate) mod fixed_source_map_asset;
2221
pub(crate) mod source_map_asset;
2322
pub mod utils;
2423

25-
pub use fixed_source_map_asset::FixedSourceMapAsset;
2624
pub use source_map_asset::SourceMapAsset;
2725

2826
/// Represents an empty value in a u32 variable in the sourcemap crate.

turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs

+42-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use anyhow::Result;
2+
use serde::{Deserialize, Serialize};
23
use turbo_rcstr::RcStr;
3-
use turbo_tasks::{FxIndexSet, ResolvedVc, ValueToString, Vc};
4+
use turbo_tasks::{
5+
debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexSet, NonLocalValue, ResolvedVc,
6+
ValueToString, Vc,
7+
};
48
use turbo_tasks_fs::{File, FileSystemPath};
59

610
use crate::{
@@ -12,11 +16,21 @@ use crate::{
1216
source_map::{GenerateSourceMap, SourceMap},
1317
};
1418

19+
#[derive(PartialEq, Eq, Serialize, Deserialize, NonLocalValue, TraceRawVcs, ValueDebugFormat)]
20+
enum PathType {
21+
Fixed {
22+
path: ResolvedVc<FileSystemPath>,
23+
},
24+
FromIdent {
25+
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
26+
ident_for_path: ResolvedVc<AssetIdent>,
27+
},
28+
}
29+
1530
/// Represents the source map of an ecmascript asset.
1631
#[turbo_tasks::value]
1732
pub struct SourceMapAsset {
18-
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
19-
ident_for_path: ResolvedVc<AssetIdent>,
33+
path_ty: PathType,
2034
generate_source_map: ResolvedVc<Box<dyn GenerateSourceMap>>,
2135
}
2236

@@ -29,8 +43,22 @@ impl SourceMapAsset {
2943
generate_source_map: ResolvedVc<Box<dyn GenerateSourceMap>>,
3044
) -> Vc<Self> {
3145
SourceMapAsset {
32-
chunking_context,
33-
ident_for_path,
46+
path_ty: PathType::FromIdent {
47+
chunking_context,
48+
ident_for_path,
49+
},
50+
generate_source_map,
51+
}
52+
.cell()
53+
}
54+
55+
#[turbo_tasks::function]
56+
pub fn new_fixed(
57+
path: ResolvedVc<FileSystemPath>,
58+
generate_source_map: ResolvedVc<Box<dyn GenerateSourceMap>>,
59+
) -> Vc<Self> {
60+
SourceMapAsset {
61+
path_ty: PathType::Fixed { path },
3462
generate_source_map,
3563
}
3664
.cell()
@@ -44,10 +72,15 @@ impl OutputAsset for SourceMapAsset {
4472
// NOTE(alexkirsz) We used to include the asset's version id in the path,
4573
// but this caused `all_assets_map` to be recomputed on every change.
4674
let this = self.await?;
47-
Ok(this
48-
.chunking_context
49-
.chunk_path(*this.ident_for_path, ".js".into())
50-
.append(".map".into()))
75+
Ok(match this.path_ty {
76+
PathType::FromIdent {
77+
chunking_context,
78+
ident_for_path,
79+
} => chunking_context
80+
.chunk_path(*ident_for_path, ".js".into())
81+
.append(".map".into()),
82+
PathType::Fixed { path } => path.append(".map".into()),
83+
})
5184
}
5285
}
5386

turbopack/crates/turbopack-nodejs/src/ecmascript/node/entry/chunk.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use turbopack_core::{
1111
code_builder::{Code, CodeBuilder},
1212
module_graph::ModuleGraph,
1313
output::{OutputAsset, OutputAssets},
14-
source_map::{FixedSourceMapAsset, GenerateSourceMap, OptionStringifiedSourceMap},
14+
source_map::{GenerateSourceMap, OptionStringifiedSourceMap, SourceMapAsset},
1515
};
1616
use turbopack_ecmascript::{chunk::EcmascriptChunkPlaceable, utils::StringifyJs};
1717

@@ -150,9 +150,9 @@ impl EcmascriptBuildNodeEntryChunk {
150150
}
151151

152152
#[turbo_tasks::function]
153-
async fn source_map(self: Vc<Self>) -> Result<Vc<FixedSourceMapAsset>> {
153+
async fn source_map(self: Vc<Self>) -> Result<Vc<SourceMapAsset>> {
154154
let this = self.await?;
155-
Ok(FixedSourceMapAsset::new(*this.path, Vc::upcast(self)))
155+
Ok(SourceMapAsset::new_fixed(*this.path, Vc::upcast(self)))
156156
}
157157
}
158158

0 commit comments

Comments
 (0)