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