Skip to content

Commit

Permalink
Merge pull request #22 from bvanjoi/next
Browse files Browse the repository at this point in the history
release: 0.0.17
  • Loading branch information
bvanjoi authored Jul 4, 2022
2 parents f805209 + de8fa68 commit 73aa3ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 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.25"
nodejs-resolver = "0.0.26"
serde = { version = "1.0.137", features = ["derive"] }

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export interface ResolverInternal {

}
export function create(options: RawResolverOptions): ExternalObject<ResolverInternal>
export function createResolverAndInheritUnsafeCacheFromAnother(options: RawResolverOptions, another: ExternalObject<Resolver>): ExternalObject<ResolverInternal>
export function resolve(resolver: ExternalObject<ResolverInternal>, base_dir: string, id: string): string
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { create, resolve } = nativeBinding
const { create, createResolverAndInheritUnsafeCacheFromAnother, resolve } = nativeBinding

module.exports.create = create
module.exports.createResolverAndInheritUnsafeCacheFromAnother = createResolverAndInheritUnsafeCacheFromAnother
module.exports.resolve = resolve
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.16",
"version": "0.0.17",
"description": "node binding for nodejs-resolver",
"main": "index.js",
"license": "MIT",
Expand Down
26 changes: 20 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use napi::bindgen_prelude::External;
use napi_derive::napi;
use nodejs_resolver::{AliasMap, Resolver, ResolverOptions};
use nodejs_resolver::{AliasMap, Resolver, ResolverOptions, ResolverUnsafeCache};
use serde::Deserialize;
use std::path::{Path, PathBuf};
use std::{
path::{Path, PathBuf},
sync::Arc,
};

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -32,7 +35,7 @@ pub struct RawResolverOptions {
}

impl RawResolverOptions {
pub fn normalized(&self) -> ResolverOptions {
pub fn normalized(&self, unsafe_cache: Option<Arc<ResolverUnsafeCache>>) -> ResolverOptions {
let default = ResolverOptions::default();
ResolverOptions {
enforce_extension: self.enforce_extension.to_owned(),
Expand All @@ -51,11 +54,12 @@ impl RawResolverOptions {
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
disable_unsafe_cache: self
.enable_unsafe_cache
.to_owned()
.unwrap_or(default.enable_unsafe_cache),
.unwrap_or(default.disable_unsafe_cache),
tsconfig: self.tsconfig_path.to_owned().map(PathBuf::from),
unsafe_cache,
}
}
}
Expand All @@ -77,7 +81,17 @@ pub struct ResolverInternal {}

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

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

0 comments on commit 73aa3ef

Please sign in to comment.