node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+159
View File
@@ -0,0 +1,159 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="2.0.1"></a>
## [2.0.1](https://github.com/webpack-contrib/cache-loader/compare/v2.0.0...v2.0.1) (2019-01-04)
### Bug Fixes
* generate normalized cache context relative paths ([#54](https://github.com/webpack-contrib/cache-loader/issues/54)) ([5b37474](https://github.com/webpack-contrib/cache-loader/commit/5b37474))
<a name="2.0.0"></a>
# [2.0.0](https://github.com/webpack-contrib/cache-loader/compare/v1.2.5...v2.0.0) (2018-12-21)
### Chores
* drop support for `webpack` < 4 ([#51](https://github.com/webpack-contrib/cache-loader/issues/51)) ([2e76d3f](https://github.com/webpack-contrib/cache-loader/commit/2e76d3f))
* drop support for node < 6 ([#50](https://github.com/webpack-contrib/cache-loader/issues/50)) ([b8225cd](https://github.com/webpack-contrib/cache-loader/commit/b8225cd))
### Features
* add `cacheContext` option ([#49](https://github.com/webpack-contrib/cache-loader/issues/49)) ([22d0173](https://github.com/webpack-contrib/cache-loader/commit/22d0173))
### BREAKING CHANGES
* drop support for `webpack` < 4
* drop support for node < 6
<a name="1.2.5"></a>
## [1.2.5](https://github.com/webpack-contrib/cache-loader/compare/v1.2.4...v1.2.5) (2018-10-31)
### Bug Fixes
* **index:** `this` of `stat` method is `undefined` ([#47](https://github.com/webpack-contrib/cache-loader/issues/47)) ([5c67ccd](https://github.com/webpack-contrib/cache-loader/commit/5c67ccd))
<a name="1.2.4"></a>
## [1.2.4](https://github.com/webpack-contrib/cache-loader/compare/v1.2.3...v1.2.4) (2018-10-31)
### Bug Fixes
* **index:** fallback to `fs` if `this.fs` is `undefined` ([#45](https://github.com/webpack-contrib/cache-loader/issues/45)) ([b84d13e](https://github.com/webpack-contrib/cache-loader/commit/b84d13e))
<a name="1.2.3"></a>
## [1.2.3](https://github.com/webpack-contrib/cache-loader/compare/v1.2.2...v1.2.3) (2018-10-30)
### Performance Improvements
* **index:** use the `compiler`'s cached `fs` for stats (`this.fs.stat`) ([#42](https://github.com/webpack-contrib/cache-loader/issues/42)) ([d8c630b](https://github.com/webpack-contrib/cache-loader/commit/d8c630b))
<a name="1.2.2"></a>
## [1.2.2](https://github.com/webpack-contrib/cache-loader/compare/v1.2.1...v1.2.2) (2018-02-27)
### Performance Improvements
* use `neo-async` instead `async` ([#31](https://github.com/webpack-contrib/cache-loader/issues/31)) ([0851582](https://github.com/webpack-contrib/cache-loader/commit/0851582))
<a name="1.2.1"></a>
## [1.2.1](https://github.com/webpack-contrib/cache-loader/compare/v1.2.0...v1.2.1) (2018-02-26)
### Bug Fixes
* **package:** add `webpack >= v4.0.0` (`peerDependencies`) ([#32](https://github.com/webpack-contrib/cache-loader/issues/32)) ([a5e921c](https://github.com/webpack-contrib/cache-loader/commit/a5e921c))
<a name="1.2.0"></a>
# [1.2.0](https://github.com/webpack-contrib/cache-loader/compare/v1.1.0...v1.2.0) (2017-11-17)
### Bug Fixes
* **index:** check for inaccurate filesystem (`mtime`) ([f24f723](https://github.com/webpack-contrib/cache-loader/commit/f24f723))
### Features
* add `options` validation (`schema-utils`) ([#24](https://github.com/webpack-contrib/cache-loader/issues/24)) ([4ac7807](https://github.com/webpack-contrib/cache-loader/commit/4ac7807))
* add support for custom cache stores (`options.read/options.write`) ([#19](https://github.com/webpack-contrib/cache-loader/issues/19)) ([060796b](https://github.com/webpack-contrib/cache-loader/commit/060796b))
<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>
## [1.0.3](https://github.com/webpack-contrib/cache-loader/compare/v1.0.2...v1.0.3) (2017-04-26)
### Bug Fixes
* **readme:** remove typo and add additional note ([cc63a7f](https://github.com/webpack-contrib/cache-loader/commit/cc63a7f))
<a name="1.0.2"></a>
## [1.0.2](https://github.com/webpack-contrib/cache-loader/compare/v1.0.1...v1.0.2) (2017-04-26)
### Bug Fixes
* **readme:** fill content into the README ([7b5d5fd](https://github.com/webpack-contrib/cache-loader/commit/7b5d5fd))
<a name="1.0.1"></a>
## 1.0.1 (2017-04-26)
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
x.x.x / <year>-<month>-<day>
==================
* Bug fix -
* Feature -
* Chore -
* Docs -
+20
View File
@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+176
View File
@@ -0,0 +1,176 @@
<div align="center">
<a href="https://webpack.js.org/">
<img width="200" height="200" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
</a>
</div>
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
[![size][size]][size-url]
# cache-loader
The `cache-loader` allow to Caches the result of following loaders on disk (default) or in the database.
## Getting Started
To begin, you'll need to install `cache-loader`:
```console
npm install --save-dev cache-loader
```
Add this loader in front of other (expensive) loaders to cache the result on disk.
**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.
## Options
| Name | Type | Default | Description |
| :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths |
| **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator |
| **`cacheDirectory`** | `{String}` | `path.resolve('.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) |
| **`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 (used for default read/write implementation) |
| **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) |
| **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file |
## Examples
### Basic
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: ['cache-loader', 'babel-loader'],
include: path.resolve('src'),
},
],
},
};
```
### Database Integration
**webpack.config.js**
```js
// Or different database client - memcached, mongodb, ...
const redis = require('redis');
const crypto = require('crypto');
// ...
// connect to client
// ...
const BUILD_CACHE_TIMEOUT = 24 * 3600; // 1 day
function digest(str) {
return crypto
.createHash('md5')
.update(str)
.digest('hex');
}
// Generate own cache key
function cacheKey(options, request) {
return `build:cache:${digest(request)}`;
}
// Read data from database and parse them
function read(key, callback) {
client.get(key, (err, result) => {
if (err) {
return callback(err);
}
if (!result) {
return callback(new Error(`Key ${key} not found`));
}
try {
let data = JSON.parse(result);
callback(null, data);
} catch (e) {
callback(e);
}
});
}
// Write data to database under cacheKey
function write(key, data, callback) {
client.set(key, JSON.stringify(data), 'EX', BUILD_CACHE_TIMEOUT, callback);
}
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'cache-loader',
options: {
cacheKey,
read,
write,
},
},
'babel-loader',
],
include: path.resolve('src'),
},
],
},
};
```
## Contributing
Please take a moment to read our contributing guidelines if you haven't yet done so.
[CONTRIBUTING](./.github/CONTRIBUTING.md)
## License
[MIT](./LICENSE)
[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
[deps-url]: https://david-dm.org/webpack-contrib/cache-loader
[tests]: https://img.shields.io/circleci/project/github/webpack-contrib/cache-loader.svg
[tests-url]: https://circleci.com/gh/webpack-contrib/cache-loader
[cover]: https://codecov.io/gh/webpack-contrib/cache-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/cache-loader
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[size]: https://packagephobia.now.sh/badge?p=cache-loader
[size-url]: https://packagephobia.now.sh/result?p=cache-loader
+3
View File
@@ -0,0 +1,3 @@
"use strict";
module.exports = require('./index');
+225
View File
@@ -0,0 +1,225 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = loader;
exports.pitch = pitch;
/* eslint-disable
import/order
*/
const fs = require('fs');
const path = require('path');
const normalizePath = require('normalize-path');
const async = require('neo-async');
const crypto = require('crypto');
const mkdirp = require('mkdirp');
const {
getOptions
} = require('loader-utils');
const validateOptions = require('schema-utils');
const pkg = require('../package.json');
const env = process.env.NODE_ENV || 'development';
const schema = require('./options.json');
const defaults = {
cacheContext: '',
cacheDirectory: path.resolve('.cache-loader'),
cacheIdentifier: `cache-loader:${pkg.version} ${env}`,
cacheKey,
read,
write
};
function pathWithCacheContext(cacheContext, originalPath) {
if (!cacheContext) {
return originalPath;
}
if (originalPath.includes(cacheContext)) {
return originalPath.split('!').map(subPath => normalizePath(path.relative(cacheContext, subPath))).join('!');
}
return originalPath.split('!').map(subPath => normalizePath(path.resolve(cacheContext, subPath))).join('!');
}
function loader(...args) {
const options = Object.assign({}, defaults, getOptions(this));
validateOptions(schema, options, 'Cache Loader');
const {
write: writeFn
} = options;
const callback = this.async();
const {
data
} = this;
const dependencies = this.getDependencies().concat(this.loaders.map(l => l.path));
const contextDependencies = this.getContextDependencies(); // Should the file get cached?
let cache = true; // this.fs can be undefined
// e.g when using the thread-loader
// fallback to the fs module
const FS = this.fs || fs;
const toDepDetails = (dep, mapCallback) => {
FS.stat(dep, (err, stats) => {
if (err) {
mapCallback(err);
return;
}
const mtime = stats.mtime.getTime();
if (mtime / 1000 >= Math.floor(data.startTime / 1000)) {
// Don't trust mtime.
// File was changed while compiling
// or it could be an inaccurate filesystem.
cache = false;
}
mapCallback(null, {
path: pathWithCacheContext(options.cacheContext, dep),
mtime
});
});
};
async.parallel([cb => async.mapLimit(dependencies, 20, toDepDetails, cb), cb => async.mapLimit(contextDependencies, 20, toDepDetails, cb)], (err, taskResults) => {
if (err) {
callback(null, ...args);
return;
}
if (!cache) {
callback(null, ...args);
return;
}
const [deps, contextDeps] = taskResults;
writeFn(data.cacheKey, {
remainingRequest: data.remainingRequest,
dependencies: deps,
contextDependencies: contextDeps,
result: args
}, () => {
// ignore errors here
callback(null, ...args);
});
});
}
function pitch(remainingRequest, prevRequest, dataInput) {
const options = Object.assign({}, defaults, getOptions(this));
validateOptions(schema, options, 'Cache Loader (Pitch)');
const {
read: readFn,
cacheContext,
cacheKey: cacheKeyFn
} = options;
const callback = this.async();
const data = dataInput;
data.remainingRequest = pathWithCacheContext(cacheContext, remainingRequest);
data.cacheKey = cacheKeyFn(options, data.remainingRequest);
readFn(data.cacheKey, (readErr, cacheData) => {
if (readErr) {
callback();
return;
}
if (cacheData.remainingRequest !== data.remainingRequest) {
// in case of a hash conflict
callback();
return;
}
const FS = this.fs || fs;
async.each(cacheData.dependencies.concat(cacheData.contextDependencies), (dep, eachCallback) => {
FS.stat(dep.path, (statErr, stats) => {
if (statErr) {
eachCallback(statErr);
return;
}
if (stats.mtime.getTime() !== dep.mtime) {
eachCallback(true);
return;
}
eachCallback();
});
}, err => {
if (err) {
data.startTime = Date.now();
callback();
return;
}
cacheData.dependencies.forEach(dep => this.addDependency(pathWithCacheContext(cacheContext, dep.path)));
cacheData.contextDependencies.forEach(dep => this.addContextDependency(pathWithCacheContext(cacheContext, dep.path)));
callback(null, ...cacheData.result);
});
});
}
function digest(str) {
return crypto.createHash('md5').update(str).digest('hex');
}
const directories = new Set();
function write(key, data, callback) {
const dirname = path.dirname(key);
const content = JSON.stringify(data);
if (directories.has(dirname)) {
// for performance skip creating directory
fs.writeFile(key, content, 'utf-8', callback);
} else {
mkdirp(dirname, mkdirErr => {
if (mkdirErr) {
callback(mkdirErr);
return;
}
directories.add(dirname);
fs.writeFile(key, content, 'utf-8', callback);
});
}
}
function read(key, callback) {
fs.readFile(key, 'utf-8', (err, content) => {
if (err) {
callback(err);
return;
}
try {
const data = JSON.parse(content);
callback(null, data);
} catch (e) {
callback(e);
}
});
}
function cacheKey(options, request) {
const {
cacheIdentifier,
cacheDirectory
} = options;
const hash = digest(`${cacheIdentifier}\n${request}`);
return path.join(cacheDirectory, `${hash}.json`);
}
+24
View File
@@ -0,0 +1,24 @@
{
"type": "object",
"properties": {
"cacheContext": {
"type": "string"
},
"cacheKey": {
"instanceof": "Function"
},
"cacheIdentifier": {
"type": "string"
},
"cacheDirectory": {
"type": "string"
},
"read": {
"instanceof": "Function"
},
"write": {
"instanceof": "Function"
}
},
"additionalProperties": false
}
+134
View File
@@ -0,0 +1,134 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="1.0.0"></a>
# [1.0.0](https://github.com/webpack-contrib/schema-utils/compare/v0.4.7...v1.0.0) (2018-08-07)
### Features
* **src:** add support for custom error messages ([#33](https://github.com/webpack-contrib/schema-utils/issues/33)) ([1cbe4ef](https://github.com/webpack-contrib/schema-utils/commit/1cbe4ef))
<a name="0.4.7"></a>
## [0.4.7](https://github.com/webpack-contrib/schema-utils/compare/v0.4.6...v0.4.7) (2018-08-07)
### Bug Fixes
* **src:** `node >= v4.0.0` support ([#32](https://github.com/webpack-contrib/schema-utils/issues/32)) ([cb13dd4](https://github.com/webpack-contrib/schema-utils/commit/cb13dd4))
<a name="0.4.6"></a>
## [0.4.6](https://github.com/webpack-contrib/schema-utils/compare/v0.4.5...v0.4.6) (2018-08-06)
### Bug Fixes
* **package:** remove lockfile ([#28](https://github.com/webpack-contrib/schema-utils/issues/28)) ([69f1a81](https://github.com/webpack-contrib/schema-utils/commit/69f1a81))
* **package:** remove unnecessary `webpack` dependency ([#26](https://github.com/webpack-contrib/schema-utils/issues/26)) ([532eaa5](https://github.com/webpack-contrib/schema-utils/commit/532eaa5))
<a name="0.4.5"></a>
## [0.4.5](https://github.com/webpack-contrib/schema-utils/compare/v0.4.4...v0.4.5) (2018-02-13)
### Bug Fixes
* **CHANGELOG:** update broken links ([4483b9f](https://github.com/webpack-contrib/schema-utils/commit/4483b9f))
* **package:** update broken links ([f2494ba](https://github.com/webpack-contrib/schema-utils/commit/f2494ba))
<a name="0.4.4"></a>
## [0.4.4](https://github.com/webpack-contrib/schema-utils/compare/v0.4.3...v0.4.4) (2018-02-13)
### Bug Fixes
* **package:** update `dependencies` ([#22](https://github.com/webpack-contrib/schema-utils/issues/22)) ([3aecac6](https://github.com/webpack-contrib/schema-utils/commit/3aecac6))
<a name="0.4.3"></a>
## [0.4.3](https://github.com/webpack-contrib/schema-utils/compare/v0.4.2...v0.4.3) (2017-12-14)
### Bug Fixes
* **validateOptions:** throw `err` instead of `process.exit(1)` ([#17](https://github.com/webpack-contrib/schema-utils/issues/17)) ([c595eda](https://github.com/webpack-contrib/schema-utils/commit/c595eda))
* **ValidationError:** never return `this` in the ctor ([#16](https://github.com/webpack-contrib/schema-utils/issues/16)) ([c723791](https://github.com/webpack-contrib/schema-utils/commit/c723791))
<a name="0.4.2"></a>
## [0.4.2](https://github.com/webpack-contrib/schema-utils/compare/v0.4.1...v0.4.2) (2017-11-09)
### Bug Fixes
* **validateOptions:** catch `ValidationError` and handle it internally ([#15](https://github.com/webpack-contrib/schema-utils/issues/15)) ([9c5ef5e](https://github.com/webpack-contrib/schema-utils/commit/9c5ef5e))
<a name="0.4.1"></a>
## [0.4.1](https://github.com/webpack-contrib/schema-utils/compare/v0.4.0...v0.4.1) (2017-11-03)
### Bug Fixes
* **ValidationError:** use `Error.captureStackTrace` for `err.stack` handling ([#14](https://github.com/webpack-contrib/schema-utils/issues/14)) ([a6fb974](https://github.com/webpack-contrib/schema-utils/commit/a6fb974))
<a name="0.4.0"></a>
# [0.4.0](https://github.com/webpack-contrib/schema-utils/compare/v0.3.0...v0.4.0) (2017-10-28)
### Features
* add support for `typeof`, `instanceof` (`{Function\|RegExp}`) ([#10](https://github.com/webpack-contrib/schema-utils/issues/10)) ([9f01816](https://github.com/webpack-contrib/schema-utils/commit/9f01816))
<a name="0.3.0"></a>
# [0.3.0](https://github.com/webpack-contrib/schema-utils/compare/v0.2.1...v0.3.0) (2017-04-29)
### Features
* add ValidationError ([#8](https://github.com/webpack-contrib/schema-utils/issues/8)) ([d48f0fb](https://github.com/webpack-contrib/schema-utils/commit/d48f0fb))
<a name="0.2.1"></a>
## [0.2.1](https://github.com/webpack-contrib/schema-utils/compare/v0.2.0...v0.2.1) (2017-03-13)
### Bug Fixes
* Include .babelrc to `files` ([28f0363](https://github.com/webpack-contrib/schema-utils/commit/28f0363))
* Include source to `files` ([43b0f2f](https://github.com/webpack-contrib/schema-utils/commit/43b0f2f))
<a name="0.2.0"></a>
# [0.2.0](https://github.com/webpack-contrib/schema-utils/compare/v0.1.0...v0.2.0) (2017-03-12)
<a name="0.1.0"></a>
# 0.1.0 (2017-03-07)
### Features
* **validations:** add validateOptions module ([ae9b47b](https://github.com/webpack-contrib/schema-utils/commit/ae9b47b))
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+20
View File
@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+149
View File
@@ -0,0 +1,149 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
<div align="center">
<a href="http://json-schema.org">
<img width="160" height="160"
src="https://raw.githubusercontent.com/webpack-contrib/schema-utils/master/docs/logo.png">
</a>
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Schema Utils</h1>
</div>
<h2 align="center">Install</h2>
```bash
npm i schema-utils
```
<h2 align="center">Usage</h2>
### `validateOptions`
**`schema.json`**
```js
{
"type": "object",
"properties": {
// Options...
},
"additionalProperties": false
}
```
#### Error Messages (Custom)
**`schema.json`**
```js
{
"type": "object",
"properties": {
"option": {
"type": [ "boolean" ]
}
},
// Overrides the default err.message for option
"errorMessage": {
"option": "should be {Boolean} (https:/github.com/org/repo#anchor)"
}
"additionalProperties": false
}
```
```js
import schema from 'path/to/schema.json'
import validateOptions from 'schema-utils'
validateOptions(schema, options, 'Loader/Plugin Name')
```
<h2 align="center">Examples</h2>
**schema.json**
```json
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"test": {
"anyOf": [
{ "type": "array" },
{ "type": "string" },
{ "instanceof": "RegExp" }
]
},
"transform": {
"instanceof": "Function"
},
"sourceMap": {
"type": "boolean"
}
},
"additionalProperties": false
}
```
### `Loader`
```js
import { getOptions } from 'loader-utils'
import validateOptions from 'schema-utils'
import schema from 'path/to/schema.json'
function loader (src, map) {
const options = getOptions(this) || {}
validateOptions(schema, options, 'Loader Name')
// Code...
}
```
### `Plugin`
```js
import validateOptions from 'schema-utils'
import schema from 'path/to/schema.json'
class Plugin {
constructor (options) {
validateOptions(schema, options, 'Plugin Name')
this.options = options
}
apply (compiler) {
// Code...
}
}
```
[npm]: https://img.shields.io/npm/v/schema-utils.svg
[npm-url]: https://npmjs.com/package/schema-utils
[node]: https://img.shields.io/node/v/schema-utils.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/schema-utils.svg
[deps-url]: https://david-dm.org/webpack-contrib/schema-utils
[test]: http://img.shields.io/travis/webpack-contrib/schema-utils.svg
[test-url]: https://travis-ci.org/webpack-contrib/schema-utils
[cover]: https://codecov.io/gh/webpack-contrib/schema-utils/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/schema-utils
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
+74
View File
@@ -0,0 +1,74 @@
{
"_from": "schema-utils@^1.0.0",
"_id": "schema-utils@1.0.0",
"_inBundle": false,
"_integrity": "sha512-i27Mic4KovM/lnGsy8whRCHhc7VicJajAjTrYg11K9zfZXnYIt4k5F+kZkwjnrhKzLic/HLU4j11mjsz2G/75g==",
"_location": "/cache-loader/schema-utils",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "schema-utils@^1.0.0",
"name": "schema-utils",
"escapedName": "schema-utils",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/cache-loader"
],
"_resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz",
"_shasum": "0b79a93204d7b600d4b2850d1f66c2a34951c770",
"_spec": "schema-utils@^1.0.0",
"_where": "D:\\Atom\\Git\\Laravel_CSSd\\node_modules\\cache-loader",
"author": {
"name": "webpack Contrib",
"url": "https://github.com/webpack-contrib"
},
"bugs": {
"url": "https://github.com/webpack-contrib/schema-utils/issues"
},
"bundleDependencies": false,
"dependencies": {
"ajv": "^6.1.0",
"ajv-errors": "^1.0.0",
"ajv-keywords": "^3.1.0"
},
"deprecated": false,
"description": "webpack Validation Utils",
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.0",
"@webpack-contrib/eslint-config-webpack": "^2.0.0",
"del-cli": "^1.0.0",
"eslint": "^5.0.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-prettier": "^2.0.0",
"jest": "^21.0.0",
"prettier": "^1.0.0",
"standard-version": "^4.0.0"
},
"engines": {
"node": ">= 4"
},
"files": [
"src"
],
"homepage": "https://github.com/webpack-contrib/schema-utils",
"license": "MIT",
"main": "src/index.js",
"name": "schema-utils",
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/schema-utils.git"
},
"scripts": {
"clean": "del-cli coverage",
"commits": "commitlint --from $(git rev-list --tags --max-count=1)",
"lint": "eslint --cache src test",
"release": "npm run commits && standard-version",
"test": "jest --env node --verbose --coverage"
},
"version": "1.0.0"
}
@@ -0,0 +1,30 @@
/* eslint-disable
strict,
no-param-reassign
*/
'use strict';
class ValidationError extends Error {
constructor(errors, name) {
super();
this.name = 'ValidationError';
this.message = `${name || ''} Invalid Options\n\n`;
this.errors = errors.map((err) => {
err.dataPath = err.dataPath.replace(/\//g, '.');
return err;
});
this.errors.forEach((err) => {
this.message += `options${err.dataPath} ${err.message}\n`;
});
Error.captureStackTrace(this, this.constructor);
}
}
module.exports = ValidationError;
+9
View File
@@ -0,0 +1,9 @@
/* eslint-disable
strict
*/
'use strict';
const validateOptions = require('./validateOptions');
module.exports = validateOptions;
@@ -0,0 +1,38 @@
/* eslint-disable
strict,
no-param-reassign
*/
'use strict';
const fs = require('fs');
const path = require('path');
const Ajv = require('ajv');
const errors = require('ajv-errors');
const keywords = require('ajv-keywords');
const ValidationError = require('./ValidationError');
const ajv = new Ajv({
allErrors: true,
jsonPointers: true,
});
errors(ajv);
keywords(ajv, ['instanceof', 'typeof']);
const validateOptions = (schema, options, name) => {
if (typeof schema === 'string') {
schema = fs.readFileSync(path.resolve(schema), 'utf8');
schema = JSON.parse(schema);
}
if (!ajv.validate(schema, options)) {
throw new ValidationError(ajv.errors, name);
}
return true;
};
module.exports = validateOptions;
+144
View File
@@ -0,0 +1,144 @@
{
"_from": "cache-loader@^2.0.1",
"_id": "cache-loader@2.0.1",
"_inBundle": false,
"_integrity": "sha512-V99T3FOynmGx26Zom+JrVBytLBsmUCzVG2/4NnUKgvXN4bEV42R1ERl1IyiH/cvFIDA1Ytq2lPZ9tXDSahcQpQ==",
"_location": "/cache-loader",
"_phantomChildren": {
"ajv": "6.10.0",
"ajv-errors": "1.0.1",
"ajv-keywords": "3.4.0"
},
"_requested": {
"type": "range",
"registry": true,
"raw": "cache-loader@^2.0.1",
"name": "cache-loader",
"escapedName": "cache-loader",
"rawSpec": "^2.0.1",
"saveSpec": null,
"fetchSpec": "^2.0.1"
},
"_requiredBy": [
"/@vue/cli-service"
],
"_resolved": "https://registry.npmjs.org/cache-loader/-/cache-loader-2.0.1.tgz",
"_shasum": "5758f41a62d7c23941e3c3c7016e6faeb03acb07",
"_spec": "cache-loader@^2.0.1",
"_where": "D:\\Atom\\Git\\Laravel_CSSd\\node_modules\\@vue\\cli-service",
"author": {
"name": "Tobias Koppers @sokra"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "6.9.0"
},
"useBuiltIns": "usage"
}
]
]
},
"bugs": {
"url": "https://github.com/webpack-contrib/cache-loader/issues"
},
"bundleDependencies": false,
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"dependencies": {
"loader-utils": "^1.1.0",
"mkdirp": "^0.5.1",
"neo-async": "^2.6.0",
"normalize-path": "^3.0.0",
"schema-utils": "^1.0.0"
},
"deprecated": false,
"description": "Caches the result of following loaders on disk.",
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/polyfill": "^7.2.3",
"@babel/preset-env": "^7.2.3",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@webpack-contrib/defaults": "^3.0.5",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"cross-env": "^5.0.0",
"del": "^3.0.0",
"del-cli": "^1.0.0",
"eslint": "^5.10.0",
"eslint-config-webpack": "^1.0.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.2.1",
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"memory-fs": "^0.4.1",
"pre-commit": "^1.0.0",
"prettier": "^1.15.2",
"standard-version": "^4.0.0",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2"
},
"engines": {
"node": ">= 6.9.0"
},
"files": [
"dist"
],
"homepage": "https://github.com/webpack-contrib/cache-loader",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"webpack"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
},
"main": "dist/cjs.js",
"name": "cache-loader",
"peerDependencies": {
"webpack": "^4.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/cache-loader.git"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"ci:coverage": "npm run test:coverage -- --runInBand",
"ci:lint": "npm run lint && npm run security",
"ci:lint:commits": "commitlint --from=origin/master --to=${CIRCLE_SHA1}",
"ci:test": "npm run test -- --runInBand",
"clean": "del-cli dist",
"commitlint": "commitlint",
"commitmsg": "commitlint -e $GIT_PARAMS",
"defaults": "webpack-defaults",
"lint": "eslint --cache src test",
"prebuild": "npm run clean",
"prepublish": "npm run build",
"release": "standard-version",
"security": "npm audit",
"start": "npm run build -- -w",
"test": "jest",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"test:watch": "jest --watch"
},
"version": "2.0.1"
}