Skip to content

Commit ebbb538

Browse files
committed
feat: optimized args
1 parent b167ff5 commit ebbb538

File tree

12 files changed

+86
-910
lines changed

12 files changed

+86
-910
lines changed

.eslintrc.yml

Lines changed: 0 additions & 167 deletions
This file was deleted.

.github/workflows/Publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ env:
77
push:
88
branches:
99
- main
10+
paths:
11+
- 'package.json'
1012

1113
jobs:
1214
build:

.github/workflows/lint.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ build/Release
4545
# Dependency directories
4646
node_modules/
4747
jspm_packages/
48+
!__test__/
4849

4950
# TypeScript v1 declaration files
5051
typings/
File renamed without changes.

__test__/fixture/lib.ts

Whitespace-only changes.

__test__/index.spec.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@ import path from 'path'
22

33
import test from 'ava'
44

5-
import factory from '../index'
5+
import factory, { RawResolverOptions } from '../index'
66

77
test('sync function from native code', (t) => {
8-
const resolver = factory.create(JSON.stringify({}))
9-
const result = factory.resolve(resolver, __dirname, './lib.js')
10-
t.is(result.path, path.resolve(__dirname, './lib.js'))
8+
const resolver = factory.create({})
9+
const result = factory.resolve(resolver, __dirname, './fixture/lib')
10+
t.is(result.path, path.resolve(__dirname, './fixture/lib.js'))
11+
t.is(result.status, true)
12+
})
13+
14+
test('resolve do not exist file', (t) => {
15+
const resolver = factory.create({})
16+
let count = 0
17+
let encounterError = false
18+
try {
19+
count += 1
20+
factory.resolve(resolver, __dirname, './lib')
21+
count += 1
22+
} catch (err: any) {
23+
encounterError = true
24+
t.assert((err.message as string).includes('Resolve ./lib failed in'))
25+
}
26+
t.is(count, 1)
27+
t.is(encounterError, true)
28+
})
29+
30+
test('extensions options', (t) => {
31+
const resolverOptions: RawResolverOptions = {
32+
extensions: ['ts', 'js'],
33+
}
34+
const resolver = factory.create(resolverOptions)
35+
const result = factory.resolve(resolver, __dirname, './fixture/lib')
36+
t.is(result.path, path.resolve(__dirname, './fixture/lib.ts'))
1137
t.is(result.status, true)
1238
})

index.d.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ export class ExternalObject<T> {
99
[K: symbol]: T
1010
}
1111
}
12-
export interface ResolverInternal {
13-
12+
export interface RawResolverOptions {
13+
extensions?: Array<string>
14+
enforceExtension?: boolean | undefined | null
15+
alias?: Record<string, string | undefined | null>
16+
aliasFields?: Array<string>
17+
conditionNames?: Array<string>
18+
symlinks?: boolean
19+
descriptionFile?: string | undefined | null
20+
mainFiles?: Array<string>
21+
mainFields?: Array<string>
22+
modules?: Array<string>
23+
preferRelative?: boolean
24+
enableUnsafeCache?: boolean
1425
}
15-
export function create(options: string): ExternalObject<ResolverInternal>
26+
export interface ResolverInternal {}
27+
export function create(options: RawResolverOptions): ExternalObject<ResolverInternal>
1628
export interface ResolveResult {
1729
status: boolean
1830
path?: string
1931
}
20-
export function resolve(resolver: ExternalObject<ResolverInternal>,): ResolveResult
32+
export function resolve(
33+
resolver: ExternalObject<ResolverInternal>,
34+
base_dir: string,
35+
id: string,
36+
): { status: boolean; path?: string }

package.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nodejs-resolver",
3-
"version": "0.0.2",
4-
"description": "Template project for writing node package with napi-rs",
3+
"version": "0.0.3",
4+
"description": "node binding for nodejs-resolver",
55
"main": "index.js",
66
"license": "MIT",
77
"keywords": [
@@ -45,33 +45,24 @@
4545
"format": "run-p format:prettier format:rs",
4646
"format:prettier": "prettier . -w",
4747
"format:rs": "cargo fmt",
48-
"lint": "eslint . -c ./.eslintrc.yml",
4948
"prepublishOnly": "napi prepublish -t npm",
5049
"test": "ava",
5150
"version": "napi version"
5251
},
5352
"devDependencies": {
5453
"@napi-rs/cli": "^2.7.0",
5554
"@swc-node/register": "^1.5.1",
56-
"@typescript-eslint/eslint-plugin": "^5.22.0",
57-
"@typescript-eslint/parser": "^5.22.0",
5855
"ava": "^4.2.0",
5956
"benny": "^3.7.1",
6057
"chalk": "^5.0.1",
61-
"eslint": "^8.14.0",
62-
"eslint-config-prettier": "^8.5.0",
63-
"eslint-plugin-import": "^2.26.0",
64-
"eslint-plugin-prettier": "^4.0.0",
6558
"husky": "^7.0.4",
6659
"lint-staged": "^12.4.1",
6760
"npm-run-all": "^4.1.5",
6861
"prettier": "^2.6.2",
69-
"typescript": "^4.6.4"
62+
"typescript": "^4.6.4",
63+
"@types/node": "^12.12.5"
7064
},
7165
"lint-staged": {
72-
"*.@(js|ts|tsx)": [
73-
"eslint -c .eslintrc.yml --fix"
74-
],
7566
"*.@(js|ts|tsx|yml|yaml|md|json)": [
7667
"prettier --write"
7768
]

simple-test.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)