1
1
use anyhow:: Result ;
2
+ use serde:: { Deserialize , Serialize } ;
2
3
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
+ } ;
4
8
use turbo_tasks_fs:: { File , FileSystemPath } ;
5
9
6
10
use crate :: {
@@ -12,11 +16,21 @@ use crate::{
12
16
source_map:: { GenerateSourceMap , SourceMap } ,
13
17
} ;
14
18
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
+
15
30
/// Represents the source map of an ecmascript asset.
16
31
#[ turbo_tasks:: value]
17
32
pub struct SourceMapAsset {
18
- chunking_context : ResolvedVc < Box < dyn ChunkingContext > > ,
19
- ident_for_path : ResolvedVc < AssetIdent > ,
33
+ path_ty : PathType ,
20
34
generate_source_map : ResolvedVc < Box < dyn GenerateSourceMap > > ,
21
35
}
22
36
@@ -29,8 +43,22 @@ impl SourceMapAsset {
29
43
generate_source_map : ResolvedVc < Box < dyn GenerateSourceMap > > ,
30
44
) -> Vc < Self > {
31
45
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 } ,
34
62
generate_source_map,
35
63
}
36
64
. cell ( )
@@ -44,10 +72,15 @@ impl OutputAsset for SourceMapAsset {
44
72
// NOTE(alexkirsz) We used to include the asset's version id in the path,
45
73
// but this caused `all_assets_map` to be recomputed on every change.
46
74
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
+ } )
51
84
}
52
85
}
53
86
0 commit comments