From 1d608ef109f32d3cbb7f2232a5fcd8e25f2164fa Mon Sep 17 00:00:00 2001 From: bvanjoi Date: Fri, 24 Jun 2022 16:19:03 +0800 Subject: [PATCH] release: 0.0.9 --- Cargo.toml | 2 +- index.d.ts | 2 +- package.json | 2 +- src/lib.rs | 28 +++++++++++++--------------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba378b3..5dad98f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] napi = "2" napi-derive = "2" -nodejs-resolver = "0.0.18" +nodejs-resolver = "0.0.19" serde = { version = "1.0.137", features = ["derive"] } [build-dependencies] diff --git a/index.d.ts b/index.d.ts index e579296..f078fbc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ export interface RawResolverOptions { aliasFields?: Array conditionNames?: Array symlinks?: boolean - descriptionFile?: string + descriptionFile?: string | undefined | null mainFiles?: Array mainFields?: Array modules?: Array diff --git a/package.json b/package.json index 61a6b66..b510f1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-resolver", - "version": "0.0.8", + "version": "0.0.9", "description": "node binding for nodejs-resolver", "main": "index.js", "license": "MIT", diff --git a/src/lib.rs b/src/lib.rs index 8cd797c..5833de6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,9 @@ use napi::bindgen_prelude::External; use napi_derive::napi; use nodejs_resolver::{AliasMap, Resolver, ResolverOptions}; use serde::Deserialize; -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, +}; #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] @@ -22,7 +24,7 @@ pub struct RawResolverOptions { pub alias_fields: Option>, pub condition_names: Option>, pub symlinks: Option, - pub description_file: Option, + pub description_file: Option>, pub main_files: Option>, pub main_fields: Option>, pub modules: Option>, @@ -37,17 +39,17 @@ impl RawResolverOptions { ResolverOptions { enforce_extension: self.enforce_extension.to_owned(), extensions: self.extensions.to_owned().unwrap_or(default.extensions), - alias: self - .alias - .to_owned() - .map_or(default.alias, parse_alias), + alias: self.alias.to_owned().map_or(default.alias, parse_alias), alias_fields: self.alias_fields.to_owned().unwrap_or(default.alias_fields), condition_names: self .condition_names .to_owned() .map_or(default.condition_names, |vec| vec.into_iter().collect()), symlinks: self.symlinks.unwrap_or(default.symlinks), - description_file: self.description_file.to_owned(), + description_file: self + .description_file + .to_owned() + .unwrap_or(default.description_file), main_files: self.main_files.to_owned().unwrap_or(default.main_files), main_fields: self.main_fields.to_owned().unwrap_or(default.main_fields), prefer_relative: self.prefer_relative.unwrap_or(default.prefer_relative), @@ -55,10 +57,7 @@ impl RawResolverOptions { .enable_unsafe_cache .to_owned() .unwrap_or(default.enable_unsafe_cache), - tsconfig: self - .tsconfig_path - .to_owned() - .map(PathBuf::from), + tsconfig: self.tsconfig_path.to_owned().map(PathBuf::from), } } } @@ -69,9 +68,7 @@ fn parse_alias(alias: Vec) -> Vec<(String, AliasMap)> { .map(|item| { ( item.key, - item - .value - .map_or(AliasMap::Ignored, AliasMap::Target), + item.value.map_or(AliasMap::Ignored, AliasMap::Target), ) }) .collect() @@ -82,7 +79,8 @@ pub struct ResolverInternal {} #[napi(ts_return_type = "ExternalObject")] pub fn create(options: RawResolverOptions) -> Result, napi::Error> { - let resolver = Resolver::new(options.normalized()); + let options = options.normalized(); + let resolver = Resolver::new(options); Ok(External::new(resolver)) }