Support declaring internal module regex or respect import/internal-regex setting
Resolver performs way too slow on a medium to large TS project where every local/internal import is absolute from the project root, since https://github.com/import-js/eslint-import-resolver-typescript/blob/71b23a206514842fef70a99220e5ffb1d6da2a0e/src/index.ts#L276 optimization branch is not used.
It would be useful to allow users to specify internalRegex similar to https://github.com/import-js/eslint-plugin-import/tree/a89eadf3247af844da6b0f9e7bca7690777bf665#importinternal-regex.
Worth mentioning that using above import/internal-regex did speed up the linting times, but unexpectedly I have seen more improvements when implemented a custom resolver like below using the same regexp, so perhaps there is a bug (or misunderstanding) there and no new option is needed, just addressing that one.
export function resolve(
importPath: string,
importerFileAbsolutePath: string,
tsResolverOptions: TsResolverOptions
): ResolveResult {
if (internalModuleRegexp.test(importPath)) {
const absoluteImportPath = path.resolve(`./${importPath}`);
return {
found: true,
path: absoluteImportPath,
};
}
return eslintImportResolverTypescript.resolve(importPath, importerFileAbsolutePath, tsResolverOptions);
}
I don't quite follow you meanings, why internalModuleRegexp matched means the related absoluteImportPath as resolved.
This is a simplified implementation that won't work for every usecase perhaps, sorry for confusion, but what I mean:
Imagine you have a large repo like this
- foo
- nested
- file1.ts
- bar
- nested
- file2.ts
- package.json
- .eslintrc.json
- tsconfig.json
And file1.ts is using an absolute (to the tsconfig) import path.
import { something } from "bar/nested/file2"
For this import we are using enchanced-resolve, however we could just resolve it faster since we have foo and bar are our top level folders and we use absolute import paths.
however we could just resolve it faster since we have foo and bar are our top level folders and we use absolute import paths
This seems not always true?
For a common mono repo, the structure would be:
- packages
- foo
- nested
- file1.ts
- bar
- nested
- file2.ts
- package.json
How can we resolve it faster for bar/nested/file2 in this case?
if we base tsconfig path while resolving not the package.json, this would work right?, though complicated when there are multiple projects linting via same config. Also we could ask for users to provide path to root folder 🤷♂️
I still can't fully get your point, but a PR for showing case would be appreciated. 👍
Perhaps it's also hard to implement in a generic way, that's why my explanation doesn't make a lot of sense but I'll give it a try when I have time.