Skip to content

fix: don't resolve not implemented node modules in bun #402

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

Merged
merged 4 commits into from
Mar 24, 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
7 changes: 7 additions & 0 deletions .changeset/stupid-paths-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"eslint-import-resolver-typescript": patch
---

fix: don't resolve not implemented node modules in `bun`

`is-bun-module` is marked as `dependency`, again, for correctness
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.4kB"
}
]
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@
"peerDependencies": {
"eslint": "*",
"eslint-plugin-import": "*",
"eslint-plugin-import-x": "*",
"is-bun-module": "*"
"eslint-plugin-import-x": "*"
},
"peerDependenciesMeta": {
"eslint-plugin-import": {
"optional": true
},
"eslint-plugin-import-x": {
"optional": true
},
"is-bun-module": {
"optional": true
}
},
"dependencies": {
"debug": "^4.4.0",
"get-tsconfig": "^4.10.0",
"is-bun-module": "^2.0.0",
"rspack-resolver": "^1.2.2",
"stable-hash": "^0.0.5",
"tinyglobby": "^0.2.12"
Expand All @@ -105,7 +102,6 @@
"eslint": "^9.22.0",
"eslint-import-resolver-typescript": "link:.",
"eslint-plugin-import-x": "^4.9.0",
"is-bun-module": "^1.3.0",
"lint-staged": "^15.5.0",
"npm-run-all2": "^7.0.2",
"path-serializer": "^0.3.4",
Expand Down
17 changes: 0 additions & 17 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import fs from 'node:fs'
import { createRequire } from 'node:module'
import path from 'node:path'

import type { IsBunModule } from './types.js'

/**
* For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`.
*/
Expand Down Expand Up @@ -74,17 +71,3 @@ export const toGlobPath = (pathname: string) => pathname.replaceAll('\\', '/')

export const toNativePath = (pathname: string) =>
'/' === path.sep ? pathname : pathname.replaceAll('/', '\\')

let isBunModule: IsBunModule | undefined

const _filename = typeof __filename === 'string' ? __filename : import.meta.url

const DEFAULT_BUN_VERSION = 'latest'

export const isBunBuiltin = (source: string) => {
isBunModule ??= createRequire(_filename)('is-bun-module')
return (
isBunModule!.isBunModule(source, DEFAULT_BUN_VERSION) ||
isBunModule!.isSupportedNodeModule(source, DEFAULT_BUN_VERSION)
)
}
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
createFilesMatcher,
parseTsconfig,
} from 'get-tsconfig'
import { isBunBuiltin } from 'is-bun-module'
import { ResolverFactory } from 'rspack-resolver'
import { stableHash } from 'stable-hash'

import { IMPORT_RESOLVER_NAME, JS_EXT_PATTERN } from './constants.js'
import {
isBunBuiltin,
mangleScopedPackage,
removeQuerystring,
sortProjectsByAffinity,
Expand Down Expand Up @@ -53,6 +53,8 @@ const oxcResolve = (
}
}

const isBun = !!process.versions.bun

export const resolve = (
source: string,
file: string,
Expand All @@ -63,7 +65,7 @@ export const resolve = (
options ||= {}

// don't worry about node/bun core modules
if (isBuiltin(source) || (options.bun && isBunBuiltin(source))) {
if ((isBun || options.bun) ? isBunBuiltin(source) : isBuiltin(source)) {
log('matched core:', source)
return { found: true, path: null }
}
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ export interface TypeScriptResolverOptions extends NapiResolveOptions {
bun?: boolean
noWarnOnMultipleProjects?: boolean
}

export type IsBunModule = typeof import('is-bun-module')
15 changes: 6 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7121,7 +7121,7 @@ __metadata:
eslint-import-resolver-typescript: "link:."
eslint-plugin-import-x: "npm:^4.9.0"
get-tsconfig: "npm:^4.10.0"
is-bun-module: "npm:^1.3.0"
is-bun-module: "npm:^2.0.0"
lint-staged: "npm:^15.5.0"
npm-run-all2: "npm:^7.0.2"
path-serializer: "npm:^0.3.4"
Expand All @@ -7142,14 +7142,11 @@ __metadata:
eslint: "*"
eslint-plugin-import: "*"
eslint-plugin-import-x: "*"
is-bun-module: "*"
peerDependenciesMeta:
eslint-plugin-import:
optional: true
eslint-plugin-import-x:
optional: true
is-bun-module:
optional: true
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -9131,12 +9128,12 @@ __metadata:
languageName: node
linkType: hard

"is-bun-module@npm:^1.3.0":
version: 1.3.0
resolution: "is-bun-module@npm:1.3.0"
"is-bun-module@npm:^2.0.0":
version: 2.0.0
resolution: "is-bun-module@npm:2.0.0"
dependencies:
semver: "npm:^7.6.3"
checksum: 10/b23d9ec7b4d4bfd89e4e72b5cd52e1bc153facad59fdd7394c656f8859a78740ef35996a2066240a32f39cc9a9da4b4eb69e68df3c71755a61ebbaf56d3daef0
semver: "npm:^7.7.1"
checksum: 10/cded5a1a58368b847872d08617975d620ad94426d76a932f3e08d55b4574d199e0a62a4fb024fa2dc444200b71719eb0bffc5d3d1e1cc82e29b293bb8d66a990
languageName: node
linkType: hard

Expand Down