From de8fa6836d4961fae04caabb62698ec2f53286d5 Mon Sep 17 00:00:00 2001 From: bvanjoi Date: Mon, 4 Jul 2022 17:05:23 +0800 Subject: [PATCH] release: 0.0.17 --- Cargo.toml | 2 +- index.d.ts | 1 + index.js | 3 ++- package.json | 2 +- src/lib.rs | 26 ++++++++++++++++++++------ 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee3f7a0..1132d6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/index.d.ts b/index.d.ts index e573e3f..6059a53 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,4 +32,5 @@ export interface ResolverInternal { } export function create(options: RawResolverOptions): ExternalObject +export function createResolverAndInheritUnsafeCacheFromAnother(options: RawResolverOptions, another: ExternalObject): ExternalObject export function resolve(resolver: ExternalObject, base_dir: string, id: string): string diff --git a/index.js b/index.js index 1ad3836..9e371a0 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/package.json b/package.json index b96fd0b..b61bbec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib.rs b/src/lib.rs index 544ab06..40fc2db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")] @@ -32,7 +35,7 @@ pub struct RawResolverOptions { } impl RawResolverOptions { - pub fn normalized(&self) -> ResolverOptions { + pub fn normalized(&self, unsafe_cache: Option>) -> ResolverOptions { let default = ResolverOptions::default(); ResolverOptions { enforce_extension: self.enforce_extension.to_owned(), @@ -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, } } } @@ -77,7 +81,17 @@ pub struct ResolverInternal {} #[napi(ts_return_type = "ExternalObject")] pub fn create(options: RawResolverOptions) -> Result, 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")] +pub fn create_resolver_and_inherit_unsafe_cache_from_another( + options: RawResolverOptions, + another: External, +) -> Result, napi::Error> { + let options = options.normalized(another.unsafe_cache.clone()); let resolver = Resolver::new(options); Ok(External::new(resolver)) }