Skip to content

Commit cd647b0

Browse files
authored
Merge pull request #27 from bvanjoi/next
release: 0.0.22
2 parents 69265dc + 2c2fb52 commit cd647b0

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ publish = false
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
napi = "2"
14-
napi-derive = "2"
15-
nodejs-resolver = "0.0.30"
16-
serde = { version = "1.0.138", features = ["derive"] }
13+
napi = "2.6.3"
14+
napi-derive = "2.6.0"
15+
nodejs-resolver = "0.0.32"
16+
serde = { version = "1.0.139", features = ["derive"] }
1717

1818
[build-dependencies]
19-
napi-build = "2"
19+
napi-build = "2.0.1"
2020

2121
[profile.release]
2222
lto = true

__test__/fixture/node_modules/a/package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__test__/index.spec.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,14 @@ test('alias options', (t) => {
5757
t.is(result2, "false")
5858
})
5959

60-
test('load sideeffects', (t) => {
60+
test('load side effects', (t) => {
6161
const resolver = factory.create({})
6262
const result = factory.loadSideEffects(resolver, path.resolve(__dirname, "./fixture/node_modules/a"));
6363
t.is(result?.boolVal, false)
6464
t.is(result?.arrayVal, undefined)
6565
t.is(result?.pkgFilePath, path.resolve(__dirname, "./fixture/node_modules/a/package.json"))
6666
})
6767

68-
test("shared cache speedy ensure", (t) => {
69-
const sharedCache = factory.createExternalCache();
70-
const resolver1 = factory.createWithExternalCache({}, sharedCache);
71-
const resolver2 = factory.createWithExternalCache({}, sharedCache);
72-
73-
const uncachedStart = process.hrtime.bigint();
74-
factory.loadSideEffects(resolver1, path.resolve(__dirname, "./fixture/node_modules/a"));
75-
const uncachedEnd = process.hrtime.bigint();
76-
const uncachedDuration = uncachedEnd - uncachedStart;
77-
78-
const cachedStart = process.hrtime.bigint();
79-
factory.loadSideEffects(resolver2, path.resolve(__dirname, "./fixture/node_modules/a"));
80-
const cachedEnd = process.hrtime.bigint();
81-
const cachedDuration = cachedEnd - cachedStart;
82-
console.log('uncached: ', uncachedDuration, 'cached: ', cachedDuration);
83-
// maybe expose content in cache and ensure it is not empty may be a better choice.
84-
// but I think the following statement will usefully.
85-
t.is(cachedDuration - uncachedDuration < 0, true)
86-
})
87-
88-
8968
test("without cache", (t) => {
9069
const resolver1 = factory.create({
9170
browserField: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodejs-resolver",
3-
"version": "0.0.21",
3+
"version": "0.0.22",
44
"description": "node binding for nodejs-resolver",
55
"main": "index.js",
66
"license": "MIT",

src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use napi::bindgen_prelude::External;
22
use napi_derive::napi;
3-
use nodejs_resolver::{AliasMap, Resolver, ResolverOptions, ResolverUnsafeCache, SideEffects};
3+
use nodejs_resolver::{AliasMap, Resolver, ResolverOptions, ResolverCache, SideEffects};
44
use serde::Deserialize;
55
use std::{
66
path::{Path, PathBuf},
@@ -34,13 +34,16 @@ pub struct RawResolverOptions {
3434
}
3535

3636
impl RawResolverOptions {
37-
pub fn normalized(&self, unsafe_cache: Option<Arc<ResolverUnsafeCache>>) -> ResolverOptions {
37+
pub fn normalized(&self, external_cache: Option<Arc<ResolverCache>>) -> ResolverOptions {
3838
let default = ResolverOptions::default();
3939
ResolverOptions {
4040
enforce_extension: self.enforce_extension.to_owned(),
4141
extensions: self.extensions.to_owned().unwrap_or(default.extensions),
4242
alias: self.alias.to_owned().map_or(default.alias, parse_alias),
43-
browser_field: self.browser_field.to_owned().unwrap_or(default.browser_field),
43+
browser_field: self
44+
.browser_field
45+
.to_owned()
46+
.unwrap_or(default.browser_field),
4447
condition_names: self
4548
.condition_names
4649
.to_owned()
@@ -54,7 +57,7 @@ impl RawResolverOptions {
5457
main_fields: self.main_fields.to_owned().unwrap_or(default.main_fields),
5558
prefer_relative: self.prefer_relative.unwrap_or(default.prefer_relative),
5659
tsconfig: self.tsconfig_path.to_owned().map(PathBuf::from),
57-
unsafe_cache,
60+
external_cache,
5861
}
5962
}
6063
}
@@ -85,9 +88,9 @@ pub fn create(options: RawResolverOptions) -> Result<External<Resolver>, napi::E
8588
pub struct ResolverCacheInternal {}
8689

8790
#[napi(ts_return_type = "ExternalObject<ResolverCacheInternal>")]
88-
pub fn create_external_cache() -> Result<External<Arc<ResolverUnsafeCache>>, napi::Error> {
91+
pub fn create_external_cache() -> Result<External<Arc<ResolverCache>>, napi::Error> {
8992
Ok(External::new(
90-
Resolver::new(Default::default()).unsafe_cache.unwrap(),
93+
Arc::new(ResolverCache::default()),
9194
))
9295
}
9396

@@ -97,7 +100,7 @@ pub fn create_external_cache() -> Result<External<Arc<ResolverUnsafeCache>>, nap
97100
)]
98101
pub fn create_with_external_cache(
99102
options: RawResolverOptions,
100-
external_cache: External<Arc<ResolverUnsafeCache>>,
103+
external_cache: External<Arc<ResolverCache>>,
101104
) -> Result<External<Resolver>, napi::Error> {
102105
let external_cache = external_cache.as_ref().clone();
103106
let options = options.normalized(Some(external_cache));
@@ -146,7 +149,7 @@ pub fn load_side_effects(
146149
resolver: External<Resolver>,
147150
path: String,
148151
) -> Result<Option<SideEffectsStats>, napi::Error> {
149-
match (*resolver).load_sideeffects(&Path::new(&path)) {
152+
match (*resolver).load_side_effects(&Path::new(&path)) {
150153
Ok(val) => Ok(val.map(|val| {
151154
let (bool_val, array_val) = val
152155
.1

0 commit comments

Comments
 (0)