@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,9 +36,19 @@ var import_utils = require("@modern-js/utils");
36
36
  var import_pkg_types = require("pkg-types");
37
37
  var import_mlly = require("mlly");
38
38
  var import_utils2 = require("./utils");
39
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson, copyWholePackage }) => {
39
+ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
40
40
  const base = "/";
41
41
  const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
42
+ const includeEntries = include.map((item) => {
43
+ if ((0, import_node_path.isAbsolute)(item)) {
44
+ return item;
45
+ }
46
+ try {
47
+ return require.resolve(item);
48
+ } catch (error) {
49
+ }
50
+ return item;
51
+ });
42
52
  const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
43
53
  const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
44
54
  const tracedFiles = Object.fromEntries(await Promise.all([
@@ -133,17 +143,9 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
133
143
  }
134
144
  tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
135
145
  }
146
+ tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
136
147
  tracedFile.pkgName = pkgName;
137
148
  tracedFile.pkgVersion = pkgJSON.version;
138
- const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
139
- if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath) {
140
- if (shouldCopyWholePackage) {
141
- const allFiles = await (0, import_utils2.readDirRecursive)(tracedFile.pkgPath);
142
- tracedPackageVersion.files.push(...allFiles);
143
- } else {
144
- tracedPackageVersion.files.push(tracedFile.path);
145
- }
146
- }
147
149
  }
148
150
  const multiVersionPkgs = {};
149
151
  const singleVersionPackages = [];
@@ -161,11 +163,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
161
163
  await Promise.all(singleVersionPackages.map((pkgName) => {
162
164
  const pkg = tracedPackages[pkgName];
163
165
  const version = Object.keys(pkg.versions)[0];
164
- return (0, import_utils2.writePackage)({
165
- pkg,
166
- version,
167
- projectDir: serverRootDir
168
- });
166
+ return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
169
167
  }));
170
168
  const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
171
169
  for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
@@ -192,12 +190,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
192
190
  for (const [version, parentPkgs] of versionEntires) {
193
191
  const pkg = tracedPackages[pkgName];
194
192
  const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
195
- await (0, import_utils2.writePackage)({
196
- pkg,
197
- version,
198
- projectDir: serverRootDir,
199
- _pkgPath: pkgDestPath
200
- });
193
+ await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
201
194
  await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
202
195
  for (const parentPkg of parentPkgs) {
203
196
  const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
@@ -206,7 +199,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
206
199
  }
207
200
  }
208
201
  const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
209
- const newPkgJson = {
202
+ await import_utils.fs.writeJSON(outputPkgPath, {
210
203
  name: `${projectPkgJson.name || "modernjs-project"}-prod`,
211
204
  version: projectPkgJson.version || "0.0.0",
212
205
  private: true,
@@ -216,9 +209,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
216
209
  Object.keys(pkg.versions)[0]
217
210
  ])
218
211
  ].sort(([a], [b]) => a.localeCompare(b)))
219
- };
220
- const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
221
- await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
212
+ });
222
213
  };
223
214
  // Annotate the CommonJS export names for ESM import in node:
224
215
  0 && (module.exports = {
@@ -50,8 +50,7 @@ function applyPublicCondition(pkg) {
50
50
  pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
51
51
  }
52
52
  }
53
- const writePackage = async (options) => {
54
- const { pkg, version, projectDir, _pkgPath } = options;
53
+ const writePackage = async (pkg, version, projectDir, _pkgPath) => {
55
54
  const pkgPath = _pkgPath || pkg.name;
56
55
  for (const src of pkg.versions[version].files) {
57
56
  if (src.includes("node_modules")) {
@@ -50,8 +50,8 @@ async function cleanDistDirectory(dir) {
50
50
  }
51
51
  }
52
52
  const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
53
- const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
54
- const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
53
+ const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
54
+ const plugins = serverPlugins.map((plugin) => plugin.name);
55
55
  const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
56
56
  const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
57
57
  const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
@@ -124,13 +124,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
124
124
  if (!needModernServer) {
125
125
  return;
126
126
  }
127
- await (0, import_dependencies.handleDependencies)({
128
- appDir: appDirectory,
129
- serverRootDir: funcsDirectory,
130
- includeEntries: [
131
- require.resolve("@modern-js/prod-server")
132
- ]
133
- });
127
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
128
+ "@modern-js/prod-server"
129
+ ]);
134
130
  }
135
131
  };
136
132
  };
@@ -36,8 +36,8 @@ var import_utils = require("@modern-js/utils");
36
36
  var import_utils2 = require("../utils");
37
37
  var import_dependencies = require("../dependencies");
38
38
  const createNodePreset = (appContext, config) => {
39
- const { appDirectory, distDirectory, serverInternalPlugins } = appContext;
40
- const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
39
+ const { appDirectory, distDirectory, serverPlugins } = appContext;
40
+ const plugins = serverPlugins.map((plugin) => plugin.name);
41
41
  const outputDirectory = import_node_path.default.join(appDirectory, ".output");
42
42
  const staticDirectory = import_node_path.default.join(outputDirectory, "static");
43
43
  const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
@@ -78,17 +78,9 @@ const createNodePreset = (appContext, config) => {
78
78
  const filter = (filePath) => {
79
79
  return !filePath.startsWith(staticDirectory);
80
80
  };
81
- await (0, import_dependencies.handleDependencies)({
82
- appDir: appDirectory,
83
- serverRootDir: outputDirectory,
84
- includeEntries: [
85
- require.resolve("@modern-js/prod-server")
86
- ],
87
- entryFilter: filter,
88
- copyWholePackage: (pkgName) => {
89
- return pkgName === "koa";
90
- }
91
- });
81
+ await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
82
+ "@modern-js/prod-server"
83
+ ], filter);
92
84
  }
93
85
  };
94
86
  };
@@ -37,8 +37,8 @@ var import_routes = require("../../../utils/routes");
37
37
  var import_utils2 = require("../utils");
38
38
  var import_dependencies = require("../dependencies");
39
39
  const createVercelPreset = (appContext, modernConfig, needModernServer) => {
40
- const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
41
- const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
40
+ const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
41
+ const plugins = serverPlugins.map((plugin) => plugin.name);
42
42
  const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
43
43
  const outputDirectory = import_node_path.default.join(vercelOutput, "output");
44
44
  const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
@@ -136,13 +136,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
136
136
  if (!needModernServer) {
137
137
  return;
138
138
  }
139
- await (0, import_dependencies.handleDependencies)({
140
- appDir: appDirectory,
141
- serverRootDir: funcsDirectory,
142
- includeEntries: [
143
- require.resolve("@modern-js/prod-server")
144
- ]
145
- });
139
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
140
+ "@modern-js/prod-server"
141
+ ]);
146
142
  }
147
143
  };
148
144
  };
@@ -22,7 +22,7 @@ __export(initialize_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(initialize_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
- var import_config = require("../config");
25
+ var import_config = require("../../config");
26
26
  var initialize_default = ({ bundler }) => ({
27
27
  name: "@modern-js/plugin-initialize",
28
28
  post: [
@@ -37,8 +37,14 @@ var import_utils = require("@modern-js/utils");
37
37
  var import_server_utils = require("@modern-js/server-utils");
38
38
  const TS_CONFIG_FILENAME = "tsconfig.json";
39
39
  function checkHasCache(appDir) {
40
- const tsFilepath = import_path.default.resolve(appDir, "server", "cache.ts");
41
- const jsfilepath = import_path.default.resolve(appDir, "server", "cache.js");
40
+ const tsFilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, "cache.ts");
41
+ const jsfilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, "cache.js");
42
+ return import_fs.default.existsSync(tsFilepath) || import_fs.default.existsSync(jsfilepath);
43
+ }
44
+ function checkHasConfig(appDir, metaName = "modern-js") {
45
+ const meta = (0, import_utils.getMeta)(metaName);
46
+ const tsFilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, `${meta}.server.ts`);
47
+ const jsfilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, `${meta}.server.js`);
42
48
  return import_fs.default.existsSync(tsFilepath) || import_fs.default.existsSync(jsfilepath);
43
49
  }
44
50
  var serverBuild_default = () => ({
@@ -46,8 +52,8 @@ var serverBuild_default = () => ({
46
52
  setup(api) {
47
53
  return {
48
54
  async afterBuild() {
49
- const { appDirectory, distDirectory } = api.useAppContext();
50
- if (!checkHasCache(appDirectory)) {
55
+ const { appDirectory, distDirectory, metaName } = api.useAppContext();
56
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
51
57
  return;
52
58
  }
53
59
  const modernConfig = api.useResolvedConfigContext();
@@ -41,7 +41,7 @@ const createServer = async (options) => {
41
41
  if (server) {
42
42
  server.close();
43
43
  }
44
- server = await (0, import_server.createDevServer)(options, import_prod_server.initProdMiddlewares);
44
+ server = await (0, import_server.createDevServer)(options, import_prod_server.applyPlugins);
45
45
  return server;
46
46
  };
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -16,24 +16,31 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getServerInternalPlugins_exports = {};
20
- __export(getServerInternalPlugins_exports, {
21
- getServerInternalPlugins: () => getServerInternalPlugins
19
+ var loadPlugins_exports = {};
20
+ __export(loadPlugins_exports, {
21
+ getServerPlugins: () => getServerPlugins,
22
+ loadServerPlugins: () => loadServerPlugins
22
23
  });
23
- module.exports = __toCommonJS(getServerInternalPlugins_exports);
24
- async function getServerInternalPlugins(api) {
25
- const hookRunners = api.useHookRunners();
26
- const { plugins: serverPlugins } = await hookRunners.collectServerPlugins({
24
+ module.exports = __toCommonJS(loadPlugins_exports);
25
+ var import_prod_server = require("@modern-js/prod-server");
26
+ async function getServerPlugins(api) {
27
+ const runner = api.useHookRunners();
28
+ const { plugins } = await runner._internalServerPlugins({
27
29
  plugins: []
28
30
  });
29
- const serverInternalPlugins = serverPlugins.reduce((result, plugin) => Object.assign(result, plugin), {});
30
31
  api.setAppContext({
31
32
  ...api.useAppContext(),
32
- serverInternalPlugins
33
+ serverPlugins: plugins
33
34
  });
34
- return serverInternalPlugins;
35
+ return plugins;
36
+ }
37
+ async function loadServerPlugins(api, appDirectory) {
38
+ const plugins = await getServerPlugins(api);
39
+ const instances = (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
40
+ return instances;
35
41
  }
36
42
  // Annotate the CommonJS export names for ESM import in node:
37
43
  0 && (module.exports = {
38
- getServerInternalPlugins
44
+ getServerPlugins,
45
+ loadServerPlugins
39
46
  });
@@ -2,10 +2,13 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { isHtmlDisabled, createVirtualModule } from "@rsbuild/shared";
5
+ import { isHtmlDisabled } from "@rsbuild/shared";
6
6
  import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
7
7
  import { template as lodashTemplate } from "@modern-js/utils/lodash";
8
8
  import { BottomTemplatePlugin } from "../bundlerPlugins";
9
+ var createVirtualModule = function(content) {
10
+ return "data:text/javascript,".concat(content);
11
+ };
9
12
  var builderPluginAdapterHtml = function(options) {
10
13
  return {
11
14
  name: "builder-plugin-adapter-modern-html",
@@ -5,7 +5,7 @@ import { isHtmlDisabled } from "@rsbuild/shared";
5
5
  import { mergeRsbuildConfig } from "@rsbuild/core";
6
6
  import { fs, isUseSSRBundle } from "@modern-js/utils";
7
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
8
- import { getServerCombinedModueFile } from "../../../analyze/utils";
8
+ import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
9
9
  var builderPluginAdapterSSR = function(options) {
10
10
  return {
11
11
  name: "builder-plugin-adapter-modern-ssr",
@@ -180,7 +180,7 @@ function applyFilterEntriesBySSRConfig(param) {
180
180
  }
181
181
  var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
182
182
  entryNames.forEach(function(name) {
183
- if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
183
+ if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
184
184
  chain.entryPoints.delete(name);
185
185
  }
186
186
  });
@@ -4,6 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { ResolvedConfigContext } from "@modern-js/core";
6
6
  import { logger } from "@modern-js/utils";
7
+ import { loadServerPlugins } from "../utils/loadPlugins";
7
8
  import { generateRoutes } from "../utils/routes";
8
9
  import { buildServerConfig } from "../utils/config";
9
10
  import { registerCompiler } from "../utils/register";
@@ -21,15 +22,21 @@ var build = function() {
21
22
  hookRunners = api.useHookRunners();
22
23
  return [
23
24
  4,
24
- registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
25
+ loadServerPlugins(api, appContext.appDirectory)
25
26
  ];
26
27
  case 1:
28
+ _state.sent();
29
+ return [
30
+ 4,
31
+ registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
32
+ ];
33
+ case 2:
27
34
  _state.sent();
28
35
  apiOnly = appContext.apiOnly;
29
36
  if (!apiOnly)
30
37
  return [
31
38
  3,
32
- 6
39
+ 7
33
40
  ];
34
41
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
35
42
  return [
@@ -39,7 +46,7 @@ var build = function() {
39
46
  bundlerConfigs: void 0
40
47
  })
41
48
  ];
42
- case 2:
49
+ case 3:
43
50
  _state.sent();
44
51
  return [
45
52
  4,
@@ -49,13 +56,13 @@ var build = function() {
49
56
  configFile: serverConfigFile
50
57
  })
51
58
  ];
52
- case 3:
59
+ case 4:
53
60
  _state.sent();
54
61
  return [
55
62
  4,
56
63
  generateRoutes(appContext)
57
64
  ];
58
- case 4:
65
+ case 5:
59
66
  _state.sent();
60
67
  return [
61
68
  4,
@@ -64,12 +71,12 @@ var build = function() {
64
71
  stats: void 0
65
72
  })
66
73
  ];
67
- case 5:
74
+ case 6:
68
75
  _state.sent();
69
76
  return [
70
77
  2
71
78
  ];
72
- case 6:
79
+ case 7:
73
80
  resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
74
81
  cliOptions: options
75
82
  });
@@ -83,7 +90,7 @@ var build = function() {
83
90
  configFile: serverConfigFile1
84
91
  })
85
92
  ];
86
- case 7:
93
+ case 8:
87
94
  _state.sent();
88
95
  logger.info("Starting production build...");
89
96
  if (!appContext.builder) {
@@ -93,7 +100,7 @@ var build = function() {
93
100
  4,
94
101
  appContext.builder.build()
95
102
  ];
96
- case 8:
103
+ case 9:
97
104
  _state.sent();
98
105
  return [
99
106
  2
@@ -1,6 +1,6 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
3
+ import { getServerPlugins } from "../utils/loadPlugins";
4
4
  var deploy = function() {
5
5
  var _ref = _async_to_generator(function(api, options) {
6
6
  var hookRunners;
@@ -10,7 +10,7 @@ var deploy = function() {
10
10
  hookRunners = api.useHookRunners();
11
11
  return [
12
12
  4,
13
- getServerInternalPlugins(api)
13
+ getServerPlugins(api)
14
14
  ];
15
15
  case 1:
16
16
  _state.sent();
@@ -2,19 +2,20 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import path from "node:path";
5
6
  import { ResolvedConfigContext } from "@modern-js/core";
6
- import { DEFAULT_DEV_HOST } from "@modern-js/utils";
7
+ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
7
8
  import { createDevServer } from "@modern-js/server";
8
- import { initProdMiddlewares } from "@modern-js/prod-server";
9
+ import { applyPlugins } from "@modern-js/prod-server";
10
+ import { loadServerPlugins } from "../utils/loadPlugins";
9
11
  import { registerCompiler } from "../utils/register";
10
12
  import { printInstructions } from "../utils/printInstructions";
11
13
  import { setServer } from "../utils/createServer";
12
14
  import { generateRoutes } from "../utils/routes";
13
15
  import { buildServerConfig } from "../utils/config";
14
- import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
15
16
  var dev = function() {
16
17
  var _ref = _async_to_generator(function(api, options) {
17
- var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
18
+ var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, app, host, server;
18
19
  var _arguments = arguments;
19
20
  return _ts_generator(this, function(_state) {
20
21
  switch (_state.label) {
@@ -48,6 +49,8 @@ var dev = function() {
48
49
  ];
49
50
  case 2:
50
51
  _state.sent();
52
+ meta = getMeta(metaName);
53
+ serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
51
54
  return [
52
55
  4,
53
56
  hookRunners.beforeDev()
@@ -65,10 +68,10 @@ var dev = function() {
65
68
  _state.sent();
66
69
  return [
67
70
  4,
68
- getServerInternalPlugins(api)
71
+ loadServerPlugins(api, appDirectory)
69
72
  ];
70
73
  case 5:
71
- serverInternalPlugins = _state.sent();
74
+ pluginInstances = _state.sent();
72
75
  serverOptions = _object_spread({
73
76
  metaName,
74
77
  dev: _object_spread({
@@ -82,11 +85,12 @@ var dev = function() {
82
85
  lambdaDirectory: appContext.lambdaDirectory,
83
86
  sharedDirectory: appContext.sharedDirectory
84
87
  },
88
+ serverConfigPath,
85
89
  routes: serverRoutes,
86
90
  pwd: appDirectory,
87
91
  config: normalizedConfig,
88
92
  serverConfigFile,
89
- internalPlugins: serverInternalPlugins
93
+ plugins: pluginInstances
90
94
  }, devServerOptions);
91
95
  if (!apiOnly)
92
96
  return [
@@ -95,7 +99,7 @@ var dev = function() {
95
99
  ];
96
100
  return [
97
101
  4,
98
- createDevServer(serverOptions, initProdMiddlewares)
102
+ createDevServer(serverOptions, applyPlugins)
99
103
  ];
100
104
  case 6:
101
105
  app = _state.sent();
@@ -115,7 +119,7 @@ var dev = function() {
115
119
  4,
116
120
  appContext.builder.startDevServer({
117
121
  serverOptions,
118
- initProdMiddlewares
122
+ applyPlugins
119
123
  })
120
124
  ];
121
125
  case 8: