From 5d451c510c15abc41b5bb14b4955a7db96aeb100 Mon Sep 17 00:00:00 2001 From: Matt Grande Date: Thu, 29 Nov 2018 07:26:02 -0500 Subject: [PATCH] Chore: Remove dependency on is-resolvable (#11128) As is-resolvable is essentially a fancy if statement, and it is only used in one file, it seems unnecessary to include it as a dependency. (I've become paranoid due to what recently happened to [event-stream](https://github.com/dominictarr/event-stream/issues/116) and other similar issues) --- lib/config.js | 17 +++++++++++++++-- package.json | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/config.js b/lib/config.js index 8ea9aeb6f37..abcb38b50d5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -15,8 +15,7 @@ const path = require("path"), ConfigFile = require("./config/config-file"), ConfigCache = require("./config/config-cache"), Plugins = require("./config/plugins"), - FileFinder = require("./util/file-finder"), - isResolvable = require("is-resolvable"); + FileFinder = require("./util/file-finder"); const debug = require("debug")("eslint:config"); @@ -41,6 +40,20 @@ function hasRules(options) { return options.rules && Object.keys(options.rules).length > 0; } +/** + * Determines if a module is can be resolved. + * @param {string} moduleId The ID (name) of the module + * @returns {boolean} True if it is resolvable; False otherwise. + */ +function isResolvable(moduleId) { + try { + require.resolve(moduleId); + return true; + } catch (err) { + return false; + } +} + //------------------------------------------------------------------------------ // API //------------------------------------------------------------------------------ diff --git a/package.json b/package.json index c64318d0b1c..2cbe9f0b37d 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "ignore": "^4.0.6", "imurmurhash": "^0.1.4", "inquirer": "^6.1.0", - "is-resolvable": "^1.1.0", "js-yaml": "^3.12.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0",