Skip to content

Commit f21bf15

Browse files
fix: don't resolve not implemented node modules in bun (#402)
Co-authored-by: JounQin <[email protected]>
1 parent c8d2f23 commit f21bf15

File tree

7 files changed

+20
-37
lines changed

7 files changed

+20
-37
lines changed

Diff for: .changeset/stupid-paths-rest.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
fix: don't resolve not implemented node modules in `bun`
6+
7+
`is-bun-module` is marked as `dependency`, again, for correctness

Diff for: .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.4kB"
55
}
66
]

Diff for: package.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,20 @@
6666
"peerDependencies": {
6767
"eslint": "*",
6868
"eslint-plugin-import": "*",
69-
"eslint-plugin-import-x": "*",
70-
"is-bun-module": "*"
69+
"eslint-plugin-import-x": "*"
7170
},
7271
"peerDependenciesMeta": {
7372
"eslint-plugin-import": {
7473
"optional": true
7574
},
7675
"eslint-plugin-import-x": {
7776
"optional": true
78-
},
79-
"is-bun-module": {
80-
"optional": true
8177
}
8278
},
8379
"dependencies": {
8480
"debug": "^4.4.0",
8581
"get-tsconfig": "^4.10.0",
82+
"is-bun-module": "^2.0.0",
8683
"rspack-resolver": "^1.2.2",
8784
"stable-hash": "^0.0.5",
8885
"tinyglobby": "^0.2.12"
@@ -105,7 +102,6 @@
105102
"eslint": "^9.22.0",
106103
"eslint-import-resolver-typescript": "link:.",
107104
"eslint-plugin-import-x": "^4.9.0",
108-
"is-bun-module": "^1.3.0",
109105
"lint-staged": "^15.5.0",
110106
"npm-run-all2": "^7.0.2",
111107
"path-serializer": "^0.3.4",

Diff for: src/helpers.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import fs from 'node:fs'
2-
import { createRequire } from 'node:module'
32
import path from 'node:path'
43

5-
import type { IsBunModule } from './types.js'
6-
74
/**
85
* For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`.
96
*/
@@ -74,17 +71,3 @@ export const toGlobPath = (pathname: string) => pathname.replaceAll('\\', '/')
7471

7572
export const toNativePath = (pathname: string) =>
7673
'/' === path.sep ? pathname : pathname.replaceAll('/', '\\')
77-
78-
let isBunModule: IsBunModule | undefined
79-
80-
const _filename = typeof __filename === 'string' ? __filename : import.meta.url
81-
82-
const DEFAULT_BUN_VERSION = 'latest'
83-
84-
export const isBunBuiltin = (source: string) => {
85-
isBunModule ??= createRequire(_filename)('is-bun-module')
86-
return (
87-
isBunModule!.isBunModule(source, DEFAULT_BUN_VERSION) ||
88-
isBunModule!.isSupportedNodeModule(source, DEFAULT_BUN_VERSION)
89-
)
90-
}

Diff for: src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
createFilesMatcher,
99
parseTsconfig,
1010
} from 'get-tsconfig'
11+
import { isBunBuiltin } from 'is-bun-module'
1112
import { ResolverFactory } from 'rspack-resolver'
1213
import { stableHash } from 'stable-hash'
1314

1415
import { IMPORT_RESOLVER_NAME, JS_EXT_PATTERN } from './constants.js'
1516
import {
16-
isBunBuiltin,
1717
mangleScopedPackage,
1818
removeQuerystring,
1919
sortProjectsByAffinity,
@@ -53,6 +53,8 @@ const oxcResolve = (
5353
}
5454
}
5555

56+
const isBun = !!process.versions.bun
57+
5658
export const resolve = (
5759
source: string,
5860
file: string,
@@ -63,7 +65,7 @@ export const resolve = (
6365
options ||= {}
6466

6567
// don't worry about node/bun core modules
66-
if (isBuiltin(source) || (options.bun && isBunBuiltin(source))) {
68+
if ((isBun || options.bun) ? isBunBuiltin(source) : isBuiltin(source)) {
6769
log('matched core:', source)
6870
return { found: true, path: null }
6971
}

Diff for: src/types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@ export interface TypeScriptResolverOptions extends NapiResolveOptions {
1212
bun?: boolean
1313
noWarnOnMultipleProjects?: boolean
1414
}
15-
16-
export type IsBunModule = typeof import('is-bun-module')

Diff for: yarn.lock

+6-9
Original file line numberDiff line numberDiff line change
@@ -7121,7 +7121,7 @@ __metadata:
71217121
eslint-import-resolver-typescript: "link:."
71227122
eslint-plugin-import-x: "npm:^4.9.0"
71237123
get-tsconfig: "npm:^4.10.0"
7124-
is-bun-module: "npm:^1.3.0"
7124+
is-bun-module: "npm:^2.0.0"
71257125
lint-staged: "npm:^15.5.0"
71267126
npm-run-all2: "npm:^7.0.2"
71277127
path-serializer: "npm:^0.3.4"
@@ -7142,14 +7142,11 @@ __metadata:
71427142
eslint: "*"
71437143
eslint-plugin-import: "*"
71447144
eslint-plugin-import-x: "*"
7145-
is-bun-module: "*"
71467145
peerDependenciesMeta:
71477146
eslint-plugin-import:
71487147
optional: true
71497148
eslint-plugin-import-x:
71507149
optional: true
7151-
is-bun-module:
7152-
optional: true
71537150
languageName: unknown
71547151
linkType: soft
71557152

@@ -9131,12 +9128,12 @@ __metadata:
91319128
languageName: node
91329129
linkType: hard
91339130

9134-
"is-bun-module@npm:^1.3.0":
9135-
version: 1.3.0
9136-
resolution: "is-bun-module@npm:1.3.0"
9131+
"is-bun-module@npm:^2.0.0":
9132+
version: 2.0.0
9133+
resolution: "is-bun-module@npm:2.0.0"
91379134
dependencies:
9138-
semver: "npm:^7.6.3"
9139-
checksum: 10/b23d9ec7b4d4bfd89e4e72b5cd52e1bc153facad59fdd7394c656f8859a78740ef35996a2066240a32f39cc9a9da4b4eb69e68df3c71755a61ebbaf56d3daef0
9135+
semver: "npm:^7.7.1"
9136+
checksum: 10/cded5a1a58368b847872d08617975d620ad94426d76a932f3e08d55b4574d199e0a62a4fb024fa2dc444200b71719eb0bffc5d3d1e1cc82e29b293bb8d66a990
91409137
languageName: node
91419138
linkType: hard
91429139

0 commit comments

Comments
 (0)