Skip to content
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

chore(deps): remove is-core-module dependency #295

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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,5 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { builtinModules } from 'node:module';

import debug from 'debug'
import type { FileSystem, ResolveOptions, Resolver } from 'enhanced-resolve'
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
Loading