@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
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createStorybookOptions: ()=>createStorybookOptions,
28
+ createCli: ()=>createCli
29
+ });
30
+ const utils_namespaceObject = require("@modern-js/utils");
31
+ const commander_namespaceObject = require("@modern-js/utils/commander");
32
+ const core_namespaceObject = require("@rsbuild/core");
33
+ const external_manager_js_namespaceObject = require("../../manager.js");
34
+ const external_api_js_namespaceObject = require("../api.js");
35
+ const external_context_js_namespaceObject = require("../context.js");
36
+ const createLoadedConfig_js_namespaceObject = require("./config/createLoadedConfig.js");
37
+ const createResolvedConfig_js_namespaceObject = require("./config/createResolvedConfig.js");
38
+ const checkIsDuplicationPlugin_js_namespaceObject = require("./utils/checkIsDuplicationPlugin.js");
39
+ const commander_js_namespaceObject = require("./utils/commander.js");
40
+ const createFileWatcher_js_namespaceObject = require("./utils/createFileWatcher.js");
41
+ const initAppDir_js_namespaceObject = require("./utils/initAppDir.js");
42
+ const debug = (0, utils_namespaceObject.createDebugger)('plugin');
43
+ const createCli = ()=>{
44
+ let initOptions;
45
+ const pluginManager = (0, external_manager_js_namespaceObject.createPluginManager)();
46
+ const existListenerMap = new Map();
47
+ function createExistListener(event, context) {
48
+ return async function(err) {
49
+ await context.hooks.onBeforeExit.call();
50
+ let hasError = false;
51
+ if (err instanceof Error) {
52
+ utils_namespaceObject.logger.error(err.stack);
53
+ hasError = true;
54
+ } else if (err && ('unhandledRejection' === event || 'uncaughtException' === event)) {
55
+ console.trace('Unknown Error', err);
56
+ hasError = true;
57
+ }
58
+ process.nextTick(()=>{
59
+ process.exit(hasError ? 1 : 0);
60
+ });
61
+ };
62
+ }
63
+ async function init(options) {
64
+ pluginManager.clear();
65
+ initOptions = options;
66
+ const { metaName = 'modern-js', configFile, config, command, version, internalPlugins, handleSetupResult } = options;
67
+ const appDirectory = await (0, initAppDir_js_namespaceObject.initAppDir)(options?.cwd);
68
+ (0, commander_js_namespaceObject.initCommandsMap)();
69
+ (0, commander_js_namespaceObject.setProgramVersion)(version);
70
+ const envName = 'modern-js' === metaName ? 'MODERN' : metaName;
71
+ (0, core_namespaceObject.loadEnv)({
72
+ cwd: appDirectory,
73
+ mode: process.env[`${envName.toUpperCase()}_ENV`] || process.env.NODE_ENV,
74
+ prefixes: [
75
+ `${envName.toUpperCase()}_`
76
+ ]
77
+ });
78
+ const loaded = await (0, createLoadedConfig_js_namespaceObject.createLoadedConfig)(appDirectory, configFile, config);
79
+ const allPlugins = [
80
+ ...internalPlugins || [],
81
+ ...loaded.config.plugins || []
82
+ ];
83
+ (0, checkIsDuplicationPlugin_js_namespaceObject.checkIsDuplicationPlugin)(allPlugins.map((plugin)=>plugin.name));
84
+ pluginManager.addPlugins(allPlugins);
85
+ const plugins = await pluginManager.getPlugins();
86
+ debug('CLI Plugins:', plugins.map((p)=>p.name));
87
+ const context = await (0, external_context_js_namespaceObject.createContext)({
88
+ appContext: (0, external_context_js_namespaceObject.initAppContext)({
89
+ packageName: loaded.packageName,
90
+ configFile: loaded.configFile,
91
+ command: command,
92
+ appDirectory,
93
+ plugins,
94
+ metaName
95
+ }),
96
+ config: loaded.config,
97
+ normalizedConfig: {}
98
+ });
99
+ const pluginAPI = (0, external_api_js_namespaceObject.initPluginAPI)({
100
+ context,
101
+ pluginManager
102
+ });
103
+ context.pluginAPI = pluginAPI;
104
+ for (const plugin of plugins){
105
+ const setupResult = await plugin.setup?.(pluginAPI);
106
+ if (handleSetupResult) await handleSetupResult(setupResult, pluginAPI);
107
+ }
108
+ [
109
+ 'SIGINT',
110
+ 'SIGTERM',
111
+ 'unhandledRejection',
112
+ 'uncaughtException'
113
+ ].forEach((event)=>{
114
+ if (existListenerMap.get(event)) process.off(event, existListenerMap.get(event));
115
+ const existListener = createExistListener(event, context);
116
+ existListenerMap.set(event, existListener);
117
+ process.on(event, existListener);
118
+ });
119
+ const extraConfigs = await context.hooks.config.call();
120
+ const normalizedConfig = await (0, createResolvedConfig_js_namespaceObject.createResolveConfig)(loaded, extraConfigs);
121
+ const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
122
+ context.normalizedConfig = resolved || normalizedConfig;
123
+ await pluginAPI.updateAppContext(context);
124
+ await context.hooks.onPrepare.call();
125
+ await context.hooks?.onAfterPrepare?.call();
126
+ return {
127
+ appContext: context
128
+ };
129
+ }
130
+ async function run(options) {
131
+ const { appContext } = await init(options);
132
+ await appContext.hooks.addCommand.call({
133
+ program: commander_namespaceObject.program
134
+ });
135
+ await (0, createFileWatcher_js_namespaceObject.createFileWatcher)(appContext);
136
+ commander_namespaceObject.program.parse(process.argv);
137
+ if (!commander_namespaceObject.program.commands?.length) utils_namespaceObject.logger.warn('No command found, please make sure you have registered plugins correctly.');
138
+ }
139
+ return {
140
+ init,
141
+ run,
142
+ getPrevInitOptions: ()=>initOptions
143
+ };
144
+ };
145
+ const createStorybookOptions = async (options)=>{
146
+ const pluginManager = (0, external_manager_js_namespaceObject.createPluginManager)();
147
+ pluginManager.clear();
148
+ const { configFile, cwd, metaName = 'modern-js' } = options;
149
+ const appDirectory = await (0, initAppDir_js_namespaceObject.initAppDir)(cwd);
150
+ const loaded = await (0, createLoadedConfig_js_namespaceObject.createLoadedConfig)(appDirectory, configFile);
151
+ pluginManager.addPlugins(loaded.config.plugins || []);
152
+ const plugins = await pluginManager.getPlugins();
153
+ const context = await (0, external_context_js_namespaceObject.createContext)({
154
+ appContext: (0, external_context_js_namespaceObject.initAppContext)({
155
+ packageName: loaded.packageName,
156
+ configFile: loaded.configFile,
157
+ command: 'storybook',
158
+ appDirectory,
159
+ plugins,
160
+ metaName
161
+ }),
162
+ config: loaded.config,
163
+ normalizedConfig: {}
164
+ });
165
+ const pluginAPI = (0, external_api_js_namespaceObject.initPluginAPI)({
166
+ context,
167
+ pluginManager
168
+ });
169
+ context.pluginAPI = pluginAPI;
170
+ for (const plugin of plugins)await plugin.setup?.(pluginAPI);
171
+ const extraConfigs = await context.hooks.config.call();
172
+ const normalizedConfig = await (0, createResolvedConfig_js_namespaceObject.createResolveConfig)(loaded, extraConfigs);
173
+ const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
174
+ return {
175
+ config: resolved || normalizedConfig,
176
+ getAppContext: ()=>pluginAPI.getAppContext()
177
+ };
178
+ };
179
+ exports.createCli = __webpack_exports__.createCli;
180
+ exports.createStorybookOptions = __webpack_exports__.createStorybookOptions;
181
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
182
+ "createCli",
183
+ "createStorybookOptions"
184
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
185
+ Object.defineProperty(exports, '__esModule', {
186
+ value: true
187
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ cli: ()=>cli,
28
+ initAppDir: ()=>initAppDir_js_namespaceObject.initAppDir,
29
+ run: ()=>external_run_js_namespaceObject.run,
30
+ loadTypeScriptFile: ()=>loadConfig_js_namespaceObject.loadTypeScriptFile,
31
+ createCli: ()=>external_create_js_namespaceObject.createCli,
32
+ createLoadedConfig: ()=>createLoadedConfig_js_namespaceObject.createLoadedConfig
33
+ });
34
+ const external_create_js_namespaceObject = require("./create.js");
35
+ const createLoadedConfig_js_namespaceObject = require("./config/createLoadedConfig.js");
36
+ const initAppDir_js_namespaceObject = require("./utils/initAppDir.js");
37
+ const loadConfig_js_namespaceObject = require("./config/loadConfig.js");
38
+ const external_run_js_namespaceObject = require("./run.js");
39
+ const cli = (0, external_create_js_namespaceObject.createCli)();
40
+ exports.cli = __webpack_exports__.cli;
41
+ exports.createCli = __webpack_exports__.createCli;
42
+ exports.createLoadedConfig = __webpack_exports__.createLoadedConfig;
43
+ exports.initAppDir = __webpack_exports__.initAppDir;
44
+ exports.loadTypeScriptFile = __webpack_exports__.loadTypeScriptFile;
45
+ exports.run = __webpack_exports__.run;
46
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
47
+ "cli",
48
+ "createCli",
49
+ "createLoadedConfig",
50
+ "initAppDir",
51
+ "loadTypeScriptFile",
52
+ "run"
53
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
54
+ Object.defineProperty(exports, '__esModule', {
55
+ value: true
56
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ run: ()=>run
28
+ });
29
+ const utils_namespaceObject = require("@modern-js/utils");
30
+ const external_index_js_namespaceObject = require("./index.js");
31
+ const run = async (options)=>{
32
+ const { initialLog, version, cwd, configFile, ...params } = options;
33
+ if (initialLog) utils_namespaceObject.logger.greet(` ${initialLog}\n`);
34
+ const command = process.argv[2];
35
+ if (!process.env.NODE_ENV) if ([
36
+ 'build',
37
+ 'serve',
38
+ 'deploy',
39
+ 'analyze'
40
+ ].includes(command)) process.env.NODE_ENV = 'production';
41
+ else if ('test' === command) process.env.NODE_ENV = 'test';
42
+ else process.env.NODE_ENV = 'development';
43
+ await external_index_js_namespaceObject.cli.run({
44
+ version,
45
+ cwd,
46
+ command,
47
+ configFile,
48
+ ...params
49
+ });
50
+ };
51
+ exports.run = __webpack_exports__.run;
52
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
53
+ "run"
54
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ checkIsDuplicationPlugin: ()=>checkIsDuplicationPlugin
28
+ });
29
+ const utils_namespaceObject = require("@modern-js/utils");
30
+ function checkIsDuplicationPlugin(plugins) {
31
+ const set = new Set();
32
+ const duplicationPlugins = [];
33
+ plugins.filter((plugin)=>'string' == typeof plugin).forEach((plugin)=>{
34
+ if (set.has(plugin)) duplicationPlugins.push(plugin);
35
+ else set.add(plugin);
36
+ });
37
+ if (duplicationPlugins.length > 0) utils_namespaceObject.logger.warn(`Duplicate registration plugins: ${duplicationPlugins.join(',')}.`);
38
+ }
39
+ exports.checkIsDuplicationPlugin = __webpack_exports__.checkIsDuplicationPlugin;
40
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
41
+ "checkIsDuplicationPlugin"
42
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
43
+ Object.defineProperty(exports, '__esModule', {
44
+ value: true
45
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ initCommandsMap: ()=>initCommandsMap,
28
+ program: ()=>utils_namespaceObject.program,
29
+ setProgramVersion: ()=>setProgramVersion
30
+ });
31
+ const utils_namespaceObject = require("@modern-js/utils");
32
+ const setProgramVersion = (version = 'unknown')=>{
33
+ const name = process.argv[1];
34
+ utils_namespaceObject.program.name(name).usage('<command> [options]').version(version);
35
+ };
36
+ function initCommandsMap() {
37
+ if (!utils_namespaceObject.program.hasOwnProperty('commandsMap')) Object.defineProperty(utils_namespaceObject.program, 'commandsMap', {
38
+ get () {
39
+ const map = new Map();
40
+ for (const command of utils_namespaceObject.program.commands)map.set(command._name, command);
41
+ return map;
42
+ },
43
+ configurable: false
44
+ });
45
+ }
46
+ exports.initCommandsMap = __webpack_exports__.initCommandsMap;
47
+ exports.program = __webpack_exports__.program;
48
+ exports.setProgramVersion = __webpack_exports__.setProgramVersion;
49
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
50
+ "initCommandsMap",
51
+ "program",
52
+ "setProgramVersion"
53
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
54
+ Object.defineProperty(exports, '__esModule', {
55
+ value: true
56
+ });
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ createFileWatcher: ()=>createFileWatcher
37
+ });
38
+ const external_crypto_namespaceObject = require("crypto");
39
+ var external_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_crypto_namespaceObject);
40
+ const external_fs_namespaceObject = require("fs");
41
+ const external_path_namespaceObject = require("path");
42
+ const utils_namespaceObject = require("@modern-js/utils");
43
+ const debug = (0, utils_namespaceObject.createDebugger)('watch-files');
44
+ const hashMap = new Map();
45
+ const md5 = (data)=>external_crypto_default().createHash('md5').update(data).digest('hex');
46
+ const createFileWatcher = async (appContext)=>{
47
+ if ((0, utils_namespaceObject.isDevCommand)()) {
48
+ const { appDirectory } = appContext;
49
+ const extraFiles = await appContext.hooks.addWatchFiles.call();
50
+ const watched = extraFiles.filter((extra)=>Array.isArray(extra)).flat();
51
+ const privateWatched = extraFiles.filter((extra)=>!Array.isArray(extra) && extra.isPrivate).map((extra)=>extra.files).flat();
52
+ const isPrivate = (filename)=>privateWatched.some((ff)=>external_path_namespaceObject.resolve(appDirectory, filename).startsWith(ff));
53
+ debug("watched: %o", watched);
54
+ const watcher = utils_namespaceObject.chokidar.watch([
55
+ ...watched,
56
+ ...privateWatched
57
+ ], {
58
+ cwd: appDirectory,
59
+ ignoreInitial: true,
60
+ ignorePermissionErrors: true,
61
+ ignored: [
62
+ '**/__test__/**',
63
+ '**/*.test.(js|jsx|ts|tsx)',
64
+ '**/*.spec.(js|jsx|ts|tsx)',
65
+ '**/*.stories.(js|jsx|ts|tsx)'
66
+ ]
67
+ });
68
+ watcher.on('change', (changed)=>{
69
+ const lastHash = hashMap.get(changed);
70
+ const currentHash = md5(external_fs_namespaceObject.readFileSync(external_path_namespaceObject.join(appDirectory, changed), 'utf8'));
71
+ if (currentHash !== lastHash) {
72
+ debug("file change: %s", changed);
73
+ hashMap.set(changed, currentHash);
74
+ appContext.hooks.onFileChanged.call({
75
+ filename: changed,
76
+ eventType: 'change',
77
+ isPrivate: isPrivate(changed)
78
+ });
79
+ }
80
+ });
81
+ watcher.on('add', (changed)=>{
82
+ debug("add file: %s", changed);
83
+ const currentHash = md5(external_fs_namespaceObject.readFileSync(external_path_namespaceObject.join(appDirectory, changed), 'utf8'));
84
+ hashMap.set(changed, currentHash);
85
+ appContext.hooks.onFileChanged.call({
86
+ filename: changed,
87
+ eventType: 'add',
88
+ isPrivate: isPrivate(changed)
89
+ });
90
+ });
91
+ watcher.on('unlink', (changed)=>{
92
+ debug("remove file: %s", changed);
93
+ if (hashMap.has(changed)) hashMap.delete(changed);
94
+ appContext.hooks.onFileChanged.call({
95
+ filename: changed,
96
+ eventType: 'unlink',
97
+ isPrivate: isPrivate(changed)
98
+ });
99
+ });
100
+ watcher.on('error', (err)=>{
101
+ throw err;
102
+ });
103
+ return watcher;
104
+ }
105
+ };
106
+ exports.createFileWatcher = __webpack_exports__.createFileWatcher;
107
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
108
+ "createFileWatcher"
109
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
110
+ Object.defineProperty(exports, '__esModule', {
111
+ value: true
112
+ });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ debug: ()=>debug
28
+ });
29
+ const utils_namespaceObject = require("@modern-js/utils");
30
+ const debug = (0, utils_namespaceObject.createDebugger)('plugin');
31
+ exports.debug = __webpack_exports__.debug;
32
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
33
+ "debug"
34
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
35
+ Object.defineProperty(exports, '__esModule', {
36
+ value: true
37
+ });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ initAppDir: ()=>initAppDir
37
+ });
38
+ const external_path_namespaceObject = require("path");
39
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
40
+ const utils_namespaceObject = require("@modern-js/utils");
41
+ const initAppDir = async (currentDir)=>{
42
+ const cwd = currentDir || process.cwd();
43
+ const pkg = await (0, utils_namespaceObject.pkgUp)({
44
+ cwd
45
+ });
46
+ if (!pkg) throw new Error(`no package.json found in current work dir: ${cwd}`);
47
+ return external_path_default().dirname(pkg);
48
+ };
49
+ exports.initAppDir = __webpack_exports__.initAppDir;
50
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
51
+ "initAppDir"
52
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
53
+ Object.defineProperty(exports, '__esModule', {
54
+ value: true
55
+ });