@modern-js/app-tools 2.31.2 → 2.31.3-alpha.1

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 (259) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/analyze/constants.js +11 -5
  3. package/dist/cjs/analyze/nestedRoutes.js +28 -1
  4. package/dist/cjs/analyze/templates.js +10 -7
  5. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  6. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  7. package/dist/cjs/index.js +16 -0
  8. package/dist/esm/analyze/constants.js +11 -5
  9. package/dist/esm/analyze/nestedRoutes.js +31 -2
  10. package/dist/esm/analyze/templates.js +10 -7
  11. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  12. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  13. package/dist/esm/index.js +42 -1
  14. package/dist/esm-node/analyze/constants.js +11 -5
  15. package/dist/esm-node/analyze/nestedRoutes.js +28 -1
  16. package/dist/esm-node/analyze/templates.js +10 -7
  17. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  18. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +24 -22
  19. package/dist/esm-node/index.js +17 -1
  20. package/dist/js/modern/analyze/constants.js +54 -0
  21. package/dist/js/modern/analyze/generateCode.js +247 -0
  22. package/dist/js/modern/analyze/getBundleEntry.js +71 -0
  23. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  24. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  25. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  26. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  27. package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
  28. package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
  29. package/dist/js/modern/analyze/getServerRoutes.js +175 -0
  30. package/dist/js/modern/analyze/index.js +332 -0
  31. package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
  32. package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
  33. package/dist/js/modern/analyze/nestedRoutes.js +157 -0
  34. package/dist/js/modern/analyze/templates.js +334 -0
  35. package/dist/js/modern/analyze/utils.js +141 -0
  36. package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
  37. package/dist/js/modern/builder/index.js +159 -0
  38. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  39. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  40. package/dist/js/modern/builder/share.js +46 -0
  41. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  42. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  43. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  44. package/dist/js/modern/commands/build.js +91 -0
  45. package/dist/js/modern/commands/deploy.js +28 -0
  46. package/dist/js/modern/commands/dev.js +109 -0
  47. package/dist/js/modern/commands/index.js +3 -0
  48. package/dist/js/modern/commands/inspect.js +38 -0
  49. package/dist/js/modern/commands/serve.js +54 -0
  50. package/dist/js/modern/config/default.js +175 -0
  51. package/dist/js/modern/config/index.js +8 -0
  52. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  53. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  54. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  55. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  56. package/dist/js/modern/config/initial/index.js +16 -0
  57. package/dist/js/modern/config/initial/inits.js +152 -0
  58. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  59. package/dist/js/modern/defineConfig.js +27 -0
  60. package/dist/js/modern/exports/server.js +4 -0
  61. package/dist/js/modern/hooks.js +35 -0
  62. package/dist/js/modern/index.js +211 -0
  63. package/dist/js/modern/initialize/index.js +124 -0
  64. package/dist/js/modern/locale/en.js +36 -0
  65. package/dist/js/modern/locale/index.js +9 -0
  66. package/dist/js/modern/locale/zh.js +36 -0
  67. package/dist/js/modern/schema/Schema.js +40 -0
  68. package/dist/js/modern/schema/index.js +88 -0
  69. package/dist/js/modern/schema/legacy.js +148 -0
  70. package/dist/js/modern/types/config/deploy.js +0 -0
  71. package/dist/js/modern/types/config/dev.js +0 -0
  72. package/dist/js/modern/types/config/experiments.js +0 -0
  73. package/dist/js/modern/types/config/html.js +0 -0
  74. package/dist/js/modern/types/config/index.js +1 -0
  75. package/dist/js/modern/types/config/output.js +0 -0
  76. package/dist/js/modern/types/config/performance.js +0 -0
  77. package/dist/js/modern/types/config/security.js +0 -0
  78. package/dist/js/modern/types/config/source.js +0 -0
  79. package/dist/js/modern/types/config/tools.js +0 -0
  80. package/dist/js/modern/types/hooks.js +0 -0
  81. package/dist/js/modern/types/index.js +3 -0
  82. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  83. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  84. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  85. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  86. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  87. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  88. package/dist/js/modern/utils/config.js +128 -0
  89. package/dist/js/modern/utils/createServer.js +75 -0
  90. package/dist/js/modern/utils/env.js +15 -0
  91. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  92. package/dist/js/modern/utils/getSelectedEntries.js +58 -0
  93. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  94. package/dist/js/modern/utils/language.js +8 -0
  95. package/dist/js/modern/utils/printInstructions.js +31 -0
  96. package/dist/js/modern/utils/restart.js +44 -0
  97. package/dist/js/modern/utils/routes.js +30 -0
  98. package/dist/js/modern/utils/types.js +0 -0
  99. package/dist/js/node/analyze/constants.js +98 -0
  100. package/dist/js/node/analyze/generateCode.js +271 -0
  101. package/dist/js/node/analyze/getBundleEntry.js +95 -0
  102. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  103. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  104. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  105. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  106. package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
  107. package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
  108. package/dist/js/node/analyze/getServerRoutes.js +194 -0
  109. package/dist/js/node/analyze/index.js +339 -0
  110. package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
  111. package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
  112. package/dist/js/node/analyze/nestedRoutes.js +184 -0
  113. package/dist/js/node/analyze/templates.js +365 -0
  114. package/dist/js/node/analyze/utils.js +172 -0
  115. package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
  116. package/dist/js/node/builder/index.js +177 -0
  117. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  118. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  119. package/dist/js/node/builder/share.js +75 -0
  120. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  121. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  122. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  123. package/dist/js/node/commands/build.js +112 -0
  124. package/dist/js/node/commands/deploy.js +51 -0
  125. package/dist/js/node/commands/dev.js +126 -0
  126. package/dist/js/node/commands/index.js +19 -0
  127. package/dist/js/node/commands/inspect.js +61 -0
  128. package/dist/js/node/commands/serve.js +83 -0
  129. package/dist/js/node/config/default.js +197 -0
  130. package/dist/js/node/config/index.js +34 -0
  131. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  132. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  133. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  134. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  135. package/dist/js/node/config/initial/index.js +41 -0
  136. package/dist/js/node/config/initial/inits.js +175 -0
  137. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  138. package/dist/js/node/defineConfig.js +49 -0
  139. package/dist/js/node/exports/server.js +27 -0
  140. package/dist/js/node/hooks.js +54 -0
  141. package/dist/js/node/index.js +235 -0
  142. package/dist/js/node/initialize/index.js +134 -0
  143. package/dist/js/node/locale/en.js +59 -0
  144. package/dist/js/node/locale/index.js +33 -0
  145. package/dist/js/node/locale/zh.js +59 -0
  146. package/dist/js/node/schema/Schema.js +63 -0
  147. package/dist/js/node/schema/index.js +118 -0
  148. package/dist/js/node/schema/legacy.js +169 -0
  149. package/dist/js/node/types/config/deploy.js +15 -0
  150. package/dist/js/node/types/config/dev.js +15 -0
  151. package/dist/js/node/types/config/experiments.js +15 -0
  152. package/dist/js/node/types/config/html.js +15 -0
  153. package/dist/js/node/types/config/index.js +17 -0
  154. package/dist/js/node/types/config/output.js +15 -0
  155. package/dist/js/node/types/config/performance.js +15 -0
  156. package/dist/js/node/types/config/security.js +15 -0
  157. package/dist/js/node/types/config/source.js +15 -0
  158. package/dist/js/node/types/config/tools.js +15 -0
  159. package/dist/js/node/types/hooks.js +15 -0
  160. package/dist/js/node/types/index.js +19 -0
  161. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  162. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  163. package/dist/js/node/types/legacyConfig/index.js +15 -0
  164. package/dist/js/node/types/legacyConfig/output.js +15 -0
  165. package/dist/js/node/types/legacyConfig/source.js +15 -0
  166. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  167. package/dist/js/node/utils/config.js +153 -0
  168. package/dist/js/node/utils/createServer.js +106 -0
  169. package/dist/js/node/utils/env.js +38 -0
  170. package/dist/js/node/utils/generateWatchFiles.js +85 -0
  171. package/dist/js/node/utils/getSelectedEntries.js +81 -0
  172. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  173. package/dist/js/node/utils/language.js +31 -0
  174. package/dist/js/node/utils/printInstructions.js +54 -0
  175. package/dist/js/node/utils/restart.js +67 -0
  176. package/dist/js/node/utils/routes.js +59 -0
  177. package/dist/js/node/utils/types.js +15 -0
  178. package/dist/js/treeshaking/analyze/constants.js +40 -0
  179. package/dist/js/treeshaking/analyze/generateCode.js +485 -0
  180. package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
  181. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  182. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  183. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  184. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  185. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  186. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  187. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  188. package/dist/js/treeshaking/analyze/index.js +697 -0
  189. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  190. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  191. package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
  192. package/dist/js/treeshaking/analyze/templates.js +468 -0
  193. package/dist/js/treeshaking/analyze/utils.js +374 -0
  194. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
  195. package/dist/js/treeshaking/builder/index.js +374 -0
  196. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  197. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  198. package/dist/js/treeshaking/builder/share.js +40 -0
  199. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  200. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  201. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
  202. package/dist/js/treeshaking/commands/build.js +291 -0
  203. package/dist/js/treeshaking/commands/deploy.js +154 -0
  204. package/dist/js/treeshaking/commands/dev.js +301 -0
  205. package/dist/js/treeshaking/commands/index.js +3 -0
  206. package/dist/js/treeshaking/commands/inspect.js +149 -0
  207. package/dist/js/treeshaking/commands/serve.js +199 -0
  208. package/dist/js/treeshaking/config/default.js +210 -0
  209. package/dist/js/treeshaking/config/index.js +3 -0
  210. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  211. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  212. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  213. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  214. package/dist/js/treeshaking/config/initial/index.js +12 -0
  215. package/dist/js/treeshaking/config/initial/inits.js +209 -0
  216. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  217. package/dist/js/treeshaking/defineConfig.js +61 -0
  218. package/dist/js/treeshaking/exports/server.js +2 -0
  219. package/dist/js/treeshaking/hooks.js +29 -0
  220. package/dist/js/treeshaking/index.js +706 -0
  221. package/dist/js/treeshaking/initialize/index.js +276 -0
  222. package/dist/js/treeshaking/locale/en.js +38 -0
  223. package/dist/js/treeshaking/locale/index.js +9 -0
  224. package/dist/js/treeshaking/locale/zh.js +38 -0
  225. package/dist/js/treeshaking/schema/Schema.js +273 -0
  226. package/dist/js/treeshaking/schema/index.js +181 -0
  227. package/dist/js/treeshaking/schema/legacy.js +337 -0
  228. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  229. package/dist/js/treeshaking/types/config/dev.js +1 -0
  230. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  231. package/dist/js/treeshaking/types/config/html.js +1 -0
  232. package/dist/js/treeshaking/types/config/index.js +1 -0
  233. package/dist/js/treeshaking/types/config/output.js +1 -0
  234. package/dist/js/treeshaking/types/config/performance.js +1 -0
  235. package/dist/js/treeshaking/types/config/security.js +1 -0
  236. package/dist/js/treeshaking/types/config/source.js +1 -0
  237. package/dist/js/treeshaking/types/config/tools.js +1 -0
  238. package/dist/js/treeshaking/types/hooks.js +1 -0
  239. package/dist/js/treeshaking/types/index.js +3 -0
  240. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  241. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  242. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  243. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  244. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  245. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  246. package/dist/js/treeshaking/utils/config.js +302 -0
  247. package/dist/js/treeshaking/utils/createServer.js +258 -0
  248. package/dist/js/treeshaking/utils/env.js +13 -0
  249. package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
  250. package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
  251. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  252. package/dist/js/treeshaking/utils/language.js +6 -0
  253. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  254. package/dist/js/treeshaking/utils/restart.js +187 -0
  255. package/dist/js/treeshaking/utils/routes.js +153 -0
  256. package/dist/js/treeshaking/utils/types.js +1 -0
  257. package/dist/types/analyze/constants.d.ts +10 -4
  258. package/dist/types/defineConfig.d.ts +1 -1
  259. package/package.json +16 -16
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Modern.js
3
+ Copyright (c) 2021-present Modern.js
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -106,16 +106,22 @@ const HTML_PARTIALS_EXTENSIONS = [
106
106
  const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
107
107
  const NESTED_ROUTE = {
108
108
  LAYOUT_FILE: "layout",
109
+ LAYOUT_CONFIG_FILE: "layout.config",
109
110
  LAYOUT_LOADER_FILE: "layout.loader",
111
+ LAYOUT_DATA_FILE: "layout.data",
112
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
110
113
  PAGE_FILE: "page",
114
+ PAGE_CONFIG_FILE: "page.config",
111
115
  PAGE_LOADER_FILE: "page.loader",
112
- LOADING_FILE: "loading",
113
- ERROR_FILE: "error",
114
- LOADER_FILE: "loader",
116
+ PAGE_DATA_FILE: "page.data",
117
+ PAGE_CLIENT_LOADER: "page.data.client",
115
118
  SPLATE_FILE: "$",
116
119
  SPLATE_LOADER_FILE: "$.loader",
117
- LAYOUT_CONFIG_FILE: "layout.config",
118
- PAGE_CONFIG_FILE: "page.config"
120
+ SPLATE_DATA_FILE: "$.data",
121
+ SPLATE_CLIENT_DATA: "$.data.client",
122
+ LOADING_FILE: "loading",
123
+ ERROR_FILE: "error",
124
+ LOADER_FILE: "loader"
119
125
  };
120
126
  const APP_CONFIG_NAME = "config";
121
127
  const APP_INIT_EXPORTED = "init";
@@ -66,7 +66,8 @@ const optimizeRoute = (routeTree) => {
66
66
  ];
67
67
  }
68
68
  const { children } = routeTree;
69
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
69
+ const hasPage = children.some((child) => child.index);
70
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
70
71
  const newRoutes = children.map((child) => {
71
72
  const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
72
73
  const newRoute = {
@@ -119,6 +120,8 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
119
120
  let pageLoaderFile = "";
120
121
  let pageRoute = null;
121
122
  let splatLoaderFile = "";
123
+ let splatClientData = "";
124
+ let splatData = "";
122
125
  let splatRoute = null;
123
126
  let pageConfigFile = "";
124
127
  const items = await _utils.fs.readdir(dirname);
@@ -142,6 +145,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
142
145
  route.loader = itemPath;
143
146
  }
144
147
  }
148
+ if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
149
+ route.clientData = itemPath;
150
+ }
151
+ if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_DATA_FILE) {
152
+ route.data = itemPath;
153
+ }
145
154
  if (itemWithoutExt === _constants.NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
146
155
  if (!route.config) {
147
156
  route.config = itemPath;
@@ -153,6 +162,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
153
162
  if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
154
163
  pageLoaderFile = itemPath;
155
164
  }
165
+ if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_CLIENT_LOADER) {
166
+ route.clientData = itemPath;
167
+ }
168
+ if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_DATA_FILE) {
169
+ route.data = itemPath;
170
+ }
156
171
  if (itemWithoutExt === _constants.NESTED_ROUTE.PAGE_CONFIG_FILE) {
157
172
  pageConfigFile = itemPath;
158
173
  }
@@ -172,6 +187,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
172
187
  if (itemWithoutExt === _constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
173
188
  splatLoaderFile = itemPath;
174
189
  }
190
+ if (itemWithoutExt === _constants.NESTED_ROUTE.SPLATE_CLIENT_DATA) {
191
+ splatClientData = itemPath;
192
+ }
193
+ if (itemWithoutExt === _constants.NESTED_ROUTE.SPLATE_DATA_FILE) {
194
+ splatData = itemPath;
195
+ }
175
196
  if (itemWithoutExt === _constants.NESTED_ROUTE.SPLATE_FILE) {
176
197
  var _route_children2;
177
198
  splatRoute = createRoute({
@@ -181,6 +202,12 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
181
202
  if (splatLoaderFile) {
182
203
  splatRoute.loader = splatLoaderFile;
183
204
  }
205
+ if (splatClientData) {
206
+ splatRoute.clientData = splatClientData;
207
+ }
208
+ if (splatData) {
209
+ splatRoute.data = splatData;
210
+ }
184
211
  (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
185
212
  }
186
213
  if (itemWithoutExt === _constants.NESTED_ROUTE.LOADING_FILE) {
@@ -164,12 +164,13 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
164
164
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
165
165
  `;
166
166
  let rootLayoutCode = ``;
167
- const getDataLoaderPath = (loaderId) => {
167
+ const getDataLoaderPath = (loaderId, clientData) => {
168
168
  if (!ssrMode) {
169
169
  return "";
170
170
  }
171
+ const clientDataStr = clientData ? `&clientData=${clientData}` : "";
171
172
  if (nestedRoutesEntry) {
172
- return `?mapFile=${(0, _utils.slash)(loadersMapFile)}&loaderId=${loaderId}`;
173
+ return `?mapFile=${(0, _utils.slash)(loadersMapFile)}&loaderId=${loaderId}${clientDataStr}`;
173
174
  }
174
175
  return "";
175
176
  };
@@ -194,15 +195,17 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
194
195
  errors.push(route.error);
195
196
  error = `error_${errors.length - 1}`;
196
197
  }
197
- if (route.loader) {
198
+ if (route.loader || route.data) {
198
199
  loaders.push(route.loader);
199
200
  const loaderId = loaders.length - 1;
200
201
  loader = `loader_${loaderId}`;
201
202
  loadersMap[loader] = {
202
203
  routeId: route.id,
203
- filePath: route.loader,
204
- inline: false
204
+ filePath: route.data || route.loader,
205
+ clientData: Boolean(route.clientData),
206
+ inline: Boolean(route.data)
205
207
  };
208
+ loader = `loader_${loaderId}`;
206
209
  }
207
210
  if (typeof route.config === "string") {
208
211
  configs.push(route.config);
@@ -301,10 +304,10 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
301
304
  let importLoadersCode = "";
302
305
  for (const [key, loaderInfo] of Object.entries(loadersMap)) {
303
306
  if (loaderInfo.inline) {
304
- importLoadersCode += `import { loader as ${key} } from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key)}";
307
+ importLoadersCode += `import { loader as ${key} } from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
305
308
  `;
306
309
  } else {
307
- importLoadersCode += `import ${key} from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key)}";
310
+ importLoadersCode += `import ${key} from "${(0, _utils.slash)(loaderInfo.filePath)}${getDataLoaderPath(key, loaderInfo.clientData)}";
308
311
  `;
309
312
  }
310
313
  }
@@ -154,6 +154,6 @@ function applySSRDataLoader(chain, options) {
154
154
  const { appDirectory } = appContext;
155
155
  const { entriesDir = "./src" } = normalizedConfig.source;
156
156
  const absolutePath = _path.resolve(appDirectory, entriesDir).split(_path.sep).join("(\\\\|/)");
157
- const reg = new RegExp(`${absolutePath}.*\\.loader\\.[t|j]s$`);
157
+ const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
158
158
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
159
159
  }
@@ -164,28 +164,30 @@ class RouterPlugin {
164
164
  const oldHtml = compilation.assets[htmlName];
165
165
  const { enableInlineRouteManifests, disableFilenameHash, staticJsDir, scriptLoading, nonce } = this;
166
166
  const nonceAttr = nonce ? `nonce="${nonce}"` : "";
167
- if (enableInlineRouteManifests) {
168
- compilation.updateAsset(
169
- htmlName,
170
- new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
171
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
172
- void 0
173
- );
174
- } else {
175
- const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
176
- const scriptUrl = `${publicPath}${scriptPath}`;
177
- const scriptLoadingAttr = (
178
- // eslint-disable-next-line no-nested-ternary
179
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
180
- );
181
- const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
182
- compilation.updateAsset(
183
- htmlName,
184
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
185
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
186
- void 0
187
- );
188
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
167
+ if (oldHtml) {
168
+ if (enableInlineRouteManifests) {
169
+ compilation.updateAsset(
170
+ htmlName,
171
+ new RawSource(oldHtml.source().toString().replace(placeholder, `<script ${nonceAttr}>${injectedContent}</script>`)),
172
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
173
+ void 0
174
+ );
175
+ } else {
176
+ const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
177
+ const scriptUrl = `${publicPath}${scriptPath}`;
178
+ const scriptLoadingAttr = (
179
+ // eslint-disable-next-line no-nested-ternary
180
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
181
+ );
182
+ const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
183
+ compilation.updateAsset(
184
+ htmlName,
185
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
186
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
187
+ void 0
188
+ );
189
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
190
+ }
189
191
  }
190
192
  }
191
193
  if (prevManifestAsset) {
package/dist/cjs/index.js CHANGED
@@ -123,6 +123,7 @@ const appTools = (options = {
123
123
  ...appContext,
124
124
  toolsType: "app-tools"
125
125
  });
126
+ const nestedRoutes = {};
126
127
  const locale = (0, _languagedetector.getLocaleLanguage)();
127
128
  _locale.i18n.changeLanguage({
128
129
  locale
@@ -208,6 +209,21 @@ const appTools = (options = {
208
209
  (0, _utils.cleanRequireCache)([
209
210
  require.resolve("./analyze")
210
211
  ]);
212
+ },
213
+ async modifyFileSystemRoutes({ entrypoint, routes }) {
214
+ nestedRoutes[entrypoint.entryName] = routes;
215
+ return {
216
+ entrypoint,
217
+ routes
218
+ };
219
+ },
220
+ async beforeGenerateRoutes({ entrypoint, code }) {
221
+ const { distDirectory } = api.useAppContext();
222
+ await _utils.fs.outputJSON(_path.default.resolve(distDirectory, _utils.NESTED_ROUTE_SPEC_FILE), nestedRoutes);
223
+ return {
224
+ entrypoint,
225
+ code
226
+ };
211
227
  }
212
228
  };
213
229
  }
@@ -27,16 +27,22 @@ export var HTML_PARTIALS_EXTENSIONS = [
27
27
  export var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
28
28
  export var NESTED_ROUTE = {
29
29
  LAYOUT_FILE: "layout",
30
+ LAYOUT_CONFIG_FILE: "layout.config",
30
31
  LAYOUT_LOADER_FILE: "layout.loader",
32
+ LAYOUT_DATA_FILE: "layout.data",
33
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
31
34
  PAGE_FILE: "page",
35
+ PAGE_CONFIG_FILE: "page.config",
32
36
  PAGE_LOADER_FILE: "page.loader",
33
- LOADING_FILE: "loading",
34
- ERROR_FILE: "error",
35
- LOADER_FILE: "loader",
37
+ PAGE_DATA_FILE: "page.data",
38
+ PAGE_CLIENT_LOADER: "page.data.client",
36
39
  SPLATE_FILE: "$",
37
40
  SPLATE_LOADER_FILE: "$.loader",
38
- LAYOUT_CONFIG_FILE: "layout.config",
39
- PAGE_CONFIG_FILE: "page.config"
41
+ SPLATE_DATA_FILE: "$.data",
42
+ SPLATE_CLIENT_DATA: "$.data.client",
43
+ LOADING_FILE: "loading",
44
+ ERROR_FILE: "error",
45
+ LOADER_FILE: "loader"
40
46
  };
41
47
  export var APP_CONFIG_NAME = "config";
42
48
  export var APP_INIT_EXPORTED = "init";
@@ -45,7 +45,10 @@ export var optimizeRoute = function(routeTree) {
45
45
  ];
46
46
  }
47
47
  var children = routeTree.children;
48
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
48
+ var hasPage = children.some(function(child) {
49
+ return child.index;
50
+ });
51
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
49
52
  var newRoutes = children.map(function(child) {
50
53
  var routePath = "".concat(routeTree.path ? routeTree.path : "").concat(child.path ? "/".concat(child.path) : "");
51
54
  var newRoute = _object_spread_props(_object_spread({}, child), {
@@ -70,7 +73,7 @@ export var optimizeRoute = function(routeTree) {
70
73
  };
71
74
  export var walk = function() {
72
75
  var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
73
- var _routePath, _finalRoute_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_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, optimizedRoutes;
76
+ var _routePath, _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatClientData, splatData, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, optimizedRoutes;
74
77
  return _ts_generator(this, function(_state) {
75
78
  switch (_state.label) {
76
79
  case 0:
@@ -116,6 +119,8 @@ export var walk = function() {
116
119
  pageLoaderFile = "";
117
120
  pageRoute = null;
118
121
  splatLoaderFile = "";
122
+ splatClientData = "";
123
+ splatData = "";
119
124
  splatRoute = null;
120
125
  pageConfigFile = "";
121
126
  return [
@@ -179,6 +184,12 @@ export var walk = function() {
179
184
  route.loader = itemPath;
180
185
  }
181
186
  }
187
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
188
+ route.clientData = itemPath;
189
+ }
190
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_DATA_FILE) {
191
+ route.data = itemPath;
192
+ }
182
193
  if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
183
194
  if (!route.config) {
184
195
  route.config = itemPath;
@@ -190,6 +201,12 @@ export var walk = function() {
190
201
  if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
191
202
  pageLoaderFile = itemPath;
192
203
  }
204
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CLIENT_LOADER) {
205
+ route.clientData = itemPath;
206
+ }
207
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE) {
208
+ route.data = itemPath;
209
+ }
193
210
  if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
194
211
  pageConfigFile = itemPath;
195
212
  }
@@ -209,6 +226,12 @@ export var walk = function() {
209
226
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
210
227
  splatLoaderFile = itemPath;
211
228
  }
229
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_CLIENT_DATA) {
230
+ splatClientData = itemPath;
231
+ }
232
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE) {
233
+ splatData = itemPath;
234
+ }
212
235
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
213
236
  ;
214
237
  splatRoute = createRoute({
@@ -218,6 +241,12 @@ export var walk = function() {
218
241
  if (splatLoaderFile) {
219
242
  splatRoute.loader = splatLoaderFile;
220
243
  }
244
+ if (splatClientData) {
245
+ splatRoute.clientData = splatClientData;
246
+ }
247
+ if (splatData) {
248
+ splatRoute.data = splatData;
249
+ }
221
250
  (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
222
251
  }
223
252
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
@@ -99,12 +99,13 @@ export var fileSystemRoutes = function() {
99
99
  loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
100
100
  importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
101
101
  rootLayoutCode = "";
102
- getDataLoaderPath = function(loaderId) {
102
+ getDataLoaderPath = function(loaderId, clientData) {
103
103
  if (!ssrMode) {
104
104
  return "";
105
105
  }
106
+ var clientDataStr = clientData ? "&clientData=".concat(clientData) : "";
106
107
  if (nestedRoutesEntry) {
107
- return "?mapFile=".concat(slash(loadersMapFile), "&loaderId=").concat(loaderId);
108
+ return "?mapFile=".concat(slash(loadersMapFile), "&loaderId=").concat(loaderId).concat(clientDataStr);
108
109
  }
109
110
  return "";
110
111
  };
@@ -129,15 +130,17 @@ export var fileSystemRoutes = function() {
129
130
  errors.push(route2.error);
130
131
  error = "error_".concat(errors.length - 1);
131
132
  }
132
- if (route2.loader) {
133
+ if (route2.loader || route2.data) {
133
134
  loaders.push(route2.loader);
134
135
  var loaderId = loaders.length - 1;
135
136
  loader = "loader_".concat(loaderId);
136
137
  loadersMap[loader] = {
137
138
  routeId: route2.id,
138
- filePath: route2.loader,
139
- inline: false
139
+ filePath: route2.data || route2.loader,
140
+ clientData: Boolean(route2.clientData),
141
+ inline: Boolean(route2.data)
140
142
  };
143
+ loader = "loader_".concat(loaderId);
141
144
  }
142
145
  if (typeof route2.config === "string") {
143
146
  configs.push(route2.config);
@@ -252,9 +255,9 @@ export var fileSystemRoutes = function() {
252
255
  for (_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
253
256
  _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
254
257
  if (loaderInfo.inline) {
255
- importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key), '";\n');
258
+ importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key, loaderInfo.clientData), '";\n');
256
259
  } else {
257
- importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key), '";\n');
260
+ importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath(key, loaderInfo.clientData), '";\n');
258
261
  }
259
262
  }
260
263
  } catch (err) {
@@ -253,6 +253,6 @@ function applySSRDataLoader(chain, options) {
253
253
  var appDirectory = appContext.appDirectory;
254
254
  var _normalizedConfig_source = normalizedConfig.source, _normalizedConfig_source_entriesDir = _normalizedConfig_source.entriesDir, entriesDir = _normalizedConfig_source_entriesDir === void 0 ? "./src" : _normalizedConfig_source_entriesDir;
255
255
  var absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
256
- var reg = new RegExp("".concat(absolutePath, ".*\\.loader\\.[t|j]s$"));
256
+ var reg = new RegExp("".concat(absolutePath, ".*\\.(loader|data|data.client)\\.[t|j]sx?$"));
257
257
  chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
258
258
  }
@@ -172,28 +172,30 @@ export var RouterPlugin = /* @__PURE__ */ function() {
172
172
  var oldHtml = compilation.assets[htmlName];
173
173
  var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
174
174
  var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
175
- if (enableInlineRouteManifests) {
176
- compilation.updateAsset(
177
- htmlName,
178
- new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
179
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
180
- void 0
181
- );
182
- } else {
183
- var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
184
- var scriptUrl = "".concat(publicPath).concat(scriptPath);
185
- var scriptLoadingAttr = (
186
- // eslint-disable-next-line no-nested-ternary
187
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
188
- );
189
- var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
190
- compilation.updateAsset(
191
- htmlName,
192
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
193
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
194
- void 0
195
- );
196
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
175
+ if (oldHtml) {
176
+ if (enableInlineRouteManifests) {
177
+ compilation.updateAsset(
178
+ htmlName,
179
+ new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
180
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
181
+ void 0
182
+ );
183
+ } else {
184
+ var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
185
+ var scriptUrl = "".concat(publicPath).concat(scriptPath);
186
+ var scriptLoadingAttr = (
187
+ // eslint-disable-next-line no-nested-ternary
188
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
189
+ );
190
+ var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
191
+ compilation.updateAsset(
192
+ htmlName,
193
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
194
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
195
+ void 0
196
+ );
197
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
198
+ }
197
199
  }
198
200
  };
199
201
  stats = compilation.getStats().toJson({
package/dist/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "path";
6
6
  import { lintPlugin } from "@modern-js/plugin-lint";
7
- import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
7
+ import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
8
8
  import { castArray } from "@modern-js/utils/lodash";
9
9
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
10
10
  import analyzePlugin from "./analyze";
@@ -301,6 +301,7 @@ export var appTools = function() {
301
301
  api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
302
302
  toolsType: "app-tools"
303
303
  }));
304
+ var nestedRoutes = {};
304
305
  var locale = getLocaleLanguage();
305
306
  i18n.changeLanguage({
306
307
  locale: locale
@@ -601,6 +602,46 @@ export var appTools = function() {
601
602
  ];
602
603
  });
603
604
  })();
605
+ },
606
+ modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
607
+ var entrypoint = param.entrypoint, routes = param.routes;
608
+ return _async_to_generator(function() {
609
+ return _ts_generator(this, function(_state) {
610
+ nestedRoutes[entrypoint.entryName] = routes;
611
+ return [
612
+ 2,
613
+ {
614
+ entrypoint: entrypoint,
615
+ routes: routes
616
+ }
617
+ ];
618
+ });
619
+ })();
620
+ },
621
+ beforeGenerateRoutes: function beforeGenerateRoutes(param) {
622
+ var entrypoint = param.entrypoint, code = param.code;
623
+ return _async_to_generator(function() {
624
+ var distDirectory;
625
+ return _ts_generator(this, function(_state) {
626
+ switch (_state.label) {
627
+ case 0:
628
+ distDirectory = api.useAppContext().distDirectory;
629
+ return [
630
+ 4,
631
+ fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes)
632
+ ];
633
+ case 1:
634
+ _state.sent();
635
+ return [
636
+ 2,
637
+ {
638
+ entrypoint: entrypoint,
639
+ code: code
640
+ }
641
+ ];
642
+ }
643
+ });
644
+ })();
604
645
  }
605
646
  };
606
647
  }
@@ -27,16 +27,22 @@ export const HTML_PARTIALS_EXTENSIONS = [
27
27
  export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
28
28
  export const NESTED_ROUTE = {
29
29
  LAYOUT_FILE: "layout",
30
+ LAYOUT_CONFIG_FILE: "layout.config",
30
31
  LAYOUT_LOADER_FILE: "layout.loader",
32
+ LAYOUT_DATA_FILE: "layout.data",
33
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
31
34
  PAGE_FILE: "page",
35
+ PAGE_CONFIG_FILE: "page.config",
32
36
  PAGE_LOADER_FILE: "page.loader",
33
- LOADING_FILE: "loading",
34
- ERROR_FILE: "error",
35
- LOADER_FILE: "loader",
37
+ PAGE_DATA_FILE: "page.data",
38
+ PAGE_CLIENT_LOADER: "page.data.client",
36
39
  SPLATE_FILE: "$",
37
40
  SPLATE_LOADER_FILE: "$.loader",
38
- LAYOUT_CONFIG_FILE: "layout.config",
39
- PAGE_CONFIG_FILE: "page.config"
41
+ SPLATE_DATA_FILE: "$.data",
42
+ SPLATE_CLIENT_DATA: "$.data.client",
43
+ LOADING_FILE: "loading",
44
+ ERROR_FILE: "error",
45
+ LOADER_FILE: "loader"
40
46
  };
41
47
  export const APP_CONFIG_NAME = "config";
42
48
  export const APP_INIT_EXPORTED = "init";
@@ -43,7 +43,8 @@ export const optimizeRoute = (routeTree) => {
43
43
  ];
44
44
  }
45
45
  const { children } = routeTree;
46
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config) {
46
+ const hasPage = children.some((child) => child.index);
47
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData && !hasPage) {
47
48
  const newRoutes = children.map((child) => {
48
49
  const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
49
50
  const newRoute = {
@@ -96,6 +97,8 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
96
97
  let pageLoaderFile = "";
97
98
  let pageRoute = null;
98
99
  let splatLoaderFile = "";
100
+ let splatClientData = "";
101
+ let splatData = "";
99
102
  let splatRoute = null;
100
103
  let pageConfigFile = "";
101
104
  const items = await fs.readdir(dirname);
@@ -119,6 +122,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
119
122
  route.loader = itemPath;
120
123
  }
121
124
  }
125
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
126
+ route.clientData = itemPath;
127
+ }
128
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_DATA_FILE) {
129
+ route.data = itemPath;
130
+ }
122
131
  if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
123
132
  if (!route.config) {
124
133
  route.config = itemPath;
@@ -130,6 +139,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
130
139
  if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
131
140
  pageLoaderFile = itemPath;
132
141
  }
142
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CLIENT_LOADER) {
143
+ route.clientData = itemPath;
144
+ }
145
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE) {
146
+ route.data = itemPath;
147
+ }
133
148
  if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
134
149
  pageConfigFile = itemPath;
135
150
  }
@@ -149,6 +164,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
149
164
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
150
165
  splatLoaderFile = itemPath;
151
166
  }
167
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_CLIENT_DATA) {
168
+ splatClientData = itemPath;
169
+ }
170
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE) {
171
+ splatData = itemPath;
172
+ }
152
173
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
153
174
  var _route_children2;
154
175
  splatRoute = createRoute({
@@ -158,6 +179,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
158
179
  if (splatLoaderFile) {
159
180
  splatRoute.loader = splatLoaderFile;
160
181
  }
182
+ if (splatClientData) {
183
+ splatRoute.clientData = splatClientData;
184
+ }
185
+ if (splatData) {
186
+ splatRoute.data = splatData;
187
+ }
161
188
  (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
162
189
  }
163
190
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {