@modern-js/app-tools 2.58.1-alpha.6 → 2.58.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +0 -1
  2. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -2
  4. package/dist/cjs/builder/index.js +2 -2
  5. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +13 -4
  6. package/dist/cjs/commands/build.js +19 -0
  7. package/dist/cjs/commands/dev.js +9 -0
  8. package/dist/cjs/commands/index.js +8 -8
  9. package/dist/cjs/commands/inspect.js +1 -1
  10. package/dist/cjs/config/initialize/inits.js +4 -4
  11. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  12. package/dist/cjs/esm/register-esm.mjs +67 -0
  13. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  14. package/dist/cjs/esm/utils.mjs +43 -0
  15. package/dist/cjs/index.js +1 -1
  16. package/dist/cjs/plugins/analyze/index.js +3 -3
  17. package/dist/cjs/plugins/deploy/dependencies/index.js +2 -15
  18. package/dist/cjs/plugins/deploy/dependencies/utils.js +13 -78
  19. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
  20. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  21. package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
  22. package/dist/cjs/plugins/deploy/platforms/netlify.js +14 -5
  23. package/dist/cjs/plugins/deploy/platforms/node.js +13 -4
  24. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
  25. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  26. package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +4 -1
  27. package/dist/cjs/plugins/deploy/platforms/vercel.js +14 -5
  28. package/dist/cjs/utils/config.js +1 -1
  29. package/dist/cjs/utils/loadPlugins.js +1 -1
  30. package/dist/cjs/utils/register.js +50 -23
  31. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +2 -2
  32. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  33. package/dist/types/builder/builder-webpack/adapterModern.d.ts +2 -2
  34. package/dist/types/builder/builder-webpack/index.d.ts +1 -1
  35. package/dist/types/builder/generator/index.d.ts +2 -2
  36. package/dist/types/builder/index.d.ts +1 -1
  37. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  38. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  39. package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
  40. package/dist/types/commands/build.d.ts +1 -1
  41. package/dist/types/commands/dev.d.ts +3 -3
  42. package/dist/types/commands/index.d.ts +3 -3
  43. package/dist/types/config/default.d.ts +1 -1
  44. package/dist/types/config/initialize/inits.d.ts +1 -1
  45. package/dist/types/config/legacy/createHtmlConfig.d.ts +1 -1
  46. package/dist/types/config/legacy/createOutputConfig.d.ts +1 -1
  47. package/dist/types/config/legacy/createSourceConfig.d.ts +1 -1
  48. package/dist/types/config/legacy/createToolsConfig.d.ts +1 -1
  49. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  50. package/dist/types/esm/register-esm.d.mts +5 -0
  51. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  52. package/dist/types/esm/utils.d.mts +6 -0
  53. package/dist/types/exports/server.d.ts +1 -1
  54. package/dist/types/hooks.d.ts +1 -1
  55. package/dist/types/index.d.ts +2 -2
  56. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  57. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  58. package/dist/types/plugins/analyze/index.d.ts +1 -1
  59. package/dist/types/plugins/deploy/dependencies/index.d.ts +3 -5
  60. package/dist/types/plugins/deploy/dependencies/utils.d.ts +2 -9
  61. package/dist/types/plugins/deploy/index.d.ts +2 -2
  62. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
  63. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
  64. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
  65. package/dist/types/plugins/deploy/platforms/netlify.d.ts +1 -1
  66. package/dist/types/plugins/deploy/platforms/node.d.ts +1 -1
  67. package/dist/types/plugins/deploy/platforms/platform.d.ts +2 -2
  68. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
  69. package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +2 -0
  70. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
  71. package/dist/types/plugins/deploy/platforms/vercel.d.ts +1 -1
  72. package/dist/types/plugins/deploy/utils.d.ts +1 -1
  73. package/dist/types/plugins/serverBuild.d.ts +1 -1
  74. package/dist/types/types/hooks.d.ts +1 -1
  75. package/dist/types/types/index.d.ts +1 -1
  76. package/dist/types/utils/createServer.d.ts +1 -1
  77. package/dist/types/utils/generateWatchFiles.d.ts +1 -1
  78. package/dist/types/utils/getSelectedEntries.d.ts +1 -1
  79. package/dist/types/utils/loadPlugins.d.ts +3 -3
  80. package/dist/types/utils/register.d.ts +2 -2
  81. package/dist/types/utils/restart.d.ts +2 -2
  82. package/lib/types.d.ts +15 -0
  83. package/package.json +20 -21
  84. package/dist/esm/builder/builder-rspack/adapterCopy.js +0 -166
  85. package/dist/esm/builder/builder-rspack/index.js +0 -34
  86. package/dist/esm/builder/builder-webpack/adapterModern.js +0 -29
  87. package/dist/esm/builder/builder-webpack/createCopyPattern.js +0 -44
  88. package/dist/esm/builder/builder-webpack/index.js +0 -52
  89. package/dist/esm/builder/generator/createBuilderProviderConfig.js +0 -37
  90. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -81
  91. package/dist/esm/builder/generator/index.js +0 -94
  92. package/dist/esm/builder/index.js +0 -45
  93. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +0 -85
  94. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +0 -126
  95. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +0 -270
  96. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +0 -43
  97. package/dist/esm/builder/shared/builderPlugins/index.js +0 -4
  98. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -51
  99. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -37
  100. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +0 -288
  101. package/dist/esm/builder/shared/bundlerPlugins/index.js +0 -3
  102. package/dist/esm/builder/shared/createCopyInfo.js +0 -14
  103. package/dist/esm/builder/shared/index.js +0 -3
  104. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +0 -7
  105. package/dist/esm/builder/shared/types.js +0 -0
  106. package/dist/esm/commands/build.js +0 -117
  107. package/dist/esm/commands/deploy.js +0 -48
  108. package/dist/esm/commands/dev.js +0 -169
  109. package/dist/esm/commands/index.js +0 -411
  110. package/dist/esm/commands/inspect.js +0 -28
  111. package/dist/esm/commands/serve.js +0 -93
  112. package/dist/esm/config/default.js +0 -190
  113. package/dist/esm/config/index.js +0 -3
  114. package/dist/esm/config/initialize/index.js +0 -9
  115. package/dist/esm/config/initialize/inits.js +0 -85
  116. package/dist/esm/config/legacy/createHtmlConfig.js +0 -21
  117. package/dist/esm/config/legacy/createOutputConfig.js +0 -45
  118. package/dist/esm/config/legacy/createSourceConfig.js +0 -46
  119. package/dist/esm/config/legacy/createToolsConfig.js +0 -28
  120. package/dist/esm/config/legacy/index.js +0 -43
  121. package/dist/esm/defineConfig.js +0 -16
  122. package/dist/esm/exports/server.js +0 -4
  123. package/dist/esm/hooks.js +0 -34
  124. package/dist/esm/index.js +0 -239
  125. package/dist/esm/locale/en.js +0 -43
  126. package/dist/esm/locale/index.js +0 -12
  127. package/dist/esm/locale/zh.js +0 -43
  128. package/dist/esm/plugins/analyze/constants.js +0 -14
  129. package/dist/esm/plugins/analyze/getBundleEntry.js +0 -102
  130. package/dist/esm/plugins/analyze/getFileSystemEntry.js +0 -238
  131. package/dist/esm/plugins/analyze/getHtmlTemplate.js +0 -178
  132. package/dist/esm/plugins/analyze/getServerRoutes.js +0 -132
  133. package/dist/esm/plugins/analyze/index.js +0 -380
  134. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +0 -49
  135. package/dist/esm/plugins/analyze/templates.js +0 -6
  136. package/dist/esm/plugins/analyze/utils.js +0 -101
  137. package/dist/esm/plugins/deploy/dependencies/index.js +0 -629
  138. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -643
  139. package/dist/esm/plugins/deploy/exports.js +0 -4
  140. package/dist/esm/plugins/deploy/index.js +0 -135
  141. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -299
  142. package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +0 -203
  143. package/dist/esm/plugins/deploy/platforms/node.js +0 -133
  144. package/dist/esm/plugins/deploy/platforms/nodeEntry.js +0 -108
  145. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  146. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -233
  147. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -203
  148. package/dist/esm/plugins/deploy/utils.js +0 -47
  149. package/dist/esm/plugins/initialize/index.js +0 -119
  150. package/dist/esm/plugins/serverBuild.js +0 -87
  151. package/dist/esm/types/config/deploy.js +0 -0
  152. package/dist/esm/types/config/dev.js +0 -0
  153. package/dist/esm/types/config/experiments.js +0 -0
  154. package/dist/esm/types/config/html.js +0 -0
  155. package/dist/esm/types/config/index.js +0 -1
  156. package/dist/esm/types/config/output.js +0 -0
  157. package/dist/esm/types/config/performance.js +0 -0
  158. package/dist/esm/types/config/security.js +0 -0
  159. package/dist/esm/types/config/source.js +0 -0
  160. package/dist/esm/types/config/testing.js +0 -0
  161. package/dist/esm/types/config/tools.js +0 -0
  162. package/dist/esm/types/hooks.js +0 -0
  163. package/dist/esm/types/index.js +0 -3
  164. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  165. package/dist/esm/types/legacyConfig/dev.js +0 -0
  166. package/dist/esm/types/legacyConfig/index.js +0 -0
  167. package/dist/esm/types/legacyConfig/output.js +0 -0
  168. package/dist/esm/types/legacyConfig/source.js +0 -0
  169. package/dist/esm/types/legacyConfig/testing.js +0 -0
  170. package/dist/esm/types/legacyConfig/tools.js +0 -0
  171. package/dist/esm/types/utils.js +0 -0
  172. package/dist/esm/utils/config.js +0 -122
  173. package/dist/esm/utils/createServer.js +0 -58
  174. package/dist/esm/utils/env.js +0 -16
  175. package/dist/esm/utils/generateWatchFiles.js +0 -71
  176. package/dist/esm/utils/getSelectedEntries.js +0 -67
  177. package/dist/esm/utils/loadPlugins.js +0 -69
  178. package/dist/esm/utils/printInstructions.js +0 -32
  179. package/dist/esm/utils/register.js +0 -129
  180. package/dist/esm/utils/restart.js +0 -67
  181. package/dist/esm/utils/routes.js +0 -42
  182. package/dist/esm/utils/types.js +0 -0
  183. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +0 -67
  184. package/dist/esm-node/builder/builder-rspack/index.js +0 -12
  185. package/dist/esm-node/builder/builder-webpack/adapterModern.js +0 -26
  186. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +0 -42
  187. package/dist/esm-node/builder/builder-webpack/index.js +0 -20
  188. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +0 -44
  189. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +0 -60
  190. package/dist/esm-node/builder/generator/index.js +0 -37
  191. package/dist/esm-node/builder/index.js +0 -11
  192. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +0 -48
  193. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +0 -60
  194. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +0 -156
  195. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +0 -27
  196. package/dist/esm-node/builder/shared/builderPlugins/index.js +0 -4
  197. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -30
  198. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -31
  199. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +0 -219
  200. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +0 -3
  201. package/dist/esm-node/builder/shared/createCopyInfo.js +0 -14
  202. package/dist/esm-node/builder/shared/index.js +0 -3
  203. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +0 -7
  204. package/dist/esm-node/builder/shared/types.js +0 -0
  205. package/dist/esm-node/commands/build.js +0 -55
  206. package/dist/esm-node/commands/deploy.js +0 -12
  207. package/dist/esm-node/commands/dev.js +0 -95
  208. package/dist/esm-node/commands/index.js +0 -92
  209. package/dist/esm-node/commands/inspect.js +0 -15
  210. package/dist/esm-node/commands/serve.js +0 -51
  211. package/dist/esm-node/config/default.js +0 -197
  212. package/dist/esm-node/config/index.js +0 -3
  213. package/dist/esm-node/config/initialize/index.js +0 -9
  214. package/dist/esm-node/config/initialize/inits.js +0 -79
  215. package/dist/esm-node/config/legacy/createHtmlConfig.js +0 -21
  216. package/dist/esm-node/config/legacy/createOutputConfig.js +0 -45
  217. package/dist/esm-node/config/legacy/createSourceConfig.js +0 -29
  218. package/dist/esm-node/config/legacy/createToolsConfig.js +0 -28
  219. package/dist/esm-node/config/legacy/index.js +0 -43
  220. package/dist/esm-node/defineConfig.js +0 -13
  221. package/dist/esm-node/exports/server.js +0 -4
  222. package/dist/esm-node/hooks.js +0 -34
  223. package/dist/esm-node/index.js +0 -124
  224. package/dist/esm-node/locale/en.js +0 -43
  225. package/dist/esm-node/locale/index.js +0 -12
  226. package/dist/esm-node/locale/zh.js +0 -43
  227. package/dist/esm-node/plugins/analyze/constants.js +0 -14
  228. package/dist/esm-node/plugins/analyze/getBundleEntry.js +0 -61
  229. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +0 -100
  230. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +0 -74
  231. package/dist/esm-node/plugins/analyze/getServerRoutes.js +0 -132
  232. package/dist/esm-node/plugins/analyze/index.js +0 -166
  233. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +0 -47
  234. package/dist/esm-node/plugins/analyze/templates.js +0 -24
  235. package/dist/esm-node/plugins/analyze/utils.js +0 -68
  236. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -215
  237. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -202
  238. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  239. package/dist/esm-node/plugins/deploy/index.js +0 -44
  240. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -108
  241. package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +0 -69
  242. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -63
  243. package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +0 -44
  244. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  245. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -120
  246. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -69
  247. package/dist/esm-node/plugins/deploy/utils.js +0 -44
  248. package/dist/esm-node/plugins/initialize/index.js +0 -84
  249. package/dist/esm-node/plugins/serverBuild.js +0 -58
  250. package/dist/esm-node/types/config/deploy.js +0 -0
  251. package/dist/esm-node/types/config/dev.js +0 -0
  252. package/dist/esm-node/types/config/experiments.js +0 -0
  253. package/dist/esm-node/types/config/html.js +0 -0
  254. package/dist/esm-node/types/config/index.js +0 -1
  255. package/dist/esm-node/types/config/output.js +0 -0
  256. package/dist/esm-node/types/config/performance.js +0 -0
  257. package/dist/esm-node/types/config/security.js +0 -0
  258. package/dist/esm-node/types/config/source.js +0 -0
  259. package/dist/esm-node/types/config/testing.js +0 -0
  260. package/dist/esm-node/types/config/tools.js +0 -0
  261. package/dist/esm-node/types/hooks.js +0 -0
  262. package/dist/esm-node/types/index.js +0 -3
  263. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  264. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  265. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  266. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  267. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  268. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  269. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  270. package/dist/esm-node/types/utils.js +0 -0
  271. package/dist/esm-node/utils/config.js +0 -49
  272. package/dist/esm-node/utils/createServer.js +0 -26
  273. package/dist/esm-node/utils/env.js +0 -16
  274. package/dist/esm-node/utils/generateWatchFiles.js +0 -30
  275. package/dist/esm-node/utils/getSelectedEntries.js +0 -34
  276. package/dist/esm-node/utils/loadPlugins.js +0 -22
  277. package/dist/esm-node/utils/printInstructions.js +0 -11
  278. package/dist/esm-node/utils/register.js +0 -69
  279. package/dist/esm-node/utils/restart.js +0 -22
  280. package/dist/esm-node/utils/routes.js +0 -21
  281. package/dist/esm-node/utils/types.js +0 -0
  282. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
  283. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  284. /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
  285. /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -39,7 +39,6 @@ function createPublicPattern(appContext, config, chain) {
39
39
  to: "public",
40
40
  context: publicDir,
41
41
  noErrorOnMissing: true,
42
- // eslint-disable-next-line node/prefer-global/buffer
43
42
  transform: (content, absoluteFrom) => {
44
43
  if (!/\.html?$/.test(absoluteFrom)) {
45
44
  return content;
@@ -38,7 +38,7 @@ async function createWebpackBuilderForModern(options) {
38
38
  const { normalizedConfig } = options;
39
39
  if (normalizedConfig.tools.esbuild) {
40
40
  const { esbuild: esbuildOptions } = normalizedConfig.tools;
41
- const { pluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/rsbuild-plugin-esbuild")));
41
+ const { pluginEsbuild } = await import("@modern-js/rsbuild-plugin-esbuild");
42
42
  builder.addPlugins([
43
43
  pluginEsbuild(esbuildOptions)
44
44
  ]);
@@ -50,7 +50,7 @@ async function generateBuilder(options, bundlerType) {
50
50
  return builder;
51
51
  }
52
52
  async function applyBuilderPlugins(builder, options) {
53
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
53
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins/index.js");
54
54
  builder.addPlugins([
55
55
  builderPluginAdapterBasic(),
56
56
  builderPluginAdapterSSR(options),
@@ -59,7 +59,7 @@ async function applyBuilderPlugins(builder, options) {
59
59
  ]);
60
60
  const { normalizedConfig } = options;
61
61
  if (!normalizedConfig.output.disableNodePolyfill) {
62
- const { pluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-node-polyfill")));
62
+ const { pluginNodePolyfill } = await import("@rsbuild/plugin-node-polyfill");
63
63
  builder.addPlugins([
64
64
  pluginNodePolyfill()
65
65
  ]);
@@ -33,10 +33,10 @@ __export(builder_exports, {
33
33
  module.exports = __toCommonJS(builder_exports);
34
34
  async function createBuilderGenerator(bundler) {
35
35
  if (bundler === "rspack") {
36
- const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
36
+ const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
37
37
  return createRspackBuilderForModern;
38
38
  }
39
- const { createWebpackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-webpack")));
39
+ const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
40
40
  return createWebpackBuilderForModern;
41
41
  }
42
42
  // Annotate the CommonJS export names for ESM import in node:
@@ -103,7 +103,11 @@ class RouterPlugin {
103
103
  routeAssets: {}
104
104
  });
105
105
  const prevManifest = JSON.parse(prevManifestStr);
106
+ const asyncEntryNames = [];
106
107
  for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
108
+ if (name.startsWith("async-")) {
109
+ asyncEntryNames.push(name);
110
+ }
107
111
  const assets = chunkGroup.assets.map((asset) => {
108
112
  const filename = asset.name;
109
113
  return publicPath ? normalizePath(publicPath) + filename : filename;
@@ -123,6 +127,14 @@ class RouterPlugin {
123
127
  });
124
128
  }
125
129
  }
130
+ if (asyncEntryNames.length > 0) {
131
+ for (const asyncEntryName of asyncEntryNames) {
132
+ const syncEntryName = asyncEntryName.replace("async-", "");
133
+ const syncEntry = routeAssets[syncEntryName];
134
+ const asyncEntry = routeAssets[asyncEntryName];
135
+ (0, import_lodash.merge)(syncEntry, asyncEntry);
136
+ }
137
+ }
126
138
  const manifest = {
127
139
  routeAssets
128
140
  };
@@ -199,10 +211,7 @@ class RouterPlugin {
199
211
  } else {
200
212
  const scriptPath = `${staticJsDir}/${ROUTE_MANIFEST_HOLDER}-${entryName}${disableFilenameHash ? ".js" : `.${generateContentHash(injectedContent)}.js`}`;
201
213
  const scriptUrl = `${publicPath}${scriptPath}`;
202
- const scriptLoadingAttr = (
203
- // eslint-disable-next-line no-nested-ternary
204
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : ""
205
- );
214
+ const scriptLoadingAttr = scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? `type="module"` : "";
206
215
  const script = `<script ${scriptLoadingAttr} ${nonceAttr} src="${scriptUrl}"></script>`;
207
216
  compilation.updateAsset(
208
217
  htmlName,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var build_exports = {};
20
30
  __export(build_exports, {
@@ -36,6 +46,15 @@ const build = async (api, options) => {
36
46
  const appContext = api.useAppContext();
37
47
  const hookRunners = api.useHookRunners();
38
48
  await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory, appContext.metaName);
49
+ if (appContext.moduleType && appContext.moduleType === "module") {
50
+ var _resolvedConfig_source1;
51
+ const { registerEsm } = await import("../esm/register-esm.mjs");
52
+ await registerEsm({
53
+ appDir: appContext.appDirectory,
54
+ distDir: appContext.distDirectory,
55
+ alias: (_resolvedConfig_source1 = resolvedConfig.source) === null || _resolvedConfig_source1 === void 0 ? void 0 : _resolvedConfig_source1.alias
56
+ });
57
+ }
39
58
  await (0, import_register.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);
40
59
  const { apiOnly } = appContext;
41
60
  if (apiOnly) {
@@ -50,6 +50,15 @@ const dev = async (api, options, devServerOptions) => {
50
50
  let normalizedConfig = api.useResolvedConfigContext();
51
51
  const appContext = api.useAppContext();
52
52
  const hookRunners = api.useHookRunners();
53
+ if (appContext.moduleType && appContext.moduleType === "module") {
54
+ var _normalizedConfig_source1;
55
+ const { registerEsm } = await import("../esm/register-esm.mjs");
56
+ await registerEsm({
57
+ appDir: appContext.appDirectory,
58
+ distDir: appContext.distDirectory,
59
+ alias: (_normalizedConfig_source1 = normalizedConfig.source) === null || _normalizedConfig_source1 === void 0 ? void 0 : _normalizedConfig_source1.alias
60
+ });
61
+ }
53
62
  await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
54
63
  normalizedConfig = {
55
64
  ...normalizedConfig,
@@ -44,7 +44,7 @@ const devCommand = async (program, api) => {
44
44
  const runner = api.useHookRunners();
45
45
  const devToolMetas = await runner.registerDev();
46
46
  const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
47
- const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
47
+ const { dev } = await import("./dev.js");
48
48
  await dev(api, options);
49
49
  });
50
50
  for (const meta of devToolMetas) {
@@ -54,7 +54,7 @@ const devCommand = async (program, api) => {
54
54
  for (const subCmd of meta.subCommands) {
55
55
  devProgram.command(subCmd).action(async (options = {}) => {
56
56
  const { appDirectory } = api.useAppContext();
57
- const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
57
+ const { isTypescript } = await import("@modern-js/utils");
58
58
  await runner.beforeDevTask(meta);
59
59
  await meta.action(options, {
60
60
  isTsProject: isTypescript(appDirectory)
@@ -67,7 +67,7 @@ const buildCommand = async (program, api) => {
67
67
  const runner = api.useHookRunners();
68
68
  const platformBuilders = await runner.registerBuildPlatform();
69
69
  const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
70
- const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
70
+ const { build } = await import("./build.js");
71
71
  await build(api, options);
72
72
  });
73
73
  for (const platformBuilder of platformBuilders) {
@@ -75,7 +75,7 @@ const buildCommand = async (program, api) => {
75
75
  for (const platform of platforms) {
76
76
  buildProgram.command(platform).action(async () => {
77
77
  const { appDirectory } = api.useAppContext();
78
- const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
78
+ const { isTypescript } = await import("@modern-js/utils");
79
79
  await runner.beforeBuildPlatform(platformBuilders);
80
80
  await platformBuilder.build(platform, {
81
81
  isTsProject: isTypescript(appDirectory)
@@ -86,17 +86,17 @@ const buildCommand = async (program, api) => {
86
86
  };
87
87
  const serverCommand = (program, api) => {
88
88
  program.command("serve").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.serve.describe)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async () => {
89
- const { start } = await Promise.resolve().then(() => __toESM(require("./serve")));
89
+ const { start } = await import("./serve.js");
90
90
  await start(api);
91
91
  });
92
92
  };
93
93
  const deployCommand = (program, api) => {
94
94
  program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options) => {
95
95
  if (!options.skipBuild) {
96
- const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
96
+ const { build } = await import("./build.js");
97
97
  await build(api);
98
98
  }
99
- const { deploy } = await Promise.resolve().then(() => __toESM(require("./deploy")));
99
+ const { deploy } = await import("./deploy.js");
100
100
  await deploy(api, options);
101
101
  process.exit(0);
102
102
  });
@@ -111,7 +111,7 @@ const newCommand = (program, locale) => {
111
111
  };
112
112
  const inspectCommand = (program, api) => {
113
113
  program.command("inspect").description("inspect the internal configs").option(`--env <env>`, import_locale.i18n.t(import_locale.localeKeys.command.inspect.env), "development").option("--output <output>", import_locale.i18n.t(import_locale.localeKeys.command.inspect.output), "./").option("--verbose", import_locale.i18n.t(import_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
114
- const { inspect } = await Promise.resolve().then(() => __toESM(require("./inspect")));
114
+ const { inspect } = await import("./inspect.js");
115
115
  inspect(api, options);
116
116
  });
117
117
  };
@@ -27,7 +27,7 @@ const inspect = async (api, options) => {
27
27
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
28
28
  }
29
29
  return appContext.builder.inspectConfig({
30
- env: options.env,
30
+ mode: options.env,
31
31
  verbose: options.verbose,
32
32
  outputPath: options.output,
33
33
  writeToDisk: true
@@ -49,14 +49,14 @@ function initHtmlConfig(config, appContext) {
49
49
  function createBuilderAppIcon(config2, appContext2) {
50
50
  const { appIcon } = config2.html;
51
51
  const { configDir } = config2.source;
52
- const defaultAppIcon = (0, import_utils.findExists)(ICON_EXTENSIONS.map((ext) => import_path.default.resolve(appContext2.appDirectory, configDir || "./config", `icon.${ext}`)));
53
- return appIcon || defaultAppIcon || void 0;
52
+ const getDefaultAppIcon = () => (0, import_utils.findExists)(ICON_EXTENSIONS.map((ext) => import_path.default.resolve(appContext2.appDirectory, configDir || "./config", `icon.${ext}`)));
53
+ return appIcon || getDefaultAppIcon() || void 0;
54
54
  }
55
55
  function createBuilderFavicon(config2, appContext2) {
56
56
  const { configDir } = config2.source;
57
57
  const { favicon } = config2.html;
58
- const defaultFavicon = (0, import_utils.findExists)(ICON_EXTENSIONS.map((ext) => import_path.default.resolve(appContext2.appDirectory, configDir || "./config", `favicon.${ext}`)));
59
- return favicon || defaultFavicon || void 0;
58
+ const getDefaultFavicon = () => (0, import_utils.findExists)(ICON_EXTENSIONS.map((ext) => import_path.default.resolve(appContext2.appDirectory, configDir || "./config", `favicon.${ext}`)));
59
+ return favicon || getDefaultFavicon() || void 0;
60
60
  }
61
61
  }
62
62
  function initSourceConfig(config, appContext, bundler) {
@@ -0,0 +1,20 @@
1
+ import { pathToFileURL } from 'url';
2
+ import { createMatchPath } from './utils.mjs';
3
+
4
+ let matchPath;
5
+ export async function initialize({ appDir, alias, tsconfigPath }) {
6
+ matchPath = createMatchPath({
7
+ alias,
8
+ appDir,
9
+ tsconfigPath,
10
+ });
11
+ }
12
+
13
+ export function resolve(specifier, context, defaultResolve) {
14
+ const match = matchPath(specifier);
15
+ return match
16
+ ? defaultResolve(pathToFileURL(match).href, context)
17
+ : defaultResolve(specifier, context);
18
+ }
19
+
20
+ export { load } from 'esbuild-register/loader';
@@ -0,0 +1,67 @@
1
+ import path from 'node:path';
2
+ import { fs, readTsConfigByFile, isVersionAtLeast1819 } from '@modern-js/utils';
3
+ import assert from 'node:assert';
4
+
5
+ const checkDep = async dep => {
6
+ try {
7
+ await import(dep);
8
+ return true;
9
+ } catch (error) {
10
+ return false;
11
+ }
12
+ };
13
+
14
+ export const registerEsm = async ({ appDir, distDir, alias }) => {
15
+ const nodeVersion = process.versions.node;
16
+ const versionArr = nodeVersion.split('.').map(Number);
17
+
18
+ assert(
19
+ isVersionAtLeast1819(nodeVersion),
20
+ `The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`,
21
+ );
22
+ const hasTsNode = await checkDep('ts-node');
23
+ // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
24
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
25
+ const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
26
+ const hasTsconfig = await fs.pathExists(tsconfigPath);
27
+ const { register } = await import('node:module');
28
+ if (hasTsNode && hasTsconfig) {
29
+ // These can be overridden by ts-node options in tsconfig.json
30
+ process.env.TS_NODE_TRANSPILE_ONLY = true;
31
+ process.env.TS_NODE_PROJECT = tsconfigPath;
32
+ process.env.TS_NODE_SCOPE = true;
33
+ process.env.TS_NODE_FILES = true;
34
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(
35
+ appDir,
36
+ distDir,
37
+ )}/`;
38
+ register('./ts-node-loader.mjs', import.meta.url, {
39
+ data: {
40
+ appDir,
41
+ distDir,
42
+ alias,
43
+ tsconfigPath,
44
+ },
45
+ });
46
+ } else {
47
+ process.env.MODERN_NODE_LOADER = 'esbuild';
48
+ let tsConfig = {};
49
+ if (hasTsconfig) {
50
+ tsConfig = readTsConfigByFile(tsconfigPath);
51
+ }
52
+ const esbuildRegister = await import('esbuild-register/dist/node');
53
+ esbuildRegister.register({
54
+ tsconfigRaw: hasTsconfig ? tsConfig : undefined,
55
+ hookIgnoreNodeModules: true,
56
+ hookMatcher: fileName => !fileName.startsWith(distDir),
57
+ });
58
+ register('./esbuild-loader.mjs', import.meta.url, {
59
+ data: {
60
+ appDir,
61
+ distDir,
62
+ alias,
63
+ tsconfigPath,
64
+ },
65
+ });
66
+ }
67
+ };
@@ -0,0 +1,21 @@
1
+ import { pathToFileURL } from 'url';
2
+ import { resolve as tsNodeResolve } from 'ts-node/esm';
3
+ import { createMatchPath } from './utils.mjs';
4
+
5
+ let matchPath;
6
+ export async function initialize({ appDir, alias, tsconfigPath }) {
7
+ matchPath = createMatchPath({
8
+ alias,
9
+ appDir,
10
+ tsconfigPath,
11
+ });
12
+ }
13
+
14
+ export function resolve(specifier, context, defaultResolve) {
15
+ const match = matchPath(specifier);
16
+ return match
17
+ ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
18
+ : tsNodeResolve(specifier, context, defaultResolve);
19
+ }
20
+
21
+ export { transformSource, load } from 'ts-node/esm';
@@ -0,0 +1,43 @@
1
+ import path from 'path';
2
+ import { createRequire } from 'module';
3
+ import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
4
+ import { getAliasConfig } from '@modern-js/utils';
5
+
6
+ const require = createRequire(import.meta.url);
7
+ export function createMatchPath({ alias, appDir, tsconfigPath }) {
8
+ const aliasConfig = getAliasConfig(alias, {
9
+ appDirectory: appDir,
10
+ tsconfigPath,
11
+ });
12
+
13
+ const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
14
+
15
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
16
+ let tsPath = paths[key];
17
+ // Do some special handling for Modern.js's internal alias, we can drop it in the next version
18
+ if (
19
+ typeof tsPath === 'string' &&
20
+ key.startsWith('@') &&
21
+ tsPath.startsWith('@')
22
+ ) {
23
+ try {
24
+ tsPath = require.resolve(tsPath, {
25
+ paths: [appDir],
26
+ });
27
+ } catch {}
28
+ }
29
+
30
+ if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
31
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
32
+ }
33
+ if (typeof tsPath === 'string') {
34
+ tsPath = [tsPath];
35
+ }
36
+ return {
37
+ ...o,
38
+ [`${key}`]: tsPath,
39
+ };
40
+ }, {});
41
+
42
+ return tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
43
+ }
package/dist/cjs/index.js CHANGED
@@ -139,7 +139,7 @@ const appTools = (options = {
139
139
  async fileChange(e) {
140
140
  const { filename, eventType, isPrivate } = e;
141
141
  if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
142
- const { closeServer } = await Promise.resolve().then(() => __toESM(require("./utils/createServer")));
142
+ const { closeServer } = await import("./utils/createServer");
143
143
  await closeServer();
144
144
  await (0, import_restart.restart)(api.useHookRunners(), filename);
145
145
  }
@@ -77,9 +77,9 @@ var analyze_default = ({ bundler }) => ({
77
77
  return;
78
78
  }
79
79
  const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
80
- Promise.resolve().then(() => __toESM(require("./getBundleEntry"))),
81
- Promise.resolve().then(() => __toESM(require("./getServerRoutes"))),
82
- Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
80
+ import("./getBundleEntry.js"),
81
+ import("./getServerRoutes.js"),
82
+ import("./getHtmlTemplate.js")
83
83
  ]);
84
84
  const { entrypoints } = await hookRunners.modifyEntrypoints({
85
85
  entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
@@ -38,27 +38,15 @@ var import_pkg_types = require("pkg-types");
38
38
  var import_mlly = require("mlly");
39
39
  var import_utils2 = require("./utils");
40
40
  var import_nft = require("@vercel/nft");
41
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
42
- cacheDir: ".modern-js/deploy",
43
- analysisCache: true,
44
- fileCache: false,
45
- symlinkCache: false
46
- }, traceOptions }) => {
41
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
47
42
  const base = "/";
48
- const startTime = Date.now();
49
43
  const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
50
- console.time("traceFiles");
51
44
  const fileTrace = await traceFiles({
52
45
  entryFiles: entryFiles.concat(includeEntries),
53
46
  serverRootDir,
54
- cacheOptions: {
55
- ...cacheOptions,
56
- cacheDir: import_node_path.default.resolve(appDir, cacheOptions.cacheDir)
57
- },
58
47
  base,
59
48
  traceOptions
60
49
  });
61
- console.timeEnd("traceFiles");
62
50
  const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
63
51
  const dependencySearchRoot = import_node_path.default.resolve(appDir, "../../../../../../");
64
52
  const tracedFiles = Object.fromEntries(await Promise.all([
@@ -231,6 +219,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
231
219
  name: `${projectPkgJson.name || "modernjs-project"}-prod`,
232
220
  version: projectPkgJson.version || "0.0.0",
233
221
  private: true,
222
+ type: projectPkgJson.type || "commonjs",
234
223
  dependencies: Object.fromEntries([
235
224
  ...Object.values(tracedPackages).map((pkg) => [
236
225
  pkg.name,
@@ -240,8 +229,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
240
229
  };
241
230
  const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
242
231
  await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
243
- const endTime = Date.now();
244
- console.log("handleDependencies cost:", `${endTime - startTime}ms`);
245
232
  };
246
233
  // Annotate the CommonJS export names for ESM import in node:
247
234
  0 && (module.exports = {
@@ -139,88 +139,23 @@ const findPackageParents = (pkg, version, tracedFiles) => {
139
139
  ];
140
140
  return parentPkgs.filter((parentPkg) => parentPkg);
141
141
  };
142
- async function serializeMap(map) {
143
- const resolvedMap = /* @__PURE__ */ new Map();
144
- await Promise.all(Array.from(map.entries()).map(async ([key, value]) => {
145
- resolvedMap.set(key, value instanceof Promise ? await Promise.resolve(value) : value);
146
- }));
147
- return JSON.stringify(resolvedMap, (key, value) => {
148
- if (value === null) {
149
- return void 0;
150
- }
151
- if (value instanceof Map) {
152
- return {
153
- dataType: "Map",
154
- value: Array.from(value.entries())
155
- };
156
- }
157
- if (value instanceof Set) {
158
- return {
159
- dataType: "Set",
160
- value: Array.from(value)
161
- };
162
- }
163
- return value;
164
- });
165
- }
166
- function deserializeMap(serializedData) {
167
- return JSON.parse(serializedData, (key, value) => {
168
- if (value && value.dataType === "Map") {
169
- return new Map(value.value);
170
- }
171
- if (value && value.dataType === "Set") {
172
- return new Set(value.value);
173
- }
174
- return value;
175
- });
176
- }
177
- const loadCache = async (filePath, enabled) => {
178
- if (enabled && await import_utils.fs.pathExists(filePath)) {
179
- console.log("load cache:", filePath);
180
- const data = (await import_utils.fs.readFile(filePath)).toString();
181
- return deserializeMap(data);
182
- }
183
- return void 0;
184
- };
185
- const writeCache = async (filePath, cacheMap) => {
186
- const newCacheMap = /* @__PURE__ */ new Map();
187
- for (const [key, value] of cacheMap.entries()) {
188
- if (key.includes("node_modules/")) {
189
- newCacheMap.set(key, value);
190
- }
191
- }
192
- await import_utils.fs.writeFile(filePath, await serializeMap(newCacheMap));
193
- console.log(`write ${import_path.default.basename(filePath)} finish`);
194
- };
195
- const traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
196
- const { cacheDir, fileCache, analysisCache, symlinkCache } = cacheOptions;
197
- const analysisCacheFile = import_path.default.join(cacheDir, "analysis-cache.json");
198
- const fileCacheFile = import_path.default.join(cacheDir, "file-cache.json");
199
- const symlinkCacheFile = import_path.default.join(cacheDir, "symlink-cache.json");
200
- const cache = {
201
- analysisCache: await loadCache(analysisCacheFile, analysisCache),
202
- fileCache: await loadCache(fileCacheFile, fileCache),
203
- symlinkCache: await loadCache(symlinkCacheFile, symlinkCache)
204
- };
205
- const res = await (0, import_nft.nodeFileTrace)(entryFiles, {
142
+ const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
143
+ return await (0, import_nft.nodeFileTrace)(entryFiles, {
206
144
  base,
207
145
  processCwd: serverRootDir,
208
- cache,
146
+ resolve: async (id, parent, job, isCjs) => {
147
+ if (id.startsWith("@modern-js/prod-server")) {
148
+ return require.resolve(id, {
149
+ paths: [
150
+ require.resolve("@modern-js/app-tools")
151
+ ]
152
+ });
153
+ } else {
154
+ return (0, import_nft.resolve)(id, parent, job, isCjs);
155
+ }
156
+ },
209
157
  ...traceOptions
210
158
  });
211
- if (analysisCache || fileCache || symlinkCache) {
212
- await import_utils.fs.ensureDir(cacheDir);
213
- if (cache.analysisCache && analysisCache) {
214
- writeCache(analysisCacheFile, cache.analysisCache);
215
- }
216
- if (cache.fileCache && fileCache) {
217
- writeCache(fileCacheFile, cache.fileCache);
218
- }
219
- if (cache.symlinkCache && symlinkCache) {
220
- writeCache(symlinkCacheFile, cache.symlinkCache);
221
- }
222
- }
223
- return res;
224
159
  };
225
160
  const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
226
161
  const isSubPath = (parentPath, childPath) => {
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const { handler } = require("./netlify-handler");
3
+ module.exports.default = handler;
@@ -0,0 +1 @@
1
+ export { handler as default } from './netlify-handler.cjs';
@@ -53,9 +53,11 @@ async function createHandler() {
53
53
  return requestHandler;
54
54
  }
55
55
  createHandler();
56
- module.exports.default = async (request, context) => {
57
- if (!requestHandler) {
58
- await createHandler();
56
+ module.exports = {
57
+ handler: async (request, context) => {
58
+ if (!requestHandler) {
59
+ await createHandler();
60
+ }
61
+ return requestHandler(request, context);
59
62
  }
60
- return requestHandler(request, context);
61
63
  };
@@ -50,11 +50,13 @@ async function cleanDistDirectory(dir) {
50
50
  }
51
51
  }
52
52
  const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
53
- const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
53
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
54
+ const isEsmProject = moduleType === "module";
54
55
  const plugins = serverPlugins.map((plugin) => plugin.name);
55
56
  const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
56
57
  const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
57
58
  const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
59
+ const handlerFilePath = import_node_path.default.join(funcsDirectory, "netlify-handler.cjs");
58
60
  return {
59
61
  async prepare() {
60
62
  await import_utils.fs.remove(netlifyOutput);
@@ -103,7 +105,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
103
105
  prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
104
106
  },
105
107
  output: {
106
- path: "."
108
+ distPath: {
109
+ root: "."
110
+ }
107
111
  }
108
112
  };
109
113
  const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
@@ -114,10 +118,15 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
114
118
  const pluginsCode = `[${plugins.map((plugin, index) => {
115
119
  return `plugin_${index}()`;
116
120
  }).join(",")}]`;
117
- let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
121
+ let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlify-handler.js"))).toString();
118
122
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
119
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
120
- await import_utils.fs.writeFile(entryFilePath, entryCode);
123
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
124
+ await import_utils.fs.writeFile(handlerFilePath, handlerCode);
125
+ if (isEsmProject) {
126
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
127
+ } else {
128
+ await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.js"), entryFilePath);
129
+ }
121
130
  },
122
131
  async end() {
123
132
  if (process.env.NODE_ENV !== "development") {