Skip to content

Commit 69265dc

Browse files
authored
Merge pull request #26 from bvanjoi/next
release: 0.0.21
2 parents aee8900 + da6241e commit 69265dc

File tree

9 files changed

+73
-18
lines changed

9 files changed

+73
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
napi = "2"
1414
napi-derive = "2"
15-
nodejs-resolver = "0.0.28"
15+
nodejs-resolver = "0.0.30"
1616
serde = { version = "1.0.138", features = ["derive"] }
1717

1818
[build-dependencies]

__test__/fixture/node_modules/a/browser.js

Whitespace-only changes.

__test__/fixture/node_modules/a/node.js

Whitespace-only changes.

__test__/fixture/node_modules/a/package.json

Lines changed: 3 additions & 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: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('load sideeffects', (t) => {
6565
t.is(result?.pkgFilePath, path.resolve(__dirname, "./fixture/node_modules/a/package.json"))
6666
})
6767

68-
test("shared cache", (t) => {
68+
test("shared cache speedy ensure", (t) => {
6969
const sharedCache = factory.createExternalCache();
7070
const resolver1 = factory.createWithExternalCache({}, sharedCache);
7171
const resolver2 = factory.createWithExternalCache({}, sharedCache);
@@ -84,3 +84,53 @@ test("shared cache", (t) => {
8484
// but I think the following statement will usefully.
8585
t.is(cachedDuration - uncachedDuration < 0, true)
8686
})
87+
88+
89+
test("without cache", (t) => {
90+
const resolver1 = factory.create({
91+
browserField: true,
92+
})
93+
const resolver2 = factory.create({})
94+
t.is(
95+
factory.resolve(
96+
resolver2,
97+
path.resolve(__dirname, './fixture'),
98+
'a/node'
99+
),
100+
path.resolve(__dirname, './fixture/node_modules/a/node.js')
101+
);
102+
t.is(
103+
factory.resolve(
104+
resolver1,
105+
path.resolve(__dirname, './fixture'),
106+
'a/node'
107+
),
108+
path.resolve(__dirname, './fixture/node_modules/a/browser.js')
109+
);
110+
})
111+
112+
test("shared cache load package.json", (t) => {
113+
const sharedCache = factory.createExternalCache();
114+
const resolver1 = factory.createWithExternalCache({
115+
browserField: true,
116+
}, sharedCache);
117+
const resolver2 = factory.createWithExternalCache({}, sharedCache);
118+
119+
t.is(
120+
factory.resolve(
121+
resolver1,
122+
path.resolve(__dirname, './fixture'),
123+
'a/node'
124+
),
125+
path.resolve(__dirname, './fixture/node_modules/a/browser.js')
126+
);
127+
128+
t.is(
129+
factory.resolve(
130+
resolver2,
131+
path.resolve(__dirname, './fixture'),
132+
'a/node'
133+
),
134+
path.resolve(__dirname, './fixture/node_modules/a/node.js')
135+
);
136+
})

index.d.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface RawResolverOptions {
1717
extensions?: Array<string>
1818
enforceExtension?: boolean
1919
alias?: Array<Alias>
20-
aliasFields?: Array<string>
20+
browserField?: boolean
2121
conditionNames?: Array<string>
2222
symlinks?: boolean
2323
descriptionFile?: string | undefined | null
@@ -27,19 +27,21 @@ export interface RawResolverOptions {
2727
preferRelative?: boolean
2828
tsconfigPath?: string
2929
}
30-
export interface ResolverInternal {
31-
32-
}
30+
export interface ResolverInternal {}
3331
export function create(options: RawResolverOptions): ExternalObject<ResolverInternal>
34-
export function createWithExternalCache(options: RawResolverOptions, external_cache: ExternalObject<ResolverCacheInternal>): ExternalObject<ResolverInternal>
35-
export interface ResolverCacheInternal {
36-
37-
}
32+
export interface ResolverCacheInternal {}
3833
export function createExternalCache(): ExternalObject<ResolverCacheInternal>
34+
export function createWithExternalCache(
35+
options: RawResolverOptions,
36+
external_cache: ExternalObject<ResolverCacheInternal>,
37+
): ExternalObject<ResolverInternal>
3938
export function resolve(resolver: ExternalObject<ResolverInternal>, base_dir: string, id: string): string
4039
export interface SideEffectsStats {
4140
boolVal?: boolean
4241
arrayVal?: Array<string>
4342
pkgFilePath: string
4443
}
45-
export function loadSideEffects(resolver: ExternalObject<ResolverInternal>, path: string): {boolVal?: boolean, arrayVal?: string[], pkgFilePath: string} | undefined
44+
export function loadSideEffects(
45+
resolver: ExternalObject<ResolverInternal>,
46+
path: string,
47+
): { boolVal?: boolean; arrayVal?: string[]; pkgFilePath: string } | undefined

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ if (!nativeBinding) {
218218
throw new Error(`Failed to load native binding`)
219219
}
220220

221-
const { create, createWithExternalCache, createExternalCache, resolve, loadSideEffects } = nativeBinding
221+
const { create, createExternalCache, createWithExternalCache, resolve, loadSideEffects } = nativeBinding
222222

223223
module.exports.create = create
224-
module.exports.createWithExternalCache = createWithExternalCache
225224
module.exports.createExternalCache = createExternalCache
225+
module.exports.createWithExternalCache = createWithExternalCache
226226
module.exports.resolve = resolve
227227
module.exports.loadSideEffects = loadSideEffects

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.20",
3+
"version": "0.0.21",
44
"description": "node binding for nodejs-resolver",
55
"main": "index.js",
66
"license": "MIT",

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct RawResolverOptions {
2222
pub extensions: Option<Vec<String>>,
2323
pub enforce_extension: Option<bool>,
2424
pub alias: Option<Vec<Alias>>,
25-
pub alias_fields: Option<Vec<String>>,
25+
pub browser_field: Option<bool>,
2626
pub condition_names: Option<Vec<String>>,
2727
pub symlinks: Option<bool>,
2828
pub description_file: Option<Option<String>>,
@@ -40,7 +40,7 @@ impl RawResolverOptions {
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-
alias_fields: self.alias_fields.to_owned().unwrap_or(default.alias_fields),
43+
browser_field: self.browser_field.to_owned().unwrap_or(default.browser_field),
4444
condition_names: self
4545
.condition_names
4646
.to_owned()
@@ -81,7 +81,6 @@ pub fn create(options: RawResolverOptions) -> Result<External<Resolver>, napi::E
8181
Ok(External::new(resolver))
8282
}
8383

84-
8584
#[napi(object)]
8685
pub struct ResolverCacheInternal {}
8786

@@ -100,7 +99,8 @@ pub fn create_with_external_cache(
10099
options: RawResolverOptions,
101100
external_cache: External<Arc<ResolverUnsafeCache>>,
102101
) -> Result<External<Resolver>, napi::Error> {
103-
let options = options.normalized(Some(external_cache.clone()));
102+
let external_cache = external_cache.as_ref().clone();
103+
let options = options.normalized(Some(external_cache));
104104
let resolver = Resolver::new(options);
105105
Ok(External::new(resolver))
106106
}

0 commit comments

Comments
 (0)