@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
@@ -3,86 +3,41 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.modifyAsyncEntry = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
7
-
6
+ exports.default = void 0;
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
- var _plugin = require("@modern-js/plugin");
11
-
12
8
  var _utils = require("@modern-js/utils");
13
-
14
9
  var _lodash = require("@modern-js/utils/lodash");
15
-
10
+ var _builder = require("../builder");
11
+ var _printInstructions = require("../utils/printInstructions");
12
+ var _routes = require("../utils/routes");
13
+ var _config = require("../utils/config");
14
+ var _commands = require("../utils/commands");
15
+ var _config2 = require("../config");
16
16
  var _utils2 = require("./utils");
17
-
18
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
19
  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; }
23
-
24
20
  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; }
25
-
26
21
  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; }
27
-
28
22
  const debug = (0, _utils.createDebugger)('plugin-analyze');
29
- const modifyEntryImports = (0, _plugin.createAsyncWaterfall)();
30
- exports.modifyEntryImports = modifyEntryImports;
31
- const modifyEntryExport = (0, _plugin.createAsyncWaterfall)();
32
- exports.modifyEntryExport = modifyEntryExport;
33
- const addRuntimeExports = (0, _plugin.createAsyncWaterfall)();
34
- exports.addRuntimeExports = addRuntimeExports;
35
- const modifyEntryRuntimePlugins = (0, _plugin.createAsyncWaterfall)();
36
- exports.modifyEntryRuntimePlugins = modifyEntryRuntimePlugins;
37
- const modifyEntryRenderFunction = (0, _plugin.createAsyncWaterfall)();
38
- exports.modifyEntryRenderFunction = modifyEntryRenderFunction;
39
- const modifyAsyncEntry = (0, _plugin.createAsyncWaterfall)();
40
- exports.modifyAsyncEntry = modifyAsyncEntry;
41
- const modifyFileSystemRoutes = (0, _plugin.createAsyncWaterfall)();
42
- exports.modifyFileSystemRoutes = modifyFileSystemRoutes;
43
- const modifyServerRoutes = (0, _plugin.createAsyncWaterfall)();
44
- exports.modifyServerRoutes = modifyServerRoutes;
45
- const htmlPartials = (0, _plugin.createAsyncWaterfall)();
46
- exports.htmlPartials = htmlPartials;
47
- const beforeGenerateRoutes = (0, _plugin.createAsyncWaterfall)();
48
- exports.beforeGenerateRoutes = beforeGenerateRoutes;
49
- const addDefineTypes = (0, _plugin.createAsyncWaterfall)();
50
- exports.addDefineTypes = addDefineTypes;
51
-
52
23
  var _default = () => ({
53
24
  name: '@modern-js/plugin-analyze',
54
- registerHook: {
55
- modifyAsyncEntry,
56
- modifyEntryImports,
57
- modifyEntryExport,
58
- modifyEntryRuntimePlugins,
59
- modifyEntryRenderFunction,
60
- modifyFileSystemRoutes,
61
- modifyServerRoutes,
62
- htmlPartials,
63
- addRuntimeExports,
64
- beforeGenerateRoutes,
65
- addDefineTypes
66
- },
67
25
  setup: api => {
68
26
  let pagesDir = [];
69
27
  let originEntrypoints = [];
70
28
  return {
71
29
  async prepare() {
72
30
  var _resolvedConfig$sourc;
73
-
74
- const appContext = api.useAppContext();
31
+ let appContext = api.useAppContext();
75
32
  const resolvedConfig = api.useResolvedConfigContext();
76
33
  const hookRunners = api.useHookRunners();
77
-
78
34
  try {
79
35
  _utils.fs.emptydirSync(appContext.internalDirectory);
80
- } catch (_unused) {// FIXME:
36
+ } catch (_unused) {
37
+ // FIXME:
81
38
  }
82
-
83
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
39
+ const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
84
40
  await hookRunners.addRuntimeExports();
85
-
86
41
  if (apiOnly) {
87
42
  const {
88
43
  routes
@@ -90,13 +45,13 @@ var _default = () => ({
90
45
  routes: []
91
46
  });
92
47
  debug(`server routes: %o`, routes);
93
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
48
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
94
49
  apiOnly,
95
50
  serverRoutes: routes
96
- }));
51
+ });
52
+ api.setAppContext(appContext);
97
53
  return;
98
54
  }
99
-
100
55
  const [{
101
56
  getBundleEntry
102
57
  }, {
@@ -119,10 +74,11 @@ var _default = () => ({
119
74
  routes: initialRoutes
120
75
  });
121
76
  debug(`server routes: %o`, routes);
122
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
77
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
123
78
  entrypoints,
124
79
  serverRoutes: routes
125
- }));
80
+ });
81
+ api.setAppContext(appContext);
126
82
  const nestedRouteEntries = entrypoints.map(point => point.nestedRoutesEntry).filter(Boolean);
127
83
  pagesDir = entrypoints.map(point => point.entry).filter(Boolean).concat(nestedRouteEntries);
128
84
  originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
@@ -134,19 +90,89 @@ var _default = () => ({
134
90
  debug(`html templates: %o`, htmlTemplates);
135
91
  await hookRunners.addDefineTypes();
136
92
  debug(`add Define Types`);
137
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
93
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
138
94
  entrypoints,
139
95
  checkedEntries: defaultChecked,
140
96
  apiOnly,
141
97
  serverRoutes: routes,
142
98
  htmlTemplates
143
- }));
99
+ });
100
+ api.setAppContext(appContext);
101
+ const command = (0, _commands.getCommand)();
102
+ const buildCommands = ['dev', 'build', 'inspect', 'deploy'];
103
+ if (buildCommands.includes(command)) {
104
+ const normalizedConfig = api.useResolvedConfigContext();
105
+ const builder = await (0, _builder.createBuilderForEdenX)({
106
+ normalizedConfig: normalizedConfig,
107
+ appContext,
108
+ compatPluginConfig: {
109
+ async onBeforeBuild({
110
+ bundlerConfigs
111
+ }) {
112
+ const hookRunners = api.useHookRunners();
113
+ await (0, _routes.generateRoutes)(appContext);
114
+ await hookRunners.beforeBuild({
115
+ bundlerConfigs
116
+ });
117
+ },
118
+ async onAfterBuild({
119
+ stats
120
+ }) {
121
+ const hookRunners = api.useHookRunners();
122
+ await hookRunners.afterBuild({
123
+ stats
124
+ });
125
+ await (0, _config.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
126
+ },
127
+ async onDevCompileDone({
128
+ isFirstCompile
129
+ }) {
130
+ const hookRunners = api.useHookRunners();
131
+ if (process.stdout.isTTY || isFirstCompile) {
132
+ hookRunners.afterDev();
133
+ if (isFirstCompile) {
134
+ (0, _printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
135
+ }
136
+ }
137
+ },
138
+ async onBeforeCreateCompiler({
139
+ bundlerConfigs
140
+ }) {
141
+ const hookRunners = api.useHookRunners();
142
+ // run modernjs framework `beforeCreateCompiler` hook
143
+ await hookRunners.beforeCreateCompiler({
144
+ bundlerConfigs
145
+ });
146
+ },
147
+ async onAfterCreateCompiler({
148
+ compiler
149
+ }) {
150
+ const hookRunners = api.useHookRunners();
151
+ // run modernjs framework afterCreateCompiler hooks
152
+ await hookRunners.afterCreateCompiler({
153
+ compiler
154
+ });
155
+ }
156
+ }
157
+ });
158
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
159
+ builder
160
+ });
161
+ api.setAppContext(appContext);
162
+ }
144
163
  },
145
-
146
164
  watchFiles() {
147
165
  return pagesDir;
148
166
  },
149
-
167
+ resolvedConfig({
168
+ resolved
169
+ }) {
170
+ const appContext = api.useAppContext();
171
+ const config = (0, _config2.initialNormalizedConfig)(resolved, appContext);
172
+ return {
173
+ resolved: config
174
+ };
175
+ },
150
176
  async fileChange(e) {
151
177
  const appContext = api.useAppContext();
152
178
  const {
@@ -156,12 +182,9 @@ var _default = () => ({
156
182
  filename,
157
183
  eventType
158
184
  } = e;
159
-
160
185
  const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
161
-
162
186
  const absoluteFilePath = path.resolve(appDirectory, filename);
163
187
  const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils2.isRouteComponentFile)(absoluteFilePath);
164
-
165
188
  if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
166
189
  const resolvedConfig = api.useResolvedConfigContext();
167
190
  const {
@@ -171,9 +194,7 @@ var _default = () => ({
171
194
  generateCode(appContext, resolvedConfig, entrypoints, api);
172
195
  }
173
196
  }
174
-
175
197
  };
176
198
  }
177
199
  });
178
-
179
200
  exports.default = _default;
@@ -4,28 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isDefaultExportFunction = void 0;
7
-
8
7
  var _fs = _interopRequireDefault(require("fs"));
9
-
10
8
  var _parser = require("@babel/parser");
11
-
12
9
  var _traverse = _interopRequireDefault(require("@babel/traverse"));
13
-
14
10
  var t = _interopRequireWildcard(require("@babel/types"));
15
-
16
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
23
-
24
15
  const isDefaultExportFunction = file => {
25
16
  if (!file || !_fs.default.existsSync(file)) {
26
17
  return false;
27
18
  }
28
-
29
19
  const ast = (0, _parser.parse)(_fs.default.readFileSync(file, 'utf8'), {
30
20
  sourceType: 'unambiguous',
31
21
  plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
@@ -38,7 +28,6 @@ const isDefaultExportFunction = file => {
38
28
  const {
39
29
  declaration
40
30
  } = path.node;
41
-
42
31
  if (isFunction(declaration)) {
43
32
  isExportFunction = true;
44
33
  }
@@ -46,5 +35,4 @@ const isDefaultExportFunction = file => {
46
35
  });
47
36
  return isExportFunction;
48
37
  };
49
-
50
38
  exports.isDefaultExportFunction = isDefaultExportFunction;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.makeLegalIdentifier = makeLegalIdentifier;
7
-
8
7
  /**
9
8
  * modified from https://github.com/rollup/plugins/blob/master/packages/pluginutils
10
9
  * license at https://github.com/rollup/plugins/blob/master/LICENSE
@@ -12,13 +11,10 @@ exports.makeLegalIdentifier = makeLegalIdentifier;
12
11
  const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
13
12
  const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
14
13
  const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
15
-
16
14
  function makeLegalIdentifier(str) {
17
15
  const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
18
-
19
16
  if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
20
17
  return `_${identifier}`;
21
18
  }
22
-
23
19
  return identifier || '_';
24
20
  }
@@ -4,62 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.walk = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _constants = require("./constants");
13
-
14
10
  var _utils2 = require("./utils");
15
-
16
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
13
  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; }
21
-
22
14
  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; }
23
-
24
15
  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; }
25
-
26
16
  const LAYOUT_FILE = 'layout';
27
17
  const PAGE_FILE = 'page';
28
18
  const LOADING_FILE = 'loading';
29
19
  const ERROR_FILE = 'error';
30
20
  const LOADER_FILE = 'loader';
31
21
  const conventionNames = [LAYOUT_FILE, PAGE_FILE, LOADING_FILE, ERROR_FILE, LOADER_FILE];
32
-
33
22
  const replaceDynamicPath = routePath => {
34
23
  return routePath.replace(/\[(.*?)\]/g, ':$1');
35
24
  };
36
-
37
- const createIndexRoute = (routeInfo, rootDir, filename) => {
25
+ const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
38
26
  return createRoute(_objectSpread(_objectSpread({}, routeInfo), {}, {
39
27
  index: true,
40
28
  children: undefined
41
- }), rootDir, filename);
29
+ }), rootDir, filename, entryName);
42
30
  };
43
-
44
- const createRoute = (routeInfo, rootDir, filename) => {
45
- const id = (0, _utils.getRouteId)(filename, rootDir);
31
+ const createRoute = (routeInfo, rootDir, filename, entryName) => {
32
+ const id = (0, _utils.getRouteId)(filename, rootDir, entryName);
46
33
  return _objectSpread(_objectSpread({}, routeInfo), {}, {
47
34
  id,
48
35
  type: 'nested'
49
36
  });
50
37
  };
51
-
52
- const walk = async (dirname, rootDir, alias) => {
38
+ const walk = async (dirname, rootDir, alias, entryName) => {
53
39
  if (!(await _utils.fs.pathExists(dirname))) {
54
40
  return null;
55
41
  }
56
-
57
42
  const isDirectory = (await _utils.fs.stat(dirname)).isDirectory();
58
-
59
43
  if (!isDirectory) {
60
44
  return null;
61
45
  }
62
-
63
46
  const relativeDir = path.relative(rootDir, dirname);
64
47
  const pathSegments = relativeDir.split(path.sep);
65
48
  const lastSegment = pathSegments[pathSegments.length - 1];
@@ -67,65 +50,52 @@ const walk = async (dirname, rootDir, alias) => {
67
50
  const isPathlessLayout = lastSegment.startsWith('__');
68
51
  const isWithoutLayoutPath = lastSegment.includes('.');
69
52
  let routePath = isRoot || isPathlessLayout ? '/' : `${lastSegment}`;
70
-
71
53
  if (isWithoutLayoutPath) {
72
54
  routePath = lastSegment.split('.').join('/');
73
55
  }
74
-
75
56
  routePath = replaceDynamicPath(routePath);
76
57
  const route = {
77
58
  path: routePath,
78
59
  children: []
79
60
  };
80
61
  const items = await _utils.fs.readdir(dirname);
81
-
82
62
  for (const item of items) {
83
63
  const itemPath = path.join(dirname, item);
84
64
  const extname = path.extname(item);
85
65
  const itemWithoutExt = item.slice(0, -extname.length);
86
66
  const isDirectory = (await _utils.fs.stat(itemPath)).isDirectory();
87
-
88
67
  if (isDirectory) {
89
- const childRoute = await walk(itemPath, rootDir, alias);
90
-
68
+ const childRoute = await walk(itemPath, rootDir, alias, entryName);
91
69
  if (childRoute) {
92
70
  var _route$children;
93
-
94
71
  (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.push(childRoute);
95
72
  }
96
73
  }
97
-
98
74
  if (extname && (!_constants.JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
99
75
  continue;
100
76
  }
101
-
102
77
  if (itemWithoutExt === LAYOUT_FILE) {
103
78
  route._component = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
104
79
  }
105
-
106
80
  if (itemWithoutExt === PAGE_FILE) {
107
81
  var _route$children2;
108
-
109
82
  const childRoute = createIndexRoute({
110
83
  _component: (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name)
111
- }, rootDir, itemPath);
84
+ }, rootDir, itemPath, entryName);
112
85
  (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.push(childRoute);
113
86
  }
114
-
115
87
  if (itemWithoutExt === LOADER_FILE) {
116
88
  route.loader = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
117
89
  }
118
-
119
90
  if (itemWithoutExt === LOADING_FILE) {
120
91
  route.loading = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
121
92
  }
122
-
123
93
  if (itemWithoutExt === ERROR_FILE) {
124
94
  route.error = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
125
95
  }
126
96
  }
97
+ const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`), entryName);
127
98
 
128
- const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`));
129
99
  /**
130
100
  * when the url is /, the __auth/layout.tsx component should not be rendered
131
101
  * - routes
@@ -133,12 +103,9 @@ const walk = async (dirname, rootDir, alias) => {
133
103
  * - layout.tsx
134
104
  * - layout.tsx
135
105
  */
136
-
137
106
  if (isPathlessLayout) {
138
107
  delete finalRoute.path;
139
108
  }
140
-
141
109
  return finalRoute;
142
110
  };
143
-
144
111
  exports.walk = walk;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.routesForServer = exports.renderFunction = exports.index = exports.html = exports.fileSystemRoutes = void 0;
7
-
8
7
  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; }
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
10
  const index = ({
15
11
  mountId,
16
12
  imports,
@@ -35,9 +31,7 @@ AppWrapper = render();
35
31
 
36
32
  ${exportStatement};
37
33
  `;
38
-
39
34
  exports.index = index;
40
-
41
35
  const renderFunction = ({
42
36
  plugins,
43
37
  customBootstrap,
@@ -59,9 +53,7 @@ const renderFunction = ({
59
53
 
60
54
  return AppWrapper
61
55
  `;
62
-
63
56
  exports.renderFunction = renderFunction;
64
-
65
57
  const html = partials => `
66
58
  <!DOCTYPE html>
67
59
  <html>
@@ -92,9 +84,7 @@ const html = partials => `
92
84
 
93
85
  </html>
94
86
  `;
95
-
96
87
  exports.html = html;
97
-
98
88
  const routesForServer = ({
99
89
  routes,
100
90
  alias
@@ -104,37 +94,28 @@ const routesForServer = ({
104
94
  basename
105
95
  } = alias;
106
96
  const loaders = [];
107
-
108
97
  const traverseRouteTree = route => {
109
98
  let children;
110
-
111
99
  if ('children' in route && route.children) {
112
100
  var _route$children;
113
-
114
101
  children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
115
102
  }
116
-
117
103
  let loader;
118
-
119
104
  if (route.type === 'nested') {
120
105
  if (route.loader) {
121
106
  loaders.push(route.loader);
122
107
  loader = `loader_${loaders.length - 1}`;
123
108
  }
124
109
  }
125
-
126
110
  const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
127
111
  loader,
128
112
  children
129
113
  });
130
-
131
114
  return finalRoute;
132
115
  };
133
-
134
116
  let routesCode = `
135
117
  export const routes = [
136
118
  `;
137
-
138
119
  for (const route of routes) {
139
120
  if ('type' in route) {
140
121
  const newRoute = traverseRouteTree(route);
@@ -143,7 +124,6 @@ const routesForServer = ({
143
124
  routesCode += `${JSON.stringify(route, null, 2)}`;
144
125
  }
145
126
  }
146
-
147
127
  routesCode += `\n];`;
148
128
  const importLoadersCode = loaders.map((loader, index) => {
149
129
  const realLoaderPath = loader.replace(name, basename);
@@ -154,93 +134,89 @@ const routesForServer = ({
154
134
  ${routesCode}
155
135
  `;
156
136
  };
157
-
158
137
  exports.routesForServer = routesForServer;
159
-
160
138
  const fileSystemRoutes = ({
161
139
  routes,
162
140
  ssrMode,
163
- nestedRoutesEntry
141
+ nestedRoutesEntry,
142
+ entryName
164
143
  }) => {
165
- const importLazyCode = ssrMode === 'stream' ? 'import { lazy } from "react";' : `import loadable from '@modern-js/runtime/loadable'`;
144
+ // The legacy mode and pages dir routes should use loadable
145
+ // nested routes + renderTostring should use loadable.lazy
146
+ // nested routes + renderToStream should use react.lazy
147
+ const importLazyCode = `
148
+ import { lazy } from "react";
149
+ import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
150
+ `;
166
151
  let dataLoaderPath = '';
167
-
168
152
  if (ssrMode) {
169
153
  dataLoaderPath = require.resolve(`@modern-js/plugin-data-loader/loader`);
170
-
171
154
  if (nestedRoutesEntry) {
172
- dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}!`;
155
+ dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&entryName=${entryName}!`;
173
156
  }
174
157
  }
175
-
176
158
  const loadings = [];
177
159
  const errors = [];
178
160
  const loaders = [];
179
-
180
161
  const traverseRouteTree = route => {
181
162
  let children;
182
-
183
163
  if ('children' in route && route.children) {
184
164
  var _route$children2;
185
-
186
165
  children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
187
166
  }
188
-
189
167
  let loading;
190
168
  let error;
191
169
  let loader;
192
-
170
+ let component = '';
193
171
  if (route.type === 'nested') {
194
172
  if (route.loading) {
195
173
  loadings.push(route.loading);
196
174
  loading = `loading_${loadings.length - 1}`;
197
175
  }
198
-
199
176
  if (route.error) {
200
177
  errors.push(route.error);
201
178
  error = `error_${errors.length - 1}`;
202
179
  }
203
-
204
180
  if (route.loader) {
205
181
  loaders.push(route.loader);
206
182
  loader = `loader_${loaders.length - 1}`;
207
183
  }
184
+ if (route._component) {
185
+ if (ssrMode === 'stream') {
186
+ component = `lazy(() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "lazy-once" */ '${route._component}'))`;
187
+ } else {
188
+ component = `loadable(() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "lazy-once" */ '${route._component}'))`;
189
+ }
190
+ }
191
+ } else if (route._component) {
192
+ component = `loadable(() => import('${route._component}'))`;
208
193
  }
209
-
210
194
  const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
211
195
  loading,
212
196
  loader,
213
197
  error,
214
198
  children
215
199
  });
216
-
217
200
  if (route._component) {
218
- const component = ssrMode === 'stream' ? `lazy(() => import('${route._component}'))` : `loadable(() => import('${route._component}'))`;
219
201
  finalRoute.component = component;
220
202
  }
221
-
222
203
  return finalRoute;
223
204
  };
224
-
225
205
  let routeComponentsCode = `
226
206
  export const routes = [
227
207
  `;
228
-
229
208
  for (const route of routes) {
230
209
  if ('type' in route) {
231
210
  const newRoute = traverseRouteTree(route);
232
- routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable[^"]*)"/g, '$1').replace(/"(lazy[^"]*)"/g, '$1').replace(/"(loading_[^"])"/g, '$1').replace(/"(loader_[^"])"/g, '$1').replace(/"(error_[^"])"/g, '$1')},`;
211
+ routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, '$1').replace(/"(loadableLazy.*\))"/g, '$1').replace(/"(lazy.*\))"/g, '$1').replace(/"(loading_[^"])"/g, '$1').replace(/"(loader_[^"])"/g, '$1').replace(/"(error_[^"])"/g, '$1').replace(/\\"/g, '"')},`;
233
212
  } else {
234
- const component = ssrMode === 'stream' ? `lazy(() => import('${route._component}'))` : `loadable(() => import('${route._component}'))`;
235
-
213
+ const component = `loadable(() => import('${route._component}'))`;
236
214
  const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
237
215
  component
238
216
  });
239
-
240
217
  routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, '$1').replace(/"(lazy[^"]*)"/g, '$1')},`;
241
218
  }
242
219
  }
243
-
244
220
  routeComponentsCode += `\n];`;
245
221
  const importLoadingCode = loadings.map((loading, index) => {
246
222
  return `import loading_${index} from '${loading}';\n`;
@@ -259,5 +235,4 @@ const fileSystemRoutes = ({
259
235
  ${routeComponentsCode}
260
236
  `;
261
237
  };
262
-
263
238
  exports.fileSystemRoutes = fileSystemRoutes;