Skip to content

Commit

Permalink
Merge pull request #26 from bvanjoi/next
Browse files Browse the repository at this point in the history
release: 0.0.21
  • Loading branch information
bvanjoi authored Jul 12, 2022
2 parents aee8900 + da6241e commit 69265dc
Show file tree
Hide file tree
Showing 9 changed files with 73 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.28"
nodejs-resolver = "0.0.30"
serde = { version = "1.0.138", features = ["derive"] }

[build-dependencies]
Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions __test__/fixture/node_modules/a/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('load sideeffects', (t) => {
t.is(result?.pkgFilePath, path.resolve(__dirname, "./fixture/node_modules/a/package.json"))
})

test("shared cache", (t) => {
test("shared cache speedy ensure", (t) => {
const sharedCache = factory.createExternalCache();
const resolver1 = factory.createWithExternalCache({}, sharedCache);
const resolver2 = factory.createWithExternalCache({}, sharedCache);
Expand All @@ -84,3 +84,53 @@ test("shared cache", (t) => {
// but I think the following statement will usefully.
t.is(cachedDuration - uncachedDuration < 0, true)
})


test("without cache", (t) => {
const resolver1 = factory.create({
browserField: true,
})
const resolver2 = factory.create({})
t.is(
factory.resolve(
resolver2,
path.resolve(__dirname, './fixture'),
'a/node'
),
path.resolve(__dirname, './fixture/node_modules/a/node.js')
);
t.is(
factory.resolve(
resolver1,
path.resolve(__dirname, './fixture'),
'a/node'
),
path.resolve(__dirname, './fixture/node_modules/a/browser.js')
);
})

test("shared cache load package.json", (t) => {
const sharedCache = factory.createExternalCache();
const resolver1 = factory.createWithExternalCache({
browserField: true,
}, sharedCache);
const resolver2 = factory.createWithExternalCache({}, sharedCache);

t.is(
factory.resolve(
resolver1,
path.resolve(__dirname, './fixture'),
'a/node'
),
path.resolve(__dirname, './fixture/node_modules/a/browser.js')
);

t.is(
factory.resolve(
resolver2,
path.resolve(__dirname, './fixture'),
'a/node'
),
path.resolve(__dirname, './fixture/node_modules/a/node.js')
);
})
20 changes: 11 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface RawResolverOptions {
extensions?: Array<string>
enforceExtension?: boolean
alias?: Array<Alias>
aliasFields?: Array<string>
browserField?: boolean
conditionNames?: Array<string>
symlinks?: boolean
descriptionFile?: string | undefined | null
Expand All @@ -27,19 +27,21 @@ export interface RawResolverOptions {
preferRelative?: boolean
tsconfigPath?: string
}
export interface ResolverInternal {

}
export interface ResolverInternal {}
export function create(options: RawResolverOptions): ExternalObject<ResolverInternal>
export function createWithExternalCache(options: RawResolverOptions, external_cache: ExternalObject<ResolverCacheInternal>): ExternalObject<ResolverInternal>
export interface ResolverCacheInternal {

}
export interface ResolverCacheInternal {}
export function createExternalCache(): ExternalObject<ResolverCacheInternal>
export function createWithExternalCache(
options: RawResolverOptions,
external_cache: ExternalObject<ResolverCacheInternal>,
): ExternalObject<ResolverInternal>
export function resolve(resolver: ExternalObject<ResolverInternal>, base_dir: string, id: string): string
export interface SideEffectsStats {
boolVal?: boolean
arrayVal?: Array<string>
pkgFilePath: string
}
export function loadSideEffects(resolver: ExternalObject<ResolverInternal>, path: string): {boolVal?: boolean, arrayVal?: string[], pkgFilePath: string} | undefined
export function loadSideEffects(
resolver: ExternalObject<ResolverInternal>,
path: string,
): { boolVal?: boolean; arrayVal?: string[]; pkgFilePath: string } | undefined
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { create, createWithExternalCache, createExternalCache, resolve, loadSideEffects } = nativeBinding
const { create, createExternalCache, createWithExternalCache, resolve, loadSideEffects } = nativeBinding

module.exports.create = create
module.exports.createWithExternalCache = createWithExternalCache
module.exports.createExternalCache = createExternalCache
module.exports.createWithExternalCache = createWithExternalCache
module.exports.resolve = resolve
module.exports.loadSideEffects = loadSideEffects
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.20",
"version": "0.0.21",
"description": "node binding for nodejs-resolver",
"main": "index.js",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct RawResolverOptions {
pub extensions: Option<Vec<String>>,
pub enforce_extension: Option<bool>,
pub alias: Option<Vec<Alias>>,
pub alias_fields: Option<Vec<String>>,
pub browser_field: Option<bool>,
pub condition_names: Option<Vec<String>>,
pub symlinks: Option<bool>,
pub description_file: Option<Option<String>>,
Expand All @@ -40,7 +40,7 @@ impl RawResolverOptions {
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_fields: self.alias_fields.to_owned().unwrap_or(default.alias_fields),
browser_field: self.browser_field.to_owned().unwrap_or(default.browser_field),
condition_names: self
.condition_names
.to_owned()
Expand Down Expand Up @@ -81,7 +81,6 @@ pub fn create(options: RawResolverOptions) -> Result<External<Resolver>, napi::E
Ok(External::new(resolver))
}


#[napi(object)]
pub struct ResolverCacheInternal {}

Expand All @@ -100,7 +99,8 @@ pub fn create_with_external_cache(
options: RawResolverOptions,
external_cache: External<Arc<ResolverUnsafeCache>>,
) -> Result<External<Resolver>, napi::Error> {
let options = options.normalized(Some(external_cache.clone()));
let external_cache = external_cache.as_ref().clone();
let options = options.normalized(Some(external_cache));
let resolver = Resolver::new(options);
Ok(External::new(resolver))
}
Expand Down

0 comments on commit 69265dc

Please sign in to comment.