Skip to content

Commit 0807115

Browse files
committed
chore: update README about default options
1 parent 8a30939 commit 0807115

File tree

3 files changed

+84
-82
lines changed

3 files changed

+84
-82
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ Inside your `eslint.config.js`, pass the resolver to `eslint-plugin-import-x`:
2424
}
2525
```
2626

27-
This lib defaults to ESM, if you use CJS(not recommended), please wait for the subsequent release. Or you can configure it yourself according to the [documentation](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options).
28-
2927
### Options
3028

31-
see [oxc-resolver](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options)
29+
Default options see [normalizeOptions.ts](./src/nomalizeOptions.ts)
30+
31+
More info see [oxc-resolver](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options)
3232

3333
## Motivation
3434

src/index.ts

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,6 @@
1-
import { cwd } from 'node:process'
21
import type { NapiResolveOptions } from 'oxc-resolver'
32
import { ResolverFactory } from 'oxc-resolver'
4-
5-
// @keep-sorted
6-
/**
7-
* some default options copy from
8-
* https://github.com/import-js/eslint-import-resolver-typescript/blob/master/src/index.ts
9-
* https://github.com/rolldown/rolldown/blob/main/crates/rolldown_resolver/src/resolver.rs
10-
*/
11-
const defaultOptions: NapiResolveOptions = {
12-
aliasFields: [
13-
['browser'],
14-
],
15-
conditionNames: [
16-
'default',
17-
'types',
18-
19-
'import',
20-
'require',
21-
22-
'node',
23-
'node-addons',
24-
'browser',
25-
26-
// APF: https://angular.io/guide/angular-package-format
27-
'esm2020',
28-
'es2020',
29-
'es2015',
30-
],
31-
extensionAlias: {
32-
'.js': [
33-
'.ts',
34-
// `.tsx` can also be compiled as `.js`
35-
'.tsx',
36-
'.d.ts',
37-
'.js',
38-
],
39-
'.jsx': ['.tsx', '.d.ts', '.jsx'],
40-
'.cjs': ['.cts', '.d.cts', '.cjs'],
41-
'.mjs': ['.mts', '.d.mts', '.mjs'],
42-
},
43-
extensions: [
44-
'.ts',
45-
'.tsx',
46-
'.d.ts',
47-
'.js',
48-
'.jsx',
49-
'.json',
50-
'.node',
51-
],
52-
mainFields: [
53-
'types',
54-
'typings',
55-
56-
// APF: https://angular.io/guide/angular-package-format
57-
'fesm2020',
58-
'fesm2015',
59-
'esm2020',
60-
'es2020',
61-
62-
'main',
63-
'module',
64-
'browser',
65-
'jsnext:main',
66-
],
67-
roots: [cwd()],
68-
}
69-
70-
function normalizeOptions(options: NapiResolveOptions): NapiResolveOptions {
71-
if (!options.tsconfig) {
72-
defaultOptions.tsconfig = {
73-
configFile: './tsconfig.json',
74-
references: 'auto',
75-
}
76-
}
77-
return {
78-
...defaultOptions,
79-
...options,
80-
}
81-
}
3+
import { normalizeOptions } from './nomalizeOptions'
824

835
let resolver: ResolverFactory | undefined
846
export function resolve(source: string, file: string, options: NapiResolveOptions = {}): { found: boolean, path?: string } {

src/nomalizeOptions.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { cwd } from 'node:process'
2+
import type { NapiResolveOptions } from 'oxc-resolver'
3+
4+
// @keep-sorted
5+
/**
6+
* some default options copy from
7+
* https://github.com/import-js/eslint-import-resolver-typescript/blob/master/src/index.ts
8+
* https://github.com/rolldown/rolldown/blob/main/crates/rolldown_resolver/src/resolver.rs
9+
*/
10+
const defaultOptions: NapiResolveOptions = {
11+
aliasFields: [
12+
['browser'],
13+
],
14+
conditionNames: [
15+
'default',
16+
'types',
17+
18+
'import',
19+
'require',
20+
21+
'node',
22+
'node-addons',
23+
'browser',
24+
25+
// APF: https://angular.io/guide/angular-package-format
26+
'esm2020',
27+
'es2020',
28+
'es2015',
29+
],
30+
extensionAlias: {
31+
'.js': [
32+
'.ts',
33+
// `.tsx` can also be compiled as `.js`
34+
'.tsx',
35+
'.d.ts',
36+
'.js',
37+
],
38+
'.jsx': ['.tsx', '.d.ts', '.jsx'],
39+
'.cjs': ['.cts', '.d.cts', '.cjs'],
40+
'.mjs': ['.mts', '.d.mts', '.mjs'],
41+
},
42+
extensions: [
43+
'.ts',
44+
'.tsx',
45+
'.d.ts',
46+
'.js',
47+
'.jsx',
48+
'.json',
49+
'.node',
50+
],
51+
mainFields: [
52+
'types',
53+
'typings',
54+
55+
// APF: https://angular.io/guide/angular-package-format
56+
'fesm2020',
57+
'fesm2015',
58+
'esm2020',
59+
'es2020',
60+
61+
'main',
62+
'module',
63+
'browser',
64+
'jsnext:main',
65+
],
66+
roots: [cwd()],
67+
}
68+
69+
export function normalizeOptions(options: NapiResolveOptions = {}): NapiResolveOptions {
70+
if (!options.tsconfig) {
71+
defaultOptions.tsconfig = {
72+
configFile: './tsconfig.json',
73+
references: 'auto',
74+
}
75+
}
76+
return {
77+
...defaultOptions,
78+
...options,
79+
}
80+
}

0 commit comments

Comments
 (0)