From 672f8ed6d1e9c2f2b4df56f1f61c8258c95f4c72 Mon Sep 17 00:00:00 2001 From: bvanjoi Date: Fri, 24 Jun 2022 20:07:47 +0800 Subject: [PATCH] release: 0.0.11 --- __test__/index.spec.ts | 15 +++++---------- index.d.ts | 6 +----- package.json | 2 +- src/lib.rs | 20 ++++---------------- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 305d657..98375a0 100644 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -7,8 +7,7 @@ import factory, { RawResolverOptions } from '../index' test('sync function from native code', (t) => { const resolver = factory.create({}) const result = factory.resolve(resolver, __dirname, './fixture/lib') - t.is(result.path, path.resolve(__dirname, './fixture/lib.js')) - t.is(result.status, true) + t.is(result, path.resolve(__dirname, './fixture/lib.js')) }) test('resolve do not exist file', (t) => { @@ -33,12 +32,10 @@ test('extensions options', (t) => { } const resolver = factory.create(resolverOptions) const result = factory.resolve(resolver, __dirname, './fixture/lib') - t.is(result.path, path.resolve(__dirname, './fixture/lib.ts')) - t.is(result.status, true) + t.is(result, path.resolve(__dirname, './fixture/lib.ts')) // with query and fragment const result2 = factory.resolve(resolver, __dirname, './fixture/lib?query#fragment') - t.is(result2.path, path.resolve(__dirname, './fixture/lib.ts?query#fragment')) - t.is(result2.status, true) + t.is(result2, path.resolve(__dirname, './fixture/lib.ts?query#fragment')) }) @@ -57,10 +54,8 @@ test('alias options', (t) => { } const resolver = factory.create(resolverOptions) const result = factory.resolve(resolver, __dirname, '@alias/lib') - t.is(result.path, path.resolve(__dirname, './fixture/lib.js')) - t.is(result.status, true) + t.is(result, path.resolve(__dirname, './fixture/lib.js')) const result2 = factory.resolve(resolver, __dirname, '@false/lib') - t.is(result2.path, undefined) - t.is(result2.status, false) + t.is(result2, "false") }) diff --git a/index.d.ts b/index.d.ts index f078fbc..2ad8c1f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,8 +32,4 @@ export interface ResolverInternal { } export function create(options: RawResolverOptions): ExternalObject -export interface ResolveResult { - status: boolean - path?: string -} -export function resolve(resolver: ExternalObject, base_dir: string, id: string): {status: boolean, path?: string} +export function resolve(resolver: ExternalObject, base_dir: string, id: string): string | false diff --git a/package.json b/package.json index a53aab9..3c507f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-resolver", - "version": "0.0.10", + "version": "0.0.11", "description": "node binding for nodejs-resolver", "main": "index.js", "license": "MIT", diff --git a/src/lib.rs b/src/lib.rs index 4b70777..dba8b04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,33 +84,21 @@ pub fn create(options: RawResolverOptions) -> Result, napi::E Ok(External::new(resolver)) } -#[napi(object)] -pub struct ResolveResult { - pub status: bool, - pub path: Option, -} - #[napi( ts_args_type = "resolver: ExternalObject, base_dir: string, id: string", - ts_return_type = "{status: boolean, path?: string}" + ts_return_type = "string | false" )] pub fn resolve( resolver: External, base_dir: String, id: String, -) -> Result { +) -> Result { match (*resolver).resolve(Path::new(&base_dir), &id) { Ok(val) => { if let nodejs_resolver::ResolverResult::Info(info) = val { - Ok(ResolveResult { - status: true, - path: Some(format!("{}{}{}", info.path.display(), &info.request.query, &info.request.fragment)), - }) + Ok(format!("{}{}{}", info.path.display(), &info.request.query, &info.request.fragment)) } else { - Ok(ResolveResult { - status: false, - path: None, - }) + Ok(String::from("false")) } } Err(err) => Err(napi::Error::new(napi::Status::GenericFailure, err)),