@@ -37,18 +37,18 @@ pub async fn compile(
37
37
let binary_writer = factory. create_compile_binary_writer ( ) . await ?;
38
38
let http_client = factory. http_client_provider ( ) ;
39
39
let entrypoint = cli_options. resolve_main_module ( ) ?;
40
- let ( module_roots, include_files) = get_module_roots_and_include_files (
41
- entrypoint,
42
- & compile_flags,
43
- cli_options. initial_cwd ( ) ,
44
- ) ?;
45
-
46
40
let output_path = resolve_compile_executable_output_path (
47
41
http_client,
48
42
& compile_flags,
49
43
cli_options. initial_cwd ( ) ,
50
44
)
51
45
. await ?;
46
+ let ( module_roots, include_files) = get_module_roots_and_include_files (
47
+ entrypoint,
48
+ & url_from_file_path ( & cli_options. initial_cwd ( ) . join ( & output_path) ) ?,
49
+ & compile_flags,
50
+ cli_options. initial_cwd ( ) ,
51
+ ) ?;
52
52
53
53
let graph = Arc :: try_unwrap (
54
54
module_graph_creator
@@ -198,6 +198,7 @@ fn validate_output_path(output_path: &Path) -> Result<(), AnyError> {
198
198
199
199
fn get_module_roots_and_include_files (
200
200
entrypoint : & ModuleSpecifier ,
201
+ output_url : & ModuleSpecifier ,
201
202
compile_flags : & CompileFlags ,
202
203
initial_cwd : & Path ,
203
204
) -> Result < ( Vec < ModuleSpecifier > , Vec < ModuleSpecifier > ) , AnyError > {
@@ -226,9 +227,8 @@ fn get_module_roots_and_include_files(
226
227
227
228
fn analyze_path (
228
229
url : & ModuleSpecifier ,
229
- module_roots : & mut Vec < ModuleSpecifier > ,
230
- include_files : & mut Vec < ModuleSpecifier > ,
231
230
searched_paths : & mut HashSet < PathBuf > ,
231
+ mut add_url : impl FnMut ( ModuleSpecifier ) ,
232
232
) -> Result < ( ) , AnyError > {
233
233
let Ok ( path) = url_to_file_path ( url) else {
234
234
return Ok ( ( ) ) ;
@@ -240,10 +240,7 @@ fn get_module_roots_and_include_files(
240
240
}
241
241
if !path. is_dir ( ) {
242
242
let url = url_from_file_path ( & path) ?;
243
- include_files. push ( url. clone ( ) ) ;
244
- if is_module_graph_module ( & url) {
245
- module_roots. push ( url) ;
246
- }
243
+ add_url ( url) ;
247
244
continue ;
248
245
}
249
246
for entry in std:: fs:: read_dir ( & path) . with_context ( || {
@@ -270,12 +267,14 @@ fn get_module_roots_and_include_files(
270
267
include_files. push ( url) ;
271
268
}
272
269
} else {
273
- analyze_path (
274
- & url,
275
- & mut module_roots,
276
- & mut include_files,
277
- & mut searched_paths,
278
- ) ?;
270
+ analyze_path ( & url, & mut searched_paths, |file_url| {
271
+ if file_url != * output_url {
272
+ include_files. push ( file_url. clone ( ) ) ;
273
+ if is_module_graph_module ( & file_url) {
274
+ module_roots. push ( file_url) ;
275
+ }
276
+ }
277
+ } ) ?;
279
278
}
280
279
}
281
280
Ok ( ( module_roots, include_files) )
0 commit comments