Skip to content

Commit

Permalink
feat: remove "is-builtin-module" dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Apr 8, 2024
1 parent 3791d11 commit 2c4e1f3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
"use strict"

const isBuiltinModule = require("is-builtin-module")
const { isBuiltin } = require("node:module")
const getConfiguredNodeVersion = require("../util/get-configured-node-version")
const getSemverRange = require("../util/get-semver-range")
const visitImport = require("../util/visit-import")
Expand Down Expand Up @@ -150,8 +150,8 @@ module.exports = {
if (
typeof value !== "string" ||
value.startsWith("node:") ||
!isBuiltinModule(value) ||
!isBuiltinModule(`node:${value}`)
!isBuiltin(value) ||
!isBuiltin(`node:${value}`)
) {
continue
}
Expand Down
6 changes: 2 additions & 4 deletions lib/util/extend-trackmap-with-node-prefix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict"

const isBuiltinModule = require("is-builtin-module")
const { isBuiltin } = require("node:module")

/**
* Extend traceMap.modules with `node:` prefixed modules
Expand All @@ -14,9 +14,7 @@ module.exports = function extendTraceMapWithNodePrefix(modules) {
...Object.fromEntries(
Object.entries(modules)
.map(([name, value]) => [`node:${name}`, value])
.filter(([name]) =>
isBuiltinModule(/** @type {string} */ (name))
)
.filter(([name]) => isBuiltin(/** @type {string} */ (name)))
),
}
return ret
Expand Down
4 changes: 2 additions & 2 deletions lib/util/import-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict"

const { resolve } = require("path")
const isBuiltinModule = require("is-builtin-module")
const { isBuiltin } = require("node:module")
const resolver = require("enhanced-resolve")

const isTypescript = require("./is-typescript")
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = class ImportTarget {
return "absolute"
}

if (isBuiltinModule(this.name)) {
if (isBuiltin(this.name)) {
return "node"
}

Expand Down
4 changes: 2 additions & 2 deletions lib/util/visit-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict"

const path = require("path")
const isBuiltinModule = require("is-builtin-module")
const { isBuiltin } = require("node:module")
const getResolvePaths = require("./get-resolve-paths")
const getTryExtensions = require("./get-try-extensions")
const ImportTarget = require("./import-target")
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = function visitImport(
}

const name = stripImportPathParams(node.source?.value)
if (includeCore === true || isBuiltinModule(name) === false) {
if (includeCore === true || isBuiltin(name) === false) {
targets.push(
new ImportTarget(context, node.source, name, options, "import")
)
Expand Down
4 changes: 2 additions & 2 deletions lib/util/visit-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
ReferenceTracker,
getStringIfConstant,
} = require("@eslint-community/eslint-utils")
const isBuiltinModule = require("is-builtin-module")
const { isBuiltin } = require("node:module")
const getResolvePaths = require("./get-resolve-paths")
const getTryExtensions = require("./get-try-extensions")
const ImportTarget = require("./import-target")
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function visitRequire(
}

const name = stripImportPathParams(rawName)
if (includeCore || !isBuiltinModule(name)) {
if (includeCore || !isBuiltin(name)) {
targets.push(
new ImportTarget(
context,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"get-tsconfig": "^4.7.0",
"globals": "^14.0.0",
"ignore": "^5.2.4",
"is-builtin-module": "^3.2.1",
"minimatch": "^9.0.0",
"semver": "^7.5.3"
},
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-missing-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ruleTester.run("no-missing-require", rule, {
filename: fixture("test.js"),
code: "require('node:fs');",
},
{
filename: fixture("test.js"),
code: "require('node:test');",
},
{
filename: fixture("test.js"),
code: "require('eslint');",
Expand Down

0 comments on commit 2c4e1f3

Please sign in to comment.