-
-
Notifications
You must be signed in to change notification settings - Fork 69
feat: rewrite, speed up by using rspack-resolver
under the hood
#368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c97fb78
feat: rewrite, speed up by using `oxc-resolver` under the hood
JounQin 3d8e5f8
feat: enable `alwaysTryTypes` by default, add `noWarnOnMultipleProjec…
JounQin 02a2649
chore: reduce size limit!
JounQin 298388b
chore: bump rspack-resolver
JounQin b83045a
Create friendly-weeks-act.md
JounQin d08485b
chore: don't run test with eslint cache
JounQin 2c797a9
fix: improve Windows compatibility
JounQin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"eslint-import-resolver-typescript": major | ||
--- | ||
|
||
feat!: rewrite, speed up by using [`rspack-resolver`](https://github.com/unrs/rspack-resolver) which supports `references` natively under the hood | ||
|
||
BREAKING CHANGES: | ||
|
||
- drop Node 14 support, Node `^16.17.0 || >=18.6` is now required | ||
- `alwaysTryTypes` is enabled by default, you can set it as `true` to opt-out | ||
- array type of `project` is discouraged but still supported, single `project` with `references` are encouraged for better performance, you can enable `noWarnOnMultipleProjects` option to supress the warning message | ||
- root `tsconfig.json` or `jsconfig.json` will be used automatically if no `project` provided |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"path": "./lib/index.js", | ||
"limit": "3.1kB" | ||
"limit": "1.5kB" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
export const defaultConditionNames = [ | ||
'types', | ||
'import', | ||
|
||
// APF: https://angular.io/guide/angular-package-format | ||
'esm2020', | ||
'es2020', | ||
'es2015', | ||
|
||
'require', | ||
'node', | ||
'node-addons', | ||
'browser', | ||
'default', | ||
] | ||
|
||
/** | ||
* `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly | ||
*/ | ||
export const defaultExtensions = [ | ||
'.ts', | ||
'.tsx', | ||
'.d.ts', | ||
'.js', | ||
'.jsx', | ||
'.json', | ||
'.node', | ||
] | ||
|
||
export const defaultExtensionAlias = { | ||
'.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'], | ||
} | ||
|
||
export const defaultMainFields = [ | ||
'types', | ||
'typings', | ||
|
||
// APF: https://angular.io/guide/angular-package-format | ||
'fesm2020', | ||
'fesm2015', | ||
'esm2020', | ||
'es2020', | ||
|
||
'module', | ||
'jsnext:main', | ||
|
||
'main', | ||
] | ||
|
||
export const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/ | ||
|
||
export const IMPORT_RESOLVER_NAME = 'eslint-import-resolver-typescript' | ||
|
||
export const interfaceVersion = 2 | ||
|
||
export const DEFAULT_TSCONFIG = 'tsconfig.json' | ||
|
||
export const DEFAULT_JSCONFIG = 'jsconfig.json' | ||
|
||
export const DEFAULT_CONFIGS = [DEFAULT_TSCONFIG, DEFAULT_JSCONFIG] | ||
|
||
export const DEFAULT_TRY_PATHS = ['', ...DEFAULT_CONFIGS] | ||
|
||
export const MATCH_ALL = '**' | ||
|
||
export const DEFAULT_IGNORE = [MATCH_ALL, 'node_modules', MATCH_ALL].join('/') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
|
||
/** | ||
* For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`. | ||
*/ | ||
export function mangleScopedPackage(moduleName: string) { | ||
if (moduleName.startsWith('@')) { | ||
const replaceSlash = moduleName.replace('/', '__') | ||
if (replaceSlash !== moduleName) { | ||
return replaceSlash.slice(1) // Take off the "@" | ||
} | ||
} | ||
return moduleName | ||
} | ||
|
||
/** Remove any trailing querystring from module id. */ | ||
export function removeQuerystring(id: string) { | ||
const querystringIndex = id.lastIndexOf('?') | ||
if (querystringIndex !== -1) { | ||
return id.slice(0, querystringIndex) | ||
} | ||
return id | ||
} | ||
|
||
export const tryFile = ( | ||
filename?: string[] | string, | ||
includeDir = false, | ||
base = process.cwd(), | ||
): string => { | ||
if (typeof filename === 'string') { | ||
const filepath = path.resolve(base, filename) | ||
return fs.existsSync(filepath) && | ||
(includeDir || fs.statSync(filepath).isFile()) | ||
? filepath | ||
: '' | ||
} | ||
|
||
for (const file of filename ?? []) { | ||
const filepath = tryFile(file, includeDir, base) | ||
if (filepath) { | ||
return filepath | ||
} | ||
} | ||
|
||
return '' | ||
} | ||
|
||
const computeAffinity = (projectDir: string, targetDir: string): number => { | ||
const a = projectDir.split(path.sep) | ||
const b = targetDir.split(path.sep) | ||
let lca = 0 | ||
while (lca < a.length && lca < b.length && a[lca] === b[lca]) { | ||
lca++ | ||
} | ||
return a.length - lca + (b.length - lca) | ||
} | ||
|
||
export const sortProjectsByAffinity = (projects: string[], file: string) => { | ||
const fileDir = path.dirname(file) | ||
return projects | ||
.map(project => ({ | ||
project, | ||
affinity: computeAffinity(path.dirname(project), fileDir), | ||
})) | ||
.sort((a, b) => a.affinity - b.affinity) | ||
.map(item => item.project) | ||
} | ||
|
||
export const toGlobPath = (pathname: string) => pathname.replaceAll('\\', '/') | ||
|
||
export const toNativePath = (pathname: string) => | ||
'/' === path.sep ? pathname : pathname.replaceAll('/', '\\') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.