Skip to content

Commit f8d7b82

Browse files
authored
fix(#303): use @nolyfill/is-core-module (#305)
* fix(#303): use @nolyfill/is-core-module * chore: add changeset
1 parent a4c6c78 commit f8d7b82

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

.changeset/dirty-lobsters-behave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-import-resolver-typescript': patch
3+
---
4+
5+
Fix resolve for `node:test`, `node:sea`, and `node:sqlite` without sacrificing installation size

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
}
7676
},
7777
"dependencies": {
78+
"@nolyfill/is-core-module": "1.0.39",
7879
"debug": "^4.3.5",
7980
"enhanced-resolve": "^5.15.0",
8081
"eslint-module-utils": "^2.8.1",

src/index.ts

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

4+
import isNodeCoreModule from '@nolyfill/is-core-module'
55
import debug from 'debug'
66
import type { FileSystem, ResolveOptions, Resolver } from 'enhanced-resolve'
77
import enhancedResolve from 'enhanced-resolve'
@@ -119,15 +119,6 @@ let resolver: Resolver | undefined
119119
const digestHashObject = (value: object | null | undefined) =>
120120
hashObject(value ?? {}).digest('hex')
121121

122-
/**
123-
* Checks if a module is a core module
124-
* module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
125-
* versions of Node.js, we can use module.isBuiltin instead of this function.
126-
*/
127-
function isBuiltin(moduleName: string) {
128-
return builtinModules.includes(moduleName.replace(/^node:/, ''))
129-
}
130-
131122
/**
132123
* @param source the module to resolve; i.e './some-module'
133124
* @param file the importing file's full path; i.e. '/usr/local/bin/file.js'
@@ -172,7 +163,7 @@ export function resolve(
172163

173164
// don't worry about core node/bun modules
174165
if (
175-
isBuiltin(source) ||
166+
isNodeCoreModule(source) ||
176167
isBunModule(source, (process.versions.bun ?? 'latest') as Version)
177168
) {
178169
log('matched core:', source)

tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": "@1stg/tsconfig/node16",
33
"compilerOptions": {
44
"module": "Node16",
5-
"outDir": "./lib"
5+
"outDir": "./lib",
6+
"allowSyntheticDefaultImports": true,
7+
"esModuleInterop": true
68
},
79
"include": ["./src", "./shim.d.ts"]
810
}

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,13 @@ __metadata:
32193219
languageName: node
32203220
linkType: hard
32213221

3222+
"@nolyfill/is-core-module@npm:1.0.39":
3223+
version: 1.0.39
3224+
resolution: "@nolyfill/is-core-module@npm:1.0.39"
3225+
checksum: 0d6e098b871eca71d875651288e1f0fa770a63478b0b50479c99dc760c64175a56b5b04f58d5581bbcc6b552b8191ab415eada093d8df9597ab3423c8cac1815
3226+
languageName: node
3227+
linkType: hard
3228+
32223229
"@npmcli/agent@npm:^2.0.0":
32233230
version: 2.2.0
32243231
resolution: "@npmcli/agent@npm:2.2.0"
@@ -6109,6 +6116,7 @@ __metadata:
61096116
"@changesets/cli": "npm:^2.27.6"
61106117
"@commitlint/cli": "npm:^17.8.1"
61116118
"@mozilla/glean": "npm:^3.0.0"
6119+
"@nolyfill/is-core-module": "npm:1.0.39"
61126120
"@pkgr/rollup": "npm:^4.1.3"
61136121
"@types/debug": "npm:^4.1.12"
61146122
"@types/is-glob": "npm:^4.0.4"

0 commit comments

Comments
 (0)