eslint-loader
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -0,1 +1,6 @@ | ||
# 1.5.0 - 2016-07-28 | ||
- Added: `cache` options | ||
([#93](https://github.com/MoOx/eslint-loader/pull/93) - @genintho) | ||
# 1.4.1 - 2016-06-07 | ||
@@ -2,0 +7,0 @@ |
61
index.js
var eslint = require("eslint") | ||
var assign = require("object-assign") | ||
var loaderUtils = require("loader-utils") | ||
var crypto = require("crypto") | ||
var fs = require("fs") | ||
var findCacheDir = require("find-cache-dir") | ||
var engine = null | ||
var cache = null | ||
var cachePath = null | ||
/** | ||
@@ -14,4 +21,2 @@ * linter | ||
function lint(input, config, webpack) { | ||
var engine = new eslint.CLIEngine(config) | ||
var resourcePath = webpack.resourcePath | ||
@@ -26,3 +31,26 @@ var cwd = process.cwd() | ||
var res = engine.executeOnText(input, resourcePath, true) | ||
var res | ||
// If cache is enable and the data are the same as in the cache, just | ||
// use them | ||
if (config.cache) { | ||
var inputMD5 = crypto.createHash("md5").update(input).digest("hex") | ||
if (cache[resourcePath] && cache[resourcePath].hash === inputMD5) { | ||
res = cache[resourcePath].res | ||
} | ||
} | ||
// Re-lint the text if the cache off or miss | ||
if (!res) { | ||
res = engine.executeOnText(input, resourcePath, true) | ||
// Save new results in the cache | ||
if (config.cache) { | ||
cache[resourcePath] = { | ||
hash: inputMD5, | ||
res: res, | ||
} | ||
fs.writeFileSync(cachePath, JSON.stringify(cache)) | ||
} | ||
} | ||
// executeOnText ensure we will have res.results[0] only | ||
@@ -113,4 +141,31 @@ | ||
this.cacheable() | ||
// Create the engine only once | ||
if (engine === null) { | ||
engine = new eslint.CLIEngine(config) | ||
} | ||
// Read the cached information only once and if enable | ||
if (cache === null) { | ||
if (config.cache) { | ||
var thunk = findCacheDir({ | ||
name: "eslint-loader", | ||
thunk: true, | ||
create: true, | ||
}) | ||
cachePath = thunk("data.json") | ||
try { | ||
cache = require(cachePath) | ||
} | ||
catch (e) { | ||
cache = {} | ||
} | ||
} | ||
else { | ||
cache = false | ||
} | ||
} | ||
lint(input, config, this) | ||
this.callback(null, input, map) | ||
} |
{ | ||
"name": "eslint-loader", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "eslint loader (for webpack)", | ||
@@ -22,2 +22,3 @@ "keywords": [ | ||
"dependencies": { | ||
"find-cache-dir": "^0.1.1", | ||
"loader-utils": "^0.2.7", | ||
@@ -24,0 +25,0 @@ "object-assign": "^4.0.1" |
@@ -97,2 +97,10 @@ # eslint-loader [![Build Status](http://img.shields.io/travis/MoOx/eslint-loader.svg)](https://travis-ci.org/MoOx/eslint-loader) | ||
#### `cache` (default: false) | ||
This option will enable caching of the linting results into a file. | ||
This is particullarly usefull to reduce linting time when doing full build. | ||
The cache is writting inside the `./node_modules/.cache` directory, thanks to the usage | ||
of the [find-cache-dir](https://www.npmjs.com/package/find-cache-dir) module. | ||
#### `formatter` (default: eslint stylish formatter) | ||
@@ -99,0 +107,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14533
151
226
4
3
+ Addedfind-cache-dir@^0.1.1
+ Addedcommondir@1.0.1(transitive)
+ Addedfind-cache-dir@0.1.1(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpkg-dir@1.0.0(transitive)