Skip to content

Commit ff3d3c6

Browse files
wojtekmajSunsetTechuilaJounQin
authored
chore(deps): remove is-core-module dependency (#295)
* chore(deps): remove `is-core-module` dependency Node.js from v6.13.0, v8.10.0, v9.3.0 includes `module.builtinModules` which we can use to natively check if some module belongs to Node.js core or not. This drops not one, but _three_ dependencies, removing 70 KB of bloat: https://npmgraph.js.org/?q=is-core-module * Simplify util Co-authored-by: Grigory <grigory.orlov.set@gmail.com> * Update index.ts * Create spotty-grapes-draw.md --------- Co-authored-by: Grigory <grigory.orlov.set@gmail.com> Co-authored-by: JounQin <admin@1stg.me>
1 parent 10f9b17 commit ff3d3c6

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

.changeset/spotty-grapes-draw.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
chore(deps): remove `is-core-module` dependency

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"eslint-module-utils": "^2.8.1",
8181
"fast-glob": "^3.3.2",
8282
"get-tsconfig": "^4.7.5",
83-
"is-core-module": "^2.13.1",
8483
"is-glob": "^4.0.3"
8584
},
8685
"devDependencies": {
@@ -91,7 +90,6 @@
9190
"@mozilla/glean": "^3.0.0",
9291
"@pkgr/rollup": "^4.1.3",
9392
"@types/debug": "^4.1.12",
94-
"@types/is-core-module": "^2.2.2",
9593
"@types/is-glob": "^4.0.4",
9694
"@types/node": "^18.19.39",
9795
"@types/unist": "^2.0.10",

src/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs'
2+
import { builtinModules } from 'node:module'
23
import path from 'node:path'
34

45
import debug from 'debug'
@@ -8,7 +9,6 @@ import { hashObject } from 'eslint-module-utils/hash.js'
89
import fg from 'fast-glob'
910
import { createPathsMatcher, getTsconfig } from 'get-tsconfig'
1011
import type { TsConfigResult } from 'get-tsconfig'
11-
import isCore from 'is-core-module'
1212
import isGlob from 'is-glob'
1313

1414
const { globSync } = fg
@@ -117,6 +117,15 @@ let resolver: Resolver | undefined
117117
const digestHashObject = (value: object | null | undefined) =>
118118
hashObject(value ?? {}).digest('hex')
119119

120+
/**
121+
* Checks if a module is a core module
122+
* module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
123+
* versions of Node.js, we can use module.isBuiltin instead of this function.
124+
*/
125+
function isBuiltin(moduleName: string) {
126+
return builtinModules.includes(moduleName.replace(/^node:/, ''))
127+
}
128+
120129
/**
121130
* @param source the module to resolve; i.e './some-module'
122131
* @param file the importing file's full path; i.e. '/usr/local/bin/file.js'
@@ -160,7 +169,7 @@ export function resolve(
160169
source = removeQuerystring(source)
161170

162171
// don't worry about core node modules
163-
if (isCore(source)) {
172+
if (isBuiltin(source)) {
164173
log('matched core:', source)
165174

166175
return {

yarn.lock

+1-10
Original file line numberDiff line numberDiff line change
@@ -3648,13 +3648,6 @@ __metadata:
36483648
languageName: node
36493649
linkType: hard
36503650

3651-
"@types/is-core-module@npm:^2.2.2":
3652-
version: 2.2.2
3653-
resolution: "@types/is-core-module@npm:2.2.2"
3654-
checksum: ceee36975a35e45da54973b64bc6d2757e01f6330c0db14ef73131562b397a28a92b387f811e9aa706e1cc02ce44a2720076e61d7c76aa7f54a92a778dcdbe6c
3655-
languageName: node
3656-
linkType: hard
3657-
36583651
"@types/is-empty@npm:^1.0.0":
36593652
version: 1.2.3
36603653
resolution: "@types/is-empty@npm:1.2.3"
@@ -6118,7 +6111,6 @@ __metadata:
61186111
"@mozilla/glean": "npm:^3.0.0"
61196112
"@pkgr/rollup": "npm:^4.1.3"
61206113
"@types/debug": "npm:^4.1.12"
6121-
"@types/is-core-module": "npm:^2.2.2"
61226114
"@types/is-glob": "npm:^4.0.4"
61236115
"@types/node": "npm:^18.19.39"
61246116
"@types/unist": "npm:^2.0.10"
@@ -6131,7 +6123,6 @@ __metadata:
61316123
eslint-plugin-import: "npm:eslint-plugin-i@^2.29.1"
61326124
fast-glob: "npm:^3.3.2"
61336125
get-tsconfig: "npm:^4.7.5"
6134-
is-core-module: "npm:^2.13.1"
61356126
is-glob: "npm:^4.0.3"
61366127
lint-staged: "npm:^13.3.0"
61376128
npm-run-all2: "npm:^5.0.2"
@@ -7943,7 +7934,7 @@ __metadata:
79437934
languageName: node
79447935
linkType: hard
79457936

7946-
"is-core-module@npm:^2.12.1, is-core-module@npm:^2.13.0, is-core-module@npm:^2.13.1, is-core-module@npm:^2.5.0":
7937+
"is-core-module@npm:^2.12.1, is-core-module@npm:^2.13.0, is-core-module@npm:^2.5.0":
79477938
version: 2.13.1
79487939
resolution: "is-core-module@npm:2.13.1"
79497940
dependencies:

0 commit comments

Comments
 (0)