@dxyl/utils 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1283 @@
1
+
2
+ /*
3
+ MIT License http://www.opensource.org/licenses/mit-license.php
4
+ Author Tobias Koppers @sokra
5
+ */
6
+
7
+ var deprecate = (fn, msg) => {
8
+ let once = true;
9
+ return function() {
10
+ if (once) {
11
+ console.warn("DeprecationWarning: " + msg);
12
+ once = false;
13
+ }
14
+ return fn.apply(this, arguments);
15
+ };
16
+ };
17
+
18
+ var utilBrowser = {
19
+ deprecate: deprecate
20
+ };
21
+
22
+ /*
23
+ MIT License http://www.opensource.org/licenses/mit-license.php
24
+ Author Tobias Koppers @sokra
25
+ */
26
+
27
+
28
+
29
+ const deprecateContext = utilBrowser.deprecate(() => {},
30
+ "Hook.context is deprecated and will be removed");
31
+
32
+ const CALL_DELEGATE = function(...args) {
33
+ this.call = this._createCall("sync");
34
+ return this.call(...args);
35
+ };
36
+ const CALL_ASYNC_DELEGATE = function(...args) {
37
+ this.callAsync = this._createCall("async");
38
+ return this.callAsync(...args);
39
+ };
40
+ const PROMISE_DELEGATE = function(...args) {
41
+ this.promise = this._createCall("promise");
42
+ return this.promise(...args);
43
+ };
44
+
45
+ class Hook {
46
+ constructor(args = [], name = undefined) {
47
+ this._args = args;
48
+ this.name = name;
49
+ this.taps = [];
50
+ this.interceptors = [];
51
+ this._call = CALL_DELEGATE;
52
+ this.call = CALL_DELEGATE;
53
+ this._callAsync = CALL_ASYNC_DELEGATE;
54
+ this.callAsync = CALL_ASYNC_DELEGATE;
55
+ this._promise = PROMISE_DELEGATE;
56
+ this.promise = PROMISE_DELEGATE;
57
+ this._x = undefined;
58
+
59
+ this.compile = this.compile;
60
+ this.tap = this.tap;
61
+ this.tapAsync = this.tapAsync;
62
+ this.tapPromise = this.tapPromise;
63
+ }
64
+
65
+ compile(options) {
66
+ throw new Error("Abstract: should be overridden");
67
+ }
68
+
69
+ _createCall(type) {
70
+ return this.compile({
71
+ taps: this.taps,
72
+ interceptors: this.interceptors,
73
+ args: this._args,
74
+ type: type
75
+ });
76
+ }
77
+
78
+ _tap(type, options, fn) {
79
+ if (typeof options === "string") {
80
+ options = {
81
+ name: options.trim()
82
+ };
83
+ } else if (typeof options !== "object" || options === null) {
84
+ throw new Error("Invalid tap options");
85
+ }
86
+ if (typeof options.name !== "string" || options.name === "") {
87
+ throw new Error("Missing name for tap");
88
+ }
89
+ if (typeof options.context !== "undefined") {
90
+ deprecateContext();
91
+ }
92
+ options = Object.assign({ type, fn }, options);
93
+ options = this._runRegisterInterceptors(options);
94
+ this._insert(options);
95
+ }
96
+
97
+ tap(options, fn) {
98
+ this._tap("sync", options, fn);
99
+ }
100
+
101
+ tapAsync(options, fn) {
102
+ this._tap("async", options, fn);
103
+ }
104
+
105
+ tapPromise(options, fn) {
106
+ this._tap("promise", options, fn);
107
+ }
108
+
109
+ _runRegisterInterceptors(options) {
110
+ for (const interceptor of this.interceptors) {
111
+ if (interceptor.register) {
112
+ const newOptions = interceptor.register(options);
113
+ if (newOptions !== undefined) {
114
+ options = newOptions;
115
+ }
116
+ }
117
+ }
118
+ return options;
119
+ }
120
+
121
+ withOptions(options) {
122
+ const mergeOptions = opt =>
123
+ Object.assign({}, options, typeof opt === "string" ? { name: opt } : opt);
124
+
125
+ return {
126
+ name: this.name,
127
+ tap: (opt, fn) => this.tap(mergeOptions(opt), fn),
128
+ tapAsync: (opt, fn) => this.tapAsync(mergeOptions(opt), fn),
129
+ tapPromise: (opt, fn) => this.tapPromise(mergeOptions(opt), fn),
130
+ intercept: interceptor => this.intercept(interceptor),
131
+ isUsed: () => this.isUsed(),
132
+ withOptions: opt => this.withOptions(mergeOptions(opt))
133
+ };
134
+ }
135
+
136
+ isUsed() {
137
+ return this.taps.length > 0 || this.interceptors.length > 0;
138
+ }
139
+
140
+ intercept(interceptor) {
141
+ this._resetCompilation();
142
+ this.interceptors.push(Object.assign({}, interceptor));
143
+ if (interceptor.register) {
144
+ for (let i = 0; i < this.taps.length; i++) {
145
+ this.taps[i] = interceptor.register(this.taps[i]);
146
+ }
147
+ }
148
+ }
149
+
150
+ _resetCompilation() {
151
+ this.call = this._call;
152
+ this.callAsync = this._callAsync;
153
+ this.promise = this._promise;
154
+ }
155
+
156
+ _insert(item) {
157
+ this._resetCompilation();
158
+ let before;
159
+ if (typeof item.before === "string") {
160
+ before = new Set([item.before]);
161
+ } else if (Array.isArray(item.before)) {
162
+ before = new Set(item.before);
163
+ }
164
+ let stage = 0;
165
+ if (typeof item.stage === "number") {
166
+ stage = item.stage;
167
+ }
168
+ let i = this.taps.length;
169
+ while (i > 0) {
170
+ i--;
171
+ const x = this.taps[i];
172
+ this.taps[i + 1] = x;
173
+ const xStage = x.stage || 0;
174
+ if (before) {
175
+ if (before.has(x.name)) {
176
+ before.delete(x.name);
177
+ continue;
178
+ }
179
+ if (before.size > 0) {
180
+ continue;
181
+ }
182
+ }
183
+ if (xStage > stage) {
184
+ continue;
185
+ }
186
+ i++;
187
+ break;
188
+ }
189
+ this.taps[i] = item;
190
+ }
191
+ }
192
+
193
+ Object.setPrototypeOf(Hook.prototype, null);
194
+
195
+ var Hook_1 = Hook;
196
+
197
+ /*
198
+ MIT License http://www.opensource.org/licenses/mit-license.php
199
+ Author Tobias Koppers @sokra
200
+ */
201
+
202
+ class HookCodeFactory {
203
+ constructor(config) {
204
+ this.config = config;
205
+ this.options = undefined;
206
+ this._args = undefined;
207
+ }
208
+
209
+ create(options) {
210
+ this.init(options);
211
+ let fn;
212
+ switch (this.options.type) {
213
+ case "sync":
214
+ fn = new Function(
215
+ this.args(),
216
+ '"use strict";\n' +
217
+ this.header() +
218
+ this.contentWithInterceptors({
219
+ onError: err => `throw ${err};\n`,
220
+ onResult: result => `return ${result};\n`,
221
+ resultReturns: true,
222
+ onDone: () => "",
223
+ rethrowIfPossible: true
224
+ })
225
+ );
226
+ break;
227
+ case "async":
228
+ fn = new Function(
229
+ this.args({
230
+ after: "_callback"
231
+ }),
232
+ '"use strict";\n' +
233
+ this.header() +
234
+ this.contentWithInterceptors({
235
+ onError: err => `_callback(${err});\n`,
236
+ onResult: result => `_callback(null, ${result});\n`,
237
+ onDone: () => "_callback();\n"
238
+ })
239
+ );
240
+ break;
241
+ case "promise":
242
+ let errorHelperUsed = false;
243
+ const content = this.contentWithInterceptors({
244
+ onError: err => {
245
+ errorHelperUsed = true;
246
+ return `_error(${err});\n`;
247
+ },
248
+ onResult: result => `_resolve(${result});\n`,
249
+ onDone: () => "_resolve();\n"
250
+ });
251
+ let code = "";
252
+ code += '"use strict";\n';
253
+ code += this.header();
254
+ code += "return new Promise((function(_resolve, _reject) {\n";
255
+ if (errorHelperUsed) {
256
+ code += "var _sync = true;\n";
257
+ code += "function _error(_err) {\n";
258
+ code += "if(_sync)\n";
259
+ code +=
260
+ "_resolve(Promise.resolve().then((function() { throw _err; })));\n";
261
+ code += "else\n";
262
+ code += "_reject(_err);\n";
263
+ code += "};\n";
264
+ }
265
+ code += content;
266
+ if (errorHelperUsed) {
267
+ code += "_sync = false;\n";
268
+ }
269
+ code += "}));\n";
270
+ fn = new Function(this.args(), code);
271
+ break;
272
+ }
273
+ this.deinit();
274
+ return fn;
275
+ }
276
+
277
+ setup(instance, options) {
278
+ instance._x = options.taps.map(t => t.fn);
279
+ }
280
+
281
+ /**
282
+ * @param {{ type: "sync" | "promise" | "async", taps: Array<Tap>, interceptors: Array<Interceptor> }} options
283
+ */
284
+ init(options) {
285
+ this.options = options;
286
+ this._args = options.args.slice();
287
+ }
288
+
289
+ deinit() {
290
+ this.options = undefined;
291
+ this._args = undefined;
292
+ }
293
+
294
+ contentWithInterceptors(options) {
295
+ if (this.options.interceptors.length > 0) {
296
+ const onError = options.onError;
297
+ const onResult = options.onResult;
298
+ const onDone = options.onDone;
299
+ let code = "";
300
+ for (let i = 0; i < this.options.interceptors.length; i++) {
301
+ const interceptor = this.options.interceptors[i];
302
+ if (interceptor.call) {
303
+ code += `${this.getInterceptor(i)}.call(${this.args({
304
+ before: interceptor.context ? "_context" : undefined
305
+ })});\n`;
306
+ }
307
+ }
308
+ code += this.content(
309
+ Object.assign(options, {
310
+ onError:
311
+ onError &&
312
+ (err => {
313
+ let code = "";
314
+ for (let i = 0; i < this.options.interceptors.length; i++) {
315
+ const interceptor = this.options.interceptors[i];
316
+ if (interceptor.error) {
317
+ code += `${this.getInterceptor(i)}.error(${err});\n`;
318
+ }
319
+ }
320
+ code += onError(err);
321
+ return code;
322
+ }),
323
+ onResult:
324
+ onResult &&
325
+ (result => {
326
+ let code = "";
327
+ for (let i = 0; i < this.options.interceptors.length; i++) {
328
+ const interceptor = this.options.interceptors[i];
329
+ if (interceptor.result) {
330
+ code += `${this.getInterceptor(i)}.result(${result});\n`;
331
+ }
332
+ }
333
+ code += onResult(result);
334
+ return code;
335
+ }),
336
+ onDone:
337
+ onDone &&
338
+ (() => {
339
+ let code = "";
340
+ for (let i = 0; i < this.options.interceptors.length; i++) {
341
+ const interceptor = this.options.interceptors[i];
342
+ if (interceptor.done) {
343
+ code += `${this.getInterceptor(i)}.done();\n`;
344
+ }
345
+ }
346
+ code += onDone();
347
+ return code;
348
+ })
349
+ })
350
+ );
351
+ return code;
352
+ } else {
353
+ return this.content(options);
354
+ }
355
+ }
356
+
357
+ header() {
358
+ let code = "";
359
+ if (this.needContext()) {
360
+ code += "var _context = {};\n";
361
+ } else {
362
+ code += "var _context;\n";
363
+ }
364
+ code += "var _x = this._x;\n";
365
+ if (this.options.interceptors.length > 0) {
366
+ code += "var _taps = this.taps;\n";
367
+ code += "var _interceptors = this.interceptors;\n";
368
+ }
369
+ return code;
370
+ }
371
+
372
+ needContext() {
373
+ for (const tap of this.options.taps) if (tap.context) return true;
374
+ return false;
375
+ }
376
+
377
+ callTap(tapIndex, { onError, onResult, onDone, rethrowIfPossible }) {
378
+ let code = "";
379
+ let hasTapCached = false;
380
+ for (let i = 0; i < this.options.interceptors.length; i++) {
381
+ const interceptor = this.options.interceptors[i];
382
+ if (interceptor.tap) {
383
+ if (!hasTapCached) {
384
+ code += `var _tap${tapIndex} = ${this.getTap(tapIndex)};\n`;
385
+ hasTapCached = true;
386
+ }
387
+ code += `${this.getInterceptor(i)}.tap(${
388
+ interceptor.context ? "_context, " : ""
389
+ }_tap${tapIndex});\n`;
390
+ }
391
+ }
392
+ code += `var _fn${tapIndex} = ${this.getTapFn(tapIndex)};\n`;
393
+ const tap = this.options.taps[tapIndex];
394
+ switch (tap.type) {
395
+ case "sync":
396
+ if (!rethrowIfPossible) {
397
+ code += `var _hasError${tapIndex} = false;\n`;
398
+ code += "try {\n";
399
+ }
400
+ if (onResult) {
401
+ code += `var _result${tapIndex} = _fn${tapIndex}(${this.args({
402
+ before: tap.context ? "_context" : undefined
403
+ })});\n`;
404
+ } else {
405
+ code += `_fn${tapIndex}(${this.args({
406
+ before: tap.context ? "_context" : undefined
407
+ })});\n`;
408
+ }
409
+ if (!rethrowIfPossible) {
410
+ code += "} catch(_err) {\n";
411
+ code += `_hasError${tapIndex} = true;\n`;
412
+ code += onError("_err");
413
+ code += "}\n";
414
+ code += `if(!_hasError${tapIndex}) {\n`;
415
+ }
416
+ if (onResult) {
417
+ code += onResult(`_result${tapIndex}`);
418
+ }
419
+ if (onDone) {
420
+ code += onDone();
421
+ }
422
+ if (!rethrowIfPossible) {
423
+ code += "}\n";
424
+ }
425
+ break;
426
+ case "async":
427
+ let cbCode = "";
428
+ if (onResult)
429
+ cbCode += `(function(_err${tapIndex}, _result${tapIndex}) {\n`;
430
+ else cbCode += `(function(_err${tapIndex}) {\n`;
431
+ cbCode += `if(_err${tapIndex}) {\n`;
432
+ cbCode += onError(`_err${tapIndex}`);
433
+ cbCode += "} else {\n";
434
+ if (onResult) {
435
+ cbCode += onResult(`_result${tapIndex}`);
436
+ }
437
+ if (onDone) {
438
+ cbCode += onDone();
439
+ }
440
+ cbCode += "}\n";
441
+ cbCode += "})";
442
+ code += `_fn${tapIndex}(${this.args({
443
+ before: tap.context ? "_context" : undefined,
444
+ after: cbCode
445
+ })});\n`;
446
+ break;
447
+ case "promise":
448
+ code += `var _hasResult${tapIndex} = false;\n`;
449
+ code += `var _promise${tapIndex} = _fn${tapIndex}(${this.args({
450
+ before: tap.context ? "_context" : undefined
451
+ })});\n`;
452
+ code += `if (!_promise${tapIndex} || !_promise${tapIndex}.then)\n`;
453
+ code += ` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${tapIndex} + ')');\n`;
454
+ code += `_promise${tapIndex}.then((function(_result${tapIndex}) {\n`;
455
+ code += `_hasResult${tapIndex} = true;\n`;
456
+ if (onResult) {
457
+ code += onResult(`_result${tapIndex}`);
458
+ }
459
+ if (onDone) {
460
+ code += onDone();
461
+ }
462
+ code += `}), function(_err${tapIndex}) {\n`;
463
+ code += `if(_hasResult${tapIndex}) throw _err${tapIndex};\n`;
464
+ code += onError(`_err${tapIndex}`);
465
+ code += "});\n";
466
+ break;
467
+ }
468
+ return code;
469
+ }
470
+
471
+ callTapsSeries({
472
+ onError,
473
+ onResult,
474
+ resultReturns,
475
+ onDone,
476
+ doneReturns,
477
+ rethrowIfPossible
478
+ }) {
479
+ if (this.options.taps.length === 0) return onDone();
480
+ const firstAsync = this.options.taps.findIndex(t => t.type !== "sync");
481
+ const somethingReturns = resultReturns || doneReturns;
482
+ let code = "";
483
+ let current = onDone;
484
+ let unrollCounter = 0;
485
+ for (let j = this.options.taps.length - 1; j >= 0; j--) {
486
+ const i = j;
487
+ const unroll =
488
+ current !== onDone &&
489
+ (this.options.taps[i].type !== "sync" || unrollCounter++ > 20);
490
+ if (unroll) {
491
+ unrollCounter = 0;
492
+ code += `function _next${i}() {\n`;
493
+ code += current();
494
+ code += `}\n`;
495
+ current = () => `${somethingReturns ? "return " : ""}_next${i}();\n`;
496
+ }
497
+ const done = current;
498
+ const doneBreak = skipDone => {
499
+ if (skipDone) return "";
500
+ return onDone();
501
+ };
502
+ const content = this.callTap(i, {
503
+ onError: error => onError(i, error, done, doneBreak),
504
+ onResult:
505
+ onResult &&
506
+ (result => {
507
+ return onResult(i, result, done, doneBreak);
508
+ }),
509
+ onDone: !onResult && done,
510
+ rethrowIfPossible:
511
+ rethrowIfPossible && (firstAsync < 0 || i < firstAsync)
512
+ });
513
+ current = () => content;
514
+ }
515
+ code += current();
516
+ return code;
517
+ }
518
+
519
+ callTapsLooping({ onError, onDone, rethrowIfPossible }) {
520
+ if (this.options.taps.length === 0) return onDone();
521
+ const syncOnly = this.options.taps.every(t => t.type === "sync");
522
+ let code = "";
523
+ if (!syncOnly) {
524
+ code += "var _looper = (function() {\n";
525
+ code += "var _loopAsync = false;\n";
526
+ }
527
+ code += "var _loop;\n";
528
+ code += "do {\n";
529
+ code += "_loop = false;\n";
530
+ for (let i = 0; i < this.options.interceptors.length; i++) {
531
+ const interceptor = this.options.interceptors[i];
532
+ if (interceptor.loop) {
533
+ code += `${this.getInterceptor(i)}.loop(${this.args({
534
+ before: interceptor.context ? "_context" : undefined
535
+ })});\n`;
536
+ }
537
+ }
538
+ code += this.callTapsSeries({
539
+ onError,
540
+ onResult: (i, result, next, doneBreak) => {
541
+ let code = "";
542
+ code += `if(${result} !== undefined) {\n`;
543
+ code += "_loop = true;\n";
544
+ if (!syncOnly) code += "if(_loopAsync) _looper();\n";
545
+ code += doneBreak(true);
546
+ code += `} else {\n`;
547
+ code += next();
548
+ code += `}\n`;
549
+ return code;
550
+ },
551
+ onDone:
552
+ onDone &&
553
+ (() => {
554
+ let code = "";
555
+ code += "if(!_loop) {\n";
556
+ code += onDone();
557
+ code += "}\n";
558
+ return code;
559
+ }),
560
+ rethrowIfPossible: rethrowIfPossible && syncOnly
561
+ });
562
+ code += "} while(_loop);\n";
563
+ if (!syncOnly) {
564
+ code += "_loopAsync = true;\n";
565
+ code += "});\n";
566
+ code += "_looper();\n";
567
+ }
568
+ return code;
569
+ }
570
+
571
+ callTapsParallel({
572
+ onError,
573
+ onResult,
574
+ onDone,
575
+ rethrowIfPossible,
576
+ onTap = (i, run) => run()
577
+ }) {
578
+ if (this.options.taps.length <= 1) {
579
+ return this.callTapsSeries({
580
+ onError,
581
+ onResult,
582
+ onDone,
583
+ rethrowIfPossible
584
+ });
585
+ }
586
+ let code = "";
587
+ code += "do {\n";
588
+ code += `var _counter = ${this.options.taps.length};\n`;
589
+ if (onDone) {
590
+ code += "var _done = (function() {\n";
591
+ code += onDone();
592
+ code += "});\n";
593
+ }
594
+ for (let i = 0; i < this.options.taps.length; i++) {
595
+ const done = () => {
596
+ if (onDone) return "if(--_counter === 0) _done();\n";
597
+ else return "--_counter;";
598
+ };
599
+ const doneBreak = skipDone => {
600
+ if (skipDone || !onDone) return "_counter = 0;\n";
601
+ else return "_counter = 0;\n_done();\n";
602
+ };
603
+ code += "if(_counter <= 0) break;\n";
604
+ code += onTap(
605
+ i,
606
+ () =>
607
+ this.callTap(i, {
608
+ onError: error => {
609
+ let code = "";
610
+ code += "if(_counter > 0) {\n";
611
+ code += onError(i, error, done, doneBreak);
612
+ code += "}\n";
613
+ return code;
614
+ },
615
+ onResult:
616
+ onResult &&
617
+ (result => {
618
+ let code = "";
619
+ code += "if(_counter > 0) {\n";
620
+ code += onResult(i, result, done, doneBreak);
621
+ code += "}\n";
622
+ return code;
623
+ }),
624
+ onDone:
625
+ !onResult &&
626
+ (() => {
627
+ return done();
628
+ }),
629
+ rethrowIfPossible
630
+ }),
631
+ done,
632
+ doneBreak
633
+ );
634
+ }
635
+ code += "} while(false);\n";
636
+ return code;
637
+ }
638
+
639
+ args({ before, after } = {}) {
640
+ let allArgs = this._args;
641
+ if (before) allArgs = [before].concat(allArgs);
642
+ if (after) allArgs = allArgs.concat(after);
643
+ if (allArgs.length === 0) {
644
+ return "";
645
+ } else {
646
+ return allArgs.join(", ");
647
+ }
648
+ }
649
+
650
+ getTapFn(idx) {
651
+ return `_x[${idx}]`;
652
+ }
653
+
654
+ getTap(idx) {
655
+ return `_taps[${idx}]`;
656
+ }
657
+
658
+ getInterceptor(idx) {
659
+ return `_interceptors[${idx}]`;
660
+ }
661
+ }
662
+
663
+ var HookCodeFactory_1 = HookCodeFactory;
664
+
665
+ /*
666
+ MIT License http://www.opensource.org/licenses/mit-license.php
667
+ Author Tobias Koppers @sokra
668
+ */
669
+
670
+
671
+
672
+
673
+ class SyncHookCodeFactory extends HookCodeFactory_1 {
674
+ content({ onError, onDone, rethrowIfPossible }) {
675
+ return this.callTapsSeries({
676
+ onError: (i, err) => onError(err),
677
+ onDone,
678
+ rethrowIfPossible
679
+ });
680
+ }
681
+ }
682
+
683
+ const factory$9 = new SyncHookCodeFactory();
684
+
685
+ const TAP_ASYNC$3 = () => {
686
+ throw new Error("tapAsync is not supported on a SyncHook");
687
+ };
688
+
689
+ const TAP_PROMISE$3 = () => {
690
+ throw new Error("tapPromise is not supported on a SyncHook");
691
+ };
692
+
693
+ const COMPILE$9 = function(options) {
694
+ factory$9.setup(this, options);
695
+ return factory$9.create(options);
696
+ };
697
+
698
+ function SyncHook$1(args = [], name = undefined) {
699
+ const hook = new Hook_1(args, name);
700
+ hook.constructor = SyncHook$1;
701
+ hook.tapAsync = TAP_ASYNC$3;
702
+ hook.tapPromise = TAP_PROMISE$3;
703
+ hook.compile = COMPILE$9;
704
+ return hook;
705
+ }
706
+
707
+ SyncHook$1.prototype = null;
708
+
709
+ var SyncHook_1 = SyncHook$1;
710
+
711
+ /*
712
+ MIT License http://www.opensource.org/licenses/mit-license.php
713
+ Author Tobias Koppers @sokra
714
+ */
715
+
716
+
717
+
718
+
719
+ class SyncBailHookCodeFactory extends HookCodeFactory_1 {
720
+ content({ onError, onResult, resultReturns, onDone, rethrowIfPossible }) {
721
+ return this.callTapsSeries({
722
+ onError: (i, err) => onError(err),
723
+ onResult: (i, result, next) =>
724
+ `if(${result} !== undefined) {\n${onResult(
725
+ result
726
+ )};\n} else {\n${next()}}\n`,
727
+ resultReturns,
728
+ onDone,
729
+ rethrowIfPossible
730
+ });
731
+ }
732
+ }
733
+
734
+ const factory$8 = new SyncBailHookCodeFactory();
735
+
736
+ const TAP_ASYNC$2 = () => {
737
+ throw new Error("tapAsync is not supported on a SyncBailHook");
738
+ };
739
+
740
+ const TAP_PROMISE$2 = () => {
741
+ throw new Error("tapPromise is not supported on a SyncBailHook");
742
+ };
743
+
744
+ const COMPILE$8 = function(options) {
745
+ factory$8.setup(this, options);
746
+ return factory$8.create(options);
747
+ };
748
+
749
+ function SyncBailHook$1(args = [], name = undefined) {
750
+ const hook = new Hook_1(args, name);
751
+ hook.constructor = SyncBailHook$1;
752
+ hook.tapAsync = TAP_ASYNC$2;
753
+ hook.tapPromise = TAP_PROMISE$2;
754
+ hook.compile = COMPILE$8;
755
+ return hook;
756
+ }
757
+
758
+ SyncBailHook$1.prototype = null;
759
+
760
+ var SyncBailHook_1 = SyncBailHook$1;
761
+
762
+ /*
763
+ MIT License http://www.opensource.org/licenses/mit-license.php
764
+ Author Tobias Koppers @sokra
765
+ */
766
+
767
+
768
+
769
+
770
+ class SyncWaterfallHookCodeFactory extends HookCodeFactory_1 {
771
+ content({ onError, onResult, resultReturns, rethrowIfPossible }) {
772
+ return this.callTapsSeries({
773
+ onError: (i, err) => onError(err),
774
+ onResult: (i, result, next) => {
775
+ let code = "";
776
+ code += `if(${result} !== undefined) {\n`;
777
+ code += `${this._args[0]} = ${result};\n`;
778
+ code += `}\n`;
779
+ code += next();
780
+ return code;
781
+ },
782
+ onDone: () => onResult(this._args[0]),
783
+ doneReturns: resultReturns,
784
+ rethrowIfPossible
785
+ });
786
+ }
787
+ }
788
+
789
+ const factory$7 = new SyncWaterfallHookCodeFactory();
790
+
791
+ const TAP_ASYNC$1 = () => {
792
+ throw new Error("tapAsync is not supported on a SyncWaterfallHook");
793
+ };
794
+
795
+ const TAP_PROMISE$1 = () => {
796
+ throw new Error("tapPromise is not supported on a SyncWaterfallHook");
797
+ };
798
+
799
+ const COMPILE$7 = function(options) {
800
+ factory$7.setup(this, options);
801
+ return factory$7.create(options);
802
+ };
803
+
804
+ function SyncWaterfallHook$1(args = [], name = undefined) {
805
+ if (args.length < 1)
806
+ throw new Error("Waterfall hooks must have at least one argument");
807
+ const hook = new Hook_1(args, name);
808
+ hook.constructor = SyncWaterfallHook$1;
809
+ hook.tapAsync = TAP_ASYNC$1;
810
+ hook.tapPromise = TAP_PROMISE$1;
811
+ hook.compile = COMPILE$7;
812
+ return hook;
813
+ }
814
+
815
+ SyncWaterfallHook$1.prototype = null;
816
+
817
+ var SyncWaterfallHook_1 = SyncWaterfallHook$1;
818
+
819
+ /*
820
+ MIT License http://www.opensource.org/licenses/mit-license.php
821
+ Author Tobias Koppers @sokra
822
+ */
823
+
824
+
825
+
826
+
827
+ class SyncLoopHookCodeFactory extends HookCodeFactory_1 {
828
+ content({ onError, onDone, rethrowIfPossible }) {
829
+ return this.callTapsLooping({
830
+ onError: (i, err) => onError(err),
831
+ onDone,
832
+ rethrowIfPossible
833
+ });
834
+ }
835
+ }
836
+
837
+ const factory$6 = new SyncLoopHookCodeFactory();
838
+
839
+ const TAP_ASYNC = () => {
840
+ throw new Error("tapAsync is not supported on a SyncLoopHook");
841
+ };
842
+
843
+ const TAP_PROMISE = () => {
844
+ throw new Error("tapPromise is not supported on a SyncLoopHook");
845
+ };
846
+
847
+ const COMPILE$6 = function(options) {
848
+ factory$6.setup(this, options);
849
+ return factory$6.create(options);
850
+ };
851
+
852
+ function SyncLoopHook$1(args = [], name = undefined) {
853
+ const hook = new Hook_1(args, name);
854
+ hook.constructor = SyncLoopHook$1;
855
+ hook.tapAsync = TAP_ASYNC;
856
+ hook.tapPromise = TAP_PROMISE;
857
+ hook.compile = COMPILE$6;
858
+ return hook;
859
+ }
860
+
861
+ SyncLoopHook$1.prototype = null;
862
+
863
+ var SyncLoopHook_1 = SyncLoopHook$1;
864
+
865
+ /*
866
+ MIT License http://www.opensource.org/licenses/mit-license.php
867
+ Author Tobias Koppers @sokra
868
+ */
869
+
870
+
871
+
872
+
873
+ class AsyncParallelHookCodeFactory extends HookCodeFactory_1 {
874
+ content({ onError, onDone }) {
875
+ return this.callTapsParallel({
876
+ onError: (i, err, done, doneBreak) => onError(err) + doneBreak(true),
877
+ onDone
878
+ });
879
+ }
880
+ }
881
+
882
+ const factory$5 = new AsyncParallelHookCodeFactory();
883
+
884
+ const COMPILE$5 = function(options) {
885
+ factory$5.setup(this, options);
886
+ return factory$5.create(options);
887
+ };
888
+
889
+ function AsyncParallelHook$1(args = [], name = undefined) {
890
+ const hook = new Hook_1(args, name);
891
+ hook.constructor = AsyncParallelHook$1;
892
+ hook.compile = COMPILE$5;
893
+ hook._call = undefined;
894
+ hook.call = undefined;
895
+ return hook;
896
+ }
897
+
898
+ AsyncParallelHook$1.prototype = null;
899
+
900
+ var AsyncParallelHook_1 = AsyncParallelHook$1;
901
+
902
+ /*
903
+ MIT License http://www.opensource.org/licenses/mit-license.php
904
+ Author Tobias Koppers @sokra
905
+ */
906
+
907
+
908
+
909
+
910
+ class AsyncParallelBailHookCodeFactory extends HookCodeFactory_1 {
911
+ content({ onError, onResult, onDone }) {
912
+ let code = "";
913
+ code += `var _results = new Array(${this.options.taps.length});\n`;
914
+ code += "var _checkDone = function() {\n";
915
+ code += "for(var i = 0; i < _results.length; i++) {\n";
916
+ code += "var item = _results[i];\n";
917
+ code += "if(item === undefined) return false;\n";
918
+ code += "if(item.result !== undefined) {\n";
919
+ code += onResult("item.result");
920
+ code += "return true;\n";
921
+ code += "}\n";
922
+ code += "if(item.error) {\n";
923
+ code += onError("item.error");
924
+ code += "return true;\n";
925
+ code += "}\n";
926
+ code += "}\n";
927
+ code += "return false;\n";
928
+ code += "}\n";
929
+ code += this.callTapsParallel({
930
+ onError: (i, err, done, doneBreak) => {
931
+ let code = "";
932
+ code += `if(${i} < _results.length && ((_results.length = ${i +
933
+ 1}), (_results[${i}] = { error: ${err} }), _checkDone())) {\n`;
934
+ code += doneBreak(true);
935
+ code += "} else {\n";
936
+ code += done();
937
+ code += "}\n";
938
+ return code;
939
+ },
940
+ onResult: (i, result, done, doneBreak) => {
941
+ let code = "";
942
+ code += `if(${i} < _results.length && (${result} !== undefined && (_results.length = ${i +
943
+ 1}), (_results[${i}] = { result: ${result} }), _checkDone())) {\n`;
944
+ code += doneBreak(true);
945
+ code += "} else {\n";
946
+ code += done();
947
+ code += "}\n";
948
+ return code;
949
+ },
950
+ onTap: (i, run, done, doneBreak) => {
951
+ let code = "";
952
+ if (i > 0) {
953
+ code += `if(${i} >= _results.length) {\n`;
954
+ code += done();
955
+ code += "} else {\n";
956
+ }
957
+ code += run();
958
+ if (i > 0) code += "}\n";
959
+ return code;
960
+ },
961
+ onDone
962
+ });
963
+ return code;
964
+ }
965
+ }
966
+
967
+ const factory$4 = new AsyncParallelBailHookCodeFactory();
968
+
969
+ const COMPILE$4 = function(options) {
970
+ factory$4.setup(this, options);
971
+ return factory$4.create(options);
972
+ };
973
+
974
+ function AsyncParallelBailHook$1(args = [], name = undefined) {
975
+ const hook = new Hook_1(args, name);
976
+ hook.constructor = AsyncParallelBailHook$1;
977
+ hook.compile = COMPILE$4;
978
+ hook._call = undefined;
979
+ hook.call = undefined;
980
+ return hook;
981
+ }
982
+
983
+ AsyncParallelBailHook$1.prototype = null;
984
+
985
+ var AsyncParallelBailHook_1 = AsyncParallelBailHook$1;
986
+
987
+ /*
988
+ MIT License http://www.opensource.org/licenses/mit-license.php
989
+ Author Tobias Koppers @sokra
990
+ */
991
+
992
+
993
+
994
+
995
+ class AsyncSeriesHookCodeFactory extends HookCodeFactory_1 {
996
+ content({ onError, onDone }) {
997
+ return this.callTapsSeries({
998
+ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
999
+ onDone
1000
+ });
1001
+ }
1002
+ }
1003
+
1004
+ const factory$3 = new AsyncSeriesHookCodeFactory();
1005
+
1006
+ const COMPILE$3 = function(options) {
1007
+ factory$3.setup(this, options);
1008
+ return factory$3.create(options);
1009
+ };
1010
+
1011
+ function AsyncSeriesHook$1(args = [], name = undefined) {
1012
+ const hook = new Hook_1(args, name);
1013
+ hook.constructor = AsyncSeriesHook$1;
1014
+ hook.compile = COMPILE$3;
1015
+ hook._call = undefined;
1016
+ hook.call = undefined;
1017
+ return hook;
1018
+ }
1019
+
1020
+ AsyncSeriesHook$1.prototype = null;
1021
+
1022
+ var AsyncSeriesHook_1 = AsyncSeriesHook$1;
1023
+
1024
+ /*
1025
+ MIT License http://www.opensource.org/licenses/mit-license.php
1026
+ Author Tobias Koppers @sokra
1027
+ */
1028
+
1029
+
1030
+
1031
+
1032
+ class AsyncSeriesBailHookCodeFactory extends HookCodeFactory_1 {
1033
+ content({ onError, onResult, resultReturns, onDone }) {
1034
+ return this.callTapsSeries({
1035
+ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
1036
+ onResult: (i, result, next) =>
1037
+ `if(${result} !== undefined) {\n${onResult(
1038
+ result
1039
+ )}\n} else {\n${next()}}\n`,
1040
+ resultReturns,
1041
+ onDone
1042
+ });
1043
+ }
1044
+ }
1045
+
1046
+ const factory$2 = new AsyncSeriesBailHookCodeFactory();
1047
+
1048
+ const COMPILE$2 = function(options) {
1049
+ factory$2.setup(this, options);
1050
+ return factory$2.create(options);
1051
+ };
1052
+
1053
+ function AsyncSeriesBailHook$1(args = [], name = undefined) {
1054
+ const hook = new Hook_1(args, name);
1055
+ hook.constructor = AsyncSeriesBailHook$1;
1056
+ hook.compile = COMPILE$2;
1057
+ hook._call = undefined;
1058
+ hook.call = undefined;
1059
+ return hook;
1060
+ }
1061
+
1062
+ AsyncSeriesBailHook$1.prototype = null;
1063
+
1064
+ var AsyncSeriesBailHook_1 = AsyncSeriesBailHook$1;
1065
+
1066
+ /*
1067
+ MIT License http://www.opensource.org/licenses/mit-license.php
1068
+ Author Tobias Koppers @sokra
1069
+ */
1070
+
1071
+
1072
+
1073
+
1074
+ class AsyncSeriesLoopHookCodeFactory extends HookCodeFactory_1 {
1075
+ content({ onError, onDone }) {
1076
+ return this.callTapsLooping({
1077
+ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
1078
+ onDone
1079
+ });
1080
+ }
1081
+ }
1082
+
1083
+ const factory$1 = new AsyncSeriesLoopHookCodeFactory();
1084
+
1085
+ const COMPILE$1 = function(options) {
1086
+ factory$1.setup(this, options);
1087
+ return factory$1.create(options);
1088
+ };
1089
+
1090
+ function AsyncSeriesLoopHook$1(args = [], name = undefined) {
1091
+ const hook = new Hook_1(args, name);
1092
+ hook.constructor = AsyncSeriesLoopHook$1;
1093
+ hook.compile = COMPILE$1;
1094
+ hook._call = undefined;
1095
+ hook.call = undefined;
1096
+ return hook;
1097
+ }
1098
+
1099
+ AsyncSeriesLoopHook$1.prototype = null;
1100
+
1101
+ var AsyncSeriesLoopHook_1 = AsyncSeriesLoopHook$1;
1102
+
1103
+ /*
1104
+ MIT License http://www.opensource.org/licenses/mit-license.php
1105
+ Author Tobias Koppers @sokra
1106
+ */
1107
+
1108
+
1109
+
1110
+
1111
+ class AsyncSeriesWaterfallHookCodeFactory extends HookCodeFactory_1 {
1112
+ content({ onError, onResult, onDone }) {
1113
+ return this.callTapsSeries({
1114
+ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true),
1115
+ onResult: (i, result, next) => {
1116
+ let code = "";
1117
+ code += `if(${result} !== undefined) {\n`;
1118
+ code += `${this._args[0]} = ${result};\n`;
1119
+ code += `}\n`;
1120
+ code += next();
1121
+ return code;
1122
+ },
1123
+ onDone: () => onResult(this._args[0])
1124
+ });
1125
+ }
1126
+ }
1127
+
1128
+ const factory = new AsyncSeriesWaterfallHookCodeFactory();
1129
+
1130
+ const COMPILE = function(options) {
1131
+ factory.setup(this, options);
1132
+ return factory.create(options);
1133
+ };
1134
+
1135
+ function AsyncSeriesWaterfallHook$1(args = [], name = undefined) {
1136
+ if (args.length < 1)
1137
+ throw new Error("Waterfall hooks must have at least one argument");
1138
+ const hook = new Hook_1(args, name);
1139
+ hook.constructor = AsyncSeriesWaterfallHook$1;
1140
+ hook.compile = COMPILE;
1141
+ hook._call = undefined;
1142
+ hook.call = undefined;
1143
+ return hook;
1144
+ }
1145
+
1146
+ AsyncSeriesWaterfallHook$1.prototype = null;
1147
+
1148
+ var AsyncSeriesWaterfallHook_1 = AsyncSeriesWaterfallHook$1;
1149
+
1150
+ /*
1151
+ MIT License http://www.opensource.org/licenses/mit-license.php
1152
+ Author Tobias Koppers @sokra
1153
+ */
1154
+
1155
+
1156
+
1157
+ const defaultFactory = (key, hook) => hook;
1158
+
1159
+ class HookMap$1 {
1160
+ constructor(factory, name = undefined) {
1161
+ this._map = new Map();
1162
+ this.name = name;
1163
+ this._factory = factory;
1164
+ this._interceptors = [];
1165
+ }
1166
+
1167
+ get(key) {
1168
+ return this._map.get(key);
1169
+ }
1170
+
1171
+ for(key) {
1172
+ const hook = this.get(key);
1173
+ if (hook !== undefined) {
1174
+ return hook;
1175
+ }
1176
+ let newHook = this._factory(key);
1177
+ const interceptors = this._interceptors;
1178
+ for (let i = 0; i < interceptors.length; i++) {
1179
+ newHook = interceptors[i].factory(key, newHook);
1180
+ }
1181
+ this._map.set(key, newHook);
1182
+ return newHook;
1183
+ }
1184
+
1185
+ intercept(interceptor) {
1186
+ this._interceptors.push(
1187
+ Object.assign(
1188
+ {
1189
+ factory: defaultFactory
1190
+ },
1191
+ interceptor
1192
+ )
1193
+ );
1194
+ }
1195
+ }
1196
+
1197
+ HookMap$1.prototype.tap = utilBrowser.deprecate(function(key, options, fn) {
1198
+ return this.for(key).tap(options, fn);
1199
+ }, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead.");
1200
+
1201
+ HookMap$1.prototype.tapAsync = utilBrowser.deprecate(function(key, options, fn) {
1202
+ return this.for(key).tapAsync(options, fn);
1203
+ }, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead.");
1204
+
1205
+ HookMap$1.prototype.tapPromise = utilBrowser.deprecate(function(key, options, fn) {
1206
+ return this.for(key).tapPromise(options, fn);
1207
+ }, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead.");
1208
+
1209
+ var HookMap_1 = HookMap$1;
1210
+
1211
+ /*
1212
+ MIT License http://www.opensource.org/licenses/mit-license.php
1213
+ Author Tobias Koppers @sokra
1214
+ */
1215
+
1216
+
1217
+
1218
+ class MultiHook$1 {
1219
+ constructor(hooks, name = undefined) {
1220
+ this.hooks = hooks;
1221
+ this.name = name;
1222
+ }
1223
+
1224
+ tap(options, fn) {
1225
+ for (const hook of this.hooks) {
1226
+ hook.tap(options, fn);
1227
+ }
1228
+ }
1229
+
1230
+ tapAsync(options, fn) {
1231
+ for (const hook of this.hooks) {
1232
+ hook.tapAsync(options, fn);
1233
+ }
1234
+ }
1235
+
1236
+ tapPromise(options, fn) {
1237
+ for (const hook of this.hooks) {
1238
+ hook.tapPromise(options, fn);
1239
+ }
1240
+ }
1241
+
1242
+ isUsed() {
1243
+ for (const hook of this.hooks) {
1244
+ if (hook.isUsed()) return true;
1245
+ }
1246
+ return false;
1247
+ }
1248
+
1249
+ intercept(interceptor) {
1250
+ for (const hook of this.hooks) {
1251
+ hook.intercept(interceptor);
1252
+ }
1253
+ }
1254
+
1255
+ withOptions(options) {
1256
+ return new MultiHook$1(
1257
+ this.hooks.map(h => h.withOptions(options)),
1258
+ this.name
1259
+ );
1260
+ }
1261
+ }
1262
+
1263
+ var MultiHook_1 = MultiHook$1;
1264
+
1265
+ /*
1266
+ MIT License http://www.opensource.org/licenses/mit-license.php
1267
+ Author Tobias Koppers @sokra
1268
+ */
1269
+
1270
+
1271
+ export const SyncHook = SyncHook_1;
1272
+ export const SyncBailHook = SyncBailHook_1;
1273
+ export const SyncWaterfallHook = SyncWaterfallHook_1;
1274
+ export const SyncLoopHook = SyncLoopHook_1;
1275
+ export const AsyncParallelHook = AsyncParallelHook_1;
1276
+ export const AsyncParallelBailHook = AsyncParallelBailHook_1;
1277
+ export const AsyncSeriesHook = AsyncSeriesHook_1;
1278
+ export const AsyncSeriesBailHook = AsyncSeriesBailHook_1;
1279
+ export const AsyncSeriesLoopHook = AsyncSeriesLoopHook_1;
1280
+ export const AsyncSeriesWaterfallHook = AsyncSeriesWaterfallHook_1;
1281
+ export const HookMap = HookMap_1;
1282
+ export const MultiHook = MultiHook_1;
1283
+