Skip to content

Commit

Permalink
Merge pull request #14 from bvanjoi/next
Browse files Browse the repository at this point in the history
release: 0.0.9
  • Loading branch information
bvanjoi authored Jun 24, 2022
2 parents 2b39741 + 1d608ef commit 1ae147c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface RawResolverOptions {
aliasFields?: Array<string>
conditionNames?: Array<string>
symlinks?: boolean
descriptionFile?: string
descriptionFile?: string | undefined | null
mainFiles?: Array<string>
mainFields?: Array<string>
modules?: Array<string>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
28 changes: 13 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -22,7 +24,7 @@ pub struct RawResolverOptions {
pub alias_fields: Option<Vec<String>>,
pub condition_names: Option<Vec<String>>,
pub symlinks: Option<bool>,
pub description_file: Option<String>,
pub description_file: Option<Option<String>>,
pub main_files: Option<Vec<String>>,
pub main_fields: Option<Vec<String>>,
pub modules: Option<Vec<String>>,
Expand All @@ -37,28 +39,25 @@ 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),
enable_unsafe_cache: self
.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),
}
}
}
Expand All @@ -69,9 +68,7 @@ fn parse_alias(alias: Vec<Alias>) -> Vec<(String, AliasMap)> {
.map(|item| {
(
item.key,
item
.value
.map_or(AliasMap::Ignored, AliasMap::Target),
item.value.map_or(AliasMap::Ignored, AliasMap::Target),
)
})
.collect()
Expand All @@ -82,7 +79,8 @@ pub struct ResolverInternal {}

#[napi(ts_return_type = "ExternalObject<ResolverInternal>")]
pub fn create(options: RawResolverOptions) -> Result<External<Resolver>, napi::Error> {
let resolver = Resolver::new(options.normalized());
let options = options.normalized();
let resolver = Resolver::new(options);
Ok(External::new(resolver))
}

Expand Down

0 comments on commit 1ae147c

Please sign in to comment.