@modern-js/plugin 2.69.5 → 3.0.0-alpha.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 (267) hide show
  1. package/dist/cjs/cli/api.js +119 -0
  2. package/dist/cjs/cli/context.js +85 -0
  3. package/dist/cjs/cli/hooks.js +65 -0
  4. package/dist/cjs/cli/index.js +68 -0
  5. package/dist/cjs/cli/run/config/createLoadedConfig.js +87 -0
  6. package/dist/cjs/cli/run/config/createResolvedConfig.js +48 -0
  7. package/dist/cjs/cli/run/config/loadConfig.js +113 -0
  8. package/dist/cjs/cli/run/create.js +187 -0
  9. package/dist/cjs/cli/run/index.js +56 -0
  10. package/dist/cjs/cli/run/run.js +57 -0
  11. package/dist/cjs/cli/run/types.js +18 -0
  12. package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
  13. package/dist/cjs/cli/run/utils/commander.js +56 -0
  14. package/dist/cjs/cli/run/utils/createFileWatcher.js +112 -0
  15. package/dist/cjs/cli/run/utils/debug.js +37 -0
  16. package/dist/cjs/cli/run/utils/initAppDir.js +55 -0
  17. package/dist/cjs/cli/run/utils/mergeConfig.js +66 -0
  18. package/dist/cjs/hooks.js +169 -0
  19. package/dist/cjs/index.js +53 -26
  20. package/dist/cjs/manager.js +135 -0
  21. package/dist/cjs/runtime/api.js +95 -0
  22. package/dist/cjs/runtime/context.js +60 -0
  23. package/dist/cjs/runtime/hooks.js +46 -0
  24. package/dist/cjs/runtime/index.js +51 -0
  25. package/dist/cjs/runtime/run/create.js +79 -0
  26. package/dist/cjs/runtime/run/index.js +37 -0
  27. package/dist/cjs/runtime/run/types.js +18 -0
  28. package/dist/cjs/server/api.js +96 -0
  29. package/dist/cjs/server/context.js +75 -0
  30. package/dist/cjs/server/hooks.js +43 -0
  31. package/dist/cjs/server/index.js +54 -0
  32. package/dist/cjs/server/run/create.js +79 -0
  33. package/dist/cjs/server/run/index.js +40 -0
  34. package/dist/cjs/server/run/types.js +18 -0
  35. package/dist/cjs/types/cli/api.js +18 -0
  36. package/dist/cjs/types/cli/context.js +18 -0
  37. package/dist/cjs/types/cli/hooks.js +18 -0
  38. package/dist/cjs/types/cli/index.js +18 -0
  39. package/dist/cjs/types/cli/plugin.js +18 -0
  40. package/dist/cjs/types/hooks.js +18 -0
  41. package/dist/cjs/types/index.js +18 -0
  42. package/dist/cjs/types/plugin.js +18 -0
  43. package/dist/cjs/types/runtime/api.js +18 -0
  44. package/dist/cjs/types/runtime/context.js +18 -0
  45. package/dist/cjs/types/runtime/hooks.js +18 -0
  46. package/dist/cjs/types/runtime/index.js +18 -0
  47. package/dist/cjs/types/runtime/plugin.js +18 -0
  48. package/dist/cjs/types/server/api.js +18 -0
  49. package/dist/cjs/types/server/context.js +18 -0
  50. package/dist/cjs/types/server/hooks.js +18 -0
  51. package/dist/cjs/types/server/index.js +18 -0
  52. package/dist/cjs/types/server/plugin.js +18 -0
  53. package/dist/cjs/types/utils.js +18 -0
  54. package/dist/esm/cli/api.mjs +85 -0
  55. package/dist/esm/cli/context.mjs +38 -0
  56. package/dist/esm/cli/hooks.mjs +31 -0
  57. package/dist/esm/cli/index.mjs +7 -0
  58. package/dist/esm/cli/run/config/createLoadedConfig.mjs +53 -0
  59. package/dist/esm/cli/run/config/createResolvedConfig.mjs +14 -0
  60. package/dist/esm/cli/run/config/loadConfig.mjs +59 -0
  61. package/dist/esm/cli/run/create.mjs +150 -0
  62. package/dist/esm/cli/run/index.mjs +7 -0
  63. package/dist/esm/cli/run/run.mjs +23 -0
  64. package/dist/esm/cli/run/types.mjs +0 -0
  65. package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
  66. package/dist/esm/cli/run/utils/commander.mjs +16 -0
  67. package/dist/esm/cli/run/utils/createFileWatcher.mjs +68 -0
  68. package/dist/esm/cli/run/utils/debug.mjs +3 -0
  69. package/dist/esm/cli/run/utils/initAppDir.mjs +11 -0
  70. package/dist/esm/cli/run/utils/mergeConfig.mjs +32 -0
  71. package/dist/esm/hooks.mjs +120 -0
  72. package/dist/esm/index.mjs +3 -0
  73. package/dist/esm/manager.mjs +101 -0
  74. package/dist/esm/runtime/api.mjs +61 -0
  75. package/dist/esm/runtime/context.mjs +23 -0
  76. package/dist/esm/runtime/hooks.mjs +12 -0
  77. package/dist/esm/runtime/index.mjs +5 -0
  78. package/dist/esm/runtime/run/create.mjs +45 -0
  79. package/dist/esm/runtime/run/index.mjs +3 -0
  80. package/dist/esm/runtime/run/types.mjs +0 -0
  81. package/dist/esm/server/api.mjs +59 -0
  82. package/dist/esm/server/context.mjs +38 -0
  83. package/dist/esm/server/hooks.mjs +9 -0
  84. package/dist/esm/server/index.mjs +5 -0
  85. package/dist/esm/server/run/create.mjs +45 -0
  86. package/dist/esm/server/run/index.mjs +3 -0
  87. package/dist/esm/server/run/types.mjs +0 -0
  88. package/dist/esm/types/cli/api.mjs +0 -0
  89. package/dist/esm/types/cli/context.mjs +0 -0
  90. package/dist/esm/types/cli/hooks.mjs +0 -0
  91. package/dist/esm/types/cli/index.mjs +0 -0
  92. package/dist/esm/types/cli/plugin.mjs +0 -0
  93. package/dist/esm/types/hooks.mjs +0 -0
  94. package/dist/esm/types/index.mjs +0 -0
  95. package/dist/esm/types/plugin.mjs +0 -0
  96. package/dist/esm/types/runtime/api.mjs +0 -0
  97. package/dist/esm/types/runtime/context.mjs +0 -0
  98. package/dist/esm/types/runtime/hooks.mjs +0 -0
  99. package/dist/esm/types/runtime/index.mjs +0 -0
  100. package/dist/esm/types/runtime/plugin.mjs +0 -0
  101. package/dist/esm/types/server/api.mjs +0 -0
  102. package/dist/esm/types/server/context.mjs +0 -0
  103. package/dist/esm/types/server/hooks.mjs +0 -0
  104. package/dist/esm/types/server/index.mjs +0 -0
  105. package/dist/esm/types/server/plugin.mjs +0 -0
  106. package/dist/esm/types/utils.mjs +0 -0
  107. package/dist/esm-node/cli/api.mjs +85 -0
  108. package/dist/esm-node/cli/context.mjs +38 -0
  109. package/dist/esm-node/cli/hooks.mjs +31 -0
  110. package/dist/esm-node/cli/index.mjs +7 -0
  111. package/dist/esm-node/cli/run/config/createLoadedConfig.mjs +53 -0
  112. package/dist/esm-node/cli/run/config/createResolvedConfig.mjs +14 -0
  113. package/dist/esm-node/cli/run/config/loadConfig.mjs +59 -0
  114. package/dist/esm-node/cli/run/create.mjs +150 -0
  115. package/dist/esm-node/cli/run/index.mjs +7 -0
  116. package/dist/esm-node/cli/run/run.mjs +23 -0
  117. package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
  118. package/dist/esm-node/cli/run/utils/commander.mjs +16 -0
  119. package/dist/esm-node/cli/run/utils/createFileWatcher.mjs +68 -0
  120. package/dist/esm-node/cli/run/utils/debug.mjs +3 -0
  121. package/dist/esm-node/cli/run/utils/initAppDir.mjs +11 -0
  122. package/dist/esm-node/cli/run/utils/mergeConfig.mjs +32 -0
  123. package/dist/esm-node/hooks.mjs +120 -0
  124. package/dist/esm-node/index.mjs +3 -0
  125. package/dist/esm-node/manager.mjs +101 -0
  126. package/dist/esm-node/runtime/api.mjs +61 -0
  127. package/dist/esm-node/runtime/context.mjs +23 -0
  128. package/dist/esm-node/runtime/hooks.mjs +12 -0
  129. package/dist/esm-node/runtime/index.mjs +5 -0
  130. package/dist/esm-node/runtime/run/create.mjs +45 -0
  131. package/dist/esm-node/runtime/run/index.mjs +3 -0
  132. package/dist/esm-node/runtime/run/types.mjs +0 -0
  133. package/dist/esm-node/server/api.mjs +59 -0
  134. package/dist/esm-node/server/context.mjs +38 -0
  135. package/dist/esm-node/server/hooks.mjs +9 -0
  136. package/dist/esm-node/server/index.mjs +5 -0
  137. package/dist/esm-node/server/run/create.mjs +45 -0
  138. package/dist/esm-node/server/run/index.mjs +3 -0
  139. package/dist/esm-node/server/run/types.mjs +0 -0
  140. package/dist/esm-node/types/cli/api.mjs +0 -0
  141. package/dist/esm-node/types/cli/context.mjs +0 -0
  142. package/dist/esm-node/types/cli/hooks.mjs +0 -0
  143. package/dist/esm-node/types/cli/index.mjs +0 -0
  144. package/dist/esm-node/types/cli/plugin.mjs +0 -0
  145. package/dist/esm-node/types/hooks.mjs +0 -0
  146. package/dist/esm-node/types/index.mjs +0 -0
  147. package/dist/esm-node/types/plugin.mjs +0 -0
  148. package/dist/esm-node/types/runtime/api.mjs +0 -0
  149. package/dist/esm-node/types/runtime/context.mjs +0 -0
  150. package/dist/esm-node/types/runtime/hooks.mjs +0 -0
  151. package/dist/esm-node/types/runtime/index.mjs +0 -0
  152. package/dist/esm-node/types/runtime/plugin.mjs +0 -0
  153. package/dist/esm-node/types/server/api.mjs +0 -0
  154. package/dist/esm-node/types/server/context.mjs +0 -0
  155. package/dist/esm-node/types/server/hooks.mjs +0 -0
  156. package/dist/esm-node/types/server/index.mjs +0 -0
  157. package/dist/esm-node/types/server/plugin.mjs +0 -0
  158. package/dist/esm-node/types/utils.mjs +0 -0
  159. package/dist/types/cli/api.d.ts +8 -0
  160. package/dist/types/cli/context.d.ts +19 -0
  161. package/dist/types/cli/hooks.d.ts +42 -0
  162. package/dist/types/cli/index.d.ts +6 -0
  163. package/dist/types/cli/run/config/createLoadedConfig.d.ts +2 -0
  164. package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
  165. package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
  166. package/dist/types/cli/run/create.d.ts +16 -0
  167. package/dist/types/cli/run/index.d.ts +13 -0
  168. package/dist/types/cli/run/run.d.ts +2 -0
  169. package/dist/types/cli/run/types.d.ts +32 -0
  170. package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
  171. package/dist/types/cli/run/utils/commander.d.ts +5 -0
  172. package/dist/types/cli/run/utils/createFileWatcher.d.ts +3 -0
  173. package/dist/types/cli/run/utils/debug.d.ts +1 -0
  174. package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
  175. package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
  176. package/dist/types/hooks.d.ts +7 -0
  177. package/dist/types/index.d.ts +7 -4
  178. package/dist/types/manager.d.ts +5 -0
  179. package/dist/types/runtime/api.d.ts +9 -0
  180. package/dist/types/runtime/context.d.ts +11 -0
  181. package/dist/types/runtime/hooks.d.ts +2 -0
  182. package/dist/types/runtime/index.d.ts +5 -0
  183. package/dist/types/runtime/run/create.d.ts +7 -0
  184. package/dist/types/runtime/run/index.d.ts +5 -0
  185. package/dist/types/runtime/run/types.d.ts +6 -0
  186. package/dist/types/server/api.d.ts +9 -0
  187. package/dist/types/server/context.d.ts +13 -0
  188. package/dist/types/server/hooks.d.ts +9 -0
  189. package/dist/types/server/index.d.ts +4 -0
  190. package/dist/types/server/run/create.d.ts +7 -0
  191. package/dist/types/server/run/index.d.ts +8 -0
  192. package/dist/types/server/run/types.d.ts +22 -0
  193. package/dist/types/types/cli/api.d.ts +49 -0
  194. package/dist/types/types/cli/context.d.ts +42 -0
  195. package/dist/types/types/cli/hooks.d.ts +72 -0
  196. package/dist/types/types/cli/index.d.ts +4 -0
  197. package/dist/types/types/cli/plugin.d.ts +17 -0
  198. package/dist/types/types/hooks.d.ts +27 -0
  199. package/dist/types/types/index.d.ts +4 -0
  200. package/dist/types/types/plugin.d.ts +46 -0
  201. package/dist/types/types/runtime/api.d.ts +22 -0
  202. package/dist/types/types/runtime/context.d.ts +13 -0
  203. package/dist/types/types/runtime/hooks.d.ts +39 -0
  204. package/dist/types/types/runtime/index.d.ts +4 -0
  205. package/dist/types/types/runtime/plugin.d.ts +14 -0
  206. package/dist/types/types/server/api.d.ts +19 -0
  207. package/dist/types/types/server/context.d.ts +28 -0
  208. package/dist/types/types/server/hooks.d.ts +24 -0
  209. package/dist/types/types/server/index.d.ts +4 -0
  210. package/dist/types/types/server/plugin.d.ts +14 -0
  211. package/dist/types/types/utils.d.ts +7 -0
  212. package/package.json +68 -14
  213. package/rslib.config.mts +4 -0
  214. package/rstest.config.ts +5 -0
  215. package/dist/cjs/farrow-pipeline/context.js +0 -44
  216. package/dist/cjs/farrow-pipeline/counter.js +0 -37
  217. package/dist/cjs/farrow-pipeline/index.js +0 -87
  218. package/dist/cjs/manager/async.js +0 -124
  219. package/dist/cjs/manager/index.js +0 -26
  220. package/dist/cjs/manager/shared.js +0 -60
  221. package/dist/cjs/manager/sync.js +0 -194
  222. package/dist/cjs/manager/types.js +0 -16
  223. package/dist/cjs/waterfall/async.js +0 -68
  224. package/dist/cjs/waterfall/index.js +0 -24
  225. package/dist/cjs/waterfall/sync.js +0 -67
  226. package/dist/cjs/workflow/async.js +0 -60
  227. package/dist/cjs/workflow/index.js +0 -30
  228. package/dist/cjs/workflow/interrupt.js +0 -64
  229. package/dist/cjs/workflow/parallel.js +0 -53
  230. package/dist/cjs/workflow/sync.js +0 -56
  231. package/dist/cjs/workflow/syncParallel.js +0 -55
  232. package/dist/esm/index.js +0 -882
  233. package/dist/esm-node/farrow-pipeline/context.js +0 -20
  234. package/dist/esm-node/farrow-pipeline/counter.js +0 -13
  235. package/dist/esm-node/farrow-pipeline/index.js +0 -60
  236. package/dist/esm-node/index.js +0 -4
  237. package/dist/esm-node/manager/async.js +0 -106
  238. package/dist/esm-node/manager/index.js +0 -3
  239. package/dist/esm-node/manager/shared.js +0 -32
  240. package/dist/esm-node/manager/sync.js +0 -172
  241. package/dist/esm-node/waterfall/async.js +0 -42
  242. package/dist/esm-node/waterfall/index.js +0 -2
  243. package/dist/esm-node/waterfall/sync.js +0 -41
  244. package/dist/esm-node/workflow/async.js +0 -35
  245. package/dist/esm-node/workflow/index.js +0 -5
  246. package/dist/esm-node/workflow/interrupt.js +0 -39
  247. package/dist/esm-node/workflow/parallel.js +0 -28
  248. package/dist/esm-node/workflow/sync.js +0 -31
  249. package/dist/esm-node/workflow/syncParallel.js +0 -30
  250. package/dist/types/farrow-pipeline/context.d.ts +0 -12
  251. package/dist/types/farrow-pipeline/counter.d.ts +0 -11
  252. package/dist/types/farrow-pipeline/index.d.ts +0 -29
  253. package/dist/types/manager/async.d.ts +0 -54
  254. package/dist/types/manager/index.d.ts +0 -3
  255. package/dist/types/manager/shared.d.ts +0 -12
  256. package/dist/types/manager/sync.d.ts +0 -66
  257. package/dist/types/manager/types.d.ts +0 -33
  258. package/dist/types/waterfall/async.d.ts +0 -21
  259. package/dist/types/waterfall/index.d.ts +0 -2
  260. package/dist/types/waterfall/sync.d.ts +0 -20
  261. package/dist/types/workflow/async.d.ts +0 -12
  262. package/dist/types/workflow/index.d.ts +0 -5
  263. package/dist/types/workflow/interrupt.d.ts +0 -12
  264. package/dist/types/workflow/parallel.d.ts +0 -10
  265. package/dist/types/workflow/sync.d.ts +0 -11
  266. package/dist/types/workflow/syncParallel.d.ts +0 -10
  267. /package/dist/esm-node/{manager/types.js → cli/run/types.mjs} +0 -0
@@ -1,20 +0,0 @@
1
- const createContext = (value) => {
2
- let currentValue = value;
3
- return {
4
- use: () => ({
5
- get value() {
6
- return currentValue;
7
- },
8
- set value(v) {
9
- currentValue = v;
10
- }
11
- }),
12
- get: () => currentValue,
13
- set: (v1) => {
14
- currentValue = v1;
15
- }
16
- };
17
- };
18
- export {
19
- createContext
20
- };
@@ -1,13 +0,0 @@
1
- const createCounter = (callback) => {
2
- const dispatch = (index, input) => {
3
- const next = (nextInput = input) => dispatch(index + 1, nextInput);
4
- return callback(index, input, next);
5
- };
6
- return {
7
- start: (input) => dispatch(0, input),
8
- dispatch
9
- };
10
- };
11
- export {
12
- createCounter
13
- };
@@ -1,60 +0,0 @@
1
- import { createContext } from "./context";
2
- import { createCounter } from "./counter";
3
- const isPipeline = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
4
- const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
5
- const getMiddleware = (input) => {
6
- if (typeof input === "function") {
7
- return input;
8
- } else if (input && typeof input.middleware === "function") {
9
- return input.middleware;
10
- }
11
- throw new Error(`${input} is not a Middleware`);
12
- };
13
- const createPipeline = () => {
14
- const middlewares = [];
15
- const use = (...inputs) => {
16
- middlewares.push(...inputs.map(getMiddleware));
17
- return pipeline;
18
- };
19
- const createCurrentCounter = (onLast) => {
20
- return createCounter((index, input, next) => {
21
- if (index >= middlewares.length) {
22
- if (onLast) {
23
- return onLast(input);
24
- }
25
- throw new Error(`Expect returning a value, but all middlewares just calling next()`);
26
- }
27
- return middlewares[index](input, next);
28
- });
29
- };
30
- const currentCounter = createCurrentCounter();
31
- const getCounter = (options) => {
32
- if (!options) {
33
- return currentCounter;
34
- }
35
- return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
36
- };
37
- const run = (input, options) => getCounter(options).start(input);
38
- const middleware = (input, next) => run(input, {
39
- onLast: next
40
- });
41
- const pipeline = {
42
- [PipelineSymbol]: true,
43
- use,
44
- run,
45
- middleware
46
- };
47
- return pipeline;
48
- };
49
- const createAsyncPipeline = () => {
50
- const pipeline = createPipeline();
51
- return {
52
- ...pipeline
53
- };
54
- };
55
- export {
56
- createAsyncPipeline,
57
- createContext,
58
- createPipeline,
59
- isPipeline
60
- };
@@ -1,4 +0,0 @@
1
- export * from "./farrow-pipeline";
2
- export * from "./waterfall";
3
- export * from "./workflow";
4
- export * from "./manager";
@@ -1,106 +0,0 @@
1
- import {
2
- checkPlugins,
3
- hasOwnProperty,
4
- includePlugin,
5
- isObject,
6
- sortPlugins
7
- } from "./shared";
8
- import { DEFAULT_OPTIONS, generateRunner } from "./sync";
9
- const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
10
- const createAsyncManager = (hooks, api) => {
11
- let index = 0;
12
- let runners;
13
- let currentHooks = {
14
- ...hooks
15
- };
16
- const useRunner = () => runners;
17
- const registerHook = (extraHooks) => {
18
- currentHooks = {
19
- ...extraHooks,
20
- ...currentHooks
21
- };
22
- };
23
- const isPlugin = (input) => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
24
- const pluginAPI = {
25
- ...api,
26
- useHookRunners: useRunner
27
- };
28
- const clone = (overrideAPI) => {
29
- let plugins = [];
30
- const addPlugin = (plugin) => {
31
- if (!includePlugin(plugins, plugin)) {
32
- plugins.push({
33
- ...plugin
34
- });
35
- }
36
- };
37
- const usePlugin = (...input) => {
38
- input.forEach((plugin) => {
39
- if (isPlugin(plugin)) {
40
- addPlugin(plugin);
41
- } else if (typeof plugin === "function") {
42
- const options = plugin();
43
- addPlugin(createPlugin(options.setup, options));
44
- } else if (isObject(plugin)) {
45
- addPlugin(createPlugin(plugin.setup, plugin));
46
- } else if (process.env.NODE_ENV !== "production") {
47
- console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
48
- }
49
- });
50
- return manager;
51
- };
52
- const createPlugin = (setup = () => {
53
- }, options = {}) => {
54
- var _options_usePlugins;
55
- if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
56
- options.usePlugins.forEach((plugin) => {
57
- usePlugin(createPlugin(plugin.setup, plugin));
58
- });
59
- }
60
- if (options.registerHook) {
61
- registerHook(options.registerHook);
62
- }
63
- return {
64
- ...DEFAULT_OPTIONS,
65
- name: `No.${index++} plugin`,
66
- ...options,
67
- ASYNC_PLUGIN_SYMBOL,
68
- setup
69
- };
70
- };
71
- const clear = () => {
72
- plugins = [];
73
- };
74
- const init = async () => {
75
- const sortedPlugins = sortPlugins(plugins);
76
- const mergedPluginAPI = {
77
- ...pluginAPI,
78
- ...overrideAPI
79
- };
80
- checkPlugins(sortedPlugins);
81
- const hooksList = [];
82
- for (const plugin of sortedPlugins) {
83
- hooksList.push(await plugin.setup(mergedPluginAPI));
84
- }
85
- runners = generateRunner(hooksList, currentHooks);
86
- return runners;
87
- };
88
- const run = (cb) => cb();
89
- const manager = {
90
- createPlugin,
91
- isPlugin,
92
- usePlugin,
93
- init,
94
- run,
95
- clear,
96
- clone,
97
- registerHook,
98
- useRunner
99
- };
100
- return manager;
101
- };
102
- return clone();
103
- };
104
- export {
105
- createAsyncManager
106
- };
@@ -1,3 +0,0 @@
1
- export * from "./sync";
2
- export * from "./async";
3
- export * from "./types";
@@ -1,32 +0,0 @@
1
- import { pluginDagSort } from "@modern-js/utils/universal/plugin-dag-sort";
2
- const checkPlugins = (plugins) => {
3
- if (process.env.NODE_ENV !== "production") {
4
- plugins.forEach((origin) => {
5
- origin.rivals.forEach((rival) => {
6
- plugins.forEach((plugin) => {
7
- if (rival === plugin.name) {
8
- throw new Error(`${origin.name} has rival ${plugin.name}`);
9
- }
10
- });
11
- });
12
- origin.required.forEach((required) => {
13
- if (!plugins.some((plugin) => plugin.name === required)) {
14
- throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
15
- }
16
- });
17
- });
18
- }
19
- };
20
- function sortPlugins(input) {
21
- return pluginDagSort(input.slice());
22
- }
23
- const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
24
- const isObject = (obj) => obj !== null && typeof obj === "object";
25
- const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
26
- export {
27
- checkPlugins,
28
- hasOwnProperty,
29
- includePlugin,
30
- isObject,
31
- sortPlugins
32
- };
@@ -1,172 +0,0 @@
1
- import { createPipeline, isPipeline } from "../farrow-pipeline";
2
- import { createAsyncWaterfall, createWaterfall, isAsyncWaterfall, isWaterfall } from "../waterfall";
3
- import { createAsyncInterruptWorkflow, createAsyncWorkflow, createParallelWorkflow, createSyncParallelWorkflow, createWorkflow, isAsyncInterruptWorkflow, isAsyncWorkflow, isParallelWorkflow, isSyncParallelWorkflow, isWorkflow } from "../workflow";
4
- import {
5
- checkPlugins,
6
- hasOwnProperty,
7
- includePlugin,
8
- isObject,
9
- sortPlugins
10
- } from "./shared";
11
- const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
12
- const DEFAULT_OPTIONS = {
13
- name: "untitled",
14
- pre: [],
15
- post: [],
16
- rivals: [],
17
- required: [],
18
- usePlugins: [],
19
- registerHook: {}
20
- };
21
- const createManager = (hooks, api) => {
22
- let index = 0;
23
- let runners;
24
- let currentHooks = {
25
- ...hooks
26
- };
27
- const useRunner = () => runners;
28
- const registerHook = (extraHooks) => {
29
- currentHooks = {
30
- ...extraHooks,
31
- ...currentHooks
32
- };
33
- };
34
- const isPlugin = (input) => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
35
- const pluginAPI = {
36
- ...api,
37
- useHookRunners: useRunner
38
- };
39
- const clone = (overrideAPI) => {
40
- let plugins = [];
41
- const addPlugin = (plugin) => {
42
- if (!includePlugin(plugins, plugin)) {
43
- plugins.push({
44
- ...plugin
45
- });
46
- }
47
- };
48
- const usePlugin = (...input) => {
49
- input.forEach((plugin) => {
50
- if (isPlugin(plugin)) {
51
- addPlugin(plugin);
52
- } else if (typeof plugin === "function") {
53
- const options = plugin();
54
- addPlugin(createPlugin(options.setup, options));
55
- } else if (isObject(plugin)) {
56
- addPlugin(createPlugin(plugin.setup, plugin));
57
- } else if (process.env.NODE_ENV !== "production") {
58
- console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
59
- }
60
- });
61
- return manager;
62
- };
63
- const createPlugin = (setup = () => {
64
- }, options = {}) => {
65
- var _options_usePlugins;
66
- if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
67
- options.usePlugins.forEach((plugin) => {
68
- usePlugin(createPlugin(plugin.setup, plugin));
69
- });
70
- }
71
- if (options.registerHook) {
72
- registerHook(options.registerHook);
73
- }
74
- return {
75
- ...DEFAULT_OPTIONS,
76
- name: `No.${index++} plugin`,
77
- ...options,
78
- SYNC_PLUGIN_SYMBOL,
79
- setup
80
- };
81
- };
82
- const clear = () => {
83
- plugins = [];
84
- };
85
- const init = () => {
86
- const sortedPlugins = sortPlugins(plugins);
87
- const mergedPluginAPI = {
88
- ...pluginAPI,
89
- ...overrideAPI
90
- };
91
- checkPlugins(sortedPlugins);
92
- const hooksList = sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI));
93
- runners = generateRunner(hooksList, currentHooks);
94
- return runners;
95
- };
96
- const run = (cb) => cb();
97
- const manager = {
98
- createPlugin,
99
- isPlugin,
100
- usePlugin,
101
- init,
102
- clear,
103
- run,
104
- registerHook,
105
- useRunner,
106
- clone
107
- };
108
- return manager;
109
- };
110
- return clone();
111
- };
112
- const generateRunner = (hooksList, hooksMap) => {
113
- const runner = {};
114
- const cloneShape = cloneHooksMap(hooksMap);
115
- if (hooksMap) {
116
- for (const key in cloneShape) {
117
- hooksList.forEach((hooks) => {
118
- if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
119
- cloneShape[key].use(hooks[key]);
120
- }
121
- });
122
- runner[key] = (input, options) => cloneShape[key].run(input, {
123
- ...options
124
- });
125
- }
126
- }
127
- return runner;
128
- };
129
- const cloneHook = (hook) => {
130
- if (isWaterfall(hook)) {
131
- return createWaterfall();
132
- }
133
- if (isAsyncWaterfall(hook)) {
134
- return createAsyncWaterfall();
135
- }
136
- if (isWorkflow(hook)) {
137
- return createWorkflow();
138
- }
139
- if (isAsyncWorkflow(hook)) {
140
- return createAsyncWorkflow();
141
- }
142
- if (isParallelWorkflow(hook)) {
143
- return createParallelWorkflow();
144
- }
145
- if (isAsyncInterruptWorkflow(hook)) {
146
- return createAsyncInterruptWorkflow();
147
- }
148
- if (isSyncParallelWorkflow(hook)) {
149
- return createSyncParallelWorkflow();
150
- }
151
- if (isPipeline(hook)) {
152
- return createPipeline();
153
- }
154
- throw new Error(`Unknown hook: ${hook}`);
155
- };
156
- const cloneHooksMap = (record) => {
157
- if (!record) {
158
- return record;
159
- }
160
- const result = {};
161
- for (const key in record) {
162
- result[key] = cloneHook(record[key]);
163
- }
164
- return result;
165
- };
166
- export {
167
- DEFAULT_OPTIONS,
168
- cloneHook,
169
- cloneHooksMap,
170
- createManager,
171
- generateRunner
172
- };
@@ -1,42 +0,0 @@
1
- import { createAsyncPipeline } from "../farrow-pipeline";
2
- const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
3
- const getAsyncBrook = (input) => {
4
- if (typeof input === "function") {
5
- return input;
6
- }
7
- if (input && typeof input.middleware === "function") {
8
- return input.middleware;
9
- }
10
- throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
11
- };
12
- const createAsyncWaterfall = () => {
13
- const pipeline = createAsyncPipeline();
14
- const use = (...input) => {
15
- pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
16
- return waterfall;
17
- };
18
- const run = (input, options) => pipeline.run(input, {
19
- ...options,
20
- onLast: (input2) => input2
21
- });
22
- const middleware = (input) => {
23
- return pipeline.run(input, {
24
- onLast: (input2) => input2
25
- });
26
- };
27
- const waterfall = {
28
- ...pipeline,
29
- use,
30
- run,
31
- middleware,
32
- [ASYNC_WATERFALL_SYMBOL]: true
33
- };
34
- return waterfall;
35
- };
36
- const isAsyncWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
37
- const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
38
- export {
39
- createAsyncWaterfall,
40
- getAsyncBrook,
41
- isAsyncWaterfall
42
- };
@@ -1,2 +0,0 @@
1
- export * from "./sync";
2
- export * from "./async";
@@ -1,41 +0,0 @@
1
- import { createPipeline } from "../farrow-pipeline";
2
- const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
3
- const getBrook = (input) => {
4
- if (typeof input === "function") {
5
- return input;
6
- } else if (input && typeof input.middleware === "function") {
7
- return input.middleware;
8
- }
9
- throw new Error(`${input} is not a Brook or { brook: Brook }`);
10
- };
11
- const createWaterfall = () => {
12
- const pipeline = createPipeline();
13
- const use = (...brooks) => {
14
- pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
15
- return waterfall;
16
- };
17
- const run = (input, options) => pipeline.run(input, {
18
- ...options,
19
- onLast: (input2) => input2
20
- });
21
- const middleware = (input) => {
22
- return pipeline.run(input, {
23
- onLast: (input2) => input2
24
- });
25
- };
26
- const waterfall = {
27
- ...pipeline,
28
- use,
29
- run,
30
- middleware,
31
- [WATERFALL_SYMBOL]: true
32
- };
33
- return waterfall;
34
- };
35
- const isWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
36
- const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
37
- export {
38
- createWaterfall,
39
- getBrook,
40
- isWaterfall
41
- };
@@ -1,35 +0,0 @@
1
- import { createAsyncPipeline } from "../farrow-pipeline";
2
- const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
3
- const isPromise = (obj) => obj && typeof obj.then === "function";
4
- const isAsyncWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
5
- const createAsyncWorkflow = () => {
6
- const pipeline = createAsyncPipeline();
7
- const use = (...input) => {
8
- pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
9
- return workflow;
10
- };
11
- const run = (input) => {
12
- const result = pipeline.run(input, {
13
- onLast: () => []
14
- });
15
- if (isPromise(result)) {
16
- return result.then((result2) => result2.filter(Boolean));
17
- }
18
- return result.filter(Boolean);
19
- };
20
- const workflow = {
21
- ...pipeline,
22
- use,
23
- run,
24
- [ASYNC_WORKFLOW_SYMBOL]: true
25
- };
26
- return workflow;
27
- };
28
- const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.resolve(worker(input)).then((result) => Promise.resolve(next(input)).then((nextResult) => [
29
- result,
30
- ...nextResult
31
- ]));
32
- export {
33
- createAsyncWorkflow,
34
- isAsyncWorkflow
35
- };
@@ -1,5 +0,0 @@
1
- export * from "./sync";
2
- export * from "./syncParallel";
3
- export * from "./parallel";
4
- export * from "./async";
5
- export * from "./interrupt";
@@ -1,39 +0,0 @@
1
- import { createAsyncPipeline } from "../farrow-pipeline";
2
- const ASYNC_INTERRUPT_WORKFLOW_SYMBOL = Symbol.for("ASYNC_INTERRUPT_WORKFLOW_SYMBOL");
3
- const isAsyncInterruptWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_INTERRUPT_WORKFLOW_SYMBOL]);
4
- const createAsyncInterruptWorkflow = () => {
5
- const pipeline = createAsyncPipeline();
6
- const use = (...input) => {
7
- pipeline.use(...input.map(mapAsyncWorkerToInterruptMiddleware));
8
- return workflow;
9
- };
10
- const run = async (input) => {
11
- const result = await pipeline.run(input, {
12
- onLast: () => []
13
- });
14
- return result;
15
- };
16
- const workflow = {
17
- ...pipeline,
18
- use,
19
- run,
20
- [ASYNC_INTERRUPT_WORKFLOW_SYMBOL]: true
21
- };
22
- return workflow;
23
- };
24
- const mapAsyncWorkerToInterruptMiddleware = (worker) => async (input, next) => {
25
- let isInterrupted = false;
26
- const interrupt = (value) => {
27
- isInterrupted = true;
28
- return value;
29
- };
30
- const result = await Promise.resolve(worker(input, interrupt));
31
- if (isInterrupted) {
32
- return result;
33
- }
34
- return Promise.resolve(next(input));
35
- };
36
- export {
37
- createAsyncInterruptWorkflow,
38
- isAsyncInterruptWorkflow
39
- };
@@ -1,28 +0,0 @@
1
- import { createPipeline } from "../farrow-pipeline";
2
- const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
3
- const isParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
4
- const createParallelWorkflow = () => {
5
- const pipeline = createPipeline();
6
- const use = (...input) => {
7
- pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
8
- return workflow;
9
- };
10
- const run = (input) => Promise.all(pipeline.run(input, {
11
- onLast: () => []
12
- })).then((result) => result.filter(Boolean));
13
- const workflow = {
14
- ...pipeline,
15
- run,
16
- use,
17
- [PARALLEL_WORKFLOW_SYMBOL]: true
18
- };
19
- return workflow;
20
- };
21
- const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [
22
- worker(input),
23
- ...next(input)
24
- ];
25
- export {
26
- createParallelWorkflow,
27
- isParallelWorkflow
28
- };
@@ -1,31 +0,0 @@
1
- import { createPipeline } from "../farrow-pipeline";
2
- const WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
3
- const createWorkflow = () => {
4
- const pipeline = createPipeline();
5
- const use = (...input) => {
6
- pipeline.use(...input.map(mapWorkerToMiddleware));
7
- return workflow;
8
- };
9
- const run = (input) => {
10
- const result = pipeline.run(input, {
11
- onLast: () => []
12
- });
13
- return result.filter(Boolean);
14
- };
15
- const workflow = {
16
- ...pipeline,
17
- use,
18
- run,
19
- [WORKFLOW_SYMBOL]: true
20
- };
21
- return workflow;
22
- };
23
- const isWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
24
- const mapWorkerToMiddleware = (worker) => (input, next) => [
25
- worker(input),
26
- ...next(input)
27
- ];
28
- export {
29
- createWorkflow,
30
- isWorkflow
31
- };
@@ -1,30 +0,0 @@
1
- import { createPipeline } from "../farrow-pipeline";
2
- const SYNC_PARALLEL_WORKFLOW_SYMBOL = Symbol.for("SYNC_MODERN_PARALLEL_WORKFLOW");
3
- const isSyncParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[SYNC_PARALLEL_WORKFLOW_SYMBOL]);
4
- const createSyncParallelWorkflow = () => {
5
- const pipeline = createPipeline();
6
- const use = (...input) => {
7
- pipeline.use(...input.map(mapSyncParallelWorkerToMiddleware));
8
- return workflow;
9
- };
10
- const run = (input) => {
11
- return pipeline.run(input, {
12
- onLast: () => []
13
- }).filter((result) => Boolean(result));
14
- };
15
- const workflow = {
16
- ...pipeline,
17
- run,
18
- use,
19
- [SYNC_PARALLEL_WORKFLOW_SYMBOL]: true
20
- };
21
- return workflow;
22
- };
23
- const mapSyncParallelWorkerToMiddleware = (worker) => (input, next) => [
24
- worker(input),
25
- ...next(input)
26
- ];
27
- export {
28
- createSyncParallelWorkflow,
29
- isSyncParallelWorkflow
30
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
- * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- */
5
- export type Context<T = any> = {
6
- use: () => {
7
- value: T;
8
- };
9
- get: () => T;
10
- set: (value: T) => void;
11
- };
12
- export declare const createContext: <T>(value: T) => Context<T>;