This commit is contained in:
wushenghua
2017-05-10 17:19:39 +08:00
parent afafd9c07b
commit 6a48d33db7
907 changed files with 118717 additions and 35470 deletions
+1
View File
@@ -0,0 +1 @@
* text=auto
+1
View File
@@ -0,0 +1 @@
/node_modules
+64
View File
@@ -0,0 +1,64 @@
# 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.0"></a>
# [0.4.0](https://github.com/webpack/compression-webpack-plugin/compare/v0.3.2...v0.4.0) (2017-04-08)
### Features
* add option to change the filename ([#51](https://github.com/webpack/compression-webpack-plugin/issues/51)) ([fb7bd81](https://github.com/webpack/compression-webpack-plugin/commit/fb7bd81))
* add option to delete original assets ([#44](https://github.com/webpack/compression-webpack-plugin/issues/44)) ([24f15f2](https://github.com/webpack/compression-webpack-plugin/commit/24f15f2))
<a name="0.3.2"></a>
## 0.3.2 (2016-09-13)
### Chores
* Update node-zopfli version ([2d3dd44](https://github.com/webpack-contrib/compression-webpack-plugin/commit/2d3dd44))
<a name="0.3.1"></a>
## 0.3.1 (2016-03-26)
### Bug Fixes
* TypeError Invalid non-strig/buffer chunk ([53ec8a9](https://github.com/webpack/compression-webpack-plugin/commit/53ec8a9))
<a name="0.3.0"></a>
## 0.3.0 (2016-01-23)
### Bug Fixes
* Correct zopfli options ([1f3b595](https://github.com/webpack/compression-webpack-plugin/commit/1f3b595))
* plugin options syntax ([437bdff](https://github.com/webpack/compression-webpack-plugin/commit/437bdff))
### Features
* Add compression level option ([9d05172](https://github.com/webpack/compression-webpack-plugin/commit/9d05172))
* Add node-zopfli option ([2c22b1c](https://github.com/webpack/compression-webpack-plugin/commit/2c22b1c))
* Permit {path} and {query} in asset name ([12d167c](https://github.com/webpack/compression-webpack-plugin/commit/12d167c))
<a name="0.2.0"></a>
## 0.2.0 (2015-04-08)
### Features
* use webpack RawSource ([3c85a2b](https://github.com/webpack/compression-webpack-plugin/commit/3c85a2b))
<a name="0.1.2"></a>
## 0.1.2 (2015-04-08)
### Bug Fixes
* Double compression on worker-loader bundles ([7ce2b32](https://github.com/webpack/compression-webpack-plugin/commit/7ce2b32))
* Remove unneeded module.exports ([6f4e60d](https://github.com/webpack/compression-webpack-plugin/commit/6f4e60d))
+21
View File
@@ -0,0 +1,21 @@
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.
+97
View File
@@ -0,0 +1,97 @@
[![npm][npm]][npm-url]
[![deps][deps]][deps-url]
[![chat][chat]][chat-url]
<div align="center">
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" vspace="" hspace="25"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
</a>
<h1>Compression Plugin</h1>
<p>Compression plugin for Webpack.<p>
</div>
<h2 align="center">Install</h2>
```bash
npm i -D compression-webpack-plugin
```
<h2 align="center">Usage</h2>
``` javascript
var CompressionPlugin = require("compression-webpack-plugin");
module.exports = {
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.(js|html)$/,
threshold: 10240,
minRatio: 0.8
})
]
}
```
Arguments:
* `asset`: The target asset name. `[file]` is replaced with the original asset. `[path]` is replaced with the path of the original asset and `[query]` with the query. Defaults to `"[path].gz[query]"`.
* `filename`: A `function(asset)` which receives the asset name (after processing `asset` option) and returns the new asset name. Defaults to `false`.
* `algorithm`: Can be a `function(buf, callback)` or a string. For a string the algorithm is taken from `zlib` (or zopfli for `zopfli`). Defaults to `"gzip"`.
* `test`: All assets matching this RegExp are processed. Defaults to every asset.
* `threshold`: Only assets bigger than this size are processed. In bytes. Defaults to `0`.
* `minRatio`: Only assets that compress better that this ratio are processed. Defaults to `0.8`.
* `deleteOriginalAssets`: Whether to delete the original assets or not. Defaults to `false`.
Option Arguments for Zopfli (see [node-zopfli](https://github.com/pierreinglebert/node-zopfli#options) doc for details):
* verbose: Default: false,
* verbose_more: Default: false,
* numiterations: Default: 15,
* blocksplitting: Default: true,
* blocksplittinglast: Default: false,
* blocksplittingmax: Default: 15
<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/compression-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/compression-webpack-plugin
[deps]: https://david-dm.org/webpack-contrib/compression-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/compression-webpack-plugin
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
+96
View File
@@ -0,0 +1,96 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var async = require("async");
var url = require('url');
var RawSource = require("webpack-sources/lib/RawSource");
function CompressionPlugin(options) {
options = options || {};
this.asset = options.asset || "[path].gz[query]";
this.algorithm = options.algorithm || "gzip";
this.filename = options.filename || false;
this.compressionOptions = {};
if(typeof this.algorithm === "string") {
if (this.algorithm === "zopfli") {
try {
var zopfli = require("node-zopfli");
} catch(err) {
throw new Error("node-zopfli not found");
}
this.compressionOptions = {
verbose: options.hasOwnProperty('verbose') ? options.verbose : false,
verbose_more: options.hasOwnProperty('verbose_more') ? options.verbose_more : false,
numiterations: options.numiterations ? options.numiterations : 15,
blocksplitting: options.hasOwnProperty('blocksplitting') ? options.blocksplitting : true,
blocksplittinglast: options.hasOwnProperty('blocksplittinglast') ? options.blocksplittinglast : false,
blocksplittingmax: options.blocksplittingmax ? options.blocksplittingmax : 15
};
this.algorithm = function (content, options, fn) {
zopfli.gzip(content, options, fn);
};
} else {
var zlib = require("zlib");
this.algorithm = zlib[this.algorithm];
if(!this.algorithm) throw new Error("Algorithm not found in zlib");
this.compressionOptions = {
level: options.level || 9,
flush: options.flush,
chunkSize: options.chunkSize,
windowBits: options.windowBits,
memLevel: options.memLevel,
strategy: options.strategy,
dictionary: options.dictionary
};
}
}
this.test = options.test || options.regExp;
this.threshold = options.threshold || 0;
this.minRatio = options.minRatio || 0.8;
this.deleteOriginalAssets = options.deleteOriginalAssets || false;
}
module.exports = CompressionPlugin;
CompressionPlugin.prototype.apply = function(compiler) {
compiler.plugin("this-compilation", function(compilation) {
compilation.plugin("optimize-assets", function(assets, callback) {
async.forEach(Object.keys(assets), function(file, callback) {
if(Array.isArray(this.test)) {
if(this.test.every(function(t) {
return !t.test(file);
})) return callback();
} else if(this.test && !this.test.test(file))
return callback();
var asset = assets[file];
var content = asset.source();
if(!Buffer.isBuffer(content))
content = new Buffer(content, "utf-8");
var originalSize = content.length;
if(originalSize < this.threshold) return callback();
this.algorithm(content, this.compressionOptions, function(err, result) {
if(err) return callback(err);
if(result.length / originalSize > this.minRatio) return callback();
var parse = url.parse(file);
var sub = {
file: file,
path: parse.pathname,
query: parse.query || ""
};
var newFile = this.asset.replace(/\[(file|path|query)\]/g, function(p0,p1) {
return sub[p1];
});
if (typeof this.filename === 'function') {
newFile = this.filename(newFile);
}
assets[newFile] = new RawSource(result);
if (this.deleteOriginalAssets) {
delete assets[file];
}
callback();
}.bind(this));
}.bind(this), callback);
}.bind(this));
}.bind(this));
};
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2010 Caolan McMahon
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.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
{
"name": "async",
"repo": "caolan/async",
"description": "Higher-order functions and common patterns for asynchronous code",
"version": "0.1.23",
"keywords": [],
"dependencies": {},
"development": {},
"main": "lib/async.js",
"scripts": [ "lib/async.js" ]
}
+958
View File
@@ -0,0 +1,958 @@
/*global setImmediate: false, setTimeout: false, console: false */
(function () {
var async = {};
// global on the server, window in the browser
var root, previous_async;
root = this;
if (root != null) {
previous_async = root.async;
}
async.noConflict = function () {
root.async = previous_async;
return async;
};
function only_once(fn) {
var called = false;
return function() {
if (called) throw new Error("Callback was already called.");
called = true;
fn.apply(root, arguments);
}
}
//// cross-browser compatiblity functions ////
var _each = function (arr, iterator) {
if (arr.forEach) {
return arr.forEach(iterator);
}
for (var i = 0; i < arr.length; i += 1) {
iterator(arr[i], i, arr);
}
};
var _map = function (arr, iterator) {
if (arr.map) {
return arr.map(iterator);
}
var results = [];
_each(arr, function (x, i, a) {
results.push(iterator(x, i, a));
});
return results;
};
var _reduce = function (arr, iterator, memo) {
if (arr.reduce) {
return arr.reduce(iterator, memo);
}
_each(arr, function (x, i, a) {
memo = iterator(memo, x, i, a);
});
return memo;
};
var _keys = function (obj) {
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
keys.push(k);
}
}
return keys;
};
//// exported async module functions ////
//// nextTick implementation with browser-compatible fallback ////
if (typeof process === 'undefined' || !(process.nextTick)) {
if (typeof setImmediate === 'function') {
async.nextTick = function (fn) {
// not a direct alias for IE10 compatibility
setImmediate(fn);
};
async.setImmediate = async.nextTick;
}
else {
async.nextTick = function (fn) {
setTimeout(fn, 0);
};
async.setImmediate = async.nextTick;
}
}
else {
async.nextTick = process.nextTick;
if (typeof setImmediate !== 'undefined') {
async.setImmediate = function (fn) {
// not a direct alias for IE10 compatibility
setImmediate(fn);
};
}
else {
async.setImmediate = async.nextTick;
}
}
async.each = function (arr, iterator, callback) {
callback = callback || function () {};
if (!arr.length) {
return callback();
}
var completed = 0;
_each(arr, function (x) {
iterator(x, only_once(function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
if (completed >= arr.length) {
callback(null);
}
}
}));
});
};
async.forEach = async.each;
async.eachSeries = function (arr, iterator, callback) {
callback = callback || function () {};
if (!arr.length) {
return callback();
}
var completed = 0;
var iterate = function () {
iterator(arr[completed], function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
if (completed >= arr.length) {
callback(null);
}
else {
iterate();
}
}
});
};
iterate();
};
async.forEachSeries = async.eachSeries;
async.eachLimit = function (arr, limit, iterator, callback) {
var fn = _eachLimit(limit);
fn.apply(null, [arr, iterator, callback]);
};
async.forEachLimit = async.eachLimit;
var _eachLimit = function (limit) {
return function (arr, iterator, callback) {
callback = callback || function () {};
if (!arr.length || limit <= 0) {
return callback();
}
var completed = 0;
var started = 0;
var running = 0;
(function replenish () {
if (completed >= arr.length) {
return callback();
}
while (running < limit && started < arr.length) {
started += 1;
running += 1;
iterator(arr[started - 1], function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
running -= 1;
if (completed >= arr.length) {
callback();
}
else {
replenish();
}
}
});
}
})();
};
};
var doParallel = function (fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [async.each].concat(args));
};
};
var doParallelLimit = function(limit, fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [_eachLimit(limit)].concat(args));
};
};
var doSeries = function (fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [async.eachSeries].concat(args));
};
};
var _asyncMap = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (err, v) {
results[x.index] = v;
callback(err);
});
}, function (err) {
callback(err, results);
});
};
async.map = doParallel(_asyncMap);
async.mapSeries = doSeries(_asyncMap);
async.mapLimit = function (arr, limit, iterator, callback) {
return _mapLimit(limit)(arr, iterator, callback);
};
var _mapLimit = function(limit) {
return doParallelLimit(limit, _asyncMap);
};
// reduce only has a series version, as doing reduce in parallel won't
// work in many situations.
async.reduce = function (arr, memo, iterator, callback) {
async.eachSeries(arr, function (x, callback) {
iterator(memo, x, function (err, v) {
memo = v;
callback(err);
});
}, function (err) {
callback(err, memo);
});
};
// inject alias
async.inject = async.reduce;
// foldl alias
async.foldl = async.reduce;
async.reduceRight = function (arr, memo, iterator, callback) {
var reversed = _map(arr, function (x) {
return x;
}).reverse();
async.reduce(reversed, memo, iterator, callback);
};
// foldr alias
async.foldr = async.reduceRight;
var _filter = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (v) {
if (v) {
results.push(x);
}
callback();
});
}, function (err) {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
};
async.filter = doParallel(_filter);
async.filterSeries = doSeries(_filter);
// select alias
async.select = async.filter;
async.selectSeries = async.filterSeries;
var _reject = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (v) {
if (!v) {
results.push(x);
}
callback();
});
}, function (err) {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
};
async.reject = doParallel(_reject);
async.rejectSeries = doSeries(_reject);
var _detect = function (eachfn, arr, iterator, main_callback) {
eachfn(arr, function (x, callback) {
iterator(x, function (result) {
if (result) {
main_callback(x);
main_callback = function () {};
}
else {
callback();
}
});
}, function (err) {
main_callback();
});
};
async.detect = doParallel(_detect);
async.detectSeries = doSeries(_detect);
async.some = function (arr, iterator, main_callback) {
async.each(arr, function (x, callback) {
iterator(x, function (v) {
if (v) {
main_callback(true);
main_callback = function () {};
}
callback();
});
}, function (err) {
main_callback(false);
});
};
// any alias
async.any = async.some;
async.every = function (arr, iterator, main_callback) {
async.each(arr, function (x, callback) {
iterator(x, function (v) {
if (!v) {
main_callback(false);
main_callback = function () {};
}
callback();
});
}, function (err) {
main_callback(true);
});
};
// all alias
async.all = async.every;
async.sortBy = function (arr, iterator, callback) {
async.map(arr, function (x, callback) {
iterator(x, function (err, criteria) {
if (err) {
callback(err);
}
else {
callback(null, {value: x, criteria: criteria});
}
});
}, function (err, results) {
if (err) {
return callback(err);
}
else {
var fn = function (left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
};
callback(null, _map(results.sort(fn), function (x) {
return x.value;
}));
}
});
};
async.auto = function (tasks, callback) {
callback = callback || function () {};
var keys = _keys(tasks);
if (!keys.length) {
return callback(null);
}
var results = {};
var listeners = [];
var addListener = function (fn) {
listeners.unshift(fn);
};
var removeListener = function (fn) {
for (var i = 0; i < listeners.length; i += 1) {
if (listeners[i] === fn) {
listeners.splice(i, 1);
return;
}
}
};
var taskComplete = function () {
_each(listeners.slice(0), function (fn) {
fn();
});
};
addListener(function () {
if (_keys(results).length === keys.length) {
callback(null, results);
callback = function () {};
}
});
_each(keys, function (k) {
var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
var taskCallback = function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
if (err) {
var safeResults = {};
_each(_keys(results), function(rkey) {
safeResults[rkey] = results[rkey];
});
safeResults[k] = args;
callback(err, safeResults);
// stop subsequent errors hitting callback multiple times
callback = function () {};
}
else {
results[k] = args;
async.setImmediate(taskComplete);
}
};
var requires = task.slice(0, Math.abs(task.length - 1)) || [];
var ready = function () {
return _reduce(requires, function (a, x) {
return (a && results.hasOwnProperty(x));
}, true) && !results.hasOwnProperty(k);
};
if (ready()) {
task[task.length - 1](taskCallback, results);
}
else {
var listener = function () {
if (ready()) {
removeListener(listener);
task[task.length - 1](taskCallback, results);
}
};
addListener(listener);
}
});
};
async.waterfall = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor !== Array) {
var err = new Error('First argument to waterfall must be an array of functions');
return callback(err);
}
if (!tasks.length) {
return callback();
}
var wrapIterator = function (iterator) {
return function (err) {
if (err) {
callback.apply(null, arguments);
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
async.setImmediate(function () {
iterator.apply(null, args);
});
}
};
};
wrapIterator(async.iterator(tasks))();
};
var _parallel = function(eachfn, tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
eachfn.map(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
callback.call(null, err, args);
});
}
}, callback);
}
else {
var results = {};
eachfn.each(_keys(tasks), function (k, callback) {
tasks[k](function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
results[k] = args;
callback(err);
});
}, function (err) {
callback(err, results);
});
}
};
async.parallel = function (tasks, callback) {
_parallel({ map: async.map, each: async.each }, tasks, callback);
};
async.parallelLimit = function(tasks, limit, callback) {
_parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback);
};
async.series = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
async.mapSeries(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
callback.call(null, err, args);
});
}
}, callback);
}
else {
var results = {};
async.eachSeries(_keys(tasks), function (k, callback) {
tasks[k](function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
results[k] = args;
callback(err);
});
}, function (err) {
callback(err, results);
});
}
};
async.iterator = function (tasks) {
var makeCallback = function (index) {
var fn = function () {
if (tasks.length) {
tasks[index].apply(null, arguments);
}
return fn.next();
};
fn.next = function () {
return (index < tasks.length - 1) ? makeCallback(index + 1): null;
};
return fn;
};
return makeCallback(0);
};
async.apply = function (fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function () {
return fn.apply(
null, args.concat(Array.prototype.slice.call(arguments))
);
};
};
var _concat = function (eachfn, arr, fn, callback) {
var r = [];
eachfn(arr, function (x, cb) {
fn(x, function (err, y) {
r = r.concat(y || []);
cb(err);
});
}, function (err) {
callback(err, r);
});
};
async.concat = doParallel(_concat);
async.concatSeries = doSeries(_concat);
async.whilst = function (test, iterator, callback) {
if (test()) {
iterator(function (err) {
if (err) {
return callback(err);
}
async.whilst(test, iterator, callback);
});
}
else {
callback();
}
};
async.doWhilst = function (iterator, test, callback) {
iterator(function (err) {
if (err) {
return callback(err);
}
if (test()) {
async.doWhilst(iterator, test, callback);
}
else {
callback();
}
});
};
async.until = function (test, iterator, callback) {
if (!test()) {
iterator(function (err) {
if (err) {
return callback(err);
}
async.until(test, iterator, callback);
});
}
else {
callback();
}
};
async.doUntil = function (iterator, test, callback) {
iterator(function (err) {
if (err) {
return callback(err);
}
if (!test()) {
async.doUntil(iterator, test, callback);
}
else {
callback();
}
});
};
async.queue = function (worker, concurrency) {
if (concurrency === undefined) {
concurrency = 1;
}
function _insert(q, data, pos, callback) {
if(data.constructor !== Array) {
data = [data];
}
_each(data, function(task) {
var item = {
data: task,
callback: typeof callback === 'function' ? callback : null
};
if (pos) {
q.tasks.unshift(item);
} else {
q.tasks.push(item);
}
if (q.saturated && q.tasks.length === concurrency) {
q.saturated();
}
async.setImmediate(q.process);
});
}
var workers = 0;
var q = {
tasks: [],
concurrency: concurrency,
saturated: null,
empty: null,
drain: null,
push: function (data, callback) {
_insert(q, data, false, callback);
},
unshift: function (data, callback) {
_insert(q, data, true, callback);
},
process: function () {
if (workers < q.concurrency && q.tasks.length) {
var task = q.tasks.shift();
if (q.empty && q.tasks.length === 0) {
q.empty();
}
workers += 1;
var next = function () {
workers -= 1;
if (task.callback) {
task.callback.apply(task, arguments);
}
if (q.drain && q.tasks.length + workers === 0) {
q.drain();
}
q.process();
};
var cb = only_once(next);
worker(task.data, cb);
}
},
length: function () {
return q.tasks.length;
},
running: function () {
return workers;
}
};
return q;
};
async.cargo = function (worker, payload) {
var working = false,
tasks = [];
var cargo = {
tasks: tasks,
payload: payload,
saturated: null,
empty: null,
drain: null,
push: function (data, callback) {
if(data.constructor !== Array) {
data = [data];
}
_each(data, function(task) {
tasks.push({
data: task,
callback: typeof callback === 'function' ? callback : null
});
if (cargo.saturated && tasks.length === payload) {
cargo.saturated();
}
});
async.setImmediate(cargo.process);
},
process: function process() {
if (working) return;
if (tasks.length === 0) {
if(cargo.drain) cargo.drain();
return;
}
var ts = typeof payload === 'number'
? tasks.splice(0, payload)
: tasks.splice(0);
var ds = _map(ts, function (task) {
return task.data;
});
if(cargo.empty) cargo.empty();
working = true;
worker(ds, function () {
working = false;
var args = arguments;
_each(ts, function (data) {
if (data.callback) {
data.callback.apply(null, args);
}
});
process();
});
},
length: function () {
return tasks.length;
},
running: function () {
return working;
}
};
return cargo;
};
var _console_fn = function (name) {
return function (fn) {
var args = Array.prototype.slice.call(arguments, 1);
fn.apply(null, args.concat([function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (typeof console !== 'undefined') {
if (err) {
if (console.error) {
console.error(err);
}
}
else if (console[name]) {
_each(args, function (x) {
console[name](x);
});
}
}
}]));
};
};
async.log = _console_fn('log');
async.dir = _console_fn('dir');
/*async.info = _console_fn('info');
async.warn = _console_fn('warn');
async.error = _console_fn('error');*/
async.memoize = function (fn, hasher) {
var memo = {};
var queues = {};
hasher = hasher || function (x) {
return x;
};
var memoized = function () {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
var key = hasher.apply(null, args);
if (key in memo) {
callback.apply(null, memo[key]);
}
else if (key in queues) {
queues[key].push(callback);
}
else {
queues[key] = [callback];
fn.apply(null, args.concat([function () {
memo[key] = arguments;
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, arguments);
}
}]));
}
};
memoized.memo = memo;
memoized.unmemoized = fn;
return memoized;
};
async.unmemoize = function (fn) {
return function () {
return (fn.unmemoized || fn).apply(null, arguments);
};
};
async.times = function (count, iterator, callback) {
var counter = [];
for (var i = 0; i < count; i++) {
counter.push(i);
}
return async.map(counter, iterator, callback);
};
async.timesSeries = function (count, iterator, callback) {
var counter = [];
for (var i = 0; i < count; i++) {
counter.push(i);
}
return async.mapSeries(counter, iterator, callback);
};
async.compose = function (/* functions... */) {
var fns = Array.prototype.reverse.call(arguments);
return function () {
var that = this;
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
async.reduce(fns, args, function (newargs, fn, cb) {
fn.apply(that, newargs.concat([function () {
var err = arguments[0];
var nextargs = Array.prototype.slice.call(arguments, 1);
cb(err, nextargs);
}]))
},
function (err, results) {
callback.apply(that, [err].concat(results));
});
};
};
var _applyEach = function (eachfn, fns /*args...*/) {
var go = function () {
var that = this;
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
return eachfn(fns, function (fn, cb) {
fn.apply(that, args.concat([cb]));
},
callback);
};
if (arguments.length > 2) {
var args = Array.prototype.slice.call(arguments, 2);
return go.apply(this, args);
}
else {
return go;
}
};
async.applyEach = doParallel(_applyEach);
async.applyEachSeries = doSeries(_applyEach);
async.forever = function (fn, callback) {
function next(err) {
if (err) {
if (callback) {
return callback(err);
}
throw err;
}
fn(next);
}
next();
};
// AMD / RequireJS
if (typeof define !== 'undefined' && define.amd) {
define([], function () {
return async;
});
}
// Node.js
else if (typeof module !== 'undefined' && module.exports) {
module.exports = async;
}
// included directly via <script> tag
else {
root.async = async;
}
}());
+103
View File
@@ -0,0 +1,103 @@
{
"_args": [
[
"async@0.2.x",
"/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5/node_modules/compression-webpack-plugin"
]
],
"_cnpm_publish_time": 1390494237271,
"_from": "async@>=0.2.0 <0.3.0",
"_hasShrinkwrap": false,
"_id": "async@0.2.10",
"_inCache": true,
"_installable": true,
"_location": "/compression-webpack-plugin/async",
"_npmUser": {
"email": "caolan.mcmahon@gmail.com",
"name": "caolan"
},
"_npmVersion": "1.3.2",
"_phantomChildren": {},
"_requested": {
"name": "async",
"raw": "async@0.2.x",
"rawSpec": "0.2.x",
"scope": null,
"spec": ">=0.2.0 <0.3.0",
"type": "range"
},
"_requiredBy": [
"/compression-webpack-plugin"
],
"_resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
"_shasum": "b6bbe0b0674b9d719708ca38de8c237cb526c3d1",
"_shrinkwrap": null,
"_spec": "async@0.2.x",
"_where": "/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5/node_modules/compression-webpack-plugin",
"author": {
"name": "Caolan McMahon"
},
"bugs": {
"url": "https://github.com/caolan/async/issues"
},
"dependencies": {},
"description": "Higher-order functions and common patterns for asynchronous code",
"devDependencies": {
"nodelint": ">0.0.0",
"nodeunit": ">0.0.0",
"uglify-js": "1.2.x"
},
"directories": {},
"dist": {
"noattachment": false,
"shasum": "b6bbe0b0674b9d719708ca38de8c237cb526c3d1",
"size": 15772,
"tarball": "http://registry.npm.taobao.org/async/download/async-0.2.10.tgz"
},
"homepage": "https://github.com/caolan/async#readme",
"jam": {
"include": [
"LICENSE",
"README.md",
"lib/async.js"
],
"main": "lib/async.js"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/caolan/async/raw/master/LICENSE"
}
],
"main": "./lib/async",
"maintainers": [
{
"name": "aearly",
"email": "alexander.early@gmail.com"
},
{
"name": "beaugunderson",
"email": "beau@beaugunderson.com"
},
{
"name": "caolan",
"email": "caolan.mcmahon@gmail.com"
},
{
"name": "megawac",
"email": "megawac@gmail.com"
}
],
"name": "async",
"optionalDependencies": {},
"publish_time": 1390494237271,
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/caolan/async.git"
},
"scripts": {
"test": "nodeunit test/test-async.js"
},
"version": "0.2.10"
}
@@ -0,0 +1,219 @@
# webpack-sources
Contains multiple classes which represent a `Source`. A `Source` can be asked for source code, size, source map and hash.
## `Source`
Base class for all sources.
### Public methods
All methods should be considered as expensive as they may need to do computations.
#### `source`
``` js
Source.prototype.source() -> String
```
Returns the represented source code as string.
#### `size`
``` js
Source.prototype.size() -> Number
```
Returns the size in chars of the represented source code.
#### `map`
``` js
Source.prototype.map(options: Object) -> Object | null
```
Returns the SourceMap of the represented source code as JSON. May return `null` if no SourceMap is available.
The `options` object can contain the following keys:
* `columns: Boolean` (default `true`): If set to false the implementation may omit mappings for columns.
* `module: Boolean` (default `true`): If set to false the implementation may omit inner mappings for modules.
#### `sourceAndMap`
``` js
Source.prototype.sourceAndMap(options: Object) -> {
code: String,
map: Object
}
```
Returns both, source code (like `Source.prototype.source()` and SourceMap (like `Source.prototype.map()`). This method could have better performance than calling `source()` and `map()` separatly.
See `map()` for `options`.
#### `updateHash`
``` js
Source.prototype.updateHash(hash: Hash) -> void
```
Updates the provided `Hash` object with the content of the represented source code. (`Hash` is an object with an `update` method, which is called with string values)
#### `node` (optional)
``` js
Source.prototype.node(options: Object) -> SourceNode
```
This is an optional method. It may be `null` if not implemented.
Returns a `SourceNode` (see source-map library) for the represented source code.
See `map()` for `options`.
#### `listNode` (optional)
``` js
Source.prototype.listNode(options: Object) -> SourceNode
```
This is an optional method. It may be `null` if not implemented.
Returns a `SourceListMap` (see source-list-map library) for the represented source code.
See `map()` for `options`.
## `RawSource`
Represents source code without SourceMap.
``` js
new RawSource(sourceCode: String)
```
## `OriginalSource`
Represents source code, which is a copy of the original file.
``` js
new OriginalSource(
sourceCode: String,
name: String
)
```
* `sourceCode`: The source code.
* `name`: The filename of the original source code.
OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (`;`, `{`, `}`).
## `SourceMapSource`
Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
``` js
new SourceMapSource(
sourceCode: String,
name: String,
sourceMap: Object | String,
originalSource?: String,
innerSourceMap?: Object | String
)
```
* `sourceCode`: The source code.
* `name`: The filename of the original source code.
* `sourceMap`: The SourceMap for the source code.
* `originalSource`: The source code of the original file. Can be omitted if the `sourceMap` already contains the original source code.
* `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
## `LineToLineMappedSource`
Represents source code, which is mapped line by line to the orginal file.
``` js
new LineToLineMappedSource(
sourceCode: String,
name: String,
originalSource: String
)
```
* `sourceCode`: The source code.
* `name`: The filename of the original source code.
* `originalSource`: The original source code.
## `CachedSource`
Decorates a `Source` and caches returned results of `map`, `source`, `size` and `sourceAndMap` in memory. Every other operation is delegated to the wrapped `Source`.
``` js
new CachedSource(source: Source)
```
## `PrefixSource`
Prefix every line of the decorated `Source` with a provided string.
``` js
new PrefixSource(
prefix: String,
source: Source
)
```
## `ConcatSource`
Concatenate mulitple `Source`s or strings to a single source.
``` js
new ConcatSource(
...items?: Source | String
)
```
### Public methods
#### `add`
``` js
ConcatSource.prototype.add(item: Source | String)
```
Adds an item to the source.
## `ReplaceSource`
Decorates a `Source` with replacements and insertions of source code.
### Public methods
#### `replace`
``` js
ReplaceSource.prototype.replace(
start: Number,
end: Number,
replacement: String
)
```
Replaces chars from `start` (0-indexed, inclusive) to `end` (0-indexed, inclusive) with `replacement`.
Locations represents locations in the original source and are not influenced by other replacements or insertions.
#### `insert`
``` js
ReplaceSource.prototype.insert(
pos: Number,
insertion: String
)
```
Inserts the `insertion` before char `pos` (0-indexed).
Location represents location in the original source and is not influenced by other replacements or insertions.
@@ -0,0 +1,70 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function CachedSource(source) {
this._source = source;
this._cachedSource = undefined;
this._cachedSize = undefined;
this._cachedMaps = {};
if(source.node) this.node = function(options) {
return this._source.node(options);
};
if(source.listMap) this.listMap = function(options) {
return this._source.listMap(options);
};
}
module.exports = CachedSource;
CachedSource.prototype.source = function() {
if(typeof this._cachedSource !== "undefined") return this._cachedSource;
return this._cachedSource = this._source.source();
};
CachedSource.prototype.size = function() {
if(typeof this._cachedSize !== "undefined") return this._cachedSize;
if(typeof this._cachedSource !== "undefined")
return this._cachedSize = this._cachedSource.length;
return this._cachedSize = this._source.size();
};
CachedSource.prototype.sourceAndMap = function(options) {
var key = JSON.stringify(options);
if(typeof this._cachedSource !== "undefined" && key in this._cachedMaps)
return {
source: this._cachedSource,
map: this._cachedMaps[key]
};
else if(typeof this._cachedSource !== "undefined") {
return {
source: this._cachedSource,
map: this._cachedMaps[key] = this._source.map(options)
};
} else if(key in this._cachedMaps) {
return {
source: this._cachedSource = this._source.source(),
map: this._cachedMaps[key]
};
}
var result = this._source.sourceAndMap(options);
this._cachedSource = result.source;
this._cachedMaps[key] = result.map;
return {
source: this._cachedSource,
map: this._cachedMaps[key]
};
};
CachedSource.prototype.map = function(options) {
if(!options) options = {};
var key = JSON.stringify(options);
if(key in this._cachedMaps)
return this._cachedMaps[key];
return this._cachedMaps[key] = this._source.map();
};
CachedSource.prototype.updateHash = function(hash) {
this._source.updateHash(hash);
};
@@ -0,0 +1,63 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceListMap = require("source-list-map").SourceListMap;
var Source = require("./Source");
function ConcatSource() {
Source.call(this);
this.children = Array.prototype.slice.call(arguments);
}
module.exports = ConcatSource;
ConcatSource.prototype = Object.create(Source.prototype);
ConcatSource.prototype.constructor = ConcatSource;
ConcatSource.prototype.add = function(item) {
this.children.push(item);
};
ConcatSource.prototype.source = function() {
return this.children.map(function(item) {
return typeof item === "string" ? item : item.source();
}).join("");
};
ConcatSource.prototype.size = function() {
return this.children.map(function(item) {
return typeof item === "string" ? item.length : item.size();
}).reduce(function(sum, s) {
return sum + s;
}, 0);
};
require("./SourceAndMapMixin")(ConcatSource.prototype);
ConcatSource.prototype.node = function(options) {
var node = new SourceNode(null, null, null, this.children.map(function(item) {
return typeof item === "string" ? item : item.node(options);
}));
return node;
};
ConcatSource.prototype.listMap = function(options) {
var map = new SourceListMap();
this.children.forEach(function(item) {
if(typeof item === "string")
map.add(item);
else
map.add(item.listMap(options));
});
return map;
};
ConcatSource.prototype.updateHash = function(hash) {
this.children.forEach(function(item) {
if(typeof item === "string")
hash.update(item);
else
item.updateHash(hash);
});
};
@@ -0,0 +1,48 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var SourceListMap = require("source-list-map").SourceListMap;
var Source = require("./Source");
function LineToLineMappedSource(value, name, originalSource) {
Source.call(this);
this._value = value;
this._name = name;
this._originalSource = originalSource;
}
module.exports = LineToLineMappedSource;
LineToLineMappedSource.prototype = Object.create(Source.prototype);
LineToLineMappedSource.prototype.constructor = LineToLineMappedSource;
LineToLineMappedSource.prototype.source = function() {
return this._value;
};
require("./SourceAndMapMixin")(LineToLineMappedSource.prototype);
LineToLineMappedSource.prototype.node = function(options) {
var value = this._value;
var name = this._name;
var lines = value.split("\n");
var node = new SourceNode(null, null, null,
lines.map(function(line, idx) {
return new SourceNode(idx + 1, 0, name, (line + (idx != lines.length - 1 ? "\n" : "")));
})
);
node.setSourceContent(name, this._originalSource);
return node;
};
LineToLineMappedSource.prototype.listMap = function(options) {
return new SourceListMap(this._value, this._name, this._originalSource)
};
LineToLineMappedSource.prototype.updateHash = function(hash) {
hash.update(this._value);
hash.update(this._originalSource);
};
@@ -0,0 +1,88 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var SourceListMap = require("source-list-map").SourceListMap;
var Source = require("./Source");
function isSplitter(c) {
switch(c) {
case 10: // \n
case 13: // \r
case 59: // ;
case 123: // {
case 125: // }
return true;
}
return false;
}
function _splitCode(code) {
var result = [];
var i = 0;
var j = 0;
for(; i < code.length; i++) {
if(isSplitter(code.charCodeAt(i))) {
while(isSplitter(code.charCodeAt(++i)));
result.push(code.substring(j, i));
j = i;
}
}
if(j < code.length)
result.push(code.substr(j));
return result;
}
function OriginalSource(value, name) {
Source.call(this);
this._value = value;
this._name = name;
}
module.exports = OriginalSource;
OriginalSource.prototype = Object.create(Source.prototype);
OriginalSource.prototype.constructor = OriginalSource;
OriginalSource.prototype.source = function() {
return this._value;
};
require("./SourceAndMapMixin")(OriginalSource.prototype);
OriginalSource.prototype.node = function(options) {
options = options || {};
var sourceMap = this._sourceMap;
var value = this._value;
var name = this._name;
var lines = value.split("\n");
var node = new SourceNode(null, null, null,
lines.map(function(line, idx) {
var pos = 0;
if(options.columns === false) {
var content = line + (idx != lines.length - 1 ? "\n" : "");
return new SourceNode(idx + 1, 0, name, content);
}
return new SourceNode(null, null, null,
_splitCode(line + (idx != lines.length - 1 ? "\n" : "")).map(function(item) {
if(/^\s*$/.test(item)) return item;
var res = new SourceNode(idx + 1, pos, name, item);
pos += item.length;
return res;
})
);
})
);
node.setSourceContent(name, value);
return node;
};
OriginalSource.prototype.listMap = function(options) {
return new SourceListMap(this._value, this._name, this._value)
};
OriginalSource.prototype.updateHash = function(hash) {
hash.update(this._value);
};
@@ -0,0 +1,75 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var Source = require("./Source");
var SourceNode = require("source-map").SourceNode;
var REPLACE_REGEX = /\n(?=.|\s)/g
function PrefixSource(prefix, source) {
Source.call(this);
this._source = source;
this._prefix = prefix;
}
module.exports = PrefixSource;
PrefixSource.prototype = Object.create(Source.prototype);
PrefixSource.prototype.constructor = PrefixSource;
PrefixSource.prototype.source = function() {
var node = typeof this._source === "string" ? this._source : this._source.source();
var prefix = this._prefix;
return prefix + node.replace(REPLACE_REGEX, "\n" + prefix);
};
require("./SourceAndMapMixin")(PrefixSource.prototype);
PrefixSource.prototype.node = function(options) {
var node = this._source.node(options);
var append = [this._prefix];
return new SourceNode(null, null, null, [
cloneAndPrefix(node, this._prefix, append)
]);
};
PrefixSource.prototype.listMap = function(options) {
var prefix = this._prefix;
var map = this._source.listMap(options);
map.mapGeneratedCode(function(code) {
return prefix + code.replace(REPLACE_REGEX, "\n" + prefix);
});
return map;
};
PrefixSource.prototype.updateHash = function(hash) {
if(typeof this._source === "string")
hash.update(this._source);
else
this._source.updateHash(hash);
if(typeof this._prefix === "string")
hash.update(this._prefix);
else
this._prefix.updateHash(hash);
};
function cloneAndPrefix(node, prefix, append) {
if(typeof node === "string") {
var result = node.replace(REPLACE_REGEX, "\n" + prefix);
if(append.length > 0) result = append.pop() + result;
if(/\n$/.test(node)) append.push(prefix);
return result;
} else {
var newNode = new SourceNode(
node.line,
node.column,
node.source,
node.children.map(function(node) {
return cloneAndPrefix(node, prefix, append);
}),
node.name
);
newNode.sourceContents = node.sourceContents;
return newNode;
}
};
@@ -0,0 +1,36 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var Source = require("./Source");
var SourceNode = require("source-map").SourceNode;
var SourceListMap = require("source-list-map").SourceListMap;
function RawSource(value) {
Source.call(this);
this._value = value;
}
module.exports = RawSource;
RawSource.prototype = Object.create(Source.prototype);
RawSource.prototype.constructor = RawSource;
RawSource.prototype.source = function() {
return this._value;
};
RawSource.prototype.map = function(options) {
return null;
};
RawSource.prototype.node = function(options) {
return new SourceNode(null, null, null, this._value);
};
RawSource.prototype.listMap = function(options) {
return new SourceListMap(this._value);
};
RawSource.prototype.updateHash = function(hash) {
hash.update(this._value);
};
@@ -0,0 +1,165 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var Source = require("./Source");
var SourceNode = require("source-map").SourceNode;
var SourceListMap = require("source-list-map").SourceListMap;
var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
function ReplaceSource(source, name) {
Source.call(this);
this._source = source;
this._name = name;
this.replacements = [];
}
module.exports = ReplaceSource;
ReplaceSource.prototype = Object.create(Source.prototype);
ReplaceSource.prototype.constructor = ReplaceSource;
ReplaceSource.prototype.replace = function(start, end, newValue) {
if(typeof newValue !== "string")
throw new Error("insertion must be a string, but is a " + typeof newValue);
this.replacements.push([start, end, newValue, this.replacements.length]);
};
ReplaceSource.prototype.insert = function(pos, newValue) {
if(typeof newValue !== "string")
throw new Error("insertion must be a string, but is a " + typeof newValue + ": " + newValue);
this.replacements.push([pos, pos - 1, newValue, this.replacements.length]);
};
ReplaceSource.prototype.source = function(options) {
return this._replaceString(this._source.source());
};
ReplaceSource.prototype._sortReplacements = function() {
this.replacements.sort(function(a, b) {
var diff = b[1] - a[1];
if(diff !== 0)
return diff;
diff = b[0] - a[0];
if(diff !== 0)
return diff;
return b[3] - a[3];
});
};
ReplaceSource.prototype._replaceString = function(str) {
if(typeof str !== "string")
throw new Error("str must be a string, but is a " + typeof str + ": " + str);
this._sortReplacements();
var result = [str];
this.replacements.forEach(function(repl) {
var remSource = result.pop();
var splitted1 = this._splitString(remSource, Math.floor(repl[1] + 1));
var splitted2 = this._splitString(splitted1[0], Math.floor(repl[0]));
result.push(splitted1[1], repl[2], splitted2[0]);
}, this);
result = result.reverse();
return result.join("");
};
require("./SourceAndMapMixin")(ReplaceSource.prototype);
ReplaceSource.prototype.node = function(options) {
this._sortReplacements();
var result = [this._source.node(options)];
this.replacements.forEach(function(repl) {
var remSource = result.pop();
var splitted1 = this._splitSourceNode(remSource, Math.floor(repl[1] + 1));
var splitted2;
if(Array.isArray(splitted1)) {
splitted2 = this._splitSourceNode(splitted1[0], Math.floor(repl[0]));
if(Array.isArray(splitted2)) {
result.push(splitted1[1], this._replacementToSourceNode(splitted2[1], repl[2]), splitted2[0]);
} else {
result.push(splitted1[1], this._replacementToSourceNode(splitted1[1], repl[2]), splitted1[0]);
}
} else {
splitted2 = this._splitSourceNode(remSource, Math.floor(repl[0]));
if(Array.isArray(splitted2)) {
result.push(this._replacementToSourceNode(splitted2[1], repl[2]), splitted2[0]);
} else {
result.push(repl[2], remSource);
}
}
}, this);
result = result.reverse();
return new SourceNode(null, null, null, result);
};
ReplaceSource.prototype.listMap = function(options) {
var map = this._source.listMap(options);
if(map.children.length !== 1) {
var code = map.toString();
code = this._replaceString(code).split("\n");
var currentIndex = 0;
map.mapGeneratedCode(function(str) {
var idx = -1;
var count = -1;
do {
count++;
idx = str.indexOf("\n", idx + 1);
} while (idx >= 0);
if(!count) return "";
var result = code.slice(currentIndex, currentIndex + count).join("\n") + "\n";
currentIndex += count;
return result;
});
map.add(code.slice(currentIndex).join("\n"));
} else {
map.mapGeneratedCode(this._replaceString.bind(this));
}
return map;
};
ReplaceSource.prototype._replacementToSourceNode = function(oldNode, newString) {
var map = oldNode.toStringWithSourceMap({
file: "?"
}).map;
var original = new SourceMapConsumer(map.toJSON()).originalPositionFor({
line: 1,
column: 0
});
if(original) {
return new SourceNode(original.line, original.column, original.source, newString);
} else {
return newString;
}
};
ReplaceSource.prototype._splitSourceNode = function(node, position) {
if(typeof node === "string") {
if(node.length <= position) return position - node.length;
return position <= 0 ? ["", node] : [node.substr(0, position), node.substr(position)];
} else {
for(var i = 0; i < node.children.length; i++) {
position = this._splitSourceNode(node.children[i], position);
if(Array.isArray(position)) {
var leftNode = new SourceNode(
node.line,
node.column,
node.source,
node.children.slice(0, i).concat([position[0]]),
node.name
);
var rightNode = new SourceNode(
node.line,
node.column,
node.source, [position[1]].concat(node.children.slice(i + 1)),
node.name
);
leftNode.sourceContents = node.sourceContents;
return [leftNode, rightNode];
}
}
return position;
}
};
ReplaceSource.prototype._splitString = function(str, position) {
return position <= 0 ? ["", str] : [str.substr(0, position), str.substr(position)];
};
@@ -0,0 +1,36 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
function Source() {}
module.exports = Source;
Source.prototype.source = null;
Source.prototype.size = function() {
return this.source().length;
};
Source.prototype.map = function(options) {
return null;
};
Source.prototype.sourceAndMap = function(options) {
return {
source: this.source(),
map: this.map()
};
};
Source.prototype.node = null;
Source.prototype.listNode = null;
Source.prototype.updateHash = function(hash) {
var source = this.source();
hash.update(source || "");
};
@@ -0,0 +1,36 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = function mixinSourceAndMap(proto) {
proto.map = function(options) {
options = options || {};
if(options.columns === false) {
return this.listMap(options).toStringWithSourceMap({
file: "x"
}).map;
}
return this.node(options).toStringWithSourceMap({
file: "x"
}).map.toJSON();
};
proto.sourceAndMap = function(options) {
options = options || {};
if(options.columns === false) {
//console.log(this.listMap(options).debugInfo());
return this.listMap(options).toStringWithSourceMap({
file: "x"
});
}
var res = this.node(options).toStringWithSourceMap({
file: "x"
});
return {
source: res.code,
map: res.map.toJSON()
};
};
}
@@ -0,0 +1,55 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var SourceMapGenerator = require("source-map").SourceMapGenerator;
var SourceListMap = require("source-list-map").SourceListMap;
var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
var Source = require("./Source");
function SourceMapSource(value, name, sourceMap, originalSource, innerSourceMap) {
Source.call(this);
this._value = value;
this._name = name;
this._sourceMap = sourceMap;
this._originalSource = originalSource;
this._innerSourceMap = innerSourceMap;
}
module.exports = SourceMapSource;
SourceMapSource.prototype = Object.create(Source.prototype);
SourceMapSource.prototype.constructor = SourceMapSource;
SourceMapSource.prototype.source = function() {
return this._value;
};
require("./SourceAndMapMixin")(SourceMapSource.prototype);
SourceMapSource.prototype.node = function(options) {
var innerSourceMap = this._innerSourceMap;
var sourceMap = this._sourceMap;
if(innerSourceMap) {
sourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
if(this._originalSource)
sourceMap.setSourceContent(this._name, this._originalSource);
innerSourceMap = new SourceMapConsumer(innerSourceMap);
sourceMap.applySourceMap(innerSourceMap, this._name);
sourceMap = sourceMap.toJSON();
}
return SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
};
SourceMapSource.prototype.listMap = function(options) {
if(options.module === false)
return new SourceListMap(this._value, this._name, this._value);
return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
};
SourceMapSource.prototype.updateHash = function(hash) {
hash.update(this._value);
if(this._originalSource)
hash.update(this._originalSource);
};
@@ -0,0 +1,15 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
exports.Source = require("./Source");
exports.RawSource = require("./RawSource");
exports.OriginalSource = require("./OriginalSource");
exports.SourceMapSource = require("./SourceMapSource");
exports.LineToLineMappedSource = require("./LineToLineMappedSource");
exports.CachedSource = require("./CachedSource");
exports.ConcatSource = require("./ConcatSource");
exports.ReplaceSource = require("./ReplaceSource");
exports.PrefixSource = require("./PrefixSource");
@@ -0,0 +1,124 @@
{
"_args": [
[
"webpack-sources@^0.1.0",
"/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5/node_modules/compression-webpack-plugin"
]
],
"_cnpm_publish_time": 1488917507369,
"_from": "webpack-sources@>=0.1.0 <0.2.0",
"_hasShrinkwrap": false,
"_id": "webpack-sources@0.1.5",
"_inCache": true,
"_installable": true,
"_location": "/compression-webpack-plugin/webpack-sources",
"_nodeVersion": "7.7.1",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/webpack-sources-0.1.5.tgz_1488917506799_0.5009965947829187"
},
"_npmUser": {
"email": "sean.larkin@cuw.edu",
"name": "thelarkinn"
},
"_npmVersion": "4.1.2",
"_phantomChildren": {},
"_requested": {
"name": "webpack-sources",
"raw": "webpack-sources@^0.1.0",
"rawSpec": "^0.1.0",
"scope": null,
"spec": ">=0.1.0 <0.2.0",
"type": "range"
},
"_requiredBy": [
"/compression-webpack-plugin"
],
"_resolved": "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-0.1.5.tgz",
"_shasum": "aa1f3abf0f0d74db7111c40e500b84f966640750",
"_shrinkwrap": null,
"_spec": "webpack-sources@^0.1.0",
"_where": "/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5/node_modules/compression-webpack-plugin",
"author": {
"name": "Tobias Koppers @sokra"
},
"bugs": {
"url": "https://github.com/webpack/webpack-sources/issues"
},
"dependencies": {
"source-list-map": "~0.1.7",
"source-map": "~0.5.3"
},
"description": "Source code handling classes for webpack",
"devDependencies": {
"beautify-lint": "^1.0.3",
"codecov.io": "^0.1.6",
"coveralls": "^2.11.6",
"eslint": "^1.1.0",
"eslint-plugin-nodeca": "^1.0.3",
"istanbul": "^0.4.1",
"js-beautify": "^1.5.10",
"mocha": "^2.3.4",
"should": "^8.0.2"
},
"directories": {},
"dist": {
"noattachment": false,
"shasum": "aa1f3abf0f0d74db7111c40e500b84f966640750",
"size": 7610,
"tarball": "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-0.1.5.tgz"
},
"files": [
"lib/"
],
"gitHead": "d4cbf577bc12570c079c1aed4ad8c196b6c919d5",
"homepage": "https://github.com/webpack/webpack-sources#readme",
"keywords": [
"source-map",
"webpack"
],
"license": "MIT",
"main": "./lib/index.js",
"maintainers": [
{
"name": "bebraw",
"email": "bebraw@gmail.com"
},
{
"name": "jhnns",
"email": "mail@johannesewald.de"
},
{
"name": "sokra",
"email": "tobias.koppers@googlemail.com"
},
{
"name": "spacek33z",
"email": "kees@webduck.nl"
},
{
"name": "thelarkinn",
"email": "sean.larkin@cuw.edu"
}
],
"name": "webpack-sources",
"optionalDependencies": {},
"publish_time": 1488917507369,
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/webpack/webpack-sources.git"
},
"scripts": {
"beautify": "beautify-rewrite lib/**.js test/**.js",
"beautify-lint": "beautify-lint lib/**.js test/**.js",
"cover": "istanbul cover node_modules/mocha/bin/_mocha",
"lint": "eslint lib test",
"precover": "npm run lint && npm run beautify-lint",
"pretest": "npm run lint && npm run beautify-lint",
"publish-patch": "npm test && npm version patch && git push && git push --tags && npm publish",
"test": "mocha --full-trace --check-leaks",
"travis": "npm run cover -- --report lcovonly"
},
"version": "0.1.5"
}
+110
View File
@@ -0,0 +1,110 @@
{
"_args": [
[
"compression-webpack-plugin",
"/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5"
]
],
"_cnpm_publish_time": 1491626538378,
"_from": "compression-webpack-plugin@latest",
"_hasShrinkwrap": false,
"_id": "compression-webpack-plugin@0.4.0",
"_inCache": true,
"_installable": true,
"_location": "/compression-webpack-plugin",
"_nodeVersion": "6.10.2",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/compression-webpack-plugin-0.4.0.tgz_1491626536272_0.7976787050720304"
},
"_npmUser": {
"email": "wiens.joshua@gmail.com",
"name": "d3viant0ne"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {
"source-list-map": "0.1.8",
"source-map": "0.5.6"
},
"_requested": {
"name": "compression-webpack-plugin",
"raw": "compression-webpack-plugin",
"rawSpec": "",
"scope": null,
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "http://registry.npm.taobao.org/compression-webpack-plugin/download/compression-webpack-plugin-0.4.0.tgz",
"_shasum": "811de04215f811ea6a12d4d8aed8457d758f13ac",
"_shrinkwrap": null,
"_spec": "compression-webpack-plugin",
"_where": "/Users/xmfish/Documents/Ash_Soft/ASHEBShop-h5",
"author": {
"name": "Tobias Koppers @sokra"
},
"bugs": {
"url": "https://github.com/webpack/compression-webpack-plugin/issues"
},
"dependencies": {
"async": "0.2.x",
"node-zopfli": "^2.0.0",
"webpack-sources": "^0.1.0"
},
"description": "Prepare compressed versions of assets to serve them with Content-Encoding",
"devDependencies": {
"standard-version": "^4.0.0"
},
"directories": {},
"dist": {
"noattachment": false,
"shasum": "811de04215f811ea6a12d4d8aed8457d758f13ac",
"size": 4169,
"tarball": "http://registry.npm.taobao.org/compression-webpack-plugin/download/compression-webpack-plugin-0.4.0.tgz"
},
"gitHead": "894a96b16caea8a6c7a29fa6134617736d81483d",
"homepage": "http://github.com/webpack/compression-webpack-plugin",
"license": "MIT",
"maintainers": [
{
"name": "bebraw",
"email": "bebraw@gmail.com"
},
{
"name": "d3viant0ne",
"email": "wiens.joshua@gmail.com"
},
{
"name": "ericclemmons",
"email": "eric@smarterspam.com"
},
{
"name": "jhnns",
"email": "mail@johannesewald.de"
},
{
"name": "sokra",
"email": "tobias.koppers@googlemail.com"
},
{
"name": "thelarkinn",
"email": "sean.larkin@cuw.edu"
}
],
"name": "compression-webpack-plugin",
"optionalDependencies": {
"node-zopfli": "^2.0.0"
},
"publish_time": 1491626538378,
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/webpack/compression-webpack-plugin.git"
},
"scripts": {
"release": "standard-version"
},
"version": "0.4.0"
}