Skip to content

Commit

Permalink
chore: remove "enhanced-resolve" from "no-hide-core-modules"
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Nov 21, 2023
1 parent 8202c24 commit fa5528e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
37 changes: 16 additions & 21 deletions lib/rules/no-hide-core-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"use strict"

const path = require("path")
const resolver = require("enhanced-resolve")
const getPackageJson = require("../util/get-package-json")
const mergeVisitorsInPlace = require("../util/merge-visitors-in-place")
const visitImport = require("../util/visit-import")
Expand All @@ -25,15 +24,17 @@ const CORE_MODULES = new Set([
"crypto",
"dgram",
"dns",
/* "domain", */ "events",
/* "domain", */
"events",
"fs",
"http",
"https",
"module",
"net",
"os",
"path",
/* "punycode", */ "querystring",
/* "punycode", */
"querystring",
"readline",
"repl",
"stream",
Expand Down Expand Up @@ -112,10 +113,6 @@ module.exports = {
),
{
"Program:exit"() {
const requireResolve = resolver.create.sync({
conditionNames: ["node", "import", "require"],
})

for (const target of targets.filter(
t =>
CORE_MODULES.has(t.moduleName) &&
Expand All @@ -131,22 +128,20 @@ module.exports = {
continue
}

try {
const resolved = requireResolve(dirPath, `${name}/`)

context.report({
node: target.node,
loc: target.node.loc,
messageId: "unexpectedImport",
data: {
name: path
.relative(dirPath, resolved)
.replace(BACK_SLASH, "/"),
},
})
} catch {
if (target.filePath == null) {
continue
}

context.report({
node: target.node,
loc: target.node.loc,
messageId: "unexpectedImport",
data: {
name: path
.relative(dirPath, target.filePath)
.replace(BACK_SLASH, "/"),
},
})
}
},
},
Expand Down
6 changes: 5 additions & 1 deletion lib/util/import-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ function getFilePath(id, options, moduleType, moduleStyle) {
conditionNames.push("import", "types")
}

if (moduleStyle === "require" || moduleType === "npm") {
if (
moduleStyle === "require" ||
moduleType === "npm" ||
moduleType === "node"
) {
mainFields.push("main")
mainFiles.push("index")
}
Expand Down

0 comments on commit fa5528e

Please sign in to comment.