Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Tapable.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const util = require("util");
  7. const SyncBailHook = require("./SyncBailHook");
  8. function Tapable() {
  9. this._pluginCompat = new SyncBailHook(["options"]);
  10. this._pluginCompat.tap(
  11. {
  12. name: "Tapable camelCase",
  13. stage: 100
  14. },
  15. options => {
  16. options.names.add(
  17. options.name.replace(/[- ]([a-z])/g, (str, ch) => ch.toUpperCase())
  18. );
  19. }
  20. );
  21. this._pluginCompat.tap(
  22. {
  23. name: "Tapable this.hooks",
  24. stage: 200
  25. },
  26. options => {
  27. let hook;
  28. for (const name of options.names) {
  29. hook = this.hooks[name];
  30. if (hook !== undefined) {
  31. break;
  32. }
  33. }
  34. if (hook !== undefined) {
  35. const tapOpt = {
  36. name: options.fn.name || "unnamed compat plugin",
  37. stage: options.stage || 0
  38. };
  39. if (options.async) hook.tapAsync(tapOpt, options.fn);
  40. else hook.tap(tapOpt, options.fn);
  41. return true;
  42. }
  43. }
  44. );
  45. }
  46. module.exports = Tapable;
  47. Tapable.addCompatLayer = function addCompatLayer(instance) {
  48. Tapable.call(instance);
  49. instance.plugin = Tapable.prototype.plugin;
  50. instance.apply = Tapable.prototype.apply;
  51. };
  52. Tapable.prototype.plugin = util.deprecate(function plugin(name, fn) {
  53. if (Array.isArray(name)) {
  54. name.forEach(function(name) {
  55. this.plugin(name, fn);
  56. }, this);
  57. return;
  58. }
  59. const result = this._pluginCompat.call({
  60. name: name,
  61. fn: fn,
  62. names: new Set([name])
  63. });
  64. if (!result) {
  65. throw new Error(
  66. `Plugin could not be registered at '${name}'. Hook was not found.\n` +
  67. "BREAKING CHANGE: There need to exist a hook at 'this.hooks'. " +
  68. "To create a compatibility layer for this hook, hook into 'this._pluginCompat'."
  69. );
  70. }
  71. }, "Tapable.plugin is deprecated. Use new API on `.hooks` instead");
  72. Tapable.prototype.apply = util.deprecate(function apply() {
  73. for (var i = 0; i < arguments.length; i++) {
  74. arguments[i].apply(this);
  75. }
  76. }, "Tapable.apply is deprecated. Call apply on the plugin directly instead");