Skip to content
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

feat: add a new bun?: boolean option for bun users #387

Merged
merged 3 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/lemon-trains-hang.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"path": "./lib/index.js",
"limit": "1.5kB"
"limit": "1.6kB"
}
]
36 changes: 20 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}