Skip to content

Commit a66d0b0

Browse files
committed
feat: add a new bun?: boolean option
1 parent ca17abb commit a66d0b0

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

.changeset/cuddly-kiwis-drum.md

-5
This file was deleted.

.changeset/lemon-trains-hang.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"eslint-import-resolver-typescript": minor
3+
---
4+
5+
feat: add a new `bun?: boolean` option for `bun` users - close #386
6+
7+
`process.versions.bun` is unavailable even with `bun eslint` due to its own design,
8+
but checking `bun` modules for non-bun users is incorrect behavior and just wasting time,
9+
so a new option is added for such case, you can still run with `bun --bun eslint` without this option enabled

.size-limit.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
33
"path": "./lib/index.js",
4-
"limit": "1.5kB"
4+
"limit": "1.6kB"
55
}
66
]

src/index.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createFilesMatcher,
99
parseTsconfig,
1010
} from 'get-tsconfig'
11-
import { type Version, isBunModule } from 'is-bun-module'
11+
import { type Version, isBunModule, isSupportedNodeModule } from 'is-bun-module'
1212
import { ResolverFactory } from 'rspack-resolver'
1313
import { stableHash } from 'stable-hash'
1414

@@ -60,32 +60,37 @@ export const resolve = (
6060
resolver?: ResolverFactory | null,
6161
// eslint-disable-next-line sonarjs/cognitive-complexity
6262
): ResolvedResult => {
63-
// don't worry about core node/bun modules
64-
if (
65-
module.isBuiltin(source) ||
66-
isBunModule(source, process.versions.bun as Version)
67-
) {
68-
log('matched core:', source)
63+
options ||= {}
6964

70-
return {
71-
found: true,
72-
path: null,
65+
let bunVersion = process.versions.bun as Version | undefined
66+
67+
// don't worry about bun core modules
68+
if (bunVersion || options.bun) {
69+
bunVersion ??= 'latest'
70+
if (
71+
isBunModule(source, bunVersion) ||
72+
isSupportedNodeModule(source, bunVersion)
73+
) {
74+
log('matched bun core:', source)
75+
return { found: true, path: null }
7376
}
77+
} else if (module.isBuiltin(source)) {
78+
// don't worry about node core modules
79+
log('matched node core:', source)
80+
return { found: true, path: null }
7481
}
7582

7683
if (process.versions.pnp && source === 'pnpapi') {
7784
return {
7885
found: true,
79-
path: module.findPnpApi(file).resolveToUnqualified(source, file, {
80-
considerBuiltins: false,
81-
}),
86+
path: module
87+
.findPnpApi(file)
88+
.resolveToUnqualified(source, file, { considerBuiltins: false }),
8289
}
8390
}
8491

8592
source = removeQuerystring(source)
8693

87-
options ||= {}
88-
8994
if (!resolver) {
9095
const optionsHash = stableHash(options)
9196
const cwd = process.cwd()

src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ export interface TypeScriptResolverOptions extends NapiResolveOptions {
66
* @default true - whether to always try to resolve `@types` packages
77
*/
88
alwaysTryTypes?: boolean
9+
/**
10+
* Whether `bun` core modules should be accounted
11+
*/
12+
bun?: boolean
913
noWarnOnMultipleProjects?: boolean
1014
}

0 commit comments

Comments
 (0)