SyncHook.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Hook = require("./Hook");
  7. const HookCodeFactory = require("./HookCodeFactory");
  8. class SyncHookCodeFactory extends HookCodeFactory {
  9. content({ onError, onDone, rethrowIfPossible }) {
  10. return this.callTapsSeries({
  11. onError: (i, err) => onError(err),
  12. onDone,
  13. rethrowIfPossible
  14. });
  15. }
  16. }
  17. const factory = new SyncHookCodeFactory();
  18. const TAP_ASYNC = () => {
  19. throw new Error("tapAsync is not supported on a SyncHook");
  20. };
  21. const TAP_PROMISE = () => {
  22. throw new Error("tapPromise is not supported on a SyncHook");
  23. };
  24. const COMPILE = function(options) {
  25. factory.setup(this, options);
  26. return factory.create(options);
  27. };
  28. function SyncHook(args = [], name = undefined) {
  29. const hook = new Hook(args, name);
  30. hook.constructor = SyncHook;
  31. hook.tapAsync = TAP_ASYNC;
  32. hook.tapPromise = TAP_PROMISE;
  33. hook.compile = COMPILE;
  34. return hook;
  35. }
  36. SyncHook.prototype = null;
  37. module.exports = SyncHook;