@@ -28,7 +28,8 @@ use turbo_tasks::{
28
28
get_effects, Completion , Effects , ReadRef , ResolvedVc , TransientInstance , UpdateInfo , Vc ,
29
29
} ;
30
30
use turbo_tasks_fs:: {
31
- util:: uri_from_file, DiskFileSystem , FileContent , FileSystem , FileSystemPath ,
31
+ get_relative_path_to, util:: uri_from_file, DiskFileSystem , FileContent , FileSystem ,
32
+ FileSystemPath ,
32
33
} ;
33
34
use turbopack_core:: {
34
35
diagnostics:: PlainDiagnostic ,
@@ -1015,6 +1016,7 @@ pub fn project_update_info_subscribe(
1015
1016
pub struct StackFrame {
1016
1017
pub is_server : bool ,
1017
1018
pub is_internal : Option < bool > ,
1019
+ pub original_file : Option < String > ,
1018
1020
pub file : String ,
1019
1021
// 1-indexed, unlike source map tokens
1020
1022
pub line : Option < u32 > ,
@@ -1084,6 +1086,7 @@ pub async fn get_source_map(
1084
1086
pub async fn project_trace_source (
1085
1087
#[ napi( ts_arg_type = "{ __napiType: \" Project\" }" ) ] project : External < ProjectInstance > ,
1086
1088
frame : StackFrame ,
1089
+ current_directory_file_url : String ,
1087
1090
) -> napi:: Result < Option < StackFrame > > {
1088
1091
let turbo_tasks = project. turbo_tasks . clone ( ) ;
1089
1092
let container = project. container ;
@@ -1120,27 +1123,50 @@ pub async fn project_trace_source(
1120
1123
}
1121
1124
} ;
1122
1125
1123
- let project_path_uri =
1124
- uri_from_file ( project. container . project ( ) . project_path ( ) , None ) . await ? + "/" ;
1125
- let ( source_file, is_internal) =
1126
- if let Some ( source_file) = original_file. strip_prefix ( & project_path_uri) {
1127
- // Client code uses file://
1128
- ( source_file, false )
1129
- } else if let Some ( source_file) =
1130
- original_file. strip_prefix ( & * SOURCE_MAP_PREFIX_PROJECT )
1131
- {
1132
- // Server code uses turbopack://[project]
1133
- // TODO should this also be file://?
1134
- ( source_file, false )
1135
- } else if let Some ( source_file) = original_file. strip_prefix ( SOURCE_MAP_PREFIX ) {
1136
- // All other code like turbopack://[turbopack] is internal code
1137
- ( source_file, true )
1138
- } else {
1139
- bail ! ( "Original file ({}) outside project" , original_file)
1140
- } ;
1126
+ let project_root_uri =
1127
+ uri_from_file ( project. container . project ( ) . project_root_path ( ) , None ) . await ? + "/" ;
1128
+ let ( file, original_file, is_internal) = if let Some ( source_file) =
1129
+ original_file. strip_prefix ( & project_root_uri)
1130
+ {
1131
+ // Client code uses file://
1132
+ (
1133
+ get_relative_path_to ( & current_directory_file_url, & original_file)
1134
+ // TODO(sokra) remove this to include a ./ here to make it a relative path
1135
+ . trim_start_matches ( "./" )
1136
+ . to_string ( ) ,
1137
+ Some ( source_file. to_string ( ) ) ,
1138
+ false ,
1139
+ )
1140
+ } else if let Some ( source_file) =
1141
+ original_file. strip_prefix ( & * SOURCE_MAP_PREFIX_PROJECT )
1142
+ {
1143
+ // Server code uses turbopack://[project]
1144
+ // TODO should this also be file://?
1145
+ (
1146
+ get_relative_path_to (
1147
+ & current_directory_file_url,
1148
+ & format ! ( "{}{}" , project_root_uri, source_file) ,
1149
+ )
1150
+ // TODO(sokra) remove this to include a ./ here to make it a relative path
1151
+ . trim_start_matches ( "./" )
1152
+ . to_string ( ) ,
1153
+ Some ( source_file. to_string ( ) ) ,
1154
+ false ,
1155
+ )
1156
+ } else if let Some ( source_file) = original_file. strip_prefix ( SOURCE_MAP_PREFIX ) {
1157
+ // All other code like turbopack://[turbopack] is internal code
1158
+ ( source_file. to_string ( ) , None , true )
1159
+ } else {
1160
+ bail ! (
1161
+ "Original file ({}) outside project ({})" ,
1162
+ original_file,
1163
+ project_root_uri
1164
+ )
1165
+ } ;
1141
1166
1142
1167
Ok ( Some ( StackFrame {
1143
- file : source_file. to_string ( ) ,
1168
+ file,
1169
+ original_file,
1144
1170
method_name : name. as_ref ( ) . map ( ToString :: to_string) ,
1145
1171
line,
1146
1172
column,
0 commit comments