@@ -73,7 +73,10 @@ use std::collections::HashMap;
73
73
use std:: collections:: HashSet ;
74
74
use std:: collections:: VecDeque ;
75
75
use std:: fmt;
76
+ use std:: path:: Path ;
76
77
use std:: sync:: Arc ;
78
+ use sys_traits:: FileType ;
79
+ use sys_traits:: FsDirEntry ;
77
80
use thiserror:: Error ;
78
81
use url:: Url ;
79
82
use wasm:: wasm_module_to_dts;
@@ -1207,7 +1210,6 @@ pub struct BuildFastCheckTypeGraphOptions<'a> {
1207
1210
pub workspace_fast_check : WorkspaceFastCheckOption < ' a > ,
1208
1211
}
1209
1212
1210
- #[ derive( Default ) ]
1211
1213
pub struct BuildOptions < ' a > {
1212
1214
pub is_dynamic : bool ,
1213
1215
/// Additional imports that should be brought into the scope of
@@ -1217,7 +1219,7 @@ pub struct BuildOptions<'a> {
1217
1219
pub imports : Vec < ReferrerImports > ,
1218
1220
pub executor : & ' a dyn Executor ,
1219
1221
pub locker : Option < & ' a mut dyn Locker > ,
1220
- pub file_system : & ' a dyn FileSystem ,
1222
+ pub file_system : & ' a FileSystem ,
1221
1223
pub jsr_url_provider : & ' a dyn JsrUrlProvider ,
1222
1224
/// Whether to pass through JSR specifiers to the resolver instead of
1223
1225
/// resolving them. This is useful in cases where you want to mark JSR
@@ -1229,6 +1231,24 @@ pub struct BuildOptions<'a> {
1229
1231
pub resolver : Option < & ' a dyn Resolver > ,
1230
1232
}
1231
1233
1234
+ impl < ' a > Default for BuildOptions < ' a > {
1235
+ fn default ( ) -> Self {
1236
+ Self {
1237
+ is_dynamic : false ,
1238
+ imports : Default :: default ( ) ,
1239
+ executor : Default :: default ( ) ,
1240
+ locker : None ,
1241
+ file_system : & NullFileSystem ,
1242
+ jsr_url_provider : Default :: default ( ) ,
1243
+ passthrough_jsr_specifiers : false ,
1244
+ module_analyzer : Default :: default ( ) ,
1245
+ npm_resolver : None ,
1246
+ reporter : None ,
1247
+ resolver : None ,
1248
+ }
1249
+ }
1250
+ }
1251
+
1232
1252
#[ derive( Debug , Copy , Clone ) ]
1233
1253
pub enum ModuleEntryRef < ' a > {
1234
1254
Module ( & ' a Module ) ,
@@ -2433,7 +2453,7 @@ pub(crate) struct ParseModuleOptions {
2433
2453
/// With the provided information, parse a module and return its "module slot"
2434
2454
#[ allow( clippy:: result_large_err) ]
2435
2455
pub ( crate ) fn parse_module (
2436
- file_system : & dyn FileSystem ,
2456
+ file_system : & FileSystem ,
2437
2457
jsr_url_provider : & dyn JsrUrlProvider ,
2438
2458
maybe_resolver : Option < & dyn Resolver > ,
2439
2459
maybe_npm_resolver : Option < & dyn NpmResolver > ,
@@ -2493,7 +2513,7 @@ pub(crate) fn parse_js_module_from_module_info(
2493
2513
maybe_headers : Option < & HashMap < String , String > > ,
2494
2514
module_info : ModuleInfo ,
2495
2515
source : Arc < str > ,
2496
- file_system : & dyn FileSystem ,
2516
+ file_system : & FileSystem ,
2497
2517
jsr_url_provider : & dyn JsrUrlProvider ,
2498
2518
maybe_resolver : Option < & dyn Resolver > ,
2499
2519
maybe_npm_resolver : Option < & dyn NpmResolver > ,
@@ -2847,7 +2867,7 @@ fn parse_wasm_module_from_module_info(
2847
2867
module_info : ModuleInfo ,
2848
2868
source : Arc < [ u8 ] > ,
2849
2869
source_dts : Arc < str > ,
2850
- file_system : & dyn FileSystem ,
2870
+ file_system : & FileSystem ,
2851
2871
jsr_url_provider : & dyn JsrUrlProvider ,
2852
2872
maybe_resolver : Option < & dyn Resolver > ,
2853
2873
maybe_npm_resolver : Option < & dyn NpmResolver > ,
@@ -2880,7 +2900,7 @@ fn fill_module_dependencies(
2880
2900
dependencies : Vec < DependencyDescriptor > ,
2881
2901
module_specifier : & ModuleSpecifier ,
2882
2902
module_dependencies : & mut IndexMap < String , Dependency > ,
2883
- file_system : & dyn FileSystem ,
2903
+ file_system : & FileSystem ,
2884
2904
jsr_url_provider : & dyn JsrUrlProvider ,
2885
2905
maybe_resolver : Option < & dyn Resolver > ,
2886
2906
maybe_npm_resolver : Option < & dyn NpmResolver > ,
@@ -3079,7 +3099,7 @@ fn analyze_dynamic_arg_template_parts(
3079
3099
referrer : & Url ,
3080
3100
referrer_range : & PositionRange ,
3081
3101
import_attributes : & ImportAttributes ,
3082
- file_system : & dyn FileSystem ,
3102
+ file_system : & FileSystem ,
3083
3103
) -> Vec < String > {
3084
3104
fn resolve_initial_dir_path (
3085
3105
parts : & [ DynamicTemplatePart ] ,
@@ -3169,18 +3189,58 @@ fn analyze_dynamic_arg_template_parts(
3169
3189
if is_fs_root_specifier ( & dir_path) {
3170
3190
return specifiers;
3171
3191
}
3192
+ let Ok ( dir_path) = deno_path_util:: url_to_file_path ( & dir_path) else {
3193
+ return specifiers;
3194
+ } ;
3172
3195
let mut pending_dirs = VecDeque :: from ( [ dir_path] ) ;
3196
+ let handle_err = |path : & Path , err : & std:: io:: Error | {
3197
+ if matches ! (
3198
+ err. kind( ) ,
3199
+ std:: io:: ErrorKind :: PermissionDenied | std:: io:: ErrorKind :: NotFound
3200
+ ) {
3201
+ return ;
3202
+ }
3203
+ // For now, errors are swallowed and not stored in the graph.
3204
+ // If we decide to represent these in the graph, we'll need to
3205
+ // figure out what to do with errors like directory errors.
3206
+ // Additionally, take note that these are dynamic import errors,
3207
+ // so they shouldn't be eagerly surfaced.
3208
+ log:: warn!(
3209
+ "Graph failed resolving '{}'. {:#}\n at {}:{}:{}" ,
3210
+ path. display( ) ,
3211
+ err,
3212
+ referrer,
3213
+ referrer_range. start. line + 1 ,
3214
+ referrer_range. start. character + 1 ,
3215
+ ) ;
3216
+ } ;
3173
3217
while let Some ( dir_path) = pending_dirs. pop_front ( ) {
3174
- let entries = file_system. read_dir ( & dir_path) ;
3218
+ let entries = match file_system. fs_read_dir_boxed ( & dir_path) {
3219
+ Ok ( entries) => entries,
3220
+ Err ( err) => {
3221
+ handle_err ( & dir_path, & err) ;
3222
+ continue ;
3223
+ }
3224
+ } ;
3175
3225
for entry in entries {
3176
- match entry. kind {
3177
- DirEntryKind :: File => {
3178
- let url = & entry. url ;
3179
- if matching_media_types. contains ( & MediaType :: from_specifier ( url) ) {
3180
- if url == referrer {
3226
+ let entry = match entry {
3227
+ Ok ( entry) => entry,
3228
+ Err ( err) => {
3229
+ handle_err ( & dir_path, & err) ;
3230
+ continue ;
3231
+ }
3232
+ } ;
3233
+ let path = entry. path ( ) ;
3234
+ match entry. file_type ( ) {
3235
+ Ok ( FileType :: File ) => {
3236
+ let Ok ( url) = deno_path_util:: url_from_file_path ( & path) else {
3237
+ continue ;
3238
+ } ;
3239
+ if matching_media_types. contains ( & MediaType :: from_specifier ( & url) ) {
3240
+ if url == * referrer {
3181
3241
continue ; // found itself, so skip
3182
3242
}
3183
- if let Some ( specifier) = referrer. make_relative ( url) {
3243
+ if let Some ( specifier) = referrer. make_relative ( & url) {
3184
3244
let specifier = if !specifier. starts_with ( "../" ) {
3185
3245
format ! ( "./{}" , specifier)
3186
3246
} else {
@@ -3210,38 +3270,25 @@ fn analyze_dynamic_arg_template_parts(
3210
3270
}
3211
3271
}
3212
3272
}
3213
- DirEntryKind :: Dir => {
3273
+ Ok ( FileType :: Dir ) => {
3214
3274
// ignore hidden directories and any node_modules/vendor folders
3215
- let is_allowed_dir = entry
3216
- . url
3217
- . path ( )
3218
- . rsplit ( '/' )
3219
- . find ( |c| !c. is_empty ( ) )
3275
+ let is_allowed_dir = path
3276
+ . file_name ( )
3220
3277
. map ( |c| {
3221
- !c. starts_with ( '.' ) && c != "node_modules" && c != "vendor"
3278
+ !c. to_string_lossy ( ) . starts_with ( '.' )
3279
+ && c != "node_modules"
3280
+ && c != "vendor"
3222
3281
} )
3223
3282
. unwrap_or ( true ) ;
3224
3283
if is_allowed_dir {
3225
- pending_dirs. push_back ( entry . url ) ;
3284
+ pending_dirs. push_back ( path . into_owned ( ) ) ;
3226
3285
}
3227
3286
}
3228
- DirEntryKind :: Symlink => {
3287
+ Ok ( _ ) => {
3229
3288
// ignore
3230
3289
}
3231
- DirEntryKind :: Error ( err) => {
3232
- // For now, errors are swallowed and not stored in the graph.
3233
- // If we decide to represent these in the graph, we'll need to
3234
- // figure out what to do with errors like directory errors.
3235
- // Additionally, take note that these are dynamic import errors,
3236
- // so they shouldn't be eagerly surfaced.
3237
- log:: warn!(
3238
- "Graph failed resolving '{}'. {:#}\n at {}:{}:{}" ,
3239
- entry. url,
3240
- err,
3241
- referrer,
3242
- referrer_range. start. line + 1 ,
3243
- referrer_range. start. character + 1 ,
3244
- ) ;
3290
+ Err ( err) => {
3291
+ handle_err ( & path, & err) ;
3245
3292
}
3246
3293
} ;
3247
3294
}
@@ -3466,7 +3513,7 @@ impl FillPassMode {
3466
3513
struct Builder < ' a , ' graph > {
3467
3514
in_dynamic_branch : bool ,
3468
3515
was_dynamic_root : bool ,
3469
- file_system : & ' a dyn FileSystem ,
3516
+ file_system : & ' a FileSystem ,
3470
3517
jsr_url_provider : & ' a dyn JsrUrlProvider ,
3471
3518
passthrough_jsr_specifiers : bool ,
3472
3519
loader : & ' a dyn Loader ,
0 commit comments