@modern-js/plugin 2.35.0 → 2.35.1

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.
@@ -25,10 +25,7 @@ _export(exports, {
25
25
  });
26
26
  const _context = require("./context");
27
27
  const _counter = require("./counter");
28
- const isPipeline = (input) => {
29
- var _input;
30
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
31
- };
28
+ const isPipeline = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
32
29
  const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
33
30
  const getMiddleware = (input) => {
34
31
  if (typeof input === "function") {
@@ -57,11 +54,10 @@ const createPipeline = () => {
57
54
  };
58
55
  const currentCounter = createCurrentCounter();
59
56
  const getCounter = (options) => {
60
- var _options;
61
57
  if (!options) {
62
58
  return currentCounter;
63
59
  }
64
- return createCurrentCounter((_options = options) === null || _options === void 0 ? void 0 : _options.onLast);
60
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
65
61
  };
66
62
  const run = (input, options) => getCounter(options).start(input);
67
63
  const middleware = (input, next) => run(input, {
@@ -75,17 +75,19 @@ const createAsyncManager = (hooks, api) => {
75
75
  const clear = () => {
76
76
  plugins = [];
77
77
  };
78
- const init = () => {
78
+ const init = async () => {
79
79
  const sortedPlugins = (0, _shared.sortPlugins)(plugins);
80
80
  const mergedPluginAPI = {
81
81
  ...pluginAPI,
82
82
  ...overrideAPI
83
83
  };
84
84
  (0, _shared.checkPlugins)(sortedPlugins);
85
- return Promise.all(sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))).then((hooksList) => {
86
- runners = (0, _sync.generateRunner)(hooksList, currentHooks);
87
- return runners;
88
- });
85
+ const hooksList = [];
86
+ for (const plugin of sortedPlugins) {
87
+ hooksList.push(await plugin.setup(mergedPluginAPI));
88
+ }
89
+ runners = (0, _sync.generateRunner)(hooksList, currentHooks);
90
+ return runners;
89
91
  };
90
92
  const run = (cb) => cb();
91
93
  const manager = {
@@ -137,8 +137,7 @@ const generateRunner = (hooksList, hooksMap) => {
137
137
  if (hooksMap) {
138
138
  for (const key in cloneShape) {
139
139
  hooksList.forEach((hooks) => {
140
- var _hooks;
141
- if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key]) {
140
+ if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
142
141
  cloneShape[key].use(hooks[key]);
143
142
  }
144
143
  });
@@ -55,8 +55,5 @@ const createAsyncWaterfall = () => {
55
55
  };
56
56
  return waterfall;
57
57
  };
58
- const isAsyncWaterfall = (input) => {
59
- var _input;
60
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
61
- };
58
+ const isAsyncWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
62
59
  const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
@@ -54,8 +54,5 @@ const createWaterfall = () => {
54
54
  };
55
55
  return waterfall;
56
56
  };
57
- const isWaterfall = (input) => {
58
- var _input;
59
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
60
- };
57
+ const isWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
61
58
  const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
@@ -19,10 +19,8 @@ _export(exports, {
19
19
  });
20
20
  const _farrowpipeline = require("../farrow-pipeline");
21
21
  const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
22
- const isAsyncWorkflow = (input) => {
23
- var _input;
24
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WORKFLOW_SYMBOL]);
25
- };
22
+ const isPromise = (obj) => obj && typeof obj.then === "function";
23
+ const isAsyncWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
26
24
  const createAsyncWorkflow = () => {
27
25
  const pipeline = (0, _farrowpipeline.createAsyncPipeline)();
28
26
  const use = (...input) => {
@@ -50,6 +48,3 @@ const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.res
50
48
  result,
51
49
  ...nextResult
52
50
  ]));
53
- function isPromise(obj) {
54
- return obj && typeof obj.then === "function";
55
- }
@@ -19,10 +19,7 @@ _export(exports, {
19
19
  });
20
20
  const _farrowpipeline = require("../farrow-pipeline");
21
21
  const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
22
- const isParallelWorkflow = (input) => {
23
- var _input;
24
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
25
- };
22
+ const isParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
26
23
  const createParallelWorkflow = () => {
27
24
  const pipeline = (0, _farrowpipeline.createPipeline)();
28
25
  const use = (...input) => {
@@ -39,10 +39,7 @@ const createWorkflow = () => {
39
39
  };
40
40
  return workflow;
41
41
  };
42
- const isWorkflow = (input) => {
43
- var _input;
44
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
45
- };
42
+ const isWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
46
43
  const mapWorkerToMiddleware = (worker) => (input, next) => [
47
44
  worker(input),
48
45
  ...next(input)
package/dist/esm/index.js CHANGED
@@ -45,8 +45,7 @@ var createCounter = function(callback) {
45
45
 
46
46
  // src/farrow-pipeline/index.ts
47
47
  var isPipeline = function(input) {
48
- var _input;
49
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
48
+ return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
50
49
  };
51
50
  var PipelineSymbol = Symbol.for("MODERN_PIPELINE");
52
51
  var getMiddleware = function(input) {
@@ -80,11 +79,10 @@ var createPipeline = function() {
80
79
  };
81
80
  var currentCounter = createCurrentCounter();
82
81
  var getCounter = function(options) {
83
- var _options;
84
82
  if (!options) {
85
83
  return currentCounter;
86
84
  }
87
- return createCurrentCounter((_options = options) === null || _options === void 0 ? void 0 : _options.onLast);
85
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
88
86
  };
89
87
  var run = function(input, options) {
90
88
  return getCounter(options).start(input);
@@ -149,8 +147,7 @@ var createWaterfall = function() {
149
147
  return waterfall;
150
148
  };
151
149
  var isWaterfall = function(input) {
152
- var _input;
153
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
150
+ return Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
154
151
  };
155
152
  var mapBrookToMiddleware = function(brook) {
156
153
  return function(input, next) {
@@ -205,8 +202,7 @@ var createAsyncWaterfall = function() {
205
202
  return waterfall;
206
203
  };
207
204
  var isAsyncWaterfall = function(input) {
208
- var _input;
209
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
205
+ return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
210
206
  };
211
207
  var mapAsyncBrookToAsyncMiddleware = function(brook) {
212
208
  return function(input, next) {
@@ -247,8 +243,7 @@ var createWorkflow = function() {
247
243
  return workflow;
248
244
  };
249
245
  var isWorkflow = function(input) {
250
- var _input;
251
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
246
+ return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
252
247
  };
253
248
  var mapWorkerToMiddleware = function(worker) {
254
249
  return function(input, next) {
@@ -265,8 +260,7 @@ import { _ as _object_spread_props4 } from "@swc/helpers/_/_object_spread_props"
265
260
  import { _ as _to_consumable_array5 } from "@swc/helpers/_/_to_consumable_array";
266
261
  var PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
267
262
  var isParallelWorkflow = function(input) {
268
- var _input;
269
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
263
+ return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
270
264
  };
271
265
  var createParallelWorkflow = function() {
272
266
  var pipeline = createPipeline();
@@ -307,9 +301,11 @@ import { _ as _object_spread6 } from "@swc/helpers/_/_object_spread";
307
301
  import { _ as _object_spread_props5 } from "@swc/helpers/_/_object_spread_props";
308
302
  import { _ as _to_consumable_array6 } from "@swc/helpers/_/_to_consumable_array";
309
303
  var ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
304
+ var isPromise = function(obj) {
305
+ return obj && typeof obj.then === "function";
306
+ };
310
307
  var isAsyncWorkflow = function(input) {
311
- var _input;
312
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WORKFLOW_SYMBOL]);
308
+ return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
313
309
  };
314
310
  var createAsyncWorkflow = function() {
315
311
  var pipeline = createAsyncPipeline();
@@ -351,9 +347,6 @@ var mapAsyncWorkerToAsyncMiddleware = function(worker) {
351
347
  });
352
348
  };
353
349
  };
354
- function isPromise(obj) {
355
- return obj && typeof obj.then === "function";
356
- }
357
350
 
358
351
  // src/manager/sync.ts
359
352
  import { _ as _object_spread7 } from "@swc/helpers/_/_object_spread";
@@ -504,8 +497,7 @@ var generateRunner = function(hooksList, hooksMap) {
504
497
  if (hooksMap) {
505
498
  var _loop = function(key2) {
506
499
  hooksList.forEach(function(hooks) {
507
- var _hooks;
508
- if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key2]) {
500
+ if (hooks === null || hooks === void 0 ? void 0 : hooks[key2]) {
509
501
  cloneShape[key2].use(hooks[key2]);
510
502
  }
511
503
  });
@@ -551,8 +543,10 @@ var cloneHooksMap = function(record) {
551
543
  };
552
544
 
553
545
  // src/manager/async.ts
546
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
554
547
  import { _ as _object_spread8 } from "@swc/helpers/_/_object_spread";
555
548
  import { _ as _object_spread_props7 } from "@swc/helpers/_/_object_spread_props";
549
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
556
550
  var ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
557
551
  var createAsyncManager = function(hooks, api) {
558
552
  var index = 0;
@@ -618,16 +612,88 @@ var createAsyncManager = function(hooks, api) {
618
612
  plugins = [];
619
613
  };
620
614
  var init = function() {
621
- var sortedPlugins = sortPlugins(plugins);
622
- var mergedPluginAPI = _object_spread8({}, pluginAPI, overrideAPI);
623
- checkPlugins(sortedPlugins);
624
- return Promise.all(sortedPlugins.map(function(plugin) {
625
- return plugin.setup(mergedPluginAPI);
626
- })).then(function(hooksList) {
627
- runners = generateRunner(hooksList, currentHooks);
628
- return runners;
615
+ var _ref = _async_to_generator(function() {
616
+ var sortedPlugins, mergedPluginAPI, hooksList, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _, err;
617
+ return _ts_generator(this, function(_state) {
618
+ switch (_state.label) {
619
+ case 0:
620
+ sortedPlugins = sortPlugins(plugins);
621
+ mergedPluginAPI = _object_spread8({}, pluginAPI, overrideAPI);
622
+ checkPlugins(sortedPlugins);
623
+ hooksList = [];
624
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
625
+ _state.label = 1;
626
+ case 1:
627
+ _state.trys.push([
628
+ 1,
629
+ 6,
630
+ 7,
631
+ 8
632
+ ]);
633
+ _iterator = sortedPlugins[Symbol.iterator]();
634
+ _state.label = 2;
635
+ case 2:
636
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
637
+ return [
638
+ 3,
639
+ 5
640
+ ];
641
+ plugin = _step.value;
642
+ _ = hooksList.push;
643
+ return [
644
+ 4,
645
+ plugin.setup(mergedPluginAPI)
646
+ ];
647
+ case 3:
648
+ _.apply(hooksList, [
649
+ _state.sent()
650
+ ]);
651
+ _state.label = 4;
652
+ case 4:
653
+ _iteratorNormalCompletion = true;
654
+ return [
655
+ 3,
656
+ 2
657
+ ];
658
+ case 5:
659
+ return [
660
+ 3,
661
+ 8
662
+ ];
663
+ case 6:
664
+ err = _state.sent();
665
+ _didIteratorError = true;
666
+ _iteratorError = err;
667
+ return [
668
+ 3,
669
+ 8
670
+ ];
671
+ case 7:
672
+ try {
673
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
674
+ _iterator.return();
675
+ }
676
+ } finally {
677
+ if (_didIteratorError) {
678
+ throw _iteratorError;
679
+ }
680
+ }
681
+ return [
682
+ 7
683
+ ];
684
+ case 8:
685
+ runners = generateRunner(hooksList, currentHooks);
686
+ return [
687
+ 2,
688
+ runners
689
+ ];
690
+ }
691
+ });
629
692
  });
630
- };
693
+ return function init2() {
694
+ return _ref.apply(this, arguments);
695
+ };
696
+ }();
631
697
  var run = function(cb) {
632
698
  return cb();
633
699
  };
@@ -1,10 +1,7 @@
1
1
  import { createContext } from "./context";
2
2
  import { createCounter } from "./counter";
3
3
  export { createContext };
4
- export const isPipeline = (input) => {
5
- var _input;
6
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
7
- };
4
+ export const isPipeline = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
8
5
  const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
9
6
  const getMiddleware = (input) => {
10
7
  if (typeof input === "function") {
@@ -33,11 +30,10 @@ export const createPipeline = () => {
33
30
  };
34
31
  const currentCounter = createCurrentCounter();
35
32
  const getCounter = (options) => {
36
- var _options;
37
33
  if (!options) {
38
34
  return currentCounter;
39
35
  }
40
- return createCurrentCounter((_options = options) === null || _options === void 0 ? void 0 : _options.onLast);
36
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
41
37
  };
42
38
  const run = (input, options) => getCounter(options).start(input);
43
39
  const middleware = (input, next) => run(input, {
@@ -65,17 +65,19 @@ export const createAsyncManager = (hooks, api) => {
65
65
  const clear = () => {
66
66
  plugins = [];
67
67
  };
68
- const init = () => {
68
+ const init = async () => {
69
69
  const sortedPlugins = sortPlugins(plugins);
70
70
  const mergedPluginAPI = {
71
71
  ...pluginAPI,
72
72
  ...overrideAPI
73
73
  };
74
74
  checkPlugins(sortedPlugins);
75
- return Promise.all(sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))).then((hooksList) => {
76
- runners = generateRunner(hooksList, currentHooks);
77
- return runners;
78
- });
75
+ const hooksList = [];
76
+ for (const plugin of sortedPlugins) {
77
+ hooksList.push(await plugin.setup(mergedPluginAPI));
78
+ }
79
+ runners = generateRunner(hooksList, currentHooks);
80
+ return runners;
79
81
  };
80
82
  const run = (cb) => cb();
81
83
  const manager = {
@@ -109,8 +109,7 @@ export const generateRunner = (hooksList, hooksMap) => {
109
109
  if (hooksMap) {
110
110
  for (const key in cloneShape) {
111
111
  hooksList.forEach((hooks) => {
112
- var _hooks;
113
- if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key]) {
112
+ if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
114
113
  cloneShape[key].use(hooks[key]);
115
114
  }
116
115
  });
@@ -33,8 +33,5 @@ export const createAsyncWaterfall = () => {
33
33
  };
34
34
  return waterfall;
35
35
  };
36
- export const isAsyncWaterfall = (input) => {
37
- var _input;
38
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
39
- };
36
+ export const isAsyncWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
40
37
  const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
@@ -32,8 +32,5 @@ export const createWaterfall = () => {
32
32
  };
33
33
  return waterfall;
34
34
  };
35
- export const isWaterfall = (input) => {
36
- var _input;
37
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
38
- };
35
+ export const isWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
39
36
  const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
@@ -1,9 +1,7 @@
1
1
  import { createAsyncPipeline } from "../farrow-pipeline";
2
2
  const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
3
- export const isAsyncWorkflow = (input) => {
4
- var _input;
5
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WORKFLOW_SYMBOL]);
6
- };
3
+ const isPromise = (obj) => obj && typeof obj.then === "function";
4
+ export const isAsyncWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
7
5
  export const createAsyncWorkflow = () => {
8
6
  const pipeline = createAsyncPipeline();
9
7
  const use = (...input) => {
@@ -31,6 +29,3 @@ const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.res
31
29
  result,
32
30
  ...nextResult
33
31
  ]));
34
- function isPromise(obj) {
35
- return obj && typeof obj.then === "function";
36
- }
@@ -1,9 +1,6 @@
1
1
  import { createPipeline } from "../farrow-pipeline";
2
2
  const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
3
- export const isParallelWorkflow = (input) => {
4
- var _input;
5
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
6
- };
3
+ export const isParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
7
4
  export const createParallelWorkflow = () => {
8
5
  const pipeline = createPipeline();
9
6
  const use = (...input) => {
@@ -20,10 +20,7 @@ export const createWorkflow = () => {
20
20
  };
21
21
  return workflow;
22
22
  };
23
- export const isWorkflow = (input) => {
24
- var _input;
25
- return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
26
- };
23
+ export const isWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
27
24
  const mapWorkerToMiddleware = (worker) => (input, next) => [
28
25
  worker(input),
29
26
  ...next(input)
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.0",
18
+ "version": "2.35.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -33,15 +33,15 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@swc/helpers": "0.5.1",
36
- "@modern-js/utils": "2.35.0"
36
+ "@modern-js/utils": "2.35.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/jest": "^29",
40
40
  "@types/node": "^14",
41
41
  "typescript": "^5",
42
42
  "jest": "^29",
43
- "@scripts/jest-config": "2.35.0",
44
- "@scripts/build": "2.35.0"
43
+ "@scripts/build": "2.35.1",
44
+ "@scripts/jest-config": "2.35.1"
45
45
  },
46
46
  "sideEffects": false,
47
47
  "publishConfig": {