Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit 8601da9

Browse files
ricardogobbosouzaevilebottnawi
authored andcommitted
fix: eslint package path for cache (#283)
1 parent bc2216e commit 8601da9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,35 @@ module.exports = function(input, map) {
160160
loaderUtils.getOptions(webpack)
161161
);
162162

163-
var userEslintPath = userOptions.eslintPath;
164-
165163
var eslintPkgPath = "eslint/package.json";
166-
if (userEslintPath) {
167-
eslintPkgPath = userEslintPath + "/package.json";
164+
var userEslintPath = eslintPkgPath;
165+
166+
if (userOptions.eslintPath) {
167+
userEslintPath = userOptions.eslintPath + "/package.json";
168+
}
169+
170+
var eslintVersion;
171+
172+
try {
173+
eslintVersion = require(require.resolve(userEslintPath)).version;
174+
} catch (_) {
175+
// ignored
168176
}
169177

170-
var eslintVersion = require(eslintPkgPath).version;
178+
if (!eslintVersion) {
179+
try {
180+
eslintVersion = require(require.resolve(eslintPkgPath)).version;
181+
} catch (_) {
182+
// ignored
183+
}
184+
}
171185

172186
var config = assign(
173187
// loader defaults
174188
{
175189
cacheIdentifier: JSON.stringify({
176190
"eslint-loader": pkg.version,
177-
eslint: eslintVersion
191+
eslint: eslintVersion || "unknown version"
178192
}),
179193
eslintPath: "eslint"
180194
},

0 commit comments

Comments
 (0)