Skip to content

Commit

Permalink
Merge pull request #335 from wojtekmaj/no-is-core-module
Browse files Browse the repository at this point in the history
Remove `is-core-module` dependency
  • Loading branch information
javierbrea authored Jul 4, 2024
2 parents 8c1cc8e + 9b92579 commit 521a272
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 9 additions & 1 deletion src/core/elementsInfo.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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("/");
Expand Down
12 changes: 12 additions & 0 deletions test/rules/one-level/element-types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 521a272

Please sign in to comment.