Tweaked gitignore

gitignore removed all composer and npm files, so automated builds would fail
This commit is contained in:
Henry Whitaker
2020-04-12 21:24:03 +01:00
parent 698687f12d
commit ea5808047f
27863 changed files with 3399604 additions and 5 deletions

View File

@@ -0,0 +1,233 @@
# 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="4.0.0-beta.0"></a>
# [4.0.0-beta.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v4.0.0-alpha.0...v4.0.0-beta.0) (2018-02-28)
### Bug Fixes
* **index:** don't crash with dynamic `import()` ([#728](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/728)) ([348b46b](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/348b46b))
<a name="4.0.0-alpha.0"></a>
# [4.0.0-alpha.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.2...v4.0.0-alpha.0) (2018-02-14)
### Chores
* **package:** update `engines` && `peerDependencies` ([05b41f3](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/05b41f3))
### Code Refactoring
* **ExtractTextPlugin:** update to new plugin system and API's ([#707](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/707)) ([51c56c0](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/51c56c0))
### BREAKING CHANGES
* **ExtractTextPlugin:** requires `webpack >= v4.0.0`
* **package:** requires `node >= v6.0.0` (`engines`)
<a name="3.0.2"></a>
## [3.0.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.1...v3.0.2) (2017-10-25)
### Bug Fixes
* refer to the `entrypoint` instead of the first `module` (`module.identifier`) ([#601](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/601)) ([d5a1de2](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/d5a1de2))
<a name="3.0.1"></a>
## [3.0.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0...v3.0.1) (2017-10-03)
### Bug Fixes
* **index:** stricter check for `shouldExtract !== wasExtracted` ([#605](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/605)) ([510704f](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/510704f))
* get real path from `__filename` instead of `__dirname` (`NS`) ([8de6558](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/8de6558))
<a name="3.0.0"></a>
# [3.0.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.2...v3.0.0) (2017-07-10)
### Bug Fixes
* add missing `options.ignoreOrder` details in Error message ([#539](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/539)) ([dd43832](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dd43832))
### Code Refactoring
* Apply webpack-defaults & webpack 3.x support ([#540](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/540)) ([7ae32d9](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/7ae32d9))
### BREAKING CHANGES
* Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10`
- refactor: DeprecationWarning: Chunk.modules [543](https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/543)
* Updates to `Chunk.mapModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
- fix: css generation order issue see: webpack/webpack#5225
* Enforces `peerDependencies` of `"webpack": "^3.1.0"`.
<a name="3.0.0-rc.2"></a>
# [3.0.0-rc.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2017-07-10)
### Bug Fixes
* Modules shouldn't be passed to sort ([#568](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/568)) ([113cabb](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/113cabb))
<a name="3.0.0-rc.1"></a>
# [3.0.0-rc.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2017-07-07)
### Bug Fixes
* Module sorting ([27e3a28](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/27e3a28))
<a name="3.0.0-rc.0"></a>
# [3.0.0-rc.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.3...v3.0.0-rc.0) (2017-07-07)
### Code Refactoring
* Update deprecated `chunk.modules` functions ([#553](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/553)) ([be7936d](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/be7936d))
### BREAKING CHANGES
* Updates to `Chunk.mapModules | forEachModule | getNumberOfModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
<a name="3.0.0-beta.3"></a>
# [3.0.0-beta.3](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2017-06-24)
### Bug Fixes
* Distribute schema with package ([5d0c28f](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/5d0c28f))
<a name="3.0.0-beta.2"></a>
# [3.0.0-beta.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2017-06-24)
* Skipped due to deployment issues with schema
<a name="3.0.0-beta.1"></a>
# [3.0.0-beta.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.0...v3.0.0-beta.1) (2017-06-24)
* Skipped due to deployment issues with schema
<a name="3.0.0-beta.0"></a>
# [3.0.0-beta.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.2...v3.0.0-beta.0) (2017-06-23)
### Bug Fixes
* add missing `options.ignoreOrder` details in Error message ([#539](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/539)) ([dd43832](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dd43832))
### Code Refactoring
* Apply webpack-defaults ([#542](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/542)) ([292e217](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/292e217))
* Chunk.modules deprecation warning ([28171b2](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/28171b2))
### BREAKING CHANGES
* Updates to `Chunk.mapModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
* Enforces `peerDependencies` of `"webpack": ">= 3.0.0-rc.0 || ^3.0.0"`.
* Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10`
<a name="2.1.2"></a>
## [2.1.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.1...v2.1.2) (2017-06-08)
<a name="2.1.1"></a>
## [2.1.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.0...v2.1.1) (2017-06-08)
### Bug Fixes
* add a not null check for the content property before throwing error ([#404](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/404)) ([58dd5d3](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/58dd5d3))
* **loader:** rm unnecessary `this.cacheable` (caching) ([#530](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/530)) ([c3cb091](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/c3cb091))
* don't extract from common async chunks ([#508](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/508)) ([e595417](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/e595417))
* validation schema (`schema-utils`) ([#527](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/527)) ([dfeb347](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dfeb347))
<a name="2.1.0"></a>
# [2.1.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0...v2.1.0) (2017-03-05)
### Features
* The plugin **filename** accepts a function now. [c9a19ad](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/c9a19ad), closes [#423](https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/423)
<a name="2.0.0"></a>
# [2.0.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.3...v2.0.0) (2017-02-24)
<a name="2.0.0-rc.2"></a>
# [2.0.0-rc.2](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.1...v2.0.0-rc.2) (2017-01-28)
### Bug Fixes
* **schema:** allow `extract` to accept omit/remove flags ([8ce93d5](https://github.com/webpack/extract-text-webpack-plugin/commit/8ce93d5)), closes [#371](https://github.com/webpack/extract-text-webpack-plugin/issues/371)
* **schema:** connect loader schema with the code properly ([03bb4aa](https://github.com/webpack/extract-text-webpack-plugin/commit/03bb4aa))
* **schema:** emit proper error messages ([70cbd4b](https://github.com/webpack/extract-text-webpack-plugin/commit/70cbd4b))
### Features
* **errors:** show nicer errors if there are extra fields ([76a171d](https://github.com/webpack/extract-text-webpack-plugin/commit/76a171d))
<a name="2.0.0-rc.1"></a>
# [2.0.0-rc.1](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.0...v2.0.0-rc.1) (2017-01-28)
### Bug Fixes
* **options:** pass proper loader options to children ([#266](https://github.com/webpack/extract-text-webpack-plugin/issues/266)) ([6abf42d](https://github.com/webpack/extract-text-webpack-plugin/commit/6abf42d))
<a name="2.0.0-rc.0"></a>
# [2.0.0-rc.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-beta.5...v2.0.0-rc.0) (2017-01-26)
### Bug Fixes
* **readme:** Incorrect loader configuration ([e477cc7](https://github.com/webpack/extract-text-webpack-plugin/commit/e477cc7))
### Features
* **extract:** return an array of loader objects ([#343](https://github.com/webpack/extract-text-webpack-plugin/issues/343)) ([74b86e0](https://github.com/webpack/extract-text-webpack-plugin/commit/74b86e0))
# 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.

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.

View File

@@ -0,0 +1,272 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
<div align="center">
<img width="200" height="200"
src="https://cdn.rawgit.com/webpack-contrib/extract-text-webpack-plugin/574e3200/logo.svg">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Extract Text Plugin</h1>
<p>Extract text from a bundle, or bundles, into a separate file.</p>
</div>
<h2 align="center">Install</h2>
```bash
# for webpack 3
npm install --save-dev extract-text-webpack-plugin
# for webpack 2
npm install --save-dev extract-text-webpack-plugin@2.1.2
# for webpack 1
npm install --save-dev extract-text-webpack-plugin@1.0.1
```
<h2 align="center">Usage</h2>
> :warning: For webpack v1, see [the README in the webpack-1 branch](https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md).
```js
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
]
}
```
It moves all the required `*.css` modules in entry chunks into a separate CSS file. So your styles are no longer inlined into the JS bundle, but in a separate CSS file (`styles.css`). If your total stylesheet volume is big, it will be faster because the CSS bundle is loaded in parallel to the JS bundle.
|Advantages|Caveats|
|:---------|:------|
| Fewer style tags (older IE has a limit) | Additional HTTP request |
| CSS SourceMap (with `devtool: "source-map"` and `extract-text-webpack-plugin?sourceMap`) | Longer compilation time |
| CSS requested in parallel | No runtime public path modification |
| CSS cached separate | No Hot Module Replacement |
| Faster runtime (less code and DOM operations) | ... |
<h2 align="center">Options</h2>
```js
new ExtractTextPlugin(options: filename | object)
```
|Name|Type|Description|
|:--:|:--:|:----------|
|**`id`**|`{String}`|Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)|
|**`filename`**|`{String\|Function}`|Name of the result file. May contain `[name]`, `[id]` and `[contenthash]`|
|**`allChunks`**|`{Boolean}`|Extract from all additional chunks too (by default it extracts only from the initial chunk(s))<br />When using `optimization.splitChunks` and there are extracted chunks (from `ExtractTextPlugin.extract`) in the commons chunk, `allChunks` **must** be set to `true`|
|**`disable`**|`{Boolean}`|Disables the plugin|
|**`ignoreOrder`**|`{Boolean}`|Disables order check (useful for CSS Modules!), `false` by default|
* `[name]` name of the chunk
* `[id]` number of the chunk
* `[contenthash]` hash of the content of the extracted file
* `[<hashType>:contenthash:<digestType>:<length>]` optionally you can configure
* other `hashType`s, e.g. `sha1`, `md5`, `sha256`, `sha512`
* other `digestType`s, e.g. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* and `length`, the length of the hash in chars
> :warning: `ExtractTextPlugin` generates a file **per entry**, so you must use `[name]`, `[id]` or `[contenthash]` when using multiple entries.
#### `#extract`
```js
ExtractTextPlugin.extract(options: loader | object)
```
Creates an extracting loader from an existing loader. Supports loaders of type `{ loader: [name]-loader -> {String}, options: {} -> {Object} }`.
|Name|Type|Description|
|:--:|:--:|:----------|
|**`options.use`**|`{String}`/`{Array}`/`{Object}`|Loader(s) that should be used for converting the resource to a CSS exporting module _(required)_|
|**`options.fallback`**|`{String}`/`{Array}`/`{Object}`|loader(e.g `'style-loader'`) that should be used when the CSS is not extracted (i.e. in an additional chunk when `allChunks: false`)|
|**`options.publicPath`**|`{String}`|Override the `publicPath` setting for this loader|
#### Multiple Instances
There is also an `extract` function on the instance. You should use this if you have more than one instance of `ExtractTextPlugin`.
```js
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// Create multiple instances
const extractCSS = new ExtractTextPlugin('stylesheets/[name]-one.css');
const extractLESS = new ExtractTextPlugin('stylesheets/[name]-two.css');
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: extractCSS.extract([ 'css-loader', 'postcss-loader' ])
},
{
test: /\.less$/i,
use: extractLESS.extract([ 'css-loader', 'less-loader' ])
},
]
},
plugins: [
extractCSS,
extractLESS
]
};
```
### Extracting Sass or LESS
The configuration is the same, switch out `sass-loader` for `less-loader` when necessary.
```js
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
//if you want to pass in options, you can do so:
//new ExtractTextPlugin({
// filename: 'style.css'
//})
]
}
```
### `url()` Resolving
If you are finding that urls are not resolving properly when you run webpack. You can expand your loader functionality with options. The `url: false` property allows your paths resolved without any changes.
```js
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
// If you are having trouble with urls not resolving add this setting.
// See https://github.com/webpack-contrib/css-loader#url
url: false,
minimize: true,
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
})
}
]
}
}
```
### Modify filename
`filename` parameter could be `Function`. It passes `getPath` to process the format like `css/[name].css` and returns the real file name, `css/js/a.css`. You can replace `css/js` with `css` then you will get the new path `css/a.css`.
```js
entry: {
'js/a': "./a"
},
plugins: [
new ExtractTextPlugin({
filename: (getPath) => {
return getPath('css/[name].css').replace('css/js', 'css');
},
allChunks: true
})
]
```
<h2 align="center">Maintainers</h2>
<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
</br>
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
</br>
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
</br>
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
</br>
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
</td>
</tr>
<tbody>
</table>
[npm]: https://img.shields.io/npm/v/extract-text-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/extract-text-webpack-plugin
[node]: https://img.shields.io/node/v/extract-text-webpack-plugin.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/extract-text-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/extract-text-webpack-plugin
[tests]: http://img.shields.io/travis/webpack-contrib/extract-text-webpack-plugin.svg
[tests-url]: https://travis-ci.org/webpack-contrib/extract-text-webpack-plugin
[cover]: https://coveralls.io/repos/github/webpack-contrib/extract-text-webpack-plugin/badge.svg
[cover-url]: https://coveralls.io/github/webpack-contrib/extract-text-webpack-plugin
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = require('./index').default;

View File

@@ -0,0 +1,338 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _Chunk = require('webpack/lib/Chunk');
var _Chunk2 = _interopRequireDefault(_Chunk);
var _webpackSources = require('webpack-sources');
var _async = require('async');
var _async2 = _interopRequireDefault(_async);
var _loaderUtils = require('loader-utils');
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
var _schemaUtils = require('schema-utils');
var _schemaUtils2 = _interopRequireDefault(_schemaUtils);
var _ExtractTextPluginCompilation = require('./lib/ExtractTextPluginCompilation');
var _ExtractTextPluginCompilation2 = _interopRequireDefault(_ExtractTextPluginCompilation);
var _OrderUndefinedError = require('./lib/OrderUndefinedError');
var _OrderUndefinedError2 = _interopRequireDefault(_OrderUndefinedError);
var _helpers = require('./lib/helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable
consistent-return,
no-param-reassign,
prefer-rest-params
*/
const NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
const plugin = { name: 'ExtractTextPlugin' };
let nextId = 0;
class ExtractTextPlugin {
constructor(options) {
if ((0, _helpers.isString)(options)) {
options = { filename: options };
} else {
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, './plugin.json'), options, 'Extract Text Plugin');
}
this.filename = options.filename;
this.id = options.id != null ? options.id : nextId += 1;
this.options = {};
(0, _helpers.mergeOptions)(this.options, options);
delete this.options.filename;
delete this.options.id;
}
static loader(options) {
return { loader: require.resolve('./loader'), options };
}
static applyAdditionalInformation(source, info) {
if (info) {
return new _webpackSources.ConcatSource(`@media ${info[0]} {`, source, '}');
}
return source;
}
loader(options) {
return ExtractTextPlugin.loader((0, _helpers.mergeOptions)({ id: this.id }, options));
}
mergeNonInitialChunks(chunk, intoChunk, checkedChunks) {
if (!intoChunk) {
const newCheckedChunks = [];
for (const asyncChunk of chunk.getAllAsyncChunks()) {
if (!asyncChunk.isOnlyInitial()) {
this.mergeNonInitialChunks(asyncChunk, chunk, newCheckedChunks);
}
}
} else if (!checkedChunks.includes(chunk)) {
const newCheckedChunks = checkedChunks.concat(chunk);
for (const chunkModule of chunk.modulesIterable) {
intoChunk.addModule(chunkModule);
chunkModule.addChunk(intoChunk);
}
for (const asyncChunk of chunk.getAllAsyncChunks()) {
if (!asyncChunk.isOnlyInitial()) {
this.mergeNonInitialChunks(asyncChunk, intoChunk, newCheckedChunks);
}
}
}
}
static renderExtractedChunk(compilation, chunk) {
const source = new _webpackSources.ConcatSource();
for (const chunkModule of chunk.modulesIterable) {
let moduleSource = chunkModule.source(compilation.dependencyTemplates, compilation.runtimeTemplate);
// This module was concatenated by the ModuleConcatenationPlugin; because the pitching loader
// only produces commonjs results, at least for now things we want to extract can't be in them.
// NOTE: if ESM support is added, _this workaround will break_.
if (moduleSource instanceof _webpackSources.ConcatSource) {
moduleSource = null;
}
// Async imports (require.ensure(), import().then) are CachedSource module
// instances caching a ReplaceSource instance, which breaks the plugin
// because their .source() is the cached "// removed by ..." text.
// The issue lies elsewhere, this is just a temporary fix that
// creates a new RawSource with the extracted text. If it's
// a CachedSource instance but there's no extracted text
// it's "__webpack_require__();" statements. Skip it.
if (moduleSource instanceof _webpackSources.CachedSource) {
if (chunkModule[NS] && chunkModule[NS].content) {
moduleSource = new _webpackSources.ConcatSource();
if (chunkModule[NS].content.length > 1) {
console.error(chunkModule[NS].content);
}
for (const content of chunkModule[NS].content) {
moduleSource.add(new _webpackSources.RawSource(content[1]));
}
} else {
moduleSource = null;
}
}
if (moduleSource) {
source.add(ExtractTextPlugin.applyAdditionalInformation(moduleSource, chunkModule.additionalInformation));
}
}
return source;
}
extract(options) {
if (Array.isArray(options) || (0, _helpers.isString)(options) || typeof options.options === 'object' || typeof options.query === 'object') {
options = { use: options };
} else {
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, './loader.json'), options, 'Extract Text Plugin (Loader)');
}
let loader = options.use;
let before = options.fallback || [];
if ((0, _helpers.isString)(loader)) {
loader = loader.split('!');
}
if ((0, _helpers.isString)(before)) {
before = before.split('!');
} else if (!Array.isArray(before)) {
before = [before];
}
options = (0, _helpers.mergeOptions)({ omit: before.length, remove: true }, options);
delete options.use;
delete options.fallback;
return [this.loader(options)].concat(before, loader).map(_helpers.getLoaderObject);
}
apply(compiler) {
const { options, filename, id } = this;
compiler.hooks.thisCompilation.tap(plugin, compilation => {
const extractCompilation = new _ExtractTextPluginCompilation2.default();
compilation.hooks.normalModuleLoader.tap(plugin, (loaderContext, module) => {
loaderContext[NS] = (content, opt) => {
if (options.disable) {
return false;
}
if (!Array.isArray(content) && content != null) {
throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(content)}`);
}
module[NS] = {
content,
options: opt || {}
};
return options.allChunks || module[`${NS}/extract`]; // eslint-disable-line no-path-concat
};
});
let extractedChunks;
compilation.hooks.optimizeTree.tapAsync(plugin, (chunks, modules, callback) => {
extractedChunks = chunks.map(() => new _Chunk2.default());
chunks.forEach((chunk, i) => {
const extractedChunk = extractedChunks[i];
extractedChunk.index = i;
extractedChunk.originalChunk = chunk;
extractedChunk.name = chunk.name;
// extractedChunk.entryModule = chunk.entryModule;
for (const chunkGroup of chunk.groupsIterable) {
extractedChunk.addGroup(chunkGroup);
}
});
_async2.default.forEach(chunks, (chunk, chunkCallback) => {
// eslint-disable-line no-shadow
const extractedChunk = extractedChunks[chunks.indexOf(chunk)];
const shouldExtract = !!(options.allChunks || (0, _helpers.isInitialOrHasNoParents)(chunk));
_async2.default.forEach(Array.from(chunk.modulesIterable).sort(
// NOTE: .index should be .index2 once ESM support is added
(a, b) => a.index - b.index), (module, moduleCallback) => {
// eslint-disable-line no-shadow
let meta = module[NS];
if (meta && (!meta.options.id || meta.options.id === id)) {
const wasExtracted = Array.isArray(meta.content);
// A stricter `shouldExtract !== wasExtracted` check to guard against cases where a previously extracted
// module would be extracted twice. Happens when a module is a dependency of an initial and a non-initial
// chunk. See issue #604
if (shouldExtract && !wasExtracted) {
module[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat
return compilation.rebuildModule(module, err => {
if (err) {
compilation.errors.push(err);
return moduleCallback();
}
meta = module[NS];
// Error out if content is not an array and is not null
if (!Array.isArray(meta.content) && meta.content != null) {
err = new Error(`${module.identifier()} doesn't export content`);
compilation.errors.push(err);
return moduleCallback();
}
if (meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
}
return moduleCallback();
});
} else if (meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
}
}
return moduleCallback();
}, err => {
if (err) {
return chunkCallback(err);
}
chunkCallback();
});
}, err => {
if (err) {
return callback(err);
}
extractedChunks.forEach(extractedChunk => {
if ((0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
this.mergeNonInitialChunks(extractedChunk);
}
});
extractedChunks.forEach(extractedChunk => {
if (!(0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
for (const chunkModule of extractedChunk.modulesIterable) {
extractedChunk.removeModule(chunkModule);
}
}
});
compilation.hooks.optimizeExtractedChunks.call(extractedChunks);
callback();
});
});
compilation.hooks.additionalAssets.tapAsync(plugin, assetCb => {
extractedChunks.forEach(extractedChunk => {
if (extractedChunk.getNumberOfModules()) {
extractedChunk.sortModules((a, b) => {
if (!options.ignoreOrder && (0, _helpers.isInvalidOrder)(a, b)) {
compilation.errors.push(new _OrderUndefinedError2.default(a.getOriginalModule()));
compilation.errors.push(new _OrderUndefinedError2.default(b.getOriginalModule()));
}
return (0, _helpers.getOrder)(a, b);
});
const chunk = extractedChunk.originalChunk;
const source = ExtractTextPlugin.renderExtractedChunk(compilation, extractedChunk);
const getPath = format => compilation.getPath(format, {
chunk
}).replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/gi,
// eslint-disable-next-line func-names
function () {
return _loaderUtils2.default.getHashDigest(source.source(), arguments[1], arguments[2], parseInt(arguments[3], 10));
});
const file = (0, _helpers.isFunction)(filename) ? filename(getPath) : getPath(filename);
compilation.assets[file] = source;
chunk.files.push(file);
}
}, this);
assetCb();
});
});
}
}
ExtractTextPlugin.extract = ExtractTextPlugin.prototype.extract.bind(ExtractTextPlugin);
exports.default = ExtractTextPlugin;

View File

@@ -0,0 +1,58 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _ExtractedModule = require('./ExtractedModule');
var _ExtractedModule2 = _interopRequireDefault(_ExtractedModule);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class ExtractTextPluginCompilation {
constructor() {
this.modulesByIdentifier = {};
}
addModule(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) {
let m;
if (!this.modulesByIdentifier[identifier]) {
m = this.modulesByIdentifier[identifier] = new _ExtractedModule2.default(identifier, originalModule, source, sourceMap, additionalInformation, prevModules);
} else {
m = this.modulesByIdentifier[identifier];
m.addPrevModules(prevModules);
if (originalModule.index2 < m.getOriginalModule().index2) {
m.setOriginalModule(originalModule);
}
}
return m;
}
addResultToChunk(identifier, result, originalModule, extractedChunk) {
if (!Array.isArray(result)) {
result = [[identifier, result]];
}
const counterMap = {};
const prevModules = [];
result.forEach(item => {
const c = counterMap[item[0]];
const module = this.addModule.call(this, item[0] + (c || ''), originalModule, item[1], item[2], item[3], prevModules.slice());
extractedChunk.addModule(module);
// extractedChunk.removeModule(originalModule);
module.addChunk(extractedChunk);
counterMap[item[0]] = (c || 0) + 1;
prevModules.push(module);
}, this);
}
} /* eslint-disable
no-multi-assign,
no-param-reassign
*/
exports.default = ExtractTextPluginCompilation;

View File

@@ -0,0 +1,77 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _webpackSources = require('webpack-sources');
class ExtractedModule {
constructor(identifier, originalModule, source, sourceMap, additionalInformation, prevModules) {
this._identifier = identifier;
this._originalModule = originalModule;
this._source = source;
this._sourceMap = sourceMap;
this._prevModules = prevModules;
this.additionalInformation = additionalInformation;
this.chunks = [];
}
getOrder() {
// http://stackoverflow.com/a/14676665/1458162
return (/^@import url/.test(this._source) ? 0 : 1
);
}
addChunk(chunk) {
const idx = this.chunks.indexOf(chunk);
if (idx < 0) {
this.chunks.push(chunk);
}
}
removeChunk(chunk) {
const idx = this.chunks.indexOf(chunk);
if (idx >= 0) {
this.chunks.splice(idx, 1);
chunk.removeModule(this);
return true;
}
return false;
}
rewriteChunkInReasons(oldChunk, newChunks) {} // eslint-disable-line
identifier() {
return this._identifier;
}
source() {
if (this._sourceMap) {
return new _webpackSources.SourceMapSource(this._source, null, this._sourceMap);
}
return new _webpackSources.RawSource(this._source);
}
getOriginalModule() {
return this._originalModule;
}
getPrevModules() {
return this._prevModules;
}
addPrevModules(prevModules) {
prevModules.forEach(m => {
if (this._prevModules.indexOf(m) < 0) {
this._prevModules.push(m);
}
}, this);
}
setOriginalModule(originalModule) {
this._originalModule = originalModule;
}
}
exports.default = ExtractedModule;

View File

@@ -0,0 +1,16 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
function OrderUndefinedError(module) {
Error.call(this);
Error.captureStackTrace(this, OrderUndefinedError);
this.name = 'OrderUndefinedError';
this.message = 'Order in extracted chunk undefined';
this.module = module;
}
exports.default = OrderUndefinedError;
OrderUndefinedError.prototype = Object.create(Error.prototype);

View File

@@ -0,0 +1,116 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isInitialOrHasNoParents = isInitialOrHasNoParents;
exports.isInvalidOrder = isInvalidOrder;
exports.getOrder = getOrder;
exports.getLoaderObject = getLoaderObject;
exports.mergeOptions = mergeOptions;
exports.isString = isString;
exports.isFunction = isFunction;
exports.isType = isType;
/* eslint-disable
no-param-reassign
*/
function isInitialOrHasNoParents(chunk) {
let parentCount = 0;
for (const chunkGroup of chunk.groupsIterable) {
parentCount += chunkGroup.getNumberOfParents();
}
return chunk.isOnlyInitial() || parentCount === 0;
}
function isInvalidOrder(a, b) {
// Async chunks' modules don't get turned into ExtractedModule
// instances for some reason. This is a temporary fix that
// moves the isInvalidOrder check inside a condition.
if (a.getPrevModules && b.getPrevModules) {
const bBeforeA = a.getPrevModules().indexOf(b) >= 0;
const aBeforeB = b.getPrevModules().indexOf(a) >= 0;
return aBeforeB && bBeforeA;
}
return false;
}
function getOrder(a, b) {
// Async chunks' modules don't get turned into ExtractedModule
// instances for some reason. This is a temporary fix that
// moves the custom sorting logic inside a condition.
if (a.getOriginalModule && b.getOriginalModule) {
const aOrder = a.getOrder();
const bOrder = b.getOrder();
if (aOrder < bOrder) return -1;
if (aOrder > bOrder) return 1;
// We are trying to use the underlying index2 property
// of the original module, but this property seems
// to be set to null most of the time. It makes
// sorting with it pointless. We should look
// into saving the index, index2 and depth
// props (maybe inside ExtractedModule).
const aIndex = a.getOriginalModule().index2;
const bIndex = b.getOriginalModule().index2;
if (aIndex < bIndex) return -1;
if (aIndex > bIndex) return 1;
const bBeforeA = a.getPrevModules().indexOf(b) >= 0;
const aBeforeB = b.getPrevModules().indexOf(a) >= 0;
if (aBeforeB && !bBeforeA) return -1;
if (!aBeforeB && bBeforeA) return 1;
// Sorting by id is the default behavior of webpack
// and it keeps the modules in the correct order,
// except for async imports. That's the reason
// it is inside the conditional branch
if (a.id < b.id) return -1;
if (a.id > b.id) return 1;
}
// Sorting by identifier breaks the order of async imported
// modules either because webpack sorts them by default,
// or because they are processed in the correct order
// in the first place, or maybe because the modules
// aren't ExtractedModule instances in this case.
// Returning 0 keeps the already correct order.
/*
const ai = a.identifier();
const bi = b.identifier();
if (ai < bi) return -1;
if (ai > bi) return 1;
*/
return 0;
}
function getLoaderObject(loader) {
if (isString(loader)) {
return { loader };
}
return loader;
}
function mergeOptions(a, b) {
if (!b) return a;
Object.keys(b).forEach(key => {
a[key] = b[key];
});
return a;
}
function isString(a) {
return typeof a === 'string';
}
function isFunction(a) {
return typeof a === 'function';
}
function isType(type, obj) {
return Object.prototype.toString.call(obj) === `[object ${type}]`;
}

View File

@@ -0,0 +1,173 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pitch = pitch;
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _loaderUtils = require('loader-utils');
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
var _NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
var _NodeTemplatePlugin2 = _interopRequireDefault(_NodeTemplatePlugin);
var _NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
var _NodeTargetPlugin2 = _interopRequireDefault(_NodeTargetPlugin);
var _LibraryTemplatePlugin = require('webpack/lib/LibraryTemplatePlugin');
var _LibraryTemplatePlugin2 = _interopRequireDefault(_LibraryTemplatePlugin);
var _SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
var _SingleEntryPlugin2 = _interopRequireDefault(_SingleEntryPlugin);
var _LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin');
var _LimitChunkCountPlugin2 = _interopRequireDefault(_LimitChunkCountPlugin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable
consistent-return,
no-param-reassign
*/
const NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
const plugin = { name: 'ExtractTextPlugin' };
exports.default = source => source;
function pitch(request) {
const query = _loaderUtils2.default.getOptions(this) || {};
let loaders = this.loaders.slice(this.loaderIndex + 1);
this.addDependency(this.resourcePath);
// We already in child compiler, return empty bundle
// eslint-disable-next-line no-undefined
if (this[NS] === undefined) {
throw new Error('"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' + 'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example');
} else if (this[NS] === false) {
return '';
} else if (this[NS](null, query)) {
if (query.omit) {
this.loaderIndex += +query.omit + 1;
request = request.split('!').slice(+query.omit).join('!');
loaders = loaders.slice(+query.omit);
}
let resultSource;
if (query.remove) {
resultSource = '// removed by extract-text-webpack-plugin';
} else {
resultSource = undefined; // eslint-disable-line no-undefined
}
const childFilename = 'extract-text-webpack-plugin-output-filename'; // eslint-disable-line no-path-concat
const publicPath = typeof query.publicPath === 'string' ? query.publicPath : this._compilation.outputOptions.publicPath;
const outputOptions = {
filename: childFilename,
publicPath
};
const childCompiler = this._compilation.createChildCompiler(`extract-text-webpack-plugin ${NS} ${request}`, outputOptions);
new _NodeTemplatePlugin2.default(outputOptions).apply(childCompiler);
new _LibraryTemplatePlugin2.default(null, 'commonjs2').apply(childCompiler);
new _NodeTargetPlugin2.default().apply(childCompiler);
new _SingleEntryPlugin2.default(this.context, `!!${request}`).apply(childCompiler);
new _LimitChunkCountPlugin2.default({ maxChunks: 1 }).apply(childCompiler);
// We set loaderContext[NS] = false to indicate we already in
// a child compiler so we don't spawn other child compilers from there.
childCompiler.hooks.thisCompilation.tap(plugin, compilation => {
compilation.hooks.normalModuleLoader.tap(plugin, (loaderContext, module) => {
loaderContext[NS] = false;
if (module.request === request) {
module.loaders = loaders.map(loader => {
return {
loader: loader.path,
options: loader.options
};
});
}
});
});
let source;
childCompiler.hooks.afterCompile.tap(plugin, compilation => {
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
// Remove all chunk assets
compilation.chunks.forEach(chunk => {
chunk.files.forEach(file => {
delete compilation.assets[file];
});
});
});
const callback = this.async();
childCompiler.runAsChild((err, entries, compilation) => {
if (err) return callback(err);
if (compilation.errors.length > 0) {
return callback(compilation.errors[0]);
}
compilation.fileDependencies.forEach(dep => {
this.addDependency(dep);
}, this);
compilation.contextDependencies.forEach(dep => {
this.addContextDependency(dep);
}, this);
if (!source) {
return callback(new Error("Didn't get a result from child compiler"));
}
try {
let text = this.exec(source, request);
if (typeof text === 'string') {
text = [[compilation.entries[0].identifier(), text]];
} else {
text.forEach(item => {
const [id] = item;
compilation.modules.forEach(module => {
if (module.id === id) {
item[0] = module.identifier();
}
});
});
}
this[NS](text, query);
// NOTE: converting this to ESM will require changes to renderExtractedChunk
if (text.locals && typeof resultSource !== 'undefined') {
resultSource += `\nmodule.exports = ${JSON.stringify(text.locals)};`;
}
} catch (e) {
return callback(e);
}
if (resultSource) {
callback(null, resultSource);
} else {
callback();
}
});
}
}

View File

@@ -0,0 +1,30 @@
{
"type": "object",
"additionalProperties": false,
"properties": {
"allChunks": {
"type": "boolean"
},
"disable": {
"type": "boolean"
},
"omit": {
"type": "boolean"
},
"remove": {
"type": "boolean"
},
"fallback": {
"type": ["string", "array", "object"]
},
"filename": {
"type": "string"
},
"use": {
"type": ["string", "array", "object"]
},
"publicPath": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,40 @@
{
"type": "object",
"additionalProperties": false,
"properties": {
"allChunks": {
"description": "",
"type": "boolean"
},
"disable": {
"description": "",
"type": "boolean"
},
"fallback": {
"description": "A loader that webpack can fall back to if the original one fails.",
"modes": {
"type": ["string", "object", "array"]
}
},
"filename": {
"description": "The filename and path that ExtractTextPlugin will extract to",
"modes": {
"type": ["string", "function"]
}
},
"ignoreOrder": {
"description": "Ignore dependency order (useful for CSS Modules)",
"type": "boolean"
},
"loader": {
"description": "The loader that ExtractTextPlugin will attempt to load through.",
"modes": {
"type": ["string", "object", "array"]
}
},
"publicPath": {
"description": "",
"type": "string"
}
}
}

View File

@@ -0,0 +1,124 @@
# 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="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.

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.

View File

@@ -0,0 +1,130 @@
[![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
}
```
```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

View File

@@ -0,0 +1,77 @@
{
"_args": [
[
"schema-utils@0.4.7",
"/home/henry/Documents/git/Speedtest-checker"
]
],
"_development": true,
"_from": "schema-utils@0.4.7",
"_id": "schema-utils@0.4.7",
"_inBundle": false,
"_integrity": "sha512-v/iwU6wvwGK8HbU9yi3/nhGzP0yGSuhQMzL6ySiec1FSrZZDkhm4noOSWzrNFo/jEc+SJY6jRTwuwbSXJPDUnQ==",
"_location": "/extract-text-webpack-plugin/schema-utils",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "schema-utils@0.4.7",
"name": "schema-utils",
"escapedName": "schema-utils",
"rawSpec": "0.4.7",
"saveSpec": null,
"fetchSpec": "0.4.7"
},
"_requiredBy": [
"/extract-text-webpack-plugin"
],
"_resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-0.4.7.tgz",
"_spec": "0.4.7",
"_where": "/home/henry/Documents/git/Speedtest-checker",
"author": {
"name": "webpack Contrib",
"url": "https://github.com/webpack-contrib"
},
"bugs": {
"url": "https://github.com/webpack-contrib/schema-utils/issues"
},
"dependencies": {
"ajv": "^6.1.0",
"ajv-keywords": "^3.1.0"
},
"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": "0.4.7"
}

View File

@@ -0,0 +1,25 @@
/* eslint-disable
strict
*/
'use strict';
class ValidationError extends Error {
constructor(errors, name) {
super();
this.name = 'ValidationError';
this.message = `${name || ''} Invalid Options\n\n`;
errors.forEach((err) => {
this.message += `options${err.dataPath} ${err.message}\n`;
});
this.errors = errors;
Error.captureStackTrace(this, this.constructor);
}
}
module.exports = ValidationError;

View File

@@ -0,0 +1,9 @@
/* eslint-disable
strict
*/
'use strict';
const validateOptions = require('./validateOptions');
module.exports = validateOptions;

View File

@@ -0,0 +1,37 @@
/* eslint-disable
strict,
no-param-reassign
*/
'use strict';
const fs = require('fs');
const path = require('path');
const Ajv = require('ajv');
const ajvKeywords = require('ajv-keywords');
const ValidationError = require('./ValidationError');
const ajv = new Ajv({
allErrors: true,
useDefaults: true,
errorDataPath: 'property',
});
ajvKeywords(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;

View File

@@ -0,0 +1,129 @@
{
"_args": [
[
"extract-text-webpack-plugin@4.0.0-beta.0",
"/home/henry/Documents/git/Speedtest-checker"
]
],
"_development": true,
"_from": "extract-text-webpack-plugin@4.0.0-beta.0",
"_id": "extract-text-webpack-plugin@4.0.0-beta.0",
"_inBundle": false,
"_integrity": "sha512-Hypkn9jUTnFr0DpekNam53X47tXn3ucY08BQumv7kdGgeVUBLq3DJHJTi6HNxv4jl9W+Skxjz9+RnK0sJyqqjA==",
"_location": "/extract-text-webpack-plugin",
"_phantomChildren": {
"ajv": "6.12.0",
"ajv-keywords": "3.4.1"
},
"_requested": {
"type": "version",
"registry": true,
"raw": "extract-text-webpack-plugin@4.0.0-beta.0",
"name": "extract-text-webpack-plugin",
"escapedName": "extract-text-webpack-plugin",
"rawSpec": "4.0.0-beta.0",
"saveSpec": null,
"fetchSpec": "4.0.0-beta.0"
},
"_requiredBy": [
"/laravel-mix"
],
"_resolved": "https://registry.npmjs.org/extract-text-webpack-plugin/-/extract-text-webpack-plugin-4.0.0-beta.0.tgz",
"_spec": "4.0.0-beta.0",
"_where": "/home/henry/Documents/git/Speedtest-checker",
"author": {
"name": "Tobias Koppers @sokra"
},
"bugs": {
"url": "https://github.com/webpack-contrib/extract-text-webpack-plugin/issues"
},
"dependencies": {
"async": "^2.4.1",
"loader-utils": "^1.1.0",
"schema-utils": "^0.4.5",
"webpack-sources": "^1.1.0"
},
"description": "Extract text from bundle into a file.",
"devDependencies": {
"@commitlint/cli": "^5.2.8",
"@commitlint/config-angular": "^5.1.1",
"@webpack-contrib/eslint-config-webpack": "^2.0.2",
"babel-cli": "^6.26.0",
"babel-jest": "^22.2.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"conventional-github-releaser": "^2.0.0",
"cross-env": "^5.1.3",
"css-loader": "^0.28.9",
"del": "^3.0.0",
"del-cli": "^1.1.0",
"eslint": "^4.17.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.6.0",
"file-loader": "^1.1.6",
"husky": "^0.14.3",
"jest": "^22.3.0",
"lint-staged": "^6.1.0",
"memory-fs": "^0.4.1",
"nsp": "^3.1.0",
"pre-commit": "^1.2.2",
"prettier": "^1.10.2",
"raw-loader": "^0.5.1",
"standard-version": "^4.3.0",
"style-loader": "^0.19.1",
"webpack": "^4.0.0",
"webpack-defaults": "^2.0.0-rc.4"
},
"engines": {
"node": ">= 6.9.0 || >= 8.9.0"
},
"files": [
"dist"
],
"homepage": "https://github.com/webpack-contrib/extract-text-webpack-plugin",
"jest": {
"testEnvironment": "node"
},
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
},
"main": "dist/cjs.js",
"name": "extract-text-webpack-plugin",
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
},
"pre-commit": "lint-staged",
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/extract-text-webpack-plugin.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=${CIRCLE_BRANCH} --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",
"lint-staged": "lint-staged",
"prebuild": "npm run clean",
"prepare": "npm run build",
"release": "standard-version",
"release:ci": "conventional-github-releaser -p angular",
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
"security": "nsp check",
"start": "npm run build -- -w",
"test": "jest",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"test:watch": "jest --watch"
},
"version": "4.0.0-beta.0"
}