@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2

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 (279) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/dist/js/modern/analyze/generateCode.js +30 -38
  3. package/dist/js/modern/analyze/getBundleEntry.js +5 -13
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
  6. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
  8. package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
  9. package/dist/js/modern/analyze/getServerRoutes.js +25 -38
  10. package/dist/js/modern/analyze/index.js +90 -48
  11. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  12. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  13. package/dist/js/modern/analyze/nestedRoutes.js +8 -33
  14. package/dist/js/modern/analyze/templates.js +22 -37
  15. package/dist/js/modern/analyze/utils.js +0 -7
  16. package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
  17. package/dist/js/modern/builder/index.js +56 -37
  18. package/dist/js/modern/builder/share.js +1 -5
  19. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
  20. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
  21. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  22. package/dist/js/modern/commands/build.js +12 -46
  23. package/dist/js/modern/commands/dev.js +20 -23
  24. package/dist/js/modern/commands/inspect.js +4 -19
  25. package/dist/js/modern/commands/start.js +1 -2
  26. package/dist/js/modern/config/default.js +207 -0
  27. package/dist/js/modern/config/index.js +2 -0
  28. package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
  29. package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
  30. package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
  31. package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
  32. package/dist/js/modern/config/initial/index.js +11 -0
  33. package/dist/js/modern/config/initial/inits.js +117 -0
  34. package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
  35. package/dist/js/modern/defineConfig.js +12 -0
  36. package/dist/js/modern/hooks.js +23 -19
  37. package/dist/js/modern/index.js +12 -19
  38. package/dist/js/modern/initialize/index.js +72 -0
  39. package/dist/js/modern/schema/Schema.js +39 -0
  40. package/dist/js/modern/schema/index.js +139 -0
  41. package/dist/js/modern/schema/legacy.js +284 -0
  42. package/dist/js/modern/types/config/deploy.js +0 -0
  43. package/dist/js/modern/types/config/dev.js +0 -0
  44. package/dist/js/modern/types/config/experiments.js +0 -0
  45. package/dist/js/modern/types/config/html.js +0 -0
  46. package/dist/js/modern/types/config/index.js +2 -0
  47. package/dist/js/modern/types/config/output.js +0 -0
  48. package/dist/js/modern/types/config/performance.js +0 -0
  49. package/dist/js/modern/types/config/security.js +0 -0
  50. package/dist/js/modern/types/config/source.js +0 -0
  51. package/dist/js/modern/types/config/tools.js +0 -0
  52. package/dist/js/modern/types/hooks.js +0 -0
  53. package/dist/js/modern/types/index.js +4 -0
  54. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  55. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  56. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  57. package/dist/js/modern/types/legacyConfig/output.js +1 -0
  58. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  59. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  60. package/dist/js/modern/utils/config.js +2 -13
  61. package/dist/js/modern/utils/createFileWatcher.js +82 -0
  62. package/dist/js/modern/utils/createServer.js +0 -5
  63. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  64. package/dist/js/modern/utils/printInstructions.js +2 -1
  65. package/dist/js/modern/utils/restart.js +17 -0
  66. package/dist/js/modern/utils/routes.js +0 -2
  67. package/dist/js/node/analyze/generateCode.js +30 -61
  68. package/dist/js/node/analyze/getBundleEntry.js +5 -19
  69. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
  70. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
  71. package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
  72. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
  73. package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
  74. package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
  75. package/dist/js/node/analyze/getServerRoutes.js +24 -46
  76. package/dist/js/node/analyze/index.js +91 -70
  77. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  78. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  79. package/dist/js/node/analyze/nestedRoutes.js +8 -41
  80. package/dist/js/node/analyze/templates.js +22 -47
  81. package/dist/js/node/analyze/utils.js +0 -20
  82. package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
  83. package/dist/js/node/builder/index.js +57 -51
  84. package/dist/js/node/builder/share.js +1 -13
  85. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
  86. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
  87. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  88. package/dist/js/node/commands/build.js +10 -57
  89. package/dist/js/node/commands/deploy.js +0 -2
  90. package/dist/js/node/commands/dev.js +19 -34
  91. package/dist/js/node/commands/index.js +0 -6
  92. package/dist/js/node/commands/inspect.js +4 -26
  93. package/dist/js/node/commands/start.js +1 -11
  94. package/dist/js/node/config/default.js +214 -0
  95. package/dist/js/node/config/index.js +31 -0
  96. package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
  97. package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
  98. package/dist/js/node/config/initial/createSourceConfig.js +38 -0
  99. package/dist/js/node/config/initial/createToolsConfig.js +47 -0
  100. package/dist/js/node/config/initial/index.js +24 -0
  101. package/dist/js/node/config/initial/inits.js +127 -0
  102. package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
  103. package/dist/js/node/defineConfig.js +20 -0
  104. package/dist/js/node/exports/server.js +0 -1
  105. package/dist/js/node/hooks.js +23 -30
  106. package/dist/js/node/index.js +35 -48
  107. package/dist/js/node/initialize/index.js +79 -0
  108. package/dist/js/node/locale/index.js +0 -4
  109. package/dist/js/node/schema/Schema.js +46 -0
  110. package/dist/js/node/schema/index.js +152 -0
  111. package/dist/js/node/schema/legacy.js +291 -0
  112. package/dist/js/node/types/config/deploy.js +0 -0
  113. package/dist/js/node/types/config/dev.js +0 -0
  114. package/dist/js/node/types/config/experiments.js +0 -0
  115. package/dist/js/node/types/config/html.js +0 -0
  116. package/dist/js/node/types/config/index.js +16 -0
  117. package/dist/js/node/types/config/output.js +0 -0
  118. package/dist/js/node/types/config/performance.js +0 -0
  119. package/dist/js/node/types/config/security.js +0 -0
  120. package/dist/js/node/types/config/source.js +0 -0
  121. package/dist/js/node/types/config/tools.js +0 -0
  122. package/dist/js/node/types/hooks.js +0 -0
  123. package/dist/js/node/types/index.js +38 -0
  124. package/dist/js/node/types/legacyConfig/deploy.js +0 -0
  125. package/dist/js/node/types/legacyConfig/dev.js +0 -0
  126. package/dist/js/node/types/legacyConfig/index.js +0 -0
  127. package/dist/js/node/types/legacyConfig/output.js +5 -0
  128. package/dist/js/node/types/legacyConfig/source.js +0 -0
  129. package/dist/js/node/types/legacyConfig/tools.js +0 -0
  130. package/dist/js/node/utils/commands.js +0 -2
  131. package/dist/js/node/utils/config.js +2 -26
  132. package/dist/js/node/utils/createFileWatcher.js +90 -0
  133. package/dist/js/node/utils/createServer.js +0 -15
  134. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  135. package/dist/js/node/utils/language.js +0 -2
  136. package/dist/js/node/utils/printInstructions.js +2 -5
  137. package/dist/js/node/utils/restart.js +23 -0
  138. package/dist/js/node/utils/routes.js +0 -5
  139. package/dist/js/treeshaking/analyze/generateCode.js +58 -101
  140. package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
  141. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
  142. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
  143. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
  144. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
  145. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
  146. package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
  147. package/dist/js/treeshaking/analyze/index.js +195 -91
  148. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
  149. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
  150. package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
  151. package/dist/js/treeshaking/analyze/templates.js +31 -50
  152. package/dist/js/treeshaking/analyze/utils.js +7 -14
  153. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
  154. package/dist/js/treeshaking/builder/index.js +69 -65
  155. package/dist/js/treeshaking/builder/share.js +1 -5
  156. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
  157. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
  158. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  159. package/dist/js/treeshaking/commands/build.js +41 -116
  160. package/dist/js/treeshaking/commands/deploy.js +0 -3
  161. package/dist/js/treeshaking/commands/dev.js +38 -46
  162. package/dist/js/treeshaking/commands/inspect.js +9 -27
  163. package/dist/js/treeshaking/commands/start.js +1 -9
  164. package/dist/js/treeshaking/config/default.js +200 -0
  165. package/dist/js/treeshaking/config/index.js +2 -0
  166. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
  167. package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
  168. package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
  169. package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
  170. package/dist/js/treeshaking/config/initial/index.js +11 -0
  171. package/dist/js/treeshaking/config/initial/inits.js +114 -0
  172. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
  173. package/dist/js/treeshaking/defineConfig.js +14 -0
  174. package/dist/js/treeshaking/hooks.js +23 -19
  175. package/dist/js/treeshaking/index.js +8 -43
  176. package/dist/js/treeshaking/initialize/index.js +121 -0
  177. package/dist/js/treeshaking/schema/Schema.js +75 -0
  178. package/dist/js/treeshaking/schema/index.js +138 -0
  179. package/dist/js/treeshaking/schema/legacy.js +273 -0
  180. package/dist/js/treeshaking/types/config/deploy.js +0 -0
  181. package/dist/js/treeshaking/types/config/dev.js +0 -0
  182. package/dist/js/treeshaking/types/config/experiments.js +0 -0
  183. package/dist/js/treeshaking/types/config/html.js +0 -0
  184. package/dist/js/treeshaking/types/config/index.js +2 -0
  185. package/dist/js/treeshaking/types/config/output.js +0 -0
  186. package/dist/js/treeshaking/types/config/performance.js +0 -0
  187. package/dist/js/treeshaking/types/config/security.js +0 -0
  188. package/dist/js/treeshaking/types/config/source.js +0 -0
  189. package/dist/js/treeshaking/types/config/tools.js +0 -0
  190. package/dist/js/treeshaking/types/hooks.js +0 -0
  191. package/dist/js/treeshaking/types/index.js +4 -0
  192. package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
  193. package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
  194. package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
  195. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  196. package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
  197. package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
  198. package/dist/js/treeshaking/utils/config.js +2 -18
  199. package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
  200. package/dist/js/treeshaking/utils/createServer.js +0 -10
  201. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
  202. package/dist/js/treeshaking/utils/printInstructions.js +0 -5
  203. package/dist/js/treeshaking/utils/restart.js +45 -0
  204. package/dist/js/treeshaking/utils/routes.js +0 -4
  205. package/dist/types/analyze/generateCode.d.ts +3 -2
  206. package/dist/types/analyze/getBundleEntry.d.ts +2 -2
  207. package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
  208. package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
  209. package/dist/types/analyze/getServerRoutes.d.ts +3 -2
  210. package/dist/types/analyze/index.d.ts +3 -42
  211. package/dist/types/analyze/nestedRoutes.d.ts +1 -1
  212. package/dist/types/analyze/templates.d.ts +4 -2
  213. package/dist/types/analyze/utils.d.ts +1 -1
  214. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
  215. package/dist/types/builder/index.d.ts +7 -8
  216. package/dist/types/builder/share.d.ts +2 -2
  217. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  218. package/dist/types/commands/build.d.ts +2 -2
  219. package/dist/types/commands/deploy.d.ts +2 -2
  220. package/dist/types/commands/dev.d.ts +2 -2
  221. package/dist/types/commands/inspect.d.ts +6 -1
  222. package/dist/types/commands/start.d.ts +2 -2
  223. package/dist/types/config/default.d.ts +3 -0
  224. package/dist/types/config/index.d.ts +2 -0
  225. package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
  226. package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
  227. package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
  228. package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
  229. package/dist/types/config/initial/index.d.ts +4 -0
  230. package/dist/types/config/initial/inits.d.ts +4 -0
  231. package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
  232. package/dist/types/defineConfig.d.ts +7 -0
  233. package/dist/types/hooks.d.ts +2 -42
  234. package/dist/types/index.d.ts +5 -7
  235. package/dist/types/initialize/index.d.ts +3 -0
  236. package/dist/types/schema/Schema.d.ts +14 -0
  237. package/dist/types/schema/index.d.ts +4 -0
  238. package/dist/types/schema/legacy.d.ts +3 -0
  239. package/dist/types/types/config/deploy.d.ts +9 -0
  240. package/dist/types/types/config/dev.d.ts +13 -0
  241. package/dist/types/types/config/experiments.d.ts +4 -0
  242. package/dist/types/types/config/html.d.ts +4 -0
  243. package/dist/types/types/config/index.d.ts +62 -0
  244. package/dist/types/types/config/output.d.ts +23 -0
  245. package/dist/types/types/config/performance.d.ts +4 -0
  246. package/dist/types/types/config/security.d.ts +4 -0
  247. package/dist/types/types/config/source.d.ts +22 -0
  248. package/dist/types/types/config/tools.d.ts +15 -0
  249. package/dist/types/types/hooks.d.ts +80 -0
  250. package/dist/types/types/index.d.ts +23 -0
  251. package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
  252. package/dist/types/types/legacyConfig/dev.d.ts +12 -0
  253. package/dist/types/types/legacyConfig/index.d.ts +33 -0
  254. package/dist/types/types/legacyConfig/output.d.ts +51 -0
  255. package/dist/types/types/legacyConfig/source.d.ts +25 -0
  256. package/dist/types/types/legacyConfig/tools.d.ts +16 -0
  257. package/dist/types/utils/config.d.ts +2 -3
  258. package/dist/types/utils/createFileWatcher.d.ts +3 -0
  259. package/dist/types/utils/printInstructions.d.ts +3 -3
  260. package/dist/types/utils/restart.d.ts +3 -0
  261. package/package.json +26 -25
  262. package/dist/js/modern/builder/createHtmlConfig.js +0 -58
  263. package/dist/js/modern/builder/createSourceConfig.js +0 -85
  264. package/dist/js/modern/builder/createToolsConfig.js +0 -94
  265. package/dist/js/modern/utils/createCompiler.js +0 -58
  266. package/dist/js/node/builder/createHtmlConfig.js +0 -76
  267. package/dist/js/node/builder/createSourceConfig.js +0 -99
  268. package/dist/js/node/builder/createToolsConfig.js +0 -103
  269. package/dist/js/node/utils/createCompiler.js +0 -75
  270. package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
  271. package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
  272. package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
  273. package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
  274. package/dist/js/treeshaking/utils/createCompiler.js +0 -117
  275. package/dist/types/builder/createHtmlConfig.d.ts +0 -6
  276. package/dist/types/builder/createOutputConfig.d.ts +0 -3
  277. package/dist/types/builder/createSourceConfig.d.ts +0 -5
  278. package/dist/types/builder/createToolsConfig.d.ts +0 -13
  279. package/dist/types/utils/createCompiler.d.ts +0 -12
@@ -0,0 +1,117 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ import path, { dirname, isAbsolute, posix, sep } from 'path';
5
+ import { applyOptionsChain, findExists, findMonorepoRoot, globby, isModernjsMonorepo } from '@modern-js/utils';
6
+ export function initHtmlConfig(config, appContext) {
7
+ const ICON_EXTENSIONS = ['png', 'jpg', 'jpeg', 'svg', 'ico'];
8
+ config.html.appIcon = createBuilderAppIcon(config, appContext);
9
+ config.html.favicon = createBuilderFavicon(config, appContext);
10
+ return config.html;
11
+ function createBuilderAppIcon(config, appContext) {
12
+ const {
13
+ configDir
14
+ } = config.source;
15
+ const appIcon = findExists(ICON_EXTENSIONS.map(ext => path.resolve(appContext.appDirectory, configDir || './config', `icon.${ext}`)));
16
+ return typeof appIcon === 'string' ? appIcon : undefined;
17
+ }
18
+ function createBuilderFavicon(config, appContext) {
19
+ const {
20
+ configDir
21
+ } = config.source;
22
+ const {
23
+ favicon
24
+ } = config.html;
25
+ const defaultFavicon = findExists(ICON_EXTENSIONS.map(ext => path.resolve(appContext.appDirectory, configDir || './config', `favicon.${ext}`)));
26
+ return favicon || defaultFavicon || undefined;
27
+ }
28
+ }
29
+ export function initSourceConfig(config, appContext) {
30
+ config.source.include = createBuilderInclude(config, appContext);
31
+ config.source.moduleScopes = createBuilderModuleScope(config);
32
+ function createBuilderInclude(config, appContext) {
33
+ const {
34
+ include
35
+ } = config.source;
36
+ const defaultInclude = [appContext.internalDirectory];
37
+ const transformInclude = (include || []).map(include => {
38
+ if (typeof include === 'string') {
39
+ if (isAbsolute(include)) {
40
+ return include;
41
+ }
42
+ return new RegExp(include);
43
+ }
44
+ return include;
45
+ }).concat(defaultInclude); // concat default Include
46
+
47
+ const root = findMonorepoRoot(appContext.appDirectory);
48
+ if (!root) {
49
+ return transformInclude;
50
+ }
51
+ const modernjsMonorepo = isModernjsMonorepo(root);
52
+ if (modernjsMonorepo) {
53
+ const paths = globby.sync(posix.join(root, 'features', '**', 'package.json'), {
54
+ ignore: ['**/node_modules/**/*']
55
+ }).map(pathname => dirname(pathname) + sep);
56
+ return [...paths, ...transformInclude];
57
+ }
58
+ return transformInclude;
59
+ }
60
+ function createBuilderModuleScope(config) {
61
+ const {
62
+ moduleScopes
63
+ } = config.source;
64
+ if (moduleScopes) {
65
+ let builderModuleScope = [];
66
+ const DEFAULT_SCOPES = ['./src', './shared', /node_modules/];
67
+ if (Array.isArray(moduleScopes)) {
68
+ if (isPrimitiveScope(moduleScopes)) {
69
+ builderModuleScope = DEFAULT_SCOPES.concat(moduleScopes);
70
+ } else {
71
+ builderModuleScope = [DEFAULT_SCOPES, ...moduleScopes];
72
+ }
73
+ } else {
74
+ builderModuleScope = [DEFAULT_SCOPES, moduleScopes];
75
+ }
76
+ return builderModuleScope;
77
+ } else {
78
+ return undefined;
79
+ }
80
+ function isPrimitiveScope(items) {
81
+ return items.every(item => typeof item === 'string' || Object.prototype.toString.call(item) === '[object RegExp]');
82
+ }
83
+ }
84
+ }
85
+ export function initToolsConfig(config) {
86
+ const defaultTsChecker = {
87
+ issue: {
88
+ include: [{
89
+ file: '**/src/**/*'
90
+ }],
91
+ exclude: [{
92
+ file: '**/*.(spec|test).ts'
93
+ }, {
94
+ file: '**/node_modules/**/*'
95
+ }]
96
+ }
97
+ };
98
+ const {
99
+ tsChecker,
100
+ tsLoader,
101
+ htmlPlugin
102
+ } = config.tools;
103
+ config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
104
+ tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
105
+ applyOptionsChain(_objectSpread(_objectSpread({}, tsLoaderConfig), {}, {
106
+ transpileOnly: false,
107
+ allowTsInNodeModules: true
108
+ }), tsLoader || {}, utils);
109
+ });
110
+ config.tools.htmlPlugin = [config => _objectSpread(_objectSpread({}, config), {}, {
111
+ minify: typeof config.minify === 'object' ? _objectSpread(_objectSpread({}, config.minify), {}, {
112
+ removeComments: false
113
+ }) : config.minify
114
+ }),
115
+ // eslint-disable-next-line no-nested-ternary
116
+ ...(Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : [])];
117
+ }
@@ -0,0 +1,40 @@
1
+ import { createToolsConfig } from "./createToolsConfig";
2
+ import { createSourceConfig } from "./createSourceConfig";
3
+ import { createOutputConfig } from "./createOutputConfig";
4
+ import { createHtmlConfig } from "./createHtmlConfig";
5
+ export function transformNormalizedConfig(config) {
6
+ const html = createHtmlConfig(config);
7
+ const output = createOutputConfig(config);
8
+ const source = createSourceConfig(config);
9
+ const tools = createToolsConfig(config);
10
+ const {
11
+ bff,
12
+ dev,
13
+ deploy,
14
+ runtime,
15
+ runtimeByEntries,
16
+ server,
17
+ cliOptions,
18
+ plugins,
19
+ testing
20
+ } = config;
21
+ return {
22
+ source,
23
+ html,
24
+ output,
25
+ tools,
26
+ bff,
27
+ dev,
28
+ deploy,
29
+ runtime,
30
+ runtimeByEntries,
31
+ server,
32
+ cliOptions,
33
+ testing,
34
+ plugins: plugins,
35
+ security: {},
36
+ _raw: {},
37
+ experiments: {},
38
+ performance: {}
39
+ };
40
+ }
@@ -0,0 +1,12 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ export const defineConfig = config => config;
5
+
6
+ /**
7
+ * @deprecated
8
+ * Using defineConfig first.
9
+ */
10
+ export const defineLegacyConfig = config => _objectSpread(_objectSpread({}, config), {}, {
11
+ legacy: true
12
+ });
@@ -1,21 +1,25 @@
1
- import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
2
- export const beforeDev = createAsyncWorkflow();
3
- export const afterDev = createAsyncWorkflow();
4
- export const beforeCreateCompiler = createAsyncWorkflow();
5
- export const afterCreateCompiler = createAsyncWorkflow();
6
- export const beforePrintInstructions = createAsyncWaterfall();
7
- export const beforeBuild = createAsyncWorkflow();
8
- export const afterBuild = createAsyncWorkflow();
9
- export const beforeDeploy = createAsyncWorkflow();
10
- export const afterDeploy = createAsyncWorkflow();
1
+ import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from '@modern-js/plugin';
11
2
  export const hooks = {
12
- beforeDev,
13
- afterDev,
14
- beforeCreateCompiler,
15
- afterCreateCompiler,
16
- beforePrintInstructions,
17
- beforeBuild,
18
- afterBuild,
19
- beforeDeploy,
20
- afterDeploy
3
+ modifyEntryExport: createAsyncWaterfall(),
4
+ modifyEntryImports: createAsyncWaterfall(),
5
+ modifyEntryRuntimePlugins: createAsyncWaterfall(),
6
+ modifyEntryRenderFunction: createAsyncWaterfall(),
7
+ modifyAsyncEntry: createAsyncWaterfall(),
8
+ modifyFileSystemRoutes: createAsyncWaterfall(),
9
+ modifyServerRoutes: createAsyncWaterfall(),
10
+ htmlPartials: createAsyncWaterfall(),
11
+ beforeGenerateRoutes: createAsyncWaterfall(),
12
+ addDefineTypes: createAsyncWaterfall(),
13
+ beforeDev: createAsyncWorkflow(),
14
+ afterDev: createAsyncWorkflow(),
15
+ beforeCreateCompiler: createAsyncWorkflow(),
16
+ afterCreateCompiler: createAsyncWorkflow(),
17
+ beforePrintInstructions: createAsyncWaterfall(),
18
+ beforeBuild: createAsyncWorkflow(),
19
+ afterBuild: createAsyncWorkflow(),
20
+ beforeDeploy: createAsyncWorkflow(),
21
+ afterDeploy: createAsyncWorkflow(),
22
+ watchFiles: createParallelWorkflow(),
23
+ fileChange: createAsyncWorkflow(),
24
+ beforeRestart: createAsyncWorkflow()
21
25
  };
@@ -1,25 +1,24 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
4
  import path from 'path';
8
- import { defineConfig, cli } from '@modern-js/core';
9
- import LintPlugin from '@modern-js/plugin-jarvis';
5
+ import LintPlugin from '@modern-js/plugin-lint';
10
6
  import { cleanRequireCache, emptyDir, Import } from '@modern-js/utils';
11
7
  import AnalyzePlugin from "./analyze";
8
+ import InitializePlugin from "./initialize";
12
9
  import { hooks } from "./hooks";
13
10
  import { i18n, localeKeys } from "./locale";
14
11
  import { getLocaleLanguage } from "./utils/language";
15
12
  import { getCommand } from "./utils/commands";
16
- export { defineConfig, hooks };
13
+ import { restart } from "./utils/restart";
14
+ export * from "./defineConfig";
15
+ export * from "./types";
17
16
  const upgradeModel = Import.lazy('@modern-js/upgrade', require);
18
17
  export default (() => ({
19
18
  name: '@modern-js/app-tools',
20
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-router-legacy', '@modern-js/plugin-polyfill'],
19
+ post: ['@modern-js/plugin-initialize', '@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-document', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-router-legacy', '@modern-js/plugin-polyfill'],
21
20
  registerHook: hooks,
22
- usePlugins: [AnalyzePlugin(), LintPlugin()],
21
+ usePlugins: [InitializePlugin(), AnalyzePlugin(), LintPlugin()],
23
22
  setup: api => {
24
23
  const locale = getLocaleLanguage();
25
24
  i18n.changeLanguage({
@@ -39,9 +38,9 @@ export default (() => ({
39
38
  const {
40
39
  build
41
40
  } = await import("./commands/build");
42
- await build(api, options); // force exit after build.
41
+ await build(api, options);
42
+ // force exit after build.
43
43
  // eslint-disable-next-line no-process-exit
44
-
45
44
  process.exit(0);
46
45
  });
47
46
  program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).action(async () => {
@@ -58,8 +57,8 @@ export default (() => ({
58
57
  const {
59
58
  deploy
60
59
  } = await import("./commands/deploy");
61
- await deploy(api, options); // eslint-disable-next-line no-process-exit
62
-
60
+ await deploy(api, options);
61
+ // eslint-disable-next-line no-process-exit
63
62
  process.exit(0);
64
63
  });
65
64
  program.command('new').usage('[options]').description(i18n.t(localeKeys.command.new.describe)).option('-d, --debug', i18n.t(localeKeys.command.new.debug), false).option('-c, --config <config>', i18n.t(localeKeys.command.new.config)).option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag)).option('--registry', i18n.t(localeKeys.command.new.registry)).action(async options => {
@@ -78,16 +77,13 @@ export default (() => ({
78
77
  });
79
78
  upgradeModel.defineCommand(program.command('upgrade'));
80
79
  },
81
-
82
80
  async prepare() {
83
81
  const command = getCommand();
84
-
85
82
  if (command === 'dev' || command === 'build') {
86
83
  const appContext = api.useAppContext();
87
84
  await emptyDir(appContext.distDirectory);
88
85
  }
89
86
  },
90
-
91
87
  // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
92
88
  async fileChange(e) {
93
89
  const {
@@ -100,20 +96,17 @@ export default (() => ({
100
96
  srcDirectory
101
97
  } = appContext;
102
98
  const absolutePath = path.resolve(appDirectory, filename);
103
-
104
99
  if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
105
100
  const {
106
101
  closeServer
107
102
  } = await import("./utils/createServer");
108
103
  await closeServer();
109
- await cli.restart();
104
+ await restart(api.useHookRunners());
110
105
  }
111
106
  },
112
-
113
107
  async beforeRestart() {
114
108
  cleanRequireCache([require.resolve("./analyze")]);
115
109
  }
116
-
117
110
  };
118
111
  }
119
112
  }));
@@ -0,0 +1,72 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ import { ensureAbsolutePath, getPort, isDev } from '@modern-js/utils';
5
+ import { legacySchema, schema } from "../schema";
6
+ import { getCommand } from "../utils/commands";
7
+ import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
8
+ import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig } from "../config";
9
+ export default (() => ({
10
+ name: '@modern-js/plugin-initialize',
11
+ setup(api) {
12
+ const config = () => {
13
+ const appContext = api.useAppContext();
14
+ const userConfig = api.useConfigContext();
15
+ return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
16
+ };
17
+ const validateSchema = () => {
18
+ const userConfig = api.useConfigContext();
19
+ const schemas = checkIsLegacyConfig(userConfig) ? legacySchema : schema;
20
+ return schemas.generate();
21
+ };
22
+ return {
23
+ config,
24
+ validateSchema,
25
+ async resolvedConfig({
26
+ resolved
27
+ }) {
28
+ var _resolved$output$dist, _normalizedConfig$ser;
29
+ let appContext = api.useAppContext();
30
+ const userConfig = api.useConfigContext();
31
+ const port = await getDevServerPort(appContext, resolved);
32
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
33
+ port,
34
+ distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved$output$dist = resolved.output.distPath) === null || _resolved$output$dist === void 0 ? void 0 : _resolved$output$dist.root) || 'dist')
35
+ });
36
+ api.setAppContext(appContext);
37
+ const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
38
+ return {
39
+ resolved: {
40
+ // FIXME: the userConfig mayby legacy userConfig
41
+ _raw: userConfig,
42
+ source: normalizedConfig.source || {},
43
+ server: _objectSpread(_objectSpread({}, normalizedConfig.server || {}), {}, {
44
+ port: port || ((_normalizedConfig$ser = normalizedConfig.server) === null || _normalizedConfig$ser === void 0 ? void 0 : _normalizedConfig$ser.port)
45
+ }),
46
+ bff: normalizedConfig.bff || {},
47
+ dev: normalizedConfig.dev || {},
48
+ html: normalizedConfig.html || {},
49
+ output: normalizedConfig.output || {},
50
+ security: normalizedConfig.security || {},
51
+ tools: normalizedConfig.tools || {},
52
+ testing: normalizedConfig.testing || {},
53
+ plugins: normalizedConfig.plugins || [],
54
+ runtime: normalizedConfig.runtime || {},
55
+ runtimeByEntries: normalizedConfig.runtimeByEntries || {},
56
+ deploy: normalizedConfig.deploy || {},
57
+ performance: normalizedConfig.performance || {},
58
+ experiments: normalizedConfig.experiments || {}
59
+ }
60
+ };
61
+ }
62
+ };
63
+ }
64
+ }));
65
+ async function getDevServerPort(appContext, resolved) {
66
+ const command = getCommand();
67
+ if (isDev() && command === 'dev') {
68
+ var _appContext$port;
69
+ return ((_appContext$port = appContext.port) !== null && _appContext$port !== void 0 ? _appContext$port : 0) > 0 ? appContext.port : await getPort(resolved.server.port || 8080);
70
+ }
71
+ return resolved.server.port;
72
+ }
@@ -0,0 +1,39 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ import { merge } from '@modern-js/utils/lodash';
3
+ export class Schema extends Map {
4
+ constructor(baseSchema = {}) {
5
+ super();
6
+ _defineProperty(this, "schema", void 0);
7
+ this.schema = baseSchema;
8
+ }
9
+ setSchema(key, object) {
10
+ Object.entries(object).forEach(([k, v]) => {
11
+ const target = `${key}.${k}`;
12
+ this.set(target, v);
13
+ });
14
+ return this;
15
+ }
16
+ set(key, value) {
17
+ if (this.has(key)) {
18
+ merge(this.schema[key], value);
19
+ } else {
20
+ this.schema[key] = value;
21
+ }
22
+ return this;
23
+ }
24
+ has(key) {
25
+ return key in this.schema;
26
+ }
27
+ get(key) {
28
+ return this.schema[key];
29
+ }
30
+ delete(key) {
31
+ return delete this.schema[key];
32
+ }
33
+ generate() {
34
+ return Object.entries(this.schema).map(([target, schema]) => ({
35
+ target,
36
+ schema
37
+ }));
38
+ }
39
+ }
@@ -0,0 +1,139 @@
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: {
9
+ type: 'object'
10
+ },
11
+ then: {
12
+ required: ['entry'],
13
+ properties: {
14
+ entry: {
15
+ type: ['string', 'array']
16
+ },
17
+ disableMount: {
18
+ type: 'boolean'
19
+ },
20
+ enableFileSystemRoutes: {
21
+ type: 'boolean'
22
+ }
23
+ },
24
+ additionalProperties: false
25
+ },
26
+ else: {
27
+ type: ['string', 'array']
28
+ }
29
+ }
30
+ }
31
+ },
32
+ enableAsyncEntry: {
33
+ type: 'boolean'
34
+ },
35
+ disableDefaultEntries: {
36
+ type: 'boolean'
37
+ },
38
+ entriesDir: {
39
+ type: 'string'
40
+ },
41
+ configDir: {
42
+ type: 'string'
43
+ },
44
+ designSystem: {
45
+ type: 'object'
46
+ }
47
+ };
48
+ const bff = {
49
+ prefix: {
50
+ type: 'string'
51
+ },
52
+ proxy: {
53
+ type: 'object',
54
+ additionalProperties: {
55
+ type: 'string'
56
+ }
57
+ }
58
+ };
59
+ const output = {
60
+ ssg: {
61
+ typeof: ['boolean', 'object', 'function']
62
+ },
63
+ enableModernMode: {
64
+ type: 'boolean'
65
+ },
66
+ disableNodePolyfill: {
67
+ type: 'boolean'
68
+ }
69
+ };
70
+ const dev = {
71
+ proxy: {
72
+ type: ['boolean', 'object']
73
+ }
74
+ };
75
+ const server = {
76
+ routes: {
77
+ type: 'object'
78
+ },
79
+ publicRoutes: {
80
+ type: 'object'
81
+ },
82
+ ssr: {
83
+ type: ['boolean', 'object']
84
+ },
85
+ ssrByEntries: {
86
+ type: 'object'
87
+ },
88
+ baseUrl: {
89
+ anyOf: [{
90
+ type: 'string'
91
+ }, {
92
+ type: 'array',
93
+ items: {
94
+ type: 'string'
95
+ }
96
+ }]
97
+ },
98
+ port: {
99
+ type: 'number'
100
+ },
101
+ logger: {
102
+ type: ['boolean', 'object']
103
+ },
104
+ metrics: {
105
+ type: ['boolean', 'object']
106
+ },
107
+ enableMicroFrontendDebug: {
108
+ type: 'boolean'
109
+ },
110
+ watchOptions: {
111
+ type: 'object'
112
+ },
113
+ compiler: {
114
+ type: 'string'
115
+ },
116
+ disableFrameworkExt: {
117
+ type: 'boolean'
118
+ }
119
+ };
120
+ const tools = {
121
+ tailwindcss: {
122
+ type: 'object'
123
+ },
124
+ jest: {
125
+ typeof: ['object', 'function']
126
+ },
127
+ esbuild: {
128
+ typeof: ['object']
129
+ }
130
+ };
131
+ const deploy = {
132
+ microFrontend: {
133
+ type: ['boolean', 'object']
134
+ }
135
+ };
136
+ const schema = new Schema();
137
+ schema.setSchema('bff', bff).setSchema('dev', dev).setSchema('server', server).setSchema('source', source).setSchema('output', output).setSchema('tools', tools).setSchema('deploy', deploy);
138
+ export { default as legacySchema } from "./legacy";
139
+ export { schema };