diff --git a/package-lock.json b/package-lock.json index 6d80794..3101efc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "chalk": "4.1.2", "eslint-import-resolver-node": "0.3.9", "eslint-module-utils": "2.8.1", - "is-core-module": "2.13.1", "micromatch": "4.0.5" }, "devDependencies": { diff --git a/package.json b/package.json index 12100b7..5a88ff0 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "chalk": "4.1.2", "eslint-import-resolver-node": "0.3.9", "eslint-module-utils": "2.8.1", - "is-core-module": "2.13.1", "micromatch": "4.0.5" }, "devDependencies": { diff --git a/src/core/elementsInfo.js b/src/core/elementsInfo.js index 03f10c1..0ef71d5 100644 --- a/src/core/elementsInfo.js +++ b/src/core/elementsInfo.js @@ -1,4 +1,4 @@ -const isCoreModule = require("is-core-module"); +const mod = require("module"); const micromatch = require("micromatch"); const resolve = require("eslint-module-utils/resolve").default; @@ -9,6 +9,14 @@ const { isArray } = require("../helpers/utils"); const { filesCache, importsCache, elementsCache } = require("./cache"); +function isCoreModule(moduleName) { + const moduleNameWithoutPrefix = moduleName.startsWith("node:") + ? moduleName.slice(5) + : moduleName; + + return mod.builtinModules.includes(moduleNameWithoutPrefix); +} + function baseModule(name) { if (isScoped(name)) { const [scope, packageName] = name.split("/"); diff --git a/test/rules/one-level/element-types.spec.js b/test/rules/one-level/element-types.spec.js index 828d193..e666a86 100644 --- a/test/rules/one-level/element-types.spec.js +++ b/test/rules/one-level/element-types.spec.js @@ -166,6 +166,18 @@ const test = (settings, options, errorMessages) => { }, ], }, + // Can import fs module + { + filename: absoluteFilePath("modules/module-a/ModuleA.js"), + code: "import fs from 'fs'", + options, + }, + // Can import node:fs module + { + filename: absoluteFilePath("modules/module-a/ModuleA.js"), + code: "import fs from 'node:fs'", + options, + }, ], invalid: [ // Helpers can't import another if everything is disallowed