Skip to content

Commit 55983cf

Browse files
committed
feat: remove dependencies for Node built-ins
1 parent 1752feb commit 55983cf

25 files changed

+64
-104
lines changed

package.json

-10
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
"jackspeak": "=2.1.1",
9494
"jsonc-parser": "=3.2.0",
9595
"linklocal": "^2.8.2",
96-
"lodash.isarray": "^4.0.0",
9796
"markdownlint-cli": "~0.35",
9897
"mocha": "^3.5.3",
9998
"npm-which": "^3.0.1",
@@ -110,23 +109,14 @@
110109
},
111110
"dependencies": {
112111
"@rtsao/scc": "^1.1.0",
113-
"array-includes": "^3.1.8",
114-
"array.prototype.findlastindex": "^1.2.5",
115-
"array.prototype.flat": "^1.3.2",
116-
"array.prototype.flatmap": "^1.3.2",
117112
"debug": "^3.2.7",
118113
"doctrine": "^2.1.0",
119114
"eslint-import-resolver-node": "^0.3.9",
120115
"eslint-module-utils": "^2.12.0",
121-
"hasown": "^2.0.2",
122-
"is-core-module": "^2.15.1",
123116
"is-glob": "^4.0.3",
124117
"minimatch": "^3.1.2",
125-
"object.fromentries": "^2.0.8",
126118
"object.groupby": "^1.0.3",
127-
"object.values": "^1.2.0",
128119
"semver": "^6.3.1",
129-
"string.prototype.trimend": "^1.0.8",
130120
"tsconfig-paths": "^3.15.0"
131121
}
132122
}

resolvers/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ If the resolver cannot resolve `source` relative to `file`, it should just retur
7373
Here is most of the [Node resolver] at the time of this writing. It is just a wrapper around substack/Browserify's synchronous [`resolve`]:
7474

7575
```js
76+
var { isBuiltin } = require('node:module');
7677
var resolve = require('resolve/sync');
77-
var isCoreModule = require('is-core-module');
7878
7979
exports.resolve = function (source, file, config) {
80-
if (isCoreModule(source)) return { found: true, path: null };
80+
if (isBuiltin(source)) return { found: true, path: null };
8181
try {
8282
return { found: true, path: resolve(source, opts(file, config)) };
8383
} catch (err) {

resolvers/node/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3+
const { isBuiltin } = require('node:module');
34
const resolve = require('resolve/sync');
4-
const isCoreModule = require('is-core-module');
55
const path = require('path');
66

77
const log = require('debug')('eslint-plugin-import:resolver:node');
@@ -49,7 +49,7 @@ exports.resolve = function (source, file, config) {
4949
log('Resolving:', source, 'from:', file);
5050
let resolvedPath;
5151

52-
if (isCoreModule(source)) {
52+
if (isBuiltin(source)) {
5353
log('resolved to core');
5454
return { found: true, path: null };
5555
}

resolvers/node/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"homepage": "https://github.com/import-js/eslint-plugin-import",
3232
"dependencies": {
3333
"debug": "^3.2.7",
34-
"is-core-module": "^2.13.0",
3534
"resolve": "^1.22.4"
3635
},
3736
"devDependencies": {

resolvers/webpack/index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
const findRoot = require('find-root');
44
const path = require('path');
5+
const { isBuiltin } = require('node:module');
56
const isEqual = require('lodash/isEqual');
67
const interpret = require('interpret');
78
const existsSync = require('fs').existsSync;
8-
const isCore = require('is-core-module');
99
const resolve = require('resolve/sync');
1010
const semver = require('semver');
11-
const hasOwn = require('hasown');
1211
const isRegex = require('is-regex');
13-
const isArray = Array.isArray;
14-
const keys = Object.keys;
15-
const assign = Object.assign;
1612

1713
const log = require('debug')('eslint-plugin-import:resolver:webpack');
1814

@@ -22,7 +18,7 @@ function registerCompiler(moduleDescriptor) {
2218
if (moduleDescriptor) {
2319
if (typeof moduleDescriptor === 'string') {
2420
require(moduleDescriptor);
25-
} else if (!isArray(moduleDescriptor)) {
21+
} else if (!Array.isArray(moduleDescriptor)) {
2622
moduleDescriptor.register(require(moduleDescriptor.module));
2723
} else {
2824
for (let i = 0; i < moduleDescriptor.length; i++) {
@@ -38,7 +34,7 @@ function registerCompiler(moduleDescriptor) {
3834
}
3935

4036
function findConfigPath(configPath, packageDir) {
41-
const extensions = keys(interpret.extensions).sort(function (a, b) {
37+
const extensions = Object.keys(interpret.extensions).sort(function (a, b) {
4238
return a === '.js' ? -1 : b === '.js' ? 1 : a.length - b.length;
4339
});
4440
let extension;
@@ -79,7 +75,7 @@ function findExternal(source, externals, context, resolveSync) {
7975
if (typeof externals === 'string') { return source === externals; }
8076

8177
// array: recurse
82-
if (isArray(externals)) {
78+
if (Array.isArray(externals)) {
8379
return externals.some(function (e) { return findExternal(source, e, context, resolveSync); });
8480
}
8581

@@ -133,7 +129,7 @@ function findExternal(source, externals, context, resolveSync) {
133129

134130
// else, vanilla object
135131
for (const key in externals) {
136-
if (hasOwn(externals, key) && source === key) {
132+
if (Object.hasOwn(externals, key) && source === key) {
137133
return true;
138134
}
139135
}
@@ -156,7 +152,7 @@ const webpack2DefaultResolveConfig = {
156152
function createWebpack2ResolveSync(webpackRequire, resolveConfig) {
157153
const EnhancedResolve = webpackRequire('enhanced-resolve');
158154

159-
return EnhancedResolve.create.sync(assign({}, webpack2DefaultResolveConfig, resolveConfig));
155+
return EnhancedResolve.create.sync(Object.assign({}, webpack2DefaultResolveConfig, resolveConfig));
160156
}
161157

162158
/**
@@ -178,7 +174,7 @@ function makeRootPlugin(ModulesInRootPlugin, name, root) {
178174
if (typeof root === 'string') {
179175
return new ModulesInRootPlugin(name, root);
180176
}
181-
if (isArray(root)) {
177+
if (Array.isArray(root)) {
182178
return function () {
183179
root.forEach(function (root) {
184180
this.apply(new ModulesInRootPlugin(name, root));
@@ -238,7 +234,7 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
238234
if (
239235
plugin.constructor
240236
&& plugin.constructor.name === 'ResolverPlugin'
241-
&& isArray(plugin.plugins)
237+
&& Array.isArray(plugin.plugins)
242238
) {
243239
resolvePlugins.push.apply(resolvePlugins, plugin.plugins);
244240
}
@@ -401,7 +397,7 @@ exports.resolve = function (source, file, settings) {
401397
webpackConfig = webpackConfig(env, argv);
402398
}
403399

404-
if (isArray(webpackConfig)) {
400+
if (Array.isArray(webpackConfig)) {
405401
webpackConfig = webpackConfig.map((cfg) => {
406402
if (typeof cfg === 'function') {
407403
return cfg(env, argv);
@@ -448,7 +444,7 @@ exports.resolve = function (source, file, settings) {
448444
try {
449445
return { found: true, path: resolveSync(path.dirname(file), source) };
450446
} catch (err) {
451-
if (isCore(source)) {
447+
if (isBuiltin(source)) {
452448
return { found: true, path: null };
453449
}
454450

resolvers/webpack/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
"debug": "^3.2.7",
3535
"enhanced-resolve": "^0.9.1",
3636
"find-root": "^1.1.0",
37-
"hasown": "^2.0.0",
3837
"interpret": "^1.4.0",
39-
"is-core-module": "^2.13.1",
4038
"is-regex": "^1.1.4",
4139
"lodash": "^4.17.21",
4240
"resolve": "^2.0.0-next.5",

src/core/importType.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { isBuiltin } from 'node:module';
12
import { isAbsolute as nodeIsAbsolute, relative, resolve as nodeResolve } from 'path';
2-
import isCoreModule from 'is-core-module';
33

44
import resolve from 'eslint-module-utils/resolve';
55
import { getContextPackagePath } from './packagePath';
@@ -32,7 +32,7 @@ export function isBuiltIn(name, settings, path) {
3232
if (path || !name) { return false; }
3333
const base = baseModule(name);
3434
const extras = settings && settings['import/core-modules'] || [];
35-
return isCoreModule(base) || extras.indexOf(base) > -1;
35+
return isBuiltin(base) || extras.indexOf(base) > -1;
3636
}
3737

3838
const moduleRegExp = /^\w/;

src/exportMap/visitor.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import includes from 'array-includes';
21
import { SourceCode } from 'eslint';
32
import { availableDocStyleParsers, captureDoc } from './doc';
43
import Namespace from './namespace';
@@ -121,11 +120,11 @@ export default class ImportExportVisitorBuilder {
121120
'TSAbstractClassDeclaration',
122121
'TSModuleDeclaration',
123122
];
124-
const exportedDecls = this.ast.body.filter(({ type, id, declarations }) => includes(declTypes, type) && (
123+
const exportedDecls = this.ast.body.filter(({ type, id, declarations }) => declTypes.includes(type) && (
125124
id && id.name === exportedName || declarations && declarations.find((d) => d.id.name === exportedName)
126125
));
127126
if (exportedDecls.length === 0) {
128-
// Export is not referencing any local declaration, must be re-exporting
127+
// Export is not referencing any local declaration, must be re-exported
129128
this.exportMap.namespace.set('default', captureDoc(this.source, this.docStyleParsers, astNode));
130129
return;
131130
}

src/rules/export.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ExportMapBuilder from '../exportMap/builder';
22
import recursivePatternCapture from '../exportMap/patternCapture';
33
import docsUrl from '../docsUrl';
4-
import includes from 'array-includes';
54

65
/*
76
Notes on TypeScript namespaces aka TSModuleDeclaration:
@@ -157,10 +156,10 @@ module.exports = {
157156
const isTypeVariableDecl = node.declaration.kind === 'type';
158157

159158
if (node.declaration.id != null) {
160-
if (includes([
159+
if ([
161160
'TSTypeAliasDeclaration',
162161
'TSInterfaceDeclaration',
163-
], node.declaration.type)) {
162+
].includes(node.declaration.type)) {
164163
addNamed(node.declaration.id.name, node.declaration.id, parent, true);
165164
} else {
166165
addNamed(node.declaration.id.name, node.declaration.id, parent, isTypeVariableDecl);

src/rules/exports-last.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import findLastIndex from 'array.prototype.findlastindex';
2-
31
import docsUrl from '../docsUrl';
42

53
function isNonExportStatement({ type }) {
@@ -22,7 +20,7 @@ module.exports = {
2220
create(context) {
2321
return {
2422
Program({ body }) {
25-
const lastNonExportStatementIndex = findLastIndex(body, isNonExportStatement);
23+
const lastNonExportStatementIndex = body.findLastIndex(isNonExportStatement);
2624

2725
if (lastNonExportStatementIndex !== -1) {
2826
body.slice(0, lastNonExportStatementIndex).forEach((node) => {

src/rules/group-exports.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import docsUrl from '../docsUrl';
2-
import values from 'object.values';
3-
import flat from 'array.prototype.flat';
42

53
const meta = {
64
type: 'suggestion',
@@ -107,8 +105,9 @@ function create(context) {
107105
}
108106

109107
// Report multiple `aggregated exports` from the same module (ES2015 modules)
110-
flat(values(nodes.modules.sources)
111-
.filter((nodesWithSource) => Array.isArray(nodesWithSource) && nodesWithSource.length > 1))
108+
Object.values(nodes.modules.sources)
109+
.filter((nodesWithSource) => Array.isArray(nodesWithSource) && nodesWithSource.length > 1)
110+
.flat()
112111
.forEach((node) => {
113112
context.report({
114113
node,
@@ -127,8 +126,9 @@ function create(context) {
127126
}
128127

129128
// Report multiple `aggregated type exports` from the same module (FLOW ES2015 modules)
130-
flat(values(nodes.types.sources)
131-
.filter((nodesWithSource) => Array.isArray(nodesWithSource) && nodesWithSource.length > 1))
129+
Object.values(nodes.types.sources)
130+
.filter((nodesWithSource) => Array.isArray(nodesWithSource) && nodesWithSource.length > 1)
131+
.flat()
132132
.forEach((node) => {
133133
context.report({
134134
node,

src/rules/no-anonymous-default-export.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
* @author Duncan Beevers
44
*/
55

6-
import hasOwn from 'hasown';
7-
import values from 'object.values';
8-
import fromEntries from 'object.fromentries';
9-
106
import docsUrl from '../docsUrl';
117

128
const defs = {
@@ -60,12 +56,12 @@ const defs = {
6056
},
6157
};
6258

63-
const schemaProperties = fromEntries(values(defs).map((def) => [def.option, {
59+
const schemaProperties = Object.fromEntries(Object.values(defs).map((def) => [def.option, {
6460
description: def.description,
6561
type: 'boolean',
6662
}]));
6763

68-
const defaults = fromEntries(values(defs).map((def) => [def.option, hasOwn(def, 'default') ? def.default : false]));
64+
const defaults = Object.fromEntries(Object.values(defs).map((def) => [def.option, Object.hasOwn(def, 'default') ? def.default : false]));
6965

7066
module.exports = {
7167
meta: {

src/rules/no-duplicates.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getSourceCode } from 'eslint-module-utils/contextCompat';
22
import resolve from 'eslint-module-utils/resolve';
33
import semver from 'semver';
4-
import flatMap from 'array.prototype.flatmap';
54

65
import docsUrl from '../docsUrl';
76

@@ -95,7 +94,7 @@ function getFix(first, rest, sourceCode, context) {
9594
}
9695

9796
const defaultImportNames = new Set(
98-
flatMap([].concat(first, rest || []), (x) => getDefaultImportName(x) || []),
97+
[].concat(first, rest || []).flatMap((x) => getDefaultImportName(x) || []),
9998
);
10099

101100
// Bail if there are multiple different default import names – it's up to the

src/rules/no-unused-modules.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import resolve from 'eslint-module-utils/resolve';
1010
import visit from 'eslint-module-utils/visit';
1111
import { dirname, join, resolve as resolvePath } from 'path';
1212
import readPkgUp from 'eslint-module-utils/readPkgUp';
13-
import values from 'object.values';
14-
import includes from 'array-includes';
15-
import flatMap from 'array.prototype.flatmap';
1613

1714
import { walkSync } from '../core/fsWalk';
1815
import ExportMapBuilder from '../exportMap/builder';
@@ -97,8 +94,7 @@ function listFilesWithLegacyFunctions(src, extensions) {
9794
listFilesToProcess: originalListFilesToProcess,
9895
} = require('eslint/lib/util/glob-util');
9996
const patterns = src.concat(
100-
flatMap(
101-
src,
97+
src.flatMap(
10298
(pattern) => extensions.map((extension) => (/\*\*|\*\./).test(pattern) ? pattern : `${pattern}/**/*${extension}`),
10399
),
104100
);
@@ -310,7 +306,7 @@ function resolveFiles(src, ignoreExports, context) {
310306
// prepare list of source files, don't consider files from node_modules
311307
const resolvedFiles = srcFileList.length && typeof srcFileList[0] === 'string'
312308
? srcFileList.filter((filePath) => !isNodeModule(filePath))
313-
: flatMap(srcFileList, ({ filename }) => isNodeModule(filename) ? [] : filename);
309+
: srcFileList.flatMap(({ filename }) => isNodeModule(filename) ? [] : filename);
314310

315311
return new Set(resolvedFiles);
316312
}
@@ -494,9 +490,9 @@ const fileIsInPkg = (file) => {
494490
};
495491

496492
const checkPkgFieldObject = (pkgField) => {
497-
const pkgFieldFiles = flatMap(values(pkgField), (value) => typeof value === 'boolean' ? [] : join(basePath, value));
493+
const pkgFieldFiles = Object.values(pkgField).flatMap((value) => typeof value === 'boolean' ? [] : join(basePath, value));
498494

499-
if (includes(pkgFieldFiles, file)) {
495+
if (pkgFieldFiles.includes(file)) {
500496
return true;
501497
}
502498
};

0 commit comments

Comments
 (0)