@modern-js/app-tools 2.15.0 → 2.17.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 (268) hide show
  1. package/CHANGELOG.md +68 -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/package.json +29 -25
@@ -1,178 +1,185 @@
1
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
14
  }
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(void 0);
27
+ });
28
+ };
29
29
  }
30
- function _defineProperty(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
42
  }
43
- function _objectSpread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _defineProperty(target, key, source[key]);
54
- });
43
+ function _object_spread(target) {
44
+ for (var i = 1; i < arguments.length; i++) {
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys2 = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
55
51
  }
56
- return target;
52
+ ownKeys2.forEach(function(key) {
53
+ _define_property(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
57
  }
58
58
  function ownKeys(object, enumerableOnly) {
59
- var keys = Object.keys(object);
60
- if (Object.getOwnPropertySymbols) {
61
- var symbols = Object.getOwnPropertySymbols(object);
62
- if (enumerableOnly) {
63
- symbols = symbols.filter(function(sym) {
64
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
- });
66
- }
67
- keys.push.apply(keys, symbols);
59
+ var keys = Object.keys(object);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var symbols = Object.getOwnPropertySymbols(object);
62
+ if (enumerableOnly) {
63
+ symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ });
68
66
  }
69
- return keys;
67
+ keys.push.apply(keys, symbols);
68
+ }
69
+ return keys;
70
70
  }
71
- function _objectSpreadProps(target, source) {
72
- source = source != null ? source : {};
73
- if (Object.getOwnPropertyDescriptors) {
74
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
- } else {
76
- ownKeys(Object(source)).forEach(function(key) {
77
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
- });
79
- }
80
- return target;
71
+ function _object_spread_props(target, source) {
72
+ source = source != null ? source : {};
73
+ if (Object.getOwnPropertyDescriptors) {
74
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
+ } else {
76
+ ownKeys(Object(source)).forEach(function(key) {
77
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
+ });
79
+ }
80
+ return target;
81
81
  }
82
- var __generator = this && this.__generator || function(thisArg, body) {
83
- var f, y, t, g, _ = {
84
- label: 0,
85
- sent: function() {
86
- if (t[0] & 1) throw t[1];
87
- return t[1];
88
- },
89
- trys: [],
90
- ops: []
82
+ var __generator = function(thisArg, body) {
83
+ var f, y, t, g, _ = {
84
+ label: 0,
85
+ sent: function() {
86
+ if (t[0] & 1)
87
+ throw t[1];
88
+ return t[1];
89
+ },
90
+ trys: [],
91
+ ops: []
92
+ };
93
+ return g = {
94
+ next: verb(0),
95
+ "throw": verb(1),
96
+ "return": verb(2)
97
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
98
+ return this;
99
+ }), g;
100
+ function verb(n) {
101
+ return function(v) {
102
+ return step([
103
+ n,
104
+ v
105
+ ]);
91
106
  };
92
- return(g = {
93
- next: verb(0),
94
- "throw": verb(1),
95
- "return": verb(2)
96
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
97
- return this;
98
- }), g);
99
- function verb(n) {
100
- return function(v) {
101
- return step([
102
- n,
103
- v
104
- ]);
105
- };
106
- }
107
- function step(op) {
108
- if (f) throw new TypeError("Generator is already executing.");
109
- while(_)try {
110
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
111
- if (y = 0, t) op = [
112
- op[0] & 2,
113
- t.value
114
- ];
115
- switch(op[0]){
116
- case 0:
117
- case 1:
118
- t = op;
119
- break;
120
- case 4:
121
- _.label++;
122
- return {
123
- value: op[1],
124
- done: false
125
- };
126
- case 5:
127
- _.label++;
128
- y = op[1];
129
- op = [
130
- 0
131
- ];
132
- continue;
133
- case 7:
134
- op = _.ops.pop();
135
- _.trys.pop();
136
- continue;
137
- default:
138
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
139
- _ = 0;
140
- continue;
141
- }
142
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
- _.label = op[1];
144
- break;
145
- }
146
- if (op[0] === 6 && _.label < t[1]) {
147
- _.label = t[1];
148
- t = op;
149
- break;
150
- }
151
- if (t && _.label < t[2]) {
152
- _.label = t[2];
153
- _.ops.push(op);
154
- break;
155
- }
156
- if (t[2]) _.ops.pop();
157
- _.trys.pop();
158
- continue;
159
- }
160
- op = body.call(thisArg, _);
161
- } catch (e) {
107
+ }
108
+ function step(op) {
109
+ if (f)
110
+ throw new TypeError("Generator is already executing.");
111
+ while (_)
112
+ try {
113
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
114
+ return t;
115
+ if (y = 0, t)
116
+ op = [
117
+ op[0] & 2,
118
+ t.value
119
+ ];
120
+ switch (op[0]) {
121
+ case 0:
122
+ case 1:
123
+ t = op;
124
+ break;
125
+ case 4:
126
+ _.label++;
127
+ return {
128
+ value: op[1],
129
+ done: false
130
+ };
131
+ case 5:
132
+ _.label++;
133
+ y = op[1];
162
134
  op = [
163
- 6,
164
- e
135
+ 0
165
136
  ];
166
- y = 0;
167
- } finally{
168
- f = t = 0;
137
+ continue;
138
+ case 7:
139
+ op = _.ops.pop();
140
+ _.trys.pop();
141
+ continue;
142
+ default:
143
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
144
+ _ = 0;
145
+ continue;
146
+ }
147
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
148
+ _.label = op[1];
149
+ break;
150
+ }
151
+ if (op[0] === 6 && _.label < t[1]) {
152
+ _.label = t[1];
153
+ t = op;
154
+ break;
155
+ }
156
+ if (t && _.label < t[2]) {
157
+ _.label = t[2];
158
+ _.ops.push(op);
159
+ break;
160
+ }
161
+ if (t[2])
162
+ _.ops.pop();
163
+ _.trys.pop();
164
+ continue;
169
165
  }
170
- if (op[0] & 5) throw op[1];
171
- return {
172
- value: op[0] ? op[1] : void 0,
173
- done: true
174
- };
175
- }
166
+ op = body.call(thisArg, _);
167
+ } catch (e) {
168
+ op = [
169
+ 6,
170
+ e
171
+ ];
172
+ y = 0;
173
+ } finally {
174
+ f = t = 0;
175
+ }
176
+ if (op[0] & 5)
177
+ throw op[1];
178
+ return {
179
+ value: op[0] ? op[1] : void 0,
180
+ done: true
181
+ };
182
+ }
176
183
  };
177
184
  import * as path from "path";
178
185
  import { fs, getRouteId } from "@modern-js/utils";
@@ -180,242 +187,243 @@ import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
180
187
  import { replaceWithAlias } from "./utils";
181
188
  var conventionNames = Object.values(NESTED_ROUTE);
182
189
  var replaceDynamicPath = function(routePath) {
183
- return routePath.replace(/\[(.*?)\]/g, ":$1");
190
+ return routePath.replace(/\[(.*?)\]/g, ":$1");
184
191
  };
185
192
  var createIndexRoute = function(routeInfo, rootDir, filename, entryName) {
186
- return createRoute(_objectSpreadProps(_objectSpread({}, routeInfo), {
187
- index: true,
188
- children: void 0
189
- }), rootDir, filename, entryName);
193
+ return createRoute(_object_spread_props(_object_spread({}, routeInfo), {
194
+ index: true,
195
+ children: void 0
196
+ }), rootDir, filename, entryName);
190
197
  };
191
198
  var createRoute = function(routeInfo, rootDir, filename, entryName) {
192
- var id = getRouteId(filename, rootDir, entryName);
193
- return _objectSpreadProps(_objectSpread({}, routeInfo), {
194
- id: id,
195
- type: "nested"
196
- });
199
+ var id = getRouteId(filename, rootDir, entryName);
200
+ return _object_spread_props(_object_spread({}, routeInfo), {
201
+ id,
202
+ type: "nested"
203
+ });
197
204
  };
198
- var walk = function() {
199
- var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
200
- var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, path2;
201
- return __generator(this, function(_state) {
202
- switch(_state.label){
203
- case 0:
204
- return [
205
- 4,
206
- fs.pathExists(dirname)
207
- ];
208
- case 1:
209
- if (!_state.sent()) {
210
- return [
211
- 2,
212
- null
213
- ];
214
- }
215
- return [
216
- 4,
217
- fs.stat(dirname)
218
- ];
219
- case 2:
220
- isDirectory = _state.sent().isDirectory();
221
- if (!isDirectory) {
222
- return [
223
- 2,
224
- null
225
- ];
226
- }
227
- relativeDir = path.relative(rootDir, dirname);
228
- pathSegments = relativeDir.split(path.sep);
229
- lastSegment = pathSegments[pathSegments.length - 1];
230
- isRoot = lastSegment === "";
231
- isPathlessLayout = lastSegment.startsWith("__");
232
- isWithoutLayoutPath = lastSegment.includes(".");
233
- routePath = isRoot || isPathlessLayout ? "/" : "".concat(lastSegment);
234
- if (isWithoutLayoutPath) {
235
- routePath = lastSegment.split(".").join("/");
236
- }
237
- routePath = replaceDynamicPath(routePath);
238
- route = {
239
- path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
240
- children: [],
241
- isRoot: isRoot
242
- };
243
- pageLoaderFile = "";
244
- pageRoute = null;
245
- splatLoaderFile = "";
246
- splatRoute = null;
247
- pageConfigFile = "";
248
- return [
249
- 4,
250
- fs.readdir(dirname)
251
- ];
252
- case 3:
253
- items = _state.sent();
254
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
255
- _state.label = 4;
256
- case 4:
257
- _state.trys.push([
258
- 4,
259
- 11,
260
- 12,
261
- 13
262
- ]);
263
- _iterator = items[Symbol.iterator]();
264
- _state.label = 5;
265
- case 5:
266
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
267
- 3,
268
- 10
269
- ];
270
- item = _step.value;
271
- itemPath = path.join(dirname, item);
272
- extname = path.extname(item);
273
- itemWithoutExt = item.slice(0, -extname.length);
274
- return [
275
- 4,
276
- fs.stat(itemPath)
277
- ];
278
- case 6:
279
- isDirectory2 = _state.sent().isDirectory();
280
- if (!isDirectory2) return [
281
- 3,
282
- 8
283
- ];
284
- return [
285
- 4,
286
- walk(itemPath, rootDir, alias, entryName)
287
- ];
288
- case 7:
289
- childRoute = _state.sent();
290
- if (childRoute) {
291
- ;
292
- (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
293
- }
294
- _state.label = 8;
295
- case 8:
296
- if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
297
- return [
298
- 3,
299
- 9
300
- ];
301
- }
302
- if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
303
- if (!route.loader) {
304
- route.loader = itemPath;
305
- }
306
- }
307
- if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
308
- if (!route.config) {
309
- route.config = itemPath;
310
- }
311
- }
312
- if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
313
- route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
314
- }
315
- if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
316
- pageLoaderFile = itemPath;
317
- }
318
- if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
319
- pageConfigFile = itemPath;
320
- }
321
- if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
322
- ;
323
- pageRoute = createIndexRoute({
324
- _component: replaceWithAlias(alias.basename, itemPath, alias.name)
325
- }, rootDir, itemPath, entryName);
326
- if (pageLoaderFile) {
327
- pageRoute.loader = pageLoaderFile;
328
- }
329
- if (pageConfigFile) {
330
- pageRoute.config = pageConfigFile;
331
- }
332
- (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
333
- }
334
- if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
335
- splatLoaderFile = itemPath;
336
- }
337
- if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
338
- ;
339
- splatRoute = createRoute({
340
- _component: replaceWithAlias(alias.basename, itemPath, alias.name),
341
- path: "*"
342
- }, rootDir, itemPath, entryName);
343
- if (splatLoaderFile) {
344
- splatRoute.loader = splatLoaderFile;
345
- }
346
- (_route_children3 = route.children) === null || _route_children3 === void 0 ? void 0 : _route_children3.push(splatRoute);
347
- }
348
- if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
349
- route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
350
- }
351
- if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
352
- route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
353
- }
354
- _state.label = 9;
355
- case 9:
356
- _iteratorNormalCompletion = true;
357
- return [
358
- 3,
359
- 5
360
- ];
361
- case 10:
362
- return [
363
- 3,
364
- 13
365
- ];
366
- case 11:
367
- err = _state.sent();
368
- _didIteratorError = true;
369
- _iteratorError = err;
370
- return [
371
- 3,
372
- 13
373
- ];
374
- case 12:
375
- try {
376
- if (!_iteratorNormalCompletion && _iterator.return != null) {
377
- _iterator.return();
378
- }
379
- } finally{
380
- if (_didIteratorError) {
381
- throw _iteratorError;
382
- }
383
- }
384
- return [
385
- 7
386
- ];
387
- case 13:
388
- finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName);
389
- if (isPathlessLayout) {
390
- delete finalRoute.path;
391
- }
392
- route.children = (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.filter(function(childRoute) {
393
- return childRoute;
394
- });
395
- if (route.children && route.children.length === 0 && !route.index) {
396
- return [
397
- 2,
398
- null
399
- ];
400
- }
401
- if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
402
- childRoute1 = finalRoute.children[0];
403
- if (childRoute1.path === "*") {
404
- path2 = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
405
- finalRoute = _objectSpreadProps(_objectSpread({}, childRoute1), {
406
- path: path2
407
- });
408
- }
409
- }
410
- return [
411
- 2,
412
- finalRoute
413
- ];
205
+ export var walk = function() {
206
+ var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName) {
207
+ var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, _$path;
208
+ return __generator(this, function(_state) {
209
+ switch (_state.label) {
210
+ case 0:
211
+ return [
212
+ 4,
213
+ fs.pathExists(dirname)
214
+ ];
215
+ case 1:
216
+ if (!_state.sent()) {
217
+ return [
218
+ 2,
219
+ null
220
+ ];
221
+ }
222
+ return [
223
+ 4,
224
+ fs.stat(dirname)
225
+ ];
226
+ case 2:
227
+ isDirectory = _state.sent().isDirectory();
228
+ if (!isDirectory) {
229
+ return [
230
+ 2,
231
+ null
232
+ ];
233
+ }
234
+ relativeDir = path.relative(rootDir, dirname);
235
+ pathSegments = relativeDir.split(path.sep);
236
+ lastSegment = pathSegments[pathSegments.length - 1];
237
+ isRoot = lastSegment === "";
238
+ isPathlessLayout = lastSegment.startsWith("__");
239
+ isWithoutLayoutPath = lastSegment.includes(".");
240
+ routePath = isRoot || isPathlessLayout ? "/" : "".concat(lastSegment);
241
+ if (isWithoutLayoutPath) {
242
+ routePath = lastSegment.split(".").join("/");
243
+ }
244
+ routePath = replaceDynamicPath(routePath);
245
+ route = {
246
+ path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
247
+ children: [],
248
+ isRoot
249
+ };
250
+ pageLoaderFile = "";
251
+ pageRoute = null;
252
+ splatLoaderFile = "";
253
+ splatRoute = null;
254
+ pageConfigFile = "";
255
+ return [
256
+ 4,
257
+ fs.readdir(dirname)
258
+ ];
259
+ case 3:
260
+ items = _state.sent();
261
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
262
+ _state.label = 4;
263
+ case 4:
264
+ _state.trys.push([
265
+ 4,
266
+ 11,
267
+ 12,
268
+ 13
269
+ ]);
270
+ _iterator = items[Symbol.iterator]();
271
+ _state.label = 5;
272
+ case 5:
273
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
274
+ return [
275
+ 3,
276
+ 10
277
+ ];
278
+ item = _step.value;
279
+ itemPath = path.join(dirname, item);
280
+ extname = path.extname(item);
281
+ itemWithoutExt = item.slice(0, -extname.length);
282
+ return [
283
+ 4,
284
+ fs.stat(itemPath)
285
+ ];
286
+ case 6:
287
+ isDirectory1 = _state.sent().isDirectory();
288
+ if (!isDirectory1)
289
+ return [
290
+ 3,
291
+ 8
292
+ ];
293
+ return [
294
+ 4,
295
+ walk(itemPath, rootDir, alias, entryName)
296
+ ];
297
+ case 7:
298
+ childRoute = _state.sent();
299
+ if (childRoute) {
300
+ ;
301
+ (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
302
+ }
303
+ _state.label = 8;
304
+ case 8:
305
+ if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
306
+ return [
307
+ 3,
308
+ 9
309
+ ];
310
+ }
311
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
312
+ if (!route.loader) {
313
+ route.loader = itemPath;
414
314
  }
415
- });
315
+ }
316
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
317
+ if (!route.config) {
318
+ route.config = itemPath;
319
+ }
320
+ }
321
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
322
+ route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
323
+ }
324
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
325
+ pageLoaderFile = itemPath;
326
+ }
327
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
328
+ pageConfigFile = itemPath;
329
+ }
330
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
331
+ ;
332
+ pageRoute = createIndexRoute({
333
+ _component: replaceWithAlias(alias.basename, itemPath, alias.name)
334
+ }, rootDir, itemPath, entryName);
335
+ if (pageLoaderFile) {
336
+ pageRoute.loader = pageLoaderFile;
337
+ }
338
+ if (pageConfigFile) {
339
+ pageRoute.config = pageConfigFile;
340
+ }
341
+ (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
342
+ }
343
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
344
+ splatLoaderFile = itemPath;
345
+ }
346
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
347
+ ;
348
+ splatRoute = createRoute({
349
+ _component: replaceWithAlias(alias.basename, itemPath, alias.name),
350
+ path: "*"
351
+ }, rootDir, itemPath, entryName);
352
+ if (splatLoaderFile) {
353
+ splatRoute.loader = splatLoaderFile;
354
+ }
355
+ (_route_children3 = route.children) === null || _route_children3 === void 0 ? void 0 : _route_children3.push(splatRoute);
356
+ }
357
+ if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
358
+ route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
359
+ }
360
+ if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
361
+ route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
362
+ }
363
+ _state.label = 9;
364
+ case 9:
365
+ _iteratorNormalCompletion = true;
366
+ return [
367
+ 3,
368
+ 5
369
+ ];
370
+ case 10:
371
+ return [
372
+ 3,
373
+ 13
374
+ ];
375
+ case 11:
376
+ err = _state.sent();
377
+ _didIteratorError = true;
378
+ _iteratorError = err;
379
+ return [
380
+ 3,
381
+ 13
382
+ ];
383
+ case 12:
384
+ try {
385
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
386
+ _iterator.return();
387
+ }
388
+ } finally {
389
+ if (_didIteratorError) {
390
+ throw _iteratorError;
391
+ }
392
+ }
393
+ return [
394
+ 7
395
+ ];
396
+ case 13:
397
+ finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName);
398
+ if (isPathlessLayout) {
399
+ delete finalRoute.path;
400
+ }
401
+ route.children = (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.filter(function(childRoute2) {
402
+ return childRoute2;
403
+ });
404
+ if (route.children && route.children.length === 0 && !route.index) {
405
+ return [
406
+ 2,
407
+ null
408
+ ];
409
+ }
410
+ if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
411
+ childRoute1 = finalRoute.children[0];
412
+ if (childRoute1.path === "*") {
413
+ _$path = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
414
+ finalRoute = _object_spread_props(_object_spread({}, childRoute1), {
415
+ path: _$path
416
+ });
417
+ }
418
+ }
419
+ return [
420
+ 2,
421
+ finalRoute
422
+ ];
423
+ }
416
424
  });
417
- return function walk(dirname, rootDir, alias, entryName) {
418
- return _ref.apply(this, arguments);
419
- };
425
+ });
426
+ return function walk2(dirname, rootDir, alias, entryName) {
427
+ return _ref.apply(this, arguments);
428
+ };
420
429
  }();
421
- export { walk };