@modern-js/plugin 2.15.0 → 2.16.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/farrow-pipeline/context.js +9 -27
  3. package/dist/cjs/farrow-pipeline/counter.js +7 -25
  4. package/dist/cjs/farrow-pipeline/index.js +25 -38
  5. package/dist/cjs/index.js +21 -20
  6. package/dist/cjs/manager/async.js +25 -41
  7. package/dist/cjs/manager/index.js +20 -19
  8. package/dist/cjs/manager/shared.js +16 -34
  9. package/dist/cjs/manager/sync.js +48 -60
  10. package/dist/cjs/manager/types.js +4 -15
  11. package/dist/cjs/waterfall/async.js +25 -34
  12. package/dist/cjs/waterfall/index.js +19 -18
  13. package/dist/cjs/waterfall/sync.js +24 -31
  14. package/dist/cjs/workflow/async.js +25 -33
  15. package/dist/cjs/workflow/index.js +20 -19
  16. package/dist/cjs/workflow/parallel.js +25 -33
  17. package/dist/cjs/workflow/sync.js +23 -29
  18. package/dist/esm/index.js +1123 -637
  19. package/dist/esm-node/farrow-pipeline/context.js +3 -6
  20. package/dist/esm-node/farrow-pipeline/counter.js +1 -4
  21. package/dist/esm-node/farrow-pipeline/index.js +11 -14
  22. package/dist/esm-node/manager/async.js +11 -18
  23. package/dist/esm-node/manager/shared.js +8 -17
  24. package/dist/esm-node/manager/sync.js +21 -42
  25. package/dist/esm-node/manager/types.js +1 -0
  26. package/dist/esm-node/waterfall/async.js +14 -16
  27. package/dist/esm-node/waterfall/sync.js +12 -10
  28. package/dist/esm-node/workflow/async.js +12 -13
  29. package/dist/esm-node/workflow/parallel.js +11 -10
  30. package/dist/esm-node/workflow/sync.js +10 -7
  31. package/package.json +10 -5
  32. package/dist/cjs/utils/pluginDagSort.js +0 -79
  33. package/dist/esm-node/utils/pluginDagSort.js +0 -56
  34. package/dist/types/utils/pluginDagSort.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- const createContext = (value) => {
1
+ export const createContext = (value) => {
2
2
  let currentValue = value;
3
3
  return {
4
4
  use: () => ({
@@ -10,11 +10,8 @@ const createContext = (value) => {
10
10
  }
11
11
  }),
12
12
  get: () => currentValue,
13
- set: (v) => {
14
- currentValue = v;
13
+ set: (v1) => {
14
+ currentValue = v1;
15
15
  }
16
16
  };
17
17
  };
18
- export {
19
- createContext
20
- };
@@ -1,4 +1,4 @@
1
- const createCounter = (callback) => {
1
+ export const createCounter = (callback) => {
2
2
  const dispatch = (index, input) => {
3
3
  const next = (nextInput = input) => dispatch(index + 1, nextInput);
4
4
  return callback(index, input, next);
@@ -8,6 +8,3 @@ const createCounter = (callback) => {
8
8
  dispatch
9
9
  };
10
10
  };
11
- export {
12
- createCounter
13
- };
@@ -1,6 +1,9 @@
1
1
  import { createContext } from "./context";
2
2
  import { createCounter } from "./counter";
3
- const isPipeline = (input) => Boolean(input == null ? void 0 : input[PipelineSymbol]);
3
+ export { createContext };
4
+ export const isPipeline = (input) => {
5
+ return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
6
+ };
4
7
  const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
5
8
  const getMiddleware = (input) => {
6
9
  if (typeof input === "function") {
@@ -10,7 +13,7 @@ const getMiddleware = (input) => {
10
13
  }
11
14
  throw new Error(`${input} is not a Middleware`);
12
15
  };
13
- const createPipeline = () => {
16
+ export const createPipeline = () => {
14
17
  const middlewares = [];
15
18
  const use = (...inputs) => {
16
19
  middlewares.push(...inputs.map(getMiddleware));
@@ -22,9 +25,7 @@ const createPipeline = () => {
22
25
  if (onLast) {
23
26
  return onLast(input);
24
27
  }
25
- throw new Error(
26
- `Expect returning a value, but all middlewares just calling next()`
27
- );
28
+ throw new Error(`Expect returning a value, but all middlewares just calling next()`);
28
29
  }
29
30
  return middlewares[index](input, next);
30
31
  });
@@ -34,7 +35,7 @@ const createPipeline = () => {
34
35
  if (!options) {
35
36
  return currentCounter;
36
37
  }
37
- return createCurrentCounter(options == null ? void 0 : options.onLast);
38
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
38
39
  };
39
40
  const run = (input, options) => getCounter(options).start(input);
40
41
  const middleware = (input, next) => run(input, {
@@ -48,13 +49,9 @@ const createPipeline = () => {
48
49
  };
49
50
  return pipeline;
50
51
  };
51
- const createAsyncPipeline = () => {
52
+ export const createAsyncPipeline = () => {
52
53
  const pipeline = createPipeline();
53
- return { ...pipeline };
54
- };
55
- export {
56
- createAsyncPipeline,
57
- createContext,
58
- createPipeline,
59
- isPipeline
54
+ return {
55
+ ...pipeline
56
+ };
60
57
  };
@@ -1,16 +1,12 @@
1
1
  import { generateRunner, DEFAULT_OPTIONS } from "./sync";
2
- import {
3
- checkPlugins,
4
- isObject,
5
- hasOwnProperty,
6
- sortPlugins,
7
- includePlugin
8
- } from "./shared";
2
+ import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
9
3
  const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
10
- const createAsyncManager = (hooks, api) => {
4
+ export const createAsyncManager = (hooks, api) => {
11
5
  let index = 0;
12
6
  let runners;
13
- let currentHooks = { ...hooks };
7
+ let currentHooks = {
8
+ ...hooks
9
+ };
14
10
  const useRunner = () => runners;
15
11
  const registerHook = (extraHooks) => {
16
12
  currentHooks = {
@@ -27,7 +23,9 @@ const createAsyncManager = (hooks, api) => {
27
23
  let plugins = [];
28
24
  const addPlugin = (plugin) => {
29
25
  if (!includePlugin(plugins, plugin)) {
30
- plugins.push({ ...plugin });
26
+ plugins.push({
27
+ ...plugin
28
+ });
31
29
  }
32
30
  };
33
31
  const usePlugin = (...input) => {
@@ -47,8 +45,8 @@ const createAsyncManager = (hooks, api) => {
47
45
  };
48
46
  const createPlugin = (setup = () => {
49
47
  }, options = {}) => {
50
- var _a;
51
- if ((_a = options.usePlugins) == null ? void 0 : _a.length) {
48
+ var _options_usePlugins;
49
+ if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
52
50
  options.usePlugins.forEach((plugin) => {
53
51
  usePlugin(createPlugin(plugin.setup, plugin));
54
52
  });
@@ -74,9 +72,7 @@ const createAsyncManager = (hooks, api) => {
74
72
  ...overrideAPI
75
73
  };
76
74
  checkPlugins(sortedPlugins);
77
- return Promise.all(
78
- sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))
79
- ).then((hooksList) => {
75
+ return Promise.all(sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))).then((hooksList) => {
80
76
  runners = generateRunner(hooksList, currentHooks);
81
77
  return runners;
82
78
  });
@@ -97,6 +93,3 @@ const createAsyncManager = (hooks, api) => {
97
93
  };
98
94
  return clone();
99
95
  };
100
- export {
101
- createAsyncManager
102
- };
@@ -1,5 +1,5 @@
1
- import { dagSort } from "../utils/pluginDagSort";
2
- const checkPlugins = (plugins) => {
1
+ import { pluginDagSort } from "@modern-js/utils/universal/pluginDagSort";
2
+ export const checkPlugins = (plugins) => {
3
3
  if (process.env.NODE_ENV !== "production") {
4
4
  plugins.forEach((origin) => {
5
5
  origin.rivals.forEach((rival) => {
@@ -11,24 +11,15 @@ const checkPlugins = (plugins) => {
11
11
  });
12
12
  origin.required.forEach((required) => {
13
13
  if (!plugins.some((plugin) => plugin.name === required)) {
14
- throw new Error(
15
- `The plugin: ${required} is required when plugin: ${origin.name} is exist.`
16
- );
14
+ throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
17
15
  }
18
16
  });
19
17
  });
20
18
  }
21
19
  };
22
- function sortPlugins(input) {
23
- return dagSort(input.slice());
20
+ export function sortPlugins(input) {
21
+ return pluginDagSort(input.slice());
24
22
  }
25
- const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
26
- const isObject = (obj) => obj !== null && typeof obj === "object";
27
- const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
28
- export {
29
- checkPlugins,
30
- hasOwnProperty,
31
- includePlugin,
32
- isObject,
33
- sortPlugins
34
- };
23
+ export const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
24
+ export const isObject = (obj) => obj !== null && typeof obj === "object";
25
+ export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
@@ -1,27 +1,9 @@
1
1
  import { isPipeline, createPipeline } from "../farrow-pipeline";
2
- import {
3
- isWaterfall,
4
- createWaterfall,
5
- isAsyncWaterfall,
6
- createAsyncWaterfall
7
- } from "../waterfall";
8
- import {
9
- isWorkflow,
10
- createWorkflow,
11
- isAsyncWorkflow,
12
- createAsyncWorkflow,
13
- isParallelWorkflow,
14
- createParallelWorkflow
15
- } from "../workflow";
16
- import {
17
- checkPlugins,
18
- hasOwnProperty,
19
- includePlugin,
20
- isObject,
21
- sortPlugins
22
- } from "./shared";
2
+ import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
3
+ import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
4
+ import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
23
5
  const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
24
- const DEFAULT_OPTIONS = {
6
+ export const DEFAULT_OPTIONS = {
25
7
  name: "untitled",
26
8
  pre: [],
27
9
  post: [],
@@ -30,10 +12,12 @@ const DEFAULT_OPTIONS = {
30
12
  usePlugins: [],
31
13
  registerHook: {}
32
14
  };
33
- const createManager = (hooks, api) => {
15
+ export const createManager = (hooks, api) => {
34
16
  let index = 0;
35
17
  let runners;
36
- let currentHooks = { ...hooks };
18
+ let currentHooks = {
19
+ ...hooks
20
+ };
37
21
  const useRunner = () => runners;
38
22
  const registerHook = (extraHooks) => {
39
23
  currentHooks = {
@@ -50,7 +34,9 @@ const createManager = (hooks, api) => {
50
34
  let plugins = [];
51
35
  const addPlugin = (plugin) => {
52
36
  if (!includePlugin(plugins, plugin)) {
53
- plugins.push({ ...plugin });
37
+ plugins.push({
38
+ ...plugin
39
+ });
54
40
  }
55
41
  };
56
42
  const usePlugin = (...input) => {
@@ -70,8 +56,8 @@ const createManager = (hooks, api) => {
70
56
  };
71
57
  const createPlugin = (setup = () => {
72
58
  }, options = {}) => {
73
- var _a;
74
- if ((_a = options.usePlugins) == null ? void 0 : _a.length) {
59
+ var _options_usePlugins;
60
+ if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
75
61
  options.usePlugins.forEach((plugin) => {
76
62
  usePlugin(createPlugin(plugin.setup, plugin));
77
63
  });
@@ -97,9 +83,7 @@ const createManager = (hooks, api) => {
97
83
  ...overrideAPI
98
84
  };
99
85
  checkPlugins(sortedPlugins);
100
- const hooksList = sortedPlugins.map(
101
- (plugin) => plugin.setup(mergedPluginAPI)
102
- );
86
+ const hooksList = sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI));
103
87
  runners = generateRunner(hooksList, currentHooks);
104
88
  return runners;
105
89
  };
@@ -119,22 +103,24 @@ const createManager = (hooks, api) => {
119
103
  };
120
104
  return clone();
121
105
  };
122
- const generateRunner = (hooksList, hooksMap) => {
106
+ export const generateRunner = (hooksList, hooksMap) => {
123
107
  const runner = {};
124
108
  const cloneShape = cloneHooksMap(hooksMap);
125
109
  if (hooksMap) {
126
110
  for (const key in cloneShape) {
127
111
  hooksList.forEach((hooks) => {
128
- if (hooks == null ? void 0 : hooks[key]) {
112
+ if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
129
113
  cloneShape[key].use(hooks[key]);
130
114
  }
131
115
  });
132
- runner[key] = (input, options) => cloneShape[key].run(input, { ...options });
116
+ runner[key] = (input, options) => cloneShape[key].run(input, {
117
+ ...options
118
+ });
133
119
  }
134
120
  }
135
121
  return runner;
136
122
  };
137
- const cloneHook = (hook) => {
123
+ export const cloneHook = (hook) => {
138
124
  if (isWaterfall(hook)) {
139
125
  return createWaterfall();
140
126
  }
@@ -155,7 +141,7 @@ const cloneHook = (hook) => {
155
141
  }
156
142
  throw new Error(`Unknown hook: ${hook}`);
157
143
  };
158
- const cloneHooksMap = (record) => {
144
+ export const cloneHooksMap = (record) => {
159
145
  if (!record) {
160
146
  return record;
161
147
  }
@@ -165,10 +151,3 @@ const cloneHooksMap = (record) => {
165
151
  }
166
152
  return result;
167
153
  };
168
- export {
169
- DEFAULT_OPTIONS,
170
- cloneHook,
171
- cloneHooksMap,
172
- createManager,
173
- generateRunner
174
- };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,6 @@
1
- import {
2
- createAsyncPipeline
3
- } from "../farrow-pipeline";
1
+ import { createAsyncPipeline } from "../farrow-pipeline";
4
2
  const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
5
- const getAsyncBrook = (input) => {
3
+ export const getAsyncBrook = (input) => {
6
4
  if (typeof input === "function") {
7
5
  return input;
8
6
  }
@@ -11,17 +9,20 @@ const getAsyncBrook = (input) => {
11
9
  }
12
10
  throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
13
11
  };
14
- const createAsyncWaterfall = () => {
12
+ export const createAsyncWaterfall = () => {
15
13
  const pipeline = createAsyncPipeline();
16
14
  const use = (...input) => {
17
- pipeline.use(
18
- ...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)
19
- );
15
+ pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
20
16
  return waterfall;
21
17
  };
22
- const run = (input, options) => pipeline.run(input, { ...options, onLast: (input2) => input2 });
18
+ const run = (input, options) => pipeline.run(input, {
19
+ ...options,
20
+ onLast: (input2) => input2
21
+ });
23
22
  const middleware = (input) => {
24
- return pipeline.run(input, { onLast: (input2) => input2 });
23
+ return pipeline.run(input, {
24
+ onLast: (input2) => input2
25
+ });
25
26
  };
26
27
  const waterfall = {
27
28
  ...pipeline,
@@ -32,10 +33,7 @@ const createAsyncWaterfall = () => {
32
33
  };
33
34
  return waterfall;
34
35
  };
35
- const isAsyncWaterfall = (input) => Boolean(input == null ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
36
- const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
37
- export {
38
- createAsyncWaterfall,
39
- getAsyncBrook,
40
- isAsyncWaterfall
36
+ export const isAsyncWaterfall = (input) => {
37
+ return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
41
38
  };
39
+ const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
@@ -1,6 +1,6 @@
1
1
  import { createPipeline } from "../farrow-pipeline";
2
2
  const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
3
- const getBrook = (input) => {
3
+ export const getBrook = (input) => {
4
4
  if (typeof input === "function") {
5
5
  return input;
6
6
  } else if (input && typeof input.middleware === "function") {
@@ -8,15 +8,20 @@ const getBrook = (input) => {
8
8
  }
9
9
  throw new Error(`${input} is not a Brook or { brook: Brook }`);
10
10
  };
11
- const createWaterfall = () => {
11
+ export const createWaterfall = () => {
12
12
  const pipeline = createPipeline();
13
13
  const use = (...brooks) => {
14
14
  pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
15
15
  return waterfall;
16
16
  };
17
- const run = (input, options) => pipeline.run(input, { ...options, onLast: (input2) => input2 });
17
+ const run = (input, options) => pipeline.run(input, {
18
+ ...options,
19
+ onLast: (input2) => input2
20
+ });
18
21
  const middleware = (input) => {
19
- return pipeline.run(input, { onLast: (input2) => input2 });
22
+ return pipeline.run(input, {
23
+ onLast: (input2) => input2
24
+ });
20
25
  };
21
26
  const waterfall = {
22
27
  ...pipeline,
@@ -27,10 +32,7 @@ const createWaterfall = () => {
27
32
  };
28
33
  return waterfall;
29
34
  };
30
- const isWaterfall = (input) => Boolean(input == null ? void 0 : input[WATERFALL_SYMBOL]);
31
- const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
32
- export {
33
- createWaterfall,
34
- getBrook,
35
- isWaterfall
35
+ export const isWaterfall = (input) => {
36
+ return Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
36
37
  };
38
+ const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
@@ -1,16 +1,18 @@
1
- import {
2
- createAsyncPipeline
3
- } from "../farrow-pipeline";
1
+ import { createAsyncPipeline } from "../farrow-pipeline";
4
2
  const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
5
- const isAsyncWorkflow = (input) => Boolean(input == null ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
6
- const createAsyncWorkflow = () => {
3
+ export const isAsyncWorkflow = (input) => {
4
+ return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
5
+ };
6
+ export const createAsyncWorkflow = () => {
7
7
  const pipeline = createAsyncPipeline();
8
8
  const use = (...input) => {
9
9
  pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
10
10
  return workflow;
11
11
  };
12
12
  const run = (input) => {
13
- const result = pipeline.run(input, { onLast: () => [] });
13
+ const result = pipeline.run(input, {
14
+ onLast: () => []
15
+ });
14
16
  if (isPromise(result)) {
15
17
  return result.then((result2) => result2.filter(Boolean));
16
18
  }
@@ -24,13 +26,10 @@ const createAsyncWorkflow = () => {
24
26
  };
25
27
  return workflow;
26
28
  };
27
- const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.resolve(worker(input)).then(
28
- (result) => Promise.resolve(next(input)).then((nextResult) => [result, ...nextResult])
29
- );
29
+ const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.resolve(worker(input)).then((result) => Promise.resolve(next(input)).then((nextResult) => [
30
+ result,
31
+ ...nextResult
32
+ ]));
30
33
  function isPromise(obj) {
31
34
  return obj && typeof obj.then === "function";
32
35
  }
33
- export {
34
- createAsyncWorkflow,
35
- isAsyncWorkflow
36
- };
@@ -1,15 +1,17 @@
1
1
  import { createPipeline } from "../farrow-pipeline";
2
2
  const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
3
- const isParallelWorkflow = (input) => Boolean(input == null ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
4
- const createParallelWorkflow = () => {
3
+ export const isParallelWorkflow = (input) => {
4
+ return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
5
+ };
6
+ export const createParallelWorkflow = () => {
5
7
  const pipeline = createPipeline();
6
8
  const use = (...input) => {
7
9
  pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
8
10
  return workflow;
9
11
  };
10
- const run = (input) => Promise.all(pipeline.run(input, { onLast: () => [] })).then(
11
- (result) => result.filter(Boolean)
12
- );
12
+ const run = (input) => Promise.all(pipeline.run(input, {
13
+ onLast: () => []
14
+ })).then((result) => result.filter(Boolean));
13
15
  const workflow = {
14
16
  ...pipeline,
15
17
  run,
@@ -18,8 +20,7 @@ const createParallelWorkflow = () => {
18
20
  };
19
21
  return workflow;
20
22
  };
21
- const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [worker(input), ...next(input)];
22
- export {
23
- createParallelWorkflow,
24
- isParallelWorkflow
25
- };
23
+ const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [
24
+ worker(input),
25
+ ...next(input)
26
+ ];
@@ -1,13 +1,15 @@
1
1
  import { createPipeline } from "../farrow-pipeline";
2
2
  const WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
3
- const createWorkflow = () => {
3
+ export const createWorkflow = () => {
4
4
  const pipeline = createPipeline();
5
5
  const use = (...input) => {
6
6
  pipeline.use(...input.map(mapWorkerToMiddleware));
7
7
  return workflow;
8
8
  };
9
9
  const run = (input) => {
10
- const result = pipeline.run(input, { onLast: () => [] });
10
+ const result = pipeline.run(input, {
11
+ onLast: () => []
12
+ });
11
13
  return result.filter(Boolean);
12
14
  };
13
15
  const workflow = {
@@ -18,9 +20,10 @@ const createWorkflow = () => {
18
20
  };
19
21
  return workflow;
20
22
  };
21
- const isWorkflow = (input) => Boolean(input == null ? void 0 : input[WORKFLOW_SYMBOL]);
22
- const mapWorkerToMiddleware = (worker) => (input, next) => [worker(input), ...next(input)];
23
- export {
24
- createWorkflow,
25
- isWorkflow
23
+ export const isWorkflow = (input) => {
24
+ return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
26
25
  };
26
+ const mapWorkerToMiddleware = (worker) => (input, next) => [
27
+ worker(input),
28
+ ...next(input)
29
+ ];
package/package.json CHANGED
@@ -3,7 +3,11 @@
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
5
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
- "repository": "web-infra-dev/modern.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/toolkit/plugin"
10
+ },
7
11
  "license": "MIT",
8
12
  "keywords": [
9
13
  "react",
@@ -11,7 +15,7 @@
11
15
  "modern",
12
16
  "modern.js"
13
17
  ],
14
- "version": "2.15.0",
18
+ "version": "2.16.0",
15
19
  "jsnext:source": "./src/index.ts",
16
20
  "types": "./dist/types/index.d.ts",
17
21
  "main": "./dist/cjs/index.js",
@@ -28,15 +32,16 @@
28
32
  }
29
33
  },
30
34
  "dependencies": {
31
- "@babel/runtime": "^7.18.0"
35
+ "@babel/runtime": "^7.18.0",
36
+ "@modern-js/utils": "2.16.0"
32
37
  },
33
38
  "devDependencies": {
34
39
  "@types/jest": "^29",
35
40
  "@types/node": "^14",
36
41
  "typescript": "^4",
37
42
  "jest": "^29",
38
- "@scripts/build": "2.15.0",
39
- "@scripts/jest-config": "2.15.0"
43
+ "@scripts/build": "2.16.0",
44
+ "@scripts/jest-config": "2.16.0"
40
45
  },
41
46
  "sideEffects": false,
42
47
  "publishConfig": {
@@ -1,79 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var pluginDagSort_exports = {};
19
- __export(pluginDagSort_exports, {
20
- dagSort: () => dagSort
21
- });
22
- module.exports = __toCommonJS(pluginDagSort_exports);
23
- const dagSort = (plugins, key = "name", preKey = "pre", postKey = "post") => {
24
- let allLines = [];
25
- function getPluginByAny(q) {
26
- const target = plugins.find(
27
- (item) => typeof q === "string" ? item[key] === q : item[key] === q[key]
28
- );
29
- if (!target) {
30
- throw new Error(`plugin ${q} not existed`);
31
- }
32
- return target;
33
- }
34
- plugins.forEach((item) => {
35
- item[preKey].forEach((p) => {
36
- if (plugins.find((ap) => ap.name === p)) {
37
- allLines.push([getPluginByAny(p)[key], getPluginByAny(item)[key]]);
38
- }
39
- });
40
- item[postKey].forEach((pt) => {
41
- if (plugins.find((ap) => ap.name === pt)) {
42
- allLines.push([getPluginByAny(item)[key], getPluginByAny(pt)[key]]);
43
- }
44
- });
45
- });
46
- let zeroEndPoints = plugins.filter(
47
- (item) => !allLines.find((l) => l[1] === item[key])
48
- );
49
- const sortedPoint = [];
50
- while (zeroEndPoints.length) {
51
- const zep = zeroEndPoints.shift();
52
- sortedPoint.push(getPluginByAny(zep));
53
- allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
54
- const restPoints = plugins.filter(
55
- (item) => !sortedPoint.find((sp) => sp[key] === item[key])
56
- );
57
- zeroEndPoints = restPoints.filter(
58
- // eslint-disable-next-line @typescript-eslint/no-loop-func
59
- (item) => !allLines.find((l) => l[1] === item[key])
60
- );
61
- }
62
- if (allLines.length) {
63
- const restInRingPoints = {};
64
- allLines.forEach((l) => {
65
- restInRingPoints[l[0]] = true;
66
- restInRingPoints[l[1]] = true;
67
- });
68
- throw new Error(
69
- `plugins dependences has loop: ${Object.keys(restInRingPoints).join(
70
- ","
71
- )}`
72
- );
73
- }
74
- return sortedPoint;
75
- };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- dagSort
79
- });