@@ -2,7 +2,9 @@ use napi::bindgen_prelude::External;
22use napi_derive:: napi;
33use nodejs_resolver:: { AliasMap , Resolver , ResolverOptions } ;
44use serde:: Deserialize ;
5- use std:: path:: { Path , PathBuf } ;
5+ use std:: {
6+ path:: { Path , PathBuf } ,
7+ } ;
68
79#[ derive( Debug , Clone , Deserialize ) ]
810#[ serde( rename_all = "camelCase" ) ]
@@ -22,7 +24,7 @@ pub struct RawResolverOptions {
2224 pub alias_fields : Option < Vec < String > > ,
2325 pub condition_names : Option < Vec < String > > ,
2426 pub symlinks : Option < bool > ,
25- pub description_file : Option < String > ,
27+ pub description_file : Option < Option < String > > ,
2628 pub main_files : Option < Vec < String > > ,
2729 pub main_fields : Option < Vec < String > > ,
2830 pub modules : Option < Vec < String > > ,
@@ -37,28 +39,25 @@ impl RawResolverOptions {
3739 ResolverOptions {
3840 enforce_extension : self . enforce_extension . to_owned ( ) ,
3941 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) ,
4443 alias_fields : self . alias_fields . to_owned ( ) . unwrap_or ( default. alias_fields ) ,
4544 condition_names : self
4645 . condition_names
4746 . to_owned ( )
4847 . map_or ( default. condition_names , |vec| vec. into_iter ( ) . collect ( ) ) ,
4948 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 ) ,
5153 main_files : self . main_files . to_owned ( ) . unwrap_or ( default. main_files ) ,
5254 main_fields : self . main_fields . to_owned ( ) . unwrap_or ( default. main_fields ) ,
5355 prefer_relative : self . prefer_relative . unwrap_or ( default. prefer_relative ) ,
5456 enable_unsafe_cache : self
5557 . enable_unsafe_cache
5658 . to_owned ( )
5759 . 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) ,
6261 }
6362 }
6463}
@@ -69,9 +68,7 @@ fn parse_alias(alias: Vec<Alias>) -> Vec<(String, AliasMap)> {
6968 . map ( |item| {
7069 (
7170 item. key ,
72- item
73- . value
74- . map_or ( AliasMap :: Ignored , AliasMap :: Target ) ,
71+ item. value . map_or ( AliasMap :: Ignored , AliasMap :: Target ) ,
7572 )
7673 } )
7774 . collect ( )
@@ -82,7 +79,8 @@ pub struct ResolverInternal {}
8279
8380#[ napi( ts_return_type = "ExternalObject<ResolverInternal>" ) ]
8481pub 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) ;
8684 Ok ( External :: new ( resolver) )
8785}
8886
0 commit comments