-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat: old import-x/resolve
options now use new built-in node resolver
#272
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
base: master
Are you sure you want to change the base?
Changes from all commits
85a9702
89e3937
2a66b0a
ffcc7d3
161c7cc
28189c5
2b0fce1
05fcf87
d21b8d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url' | |
|
||
import { stableHash } from 'stable-hash' | ||
|
||
import { createNodeResolver } from '../node-resolver.js' | ||
import type { | ||
ImportSettings, | ||
LegacyResolver, | ||
|
@@ -110,6 +111,8 @@ function isValidNewResolver(resolver: unknown): resolver is NewResolver { | |
return true | ||
} | ||
|
||
let fallbackLegacyNodeResolver: NewResolver | ||
|
||
function fullResolve( | ||
modulePath: string, | ||
sourceFile: string, | ||
|
@@ -140,10 +143,7 @@ function fullResolve( | |
return { found: true, path: cachedPath } | ||
} | ||
|
||
if ( | ||
Object.prototype.hasOwnProperty.call(settings, 'import-x/resolver-next') && | ||
settings['import-x/resolver-next'] | ||
) { | ||
if (settings['import-x/resolver-next']) { | ||
const configResolvers = settings['import-x/resolver-next'] | ||
|
||
for (let i = 0, len = configResolvers.length; i < len; i++) { | ||
|
@@ -169,33 +169,56 @@ function fullResolve( | |
fileExistsCache.set(cacheKey, resolved.path as string | null) | ||
return resolved | ||
} | ||
} else { | ||
const configResolvers = settings['import-x/resolver-legacy'] || | ||
settings['import-x/resolver'] || { | ||
node: settings['import-x/resolve'], | ||
} // backward compatibility | ||
|
||
for (const { enable, options, resolver } of normalizeConfigResolvers( | ||
configResolvers, | ||
sourceFile, | ||
)) { | ||
if (!enable) { | ||
continue | ||
} | ||
} else if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems not covering There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to leave those three in the major version bump. These could potentially be a breaking change (unlike There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, they can still use It is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then no breaking changes, and no regressions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The only default thing that happened here is in the Here is the thing, it is possible to have both node resolvers enabled: // eslint.config.js
export default [
{ files, settings: { 'import-x/resolve': legacy } },
{ files, settings: { 'import-x/resolve': lessLegacy } }
]; Then it just becomes "why my Let's just not overcomplicate things. If they explicitly declare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing We can warn and document if unsupported options passed, it'll fallback to original I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm. You are right. Let's move this to the breaking change then, and no legacy options will be supported. Closing now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still want to support it with my proposal, so I'll continue your work to finish it. |
||
// backward compatibility for very old `import-x/resolve` options that is no longer supported | ||
settings['import-x/resolve'] | ||
) { | ||
const resolveSettings = settings['import-x/resolve'] | ||
|
||
fallbackLegacyNodeResolver ||= createNodeResolver({ | ||
extensions: (resolveSettings.extensions || | ||
settings['import-x/extensions']) as string[] | undefined, | ||
builtinModules: resolveSettings.includeCoreModules !== false, | ||
modules: [ | ||
resolveSettings.moduleDirectory, | ||
...(resolveSettings.paths ?? []), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well. Probably just implements this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That could be confusing between
|
||
].filter(Boolean), | ||
symlinks: resolveSettings.preserveSymlinks ?? true, | ||
}) | ||
|
||
const resolved = fallbackLegacyNodeResolver.resolve(modulePath, sourceFile) | ||
if (resolved.found) { | ||
fileExistsCache.set(cacheKey, resolved.path as string | null) | ||
return resolved | ||
} | ||
|
||
const resolved = resolveWithLegacyResolver( | ||
resolver, | ||
options, | ||
modulePath, | ||
// not found, don't do anything | ||
} else { | ||
const configResolvers = | ||
settings['import-x/resolver-legacy'] || settings['import-x/resolver'] | ||
if (configResolvers) { | ||
for (const { enable, options, resolver } of normalizeConfigResolvers( | ||
configResolvers, | ||
sourceFile, | ||
) | ||
if (!resolved.found) { | ||
continue | ||
} | ||
)) { | ||
if (!enable) { | ||
continue | ||
} | ||
|
||
const resolved = resolveWithLegacyResolver( | ||
resolver, | ||
options, | ||
modulePath, | ||
sourceFile, | ||
) | ||
if (!resolved.found) { | ||
continue | ||
} | ||
|
||
// else, counts | ||
fileExistsCache.set(cacheKey, resolved.path as string | null) | ||
return resolved | ||
// else, counts | ||
fileExistsCache.set(cacheKey, resolved.path as string | null) | ||
return resolved | ||
} | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.