New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cache-loader

Package Overview
Dependencies
Maintainers
6
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-loader - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

21

CHANGELOG.md

@@ -5,2 +5,23 @@ # Change Log

<a name="1.1.0"></a>
# [1.1.0](https://github.com/webpack-contrib/cache-loader/compare/v1.0.3...v1.1.0) (2017-10-09)
### Bug Fixes
* add `cacheIdentifier` to documentation ([9a18ba9](https://github.com/webpack-contrib/cache-loader/commit/9a18ba9))
* upgrade webpack-defaults, add missing dependency ([5025869](https://github.com/webpack-contrib/cache-loader/commit/5025869))
### Features
* invalidate cache ([#9](https://github.com/webpack-contrib/cache-loader/issues/9)) ([663e18a](https://github.com/webpack-contrib/cache-loader/commit/663e18a))
### Performance Improvements
* throw early if file doesn't exists ([#5](https://github.com/webpack-contrib/cache-loader/issues/5)) ([a7f3449](https://github.com/webpack-contrib/cache-loader/commit/a7f3449))
<a name="1.0.3"></a>

@@ -7,0 +28,0 @@ ## [1.0.3](https://github.com/webpack-contrib/cache-loader/compare/v1.0.2...v1.0.3) (2017-04-26)

97

dist/index.js

@@ -17,3 +17,7 @@ 'use strict';

var loaderUtils = require('loader-utils');
var pkgVersion = require('../package.json').version;
var defaultCacheDirectory = path.resolve('.cache-loader');
var ENV = process.env.NODE_ENV || 'development';
function loader() {

@@ -60,2 +64,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

remainingRequest: data.remainingRequest,
cacheIdentifier: data.cacheIdentifier,
dependencies: deps,

@@ -87,58 +92,60 @@ contextDependencies: contextDeps,

var options = loaderUtils.getOptions(this) || {};
var cacheDirectory = options.cacheDirectory || path.resolve('.cache-loader');
var loaderOptions = loaderUtils.getOptions(this) || {};
var defaultOptions = {
cacheDirectory: defaultCacheDirectory,
cacheIdentifier: `cache-loader:${pkgVersion} ${ENV}`
};
var options = Object.assign({}, defaultOptions, loaderOptions);
var cacheIdentifier = options.cacheIdentifier,
cacheDirectory = options.cacheDirectory;
var data = dataInput;
data.remainingRequest = remainingRequest;
var callback = this.async();
var hash = digest(remainingRequest);
var hash = digest(`${cacheIdentifier}\n${remainingRequest}`);
var cacheFile = path.join(cacheDirectory, `${hash}.json`);
data.remainingRequest = remainingRequest;
data.cacheIdentifier = cacheIdentifier;
data.cacheFile = cacheFile;
fs.exists(cacheFile, function (exist) {
if (!exist) {
fs.readFile(cacheFile, 'utf-8', function (readFileErr, content) {
if (readFileErr) {
callback();
return;
}
fs.readFile(cacheFile, 'utf-8', function (readFileErr, content) {
if (readFileErr) {
data.fileExists = true;
var cacheData = void 0;
try {
cacheData = JSON.parse(content);
} catch (e) {
callback();
return;
}
if (cacheData.remainingRequest !== remainingRequest || cacheData.cacheIdentifier !== cacheIdentifier) {
// in case of a hash conflict
callback();
return;
}
async.each(cacheData.dependencies.concat(cacheData.contextDependencies), function (dep, eachCallback) {
fs.stat(dep.path, function (statErr, stats) {
if (statErr) {
eachCallback(statErr);
return;
}
if (stats.mtime.getTime() !== dep.mtime) {
eachCallback(true);
return;
}
eachCallback();
});
}, function (err) {
if (err) {
callback();
return;
}
data.fileExists = true;
var cacheData = void 0;
try {
cacheData = JSON.parse(content);
} catch (e) {
callback();
return;
}
if (cacheData.remainingRequest !== remainingRequest) {
// in case of a hash conflict
callback();
return;
}
async.each(cacheData.dependencies.concat(cacheData.contextDependencies), function (dep, eachCallback) {
fs.stat(dep.path, function (statErr, stats) {
if (statErr) {
eachCallback(statErr);
return;
}
if (stats.mtime.getTime() !== dep.mtime) {
eachCallback(true);
return;
}
eachCallback();
});
}, function (err) {
if (err) {
callback();
return;
}
cacheData.dependencies.forEach(function (dep) {
return _this.addDependency(dep.path);
});
cacheData.contextDependencies.forEach(function (dep) {
return _this.addContextDependency(dep.path);
});
callback.apply(undefined, [null].concat(_toConsumableArray(cacheData.result)));
cacheData.dependencies.forEach(function (dep) {
return _this.addDependency(dep.path);
});
cacheData.contextDependencies.forEach(function (dep) {
return _this.addContextDependency(dep.path);
});
callback.apply(undefined, [null].concat(_toConsumableArray(cacheData.result)));
});

@@ -145,0 +152,0 @@ });

{
"name": "cache-loader",
"version": "1.0.3",
"version": "1.1.0",
"description": "Caches the result of following loaders on disk.",
"author": "Tobias Koppers @sokra",
"license": "MIT",
"main": "dist/cjs.js",
"files": [
"dist"
],
"scripts": {
"test": "jest",
"webpack-defaults": "webpack-defaults",
"start": "yarn run serve:dev src",
"start": "npm run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"clean:dist": "del-cli dist",
"clean": "del-cli dist",
"lint": "eslint --cache src test",
"lint-staged": "lint-staged",
"prebuild": "yarn run clean:dist",
"prepublish": "yarn run build",
"release": "yarn run standard-version",
"prebuild": "npm run clean",
"prepublish": "npm run build",
"release": "standard-version",
"security": "nsp check",
"serve:dev": "nodemon $2 --exec babel-node",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:coverage": "yarn run test:coverage",
"travis:lint": "yarn run lint && yarn run security",
"travis:test": "yarn run test"
"travis:coverage": "npm run test:coverage -- --runInBand",
"travis:lint": "npm run lint && npm run security",
"travis:test": "npm run test -- --runInBand",
"webpack-defaults": "webpack-defaults",
"appveyor:test": "npm run test"
},
"author": "Tobias Koppers @sokra",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:webpack-contrib/cache-loader.git"
},
"dependencies": {
"async": "^2.3.0",
"async": "^2.4.1",
"loader-utils": "^1.1.0",

@@ -37,24 +36,20 @@ "mkdirp": "^0.5.1"

"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-jest": "^19.0.0",
"babel-loader": "^6.4.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.4.0",
"babel-preset-latest": "^6.24.1",
"cross-env": "^4.0.0",
"del-cli": "^0.2.1",
"eslint": "^3.19.0",
"eslint-config-webpack": "^1.2.1",
"eslint-plugin-import": "^2.2.0",
"jest": "^19.0.2",
"lint-staged": "^3.4.0",
"nodemon": "^1.11.0",
"nsp": "^2.6.3",
"babel-cli": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"cross-env": "^5.0.5",
"del-cli": "^1.1.0",
"eslint": "^4.8.0",
"eslint-config-webpack": "^1.2.5",
"eslint-plugin-import": "^2.7.0",
"jest": "^21.2.1",
"lint-staged": "^4.2.3",
"nsp": "^2.8.1",
"pre-commit": "^1.2.2",
"react": "^15.5.4",
"standard-version": "^4.0.0",
"webpack": "^2.4.1",
"webpack-defaults": "^0.4.5"
"standard-version": "^4.1.0",
"webpack": "^3.6.0",
"webpack-defaults": "^1.6.0"
},

@@ -64,5 +59,9 @@ "engines": {

},
"files": [
"dist"
],
"peerDependencies": {
"webpack": "^2.0.0 || ^3.0.0"
},
"repository": {
"type": "git",
"url": "git@github.com:webpack-contrib/cache-loader.git"
},
"pre-commit": "lint-staged",

@@ -69,0 +68,0 @@ "lint-staged": {

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]

@@ -9,6 +10,6 @@ [![test][test]][test-url]

<a href="https://webpack.js.org/">
<img width="200" height="200" vspace="" hspace="25" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
<img width="200" height="200" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
</a>
<h1>cache-loader</h1>
<p>Caches the result of following loaders on disk.</p>
<h1>Cache Loader</h1>
<p>Caches the result of following loaders on disk</p>
</div>

@@ -26,8 +27,32 @@

Note that there is an overhead for saving the reading and saving the cache file, so only use this loader to cache expensive loaders.
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.ext$/,
use: [
'cache-loader',
...loaders
],
include: path.resolve('src')
}
]
}
}
```
> ⚠️ Note that there is an overhead for saving the reading and saving the cache file, so only use this loader to cache expensive loaders.
<h2 align="center">Options</h2>
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`cacheDirectory`**|`{String}`|`path.resolve('.cache-loader')`|Provide a cache directory where cache items should be stored|
|**`cacheIdentifier`**|`{String}`|`cache-loader:{version} {process.env.NODE_ENV}`|Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders.|
<h2 align="center">Examples</h2>
**webpack.config.js**
```js

@@ -39,7 +64,7 @@ module.exports = {

test: /\.js$/,
include: path.resolve("src"),
use: [
"cache-loader",
"babel-loader"
]
'cache-loader',
'babel-loader'
],
include: path.resolve('src')
}

@@ -51,15 +76,25 @@ ]

**with options**
### `Options`
**webpack.config.js**
```js
use: [
{
loader: "cache-loader",
options: {
// provide a cache directory where cache items should be stored
cacheDirectory: path.resolve(".cache")
}
},
"babel-loader"
]
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve('.cache')
}
},
'babel-loader'
],
include: path.resolve('src')
}
]
}
}
```

@@ -76,5 +111,40 @@

</br>
sokra
Tobias Koppers
</a>
</td>
<td align="center">
<a href="https://github.com/bebraw">
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
</br>
Juho Vepsäläinen
</a>
</td>
<td align="center">
<a href="https://github.com/d3viant0ne">
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
</br>
Joshua Wiens
</a>
</td>
<td align="center">
<a href="https://github.com/sapegin">
<img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150">
</br>
Artem Sapegin
</a>
</td>
<td align="center">
<a href="https://github.com/michael-ciniawsky">
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
</br>
Michael Ciniawsky
</a>
</td>
<td align="center">
<a href="https://github.com/evilebottnawi">
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
</br>
Alexander Krasnoyarov
</a>
</td>
</tr>

@@ -84,5 +154,9 @@ <tbody>

[npm]: https://img.shields.io/npm/v/cache-loader.svg
[npm-url]: https://npmjs.com/package/cache-loader
[node]: https://img.shields.io/node/v/cache-loader.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/cache-loader.svg

@@ -89,0 +163,0 @@ [deps-url]: https://david-dm.org/webpack-contrib/cache-loader

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc