@modern-js/app-tools 2.27.1-alpha.0 → 2.28.1-alpha.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 (49) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/cjs/analyze/generateCode.js +16 -7
  3. package/dist/cjs/analyze/getFileSystemEntry.js +2 -1
  4. package/dist/cjs/analyze/getServerRoutes.js +5 -4
  5. package/dist/cjs/analyze/index.js +209 -211
  6. package/dist/cjs/analyze/nestedRoutes.js +58 -15
  7. package/dist/cjs/analyze/templates.js +4 -4
  8. package/dist/cjs/builder/builder-rspack/adapterCopy.js +41 -43
  9. package/dist/cjs/builder/builder-webpack/adapterModern.js +23 -25
  10. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +2 -1
  11. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -15
  12. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
  13. package/dist/cjs/commands/build.js +2 -1
  14. package/dist/cjs/commands/inspect.js +2 -1
  15. package/dist/cjs/commands/serve.js +2 -2
  16. package/dist/cjs/index.js +3 -2
  17. package/dist/cjs/initialize/index.js +70 -72
  18. package/dist/esm/analyze/generateCode.js +35 -10
  19. package/dist/esm/analyze/getFileSystemEntry.js +2 -1
  20. package/dist/esm/analyze/getServerRoutes.js +5 -4
  21. package/dist/esm/analyze/nestedRoutes.js +59 -13
  22. package/dist/esm/analyze/templates.js +4 -4
  23. package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -1
  24. package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -1
  25. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +13 -16
  26. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +41 -101
  27. package/dist/esm/commands/build.js +2 -2
  28. package/dist/esm/commands/inspect.js +2 -2
  29. package/dist/esm/commands/serve.js +2 -2
  30. package/dist/esm/index.js +3 -2
  31. package/dist/esm-node/analyze/generateCode.js +16 -7
  32. package/dist/esm-node/analyze/getFileSystemEntry.js +2 -1
  33. package/dist/esm-node/analyze/getServerRoutes.js +5 -4
  34. package/dist/esm-node/analyze/index.js +209 -211
  35. package/dist/esm-node/analyze/nestedRoutes.js +55 -15
  36. package/dist/esm-node/analyze/templates.js +4 -4
  37. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +41 -43
  38. package/dist/esm-node/builder/builder-webpack/adapterModern.js +23 -25
  39. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +2 -1
  40. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -15
  41. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
  42. package/dist/esm-node/commands/build.js +2 -1
  43. package/dist/esm-node/commands/inspect.js +2 -1
  44. package/dist/esm-node/commands/serve.js +2 -2
  45. package/dist/esm-node/index.js +3 -2
  46. package/dist/esm-node/initialize/index.js +70 -72
  47. package/dist/types/analyze/nestedRoutes.d.ts +2 -1
  48. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +0 -8
  49. package/package.json +24 -24
@@ -11,234 +11,232 @@ import { checkIsBuildCommands, isPageComponentFile, parseModule, replaceWithAlia
11
11
  import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
12
12
  import { generateIndexCode } from "./generateCode";
13
13
  const debug = createDebugger("plugin-analyze");
14
- export default ({ bundler }) => {
15
- return {
16
- name: "@modern-js/plugin-analyze",
17
- setup: (api) => {
18
- let pagesDir = [];
19
- let nestedRouteEntries = [];
20
- let originEntrypoints = [];
21
- return {
22
- async prepare() {
23
- var _resolvedConfig_source;
24
- let appContext = api.useAppContext();
25
- const resolvedConfig = api.useResolvedConfigContext();
26
- const hookRunners = api.useHookRunners();
27
- try {
28
- if (checkIsBuildCommands()) {
29
- fs.emptydirSync(appContext.internalDirectory);
30
- }
31
- } catch {
32
- }
33
- const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
34
- await hookRunners.addRuntimeExports();
35
- if (apiOnly) {
36
- const { routes: routes2 } = await hookRunners.modifyServerRoutes({
37
- routes: []
38
- });
39
- debug(`server routes: %o`, routes2);
40
- appContext = {
41
- ...api.useAppContext(),
42
- apiOnly,
43
- serverRoutes: routes2
44
- };
45
- api.setAppContext(appContext);
46
- return;
14
+ export default ({ bundler }) => ({
15
+ name: "@modern-js/plugin-analyze",
16
+ setup: (api) => {
17
+ let pagesDir = [];
18
+ let nestedRouteEntries = [];
19
+ let originEntrypoints = [];
20
+ return {
21
+ async prepare() {
22
+ var _resolvedConfig_source;
23
+ let appContext = api.useAppContext();
24
+ const resolvedConfig = api.useResolvedConfigContext();
25
+ const hookRunners = api.useHookRunners();
26
+ try {
27
+ if (checkIsBuildCommands()) {
28
+ fs.emptydirSync(appContext.internalDirectory);
47
29
  }
48
- const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
49
- import("./getBundleEntry"),
50
- import("./getServerRoutes"),
51
- import("./generateCode"),
52
- import("./getHtmlTemplate")
53
- ]);
54
- const entrypoints = getBundleEntry(appContext, resolvedConfig);
55
- debug(`entrypoints: %o`, entrypoints);
56
- const initialRoutes = getServerRoutes(entrypoints, {
57
- appContext,
58
- config: resolvedConfig
59
- });
60
- const { routes } = await hookRunners.modifyServerRoutes({
61
- routes: initialRoutes
62
- });
63
- debug(`server routes: %o`, routes);
64
- appContext = {
65
- ...api.useAppContext(),
66
- entrypoints,
67
- serverRoutes: routes
68
- };
69
- api.setAppContext(appContext);
70
- nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
71
- pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
72
- originEntrypoints = cloneDeep(entrypoints);
73
- const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
74
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
75
- appContext,
76
- config: resolvedConfig
30
+ } catch {
31
+ }
32
+ const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
33
+ await hookRunners.addRuntimeExports();
34
+ if (apiOnly) {
35
+ const { routes: routes2 } = await hookRunners.modifyServerRoutes({
36
+ routes: []
77
37
  });
78
- debug(`html templates: %o`, htmlTemplates);
79
- await hookRunners.addDefineTypes();
80
- debug(`add Define Types`);
81
- let checkedEntries = entrypoints.map((point) => point.entryName);
82
- if (isDevCommand()) {
83
- const { entry } = minimist(getArgv());
84
- checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
85
- }
38
+ debug(`server routes: %o`, routes2);
86
39
  appContext = {
87
40
  ...api.useAppContext(),
88
- entrypoints,
89
- checkedEntries,
90
41
  apiOnly,
91
- serverRoutes: routes,
92
- htmlTemplates
42
+ serverRoutes: routes2
93
43
  };
94
44
  api.setAppContext(appContext);
95
- if (checkIsBuildCommands()) {
96
- const normalizedConfig = api.useResolvedConfigContext();
97
- const createBuilderForModern = await createBuilderGenerator(bundler);
98
- const builder = await createBuilderForModern({
99
- normalizedConfig,
100
- appContext
45
+ return;
46
+ }
47
+ const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
48
+ import("./getBundleEntry"),
49
+ import("./getServerRoutes"),
50
+ import("./generateCode"),
51
+ import("./getHtmlTemplate")
52
+ ]);
53
+ const entrypoints = getBundleEntry(appContext, resolvedConfig);
54
+ debug(`entrypoints: %o`, entrypoints);
55
+ const initialRoutes = getServerRoutes(entrypoints, {
56
+ appContext,
57
+ config: resolvedConfig
58
+ });
59
+ const { routes } = await hookRunners.modifyServerRoutes({
60
+ routes: initialRoutes
61
+ });
62
+ debug(`server routes: %o`, routes);
63
+ appContext = {
64
+ ...api.useAppContext(),
65
+ entrypoints,
66
+ serverRoutes: routes
67
+ };
68
+ api.setAppContext(appContext);
69
+ nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
70
+ pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
71
+ originEntrypoints = cloneDeep(entrypoints);
72
+ const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
73
+ const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
74
+ appContext,
75
+ config: resolvedConfig
76
+ });
77
+ debug(`html templates: %o`, htmlTemplates);
78
+ await hookRunners.addDefineTypes();
79
+ debug(`add Define Types`);
80
+ let checkedEntries = entrypoints.map((point) => point.entryName);
81
+ if (isDevCommand()) {
82
+ const { entry } = minimist(getArgv());
83
+ checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
84
+ }
85
+ appContext = {
86
+ ...api.useAppContext(),
87
+ entrypoints,
88
+ checkedEntries,
89
+ apiOnly,
90
+ serverRoutes: routes,
91
+ htmlTemplates
92
+ };
93
+ api.setAppContext(appContext);
94
+ if (checkIsBuildCommands()) {
95
+ const normalizedConfig = api.useResolvedConfigContext();
96
+ const createBuilderForModern = await createBuilderGenerator(bundler);
97
+ const builder = await createBuilderForModern({
98
+ normalizedConfig,
99
+ appContext
100
+ });
101
+ builder.onBeforeBuild(async ({ bundlerConfigs }) => {
102
+ const hookRunners2 = api.useHookRunners();
103
+ await generateRoutes(appContext);
104
+ await hookRunners2.beforeBuild({
105
+ bundlerConfigs
101
106
  });
102
- builder.onBeforeBuild(async ({ bundlerConfigs }) => {
103
- const hookRunners2 = api.useHookRunners();
104
- await generateRoutes(appContext);
105
- await hookRunners2.beforeBuild({
106
- bundlerConfigs
107
- });
107
+ });
108
+ builder.onAfterBuild(async ({ stats }) => {
109
+ const hookRunners2 = api.useHookRunners();
110
+ await hookRunners2.afterBuild({
111
+ stats
108
112
  });
109
- builder.onAfterBuild(async ({ stats }) => {
110
- const hookRunners2 = api.useHookRunners();
111
- await hookRunners2.afterBuild({
112
- stats
113
+ await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
114
+ });
115
+ builder.onDevCompileDone(async ({ isFirstCompile }) => {
116
+ const hookRunners2 = api.useHookRunners();
117
+ if (process.stdout.isTTY || isFirstCompile) {
118
+ hookRunners2.afterDev({
119
+ isFirstCompile
113
120
  });
114
- await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
115
- });
116
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
117
- const hookRunners2 = api.useHookRunners();
118
- if (process.stdout.isTTY || isFirstCompile) {
119
- hookRunners2.afterDev({
120
- isFirstCompile
121
- });
122
- if (isFirstCompile) {
123
- printInstructions(hookRunners2, appContext, normalizedConfig);
124
- }
121
+ if (isFirstCompile) {
122
+ printInstructions(hookRunners2, appContext, normalizedConfig);
125
123
  }
124
+ }
125
+ });
126
+ builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
127
+ const hookRunners2 = api.useHookRunners();
128
+ await generateIndexCode({
129
+ appContext,
130
+ config: resolvedConfig,
131
+ entrypoints,
132
+ api,
133
+ importsStatemets,
134
+ bundlerConfigs
126
135
  });
127
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
128
- const hookRunners2 = api.useHookRunners();
129
- await generateIndexCode({
130
- appContext,
131
- config: resolvedConfig,
132
- entrypoints,
133
- api,
134
- importsStatemets,
135
- bundlerConfigs
136
- });
137
- await hookRunners2.beforeCreateCompiler({
138
- bundlerConfigs
139
- });
136
+ await hookRunners2.beforeCreateCompiler({
137
+ bundlerConfigs
140
138
  });
141
- builder.onAfterCreateCompiler(async ({ compiler }) => {
142
- const hookRunners2 = api.useHookRunners();
143
- await hookRunners2.afterCreateCompiler({
144
- compiler
145
- });
139
+ });
140
+ builder.onAfterCreateCompiler(async ({ compiler }) => {
141
+ const hookRunners2 = api.useHookRunners();
142
+ await hookRunners2.afterCreateCompiler({
143
+ compiler
146
144
  });
147
- builder.addPlugins(resolvedConfig.builderPlugins);
148
- appContext = {
149
- ...api.useAppContext(),
150
- builder
151
- };
152
- api.setAppContext(appContext);
153
- }
154
- },
155
- watchFiles() {
156
- return {
157
- files: pagesDir,
158
- isPrivate: true
159
- };
160
- },
161
- resolvedConfig({ resolved }) {
162
- const appContext = api.useAppContext();
163
- const config = initialNormalizedConfig(resolved, appContext, bundler);
164
- return {
165
- resolved: config
145
+ });
146
+ builder.addPlugins(resolvedConfig.builderPlugins);
147
+ appContext = {
148
+ ...api.useAppContext(),
149
+ builder
166
150
  };
167
- },
168
- // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
169
- async modifyEntryImports({ entrypoint, imports }) {
170
- const appContext = api.useAppContext();
171
- const { srcDirectory, internalSrcAlias } = appContext;
172
- const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
173
- if (fileSystemRoutes && nestedRoutesEntry) {
174
- const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
175
- const rootLayoutFile = findExists([
176
- ".js",
177
- ".ts",
178
- ".jsx",
179
- ".tsx"
180
- ].map((ext) => `${rootLayoutPath}${ext}`));
181
- if (rootLayoutFile) {
182
- const rootLayoutBuffer = await fs.readFile(rootLayoutFile);
183
- const rootLayout = rootLayoutBuffer.toString();
184
- const [, moduleExports] = await parseModule({
185
- source: rootLayout.toString(),
186
- filename: rootLayoutFile
151
+ api.setAppContext(appContext);
152
+ }
153
+ },
154
+ watchFiles() {
155
+ return {
156
+ files: pagesDir,
157
+ isPrivate: true
158
+ };
159
+ },
160
+ resolvedConfig({ resolved }) {
161
+ const appContext = api.useAppContext();
162
+ const config = initialNormalizedConfig(resolved, appContext, bundler);
163
+ return {
164
+ resolved: config
165
+ };
166
+ },
167
+ // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
168
+ async modifyEntryImports({ entrypoint, imports }) {
169
+ const appContext = api.useAppContext();
170
+ const { srcDirectory, internalSrcAlias } = appContext;
171
+ const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
172
+ if (fileSystemRoutes && nestedRoutesEntry) {
173
+ const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
174
+ const rootLayoutFile = findExists([
175
+ ".js",
176
+ ".ts",
177
+ ".jsx",
178
+ ".tsx"
179
+ ].map((ext) => `${rootLayoutPath}${ext}`));
180
+ if (rootLayoutFile) {
181
+ const rootLayoutBuffer = await fs.readFile(rootLayoutFile);
182
+ const rootLayout = rootLayoutBuffer.toString();
183
+ const [, moduleExports] = await parseModule({
184
+ source: rootLayout.toString(),
185
+ filename: rootLayoutFile
186
+ });
187
+ const hasAppConfig = moduleExports.some((e) => e.n === APP_CONFIG_NAME);
188
+ const generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias);
189
+ if (hasAppConfig) {
190
+ imports.push({
191
+ value: generateLayoutPath,
192
+ specifiers: [
193
+ {
194
+ imported: APP_CONFIG_NAME
195
+ }
196
+ ]
187
197
  });
188
- const hasAppConfig = moduleExports.some((e) => e.n === APP_CONFIG_NAME);
189
- const generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias);
190
- if (hasAppConfig) {
191
- imports.push({
192
- value: generateLayoutPath,
193
- specifiers: [
194
- {
195
- imported: APP_CONFIG_NAME
196
- }
197
- ]
198
- });
199
- }
200
- const hasAppInit = moduleExports.some((e) => e.n === APP_INIT_EXPORTED);
201
- if (hasAppInit) {
202
- imports.push({
203
- value: generateLayoutPath,
204
- specifiers: [
205
- {
206
- imported: APP_INIT_EXPORTED,
207
- local: APP_INIT_IMPORTED
208
- }
209
- ]
210
- });
211
- }
212
198
  }
213
- }
214
- return {
215
- entrypoint,
216
- imports
217
- };
218
- },
219
- validateSchema() {
220
- return {
221
- target: "output.splitRouteChunks",
222
- schema: {
223
- type: "boolean"
199
+ const hasAppInit = moduleExports.some((e) => e.n === APP_INIT_EXPORTED);
200
+ if (hasAppInit) {
201
+ imports.push({
202
+ value: generateLayoutPath,
203
+ specifiers: [
204
+ {
205
+ imported: APP_INIT_EXPORTED,
206
+ local: APP_INIT_IMPORTED
207
+ }
208
+ ]
209
+ });
224
210
  }
225
- };
226
- },
227
- async fileChange(e) {
228
- const appContext = api.useAppContext();
229
- const { appDirectory } = appContext;
230
- const { filename, eventType } = e;
231
- const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
232
- const absoluteFilePath = path.resolve(appDirectory, filename);
233
- const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
234
- if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
235
- const resolvedConfig = api.useResolvedConfigContext();
236
- const { generateCode } = await import("./generateCode");
237
- const entrypoints = cloneDeep(originEntrypoints);
238
- generateCode(appContext, resolvedConfig, entrypoints, api);
239
211
  }
240
212
  }
241
- };
242
- }
243
- };
244
- };
213
+ return {
214
+ entrypoint,
215
+ imports
216
+ };
217
+ },
218
+ validateSchema() {
219
+ return {
220
+ target: "output.splitRouteChunks",
221
+ schema: {
222
+ type: "boolean"
223
+ }
224
+ };
225
+ },
226
+ async fileChange(e) {
227
+ const appContext = api.useAppContext();
228
+ const { appDirectory } = appContext;
229
+ const { filename, eventType } = e;
230
+ const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
231
+ const absoluteFilePath = path.resolve(appDirectory, filename);
232
+ const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
233
+ if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
234
+ const resolvedConfig = api.useResolvedConfigContext();
235
+ const { generateCode } = await import("./generateCode");
236
+ const entrypoints = cloneDeep(originEntrypoints);
237
+ generateCode(appContext, resolvedConfig, entrypoints, api);
238
+ }
239
+ }
240
+ };
241
+ }
242
+ });
@@ -36,8 +36,35 @@ const createRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
36
36
  type: "nested"
37
37
  };
38
38
  };
39
- export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
40
- var _route_children;
39
+ export const optimizeRoute = (routeTree) => {
40
+ if (!routeTree.children || routeTree.children.length === 0) {
41
+ return [
42
+ routeTree
43
+ ];
44
+ }
45
+ const { children } = routeTree;
46
+ if (!routeTree._component) {
47
+ const newRoutes = children.map((child) => {
48
+ var _routeTree_path;
49
+ const routePath = `${(_routeTree_path = routeTree.path) !== null && _routeTree_path !== void 0 ? _routeTree_path : ""}${child.path ? `/${child.path}` : ""}`;
50
+ return {
51
+ ...child,
52
+ path: routePath
53
+ };
54
+ });
55
+ if (newRoutes.length > 1) {
56
+ return newRoutes.flatMap((newRoute) => optimizeRoute(newRoute));
57
+ }
58
+ return newRoutes;
59
+ } else {
60
+ routeTree.children = children.flatMap(optimizeRoute);
61
+ return [
62
+ routeTree
63
+ ];
64
+ }
65
+ };
66
+ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion) => {
67
+ var _routePath, _finalRoute_children;
41
68
  if (!await fs.pathExists(dirname)) {
42
69
  return null;
43
70
  }
@@ -57,7 +84,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
57
84
  }
58
85
  routePath = replaceDynamicPath(routePath);
59
86
  const route = {
60
- path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
87
+ path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
61
88
  children: [],
62
89
  isRoot
63
90
  };
@@ -73,10 +100,10 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
73
100
  const itemWithoutExt = item.slice(0, -extname.length);
74
101
  const isDirectory2 = (await fs.stat(itemPath)).isDirectory();
75
102
  if (isDirectory2) {
76
- const childRoute = await walk(itemPath, rootDir, alias, entryName, isMainEntry);
77
- if (childRoute) {
78
- var _route_children1;
79
- (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
103
+ const childRoute = await walk(itemPath, rootDir, alias, entryName, isMainEntry, oldVersion);
104
+ if (childRoute && !Array.isArray(childRoute)) {
105
+ var _route_children;
106
+ (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.push(childRoute);
80
107
  }
81
108
  }
82
109
  if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
@@ -102,7 +129,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
102
129
  pageConfigFile = itemPath;
103
130
  }
104
131
  if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
105
- var _route_children2;
132
+ var _route_children1;
106
133
  pageRoute = createIndexRoute({
107
134
  _component: replaceWithAlias(alias.basename, itemPath, alias.name)
108
135
  }, rootDir, itemPath, entryName, isMainEntry);
@@ -112,13 +139,13 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
112
139
  if (pageConfigFile) {
113
140
  pageRoute.config = pageConfigFile;
114
141
  }
115
- (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
142
+ (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(pageRoute);
116
143
  }
117
144
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
118
145
  splatLoaderFile = itemPath;
119
146
  }
120
147
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
121
- var _route_children3;
148
+ var _route_children2;
122
149
  splatRoute = createRoute({
123
150
  _component: replaceWithAlias(alias.basename, itemPath, alias.name),
124
151
  path: "*"
@@ -126,7 +153,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
126
153
  if (splatLoaderFile) {
127
154
  splatRoute.loader = splatLoaderFile;
128
155
  }
129
- (_route_children3 = route.children) === null || _route_children3 === void 0 ? void 0 : _route_children3.push(splatRoute);
156
+ (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
130
157
  }
131
158
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
132
159
  route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
@@ -139,12 +166,12 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
139
166
  if (isPathlessLayout) {
140
167
  delete finalRoute.path;
141
168
  }
142
- route.children = (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.filter((childRoute) => childRoute);
143
- if (route.children && route.children.length === 0 && !route.index) {
169
+ const childRoutes = finalRoute.children = (_finalRoute_children = finalRoute.children) === null || _finalRoute_children === void 0 ? void 0 : _finalRoute_children.filter((childRoute) => childRoute);
170
+ if (childRoutes && childRoutes.length === 0 && !finalRoute.index) {
144
171
  return null;
145
172
  }
146
- if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
147
- const childRoute = finalRoute.children[0];
173
+ if (childRoutes && childRoutes.length === 1 && !finalRoute._component) {
174
+ const childRoute = childRoutes[0];
148
175
  if (childRoute.path === "*") {
149
176
  const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
150
177
  finalRoute = {
@@ -153,5 +180,18 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
153
180
  };
154
181
  }
155
182
  }
183
+ if (splatRoute) {
184
+ var _childRoutes;
185
+ const slatRouteIndex = (_childRoutes = childRoutes) === null || _childRoutes === void 0 ? void 0 : _childRoutes.findIndex((childRoute) => childRoute === splatRoute);
186
+ if (typeof slatRouteIndex === "number" && slatRouteIndex !== -1) {
187
+ var _childRoutes1, _childRoutes2;
188
+ (_childRoutes1 = childRoutes) === null || _childRoutes1 === void 0 ? void 0 : _childRoutes1.splice(slatRouteIndex, 1);
189
+ (_childRoutes2 = childRoutes) === null || _childRoutes2 === void 0 ? void 0 : _childRoutes2.push(splatRoute);
190
+ }
191
+ }
192
+ if (isRoot && !oldVersion) {
193
+ const optimizedRoutes = optimizeRoute(finalRoute);
194
+ return optimizedRoutes;
195
+ }
156
196
  return finalRoute;
157
197
  };
@@ -79,8 +79,8 @@ export const routesForServer = ({ routes }) => {
79
79
  const traverseRouteTree = (route) => {
80
80
  let children;
81
81
  if ("children" in route && route.children) {
82
- var _route_children;
83
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
82
+ var _route_children, _route;
83
+ children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
84
84
  }
85
85
  let loader;
86
86
  if (route.type === "nested") {
@@ -147,8 +147,8 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
147
147
  const traverseRouteTree = (route) => {
148
148
  let children;
149
149
  if ("children" in route && route.children) {
150
- var _route_children;
151
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
150
+ var _route_children, _route;
151
+ children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
152
152
  }
153
153
  let loading;
154
154
  let error;