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

feat: remove "is-builtin-module" dependency (fixes #232) #227

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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');",
},
Comment on lines +39 to +42
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added node:test as it's new enough that is-builtin-module does not have it 👀

{
filename: fixture("test.js"),
code: "require('eslint');",
Expand Down