@modern-js/app-tools 2.4.0 → 2.5.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 (276) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/cjs/analyze/constants.js +100 -0
  3. package/dist/cjs/analyze/generateCode.js +251 -0
  4. package/dist/cjs/analyze/getBundleEntry.js +101 -0
  5. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +225 -0
  6. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +221 -0
  7. package/dist/cjs/analyze/getClientRoutes/index.js +30 -0
  8. package/dist/cjs/analyze/getClientRoutes/utils.js +58 -0
  9. package/dist/cjs/analyze/getFileSystemEntry.js +131 -0
  10. package/dist/cjs/analyze/getHtmlTemplate.js +124 -0
  11. package/dist/cjs/analyze/getServerRoutes.js +174 -0
  12. package/dist/cjs/analyze/index.js +294 -0
  13. package/dist/cjs/analyze/isDefaultExportFunction.js +71 -0
  14. package/dist/cjs/analyze/makeLegalIdentifier.js +36 -0
  15. package/dist/cjs/analyze/nestedRoutes.js +179 -0
  16. package/dist/cjs/analyze/templates.js +330 -0
  17. package/dist/cjs/analyze/utils.js +152 -0
  18. package/dist/cjs/builder/builder-rspack/index.js +31 -0
  19. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  20. package/dist/cjs/builder/builder-webpack/index.js +78 -0
  21. package/dist/cjs/builder/builder-webpack/webpackPlugins/RouterPlugin.js +120 -0
  22. package/dist/cjs/builder/builder-webpack/webpackPlugins/index.js +17 -0
  23. package/dist/cjs/builder/generator/createBuilderOptions.js +47 -0
  24. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +49 -0
  25. package/dist/cjs/builder/generator/getBuilderTargets.js +39 -0
  26. package/dist/cjs/builder/generator/index.js +58 -0
  27. package/dist/cjs/builder/index.js +46 -0
  28. package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +230 -0
  29. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +50 -0
  30. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +57 -0
  31. package/dist/cjs/builder/shared/createCopyPattern.js +75 -0
  32. package/dist/cjs/builder/shared/index.js +19 -0
  33. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +28 -0
  34. package/dist/cjs/builder/shared/types.js +15 -0
  35. package/dist/cjs/commands/build.js +75 -0
  36. package/dist/cjs/commands/deploy.js +31 -0
  37. package/dist/cjs/commands/dev.js +91 -0
  38. package/dist/cjs/commands/index.js +19 -0
  39. package/dist/cjs/commands/inspect.js +41 -0
  40. package/dist/cjs/commands/serve.js +63 -0
  41. package/dist/cjs/config/default.js +186 -0
  42. package/dist/cjs/config/index.js +19 -0
  43. package/dist/cjs/config/initialize/index.js +35 -0
  44. package/dist/cjs/config/initialize/inits.js +161 -0
  45. package/dist/cjs/config/legacy/createHtmlConfig.js +58 -0
  46. package/dist/cjs/config/legacy/createOutputConfig.js +91 -0
  47. package/dist/cjs/config/legacy/createSourceConfig.js +62 -0
  48. package/dist/cjs/config/legacy/createToolsConfig.js +65 -0
  49. package/dist/cjs/config/legacy/index.js +75 -0
  50. package/dist/cjs/defineConfig.js +33 -0
  51. package/dist/cjs/exports/server.js +27 -0
  52. package/dist/cjs/hooks.js +54 -0
  53. package/dist/cjs/index.js +198 -0
  54. package/dist/cjs/initialize/index.js +102 -0
  55. package/dist/cjs/locale/en.js +59 -0
  56. package/dist/cjs/locale/index.js +33 -0
  57. package/dist/cjs/locale/zh.js +59 -0
  58. package/dist/cjs/schema/Schema.js +63 -0
  59. package/dist/cjs/schema/index.js +118 -0
  60. package/dist/cjs/schema/legacy.js +169 -0
  61. package/dist/cjs/types/config/deploy.js +15 -0
  62. package/dist/cjs/types/config/dev.js +15 -0
  63. package/dist/cjs/types/config/experiments.js +15 -0
  64. package/dist/cjs/types/config/html.js +15 -0
  65. package/dist/cjs/types/config/index.js +17 -0
  66. package/dist/cjs/types/config/output.js +15 -0
  67. package/dist/cjs/types/config/performance.js +15 -0
  68. package/dist/cjs/types/config/security.js +15 -0
  69. package/dist/cjs/types/config/source.js +15 -0
  70. package/dist/cjs/types/config/tools.js +15 -0
  71. package/dist/cjs/types/hooks.js +15 -0
  72. package/dist/cjs/types/index.js +19 -0
  73. package/dist/cjs/types/legacyConfig/deploy.js +15 -0
  74. package/dist/cjs/types/legacyConfig/dev.js +15 -0
  75. package/dist/cjs/types/legacyConfig/index.js +15 -0
  76. package/dist/cjs/types/legacyConfig/output.js +15 -0
  77. package/dist/cjs/types/legacyConfig/source.js +15 -0
  78. package/dist/cjs/types/legacyConfig/tools.js +15 -0
  79. package/dist/cjs/types/utils.js +15 -0
  80. package/dist/cjs/utils/config.js +115 -0
  81. package/dist/cjs/utils/createServer.js +70 -0
  82. package/dist/cjs/utils/env.js +38 -0
  83. package/dist/cjs/utils/generateWatchFiles.js +63 -0
  84. package/dist/cjs/utils/getSelectedEntries.js +61 -0
  85. package/dist/cjs/utils/getServerInternalPlugins.js +41 -0
  86. package/dist/cjs/utils/language.js +31 -0
  87. package/dist/cjs/utils/printInstructions.js +34 -0
  88. package/dist/cjs/utils/restart.js +45 -0
  89. package/dist/cjs/utils/routes.js +39 -0
  90. package/dist/cjs/utils/types.js +15 -0
  91. package/dist/esm/analyze/constants.js +42 -0
  92. package/dist/esm/analyze/generateCode.js +486 -0
  93. package/dist/esm/analyze/getBundleEntry.js +64 -0
  94. package/dist/esm/analyze/getClientRoutes/getRoutes.js +233 -0
  95. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  96. package/dist/esm/analyze/getClientRoutes/index.js +3 -0
  97. package/dist/esm/analyze/getClientRoutes/utils.js +23 -0
  98. package/dist/esm/analyze/getFileSystemEntry.js +107 -0
  99. package/dist/esm/analyze/getHtmlTemplate.js +302 -0
  100. package/dist/esm/analyze/getServerRoutes.js +224 -0
  101. package/dist/esm/analyze/index.js +703 -0
  102. package/dist/esm/analyze/isDefaultExportFunction.js +47 -0
  103. package/dist/esm/analyze/makeLegalIdentifier.js +13 -0
  104. package/dist/esm/analyze/nestedRoutes.js +409 -0
  105. package/dist/esm/analyze/templates.js +466 -0
  106. package/dist/esm/analyze/utils.js +374 -0
  107. package/dist/esm/builder/builder-rspack/index.js +6 -0
  108. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  109. package/dist/esm/builder/builder-webpack/index.js +301 -0
  110. package/dist/esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js +346 -0
  111. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +1 -0
  112. package/dist/esm/builder/generator/createBuilderOptions.js +41 -0
  113. package/dist/esm/builder/generator/createBuilderProviderConfig.js +70 -0
  114. package/dist/esm/builder/generator/getBuilderTargets.js +16 -0
  115. package/dist/esm/builder/generator/index.js +199 -0
  116. package/dist/esm/builder/index.js +175 -0
  117. package/dist/esm/builder/shared/builderPlugins/adapterModern.js +300 -0
  118. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +110 -0
  119. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +72 -0
  120. package/dist/esm/builder/shared/createCopyPattern.js +40 -0
  121. package/dist/esm/builder/shared/index.js +3 -0
  122. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +5 -0
  123. package/dist/esm/builder/shared/types.js +1 -0
  124. package/dist/esm/commands/build.js +291 -0
  125. package/dist/esm/commands/deploy.js +154 -0
  126. package/dist/esm/commands/dev.js +301 -0
  127. package/dist/esm/commands/index.js +3 -0
  128. package/dist/esm/commands/inspect.js +149 -0
  129. package/dist/esm/commands/serve.js +199 -0
  130. package/dist/esm/config/default.js +210 -0
  131. package/dist/esm/config/index.js +3 -0
  132. package/dist/esm/config/initialize/index.js +10 -0
  133. package/dist/esm/config/initialize/inits.js +211 -0
  134. package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
  135. package/dist/esm/config/legacy/createOutputConfig.js +41 -0
  136. package/dist/esm/config/legacy/createSourceConfig.js +42 -0
  137. package/dist/esm/config/legacy/createToolsConfig.js +23 -0
  138. package/dist/esm/config/legacy/index.js +38 -0
  139. package/dist/esm/defineConfig.js +61 -0
  140. package/dist/esm/exports/server.js +2 -0
  141. package/dist/esm/hooks.js +29 -0
  142. package/dist/esm/index.js +713 -0
  143. package/dist/esm/initialize/index.js +284 -0
  144. package/dist/esm/locale/en.js +38 -0
  145. package/dist/esm/locale/index.js +9 -0
  146. package/dist/esm/locale/zh.js +38 -0
  147. package/dist/esm/schema/Schema.js +273 -0
  148. package/dist/esm/schema/index.js +181 -0
  149. package/dist/esm/schema/legacy.js +337 -0
  150. package/dist/esm/types/config/deploy.js +1 -0
  151. package/dist/esm/types/config/dev.js +1 -0
  152. package/dist/esm/types/config/experiments.js +1 -0
  153. package/dist/esm/types/config/html.js +1 -0
  154. package/dist/esm/types/config/index.js +1 -0
  155. package/dist/esm/types/config/output.js +1 -0
  156. package/dist/esm/types/config/performance.js +1 -0
  157. package/dist/esm/types/config/security.js +1 -0
  158. package/dist/esm/types/config/source.js +1 -0
  159. package/dist/esm/types/config/tools.js +1 -0
  160. package/dist/esm/types/hooks.js +1 -0
  161. package/dist/esm/types/index.js +3 -0
  162. package/dist/esm/types/legacyConfig/deploy.js +1 -0
  163. package/dist/esm/types/legacyConfig/dev.js +1 -0
  164. package/dist/esm/types/legacyConfig/index.js +1 -0
  165. package/dist/esm/types/legacyConfig/output.js +1 -0
  166. package/dist/esm/types/legacyConfig/source.js +1 -0
  167. package/dist/esm/types/legacyConfig/tools.js +1 -0
  168. package/dist/esm/types/utils.js +1 -0
  169. package/dist/esm/utils/config.js +302 -0
  170. package/dist/esm/utils/createServer.js +258 -0
  171. package/dist/esm/utils/env.js +13 -0
  172. package/dist/esm/utils/generateWatchFiles.js +214 -0
  173. package/dist/esm/utils/getSelectedEntries.js +186 -0
  174. package/dist/esm/utils/getServerInternalPlugins.js +210 -0
  175. package/dist/esm/utils/language.js +6 -0
  176. package/dist/esm/utils/printInstructions.js +152 -0
  177. package/dist/esm/utils/restart.js +187 -0
  178. package/dist/esm/utils/routes.js +153 -0
  179. package/dist/esm/utils/types.js +1 -0
  180. package/dist/esm-node/analyze/constants.js +56 -0
  181. package/dist/esm-node/analyze/generateCode.js +227 -0
  182. package/dist/esm-node/analyze/getBundleEntry.js +77 -0
  183. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +201 -0
  184. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +197 -0
  185. package/dist/esm-node/analyze/getClientRoutes/index.js +6 -0
  186. package/dist/esm-node/analyze/getClientRoutes/utils.js +31 -0
  187. package/dist/esm-node/analyze/getFileSystemEntry.js +109 -0
  188. package/dist/esm-node/analyze/getHtmlTemplate.js +95 -0
  189. package/dist/esm-node/analyze/getServerRoutes.js +154 -0
  190. package/dist/esm-node/analyze/index.js +285 -0
  191. package/dist/esm-node/analyze/isDefaultExportFunction.js +42 -0
  192. package/dist/esm-node/analyze/makeLegalIdentifier.js +13 -0
  193. package/dist/esm-node/analyze/nestedRoutes.js +150 -0
  194. package/dist/esm-node/analyze/templates.js +297 -0
  195. package/dist/esm-node/analyze/utils.js +121 -0
  196. package/dist/esm-node/builder/builder-rspack/index.js +8 -0
  197. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  198. package/dist/esm-node/builder/builder-webpack/index.js +51 -0
  199. package/dist/esm-node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +96 -0
  200. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +1 -0
  201. package/dist/esm-node/builder/generator/createBuilderOptions.js +24 -0
  202. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
  203. package/dist/esm-node/builder/generator/getBuilderTargets.js +21 -0
  204. package/dist/esm-node/builder/generator/index.js +29 -0
  205. package/dist/esm-node/builder/index.js +17 -0
  206. package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +202 -0
  207. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  208. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  209. package/dist/esm-node/builder/shared/createCopyPattern.js +46 -0
  210. package/dist/esm-node/builder/shared/index.js +3 -0
  211. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
  212. package/dist/esm-node/builder/shared/types.js +0 -0
  213. package/dist/esm-node/commands/build.js +52 -0
  214. package/dist/esm-node/commands/deploy.js +8 -0
  215. package/dist/esm-node/commands/dev.js +72 -0
  216. package/dist/esm-node/commands/index.js +3 -0
  217. package/dist/esm-node/commands/inspect.js +18 -0
  218. package/dist/esm-node/commands/serve.js +34 -0
  219. package/dist/esm-node/config/default.js +162 -0
  220. package/dist/esm-node/config/index.js +3 -0
  221. package/dist/esm-node/config/initialize/index.js +12 -0
  222. package/dist/esm-node/config/initialize/inits.js +136 -0
  223. package/dist/esm-node/config/legacy/createHtmlConfig.js +35 -0
  224. package/dist/esm-node/config/legacy/createOutputConfig.js +68 -0
  225. package/dist/esm-node/config/legacy/createSourceConfig.js +39 -0
  226. package/dist/esm-node/config/legacy/createToolsConfig.js +42 -0
  227. package/dist/esm-node/config/legacy/index.js +51 -0
  228. package/dist/esm-node/defineConfig.js +9 -0
  229. package/dist/esm-node/exports/server.js +4 -0
  230. package/dist/esm-node/hooks.js +35 -0
  231. package/dist/esm-node/index.js +172 -0
  232. package/dist/esm-node/initialize/index.js +91 -0
  233. package/dist/esm-node/locale/en.js +36 -0
  234. package/dist/esm-node/locale/index.js +9 -0
  235. package/dist/esm-node/locale/zh.js +36 -0
  236. package/dist/esm-node/schema/Schema.js +40 -0
  237. package/dist/esm-node/schema/index.js +88 -0
  238. package/dist/esm-node/schema/legacy.js +148 -0
  239. package/dist/esm-node/types/config/deploy.js +0 -0
  240. package/dist/esm-node/types/config/dev.js +0 -0
  241. package/dist/esm-node/types/config/experiments.js +0 -0
  242. package/dist/esm-node/types/config/html.js +0 -0
  243. package/dist/esm-node/types/config/index.js +1 -0
  244. package/dist/esm-node/types/config/output.js +0 -0
  245. package/dist/esm-node/types/config/performance.js +0 -0
  246. package/dist/esm-node/types/config/security.js +0 -0
  247. package/dist/esm-node/types/config/source.js +0 -0
  248. package/dist/esm-node/types/config/tools.js +0 -0
  249. package/dist/esm-node/types/hooks.js +0 -0
  250. package/dist/esm-node/types/index.js +3 -0
  251. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  252. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  253. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  254. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  255. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  256. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  257. package/dist/esm-node/types/utils.js +0 -0
  258. package/dist/esm-node/utils/config.js +88 -0
  259. package/dist/esm-node/utils/createServer.js +37 -0
  260. package/dist/esm-node/utils/env.js +15 -0
  261. package/dist/esm-node/utils/generateWatchFiles.js +33 -0
  262. package/dist/esm-node/utils/getSelectedEntries.js +38 -0
  263. package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
  264. package/dist/esm-node/utils/language.js +8 -0
  265. package/dist/esm-node/utils/printInstructions.js +11 -0
  266. package/dist/esm-node/utils/restart.js +22 -0
  267. package/dist/esm-node/utils/routes.js +10 -0
  268. package/dist/esm-node/utils/types.js +0 -0
  269. package/dist/js/modern/analyze/nestedRoutes.js +1 -10
  270. package/dist/js/node/analyze/nestedRoutes.js +1 -10
  271. package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -10
  272. package/dist/types/analyze/templates.d.ts +3 -1
  273. package/dist/types/types/config/tools.d.ts +1 -1
  274. package/dist/types/types/hooks.d.ts +5 -4
  275. package/dist/types/types/index.d.ts +3 -1
  276. package/package.json +30 -31
@@ -0,0 +1,35 @@
1
+ import {
2
+ createAsyncWaterfall,
3
+ createAsyncWorkflow,
4
+ createParallelWorkflow
5
+ } from "@modern-js/plugin";
6
+ const hooks = {
7
+ modifyEntryExport: createAsyncWaterfall(),
8
+ modifyEntryImports: createAsyncWaterfall(),
9
+ modifyEntryRuntimePlugins: createAsyncWaterfall(),
10
+ modifyEntryRenderFunction: createAsyncWaterfall(),
11
+ modifyAsyncEntry: createAsyncWaterfall(),
12
+ modifyFileSystemRoutes: createAsyncWaterfall(),
13
+ modifyServerRoutes: createAsyncWaterfall(),
14
+ htmlPartials: createAsyncWaterfall(),
15
+ beforeGenerateRoutes: createAsyncWaterfall(),
16
+ addDefineTypes: createAsyncWaterfall(),
17
+ collectServerPlugins: createAsyncWaterfall(),
18
+ beforeDev: createAsyncWorkflow(),
19
+ afterDev: createAsyncWorkflow(),
20
+ beforeCreateCompiler: createAsyncWorkflow(),
21
+ afterCreateCompiler: createAsyncWorkflow(),
22
+ beforePrintInstructions: createAsyncWaterfall(),
23
+ beforeBuild: createAsyncWorkflow(),
24
+ afterBuild: createAsyncWorkflow(),
25
+ beforeDeploy: createAsyncWorkflow(),
26
+ afterDeploy: createAsyncWorkflow(),
27
+ beforeRestart: createAsyncWorkflow(),
28
+ registerDev: createParallelWorkflow(),
29
+ beforeDevTask: createParallelWorkflow(),
30
+ registerBuildPlatform: createParallelWorkflow(),
31
+ beforeBuildPlatform: createParallelWorkflow()
32
+ };
33
+ export {
34
+ hooks
35
+ };
@@ -0,0 +1,172 @@
1
+ import path from "path";
2
+ import lintPlugin from "@modern-js/plugin-lint";
3
+ import {
4
+ cleanRequireCache,
5
+ emptyDir,
6
+ Import,
7
+ getCommand
8
+ } from "@modern-js/utils";
9
+ import { castArray } from "@modern-js/utils/lodash";
10
+ import analyzePlugin from "./analyze";
11
+ import initializePlugin from "./initialize";
12
+ import { hooks } from "./hooks";
13
+ import { i18n, localeKeys } from "./locale";
14
+ import { getLocaleLanguage } from "./utils/language";
15
+ import { restart } from "./utils/restart";
16
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
17
+ export * from "./defineConfig";
18
+ export * from "./types";
19
+ const upgradeModel = Import.lazy(
20
+ "@modern-js/upgrade",
21
+ require
22
+ );
23
+ const devCommand = async (program, api) => {
24
+ const runner = api.useHookRunners();
25
+ const devToolMetas = await runner.registerDev();
26
+ const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).action(async (options) => {
27
+ const { dev } = await import("./commands/dev");
28
+ await dev(api, options);
29
+ });
30
+ for (const meta of devToolMetas) {
31
+ if (!meta.subCommands) {
32
+ continue;
33
+ }
34
+ for (const subCmd of meta.subCommands) {
35
+ devProgram.command(subCmd).action(async (options = {}) => {
36
+ const { appDirectory } = api.useAppContext();
37
+ const { isTypescript } = await import("@modern-js/utils");
38
+ await runner.beforeDevTask(meta);
39
+ await meta.action(options, {
40
+ isTsProject: isTypescript(appDirectory)
41
+ });
42
+ });
43
+ }
44
+ }
45
+ };
46
+ const buildCommand = async (program, api) => {
47
+ const runner = api.useHookRunners();
48
+ const platformBuilders = await runner.registerBuildPlatform();
49
+ const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
50
+ const { build } = await import("./commands/build");
51
+ await build(api, options);
52
+ });
53
+ for (const platformBuilder of platformBuilders) {
54
+ const platforms = castArray(platformBuilder.platform);
55
+ for (const platform of platforms) {
56
+ buildProgram.command(platform).action(async () => {
57
+ const { appDirectory } = api.useAppContext();
58
+ const { isTypescript } = await import("@modern-js/utils");
59
+ await runner.beforeBuildPlatform(platformBuilders);
60
+ await platformBuilder.build(platform, {
61
+ isTsProject: isTypescript(appDirectory)
62
+ });
63
+ });
64
+ }
65
+ }
66
+ };
67
+ var src_default = (options = {
68
+ bundler: "webpack"
69
+ }) => ({
70
+ name: "@modern-js/app-tools",
71
+ post: [
72
+ "@modern-js/plugin-initialize",
73
+ "@modern-js/plugin-analyze",
74
+ "@modern-js/plugin-ssr",
75
+ "@modern-js/plugin-document",
76
+ "@modern-js/plugin-state",
77
+ "@modern-js/plugin-router",
78
+ "@modern-js/plugin-router-v5",
79
+ "@modern-js/plugin-polyfill"
80
+ ],
81
+ registerHook: hooks,
82
+ usePlugins: [
83
+ initializePlugin({
84
+ bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
85
+ }),
86
+ analyzePlugin({
87
+ bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
88
+ }),
89
+ lintPlugin()
90
+ ],
91
+ setup: (api) => {
92
+ const locale = getLocaleLanguage();
93
+ i18n.changeLanguage({ locale });
94
+ return {
95
+ async commands({ program }) {
96
+ await devCommand(program, api);
97
+ await buildCommand(program, api);
98
+ program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option(
99
+ "-c --config <config>",
100
+ i18n.t(localeKeys.command.shared.config)
101
+ ).action(async () => {
102
+ const { start } = await import("./commands/serve");
103
+ await start(api);
104
+ });
105
+ program.command("deploy").usage("[options]").option(
106
+ "-c --config <config>",
107
+ i18n.t(localeKeys.command.shared.config)
108
+ ).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
109
+ const { build } = await import("./commands/build");
110
+ await build(api);
111
+ const { deploy } = await import("./commands/deploy");
112
+ await deploy(api, options2);
113
+ process.exit(0);
114
+ });
115
+ program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option(
116
+ "-c, --config <config>",
117
+ i18n.t(localeKeys.command.new.config)
118
+ ).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action(async (options2) => {
119
+ const { MWANewAction } = await import("@modern-js/new-action");
120
+ await MWANewAction({ ...options2, locale: options2.lang || locale });
121
+ });
122
+ program.command("inspect").description("inspect internal webpack config").option(
123
+ `--env <env>`,
124
+ i18n.t(localeKeys.command.inspect.env),
125
+ "development"
126
+ ).option(
127
+ "--output <output>",
128
+ i18n.t(localeKeys.command.inspect.output),
129
+ "/"
130
+ ).option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option(
131
+ "-c --config <config>",
132
+ i18n.t(localeKeys.command.shared.config)
133
+ ).action(async (options2) => {
134
+ const { inspect } = await import("./commands/inspect");
135
+ inspect(api, options2);
136
+ });
137
+ upgradeModel.defineCommand(program.command("upgrade"));
138
+ },
139
+ async prepare() {
140
+ const command = getCommand();
141
+ if (command === "dev" || command === "start" || command === "build") {
142
+ const appContext = api.useAppContext();
143
+ await emptyDir(appContext.distDirectory);
144
+ }
145
+ },
146
+ async watchFiles() {
147
+ const appContext = api.useAppContext();
148
+ const config = api.useResolvedConfigContext();
149
+ return generateWatchFiles(appContext, config.source.configDir);
150
+ },
151
+ async fileChange(e) {
152
+ const { filename, eventType } = e;
153
+ const appContext = api.useAppContext();
154
+ const { appDirectory, srcDirectory } = appContext;
155
+ const absolutePath = path.resolve(appDirectory, filename);
156
+ if (!absolutePath.includes(srcDirectory) && (eventType === "change" || eventType === "unlink")) {
157
+ const { closeServer } = await import("./utils/createServer");
158
+ await closeServer();
159
+ await restart(api.useHookRunners(), filename);
160
+ }
161
+ },
162
+ async beforeRestart() {
163
+ cleanRequireCache([require.resolve("./analyze")]);
164
+ }
165
+ };
166
+ }
167
+ });
168
+ export {
169
+ buildCommand,
170
+ src_default as default,
171
+ devCommand
172
+ };
@@ -0,0 +1,91 @@
1
+ import {
2
+ ensureAbsolutePath,
3
+ getPort,
4
+ isDev,
5
+ isDevCommand
6
+ } from "@modern-js/utils";
7
+ import { legacySchema, schema } from "../schema";
8
+ import {
9
+ checkIsLegacyConfig,
10
+ createDefaultConfig,
11
+ createLegacyDefaultConfig,
12
+ transformNormalizedConfig
13
+ } from "../config";
14
+ var initialize_default = ({
15
+ bundler
16
+ }) => ({
17
+ name: "@modern-js/plugin-initialize",
18
+ setup(api) {
19
+ const config = () => {
20
+ const appContext = api.useAppContext();
21
+ const userConfig = api.useConfigContext();
22
+ return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext, bundler);
23
+ };
24
+ const validateSchema = () => {
25
+ const userConfig = api.useConfigContext();
26
+ const schemas = checkIsLegacyConfig(userConfig) ? legacySchema : schema;
27
+ return schemas.generate();
28
+ };
29
+ return {
30
+ config,
31
+ validateSchema,
32
+ async resolvedConfig({ resolved }) {
33
+ var _a;
34
+ let appContext = api.useAppContext();
35
+ const userConfig = api.useConfigContext();
36
+ const port = await getServerPort(resolved);
37
+ appContext = {
38
+ ...appContext,
39
+ port,
40
+ distDirectory: ensureAbsolutePath(
41
+ appContext.distDirectory,
42
+ ((_a = resolved.output.distPath) == null ? void 0 : _a.root) || "dist"
43
+ )
44
+ };
45
+ api.setAppContext(appContext);
46
+ const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
47
+ resolved._raw = userConfig;
48
+ resolved.server = {
49
+ ...normalizedConfig.server || {},
50
+ port
51
+ };
52
+ resolved.autoLoadPlugins = normalizedConfig.autoLoadPlugins || false;
53
+ stabilizeConfig(resolved, normalizedConfig, [
54
+ "source",
55
+ "bff",
56
+ "dev",
57
+ "html",
58
+ "output",
59
+ "tools",
60
+ "testing",
61
+ "plugins",
62
+ "builderPlugins",
63
+ "runtime",
64
+ "runtimeByEntries",
65
+ "deploy",
66
+ "performance"
67
+ ]);
68
+ if (bundler === "webpack") {
69
+ resolved.security = normalizedConfig.security || {};
70
+ resolved.experiments = normalizedConfig.experiments;
71
+ }
72
+ return { resolved };
73
+ }
74
+ };
75
+ }
76
+ });
77
+ function stabilizeConfig(resolve, config, keys) {
78
+ keys.forEach((key) => {
79
+ resolve[key] = config[key] || {};
80
+ });
81
+ }
82
+ async function getServerPort(config) {
83
+ const prodPort = config.server.port || 8080;
84
+ if (isDev() && isDevCommand()) {
85
+ return getPort(config.dev.port || prodPort);
86
+ }
87
+ return prodPort;
88
+ }
89
+ export {
90
+ initialize_default as default
91
+ };
@@ -0,0 +1,36 @@
1
+ const EN_LOCALE = {
2
+ command: {
3
+ shared: {
4
+ analyze: "analyze bundle size",
5
+ config: "specify config file"
6
+ },
7
+ dev: {
8
+ describe: "start dev server",
9
+ entry: "compiler by entry",
10
+ apiOnly: "start api server only",
11
+ selectEntry: "Please select the entry that needs to be built",
12
+ requireEntry: "You must choose at least one entry"
13
+ },
14
+ build: {
15
+ describe: "build application"
16
+ },
17
+ serve: { describe: "start server" },
18
+ deploy: { describe: "deploy application" },
19
+ new: {
20
+ describe: "generator runner for MWA project",
21
+ debug: "using debug mode to log something",
22
+ config: "set default generator config(json string)",
23
+ distTag: `use specified tag version for it's generator`,
24
+ registry: "set npm registry url to run npm command",
25
+ lang: "set new command language(en or zh)"
26
+ },
27
+ inspect: {
28
+ env: "specify env mode",
29
+ output: "specify inspect content output path",
30
+ verbose: "show full function definitions in output"
31
+ }
32
+ }
33
+ };
34
+ export {
35
+ EN_LOCALE
36
+ };
@@ -0,0 +1,9 @@
1
+ import { I18n } from "@modern-js/plugin-i18n";
2
+ import { ZH_LOCALE } from "./zh";
3
+ import { EN_LOCALE } from "./en";
4
+ const i18n = new I18n();
5
+ const localeKeys = i18n.init("zh", { zh: ZH_LOCALE, en: EN_LOCALE });
6
+ export {
7
+ i18n,
8
+ localeKeys
9
+ };
@@ -0,0 +1,36 @@
1
+ const ZH_LOCALE = {
2
+ command: {
3
+ shared: {
4
+ analyze: "分析构建产物体积,查看各个模块打包后的大小",
5
+ config: "指定配置文件路径,可以为相对路径或绝对路径"
6
+ },
7
+ dev: {
8
+ describe: "本地开发命令",
9
+ entry: "指定入口,编译特定的页面",
10
+ apiOnly: "仅启动 API 接口服务",
11
+ selectEntry: "请选择需要构建的入口",
12
+ requireEntry: "请至少选择一个入口"
13
+ },
14
+ build: {
15
+ describe: "构建应用命令"
16
+ },
17
+ serve: { describe: "应用启动命令" },
18
+ deploy: { describe: "部署应用命令" },
19
+ new: {
20
+ describe: "Web App 项目中执行生成器",
21
+ debug: "开启 Debug 模式,打印调试日志信息",
22
+ config: "生成器运行默认配置(JSON 字符串)",
23
+ distTag: "生成器使用特殊的 npm Tag 版本",
24
+ registry: "生成器运行过程中定制 npm Registry",
25
+ lang: "设置 new 命令执行语言(zh 或者 en)"
26
+ },
27
+ inspect: {
28
+ env: "查看指定环境下的配置",
29
+ output: "指定在 dist 目录下输出的路径",
30
+ verbose: "在结果中展示函数的完整内容"
31
+ }
32
+ }
33
+ };
34
+ export {
35
+ ZH_LOCALE
36
+ };
@@ -0,0 +1,40 @@
1
+ import { merge } from "@modern-js/utils/lodash";
2
+ class Schema extends Map {
3
+ constructor(baseSchema = {}) {
4
+ super();
5
+ this.schema = baseSchema;
6
+ }
7
+ setSchema(key, object) {
8
+ Object.entries(object).forEach(([k, v]) => {
9
+ const target = `${key}.${k}`;
10
+ this.set(target, v);
11
+ });
12
+ return this;
13
+ }
14
+ set(key, value) {
15
+ if (this.has(key)) {
16
+ merge(this.schema[key], value);
17
+ } else {
18
+ this.schema[key] = value;
19
+ }
20
+ return this;
21
+ }
22
+ has(key) {
23
+ return key in this.schema;
24
+ }
25
+ get(key) {
26
+ return this.schema[key];
27
+ }
28
+ delete(key) {
29
+ return delete this.schema[key];
30
+ }
31
+ generate() {
32
+ return Object.entries(this.schema).map(([target, schema]) => ({
33
+ target,
34
+ schema
35
+ }));
36
+ }
37
+ }
38
+ export {
39
+ Schema
40
+ };
@@ -0,0 +1,88 @@
1
+ import { ENTRY_NAME_PATTERN } from "@modern-js/utils/constants";
2
+ import { Schema } from "./Schema";
3
+ const source = {
4
+ entries: {
5
+ type: "object",
6
+ patternProperties: {
7
+ [ENTRY_NAME_PATTERN]: {
8
+ if: { type: "object" },
9
+ then: {
10
+ required: ["entry"],
11
+ properties: {
12
+ entry: { type: ["string", "array"] },
13
+ disableMount: { type: "boolean" },
14
+ customBootstrap: { type: "string" }
15
+ },
16
+ additionalProperties: false
17
+ },
18
+ else: { type: ["string", "array"] }
19
+ }
20
+ }
21
+ },
22
+ enableAsyncEntry: { type: "boolean" },
23
+ disableDefaultEntries: { type: "boolean" },
24
+ entriesDir: { type: "string" },
25
+ disableEntryDirs: { type: "array" },
26
+ configDir: { type: "string" },
27
+ designSystem: { type: "object" }
28
+ };
29
+ const bff = {
30
+ prefix: {
31
+ type: "string"
32
+ },
33
+ proxy: {
34
+ type: "object",
35
+ additionalProperties: {
36
+ type: "string"
37
+ }
38
+ }
39
+ };
40
+ const output = {
41
+ ssg: { typeof: ["boolean", "object", "function"] },
42
+ disableNodePolyfill: { type: "boolean" }
43
+ };
44
+ const dev = {};
45
+ const server = {
46
+ routes: { type: "object" },
47
+ publicRoutes: { type: "object" },
48
+ ssr: {
49
+ type: ["boolean", "object"]
50
+ },
51
+ ssrByEntries: { type: "object" },
52
+ baseUrl: {
53
+ anyOf: [
54
+ {
55
+ type: "string"
56
+ },
57
+ {
58
+ type: "array",
59
+ items: {
60
+ type: "string"
61
+ }
62
+ }
63
+ ]
64
+ },
65
+ port: { type: "number" },
66
+ logger: { type: ["boolean", "object"] },
67
+ metrics: { type: ["boolean", "object"] },
68
+ enableMicroFrontendDebug: { type: "boolean" },
69
+ watchOptions: { type: "object" },
70
+ compiler: { type: "string" },
71
+ enableFrameworkExt: { type: "boolean" }
72
+ };
73
+ const tools = {
74
+ tailwindcss: { type: "object" },
75
+ jest: { typeof: ["object", "function"] },
76
+ esbuild: { typeof: ["object"] }
77
+ };
78
+ const deploy = {
79
+ microFrontend: { type: ["boolean", "object"] }
80
+ };
81
+ const builderPlugins = { type: "array" };
82
+ const schema = new Schema();
83
+ schema.setSchema("bff", bff).setSchema("dev", dev).setSchema("server", server).setSchema("source", source).setSchema("output", output).setSchema("tools", tools).setSchema("deploy", deploy).set("builderPlugin", builderPlugins);
84
+ import { default as default2 } from "./legacy";
85
+ export {
86
+ default2 as legacySchema,
87
+ schema
88
+ };
@@ -0,0 +1,148 @@
1
+ import { ENTRY_NAME_PATTERN } from "@modern-js/utils/constants";
2
+ import { Schema } from "./Schema";
3
+ const source = {
4
+ entries: {
5
+ type: "object",
6
+ patternProperties: {
7
+ [ENTRY_NAME_PATTERN]: {
8
+ if: { type: "object" },
9
+ then: {
10
+ required: ["entry"],
11
+ properties: {
12
+ entry: { type: ["string", "array"] },
13
+ disableMount: { type: "boolean" }
14
+ },
15
+ additionalProperties: false
16
+ },
17
+ else: { type: ["string", "array"] }
18
+ }
19
+ }
20
+ },
21
+ preEntry: { type: ["string", "array"] },
22
+ alias: { typeof: ["object", "function"] },
23
+ enableAsyncEntry: { type: "boolean" },
24
+ disableDefaultEntries: { type: "boolean" },
25
+ envVars: { type: "array" },
26
+ globalVars: { type: "object" },
27
+ moduleScopes: { instanceof: ["Array", "Function"] },
28
+ entriesDir: { type: "string" },
29
+ configDir: { type: "string" },
30
+ include: { type: ["array"] }
31
+ };
32
+ const output = {
33
+ assetPrefix: { type: "string" },
34
+ path: { type: "string" },
35
+ jsPath: { type: "string" },
36
+ cssPath: { type: "string" },
37
+ htmlPath: { type: "string" },
38
+ mediaPath: { type: "string" },
39
+ mountId: { type: "string" },
40
+ favicon: { type: "string" },
41
+ faviconByEntries: {
42
+ type: "object",
43
+ patternProperties: { [ENTRY_NAME_PATTERN]: { type: "string" } }
44
+ },
45
+ title: { type: "string" },
46
+ titleByEntries: {
47
+ type: "object",
48
+ patternProperties: { [ENTRY_NAME_PATTERN]: { type: "string" } }
49
+ },
50
+ meta: { type: "object" },
51
+ metaByEntries: {
52
+ type: "object",
53
+ patternProperties: { [ENTRY_NAME_PATTERN]: { type: "object" } }
54
+ },
55
+ inject: { enum: [true, "head", "body", false] },
56
+ injectByEntries: {
57
+ type: "object",
58
+ patternProperties: {
59
+ [ENTRY_NAME_PATTERN]: { enum: [true, "head", "body", false] }
60
+ }
61
+ },
62
+ copy: { type: "array" },
63
+ scriptExt: { type: "object" },
64
+ disableTsChecker: { type: "boolean" },
65
+ disableHtmlFolder: { type: "boolean" },
66
+ disableCssModuleExtension: { type: "boolean" },
67
+ disableCssExtract: { type: "boolean" },
68
+ enableCssModuleTSDeclaration: { type: "boolean" },
69
+ disableMinimize: { type: "boolean" },
70
+ enableInlineStyles: { type: "boolean" },
71
+ enableInlineScripts: { type: "boolean" },
72
+ disableSourceMap: { type: "boolean" },
73
+ disableInlineRuntimeChunk: { type: "boolean" },
74
+ disableAssetsCache: { type: "boolean" },
75
+ enableLatestDecorators: { type: "boolean" },
76
+ enableTsLoader: { type: "boolean" },
77
+ dataUriLimit: { type: "number" },
78
+ templateParameters: { type: "object" },
79
+ templateParametersByEntries: {
80
+ type: "object",
81
+ patternProperties: { [ENTRY_NAME_PATTERN]: { type: "object" } }
82
+ },
83
+ polyfill: {
84
+ type: "string",
85
+ enum: ["usage", "entry", "off", "ua"]
86
+ },
87
+ cssModuleLocalIdentName: { type: "string" },
88
+ federation: { type: "object" },
89
+ disableNodePolyfill: { type: "boolean" }
90
+ };
91
+ const server = {
92
+ routes: { type: "object" },
93
+ publicRoutes: { type: "object" },
94
+ ssr: {
95
+ type: ["boolean", "object"]
96
+ },
97
+ ssrByEntries: { type: "object" },
98
+ baseUrl: {
99
+ anyOf: [
100
+ {
101
+ type: "string"
102
+ },
103
+ {
104
+ type: "array",
105
+ items: {
106
+ type: "string"
107
+ }
108
+ }
109
+ ]
110
+ },
111
+ port: { type: "number" },
112
+ logger: { type: ["boolean", "object"] },
113
+ metrics: { type: ["boolean", "object"] },
114
+ enableMicroFrontendDebug: { type: "boolean" },
115
+ watchOptions: { type: "object" },
116
+ compiler: { type: "string" },
117
+ enableFrameworkExt: { type: "boolean" }
118
+ };
119
+ const dev = {
120
+ proxy: {
121
+ type: ["boolean", "object"]
122
+ }
123
+ };
124
+ const deploy = {
125
+ microFrontend: { type: ["boolean", "object"] }
126
+ };
127
+ const tools = {
128
+ tailwindcss: { type: "object" },
129
+ jest: { typeof: ["object", "function"] },
130
+ esbuild: { typeof: ["object"] }
131
+ };
132
+ const bff = {
133
+ prefix: {
134
+ type: "string"
135
+ },
136
+ proxy: {
137
+ type: "object",
138
+ additionalProperties: {
139
+ type: "string"
140
+ }
141
+ }
142
+ };
143
+ const schema = new Schema();
144
+ schema.setSchema("bff", bff).setSchema("dev", dev).setSchema("server", server).setSchema("source", source).setSchema("output", output).setSchema("tools", tools).setSchema("deploy", deploy);
145
+ var legacy_default = schema;
146
+ export {
147
+ legacy_default as default
148
+ };
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ export * from "./output";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes