Skip to content

Commit

Permalink
chore(deps): remove is-core-module dependency (#295)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update index.ts

* Create spotty-grapes-draw.md

---------

Co-authored-by: Grigory <[email protected]>
Co-authored-by: JounQin <[email protected]>
  • Loading branch information
3 people authored Jul 14, 2024
1 parent 10f9b17 commit ff3d3c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-grapes-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

chore(deps): remove `is-core-module` dependency
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"eslint-module-utils": "^2.8.1",
"fast-glob": "^3.3.2",
"get-tsconfig": "^4.7.5",
"is-core-module": "^2.13.1",
"is-glob": "^4.0.3"
},
"devDependencies": {
Expand All @@ -91,7 +90,6 @@
"@mozilla/glean": "^3.0.0",
"@pkgr/rollup": "^4.1.3",
"@types/debug": "^4.1.12",
"@types/is-core-module": "^2.2.2",
"@types/is-glob": "^4.0.4",
"@types/node": "^18.19.39",
"@types/unist": "^2.0.10",
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs'
import { builtinModules } from 'node:module'
import path from 'node:path'

import debug from 'debug'
Expand All @@ -8,7 +9,6 @@ import { hashObject } from 'eslint-module-utils/hash.js'
import fg from 'fast-glob'
import { createPathsMatcher, getTsconfig } from 'get-tsconfig'
import type { TsConfigResult } from 'get-tsconfig'
import isCore from 'is-core-module'
import isGlob from 'is-glob'

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

/**
* Checks if a module is a core module
* module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
* versions of Node.js, we can use module.isBuiltin instead of this function.
*/
function isBuiltin(moduleName: string) {
return builtinModules.includes(moduleName.replace(/^node:/, ''))
}

/**
* @param source the module to resolve; i.e './some-module'
* @param file the importing file's full path; i.e. '/usr/local/bin/file.js'
Expand Down Expand Up @@ -160,7 +169,7 @@ export function resolve(
source = removeQuerystring(source)

// don't worry about core node modules
if (isCore(source)) {
if (isBuiltin(source)) {
log('matched core:', source)

return {
Expand Down
11 changes: 1 addition & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3648,13 +3648,6 @@ __metadata:
languageName: node
linkType: hard

"@types/is-core-module@npm:^2.2.2":
version: 2.2.2
resolution: "@types/is-core-module@npm:2.2.2"
checksum: ceee36975a35e45da54973b64bc6d2757e01f6330c0db14ef73131562b397a28a92b387f811e9aa706e1cc02ce44a2720076e61d7c76aa7f54a92a778dcdbe6c
languageName: node
linkType: hard

"@types/is-empty@npm:^1.0.0":
version: 1.2.3
resolution: "@types/is-empty@npm:1.2.3"
Expand Down Expand Up @@ -6118,7 +6111,6 @@ __metadata:
"@mozilla/glean": "npm:^3.0.0"
"@pkgr/rollup": "npm:^4.1.3"
"@types/debug": "npm:^4.1.12"
"@types/is-core-module": "npm:^2.2.2"
"@types/is-glob": "npm:^4.0.4"
"@types/node": "npm:^18.19.39"
"@types/unist": "npm:^2.0.10"
Expand All @@ -6131,7 +6123,6 @@ __metadata:
eslint-plugin-import: "npm:eslint-plugin-i@^2.29.1"
fast-glob: "npm:^3.3.2"
get-tsconfig: "npm:^4.7.5"
is-core-module: "npm:^2.13.1"
is-glob: "npm:^4.0.3"
lint-staged: "npm:^13.3.0"
npm-run-all2: "npm:^5.0.2"
Expand Down Expand Up @@ -7943,7 +7934,7 @@ __metadata:
languageName: node
linkType: hard

"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":
"is-core-module@npm:^2.12.1, is-core-module@npm:^2.13.0, is-core-module@npm:^2.5.0":
version: 2.13.1
resolution: "is-core-module@npm:2.13.1"
dependencies:
Expand Down

0 comments on commit ff3d3c6

Please sign in to comment.