Skip to content

Commit 946a4e0

Browse files
committed
feat: make is-bun-module as optional peer dependency
1 parent 458fdaf commit 946a4e0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@
6565
"peerDependencies": {
6666
"eslint": "*",
6767
"eslint-plugin-import": "*",
68-
"eslint-plugin-import-x": "*"
68+
"eslint-plugin-import-x": "*",
69+
"is-bun-module": "*"
6970
},
7071
"peerDependenciesMeta": {
7172
"eslint-plugin-import": {
7273
"optional": true
7374
},
7475
"eslint-plugin-import-x": {
7576
"optional": true
77+
},
78+
"is-bun-module": {
79+
"optional": true
7680
}
7781
},
7882
"dependencies": {
7983
"debug": "^4.4.0",
8084
"get-tsconfig": "^4.10.0",
81-
"is-bun-module": "^1.3.0",
8285
"rspack-resolver": "^1.1.2",
8386
"stable-hash": "^0.0.5",
8487
"tinyglobby": "^0.2.12"
@@ -100,6 +103,7 @@
100103
"eslint": "^9.22.0",
101104
"eslint-import-resolver-typescript": "link:.",
102105
"eslint-plugin-import-x": "^4.8.0",
106+
"is-bun-module": "^1.3.0",
103107
"lint-staged": "^15.5.0",
104108
"npm-run-all2": "^7.0.2",
105109
"prettier": "^3.5.3",

src/index.ts

+10-3
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, isSupportedNodeModule } from 'is-bun-module'
11+
import { type Version } from 'is-bun-module'
1212
import { ResolverFactory } from 'rspack-resolver'
1313
import { stableHash } from 'stable-hash'
1414

@@ -53,6 +53,11 @@ const oxcResolve = (
5353
}
5454
}
5555

56+
type IsBunModule = typeof import('is-bun-module')
57+
let isBunModule: IsBunModule | undefined
58+
59+
const _filename = typeof __filename === 'string' ? __filename : import.meta.url
60+
5661
export const resolve = (
5762
source: string,
5863
file: string,
@@ -69,8 +74,10 @@ export const resolve = (
6974
if (
7075
bunVersion
7176
? module.isBuiltin(source)
72-
: isBunModule(source, (bunVersion = 'latest')) ||
73-
isSupportedNodeModule(source, bunVersion)
77+
: (isBunModule ??= module.createRequire(_filename)(
78+
'is-bun-module',
79+
) as IsBunModule).isBunModule(source, (bunVersion = 'latest')) ||
80+
isBunModule.isSupportedNodeModule(source, bunVersion)
7481
) {
7582
log('matched bun core:', source)
7683
return { found: true, path: null }

yarn.lock

+3
Original file line numberDiff line numberDiff line change
@@ -6715,11 +6715,14 @@ __metadata:
67156715
eslint: "*"
67166716
eslint-plugin-import: "*"
67176717
eslint-plugin-import-x: "*"
6718+
is-bun-module: "*"
67186719
peerDependenciesMeta:
67196720
eslint-plugin-import:
67206721
optional: true
67216722
eslint-plugin-import-x:
67226723
optional: true
6724+
is-bun-module:
6725+
optional: true
67236726
languageName: unknown
67246727
linkType: soft
67256728

0 commit comments

Comments
 (0)