-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
New resolver design #40
Comments
Why not: {
resolver: "webpack",
resolverOptions: {/* resolver-specific options */},
} |
I don't like this idea of Let's do |
Since we have multiple resolvers, and each one of them will have its own unique set of options. Perhaps we could approach it like this instead: {
webpack?: boolean | WebpackResolverOption | null
typescript?: boolean | TypeScriptResolverOption | null
node?: boolean | NodeResolverOption | null
} |
That's how it's working nowadays except it requires specific npm packages installed. 🥹 But if we are going to adopt using For resolver options, could there be any other options except I'm asking because I want to make a breaking change to drop support for previous resolvers instead of continuing. |
That would work and be preferred in flat config format. Nonflat config has to support the package name as string. |
Yeah, I want to do the same. There are many resolve libraries out there trying to mimic Node.js-like resolving algorithm: |
I think the only modern resolution mechanisms one needs are these two (names based on tsconfig
|
We will still need a library as long as we are publishing ESM/CJS dual packages and want to have a unified behavior across |
Is CJS support still desired? CJS packages could just remain on using Non-flat configs load as CJS but if I recall correctly, |
Flat config supports both CJS and ESM, so there is no reason to make |
Ah, you are right. I wasn't aware that it's possible to support CJS in flat config as I head read this, so transpilation to CJS will be required if non-flat config is to be supported. |
@JounQin Was reading this blog post: How we made Vite 4.3 faaaaster 🚀, and here I quote:
IMHO should we build our own resolving algorithm as well? |
Regarding typescript, it would be great if this could somehow piggyback off of typescript's own module resolution. https://github.com/import-js/eslint-import-resolver-typescript mostly matches typescript, but I don't think it supports the project service, so you still have to tell it about all the relevant projects manually (in dependency order). typescript-eslint does support the project service through |
|
Here's a request for that: import-js/eslint-import-resolver-typescript#282 |
So is there any official way currently to support |
|
For anyone who wants to know, if you explicitly provide |
If you do so, the typescript-eslint will become 1.5x slower, see typescript-eslint/typescript-eslint#8424 That's why |
Yeah seems so, but currently I can't really find a way to make things work without specifying the I seems have some idea how the resolver works, but I'm not too sure. Anyway as a result, previously when I'm using the I tried my best to read through those issues, but this is just a bit hard for someone have no insights to understand well😥. At least for now I have a way to make it work, so I'm satisfied with it. I guess if one day |
Does this help at all? typescript-eslint/typescript-eslint#8030 (reply in thread) Has there been communications directly between |
I am going to share my ideas about new resolver implementations and settings: // eslint.config.js
{
settings: {
// multiple resolvers
'import-x/resolver': [
nodeResolverObject,
createTsResolver(enhancedResolverOptions),
createOxcResolver(oxcOptions),
],
// single resolver:
'import-x/resolver': createOxcResolver(oxcOptions)
}
} For the custom resolver author/maintainer, here is the signature of the resolver interface v3: export interface ResolverV3<T = unknown, U = T> = {
interfaceVersion: 3,
name?: string, // This will only be included in the debug log
resolve: (modulePath: string, sourceFile: string) => ResolvedResult
}
export interface ResolverV3MigrateFromV1<T = unknown, U = T> {
interfaceVersion: 3,
name?: string, // This will only be included in the debug log
/**
* @deprecated
* To minimize the effort when migrating v1 version of custom resolver directly to v3, `resolveImport` is retained. This is not recommended, all new resolvers should implement `resolve`.
*/
resolveImport: (modulePath: string, sourceFile: string) => string | undefined,
}
// The `ResolvedResult` (returned resolved result) will remain the same
export type ResultNotFound = {
found: false
path?: undefined
}
export type ResultFound = {
found: true
path: string | null
}
export type ResolvedResult = ResultNotFound | ResultFound Note that export const createResolver = (options) => {
// Create a re-usable resolver instance with the shared options
const resolver = new ResolverFactory(options);
return {
interfaceVersion: 3,
name: 'custom-resolver',
resolve: (modPath, sourcePath) => {
const resolved = resolver.sync(modPath, { path: path.dirname(sourcePath) });
},
}
}; The format of the I will be adding In the next major version, In the meantime, we will also export a compat utility for an easier transition from existing resolvers: export const compatImportXResolverV3 = (options: T, legacyResolver: object) => {
return {
interfaceVersion: 3,
resolve: (modPath, sourcePath) => legacyResolver.resolve(modPath, sourcePath, options),
resolveImport: (modPath, sourcePath) => legacyResolver.resolveImport(modPath, sourcePath, options)
}
} I chose to drop the The ESLint flat config involves passing objects and functions directly, so we don't have to adhere to the idea of Also, the current resolver interface ( @JounQin @antfu @silverwind @9romise What do you think? |
I agree with your design but have a few questions. |
But of course, I'd recommend all new resolvers implement The original proposal updated. |
Hey there, |
All resolves are happening inside the rules. So, unless ESLint supports async rules, we can only use a sync resolver for now. |
I haven't remove the
resolver
concept ineslint-plugin-import-x<=0.2
because I found that thewebpack
resolver may be still useful for those webpack users, and although we can useenhanced-resolve
directly, but the settings can not fit all projects, I need to figure out how to set the resolver correctly for specific projects.For example:
I'm thinking the interface of
import-x/resolver
setting should be:By default,
eslint-plugin-import-x
should useenhanced-resolve
directly to simulate nativenode
resolve algorithm.The text was updated successfully, but these errors were encountered: