@@ -2,7 +2,9 @@ use napi::bindgen_prelude::External;
2
2
use napi_derive:: napi;
3
3
use nodejs_resolver:: { AliasMap , Resolver , ResolverOptions } ;
4
4
use serde:: Deserialize ;
5
- use std:: path:: { Path , PathBuf } ;
5
+ use std:: {
6
+ path:: { Path , PathBuf } ,
7
+ } ;
6
8
7
9
#[ derive( Debug , Clone , Deserialize ) ]
8
10
#[ serde( rename_all = "camelCase" ) ]
@@ -22,7 +24,7 @@ pub struct RawResolverOptions {
22
24
pub alias_fields : Option < Vec < String > > ,
23
25
pub condition_names : Option < Vec < String > > ,
24
26
pub symlinks : Option < bool > ,
25
- pub description_file : Option < String > ,
27
+ pub description_file : Option < Option < String > > ,
26
28
pub main_files : Option < Vec < String > > ,
27
29
pub main_fields : Option < Vec < String > > ,
28
30
pub modules : Option < Vec < String > > ,
@@ -37,28 +39,25 @@ impl RawResolverOptions {
37
39
ResolverOptions {
38
40
enforce_extension : self . enforce_extension . to_owned ( ) ,
39
41
extensions : self . extensions . to_owned ( ) . unwrap_or ( default. extensions ) ,
40
- alias : self
41
- . alias
42
- . to_owned ( )
43
- . map_or ( default. alias , parse_alias) ,
42
+ alias : self . alias . to_owned ( ) . map_or ( default. alias , parse_alias) ,
44
43
alias_fields : self . alias_fields . to_owned ( ) . unwrap_or ( default. alias_fields ) ,
45
44
condition_names : self
46
45
. condition_names
47
46
. to_owned ( )
48
47
. map_or ( default. condition_names , |vec| vec. into_iter ( ) . collect ( ) ) ,
49
48
symlinks : self . symlinks . unwrap_or ( default. symlinks ) ,
50
- description_file : self . description_file . to_owned ( ) ,
49
+ description_file : self
50
+ . description_file
51
+ . to_owned ( )
52
+ . unwrap_or ( default. description_file ) ,
51
53
main_files : self . main_files . to_owned ( ) . unwrap_or ( default. main_files ) ,
52
54
main_fields : self . main_fields . to_owned ( ) . unwrap_or ( default. main_fields ) ,
53
55
prefer_relative : self . prefer_relative . unwrap_or ( default. prefer_relative ) ,
54
56
enable_unsafe_cache : self
55
57
. enable_unsafe_cache
56
58
. to_owned ( )
57
59
. unwrap_or ( default. enable_unsafe_cache ) ,
58
- tsconfig : self
59
- . tsconfig_path
60
- . to_owned ( )
61
- . map ( PathBuf :: from) ,
60
+ tsconfig : self . tsconfig_path . to_owned ( ) . map ( PathBuf :: from) ,
62
61
}
63
62
}
64
63
}
@@ -69,9 +68,7 @@ fn parse_alias(alias: Vec<Alias>) -> Vec<(String, AliasMap)> {
69
68
. map ( |item| {
70
69
(
71
70
item. key ,
72
- item
73
- . value
74
- . map_or ( AliasMap :: Ignored , AliasMap :: Target ) ,
71
+ item. value . map_or ( AliasMap :: Ignored , AliasMap :: Target ) ,
75
72
)
76
73
} )
77
74
. collect ( )
@@ -82,7 +79,8 @@ pub struct ResolverInternal {}
82
79
83
80
#[ napi( ts_return_type = "ExternalObject<ResolverInternal>" ) ]
84
81
pub fn create ( options : RawResolverOptions ) -> Result < External < Resolver > , napi:: Error > {
85
- let resolver = Resolver :: new ( options. normalized ( ) ) ;
82
+ let options = options. normalized ( ) ;
83
+ let resolver = Resolver :: new ( options) ;
86
84
Ok ( External :: new ( resolver) )
87
85
}
88
86
0 commit comments