@modern-js/app-tools 2.14.0 → 2.16.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 (269) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/cjs/analyze/constants.js +37 -61
  3. package/dist/cjs/analyze/generateCode.js +102 -127
  4. package/dist/cjs/analyze/getBundleEntry.js +33 -66
  5. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +61 -117
  6. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +61 -115
  7. package/dist/cjs/analyze/getClientRoutes/index.js +15 -28
  8. package/dist/cjs/analyze/getClientRoutes/utils.js +24 -48
  9. package/dist/cjs/analyze/getFileSystemEntry.js +39 -79
  10. package/dist/cjs/analyze/getHtmlTemplate.js +88 -98
  11. package/dist/cjs/analyze/getServerRoutes.js +67 -110
  12. package/dist/cjs/analyze/index.js +265 -257
  13. package/dist/cjs/analyze/isDefaultExportFunction.js +66 -44
  14. package/dist/cjs/analyze/makeLegalIdentifier.js +7 -25
  15. package/dist/cjs/analyze/nestedRoutes.js +99 -104
  16. package/dist/cjs/analyze/templates.js +49 -110
  17. package/dist/cjs/analyze/utils.js +98 -102
  18. package/dist/cjs/builder/builder-rspack/adapterCopy.js +58 -100
  19. package/dist/cjs/builder/builder-rspack/index.js +14 -30
  20. package/dist/cjs/builder/builder-webpack/adapterModern.js +33 -50
  21. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +16 -32
  22. package/dist/cjs/builder/builder-webpack/index.js +65 -46
  23. package/dist/cjs/builder/generator/createBuilderOptions.js +10 -26
  24. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +11 -27
  25. package/dist/cjs/builder/generator/getBuilderTargets.js +13 -29
  26. package/dist/cjs/builder/generator/index.js +61 -55
  27. package/dist/cjs/builder/index.js +53 -43
  28. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +13 -36
  29. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +90 -90
  30. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +108 -111
  31. package/dist/cjs/builder/shared/builderPlugins/index.js +20 -19
  32. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -30
  33. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +32 -38
  34. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +86 -116
  35. package/dist/cjs/builder/shared/bundlerPlugins/index.js +20 -19
  36. package/dist/cjs/builder/shared/createCopyInfo.js +16 -42
  37. package/dist/cjs/builder/shared/index.js +20 -19
  38. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +8 -24
  39. package/dist/cjs/builder/shared/types.js +4 -15
  40. package/dist/cjs/commands/build.js +23 -40
  41. package/dist/cjs/commands/deploy.js +7 -25
  42. package/dist/cjs/commands/dev.js +38 -57
  43. package/dist/cjs/commands/index.js +20 -19
  44. package/dist/cjs/commands/inspect.js +10 -30
  45. package/dist/cjs/commands/serve.js +28 -66
  46. package/dist/cjs/config/default.js +34 -34
  47. package/dist/cjs/config/index.js +20 -19
  48. package/dist/cjs/config/initialize/index.js +11 -29
  49. package/dist/cjs/config/initialize/inits.js +103 -82
  50. package/dist/cjs/config/legacy/createHtmlConfig.js +8 -40
  51. package/dist/cjs/config/legacy/createOutputConfig.js +8 -51
  52. package/dist/cjs/config/legacy/createSourceConfig.js +8 -38
  53. package/dist/cjs/config/legacy/createToolsConfig.js +8 -43
  54. package/dist/cjs/config/legacy/index.js +22 -46
  55. package/dist/cjs/defineConfig.js +16 -31
  56. package/dist/cjs/exports/server.js +7 -25
  57. package/dist/cjs/hooks.js +33 -51
  58. package/dist/cjs/index.js +185 -166
  59. package/dist/cjs/initialize/index.js +84 -100
  60. package/dist/cjs/locale/en.js +13 -27
  61. package/dist/cjs/locale/index.js +18 -28
  62. package/dist/cjs/locale/zh.js +13 -27
  63. package/dist/cjs/schema/Schema.js +27 -31
  64. package/dist/cjs/schema/index.js +141 -71
  65. package/dist/cjs/schema/legacy.js +273 -96
  66. package/dist/cjs/types/config/deploy.js +4 -15
  67. package/dist/cjs/types/config/dev.js +4 -15
  68. package/dist/cjs/types/config/experiments.js +4 -15
  69. package/dist/cjs/types/config/html.js +4 -15
  70. package/dist/cjs/types/config/index.js +18 -17
  71. package/dist/cjs/types/config/output.js +4 -15
  72. package/dist/cjs/types/config/performance.js +4 -15
  73. package/dist/cjs/types/config/security.js +4 -15
  74. package/dist/cjs/types/config/source.js +4 -15
  75. package/dist/cjs/types/config/tools.js +4 -15
  76. package/dist/cjs/types/hooks.js +4 -15
  77. package/dist/cjs/types/index.js +20 -19
  78. package/dist/cjs/types/legacyConfig/deploy.js +4 -15
  79. package/dist/cjs/types/legacyConfig/dev.js +4 -15
  80. package/dist/cjs/types/legacyConfig/index.js +4 -15
  81. package/dist/cjs/types/legacyConfig/output.js +4 -15
  82. package/dist/cjs/types/legacyConfig/source.js +4 -15
  83. package/dist/cjs/types/legacyConfig/tools.js +4 -15
  84. package/dist/cjs/types/utils.js +4 -15
  85. package/dist/cjs/utils/config.js +74 -79
  86. package/dist/cjs/utils/createServer.js +16 -42
  87. package/dist/cjs/utils/env.js +7 -25
  88. package/dist/cjs/utils/generateWatchFiles.js +31 -52
  89. package/dist/cjs/utils/getSelectedEntries.js +13 -35
  90. package/dist/cjs/utils/getServerInternalPlugins.js +8 -29
  91. package/dist/cjs/utils/printInstructions.js +10 -28
  92. package/dist/cjs/utils/restart.js +13 -31
  93. package/dist/cjs/utils/routes.js +18 -39
  94. package/dist/cjs/utils/types.js +4 -15
  95. package/dist/esm/analyze/constants.js +40 -41
  96. package/dist/esm/analyze/generateCode.js +477 -455
  97. package/dist/esm/analyze/getBundleEntry.js +53 -54
  98. package/dist/esm/analyze/getClientRoutes/getRoutes.js +201 -202
  99. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +199 -200
  100. package/dist/esm/analyze/getClientRoutes/index.js +2 -3
  101. package/dist/esm/analyze/getClientRoutes/utils.js +15 -15
  102. package/dist/esm/analyze/getFileSystemEntry.js +86 -87
  103. package/dist/esm/analyze/getHtmlTemplate.js +289 -278
  104. package/dist/esm/analyze/getServerRoutes.js +203 -190
  105. package/dist/esm/analyze/index.js +679 -651
  106. package/dist/esm/analyze/isDefaultExportFunction.js +38 -39
  107. package/dist/esm/analyze/makeLegalIdentifier.js +8 -9
  108. package/dist/esm/analyze/nestedRoutes.js +400 -392
  109. package/dist/esm/analyze/templates.js +536 -509
  110. package/dist/esm/analyze/utils.js +357 -336
  111. package/dist/esm/builder/builder-rspack/adapterCopy.js +347 -330
  112. package/dist/esm/builder/builder-rspack/index.js +8 -9
  113. package/dist/esm/builder/builder-webpack/adapterModern.js +51 -43
  114. package/dist/esm/builder/builder-webpack/createCopyPattern.js +31 -32
  115. package/dist/esm/builder/builder-webpack/index.js +266 -249
  116. package/dist/esm/builder/generator/createBuilderOptions.js +37 -38
  117. package/dist/esm/builder/generator/createBuilderProviderConfig.js +62 -63
  118. package/dist/esm/builder/generator/getBuilderTargets.js +13 -14
  119. package/dist/esm/builder/generator/index.js +203 -196
  120. package/dist/esm/builder/index.js +183 -176
  121. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +90 -91
  122. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +300 -291
  123. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +337 -329
  124. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +108 -97
  125. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +66 -64
  126. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +364 -337
  127. package/dist/esm/builder/shared/createCopyInfo.js +9 -10
  128. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +2 -3
  129. package/dist/esm/builder/shared/types.js +1 -1
  130. package/dist/esm/commands/build.js +279 -272
  131. package/dist/esm/commands/deploy.js +150 -144
  132. package/dist/esm/commands/dev.js +296 -289
  133. package/dist/esm/commands/inspect.js +144 -138
  134. package/dist/esm/commands/serve.js +241 -235
  135. package/dist/esm/config/default.js +202 -203
  136. package/dist/esm/config/initialize/index.js +7 -8
  137. package/dist/esm/config/initialize/inits.js +189 -181
  138. package/dist/esm/config/legacy/createHtmlConfig.js +17 -18
  139. package/dist/esm/config/legacy/createOutputConfig.js +41 -42
  140. package/dist/esm/config/legacy/createSourceConfig.js +38 -39
  141. package/dist/esm/config/legacy/createToolsConfig.js +24 -25
  142. package/dist/esm/config/legacy/index.js +31 -32
  143. package/dist/esm/defineConfig.js +52 -53
  144. package/dist/esm/exports/server.js +1 -2
  145. package/dist/esm/hooks.js +26 -27
  146. package/dist/esm/index.js +685 -671
  147. package/dist/esm/initialize/index.js +276 -269
  148. package/dist/esm/locale/en.js +36 -37
  149. package/dist/esm/locale/index.js +2 -2
  150. package/dist/esm/locale/zh.js +36 -37
  151. package/dist/esm/schema/Schema.js +255 -244
  152. package/dist/esm/schema/index.js +165 -165
  153. package/dist/esm/schema/legacy.js +316 -317
  154. package/dist/esm/types/config/deploy.js +1 -1
  155. package/dist/esm/types/config/dev.js +1 -1
  156. package/dist/esm/types/config/experiments.js +1 -1
  157. package/dist/esm/types/config/html.js +1 -1
  158. package/dist/esm/types/config/output.js +1 -1
  159. package/dist/esm/types/config/performance.js +1 -1
  160. package/dist/esm/types/config/security.js +1 -1
  161. package/dist/esm/types/config/source.js +1 -1
  162. package/dist/esm/types/config/tools.js +1 -1
  163. package/dist/esm/types/hooks.js +1 -1
  164. package/dist/esm/types/legacyConfig/deploy.js +1 -1
  165. package/dist/esm/types/legacyConfig/dev.js +1 -1
  166. package/dist/esm/types/legacyConfig/index.js +1 -1
  167. package/dist/esm/types/legacyConfig/output.js +1 -1
  168. package/dist/esm/types/legacyConfig/source.js +1 -1
  169. package/dist/esm/types/legacyConfig/tools.js +1 -1
  170. package/dist/esm/types/utils.js +1 -1
  171. package/dist/esm/utils/config.js +285 -278
  172. package/dist/esm/utils/createServer.js +242 -234
  173. package/dist/esm/utils/env.js +11 -12
  174. package/dist/esm/utils/generateWatchFiles.js +205 -190
  175. package/dist/esm/utils/getSelectedEntries.js +180 -173
  176. package/dist/esm/utils/getServerInternalPlugins.js +197 -191
  177. package/dist/esm/utils/printInstructions.js +147 -141
  178. package/dist/esm/utils/restart.js +179 -173
  179. package/dist/esm/utils/routes.js +146 -139
  180. package/dist/esm/utils/types.js +1 -1
  181. package/dist/esm-node/analyze/constants.js +31 -46
  182. package/dist/esm-node/analyze/generateCode.js +28 -94
  183. package/dist/esm-node/analyze/getBundleEntry.js +8 -27
  184. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +24 -65
  185. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +24 -63
  186. package/dist/esm-node/analyze/getClientRoutes/index.js +2 -6
  187. package/dist/esm-node/analyze/getClientRoutes/utils.js +5 -19
  188. package/dist/esm-node/analyze/getFileSystemEntry.js +10 -37
  189. package/dist/esm-node/analyze/getHtmlTemplate.js +29 -59
  190. package/dist/esm-node/analyze/getServerRoutes.js +43 -75
  191. package/dist/esm-node/analyze/index.js +208 -230
  192. package/dist/esm-node/analyze/isDefaultExportFunction.js +7 -5
  193. package/dist/esm-node/analyze/makeLegalIdentifier.js +1 -4
  194. package/dist/esm-node/analyze/nestedRoutes.js +23 -43
  195. package/dist/esm-node/analyze/templates.js +22 -69
  196. package/dist/esm-node/analyze/utils.js +66 -60
  197. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +40 -62
  198. package/dist/esm-node/builder/builder-rspack/index.js +4 -5
  199. package/dist/esm-node/builder/builder-webpack/adapterModern.js +24 -26
  200. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +3 -10
  201. package/dist/esm-node/builder/builder-webpack/index.js +13 -11
  202. package/dist/esm-node/builder/generator/createBuilderOptions.js +4 -5
  203. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +5 -6
  204. package/dist/esm-node/builder/generator/getBuilderTargets.js +5 -11
  205. package/dist/esm-node/builder/generator/index.js +7 -16
  206. package/dist/esm-node/builder/index.js +2 -7
  207. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +2 -6
  208. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +34 -60
  209. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +54 -74
  210. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +23 -8
  211. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +25 -16
  212. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +66 -76
  213. package/dist/esm-node/builder/shared/createCopyInfo.js +2 -8
  214. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +1 -4
  215. package/dist/esm-node/builder/shared/types.js +1 -0
  216. package/dist/esm-node/commands/build.js +7 -9
  217. package/dist/esm-node/commands/deploy.js +1 -4
  218. package/dist/esm-node/commands/dev.js +19 -27
  219. package/dist/esm-node/commands/inspect.js +3 -8
  220. package/dist/esm-node/commands/serve.js +7 -25
  221. package/dist/esm-node/config/default.js +20 -11
  222. package/dist/esm-node/config/initialize/index.js +1 -4
  223. package/dist/esm-node/config/initialize/inits.js +48 -54
  224. package/dist/esm-node/config/legacy/createHtmlConfig.js +2 -19
  225. package/dist/esm-node/config/legacy/createOutputConfig.js +2 -30
  226. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -17
  227. package/dist/esm-node/config/legacy/createToolsConfig.js +2 -22
  228. package/dist/esm-node/config/legacy/index.js +3 -18
  229. package/dist/esm-node/defineConfig.js +7 -13
  230. package/dist/esm-node/exports/server.js +1 -4
  231. package/dist/esm-node/hooks.js +2 -9
  232. package/dist/esm-node/index.js +95 -120
  233. package/dist/esm-node/initialize/index.js +74 -87
  234. package/dist/esm-node/locale/en.js +7 -6
  235. package/dist/esm-node/locale/index.js +5 -5
  236. package/dist/esm-node/locale/zh.js +7 -6
  237. package/dist/esm-node/schema/Schema.js +19 -8
  238. package/dist/esm-node/schema/index.js +121 -36
  239. package/dist/esm-node/schema/legacy.js +262 -72
  240. package/dist/esm-node/types/config/deploy.js +1 -0
  241. package/dist/esm-node/types/config/dev.js +1 -0
  242. package/dist/esm-node/types/config/experiments.js +1 -0
  243. package/dist/esm-node/types/config/html.js +1 -0
  244. package/dist/esm-node/types/config/output.js +1 -0
  245. package/dist/esm-node/types/config/performance.js +1 -0
  246. package/dist/esm-node/types/config/security.js +1 -0
  247. package/dist/esm-node/types/config/source.js +1 -0
  248. package/dist/esm-node/types/config/tools.js +1 -0
  249. package/dist/esm-node/types/hooks.js +1 -0
  250. package/dist/esm-node/types/legacyConfig/deploy.js +1 -0
  251. package/dist/esm-node/types/legacyConfig/dev.js +1 -0
  252. package/dist/esm-node/types/legacyConfig/index.js +1 -0
  253. package/dist/esm-node/types/legacyConfig/output.js +1 -0
  254. package/dist/esm-node/types/legacyConfig/source.js +1 -0
  255. package/dist/esm-node/types/legacyConfig/tools.js +1 -0
  256. package/dist/esm-node/types/utils.js +1 -0
  257. package/dist/esm-node/utils/config.js +16 -47
  258. package/dist/esm-node/utils/createServer.js +5 -12
  259. package/dist/esm-node/utils/env.js +1 -4
  260. package/dist/esm-node/utils/generateWatchFiles.js +13 -20
  261. package/dist/esm-node/utils/getSelectedEntries.js +2 -9
  262. package/dist/esm-node/utils/getServerInternalPlugins.js +2 -8
  263. package/dist/esm-node/utils/printInstructions.js +1 -4
  264. package/dist/esm-node/utils/restart.js +2 -11
  265. package/dist/esm-node/utils/routes.js +4 -4
  266. package/dist/esm-node/utils/types.js +1 -0
  267. package/dist/types/index.d.ts +2 -2
  268. package/lib/types.d.ts +1 -0
  269. package/package.json +29 -25
@@ -3,62 +3,61 @@ import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, isRouterV5 } from
3
3
  import { getFileSystemEntry } from "./getFileSystemEntry";
4
4
  import { JS_EXTENSIONS } from "./constants";
5
5
  var ensureExtensions = function(file) {
6
- if (!path.extname(file)) {
7
- return findExists(JS_EXTENSIONS.map(function(ext) {
8
- return "".concat(file).concat(ext);
9
- })) || file;
10
- }
11
- return file;
6
+ if (!path.extname(file)) {
7
+ return findExists(JS_EXTENSIONS.map(function(ext) {
8
+ return "".concat(file).concat(ext);
9
+ })) || file;
10
+ }
11
+ return file;
12
12
  };
13
13
  var ifAlreadyExists = function(entrypoints, checked) {
14
- return entrypoints.some(function(entrypoint) {
15
- if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
16
- checked.entryName = entrypoint.entryName;
17
- return true;
18
- }
19
- if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
20
- throw new Error("Entry configuration conflicts\n Your configuration: ".concat(checked.entry, ".\n Default entrypoint: ").concat(entrypoint.entry, "\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules."));
21
- }
22
- return false;
23
- });
24
- };
25
- var getBundleEntry = function(appContext, config) {
26
- var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
27
- var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir;
28
- var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
29
- if (entries) {
30
- Object.keys(entries).forEach(function(name) {
31
- var value = entries[name];
32
- var entrypoint = typeof value === "string" ? {
33
- entryName: name,
34
- entry: ensureAbsolutePath(appDirectory, value),
35
- absoluteEntryDir: path.dirname(ensureAbsolutePath(appDirectory, value)),
36
- isAutoMount: true,
37
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : void 0
38
- } : {
39
- entryName: name,
40
- entry: ensureAbsolutePath(appDirectory, value.entry),
41
- absoluteEntryDir: path.dirname(ensureAbsolutePath(appDirectory, value.entry)),
42
- isAutoMount: !value.disableMount,
43
- customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
44
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
45
- };
46
- if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
47
- entrypoint.nestedRoutesEntry = entrypoint.entry;
48
- }
49
- if (!ifAlreadyExists(defaults, entrypoint)) {
50
- defaults.push(entrypoint);
51
- }
52
- });
14
+ return entrypoints.some(function(entrypoint) {
15
+ if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
16
+ checked.entryName = entrypoint.entryName;
17
+ return true;
53
18
  }
54
- if (!disableDefaultEntries) {
55
- var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
56
- var found = defaults.find(function(param) {
57
- var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
58
- return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
59
- });
60
- found && (found.entryName = MAIN_ENTRY_NAME);
19
+ if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
20
+ throw new Error("Entry configuration conflicts\n Your configuration: ".concat(checked.entry, ".\n Default entrypoint: ").concat(entrypoint.entry, "\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules."));
61
21
  }
62
- return defaults;
22
+ return false;
23
+ });
24
+ };
25
+ export var getBundleEntry = function(appContext, config) {
26
+ var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
27
+ var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir;
28
+ var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
29
+ if (entries) {
30
+ Object.keys(entries).forEach(function(name) {
31
+ var value = entries[name];
32
+ var entrypoint = typeof value === "string" ? {
33
+ entryName: name,
34
+ entry: ensureAbsolutePath(appDirectory, value),
35
+ absoluteEntryDir: path.dirname(ensureAbsolutePath(appDirectory, value)),
36
+ isAutoMount: true,
37
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : void 0
38
+ } : {
39
+ entryName: name,
40
+ entry: ensureAbsolutePath(appDirectory, value.entry),
41
+ absoluteEntryDir: path.dirname(ensureAbsolutePath(appDirectory, value.entry)),
42
+ isAutoMount: !value.disableMount,
43
+ customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
44
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
45
+ };
46
+ if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
47
+ entrypoint.nestedRoutesEntry = entrypoint.entry;
48
+ }
49
+ if (!ifAlreadyExists(defaults, entrypoint)) {
50
+ defaults.push(entrypoint);
51
+ }
52
+ });
53
+ }
54
+ if (!disableDefaultEntries) {
55
+ var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
56
+ var found = defaults.find(function(param) {
57
+ var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
58
+ return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
59
+ });
60
+ found && (found.entryName = MAIN_ENTRY_NAME);
61
+ }
62
+ return defaults;
63
63
  };
64
- export { getBundleEntry };
@@ -1,54 +1,54 @@
1
- function _defineProperty(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
13
  }
14
- function _objectSpread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _defineProperty(target, key, source[key]);
25
- });
14
+ function _object_spread(target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys2 = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
26
22
  }
27
- return target;
23
+ ownKeys2.forEach(function(key) {
24
+ _define_property(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
28
  }
29
29
  function ownKeys(object, enumerableOnly) {
30
- var keys = Object.keys(object);
31
- if (Object.getOwnPropertySymbols) {
32
- var symbols = Object.getOwnPropertySymbols(object);
33
- if (enumerableOnly) {
34
- symbols = symbols.filter(function(sym) {
35
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
- });
37
- }
38
- keys.push.apply(keys, symbols);
30
+ var keys = Object.keys(object);
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ if (enumerableOnly) {
34
+ symbols = symbols.filter(function(sym) {
35
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
+ });
39
37
  }
40
- return keys;
38
+ keys.push.apply(keys, symbols);
39
+ }
40
+ return keys;
41
41
  }
42
- function _objectSpreadProps(target, source) {
43
- source = source != null ? source : {};
44
- if (Object.getOwnPropertyDescriptors) {
45
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
- } else {
47
- ownKeys(Object(source)).forEach(function(key) {
48
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
- });
50
- }
51
- return target;
42
+ function _object_spread_props(target, source) {
43
+ source = source != null ? source : {};
44
+ if (Object.getOwnPropertyDescriptors) {
45
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
+ } else {
47
+ ownKeys(Object(source)).forEach(function(key) {
48
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
+ });
50
+ }
51
+ return target;
52
52
  }
53
53
  import path from "path";
54
54
  import { fs } from "@modern-js/utils";
@@ -57,177 +57,176 @@ import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, F
57
57
  import { replaceWithAlias } from "../utils";
58
58
  import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
59
59
  var compName = function(srcDirectory, filePath) {
60
- var legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
61
- return "Comp_".concat(legalCompName);
60
+ var legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
61
+ return "Comp_".concat(legalCompName);
62
62
  };
63
63
  var layoutNameAbbr = function(filePath) {
64
- var prefix = "L_";
65
- var dirName = path.dirname(filePath).split("/").pop() || "";
66
- return "".concat(prefix).concat(makeLegalIdentifier(dirName));
64
+ var prefix = "L_";
65
+ var dirName = path.dirname(filePath).split("/").pop() || "";
66
+ return "".concat(prefix).concat(makeLegalIdentifier(dirName));
67
67
  };
68
68
  var parents = [];
69
69
  var recursiveReadDir = function(param) {
70
- var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
- var hasDynamicRoute = false;
72
- var resetParent = false;
73
- var parent = parents[parents.length - 1];
74
- var layout = findLayout(dir);
75
- if (layout) {
76
- if (basePath === "/") {
77
- throw new Error("should use _app instead of _layout in ".concat(dir));
78
- } else {
79
- var alias = replaceWithAlias(srcDirectory, layout, srcAlias);
80
- var componentName = compName(srcDirectory, layout);
81
- var route = {
82
- path: "".concat(basePath.substring(0, basePath.length - 1)),
83
- children: [],
84
- _component: alias,
85
- component: componentName,
86
- parent: parent,
87
- type: "page"
88
- };
89
- parent = route;
90
- resetParent = true;
91
- routes.push(route);
92
- parents.push(route);
93
- routes = route.children;
94
- }
70
+ var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
+ var hasDynamicRoute = false;
72
+ var resetParent = false;
73
+ var parent = parents[parents.length - 1];
74
+ var layout = findLayout(dir);
75
+ if (layout) {
76
+ if (basePath === "/") {
77
+ throw new Error("should use _app instead of _layout in ".concat(dir));
78
+ } else {
79
+ var alias = replaceWithAlias(srcDirectory, layout, srcAlias);
80
+ var componentName = compName(srcDirectory, layout);
81
+ var route = {
82
+ path: "".concat(basePath.substring(0, basePath.length - 1)),
83
+ children: [],
84
+ _component: alias,
85
+ component: componentName,
86
+ parent,
87
+ type: "page"
88
+ };
89
+ parent = route;
90
+ resetParent = true;
91
+ routes.push(route);
92
+ parents.push(route);
93
+ routes = route.children;
95
94
  }
96
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
97
- try {
98
- for(var _iterator = fs.readdirSync(dir)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
99
- var relative = _step.value;
100
- var filePath = path.join(dir, relative);
101
- if (!shouldSkip(filePath)) {
102
- var filename = path.basename(filePath, path.extname(filePath));
103
- var alias1 = replaceWithAlias(srcDirectory, filePath, srcAlias);
104
- var componentName1 = compName(srcDirectory, filePath);
105
- var dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
106
- if (dynamicRouteMatched) {
107
- if (hasDynamicRoute) {
108
- throw new Error("Can't set two dynamic route in one directory: ".concat(dir));
109
- } else {
110
- hasDynamicRoute = true;
111
- }
112
- }
113
- var route1 = {
114
- path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
115
- _component: alias1,
116
- component: componentName1,
117
- parent: parent,
118
- type: "page"
119
- };
120
- if (fs.statSync(filePath).isDirectory()) {
121
- recursiveReadDir({
122
- dir: filePath,
123
- routes: routes,
124
- basePath: "".concat(route1.path, "/"),
125
- srcDirectory: srcDirectory,
126
- srcAlias: srcAlias
127
- });
128
- continue;
129
- }
130
- if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
131
- continue;
132
- }
133
- if (filename === FILE_SYSTEM_ROUTES_INDEX) {
134
- route1.path = basePath === "/" ? basePath : "".concat(basePath.substring(0, basePath.length - 1));
135
- }
136
- if (filename === "404" && basePath === "/") {
137
- route1.path = "*";
138
- }
139
- routes.push(route1);
140
- }
95
+ }
96
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
97
+ try {
98
+ for (var _iterator = fs.readdirSync(dir)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
99
+ var relative = _step.value;
100
+ var filePath = path.join(dir, relative);
101
+ if (!shouldSkip(filePath)) {
102
+ var filename = path.basename(filePath, path.extname(filePath));
103
+ var alias1 = replaceWithAlias(srcDirectory, filePath, srcAlias);
104
+ var componentName1 = compName(srcDirectory, filePath);
105
+ var dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
106
+ if (dynamicRouteMatched) {
107
+ if (hasDynamicRoute) {
108
+ throw new Error("Can't set two dynamic route in one directory: ".concat(dir));
109
+ } else {
110
+ hasDynamicRoute = true;
111
+ }
112
+ }
113
+ var route1 = {
114
+ path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
115
+ _component: alias1,
116
+ component: componentName1,
117
+ parent,
118
+ type: "page"
119
+ };
120
+ if (fs.statSync(filePath).isDirectory()) {
121
+ recursiveReadDir({
122
+ dir: filePath,
123
+ routes,
124
+ basePath: "".concat(route1.path, "/"),
125
+ srcDirectory,
126
+ srcAlias
127
+ });
128
+ continue;
129
+ }
130
+ if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
131
+ continue;
141
132
  }
142
- } catch (err) {
143
- _didIteratorError = true;
144
- _iteratorError = err;
145
- } finally{
146
- try {
147
- if (!_iteratorNormalCompletion && _iterator.return != null) {
148
- _iterator.return();
149
- }
150
- } finally{
151
- if (_didIteratorError) {
152
- throw _iteratorError;
153
- }
133
+ if (filename === FILE_SYSTEM_ROUTES_INDEX) {
134
+ route1.path = basePath === "/" ? basePath : "".concat(basePath.substring(0, basePath.length - 1));
154
135
  }
136
+ if (filename === "404" && basePath === "/") {
137
+ route1.path = "*";
138
+ }
139
+ routes.push(route1);
140
+ }
155
141
  }
156
- if (resetParent) {
157
- parents.pop();
142
+ } catch (err) {
143
+ _didIteratorError = true;
144
+ _iteratorError = err;
145
+ } finally {
146
+ try {
147
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
148
+ _iterator.return();
149
+ }
150
+ } finally {
151
+ if (_didIteratorError) {
152
+ throw _iteratorError;
153
+ }
158
154
  }
155
+ }
156
+ if (resetParent) {
157
+ parents.pop();
158
+ }
159
159
  };
160
160
  var normalizeNestedRoutes = function(nested, internalComponentsDir, internalDirectory, internalDirAlias) {
161
- var flat = function(routes) {
162
- return routes.reduce(function(memo, route) {
163
- return memo.concat(Array.isArray(route.children) ? flat(route.children) : [
164
- route
165
- ]);
166
- }, []);
167
- };
168
- var generate = function(route) {
169
- var codes = [];
170
- var lastComponent = route.component;
171
- var imports = [
172
- "import React from 'react';",
173
- "import ".concat(lastComponent, " from '").concat(route._component, "'")
174
- ];
175
- while(route = route.parent){
176
- var layoutComponent = route.component;
177
- var layoutComponentAbbr = layoutNameAbbr(route._component);
178
- imports.push("import ".concat(layoutComponent, " from '").concat(route._component, "';"));
179
- var currentComponent = "".concat(layoutComponentAbbr, "_").concat(lastComponent);
180
- codes.push("const ".concat(currentComponent, " = props => <").concat(layoutComponent, " Component={").concat(lastComponent, "} {...props} />;"));
181
- lastComponent = currentComponent;
182
- }
183
- var file = path.resolve(internalComponentsDir, "".concat(lastComponent, ".jsx"));
184
- fs.outputFileSync(file, "".concat(imports.join("\n"), "\n").concat(codes.join("\n"), "\nexport default ").concat(lastComponent));
185
- return {
186
- component: lastComponent,
187
- _component: replaceWithAlias(internalDirectory, file, internalDirAlias)
188
- };
161
+ var flat = function(routes) {
162
+ return routes.reduce(function(memo, route) {
163
+ return memo.concat(Array.isArray(route.children) ? flat(route.children) : [
164
+ route
165
+ ]);
166
+ }, []);
167
+ };
168
+ var generate = function(route) {
169
+ var codes = [];
170
+ var lastComponent = route.component;
171
+ var imports = [
172
+ "import React from 'react';",
173
+ "import ".concat(lastComponent, " from '").concat(route._component, "'")
174
+ ];
175
+ while (route = route.parent) {
176
+ var layoutComponent = route.component;
177
+ var layoutComponentAbbr = layoutNameAbbr(route._component);
178
+ imports.push("import ".concat(layoutComponent, " from '").concat(route._component, "';"));
179
+ var currentComponent = "".concat(layoutComponentAbbr, "_").concat(lastComponent);
180
+ codes.push("const ".concat(currentComponent, " = props => <").concat(layoutComponent, " Component={").concat(lastComponent, "} {...props} />;"));
181
+ lastComponent = currentComponent;
182
+ }
183
+ var file = path.resolve(internalComponentsDir, "".concat(lastComponent, ".jsx"));
184
+ fs.outputFileSync(file, "".concat(imports.join("\n"), "\n").concat(codes.join("\n"), "\nexport default ").concat(lastComponent));
185
+ return {
186
+ component: lastComponent,
187
+ _component: replaceWithAlias(internalDirectory, file, internalDirAlias)
189
188
  };
190
- var normalized = flat(nested).map(function(route) {
191
- return route.parent ? _objectSpreadProps(_objectSpread({}, route, generate(route)), {
192
- parent: void 0
193
- }) : _objectSpreadProps(_objectSpread({}, route), {
194
- parent: void 0
195
- });
189
+ };
190
+ var normalized = flat(nested).map(function(route) {
191
+ return route.parent ? _object_spread_props(_object_spread({}, route, generate(route)), {
192
+ parent: void 0
193
+ }) : _object_spread_props(_object_spread({}, route), {
194
+ parent: void 0
196
195
  });
197
- return normalized;
196
+ });
197
+ return normalized;
198
198
  };
199
- var getClientRoutes = function(param) {
200
- var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
201
- var entryName = entrypoint.entryName, pageRoutesEntry = entrypoint.pageRoutesEntry;
202
- if (!pageRoutesEntry) {
203
- return [];
204
- }
205
- if (!fs.existsSync(pageRoutesEntry)) {
206
- throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " directory not found."));
207
- }
208
- if (!(fs.existsSync(pageRoutesEntry) && fs.statSync(pageRoutesEntry).isDirectory())) {
209
- throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " should be directory."));
199
+ export var getClientRoutes = function(param) {
200
+ var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
201
+ var entryName = entrypoint.entryName, pageRoutesEntry = entrypoint.pageRoutesEntry;
202
+ if (!pageRoutesEntry) {
203
+ return [];
204
+ }
205
+ if (!fs.existsSync(pageRoutesEntry)) {
206
+ throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " directory not found."));
207
+ }
208
+ if (!(fs.existsSync(pageRoutesEntry) && fs.statSync(pageRoutesEntry).isDirectory())) {
209
+ throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " should be directory."));
210
+ }
211
+ var routes = [];
212
+ recursiveReadDir({
213
+ dir: pageRoutesEntry,
214
+ routes,
215
+ basePath: "/",
216
+ srcDirectory,
217
+ srcAlias
218
+ });
219
+ var internalComponentsDir = path.resolve(internalDirectory, "".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_COMPONENTS_DIR));
220
+ fs.emptyDirSync(internalComponentsDir);
221
+ routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
222
+ parents.length = 0;
223
+ routes.sort(function(a, b) {
224
+ var delta = getRouteWeight(a.path) - getRouteWeight(b.path);
225
+ if (delta === 0) {
226
+ return a.path.length - b.path.length;
210
227
  }
211
- var routes = [];
212
- recursiveReadDir({
213
- dir: pageRoutesEntry,
214
- routes: routes,
215
- basePath: "/",
216
- srcDirectory: srcDirectory,
217
- srcAlias: srcAlias
218
- });
219
- var internalComponentsDir = path.resolve(internalDirectory, "".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_COMPONENTS_DIR));
220
- fs.emptyDirSync(internalComponentsDir);
221
- routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
222
- parents.length = 0;
223
- routes.sort(function(a, b) {
224
- var delta = getRouteWeight(a.path) - getRouteWeight(b.path);
225
- if (delta === 0) {
226
- return a.path.length - b.path.length;
227
- }
228
- return delta;
229
- });
230
- debug("fileSystem routes: %o", routes);
231
- return routes;
228
+ return delta;
229
+ });
230
+ debug("fileSystem routes: %o", routes);
231
+ return routes;
232
232
  };
233
- export { getClientRoutes };