@modern-js/app-tools 2.53.1-alpha.3 → 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 (214) 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/dependencies/index.js +16 -25
  20. package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
  21. package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
  22. package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
  23. package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
  24. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  25. package/dist/cjs/plugins/serverBuild.js +10 -4
  26. package/dist/cjs/utils/createServer.js +1 -1
  27. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  30. package/dist/esm/commands/build.js +16 -9
  31. package/dist/esm/commands/deploy.js +2 -2
  32. package/dist/esm/commands/dev.js +13 -9
  33. package/dist/esm/commands/index.js +411 -3
  34. package/dist/esm/commands/serve.js +12 -8
  35. package/dist/esm/hooks.js +5 -0
  36. package/dist/esm/index.js +12 -394
  37. package/dist/esm/plugins/analyze/constants.js +24 -0
  38. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  39. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  40. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  41. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  42. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  43. package/dist/esm/plugins/analyze/templates.js +22 -0
  44. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  45. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  46. package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
  47. package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
  48. package/dist/esm/plugins/deploy/platforms/node.js +8 -14
  49. package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
  50. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  51. package/dist/esm/plugins/serverBuild.js +13 -6
  52. package/dist/esm/utils/createServer.js +2 -2
  53. package/dist/esm/utils/loadPlugins.js +64 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  56. package/dist/esm-node/commands/build.js +2 -0
  57. package/dist/esm-node/commands/deploy.js +2 -2
  58. package/dist/esm-node/commands/dev.js +11 -7
  59. package/dist/esm-node/commands/index.js +92 -3
  60. package/dist/esm-node/commands/serve.js +10 -6
  61. package/dist/esm-node/hooks.js +5 -0
  62. package/dist/esm-node/index.js +12 -79
  63. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  64. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  65. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  66. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  67. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  68. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  69. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  70. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  71. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  72. package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
  73. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
  74. package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
  75. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
  76. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  77. package/dist/esm-node/plugins/serverBuild.js +11 -5
  78. package/dist/esm-node/utils/createServer.js +2 -2
  79. package/dist/esm-node/utils/loadPlugins.js +21 -0
  80. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +10 -3
  82. package/dist/types/config/initialize/inits.d.ts +1 -1
  83. package/dist/types/exports/server.d.ts +4 -0
  84. package/dist/types/index.d.ts +2 -5
  85. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  86. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  87. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  88. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  89. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  90. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  91. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  92. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  93. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  94. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
  95. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  96. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  97. package/dist/types/types/hooks.d.ts +11 -1
  98. package/dist/types/utils/loadPlugins.d.ts +5 -0
  99. package/package.json +22 -30
  100. package/dist/cjs/analyze/constants.js +0 -122
  101. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  102. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  103. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  104. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  105. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  106. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  107. package/dist/cjs/analyze/templates.js +0 -444
  108. package/dist/cjs/plugins/deploy/exports.js +0 -28
  109. package/dist/esm/analyze/constants.js +0 -76
  110. package/dist/esm/analyze/getBundleEntry.js +0 -75
  111. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  112. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  113. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  114. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  115. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  116. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  117. package/dist/esm/analyze/nestedRoutes.js +0 -398
  118. package/dist/esm/analyze/templates.js +0 -435
  119. package/dist/esm/plugins/deploy/exports.js +0 -4
  120. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  121. package/dist/esm-node/analyze/constants.js +0 -76
  122. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  123. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  124. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  125. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  126. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  127. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  128. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  129. package/dist/esm-node/analyze/templates.js +0 -405
  130. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  131. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  132. package/dist/js/modern/analyze/constants.js +0 -15
  133. package/dist/js/modern/analyze/generateCode.js +0 -179
  134. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  135. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  136. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  137. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  138. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  139. package/dist/js/modern/analyze/index.js +0 -148
  140. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  141. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  142. package/dist/js/modern/analyze/templates.js +0 -88
  143. package/dist/js/modern/analyze/utils.js +0 -92
  144. package/dist/js/modern/commands/build.js +0 -154
  145. package/dist/js/modern/commands/deploy.js +0 -5
  146. package/dist/js/modern/commands/dev.js +0 -95
  147. package/dist/js/modern/commands/index.js +0 -3
  148. package/dist/js/modern/commands/inspect.js +0 -69
  149. package/dist/js/modern/commands/start.js +0 -31
  150. package/dist/js/modern/exports/server.js +0 -1
  151. package/dist/js/modern/hooks.js +0 -21
  152. package/dist/js/modern/index.js +0 -109
  153. package/dist/js/modern/locale/en.js +0 -35
  154. package/dist/js/modern/locale/index.js +0 -9
  155. package/dist/js/modern/locale/zh.js +0 -35
  156. package/dist/js/modern/utils/config.js +0 -78
  157. package/dist/js/modern/utils/createCompiler.js +0 -61
  158. package/dist/js/modern/utils/createServer.js +0 -18
  159. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  160. package/dist/js/modern/utils/language.js +0 -5
  161. package/dist/js/modern/utils/printInstructions.js +0 -11
  162. package/dist/js/modern/utils/routes.js +0 -15
  163. package/dist/js/modern/utils/types.js +0 -0
  164. package/dist/js/node/analyze/constants.js +0 -36
  165. package/dist/js/node/analyze/generateCode.js +0 -208
  166. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  167. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  168. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  169. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  170. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  171. package/dist/js/node/analyze/index.js +0 -178
  172. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  173. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  174. package/dist/js/node/analyze/templates.js +0 -106
  175. package/dist/js/node/analyze/utils.js +0 -113
  176. package/dist/js/node/commands/build.js +0 -174
  177. package/dist/js/node/commands/deploy.js +0 -14
  178. package/dist/js/node/commands/dev.js +0 -120
  179. package/dist/js/node/commands/index.js +0 -44
  180. package/dist/js/node/commands/inspect.js +0 -98
  181. package/dist/js/node/commands/start.js +0 -47
  182. package/dist/js/node/exports/server.js +0 -13
  183. package/dist/js/node/hooks.js +0 -39
  184. package/dist/js/node/index.js +0 -141
  185. package/dist/js/node/locale/en.js +0 -42
  186. package/dist/js/node/locale/index.js +0 -20
  187. package/dist/js/node/locale/zh.js +0 -42
  188. package/dist/js/node/utils/config.js +0 -103
  189. package/dist/js/node/utils/createCompiler.js +0 -81
  190. package/dist/js/node/utils/createServer.js +0 -35
  191. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  192. package/dist/js/node/utils/language.js +0 -13
  193. package/dist/js/node/utils/printInstructions.js +0 -22
  194. package/dist/js/node/utils/routes.js +0 -25
  195. package/dist/js/node/utils/types.js +0 -0
  196. package/dist/types/analyze/constants.d.ts +0 -42
  197. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  198. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  199. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  200. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  201. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  202. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  203. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  204. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  205. package/dist/types/analyze/templates.d.ts +0 -30
  206. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  207. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  208. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  209. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  210. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  211. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  212. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  213. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  214. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -36,10 +36,8 @@ module.exports = __toCommonJS(generateCode_exports);
36
36
  var import_path = __toESM(require("path"));
37
37
  var import_utils = require("@modern-js/utils");
38
38
  var templates = __toESM(require("./templates"));
39
- var import_getClientRoutes = require("./getClientRoutes");
40
39
  var import_constants = require("./constants");
41
40
  var import_utils2 = require("./utils");
42
- var import_nestedRoutes = require("./nestedRoutes");
43
41
  const createImportSpecifier = (specifiers) => {
44
42
  let defaults = "";
45
43
  const named = [];
@@ -85,92 +83,17 @@ ${initialize || ""}`);
85
83
  ${initialize || ""}`).join("\n");
86
84
  };
87
85
  const generateCode = async (appContext, config, entrypoints, api) => {
88
- const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
86
+ const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile } = appContext;
89
87
  const hookRunners = api.useHookRunners();
90
- const isV5 = (0, import_utils.isRouterV5)(config);
91
- const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
88
+ const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
92
89
  const importsStatemets = /* @__PURE__ */ new Map();
93
- const 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;
94
- await Promise.all(entrypoints.map(generateEntryCode));
90
+ await Promise.all(entrypoints.map((entrypoint) => generateEntryCode(entrypoint, customRuntimeConfig)));
95
91
  return {
96
92
  importsStatemets
97
93
  };
98
- async function generateEntryCode(entrypoint) {
99
- const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
94
+ async function generateEntryCode(entrypoint, customRuntimeConfig2) {
95
+ const { entryName, isAutoMount } = entrypoint;
100
96
  if (isAutoMount) {
101
- if (fileSystemRoutes) {
102
- var _config_output;
103
- let initialRoutes = [];
104
- let nestedRoutes = null;
105
- if (entrypoint.entry) {
106
- initialRoutes = getRoutes({
107
- entrypoint,
108
- srcDirectory,
109
- srcAlias: internalSrcAlias,
110
- internalDirectory,
111
- internalDirAlias
112
- });
113
- }
114
- if (!isV5 && entrypoint.nestedRoutesEntry) {
115
- nestedRoutes = await (0, import_nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
116
- name: internalSrcAlias,
117
- basename: srcDirectory
118
- }, entrypoint.entryName, entrypoint.isMainEntry, oldVersion);
119
- if (nestedRoutes) {
120
- if (!Array.isArray(nestedRoutes)) {
121
- nestedRoutes = [
122
- nestedRoutes
123
- ];
124
- }
125
- for (const route of nestedRoutes) {
126
- initialRoutes.unshift(route);
127
- }
128
- }
129
- }
130
- const { routes } = await hookRunners.modifyFileSystemRoutes({
131
- entrypoint,
132
- routes: initialRoutes
133
- });
134
- const config2 = api.useResolvedConfigContext();
135
- const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
136
- const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
137
- let mode;
138
- if (ssr) {
139
- mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
140
- }
141
- if (mode === "stream") {
142
- const hasPageRoute = routes.some((route) => "type" in route && route.type === "page");
143
- if (hasPageRoute) {
144
- import_utils.logger.error("Streaming ssr is not supported when pages dir exists");
145
- process.exit(1);
146
- }
147
- }
148
- const { code } = await hookRunners.beforeGenerateRoutes({
149
- entrypoint,
150
- code: await templates.fileSystemRoutes({
151
- routes,
152
- ssrMode: useSSG ? "string" : mode,
153
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
154
- entryName: entrypoint.entryName,
155
- internalDirectory,
156
- splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
157
- })
158
- });
159
- if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
160
- const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
161
- const code2 = templates.routesForServer({
162
- routes
163
- });
164
- await import_utils.fs.ensureFile(routesServerFile);
165
- await import_utils.fs.writeFile(routesServerFile, code2);
166
- }
167
- const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
168
- if (serverLoaderCombined) {
169
- const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(internalDirectory, entryName);
170
- await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
171
- }
172
- import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, "utf8");
173
- }
174
97
  const { imports } = await hookRunners.modifyEntryImports({
175
98
  entrypoint,
176
99
  imports: (0, import_utils2.getDefaultImports)({
@@ -178,7 +101,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
178
101
  srcDirectory,
179
102
  appDirectory,
180
103
  internalSrcAlias,
181
- internalDirAlias
104
+ internalDirAlias,
105
+ runtimeConfigFile,
106
+ customRuntimeConfig: customRuntimeConfig2
182
107
  })
183
108
  });
184
109
  importsStatemets.set(entryName, imports);
@@ -190,7 +115,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
190
115
  const generateIndexCode = async ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs }) => {
191
116
  const hookRunners = api.useHookRunners();
192
117
  const { mountId } = config.html;
193
- const { internalDirectory, packageName } = appContext;
118
+ const { internalDirectory, packageName, srcDirectory, runtimeConfigFile } = appContext;
119
+ const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
194
120
  await Promise.all(entrypoints.map(async (entrypoint) => {
195
121
  const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
196
122
  if (isAutoMount) {
@@ -204,6 +130,7 @@ const generateIndexCode = async ({ appContext, api, entrypoints, config, imports
204
130
  code: templates.renderFunction({
205
131
  plugins,
206
132
  customBootstrap,
133
+ customRuntimeConfig,
207
134
  fileSystemRoutes
208
135
  })
209
136
  });
@@ -34,11 +34,10 @@ module.exports = __toCommonJS(getBundleEntry_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
36
  var import_getFileSystemEntry = require("./getFileSystemEntry");
37
- var import_constants = require("./constants");
38
37
  var import_utils2 = require("./utils");
39
38
  const ensureExtensions = (file) => {
40
39
  if (!import_path.default.extname(file)) {
41
- return (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => `${file}${ext}`)) || file;
40
+ return (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => `${file}${ext}`)) || file;
42
41
  }
43
42
  return file;
44
43
  };
@@ -56,32 +55,24 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
56
55
  }
57
56
  return false;
58
57
  });
59
- const getBundleEntry = (appContext, config) => {
58
+ const getBundleEntry = async (hookRunners, appContext, config) => {
60
59
  const { appDirectory, packageName } = appContext;
61
60
  const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
62
- const defaults = disableDefaultEntries ? [] : (0, import_getFileSystemEntry.getFileSystemEntry)(appContext, config);
61
+ const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(hookRunners, appContext, config);
63
62
  if (entries) {
64
63
  Object.keys(entries).forEach((name) => {
65
64
  const value = entries[name];
66
- const entrypoint = typeof value === "string" ? {
65
+ const entryName = typeof value === "string" ? value : value.entry;
66
+ const isAutoMount = typeof value === "string" ? true : !value.disableMount;
67
+ const entrypoint = {
67
68
  entryName: name,
68
69
  isMainEntry: false,
69
- entry: (0, import_utils.ensureAbsolutePath)(appDirectory, value),
70
- absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory, value)) ? (0, import_utils.ensureAbsolutePath)(appDirectory, value) : import_path.default.dirname((0, import_utils.ensureAbsolutePath)(appDirectory, value)),
71
- isAutoMount: true,
72
- fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, value)).isDirectory() ? {} : void 0
73
- } : {
74
- entryName: name,
75
- isMainEntry: false,
76
- entry: (0, import_utils.ensureAbsolutePath)(appDirectory, value.entry),
77
- absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)) ? (0, import_utils.ensureAbsolutePath)(appDirectory, value.entry) : import_path.default.dirname((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)),
78
- isAutoMount: !value.disableMount,
79
- customBootstrap: value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
80
- fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)).isDirectory() ? {} : void 0
70
+ entry: (0, import_utils.ensureAbsolutePath)(appDirectory, entryName),
71
+ absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)) ? (0, import_utils.ensureAbsolutePath)(appDirectory, entryName) : import_path.default.dirname((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)),
72
+ isAutoMount,
73
+ customBootstrap: typeof value === "string" ? false : value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
74
+ fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)).isDirectory() ? {} : void 0
81
75
  };
82
- if (entrypoint.fileSystemRoutes && !(0, import_utils.isRouterV5)(config)) {
83
- entrypoint.nestedRoutesEntry = entrypoint.entry;
84
- }
85
76
  if (!ifAlreadyExists(defaults, entrypoint)) {
86
77
  defaults.push(entrypoint);
87
78
  }
@@ -34,14 +34,16 @@ module.exports = __toCommonJS(getFileSystemEntry_exports);
34
34
  var import_fs = __toESM(require("fs"));
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("@modern-js/utils");
37
- var import_isDefaultExportFunction = require("./isDefaultExportFunction");
38
37
  var import_constants = require("./constants");
39
- const hasIndex = (dir) => (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
40
- const hasApp = (dir) => (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.APP_FILE_NAME}${ext}`)));
41
- const hasPages = (dir) => import_fs.default.existsSync(import_path.default.join(dir, import_constants.PAGES_DIR_NAME));
42
- const hasNestedRoutes = (dir) => import_fs.default.existsSync(import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR));
43
- const isBundleEntry = (dir) => hasApp(dir) || hasPages(dir) || hasIndex(dir) || hasNestedRoutes(dir);
44
- const scanDir = (dirs) => dirs.map((dir) => {
38
+ var import_isDefaultExportFunction = require("./isDefaultExportFunction");
39
+ const hasIndex = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
40
+ const isBundleEntry = async (hookRunners, dir) => {
41
+ return (await hookRunners.checkEntryPoint({
42
+ path: dir,
43
+ entry: false
44
+ })).entry || hasIndex(dir);
45
+ };
46
+ const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
45
47
  const indexFile = hasIndex(dir);
46
48
  const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
47
49
  const entryName = import_path.default.basename(dir);
@@ -51,53 +53,27 @@ const scanDir = (dirs) => dirs.map((dir) => {
51
53
  isMainEntry: false,
52
54
  entry: indexFile,
53
55
  absoluteEntryDir: import_path.default.resolve(dir),
54
- isAutoMount: false
56
+ isAutoMount: false,
57
+ customBootstrap
55
58
  };
56
59
  }
57
- const isHasApp = hasApp(dir);
58
- if (isHasApp) {
60
+ const entryFile = (await hookRunners.checkEntryPoint({
61
+ path: dir,
62
+ entry: false
63
+ })).entry;
64
+ if (entryFile) {
59
65
  return {
60
66
  entryName,
61
67
  isMainEntry: false,
62
- entry: import_path.default.join(dir, import_constants.APP_FILE_NAME),
63
- isAutoMount: true,
68
+ entry: entryFile,
64
69
  absoluteEntryDir: import_path.default.resolve(dir),
65
- customBootstrap
66
- };
67
- }
68
- const isHasNestedRoutes = hasNestedRoutes(dir);
69
- const isHasPages = hasPages(dir);
70
- if (isHasNestedRoutes || isHasPages) {
71
- const entrypoint = {
72
- entryName,
73
- isMainEntry: false,
74
- entry: "",
75
- fileSystemRoutes: {
76
- globalApp: (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `./${import_constants.PAGES_DIR_NAME}/${import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
77
- },
78
70
  isAutoMount: true,
79
- absoluteEntryDir: import_path.default.resolve(dir),
80
71
  customBootstrap
81
72
  };
82
- if (isHasPages) {
83
- entrypoint.entry = import_path.default.join(dir, import_constants.PAGES_DIR_NAME);
84
- entrypoint.pageRoutesEntry = entrypoint.entry;
85
- }
86
- if (isHasNestedRoutes) {
87
- entrypoint.entry = import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR);
88
- entrypoint.nestedRoutesEntry = entrypoint.entry;
89
- }
90
- return entrypoint;
91
73
  }
92
- return {
93
- entryName,
94
- isMainEntry: false,
95
- entry: indexFile,
96
- absoluteEntryDir: import_path.default.resolve(dir),
97
- isAutoMount: false
98
- };
99
- });
100
- const getFileSystemEntry = (appContext, config) => {
74
+ throw Error("There is no valid entry point in the current project!");
75
+ }));
76
+ const getFileSystemEntry = async (hookRunners, appContext, config) => {
101
77
  const { appDirectory } = appContext;
102
78
  const { source: { entriesDir, disableEntryDirs } } = config;
103
79
  let disabledDirs = [];
@@ -107,9 +83,19 @@ const getFileSystemEntry = (appContext, config) => {
107
83
  const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
108
84
  if (import_fs.default.existsSync(src)) {
109
85
  if (import_fs.default.statSync(src).isDirectory()) {
110
- return scanDir(isBundleEntry(src) ? [
111
- src
112
- ] : import_fs.default.readdirSync(src).map((file) => import_path.default.join(src, file)).filter((file) => import_fs.default.statSync(file).isDirectory() && isBundleEntry(file) && !disabledDirs.includes(file)));
86
+ if (await isBundleEntry(hookRunners, src)) {
87
+ return scanDir(hookRunners, [
88
+ src
89
+ ]);
90
+ }
91
+ const dirs = [];
92
+ await Promise.all(import_fs.default.readdirSync(src).map(async (filename) => {
93
+ const file = import_path.default.join(src, filename);
94
+ if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
95
+ dirs.push(file);
96
+ }
97
+ }));
98
+ return scanDir(hookRunners, dirs);
113
99
  } else {
114
100
  throw Error(`source.entriesDir accept a directory.`);
115
101
  }
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(getServerRoutes_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_utils = require("@modern-js/utils");
37
- var import_routes = require("../utils/routes");
37
+ var import_routes = require("../../utils/routes");
38
38
  var import_utils2 = require("./utils");
39
39
  const applyBaseUrl = (baseUrl, routes) => {
40
40
  if (baseUrl) {
@@ -33,13 +33,12 @@ __export(analyze_exports, {
33
33
  module.exports = __toCommonJS(analyze_exports);
34
34
  var path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- var import_lodash = require("@modern-js/utils/lodash");
37
- var import_printInstructions = require("../utils/printInstructions");
38
- var import_routes = require("../utils/routes");
39
- var import_config = require("../utils/config");
40
- var import_getSelectedEntries = require("../utils/getSelectedEntries");
41
- var import_config2 = require("../config");
42
- var import_builder = require("../builder");
36
+ var import_printInstructions = require("../../utils/printInstructions");
37
+ var import_routes = require("../../utils/routes");
38
+ var import_config = require("../../utils/config");
39
+ var import_getSelectedEntries = require("../../utils/getSelectedEntries");
40
+ var import_config2 = require("../../config");
41
+ var import_builder = require("../../builder");
43
42
  var import_utils2 = require("./utils");
44
43
  var import_constants = require("./constants");
45
44
  var import_generateCode = require("./generateCode");
@@ -49,7 +48,6 @@ var analyze_default = ({ bundler }) => ({
49
48
  setup: (api) => {
50
49
  let pagesDir = [];
51
50
  let nestedRouteEntries = [];
52
- let originEntrypoints = [];
53
51
  return {
54
52
  async prepare() {
55
53
  var _resolvedConfig_source;
@@ -83,7 +81,9 @@ var analyze_default = ({ bundler }) => ({
83
81
  Promise.resolve().then(() => __toESM(require("./generateCode"))),
84
82
  Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
85
83
  ]);
86
- const entrypoints = getBundleEntry(appContext, resolvedConfig);
84
+ const { entrypoints } = await hookRunners.modifyEntrypoints({
85
+ entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
86
+ });
87
87
  debug(`entrypoints: %o`, entrypoints);
88
88
  const initialRoutes = getServerRoutes(entrypoints, {
89
89
  appContext,
@@ -101,7 +101,6 @@ var analyze_default = ({ bundler }) => ({
101
101
  api.setAppContext(appContext);
102
102
  nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
103
103
  pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
104
- originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
105
104
  const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
106
105
  const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
107
106
  appContext,
@@ -245,20 +244,6 @@ var analyze_default = ({ bundler }) => ({
245
244
  entrypoint,
246
245
  imports
247
246
  };
248
- },
249
- async fileChange(e) {
250
- const appContext = api.useAppContext();
251
- const { appDirectory } = appContext;
252
- const { filename, eventType } = e;
253
- const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
254
- const absoluteFilePath = path.resolve(appDirectory, filename);
255
- const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils2.isPageComponentFile)(absoluteFilePath);
256
- if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
257
- const resolvedConfig = api.useResolvedConfigContext();
258
- const { generateCode } = await Promise.resolve().then(() => __toESM(require("./generateCode")));
259
- const entrypoints = (0, import_lodash.cloneDeep)(originEntrypoints);
260
- generateCode(appContext, resolvedConfig, entrypoints, api);
261
- }
262
247
  }
263
248
  };
264
249
  }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var templates_exports = {};
20
+ __export(templates_exports, {
21
+ html: () => html,
22
+ index: () => index,
23
+ renderFunction: () => renderFunction
24
+ });
25
+ module.exports = __toCommonJS(templates_exports);
26
+ var import_constants = require("./constants");
27
+ const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
28
+ const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
29
+ const IS_REACT18 = process.env.IS_REACT18 === 'true';
30
+ const MOUNT_ID = '${mountId}';
31
+
32
+ ${imports}
33
+
34
+ let AppWrapper = null;
35
+
36
+ let root = null;
37
+
38
+ function render() {
39
+ ${renderFunction2}
40
+ }
41
+
42
+ AppWrapper = render();
43
+
44
+ ${exportStatement};
45
+ `;
46
+ const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
47
+ const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
48
+ const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
49
+ return `
50
+ const finalAppConfig = {
51
+ ...App.config,
52
+ ...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
53
+ }
54
+
55
+ AppWrapper = createApp({
56
+ plugins: [
57
+ ${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
58
+ ${customRuntimeConfig ? runtimePlugins : ""}
59
+ ]
60
+ })(${fileSystemRoutes ? "" : `App`})
61
+
62
+
63
+ if(!AppWrapper.init && typeof appInit !== 'undefined') {
64
+ AppWrapper.init = appInit;
65
+ }
66
+
67
+
68
+ if (IS_BROWSER) {
69
+ ${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
70
+ }
71
+
72
+ return AppWrapper
73
+ `;
74
+ };
75
+ const html = (partials) => `
76
+ <!DOCTYPE html>
77
+ <html>
78
+ <head>
79
+
80
+ ${partials.top.join("\n")}
81
+
82
+ ${partials.head.join("\n")}
83
+
84
+ </head>
85
+
86
+ <body>
87
+ <div id="<%= mountId %>"><!--<?- html ?>--></div>
88
+ ${partials.body.join("\n")}
89
+ <!--<?- chunksMap.js ?>-->
90
+ <!--<?- SSRDataScript ?>-->
91
+ <!--<?- bottomTemplate ?>-->
92
+ </body>
93
+
94
+ </html>
95
+ `;
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ html,
99
+ index,
100
+ renderFunction
101
+ });
@@ -31,10 +31,6 @@ __export(utils_exports, {
31
31
  checkIsBuildCommands: () => checkIsBuildCommands,
32
32
  getDefaultImports: () => getDefaultImports,
33
33
  getServerCombinedModueFile: () => getServerCombinedModueFile,
34
- getServerLoadersFile: () => getServerLoadersFile,
35
- hasAction: () => hasAction,
36
- hasLoader: () => hasLoader,
37
- isPageComponentFile: () => isPageComponentFile,
38
34
  isSubDirOrEqual: () => isSubDirOrEqual,
39
35
  parseModule: () => parseModule,
40
36
  replaceWithAlias: () => replaceWithAlias,
@@ -61,7 +57,7 @@ const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previo
61
57
  ];
62
58
  }
63
59
  }, []);
64
- const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias }) => {
60
+ const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
65
61
  const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
66
62
  const imports = [
67
63
  {
@@ -132,21 +128,17 @@ const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrc
132
128
  value: (0, import_utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
133
129
  });
134
130
  }
135
- return imports;
136
- };
137
- const isPageComponentFile = (filePath) => {
138
- if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
139
- return false;
140
- }
141
- if ([
142
- ".js",
143
- ".jsx",
144
- ".ts",
145
- ".tsx"
146
- ].includes(import_path.default.extname(filePath))) {
147
- return true;
131
+ if (customRuntimeConfig) {
132
+ imports.push({
133
+ specifiers: [
134
+ {
135
+ local: "runtimeConfig"
136
+ }
137
+ ],
138
+ value: import_path.default.join(internalSrcAlias, runtimeConfigFile || "")
139
+ });
148
140
  }
149
- return false;
141
+ return imports;
150
142
  };
151
143
  const replaceWithAlias = (base, filePath, alias) => {
152
144
  if (filePath.includes(base)) {
@@ -157,7 +149,7 @@ const replaceWithAlias = (base, filePath, alias) => {
157
149
  };
158
150
  const parseModule = async ({ source, filename }) => {
159
151
  let content = source;
160
- if (import_constants.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
152
+ if (import_utils.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
161
153
  const result = await (0, import_esbuild.transform)(content, {
162
154
  loader: import_path.default.extname(filename).slice(1),
163
155
  format: "esm"
@@ -166,37 +158,6 @@ const parseModule = async ({ source, filename }) => {
166
158
  }
167
159
  return await (0, import_es_module_lexer.parse)(content);
168
160
  };
169
- const hasLoader = async (filename, source) => {
170
- let content = source;
171
- if (!source) {
172
- content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
173
- }
174
- if (content) {
175
- const [, moduleExports] = await parseModule({
176
- source: content.toString(),
177
- filename
178
- });
179
- return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
180
- }
181
- return false;
182
- };
183
- const hasAction = async (filename, source) => {
184
- let content = source;
185
- if (!source) {
186
- content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
187
- }
188
- if (content) {
189
- const [, moduleExports] = await parseModule({
190
- source: content.toString(),
191
- filename
192
- });
193
- return moduleExports.some((e) => e.n === import_constants.ACTION_EXPORT_NAME);
194
- }
195
- return false;
196
- };
197
- const getServerLoadersFile = (internalDirectory, entryName) => {
198
- return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
199
- };
200
161
  const getServerCombinedModueFile = (internalDirectory, entryName) => {
201
162
  return import_path.default.join(internalDirectory, entryName, "server-loader-combined.js");
202
163
  };
@@ -225,10 +186,6 @@ const isSubDirOrEqual = (parent, child) => {
225
186
  checkIsBuildCommands,
226
187
  getDefaultImports,
227
188
  getServerCombinedModueFile,
228
- getServerLoadersFile,
229
- hasAction,
230
- hasLoader,
231
- isPageComponentFile,
232
189
  isSubDirOrEqual,
233
190
  parseModule,
234
191
  replaceWithAlias,