pax_global_header00006660000000000000000000000064131403041700014503gustar00rootroot0000000000000052 comment=004df5643c1ac002a16de3ae8962330e1df3599d tapable-0.2.8/000077500000000000000000000000001314030417000131225ustar00rootroot00000000000000tapable-0.2.8/.editorconfig000066400000000000000000000005321314030417000155770ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 4 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 233 [*.json] indent_style = space indent_size = 2 [*.yml] indent_style = space indent_size = 2 [test/cases/parsing/bom/bomfile.{css,js}] charset = utf-8-bom [*.md] trim_trailing_whitespace = falsetapable-0.2.8/.eslintrc000066400000000000000000000004411314030417000147450ustar00rootroot00000000000000{ "env": { "node": true }, "rules": { "strict": 0, "curly": 0, "eol-last": 1, "no-shadow": 0, "no-redeclare": 1, "no-extra-bind": 1, "no-underscore-dangle": 0, "no-use-before-define": 0, "consistent-return": 0, "no-inner-declarations": 1, "no-loop-func": 1 } } tapable-0.2.8/.gitattributes000066400000000000000000000000141314030417000160100ustar00rootroot00000000000000* text=auto tapable-0.2.8/.gitignore000066400000000000000000000001741314030417000151140ustar00rootroot00000000000000/node_modules ############ ## Windows ############ # Windows image file caches Thumbs.db # Folder config file Desktop.initapable-0.2.8/.travis.yml000066400000000000000000000000711314030417000152310ustar00rootroot00000000000000sudo: false language: node_js node_js: - 4 - 6 - 7 tapable-0.2.8/README.md000066400000000000000000000112571314030417000144070ustar00rootroot00000000000000# Tapable ``` javascript var Tapable = require("tapable"); ``` `Tapable` is a class for plugin binding and applying. Just extend it. ``` javascript function MyClass() { Tapable.call(this); } MyClass.prototype = Object.create(Tapable.prototype); MyClass.prototype.method = function() {}; ``` Or mix it in. ``` javascript function MyClass2() { EventEmitter.call(this); Tapable.call(this); } MyClass2.prototype = Object.create(EventEmitter.prototype); Tapable.mixin(MyClass2.prototype); MyClass2.prototype.method = function() {}; ``` ## Public functions ### apply ``` javascript void apply(plugins: Plugin...) ``` Attaches all plugins passed as arguments to the instance, by calling `apply` on them. ### plugin ``` javascript void plugin(names: string|string[], handler: Function) ``` `names` are the names (or a single name) of the plugin interfaces the class provides. `handler` is a callback function. The signature depends on the class. `this` is the instance of the class. ## Protected functions ### applyPlugins ``` javascript void applyPlugins(name: string, args: any...) ``` Synchronously applies all registered handlers for `name`. The handler functions are called with all args. ### applyPluginsWaterfall ``` javascript any applyPluginsWaterfall(name: string, init: any, args: any...) ``` Synchronously applies all registered handlers for `name`. The handler functions are called with the return value of the previous handler and all args. For the first handler `init` is used and the return value of the last handler is return by `applyPluginsWaterfall` ### applyPluginsAsync ``` javascript void applyPluginsAsync( name: string, args: any..., callback: (err?: Error) -> void ) ``` Asynchronously applies all registered handlers for `name`. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The handler functions are called in order of registration. `callback` is called after all handlers are called. ### applyPluginsBailResult ``` javascript any applyPluginsBailResult(name: string, args: any...) ``` Synchronously applies all registered handlers for `name`. The handler function are called with all args. If a handler function returns something `!== undefined`, the value is returned and no more handlers are applied. ### applyPluginsAsyncWaterfall ``` javascript applyPluginsAsyncWaterfall( name: string, init: any, callback: (err: Error, result: any) -> void ) ``` Asynchronously applies all registered handlers for `name`. The handler functions are called with the current value and a callback function with the signature `(err: Error, nextValue: any) -> void`. When called, `nextValue` is the current value for the next handler. The current value for the first handler is `init`. After all handlers are applied, `callback` is called with the last value. If any handler passes a value for `err`, the `callback` is called with this error and no more handlers are called. ### applyPluginsAsyncSeries ``` javascript applyPluginsAsyncSeries( name: string, args: any..., callback: (err: Error, result: any) -> void ) ``` Asynchronously applies all registered handlers for `name`. The handler functions are called with all `args` and a callback function with the signature `(err: Error) -> void`. The handlers are called in series, one at a time. After all handlers are applied, `callback` is called. If any handler passes a value for `err`, the `callback` is called with this error and no more handlers are called. ### applyPluginsParallel ``` javascript applyPluginsParallel( name: string, args: any..., callback: (err?: Error) -> void ) ``` Applies all registered handlers for `name` in parallel. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The `callback` function is called when all handlers have called the callback without `err`. If any handler calls the callback with `err`, `callback` is invoked with this error and the other handlers are ignored. ### applyPluginsParallelBailResult ``` javascript applyPluginsParallelBailResult( name: string, args: any..., callback: (err: Error, result: any) -> void ) ``` Applies all registered handlers for `name` in parallel. The handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. Handler functions must call the callback. They can either pass an error, pass undefined, or pass a value. The first result (either error or value) which is not undefined is passed to the `callback`. The order is defined by registration, not by the speed of the handler function. ### hasPlugins ``` js hasPlugins( name: string ) ``` Returns true, if plugins are registered for this name. tapable-0.2.8/lib/000077500000000000000000000000001314030417000136705ustar00rootroot00000000000000tapable-0.2.8/lib/Tapable.js000066400000000000000000000257501314030417000156070ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ // polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter // using the polyfill specifically to avoid the call to `Object.defineProperty` for performance reasons function fastFilter(fun/*, thisArg*/) { 'use strict'; if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (typeof fun !== 'function') { throw new TypeError(); } var res = []; var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { if (i in t) { var val = t[i]; // NOTE: Technically this should Object.defineProperty at // the next index, as push can be affected by // properties on Object.prototype and Array.prototype. // But that method's new, and collisions should be // rare, so use the more-compatible alternative. if (fun.call(thisArg, val, i, t)) { res.push(val); } } } return res; } function Tapable() { this._plugins = {}; } module.exports = Tapable; function copyProperties(from, to) { for(var key in from) to[key] = from[key]; return to; } Tapable.mixin = function mixinTapable(pt) { copyProperties(Tapable.prototype, pt); }; Tapable.prototype.applyPlugins = function applyPlugins(name) { if(!this._plugins[name]) return; var args = Array.prototype.slice.call(arguments, 1); var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) plugins[i].apply(this, args); }; Tapable.prototype.applyPlugins0 = function applyPlugins0(name) { var plugins = this._plugins[name]; if(!plugins) return; for(var i = 0; i < plugins.length; i++) plugins[i].call(this); }; Tapable.prototype.applyPlugins1 = function applyPlugins1(name, param) { var plugins = this._plugins[name]; if(!plugins) return; for(var i = 0; i < plugins.length; i++) plugins[i].call(this, param); }; Tapable.prototype.applyPlugins2 = function applyPlugins2(name, param1, param2) { var plugins = this._plugins[name]; if(!plugins) return; for(var i = 0; i < plugins.length; i++) plugins[i].call(this, param1, param2); }; Tapable.prototype.applyPluginsWaterfall = function applyPluginsWaterfall(name, init) { if(!this._plugins[name]) return init; var args = Array.prototype.slice.call(arguments, 1); var plugins = this._plugins[name]; var current = init; for(var i = 0; i < plugins.length; i++) { args[0] = current; current = plugins[i].apply(this, args); } return current; }; Tapable.prototype.applyPluginsWaterfall0 = function applyPluginsWaterfall0(name, init) { var plugins = this._plugins[name]; if(!plugins) return init; var current = init; for(var i = 0; i < plugins.length; i++) current = plugins[i].call(this, current); return current; }; Tapable.prototype.applyPluginsWaterfall1 = function applyPluginsWaterfall1(name, init, param) { var plugins = this._plugins[name]; if(!plugins) return init; var current = init; for(var i = 0; i < plugins.length; i++) current = plugins[i].call(this, current, param); return current; }; Tapable.prototype.applyPluginsWaterfall2 = function applyPluginsWaterfall2(name, init, param1, param2) { var plugins = this._plugins[name]; if(!plugins) return init; var current = init; for(var i = 0; i < plugins.length; i++) current = plugins[i].call(this, current, param1, param2); return current; }; Tapable.prototype.applyPluginsBailResult = function applyPluginsBailResult(name) { if(!this._plugins[name]) return; var args = Array.prototype.slice.call(arguments, 1); var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].apply(this, args); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsBailResult1 = function applyPluginsBailResult1(name, param) { if(!this._plugins[name]) return; var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].call(this, param); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsBailResult2 = function applyPluginsBailResult2(name, param1, param2) { if(!this._plugins[name]) return; var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].call(this, param1, param2); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsBailResult3 = function applyPluginsBailResult3(name, param1, param2, param3) { if(!this._plugins[name]) return; var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].call(this, param1, param2, param3); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsBailResult4 = function applyPluginsBailResult4(name, param1, param2, param3, param4) { if(!this._plugins[name]) return; var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].call(this, param1, param2, param3, param4); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsBailResult5 = function applyPluginsBailResult5(name, param1, param2, param3, param4, param5) { if(!this._plugins[name]) return; var plugins = this._plugins[name]; for(var i = 0; i < plugins.length; i++) { var result = plugins[i].call(this, param1, param2, param3, param4, param5); if(typeof result !== "undefined") { return result; } } }; Tapable.prototype.applyPluginsAsyncSeries = Tapable.prototype.applyPluginsAsync = function applyPluginsAsyncSeries(name) { var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); var plugins = this._plugins[name]; if(!plugins || plugins.length === 0) return callback(); var i = 0; var _this = this; args.push(copyProperties(callback, function next(err) { if(err) return callback(err); i++; if(i >= plugins.length) { return callback(); } plugins[i].apply(_this, args); })); plugins[0].apply(this, args); }; Tapable.prototype.applyPluginsAsyncSeries1 = function applyPluginsAsyncSeries1(name, param, callback) { var plugins = this._plugins[name]; if(!plugins || plugins.length === 0) return callback(); var i = 0; var _this = this; var innerCallback = copyProperties(callback, function next(err) { if(err) return callback(err); i++; if(i >= plugins.length) { return callback(); } plugins[i].call(_this, param, innerCallback); }); plugins[0].call(this, param, innerCallback); }; Tapable.prototype.applyPluginsAsyncSeriesBailResult = function applyPluginsAsyncSeriesBailResult(name) { var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); if(!this._plugins[name] || this._plugins[name].length === 0) return callback(); var plugins = this._plugins[name]; var i = 0; var _this = this; args.push(copyProperties(callback, function next() { if(arguments.length > 0) return callback.apply(null, arguments); i++; if(i >= plugins.length) { return callback(); } plugins[i].apply(_this, args); })); plugins[0].apply(this, args); }; Tapable.prototype.applyPluginsAsyncSeriesBailResult1 = function applyPluginsAsyncSeriesBailResult1(name, param, callback) { var plugins = this._plugins[name]; if(!plugins || plugins.length === 0) return callback(); var i = 0; var _this = this; var innerCallback = copyProperties(callback, function next(err, result) { if(arguments.length > 0) return callback(err, result); i++; if(i >= plugins.length) { return callback(); } plugins[i].call(_this, param, innerCallback); }); plugins[0].call(this, param, innerCallback); }; Tapable.prototype.applyPluginsAsyncWaterfall = function applyPluginsAsyncWaterfall(name, init, callback) { if(!this._plugins[name] || this._plugins[name].length === 0) return callback(null, init); var plugins = this._plugins[name]; var i = 0; var _this = this; var next = copyProperties(callback, function(err, value) { if(err) return callback(err); i++; if(i >= plugins.length) { return callback(null, value); } plugins[i].call(_this, value, next); }); plugins[0].call(this, init, next); }; Tapable.prototype.applyPluginsParallel = function applyPluginsParallel(name) { var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); if(!this._plugins[name] || this._plugins[name].length === 0) return callback(); var plugins = this._plugins[name]; var remaining = plugins.length; args.push(copyProperties(callback, function(err) { if(remaining < 0) return; // ignore if(err) { remaining = -1; return callback(err); } remaining--; if(remaining === 0) { return callback(); } })); for(var i = 0; i < plugins.length; i++) { plugins[i].apply(this, args); if(remaining < 0) return; } }; Tapable.prototype.applyPluginsParallelBailResult = function applyPluginsParallelBailResult(name) { var args = Array.prototype.slice.call(arguments, 1); var callback = args[args.length - 1]; if(!this._plugins[name] || this._plugins[name].length === 0) return callback(); var plugins = this._plugins[name]; var currentPos = plugins.length; var currentResult; var done = []; for(var i = 0; i < plugins.length; i++) { args[args.length - 1] = (function(i) { return copyProperties(callback, function() { if(i >= currentPos) return; // ignore done.push(i); if(arguments.length > 0) { currentPos = i + 1; done = fastFilter.call(done, function(item) { return item <= i; }); currentResult = Array.prototype.slice.call(arguments); } if(done.length === currentPos) { callback.apply(null, currentResult); currentPos = 0; } }); }(i)); plugins[i].apply(this, args); } }; Tapable.prototype.applyPluginsParallelBailResult1 = function applyPluginsParallelBailResult1(name, param, callback) { var plugins = this._plugins[name]; if(!plugins || plugins.length === 0) return callback(); var currentPos = plugins.length; var currentResult; var done = []; for(var i = 0; i < plugins.length; i++) { var innerCallback = (function(i) { return copyProperties(callback, function() { if(i >= currentPos) return; // ignore done.push(i); if(arguments.length > 0) { currentPos = i + 1; done = fastFilter.call(done, function(item) { return item <= i; }); currentResult = Array.prototype.slice.call(arguments); } if(done.length === currentPos) { callback.apply(null, currentResult); currentPos = 0; } }); }(i)); plugins[i].call(this, param, innerCallback); } }; Tapable.prototype.hasPlugins = function hasPlugins(name) { var plugins = this._plugins[name]; return plugins && plugins.length > 0; }; Tapable.prototype.plugin = function plugin(name, fn) { if(Array.isArray(name)) { name.forEach(function(name) { this.plugin(name, fn); }, this); return; } if(!this._plugins[name]) this._plugins[name] = [fn]; else this._plugins[name].push(fn); }; Tapable.prototype.apply = function apply() { for(var i = 0; i < arguments.length; i++) { arguments[i].apply(this); } }; tapable-0.2.8/package.json000066400000000000000000000010201314030417000154010ustar00rootroot00000000000000{ "name": "tapable", "version": "0.2.8", "author": "Tobias Koppers @sokra", "description": "Just a little module for plugins.", "license": "MIT", "repository": { "type": "git", "url": "http://github.com/webpack/tapable.git" }, "devDependencies": { "mocha": "^2.2.4", "should": "^5.2.0" }, "engines": { "node": ">=0.6" }, "files": [ "lib" ], "homepage": "https://github.com/webpack/tapable", "main": "lib/Tapable.js", "scripts": { "test": "mocha --reporter spec" } } tapable-0.2.8/test/000077500000000000000000000000001314030417000141015ustar00rootroot00000000000000tapable-0.2.8/test/applyPluginsParallelBailResultTest.js000066400000000000000000000071671314030417000234450ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var Tapable = require("../lib/Tapable"); var should = require("should"); function makeTestPlugin(arr, index) { var last; var f = function() { f.shouldNotBeCalled(); var args = Array.prototype.slice.call(arguments); args.unshift(index); last = args; arr.push(args); }; f.issue = function() { f.shouldBeCalled(); last.pop().apply(null, arguments); last = null; }; f.shouldNotBeCalled = function() { if(last) throw new Error("Plugin " + index + " was called, but shouldn't be."); }; f.shouldBeCalled = function() { if(!last) throw new Error("Plugin " + index + " was not called, but should be."); }; f.shouldBeCalledAsyncWith = function() { f.shouldBeCalled(); var args = Array.prototype.slice.call(arguments); for(var i = 0; i < args.length && i < last.length - 2; i++) { if(args[i] === null || args[i] === undefined) { should.not.exist(last[i+1]); } else { should.exist(last[i+1]); last[i+1].should.be.eql(args[i]); } } args.length.should.be.eql(last.length - 2); }; return f; } describe("applyPluginsParallelBailResult", function() { it("should call all handlers", function() { var tapable = new Tapable(); var log = []; var p1 = makeTestPlugin(log, 1); var p2 = makeTestPlugin(log, 2); var p3 = makeTestPlugin(log, 3); var p4 = makeTestPlugin(log, 4); var result = makeTestPlugin(log, 0); tapable.plugin("test", p1); tapable.plugin("test", p2); tapable.plugin("xxxx", p3); tapable.plugin("test", p4); tapable.applyPluginsParallelBailResult("test", 1, 2, result); p1.shouldBeCalledAsyncWith(1, 2); p2.shouldBeCalledAsyncWith(1, 2); p3.shouldNotBeCalled(); p4.shouldBeCalledAsyncWith(1, 2); p1.issue(); p2.issue(null, "ok"); p4.issue(null, "fail"); log.should.be.eql([ [1, 1, 2], [2, 1, 2], [4, 1, 2], [0, null, "ok"] ]); }); it("should save valid results", function() { var tapable = new Tapable(); var log = []; var p1 = makeTestPlugin(log, 1); var p2 = makeTestPlugin(log, 2); var p3 = makeTestPlugin(log, 3); tapable.plugin("test", p1); tapable.plugin("test", p2); tapable.plugin("test", p3); var result = makeTestPlugin(log, 0); tapable.applyPluginsParallelBailResult("test", "a", result); p3.issue(null, "fail"); p2.issue(null, "ok"); p1.issue(); log.should.be.eql([ [1, "a"], [2, "a"], [3, "a"], [0, null, "ok"], ]); }); it("should take the first result", function() { var tapable = new Tapable(); var log = []; var p1 = makeTestPlugin(log, 1); var p2 = makeTestPlugin(log, 2); var p3 = makeTestPlugin(log, 3); tapable.plugin("test", p1); tapable.plugin("test", p2); tapable.plugin("test", p3); var result = makeTestPlugin(log, 0); tapable.applyPluginsParallelBailResult("test", "a", result); log.length.should.be.eql(3); p1.issue(null, "ok"); log.length.should.be.eql(4); p2.issue(new Error("fail")); p3.issue(); log.should.be.eql([ [1, "a"], [2, "a"], [3, "a"], [0, null, "ok"], ]); }); it("should return errors", function() { var tapable = new Tapable(); var log = []; var p1 = makeTestPlugin(log, 1); var p2 = makeTestPlugin(log, 2); var p3 = makeTestPlugin(log, 3); tapable.plugin("test", p1); tapable.plugin("test", p2); tapable.plugin("test", p3); var result = makeTestPlugin(log, 0); tapable.applyPluginsParallelBailResult("test", "a", result); log.length.should.be.eql(3); p1.issue("ok"); log.length.should.be.eql(4); p2.issue(); p3.issue(null, "fail"); log.should.be.eql([ [1, "a"], [2, "a"], [3, "a"], [0, "ok"], ]); }); });tapable-0.2.8/test/applyPluginsWaterfall.js000066400000000000000000000054151314030417000207750ustar00rootroot00000000000000var Tapable = require("../lib/Tapable"); var should = require("should"); /** * Function designed to return a plugin handler. * With applyPluginsWaterfall, each plugin handler * has some expected arguments it will receive and an * optional return value. This function produces plugin * handler functions that perform expected arg checks and * returns some value (implicitly undefined if none specified). */ function makeTestPlugin(expectedArgs, returnVal) { return function() { var args = Array.prototype.slice.call(arguments); args.should.be.eql(expectedArgs); return returnVal; } } describe("applyPluginsWaterfall", function() { it("should call all handlers", function() { var runningSum = 0; var tapable = new Tapable(); tapable.plugin('plugin', function() { runningSum++; }); tapable.plugin('plugin', function() { runningSum++; }); tapable.plugin('plugin', function() { runningSum++; }); tapable.applyPluginsWaterfall('plugin'); runningSum.should.be.eql(3); }); it("should call first handler with init value", function() { var tapable = new Tapable(); var pluginHandler = makeTestPlugin(['initValue']); tapable.plugin('plugin', pluginHandler); tapable.applyPluginsWaterfall('plugin', 'initValue'); }); it("should call subsequent handlers with previous handler return value", function() { var tapable = new Tapable(); var pluginHandler1 = makeTestPlugin(['initValue'], 'handler1Return'); var pluginHandler2 = makeTestPlugin(['handler1Return'], 'handler2Return'); var pluginHandler3 = makeTestPlugin(['handler2Return'], 'handler3Return'); var pluginHandler4 = makeTestPlugin(['handler3Return']); tapable.plugin('plugin', pluginHandler1); tapable.plugin('plugin', pluginHandler2); tapable.plugin('plugin', pluginHandler3); tapable.plugin('plugin', pluginHandler4); tapable.applyPluginsWaterfall('plugin', 'initValue'); }); it("should call subsequent handlers with original arguments", function() { var tapable = new Tapable(); var allArgs = ['plugin', 'initValue', 'sharedArg1', 'sharedArg2', 'sharedArg3']; var sharedArgs = allArgs.slice(2); // arguments that each plugin handler will get var pluginHandler1 = makeTestPlugin(allArgs.slice(1), 'handler1Return'); var pluginHandler2 = makeTestPlugin(['handler1Return'].concat(sharedArgs), 'handler2Return'); var pluginHandler3 = makeTestPlugin(['handler2Return'].concat(sharedArgs), 'handler3Return'); var pluginHandler4 = makeTestPlugin(['handler3Return'].concat(sharedArgs)); tapable.plugin('plugin', pluginHandler1); tapable.plugin('plugin', pluginHandler2); tapable.plugin('plugin', pluginHandler3); tapable.plugin('plugin', pluginHandler4); // Calling apply to simulate ...spreadOperator tapable.applyPluginsWaterfall.apply(tapable, allArgs); }); });