Sha256: a54fc042fbead1eca1453f53bf5f8de88f7501751f789f3be4debb088d1f1f4f

Contents?: true

Size: 1.96 KB

Versions: 27

Compression:

Stored size: 1.96 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
"use strict";

const util = require("util");
const SyncBailHook = require("./SyncBailHook");

function Tapable() {
	this._pluginCompat = new SyncBailHook(["options"]);
	this._pluginCompat.tap(
		{
			name: "Tapable camelCase",
			stage: 100
		},
		options => {
			options.names.add(
				options.name.replace(/[- ]([a-z])/g, (str, ch) => ch.toUpperCase())
			);
		}
	);
	this._pluginCompat.tap(
		{
			name: "Tapable this.hooks",
			stage: 200
		},
		options => {
			let hook;
			for (const name of options.names) {
				hook = this.hooks[name];
				if (hook !== undefined) {
					break;
				}
			}
			if (hook !== undefined) {
				const tapOpt = {
					name: options.fn.name || "unnamed compat plugin",
					stage: options.stage || 0
				};
				if (options.async) hook.tapAsync(tapOpt, options.fn);
				else hook.tap(tapOpt, options.fn);
				return true;
			}
		}
	);
}
module.exports = Tapable;

Tapable.addCompatLayer = function addCompatLayer(instance) {
	Tapable.call(instance);
	instance.plugin = Tapable.prototype.plugin;
	instance.apply = Tapable.prototype.apply;
};

Tapable.prototype.plugin = util.deprecate(function plugin(name, fn) {
	if (Array.isArray(name)) {
		name.forEach(function(name) {
			this.plugin(name, fn);
		}, this);
		return;
	}
	const result = this._pluginCompat.call({
		name: name,
		fn: fn,
		names: new Set([name])
	});
	if (!result) {
		throw new Error(
			`Plugin could not be registered at '${name}'. Hook was not found.\n` +
				"BREAKING CHANGE: There need to exist a hook at 'this.hooks'. " +
				"To create a compatibility layer for this hook, hook into 'this._pluginCompat'."
		);
	}
}, "Tapable.plugin is deprecated. Use new API on `.hooks` instead");

Tapable.prototype.apply = util.deprecate(function apply() {
	for (var i = 0; i < arguments.length; i++) {
		arguments[i].apply(this);
	}
}, "Tapable.apply is deprecated. Call apply on the plugin directly instead");

Version data entries

27 entries across 26 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.18.0 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.18.2 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.16.1 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.15.2 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.18.4 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.18.1 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.14.0 test/dummy/node_modules/tapable/lib/Tapable.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/tapable/lib/Tapable.js
tang-0.2.1 spec/tang_app/node_modules/tapable/lib/Tapable.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/tapable/lib/Tapable.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/tapable/lib/Tapable.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/tapable/lib/Tapable.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/tapable/lib/Tapable.js
tang-0.2.0 spec/tang_app/node_modules/tapable/lib/Tapable.js
tang-0.1.0 spec/tang_app/node_modules/tapable/lib/Tapable.js
tang-0.0.9 spec/tang_app/node_modules/tapable/lib/Tapable.js
enju_library-0.3.8 spec/dummy/node_modules/tapable/lib/Tapable.js
jester-data-8.0.0 node_modules/tapable/lib/Tapable.js