diff --git a/.changeset/lemon-trains-hang.md b/.changeset/lemon-trains-hang.md new file mode 100644 index 0000000..7a616ee --- /dev/null +++ b/.changeset/lemon-trains-hang.md @@ -0,0 +1,9 @@ +--- +"eslint-import-resolver-typescript": minor +--- + +feat: add a new `bun?: boolean` option for `bun` users - close #386 + +`process.versions.bun` is unavailable even with `bun eslint` due to its own design, +but checking `bun` modules for non-bun users is incorrect behavior and just wasting time, +so a new option is added for such case, you can still run with `bun --bun eslint` without this option enabled diff --git a/.size-limit.json b/.size-limit.json index f8a0842..c601a11 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -1,6 +1,6 @@ [ { "path": "./lib/index.js", - "limit": "1.5kB" + "limit": "1.6kB" } ] diff --git a/src/index.ts b/src/index.ts index 49cc9ab..2574de8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import { createFilesMatcher, parseTsconfig, } from 'get-tsconfig' -import { type Version, isBunModule } from 'is-bun-module' +import { type Version, isBunModule, isSupportedNodeModule } from 'is-bun-module' import { ResolverFactory } from 'rspack-resolver' import { stableHash } from 'stable-hash' @@ -60,33 +60,37 @@ export const resolve = ( resolver?: ResolverFactory | null, // eslint-disable-next-line sonarjs/cognitive-complexity ): ResolvedResult => { - // don't worry about core node/bun modules - if ( - module.isBuiltin(source) || - (process.versions.bun && - isBunModule(source, process.versions.bun as Version)) - ) { - log('matched core:', source) + options ||= {} - return { - found: true, - path: null, + let bunVersion = process.versions.bun as Version | undefined + + // don't worry about bun core modules + if (bunVersion || options.bun) { + bunVersion ??= 'latest' + if ( + isBunModule(source, bunVersion) || + isSupportedNodeModule(source, bunVersion) + ) { + log('matched bun core:', source) + return { found: true, path: null } } + } else if (module.isBuiltin(source)) { + // don't worry about node core modules + log('matched node core:', source) + return { found: true, path: null } } if (process.versions.pnp && source === 'pnpapi') { return { found: true, - path: module.findPnpApi(file).resolveToUnqualified(source, file, { - considerBuiltins: false, - }), + path: module + .findPnpApi(file) + .resolveToUnqualified(source, file, { considerBuiltins: false }), } } source = removeQuerystring(source) - options ||= {} - if (!resolver) { const optionsHash = stableHash(options) const cwd = process.cwd() diff --git a/src/types.ts b/src/types.ts index 1043060..8f255a2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,5 +6,9 @@ export interface TypeScriptResolverOptions extends NapiResolveOptions { * @default true - whether to always try to resolve `@types` packages */ alwaysTryTypes?: boolean + /** + * Whether `bun` core modules should be accounted + */ + bun?: boolean noWarnOnMultipleProjects?: boolean }