Skip to content

Commit

Permalink
chore: update README about default options
Browse files Browse the repository at this point in the history
  • Loading branch information
9romise committed Jun 30, 2024
1 parent 8a30939 commit 0807115
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 82 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Inside your `eslint.config.js`, pass the resolver to `eslint-plugin-import-x`:
}
```

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).

### Options

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

More info see [oxc-resolver](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#options)

## Motivation

Expand Down
80 changes: 1 addition & 79 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,6 @@
import { cwd } from 'node:process'
import type { NapiResolveOptions } from 'oxc-resolver'
import { ResolverFactory } from 'oxc-resolver'

// @keep-sorted
/**
* some default options copy from
* https://github.com/import-js/eslint-import-resolver-typescript/blob/master/src/index.ts
* https://github.com/rolldown/rolldown/blob/main/crates/rolldown_resolver/src/resolver.rs
*/
const defaultOptions: NapiResolveOptions = {
aliasFields: [
['browser'],
],
conditionNames: [
'default',
'types',

'import',
'require',

'node',
'node-addons',
'browser',

// APF: https://angular.io/guide/angular-package-format
'esm2020',
'es2020',
'es2015',
],
extensionAlias: {
'.js': [
'.ts',
// `.tsx` can also be compiled as `.js`
'.tsx',
'.d.ts',
'.js',
],
'.jsx': ['.tsx', '.d.ts', '.jsx'],
'.cjs': ['.cts', '.d.cts', '.cjs'],
'.mjs': ['.mts', '.d.mts', '.mjs'],
},
extensions: [
'.ts',
'.tsx',
'.d.ts',
'.js',
'.jsx',
'.json',
'.node',
],
mainFields: [
'types',
'typings',

// APF: https://angular.io/guide/angular-package-format
'fesm2020',
'fesm2015',
'esm2020',
'es2020',

'main',
'module',
'browser',
'jsnext:main',
],
roots: [cwd()],
}

function normalizeOptions(options: NapiResolveOptions): NapiResolveOptions {
if (!options.tsconfig) {
defaultOptions.tsconfig = {
configFile: './tsconfig.json',
references: 'auto',
}
}
return {
...defaultOptions,
...options,
}
}
import { normalizeOptions } from './nomalizeOptions'

let resolver: ResolverFactory | undefined
export function resolve(source: string, file: string, options: NapiResolveOptions = {}): { found: boolean, path?: string } {
Expand Down
80 changes: 80 additions & 0 deletions src/nomalizeOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { cwd } from 'node:process'
import type { NapiResolveOptions } from 'oxc-resolver'

// @keep-sorted
/**
* some default options copy from
* https://github.com/import-js/eslint-import-resolver-typescript/blob/master/src/index.ts
* https://github.com/rolldown/rolldown/blob/main/crates/rolldown_resolver/src/resolver.rs
*/
const defaultOptions: NapiResolveOptions = {
aliasFields: [
['browser'],
],
conditionNames: [
'default',
'types',

'import',
'require',

'node',
'node-addons',
'browser',

// APF: https://angular.io/guide/angular-package-format
'esm2020',
'es2020',
'es2015',
],
extensionAlias: {
'.js': [
'.ts',
// `.tsx` can also be compiled as `.js`
'.tsx',
'.d.ts',
'.js',
],
'.jsx': ['.tsx', '.d.ts', '.jsx'],
'.cjs': ['.cts', '.d.cts', '.cjs'],
'.mjs': ['.mts', '.d.mts', '.mjs'],
},
extensions: [
'.ts',
'.tsx',
'.d.ts',
'.js',
'.jsx',
'.json',
'.node',
],
mainFields: [
'types',
'typings',

// APF: https://angular.io/guide/angular-package-format
'fesm2020',
'fesm2015',
'esm2020',
'es2020',

'main',
'module',
'browser',
'jsnext:main',
],
roots: [cwd()],
}

export function normalizeOptions(options: NapiResolveOptions = {}): NapiResolveOptions {
if (!options.tsconfig) {
defaultOptions.tsconfig = {
configFile: './tsconfig.json',
references: 'auto',
}
}
return {
...defaultOptions,
...options,
}
}

0 comments on commit 0807115

Please sign in to comment.