diff --git a/.changeset/stupid-paths-rest.md b/.changeset/stupid-paths-rest.md new file mode 100644 index 0000000..c1f2a70 --- /dev/null +++ b/.changeset/stupid-paths-rest.md @@ -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 diff --git a/.size-limit.json b/.size-limit.json index f8a0842..32a6a58 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -1,6 +1,6 @@ [ { "path": "./lib/index.js", - "limit": "1.5kB" + "limit": "1.4kB" } ] diff --git a/package.json b/package.json index e0d9de1..6b3f5e1 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,7 @@ "peerDependencies": { "eslint": "*", "eslint-plugin-import": "*", - "eslint-plugin-import-x": "*", - "is-bun-module": "*" + "eslint-plugin-import-x": "*" }, "peerDependenciesMeta": { "eslint-plugin-import": { @@ -75,14 +74,12 @@ }, "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" @@ -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", diff --git a/src/helpers.ts b/src/helpers.ts index cecfdd3..4bc993e 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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`. */ @@ -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) - ) -} diff --git a/src/index.ts b/src/index.ts index a391db3..34ae9aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, @@ -53,6 +53,8 @@ const oxcResolve = ( } } +const isBun = !!process.versions.bun + export const resolve = ( source: string, file: string, @@ -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 } } diff --git a/src/types.ts b/src/types.ts index 7f5c3e7..8f255a2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,5 +12,3 @@ export interface TypeScriptResolverOptions extends NapiResolveOptions { bun?: boolean noWarnOnMultipleProjects?: boolean } - -export type IsBunModule = typeof import('is-bun-module') diff --git a/yarn.lock b/yarn.lock index 07be1be..9cb7bc8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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 @@ -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