@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
  20. package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
  21. package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
  22. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  23. package/dist/cjs/plugins/serverBuild.js +10 -4
  24. package/dist/cjs/utils/createServer.js +1 -1
  25. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  28. package/dist/esm/commands/build.js +16 -9
  29. package/dist/esm/commands/deploy.js +2 -2
  30. package/dist/esm/commands/dev.js +13 -9
  31. package/dist/esm/commands/index.js +411 -3
  32. package/dist/esm/commands/serve.js +12 -8
  33. package/dist/esm/hooks.js +5 -0
  34. package/dist/esm/index.js +12 -394
  35. package/dist/esm/plugins/analyze/constants.js +24 -0
  36. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  39. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  40. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  41. package/dist/esm/plugins/analyze/templates.js +22 -0
  42. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -3
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
  46. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  47. package/dist/esm/plugins/serverBuild.js +13 -6
  48. package/dist/esm/utils/createServer.js +2 -2
  49. package/dist/esm/utils/loadPlugins.js +64 -0
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  51. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  52. package/dist/esm-node/commands/build.js +2 -0
  53. package/dist/esm-node/commands/deploy.js +2 -2
  54. package/dist/esm-node/commands/dev.js +11 -7
  55. package/dist/esm-node/commands/index.js +92 -3
  56. package/dist/esm-node/commands/serve.js +10 -6
  57. package/dist/esm-node/hooks.js +5 -0
  58. package/dist/esm-node/index.js +12 -79
  59. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  60. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  61. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  63. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  64. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  65. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  66. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  67. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
  68. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
  69. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
  70. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  71. package/dist/esm-node/plugins/serverBuild.js +11 -5
  72. package/dist/esm-node/utils/createServer.js +2 -2
  73. package/dist/esm-node/utils/loadPlugins.js +21 -0
  74. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  75. package/dist/types/commands/index.d.ts +10 -3
  76. package/dist/types/config/initialize/inits.d.ts +1 -1
  77. package/dist/types/exports/server.d.ts +4 -0
  78. package/dist/types/index.d.ts +2 -5
  79. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  80. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  81. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  82. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  83. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  84. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  85. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  86. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  87. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  88. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  89. package/dist/types/types/hooks.d.ts +11 -1
  90. package/dist/types/utils/loadPlugins.d.ts +5 -0
  91. package/package.json +22 -22
  92. package/dist/cjs/analyze/constants.js +0 -122
  93. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  94. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  95. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  96. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  97. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  98. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  99. package/dist/cjs/analyze/templates.js +0 -444
  100. package/dist/esm/analyze/constants.js +0 -76
  101. package/dist/esm/analyze/getBundleEntry.js +0 -75
  102. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  103. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  104. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  105. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  106. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  107. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  108. package/dist/esm/analyze/nestedRoutes.js +0 -398
  109. package/dist/esm/analyze/templates.js +0 -435
  110. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  111. package/dist/esm-node/analyze/constants.js +0 -76
  112. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  113. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  114. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  115. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  116. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  117. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  118. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  119. package/dist/esm-node/analyze/templates.js +0 -405
  120. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  121. package/dist/types/analyze/constants.d.ts +0 -42
  122. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  123. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  124. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  125. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  126. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  127. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  128. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  129. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  130. package/dist/types/analyze/templates.d.ts +0 -30
  131. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  132. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  133. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  134. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  135. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  136. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  137. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  138. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,435 +0,0 @@
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 _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
- import path from "path";
7
- import { fs, getEntryOptions, isSSGEntry, slash } from "@modern-js/utils";
8
- import { ROUTE_MODULES } from "@modern-js/utils/universal/constants";
9
- import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
10
- import { getServerLoadersFile } from "./utils";
11
- var index = function(param) {
12
- var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
13
- return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
14
- };
15
- var renderFunction = function(param) {
16
- var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
17
- var bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
18
- return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param2) {
19
- var name = param2.name, options = param2.options, args = param2.args;
20
- return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
21
- }).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper, () => ".concat(bootstrap, ");") : "".concat(bootstrap, ";"), "\n }\n\n return AppWrapper\n");
22
- };
23
- var html = function(partials) {
24
- return "\n<!DOCTYPE html>\n<html>\n<head>\n\n ".concat(partials.top.join("\n"), "\n\n ").concat(partials.head.join("\n"), '\n\n</head>\n\n<body>\n <div id="<%= mountId %>"><!--<?- html ?>--></div>\n ').concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
25
- };
26
- var routesForServer = function(param) {
27
- var routes = param.routes;
28
- var loaders = [];
29
- var actions = [];
30
- var loadersMap = {};
31
- var traverseRouteTree = function(route2) {
32
- var children;
33
- if ("children" in route2 && route2.children) {
34
- var _route_children;
35
- children = route2 === null || route2 === void 0 ? void 0 : (_route_children = route2.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
36
- }
37
- var loader;
38
- var action;
39
- if (route2.type === "nested") {
40
- if (route2.loader || route2.data) {
41
- loaders.push(route2.loader);
42
- var loaderId = loaders.length - 1;
43
- loader = "loader_".concat(loaderId);
44
- var inline = Boolean(route2.data);
45
- loadersMap[loader] = {
46
- loaderId,
47
- routeId: route2.id,
48
- filePath: route2.data || route2.loader,
49
- clientData: Boolean(route2.clientData),
50
- route: route2,
51
- inline
52
- };
53
- if (route2.action) {
54
- actions.push(route2.action);
55
- action = "action_".concat(loaders.length - 1);
56
- }
57
- }
58
- }
59
- var finalRoute = _object_spread_props(_object_spread({}, route2), {
60
- loader,
61
- action,
62
- children
63
- });
64
- return finalRoute;
65
- };
66
- var routesCode = "\n export const routes = [\n ";
67
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
68
- try {
69
- for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
70
- var route = _step.value;
71
- if ("type" in route) {
72
- var keywords = [
73
- "loader",
74
- "action"
75
- ];
76
- var regs = keywords.map(createMatchReg);
77
- var newRoute = traverseRouteTree(route);
78
- var routeStr = JSON.stringify(newRoute, null, 2);
79
- routesCode += regs.reduce(function(acc, reg) {
80
- return acc.replace(reg, "$1$2");
81
- }, routeStr).replace(/\\"/g, '"');
82
- } else {
83
- routesCode += "".concat(JSON.stringify(route, null, 2));
84
- }
85
- }
86
- } catch (err) {
87
- _didIteratorError = true;
88
- _iteratorError = err;
89
- } finally {
90
- try {
91
- if (!_iteratorNormalCompletion && _iterator.return != null) {
92
- _iterator.return();
93
- }
94
- } finally {
95
- if (_didIteratorError) {
96
- throw _iteratorError;
97
- }
98
- }
99
- }
100
- routesCode += "\n];";
101
- var importLoadersCode = "";
102
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
103
- try {
104
- for (var _iterator1 = Object.entries(loadersMap)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
105
- var _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
106
- if (loaderInfo.inline) {
107
- var route1 = loaderInfo.route;
108
- if (route1.action) {
109
- importLoadersCode += "import { loader as ".concat(key, ", action as action_").concat(loaderInfo.loaderId, ' } from "').concat(slash(loaderInfo.filePath), '";\n');
110
- } else {
111
- importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath), '";\n');
112
- }
113
- } else {
114
- importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath), '";\n');
115
- }
116
- }
117
- } catch (err) {
118
- _didIteratorError1 = true;
119
- _iteratorError1 = err;
120
- } finally {
121
- try {
122
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
123
- _iterator1.return();
124
- }
125
- } finally {
126
- if (_didIteratorError1) {
127
- throw _iteratorError1;
128
- }
129
- }
130
- }
131
- return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
132
- };
133
- var createMatchReg = function(keyword) {
134
- return new RegExp('("'.concat(keyword, '":\\s)"([^\n]+)"'), "g");
135
- };
136
- var fileSystemRoutes = function() {
137
- var _ref = _async_to_generator(function(param) {
138
- var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRouteChunks, splitRouteChunks, components, loadings, errors, loaders, loadersMap, configs, configsMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, routeStr, keywords, regs, newRouteStr, component, finalRoute, keywords1, routeStr1, regs1, newRouteStr1, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo, route1, importConfigsCode, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value1, key1, configPath, importRuntimeRouterCode, routeModulesCode;
139
- return _ts_generator(this, function(_state) {
140
- switch (_state.label) {
141
- case 0:
142
- routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory, _param_splitRouteChunks = param.splitRouteChunks, splitRouteChunks = _param_splitRouteChunks === void 0 ? true : _param_splitRouteChunks;
143
- components = [];
144
- loadings = [];
145
- errors = [];
146
- loaders = [];
147
- loadersMap = {};
148
- configs = [];
149
- configsMap = {};
150
- loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
151
- importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
152
- rootLayoutCode = "";
153
- getDataLoaderPath = function(param2) {
154
- var loaderId = param2.loaderId, clientData = param2.clientData, action = param2.action, inline = param2.inline, routeId = param2.routeId;
155
- if (!ssrMode) {
156
- return "";
157
- }
158
- var clientDataStr = clientData ? "&clientData=".concat(clientData) : "";
159
- if (nestedRoutesEntry) {
160
- return "?loaderId=".concat(loaderId).concat(clientDataStr, "&action=").concat(action ? slash(action) : action, "&inline=").concat(inline, "&routeId=").concat(routeId);
161
- }
162
- return "";
163
- };
164
- traverseRouteTree = function(route2) {
165
- var children;
166
- if ("children" in route2 && route2.children) {
167
- var _route_children;
168
- children = route2 === null || route2 === void 0 ? void 0 : (_route_children = route2.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
169
- }
170
- var loading;
171
- var error;
172
- var loader;
173
- var action;
174
- var config;
175
- var component2 = "";
176
- var lazyImport = null;
177
- if (route2.type === "nested") {
178
- if (route2.loading) {
179
- loadings.push(route2.loading);
180
- loading = "loading_".concat(loadings.length - 1);
181
- }
182
- if (route2.error) {
183
- errors.push(route2.error);
184
- error = "error_".concat(errors.length - 1);
185
- }
186
- if (route2.loader || route2.data) {
187
- loaders.push(route2.loader);
188
- var loaderId = loaders.length - 1;
189
- loader = "loader_".concat(loaderId);
190
- var inline = Boolean(route2.data);
191
- loadersMap[loader] = {
192
- loaderId,
193
- routeId: route2.id,
194
- filePath: route2.data || route2.loader,
195
- clientData: Boolean(route2.clientData),
196
- route: route2,
197
- inline
198
- };
199
- loader = "loader_".concat(loaderId);
200
- if (route2.action) {
201
- action = "action_".concat(loaderId);
202
- }
203
- }
204
- if (typeof route2.config === "string") {
205
- configs.push(route2.config);
206
- var configId = configs.length - 1;
207
- config = "config_".concat(configId);
208
- configsMap[config] = route2.config;
209
- }
210
- if (route2._component) {
211
- if (splitRouteChunks) {
212
- if (route2.isRoot) {
213
- lazyImport = "() => import('".concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
214
- rootLayoutCode = "import RootLayout from '".concat(route2._component, "'");
215
- component2 = "RootLayout";
216
- } else if (ssrMode === "string") {
217
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
218
- component2 = "loadable(".concat(lazyImport, ")");
219
- } else {
220
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
221
- component2 = "lazy(".concat(lazyImport, ")");
222
- }
223
- } else if (ssrMode === "string") {
224
- components.push(route2._component);
225
- component2 = "component_".concat(components.length - 1);
226
- } else {
227
- lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
228
- component2 = "lazy(".concat(lazyImport, ")");
229
- }
230
- }
231
- } else if (route2._component) {
232
- if (splitRouteChunks) {
233
- lazyImport = "() => import('".concat(route2._component, "')");
234
- component2 = "loadable(".concat(lazyImport, ")");
235
- } else {
236
- components.push(route2._component);
237
- component2 = "component_".concat(components.length - 1);
238
- }
239
- }
240
- var finalRoute2 = _object_spread_props(_object_spread({}, route2), {
241
- lazyImport,
242
- loading,
243
- loader,
244
- action,
245
- config,
246
- error,
247
- children
248
- });
249
- if (route2._component) {
250
- finalRoute2.component = component2;
251
- }
252
- if (route2.type === "nested" && route2._component && (route2.loader || route2.data)) {
253
- finalRoute2.shouldRevalidate = 'createShouldRevalidate("'.concat(route2.id, '")');
254
- }
255
- return finalRoute2;
256
- };
257
- routeComponentsCode = "\n export const routes = [\n ";
258
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
259
- try {
260
- for (_iterator = routes[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
261
- route = _step.value;
262
- if ("type" in route) {
263
- newRoute = traverseRouteTree(route);
264
- routeStr = JSON.stringify(newRoute, null, 2);
265
- keywords = [
266
- "component",
267
- "lazyImport",
268
- "shouldRevalidate",
269
- "loader",
270
- "action",
271
- "loading",
272
- "error",
273
- "config"
274
- ];
275
- regs = keywords.map(createMatchReg);
276
- newRouteStr = regs.reduce(function(acc, reg) {
277
- return acc.replace(reg, "$1$2");
278
- }, routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
279
- routeComponentsCode += "".concat(newRouteStr, ",");
280
- } else {
281
- component = "loadable(() => import('".concat(route._component, "'))");
282
- finalRoute = _object_spread_props(_object_spread({}, route), {
283
- component
284
- });
285
- keywords1 = [
286
- "component",
287
- "lazyImport"
288
- ];
289
- routeStr1 = JSON.stringify(finalRoute, null, 2);
290
- regs1 = keywords1.map(createMatchReg);
291
- newRouteStr1 = regs1.reduce(function(acc, reg) {
292
- return acc.replace(reg, "$1$2");
293
- }, routeStr1).replace(/\\"/g, '"');
294
- routeComponentsCode += "".concat(newRouteStr1, ",");
295
- }
296
- }
297
- } catch (err) {
298
- _didIteratorError = true;
299
- _iteratorError = err;
300
- } finally {
301
- try {
302
- if (!_iteratorNormalCompletion && _iterator.return != null) {
303
- _iterator.return();
304
- }
305
- } finally {
306
- if (_didIteratorError) {
307
- throw _iteratorError;
308
- }
309
- }
310
- }
311
- routeComponentsCode += "\n];";
312
- importLoadingCode = loadings.map(function(loading, index2) {
313
- return "import loading_".concat(index2, " from '").concat(loading, "';\n");
314
- }).join("");
315
- importComponentsCode = components.map(function(component2, index2) {
316
- return "import component_".concat(index2, " from '").concat(component2, "';\n");
317
- }).join("");
318
- importErrorComponentsCode = errors.map(function(error, index2) {
319
- return "import error_".concat(index2, " from '").concat(error, "';\n");
320
- }).join("");
321
- importLoadersCode = "";
322
- _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
323
- try {
324
- for (_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
325
- _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
326
- if (loaderInfo.inline) {
327
- route1 = loaderInfo.route;
328
- if (route1.action) {
329
- importLoadersCode += "import { loader as ".concat(key, ", action as action_").concat(loaderInfo.loaderId, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath({
330
- loaderId: key,
331
- clientData: loaderInfo.clientData,
332
- action: route1.action,
333
- inline: loaderInfo.inline,
334
- routeId: loaderInfo.routeId
335
- }), '";\n');
336
- } else {
337
- importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath({
338
- loaderId: key,
339
- clientData: loaderInfo.clientData,
340
- action: false,
341
- inline: loaderInfo.inline,
342
- routeId: route1.id
343
- }), '";\n');
344
- }
345
- } else {
346
- importLoadersCode += "import ".concat(key, ' from "').concat(slash(loaderInfo.filePath)).concat(getDataLoaderPath({
347
- loaderId: key,
348
- clientData: loaderInfo.clientData,
349
- action: false,
350
- inline: loaderInfo.inline,
351
- routeId: loaderInfo.routeId
352
- }), '";\n');
353
- }
354
- }
355
- } catch (err) {
356
- _didIteratorError1 = true;
357
- _iteratorError1 = err;
358
- } finally {
359
- try {
360
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
361
- _iterator1.return();
362
- }
363
- } finally {
364
- if (_didIteratorError1) {
365
- throw _iteratorError1;
366
- }
367
- }
368
- }
369
- importConfigsCode = "";
370
- _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
371
- try {
372
- for (_iterator2 = Object.entries(configsMap)[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
373
- _step_value1 = _sliced_to_array(_step2.value, 2), key1 = _step_value1[0], configPath = _step_value1[1];
374
- importConfigsCode += "import * as ".concat(key1, ' from "').concat(slash(configPath), '";\n');
375
- }
376
- } catch (err) {
377
- _didIteratorError2 = true;
378
- _iteratorError2 = err;
379
- } finally {
380
- try {
381
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
382
- _iterator2.return();
383
- }
384
- } finally {
385
- if (_didIteratorError2) {
386
- throw _iteratorError2;
387
- }
388
- }
389
- }
390
- return [
391
- 4,
392
- fs.ensureFile(loadersMapFile)
393
- ];
394
- case 1:
395
- _state.sent();
396
- return [
397
- 4,
398
- fs.writeJSON(loadersMapFile, loadersMap)
399
- ];
400
- case 2:
401
- _state.sent();
402
- importRuntimeRouterCode = "\n import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';\n ";
403
- routeModulesCode = "\n if(typeof document !== 'undefined'){\n window.".concat(ROUTE_MODULES, " = {}\n }\n ");
404
- return [
405
- 2,
406
- "\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(importRuntimeRouterCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(importConfigsCode, "\n ").concat(routeModulesCode, "\n ").concat(routeComponentsCode, "\n ")
407
- ];
408
- }
409
- });
410
- });
411
- return function fileSystemRoutes2(_) {
412
- return _ref.apply(this, arguments);
413
- };
414
- }();
415
- function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
416
- var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
417
- var packageName = appContext.packageName, internalDirectory = appContext.internalDirectory;
418
- var ssr = getEntryOptions(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
419
- var ssg = isSSGEntry(config, entryName, entrypoints);
420
- if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
421
- var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
422
- var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
423
- var combinedModule = 'export * from "'.concat(slash(serverLoaderRuntime), '"; export * from "').concat(slash(serverLoadersFile), '"');
424
- return combinedModule;
425
- }
426
- return null;
427
- }
428
- export {
429
- fileSystemRoutes,
430
- html,
431
- index,
432
- renderFunction,
433
- routesForServer,
434
- ssrLoaderCombinedModule
435
- };
@@ -1,40 +0,0 @@
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
- function getServerInternalPlugins(api) {
6
- return _getServerInternalPlugins.apply(this, arguments);
7
- }
8
- function _getServerInternalPlugins() {
9
- _getServerInternalPlugins = _async_to_generator(function(api) {
10
- var hookRunners, _ref, serverPlugins, serverInternalPlugins;
11
- return _ts_generator(this, function(_state) {
12
- switch (_state.label) {
13
- case 0:
14
- hookRunners = api.useHookRunners();
15
- return [
16
- 4,
17
- hookRunners.collectServerPlugins({
18
- plugins: []
19
- })
20
- ];
21
- case 1:
22
- _ref = _state.sent(), serverPlugins = _ref.plugins;
23
- serverInternalPlugins = serverPlugins.reduce(function(result, plugin) {
24
- return Object.assign(result, plugin);
25
- }, {});
26
- api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
27
- serverInternalPlugins
28
- }));
29
- return [
30
- 2,
31
- serverInternalPlugins
32
- ];
33
- }
34
- });
35
- });
36
- return _getServerInternalPlugins.apply(this, arguments);
37
- }
38
- export {
39
- getServerInternalPlugins
40
- };
@@ -1,76 +0,0 @@
1
- const JS_EXTENSIONS = [
2
- ".js",
3
- ".ts",
4
- ".jsx",
5
- ".tsx"
6
- ];
7
- const INDEX_FILE_NAME = "index";
8
- const APP_FILE_NAME = "App";
9
- const PAGES_DIR_NAME = "pages";
10
- const NESTED_ROUTES_DIR = "routes";
11
- const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
12
- const LOADER_EXPORT_NAME = "loader";
13
- const ACTION_EXPORT_NAME = "action";
14
- const TEMP_LOADERS_DIR = "__loaders__";
15
- const ENTRY_POINT_FILE_NAME = "index.jsx";
16
- const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
17
- const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
18
- const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
19
- const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
20
- const FILE_SYSTEM_ROUTES_INDEX = "index";
21
- const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
22
- const HTML_PARTIALS_FOLDER = "html";
23
- const HTML_PARTIALS_EXTENSIONS = [
24
- ".htm",
25
- ".html",
26
- ".ejs"
27
- ];
28
- const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
29
- const NESTED_ROUTE = {
30
- LAYOUT_FILE: "layout",
31
- LAYOUT_CONFIG_FILE: "layout.config",
32
- LAYOUT_LOADER_FILE: "layout.loader",
33
- LAYOUT_DATA_FILE: "layout.data",
34
- LAYOUT_CLIENT_LOADER: "layout.data.client",
35
- PAGE_FILE: "page",
36
- PAGE_CONFIG_FILE: "page.config",
37
- PAGE_LOADER_FILE: "page.loader",
38
- PAGE_DATA_FILE: "page.data",
39
- PAGE_CLIENT_LOADER: "page.data.client",
40
- SPLATE_FILE: "$",
41
- SPLATE_CONFIG_FILE: "$.config",
42
- SPLATE_LOADER_FILE: "$.loader",
43
- SPLATE_DATA_FILE: "$.data",
44
- SPLATE_CLIENT_DATA: "$.data.client",
45
- LOADING_FILE: "loading",
46
- ERROR_FILE: "error",
47
- LOADER_FILE: "loader"
48
- };
49
- const APP_CONFIG_NAME = "config";
50
- const APP_INIT_EXPORTED = "init";
51
- const APP_INIT_IMPORTED = "appInit";
52
- export {
53
- ACTION_EXPORT_NAME,
54
- APP_CONFIG_NAME,
55
- APP_FILE_NAME,
56
- APP_INIT_EXPORTED,
57
- APP_INIT_IMPORTED,
58
- ENTRY_BOOTSTRAP_FILE_NAME,
59
- ENTRY_POINT_FILE_NAME,
60
- FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
61
- FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
62
- FILE_SYSTEM_ROUTES_FILE_NAME,
63
- FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
64
- FILE_SYSTEM_ROUTES_IGNORED_REGEX,
65
- FILE_SYSTEM_ROUTES_INDEX,
66
- FILE_SYSTEM_ROUTES_LAYOUT,
67
- HTML_PARTIALS_EXTENSIONS,
68
- HTML_PARTIALS_FOLDER,
69
- INDEX_FILE_NAME,
70
- JS_EXTENSIONS,
71
- LOADER_EXPORT_NAME,
72
- NESTED_ROUTE,
73
- NESTED_ROUTES_DIR,
74
- PAGES_DIR_NAME,
75
- TEMP_LOADERS_DIR
76
- };