@modern-js/runtime 2.53.0 → 2.54.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 (123) hide show
  1. package/dist/cjs/{runtimeContext.js → cli/constants.js} +6 -10
  2. package/dist/cjs/cli/entry.js +42 -0
  3. package/dist/cjs/cli/index.js +10 -0
  4. package/dist/cjs/core/compatible.js +13 -29
  5. package/dist/cjs/core/{appConfig.js → config.js} +6 -4
  6. package/dist/cjs/core/context/index.js +28 -0
  7. package/dist/cjs/core/context/runtime.js +42 -0
  8. package/dist/cjs/core/index.js +8 -12
  9. package/dist/cjs/core/loader/useLoader.js +2 -2
  10. package/dist/cjs/core/{plugin.js → plugin/base.js} +5 -25
  11. package/dist/cjs/core/plugin/index.js +39 -0
  12. package/dist/cjs/core/plugin/runner.js +42 -0
  13. package/dist/cjs/index.js +2 -4
  14. package/dist/cjs/router/cli/code/getClientRoutes/getRoutes.js +197 -0
  15. package/dist/cjs/router/cli/code/getClientRoutes/getRoutesLegacy.js +195 -0
  16. package/dist/cjs/router/cli/code/getClientRoutes/index.js +31 -0
  17. package/dist/cjs/router/cli/code/getClientRoutes/utils.js +59 -0
  18. package/dist/cjs/router/cli/code/index.js +134 -0
  19. package/dist/cjs/router/cli/code/makeLegalIdentifier.js +37 -0
  20. package/dist/cjs/router/cli/code/nestedRoutes.js +294 -0
  21. package/dist/cjs/router/cli/code/templates.js +371 -0
  22. package/dist/cjs/router/cli/code/utils.js +143 -0
  23. package/dist/cjs/router/cli/constants.js +83 -0
  24. package/dist/cjs/router/cli/entry.js +87 -0
  25. package/dist/cjs/router/cli/handler.js +71 -0
  26. package/dist/cjs/router/cli/index.js +25 -0
  27. package/dist/cjs/router/runtime/plugin.js +7 -4
  28. package/dist/cjs/router/runtime/plugin.node.js +12 -5
  29. package/dist/cjs/ssr/index.node.js +1 -0
  30. package/dist/cjs/state/runtime/plugin.js +3 -2
  31. package/dist/esm/cli/constants.js +4 -0
  32. package/dist/esm/cli/entry.js +14 -0
  33. package/dist/esm/cli/index.js +10 -0
  34. package/dist/esm/core/compatible.js +11 -30
  35. package/dist/esm/core/{appConfig.js → config.js} +4 -1
  36. package/dist/esm/core/context/index.js +4 -0
  37. package/dist/esm/core/context/runtime.js +18 -0
  38. package/dist/esm/core/index.js +4 -6
  39. package/dist/esm/core/loader/useLoader.js +1 -1
  40. package/dist/esm/core/plugin/base.js +21 -0
  41. package/dist/esm/core/plugin/index.js +15 -0
  42. package/dist/esm/core/plugin/runner.js +17 -0
  43. package/dist/esm/index.js +2 -3
  44. package/dist/esm/router/cli/code/getClientRoutes/getRoutes.js +185 -0
  45. package/dist/esm/router/cli/code/getClientRoutes/getRoutesLegacy.js +183 -0
  46. package/dist/esm/router/cli/code/getClientRoutes/index.js +6 -0
  47. package/dist/esm/router/cli/code/getClientRoutes/utils.js +28 -0
  48. package/dist/esm/router/cli/code/index.js +214 -0
  49. package/dist/esm/router/cli/code/makeLegalIdentifier.js +15 -0
  50. package/dist/esm/router/cli/code/nestedRoutes.js +397 -0
  51. package/dist/esm/router/cli/code/templates.js +417 -0
  52. package/dist/esm/router/cli/code/utils.js +212 -0
  53. package/dist/esm/router/cli/constants.js +47 -0
  54. package/dist/esm/router/cli/entry.js +57 -0
  55. package/dist/esm/router/cli/handler.js +103 -0
  56. package/dist/esm/router/cli/index.js +57 -0
  57. package/dist/esm/router/runtime/plugin.js +7 -4
  58. package/dist/esm/router/runtime/plugin.node.js +13 -6
  59. package/dist/esm/ssr/index.node.js +1 -0
  60. package/dist/esm/state/runtime/plugin.js +3 -2
  61. package/dist/esm-node/cli/constants.js +4 -0
  62. package/dist/esm-node/cli/entry.js +8 -0
  63. package/dist/esm-node/cli/index.js +9 -0
  64. package/dist/esm-node/core/compatible.js +12 -28
  65. package/dist/esm-node/core/{appConfig.js → config.js} +2 -1
  66. package/dist/esm-node/core/context/index.js +4 -0
  67. package/dist/esm-node/core/context/runtime.js +16 -0
  68. package/dist/esm-node/core/index.js +4 -6
  69. package/dist/esm-node/core/loader/useLoader.js +1 -1
  70. package/dist/esm-node/core/plugin/base.js +19 -0
  71. package/dist/esm-node/core/plugin/index.js +13 -0
  72. package/dist/esm-node/core/plugin/runner.js +17 -0
  73. package/dist/esm-node/index.js +2 -3
  74. package/dist/esm-node/router/cli/code/getClientRoutes/getRoutes.js +163 -0
  75. package/dist/esm-node/router/cli/code/getClientRoutes/getRoutesLegacy.js +161 -0
  76. package/dist/esm-node/router/cli/code/getClientRoutes/index.js +6 -0
  77. package/dist/esm-node/router/cli/code/getClientRoutes/utils.js +22 -0
  78. package/dist/esm-node/router/cli/code/index.js +100 -0
  79. package/dist/esm-node/router/cli/code/makeLegalIdentifier.js +13 -0
  80. package/dist/esm-node/router/cli/code/nestedRoutes.js +258 -0
  81. package/dist/esm-node/router/cli/code/templates.js +335 -0
  82. package/dist/esm-node/router/cli/code/utils.js +101 -0
  83. package/dist/esm-node/router/cli/constants.js +47 -0
  84. package/dist/esm-node/router/cli/entry.js +50 -0
  85. package/dist/esm-node/router/cli/handler.js +36 -0
  86. package/dist/esm-node/router/cli/index.js +22 -0
  87. package/dist/esm-node/router/runtime/plugin.js +7 -4
  88. package/dist/esm-node/router/runtime/plugin.node.js +12 -5
  89. package/dist/esm-node/ssr/index.node.js +1 -0
  90. package/dist/esm-node/state/runtime/plugin.js +3 -2
  91. package/dist/types/cli/constants.d.ts +1 -0
  92. package/dist/types/cli/entry.d.ts +1 -0
  93. package/dist/types/cli/index.d.ts +1 -0
  94. package/dist/types/core/compatible.d.ts +7 -3
  95. package/dist/types/core/config.d.ts +14 -0
  96. package/dist/types/core/context/index.d.ts +1 -0
  97. package/dist/types/{runtimeContext.d.ts → core/context/runtime.d.ts} +5 -4
  98. package/dist/types/core/index.d.ts +4 -4
  99. package/dist/types/core/plugin/base.d.ts +80 -0
  100. package/dist/types/core/plugin/index.d.ts +29 -0
  101. package/dist/types/core/plugin/runner.d.ts +26 -0
  102. package/dist/types/index.d.ts +2 -2
  103. package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
  104. package/dist/types/router/cli/code/getClientRoutes/getRoutesLegacy.d.ts +9 -0
  105. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +2 -0
  106. package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +5 -0
  107. package/dist/types/router/cli/code/index.d.ts +6 -0
  108. package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
  109. package/dist/types/router/cli/code/nestedRoutes.d.ts +7 -0
  110. package/dist/types/router/cli/code/templates.d.ts +14 -0
  111. package/dist/types/router/cli/code/utils.d.ts +12 -0
  112. package/dist/types/router/cli/constants.d.ts +32 -0
  113. package/dist/types/router/cli/entry.d.ts +5 -0
  114. package/dist/types/router/cli/handler.d.ts +5 -0
  115. package/dist/types/router/cli/index.d.ts +3 -1
  116. package/dist/types/ssr/serverRender/types.d.ts +3 -0
  117. package/package.json +37 -11
  118. package/dist/esm/core/plugin.js +0 -59
  119. package/dist/esm/runtimeContext.js +0 -7
  120. package/dist/esm-node/core/plugin.js +0 -37
  121. package/dist/esm-node/runtimeContext.js +0 -7
  122. package/dist/types/core/appConfig.d.ts +0 -4
  123. package/dist/types/core/plugin.d.ts +0 -204
@@ -0,0 +1,214 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import path from "path";
4
+ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
5
+ import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
6
+ import * as templates from "./templates";
7
+ import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
8
+ import { getServerLoadersFile, getServerCombinedModueFile } from "./utils";
9
+ import { walk } from "./nestedRoutes";
10
+ var generateCode = function() {
11
+ var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
12
+ var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
13
+ function generateEntryCode(entrypoint) {
14
+ return _generateEntryCode.apply(this, arguments);
15
+ }
16
+ function _generateEntryCode() {
17
+ _generateEntryCode = _async_to_generator(function(entrypoint) {
18
+ var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile;
19
+ return _ts_generator(this, function(_state) {
20
+ switch (_state.label) {
21
+ case 0:
22
+ entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, fileSystemRoutes = entrypoint.fileSystemRoutes;
23
+ if (!isAutoMount)
24
+ return [
25
+ 3,
26
+ 11
27
+ ];
28
+ if (!fileSystemRoutes)
29
+ return [
30
+ 3,
31
+ 11
32
+ ];
33
+ initialRoutes = [];
34
+ nestedRoutes = null;
35
+ if (entrypoint.entry) {
36
+ initialRoutes = getRoutes({
37
+ entrypoint,
38
+ srcDirectory,
39
+ srcAlias: internalSrcAlias,
40
+ internalDirectory,
41
+ internalDirAlias
42
+ });
43
+ }
44
+ if (!(!isV5 && entrypoint.nestedRoutesEntry))
45
+ return [
46
+ 3,
47
+ 2
48
+ ];
49
+ return [
50
+ 4,
51
+ walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
52
+ name: internalSrcAlias,
53
+ basename: srcDirectory
54
+ }, entrypoint.entryName, entrypoint.isMainEntry, oldVersion)
55
+ ];
56
+ case 1:
57
+ nestedRoutes = _state.sent();
58
+ if (nestedRoutes) {
59
+ if (!Array.isArray(nestedRoutes)) {
60
+ nestedRoutes = [
61
+ nestedRoutes
62
+ ];
63
+ }
64
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
65
+ try {
66
+ for (_iterator = nestedRoutes[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
67
+ route = _step.value;
68
+ initialRoutes.unshift(route);
69
+ }
70
+ } catch (err) {
71
+ _didIteratorError = true;
72
+ _iteratorError = err;
73
+ } finally {
74
+ try {
75
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
76
+ _iterator.return();
77
+ }
78
+ } finally {
79
+ if (_didIteratorError) {
80
+ throw _iteratorError;
81
+ }
82
+ }
83
+ }
84
+ }
85
+ _state.label = 2;
86
+ case 2:
87
+ return [
88
+ 4,
89
+ hookRunners.modifyFileSystemRoutes({
90
+ entrypoint,
91
+ routes: initialRoutes
92
+ })
93
+ ];
94
+ case 3:
95
+ routes = _state.sent().routes;
96
+ _$config = api.useResolvedConfigContext();
97
+ ssr = getEntryOptions(entryName, isMainEntry, _$config.server.ssr, _$config.server.ssrByEntries, packageName);
98
+ useSSG = isSSGEntry(_$config, entryName, entrypoints);
99
+ if (ssr) {
100
+ mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
101
+ }
102
+ if (mode === "stream") {
103
+ hasPageRoute = routes.some(function(route2) {
104
+ return "type" in route2 && route2.type === "page";
105
+ });
106
+ if (hasPageRoute) {
107
+ logger.error("Streaming ssr is not supported when pages dir exists");
108
+ process.exit(1);
109
+ }
110
+ }
111
+ _ = hookRunners.beforeGenerateRoutes;
112
+ _tmp = {
113
+ entrypoint
114
+ };
115
+ return [
116
+ 4,
117
+ templates.fileSystemRoutes({
118
+ routes,
119
+ ssrMode: useSSG ? "string" : mode,
120
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
121
+ entryName: entrypoint.entryName,
122
+ internalDirectory,
123
+ splitRouteChunks: _$config === null || _$config === void 0 ? void 0 : (_config_output = _$config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
124
+ })
125
+ ];
126
+ case 4:
127
+ return [
128
+ 4,
129
+ _.apply(hookRunners, [
130
+ (_tmp.code = _state.sent(), _tmp)
131
+ ])
132
+ ];
133
+ case 5:
134
+ code = _state.sent().code;
135
+ if (!(entrypoint.nestedRoutesEntry && isUseSSRBundle(_$config)))
136
+ return [
137
+ 3,
138
+ 8
139
+ ];
140
+ routesServerFile = getServerLoadersFile(internalDirectory, entryName);
141
+ code1 = templates.routesForServer({
142
+ routes
143
+ });
144
+ return [
145
+ 4,
146
+ fs.ensureFile(routesServerFile)
147
+ ];
148
+ case 6:
149
+ _state.sent();
150
+ return [
151
+ 4,
152
+ fs.writeFile(routesServerFile, code1)
153
+ ];
154
+ case 7:
155
+ _state.sent();
156
+ _state.label = 8;
157
+ case 8:
158
+ serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, _$config, appContext);
159
+ if (!serverLoaderCombined)
160
+ return [
161
+ 3,
162
+ 10
163
+ ];
164
+ serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
165
+ return [
166
+ 4,
167
+ fs.outputFile(serverLoaderFile, serverLoaderCombined)
168
+ ];
169
+ case 9:
170
+ _state.sent();
171
+ _state.label = 10;
172
+ case 10:
173
+ fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code, "utf8");
174
+ _state.label = 11;
175
+ case 11:
176
+ return [
177
+ 2
178
+ ];
179
+ }
180
+ });
181
+ });
182
+ return _generateEntryCode.apply(this, arguments);
183
+ }
184
+ return _ts_generator(this, function(_state) {
185
+ switch (_state.label) {
186
+ case 0:
187
+ internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
188
+ hookRunners = api.useHookRunners();
189
+ isV5 = isRouterV5(config);
190
+ getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
191
+ importsStatemets = /* @__PURE__ */ new Map();
192
+ oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
193
+ return [
194
+ 4,
195
+ Promise.all(entrypoints.map(generateEntryCode))
196
+ ];
197
+ case 1:
198
+ _state.sent();
199
+ return [
200
+ 2,
201
+ {
202
+ importsStatemets
203
+ }
204
+ ];
205
+ }
206
+ });
207
+ });
208
+ return function generateCode2(appContext, config, entrypoints, api) {
209
+ return _ref.apply(this, arguments);
210
+ };
211
+ }();
212
+ export {
213
+ generateCode
214
+ };
@@ -0,0 +1,15 @@
1
+ var reservedWords = "break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public";
2
+ var builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
3
+ var forbidList = new Set("".concat(reservedWords, " ").concat(builtins).split(" "));
4
+ function makeLegalIdentifier(str) {
5
+ var identifier = str.replace(/-(\w)/g, function(_, letter) {
6
+ return letter.toUpperCase();
7
+ }).replace(/[^$_a-zA-Z0-9]/g, "_");
8
+ if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
9
+ return "_".concat(identifier);
10
+ }
11
+ return identifier || "_";
12
+ }
13
+ export {
14
+ makeLegalIdentifier
15
+ };
@@ -0,0 +1,397 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import * as path from "path";
6
+ import { JS_EXTENSIONS, fs, normalizeToPosixPath } from "@modern-js/utils";
7
+ import { NESTED_ROUTE } from "../constants";
8
+ import { getPathWithoutExt, hasAction, replaceWithAlias } from "./utils";
9
+ var conventionNames = Object.values(NESTED_ROUTE);
10
+ var replaceDynamicPath = function(routePath) {
11
+ return routePath.replace(/\[(.*?)\]/g, ":$1");
12
+ };
13
+ var getRouteId = function(componentPath, routesDir, entryName, isMainEntry) {
14
+ var relativePath = normalizeToPosixPath(path.relative(routesDir, componentPath));
15
+ var pathWithoutExt = getPathWithoutExt(relativePath);
16
+ var id = "";
17
+ if (isMainEntry) {
18
+ id = pathWithoutExt;
19
+ } else {
20
+ id = "".concat(entryName, "_").concat(pathWithoutExt);
21
+ }
22
+ return id.replace(/\[(.*?)\]/g, "($1)");
23
+ };
24
+ var createIndexRoute = function(routeInfo, rootDir, filename, entryName, isMainEntry) {
25
+ return createRoute(_object_spread_props(_object_spread({}, routeInfo), {
26
+ index: true,
27
+ children: void 0
28
+ }), rootDir, filename, entryName, isMainEntry);
29
+ };
30
+ var createRoute = function(routeInfo, rootDir, filename, entryName, isMainEntry) {
31
+ var id = getRouteId(filename, rootDir, entryName, isMainEntry);
32
+ return _object_spread_props(_object_spread({}, routeInfo), {
33
+ id,
34
+ type: "nested"
35
+ });
36
+ };
37
+ var optimizeRoute = function(routeTree) {
38
+ if (!routeTree.children || routeTree.children.length === 0) {
39
+ return [
40
+ routeTree
41
+ ];
42
+ }
43
+ var children = routeTree.children;
44
+ if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData) {
45
+ var newRoutes = children.map(function(child) {
46
+ var routePath = "".concat(routeTree.path ? routeTree.path : "").concat(child.path ? "/".concat(child.path) : "");
47
+ var newRoute = _object_spread_props(_object_spread({}, child), {
48
+ path: routePath.replace(/\/\//g, "/")
49
+ });
50
+ if (routePath.length > 0) {
51
+ delete newRoute.index;
52
+ } else {
53
+ delete newRoute.path;
54
+ }
55
+ return newRoute;
56
+ });
57
+ return Array.from(new Set(newRoutes)).flatMap(optimizeRoute);
58
+ } else {
59
+ var optimizedChildren = routeTree.children.flatMap(optimizeRoute);
60
+ return [
61
+ _object_spread_props(_object_spread({}, routeTree), {
62
+ children: optimizedChildren
63
+ })
64
+ ];
65
+ }
66
+ };
67
+ var walk = function() {
68
+ var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
69
+ var _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, pageConfigFile, pageClientData, pageData, pageAction, splatLoaderFile, splatRoute, splatConfigFile, splatClientData, splatData, splatAction, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, itemPathWithAlias, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, optimizedRoutes;
70
+ return _ts_generator(this, function(_state) {
71
+ switch (_state.label) {
72
+ case 0:
73
+ return [
74
+ 4,
75
+ fs.pathExists(dirname)
76
+ ];
77
+ case 1:
78
+ if (!_state.sent()) {
79
+ return [
80
+ 2,
81
+ null
82
+ ];
83
+ }
84
+ return [
85
+ 4,
86
+ fs.stat(dirname)
87
+ ];
88
+ case 2:
89
+ isDirectory = _state.sent().isDirectory();
90
+ if (!isDirectory) {
91
+ return [
92
+ 2,
93
+ null
94
+ ];
95
+ }
96
+ relativeDir = path.relative(rootDir, dirname);
97
+ pathSegments = relativeDir.split(path.sep);
98
+ lastSegment = pathSegments[pathSegments.length - 1];
99
+ isRoot = lastSegment === "";
100
+ isPathlessLayout = lastSegment.startsWith("__");
101
+ isWithoutLayoutPath = lastSegment.includes(".");
102
+ routePath = isRoot || isPathlessLayout ? "/" : "".concat(lastSegment);
103
+ if (isWithoutLayoutPath) {
104
+ routePath = lastSegment.split(".").join("/");
105
+ }
106
+ routePath = replaceDynamicPath(routePath);
107
+ route = {
108
+ path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
109
+ children: [],
110
+ isRoot
111
+ };
112
+ pageLoaderFile = "";
113
+ pageRoute = null;
114
+ pageConfigFile = "";
115
+ pageClientData = "";
116
+ pageData = "";
117
+ pageAction = "";
118
+ splatLoaderFile = "";
119
+ splatRoute = null;
120
+ splatConfigFile = "";
121
+ splatClientData = "";
122
+ splatData = "";
123
+ splatAction = "";
124
+ return [
125
+ 4,
126
+ fs.readdir(dirname)
127
+ ];
128
+ case 3:
129
+ items = _state.sent();
130
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
131
+ _state.label = 4;
132
+ case 4:
133
+ _state.trys.push([
134
+ 4,
135
+ 17,
136
+ 18,
137
+ 19
138
+ ]);
139
+ _iterator = items[Symbol.iterator]();
140
+ _state.label = 5;
141
+ case 5:
142
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
143
+ return [
144
+ 3,
145
+ 16
146
+ ];
147
+ item = _step.value;
148
+ itemPath = path.join(dirname, item);
149
+ itemPathWithAlias = getPathWithoutExt(replaceWithAlias(alias.basename, itemPath, alias.name));
150
+ extname = path.extname(item);
151
+ itemWithoutExt = item.slice(0, -extname.length);
152
+ return [
153
+ 4,
154
+ fs.stat(itemPath)
155
+ ];
156
+ case 6:
157
+ isDirectory1 = _state.sent().isDirectory();
158
+ if (!isDirectory1)
159
+ return [
160
+ 3,
161
+ 8
162
+ ];
163
+ return [
164
+ 4,
165
+ walk(itemPath, rootDir, alias, entryName, isMainEntry, oldVersion)
166
+ ];
167
+ case 7:
168
+ childRoute = _state.sent();
169
+ if (childRoute && !Array.isArray(childRoute)) {
170
+ ;
171
+ (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.push(childRoute);
172
+ }
173
+ _state.label = 8;
174
+ case 8:
175
+ if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
176
+ return [
177
+ 3,
178
+ 15
179
+ ];
180
+ }
181
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
182
+ if (!route.loader) {
183
+ route.loader = itemPathWithAlias;
184
+ }
185
+ }
186
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
187
+ route.clientData = itemPathWithAlias;
188
+ }
189
+ if (!(itemWithoutExt === NESTED_ROUTE.LAYOUT_DATA_FILE))
190
+ return [
191
+ 3,
192
+ 10
193
+ ];
194
+ route.data = itemPathWithAlias;
195
+ return [
196
+ 4,
197
+ hasAction(itemPath)
198
+ ];
199
+ case 9:
200
+ if (_state.sent()) {
201
+ route.action = itemPathWithAlias;
202
+ }
203
+ _state.label = 10;
204
+ case 10:
205
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
206
+ if (!route.config) {
207
+ route.config = itemPathWithAlias;
208
+ }
209
+ }
210
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
211
+ route._component = itemPathWithAlias;
212
+ }
213
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
214
+ pageLoaderFile = itemPathWithAlias;
215
+ }
216
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CLIENT_LOADER) {
217
+ pageClientData = itemPathWithAlias;
218
+ }
219
+ if (!(itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE))
220
+ return [
221
+ 3,
222
+ 12
223
+ ];
224
+ pageData = itemPathWithAlias;
225
+ return [
226
+ 4,
227
+ hasAction(itemPath)
228
+ ];
229
+ case 11:
230
+ if (_state.sent()) {
231
+ pageAction = itemPathWithAlias;
232
+ }
233
+ _state.label = 12;
234
+ case 12:
235
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
236
+ pageConfigFile = itemPathWithAlias;
237
+ }
238
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
239
+ ;
240
+ pageRoute = createIndexRoute({
241
+ _component: itemPathWithAlias
242
+ }, rootDir, itemPath, entryName, isMainEntry);
243
+ if (pageLoaderFile) {
244
+ pageRoute.loader = pageLoaderFile;
245
+ }
246
+ if (pageConfigFile) {
247
+ pageRoute.config = pageConfigFile;
248
+ }
249
+ if (pageData) {
250
+ pageRoute.data = pageData;
251
+ }
252
+ if (pageClientData) {
253
+ pageRoute.clientData = pageClientData;
254
+ }
255
+ if (pageAction) {
256
+ pageRoute.action = pageAction;
257
+ }
258
+ (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(pageRoute);
259
+ }
260
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
261
+ splatLoaderFile = itemPathWithAlias;
262
+ }
263
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_CLIENT_DATA) {
264
+ splatClientData = itemPathWithAlias;
265
+ }
266
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_CONFIG_FILE) {
267
+ if (!route.config) {
268
+ splatConfigFile = replaceWithAlias(alias.basename, itemPath, alias.name);
269
+ }
270
+ }
271
+ if (!(itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE))
272
+ return [
273
+ 3,
274
+ 14
275
+ ];
276
+ splatData = itemPathWithAlias;
277
+ return [
278
+ 4,
279
+ hasAction(itemPath)
280
+ ];
281
+ case 13:
282
+ if (_state.sent()) {
283
+ splatAction = itemPathWithAlias;
284
+ }
285
+ _state.label = 14;
286
+ case 14:
287
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
288
+ ;
289
+ splatRoute = createRoute({
290
+ _component: itemPathWithAlias,
291
+ path: "*"
292
+ }, rootDir, itemPath, entryName, isMainEntry);
293
+ if (splatLoaderFile) {
294
+ splatRoute.loader = splatLoaderFile;
295
+ }
296
+ if (splatClientData) {
297
+ splatRoute.clientData = splatClientData;
298
+ }
299
+ if (splatData) {
300
+ splatRoute.data = splatData;
301
+ }
302
+ if (splatConfigFile) {
303
+ splatRoute.config = splatConfigFile;
304
+ }
305
+ if (splatAction) {
306
+ splatRoute.action = splatAction;
307
+ }
308
+ (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
309
+ }
310
+ if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
311
+ route.loading = itemPathWithAlias;
312
+ }
313
+ if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
314
+ route.error = itemPathWithAlias;
315
+ }
316
+ _state.label = 15;
317
+ case 15:
318
+ _iteratorNormalCompletion = true;
319
+ return [
320
+ 3,
321
+ 5
322
+ ];
323
+ case 16:
324
+ return [
325
+ 3,
326
+ 19
327
+ ];
328
+ case 17:
329
+ err = _state.sent();
330
+ _didIteratorError = true;
331
+ _iteratorError = err;
332
+ return [
333
+ 3,
334
+ 19
335
+ ];
336
+ case 18:
337
+ try {
338
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
339
+ _iterator.return();
340
+ }
341
+ } finally {
342
+ if (_didIteratorError) {
343
+ throw _iteratorError;
344
+ }
345
+ }
346
+ return [
347
+ 7
348
+ ];
349
+ case 19:
350
+ finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName, isMainEntry);
351
+ if (isPathlessLayout) {
352
+ delete finalRoute.path;
353
+ }
354
+ childRoutes = finalRoute.children = (_finalRoute_children = finalRoute.children) === null || _finalRoute_children === void 0 ? void 0 : _finalRoute_children.filter(function(childRoute2) {
355
+ return childRoute2;
356
+ });
357
+ if (childRoutes && childRoutes.length === 0 && !finalRoute.index && !finalRoute._component) {
358
+ return [
359
+ 2,
360
+ null
361
+ ];
362
+ }
363
+ if (childRoutes && childRoutes.length === 1 && !finalRoute._component) {
364
+ childRoute1 = childRoutes[0];
365
+ if (childRoute1.path === "*") {
366
+ _$path = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
367
+ finalRoute = _object_spread_props(_object_spread({}, childRoute1), {
368
+ path: _$path
369
+ });
370
+ }
371
+ }
372
+ if (isRoot && !finalRoute._component) {
373
+ throw new Error("The root layout component is required, make sure the routes/layout.tsx file exists.");
374
+ }
375
+ if (isRoot && !oldVersion) {
376
+ optimizedRoutes = optimizeRoute(finalRoute);
377
+ return [
378
+ 2,
379
+ optimizedRoutes
380
+ ];
381
+ }
382
+ return [
383
+ 2,
384
+ finalRoute
385
+ ];
386
+ }
387
+ });
388
+ });
389
+ return function walk2(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
390
+ return _ref.apply(this, arguments);
391
+ };
392
+ }();
393
+ export {
394
+ getRouteId,
395
+ optimizeRoute,
396
+ walk
397
+ };