@modern-js/app-tools 2.58.1 → 2.58.3

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 (309) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
  2. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +0 -1
  3. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  4. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
  5. package/dist/cjs/builder/generator/index.js +2 -2
  6. package/dist/cjs/builder/index.js +2 -2
  7. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
  8. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -5
  9. package/dist/cjs/commands/build.js +21 -2
  10. package/dist/cjs/commands/dev.js +15 -5
  11. package/dist/cjs/commands/index.js +9 -9
  12. package/dist/cjs/commands/serve.js +4 -3
  13. package/dist/cjs/config/initialize/inits.js +4 -4
  14. package/dist/cjs/config/legacy/index.js +3 -3
  15. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  16. package/dist/cjs/esm/register-esm.mjs +66 -0
  17. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  18. package/dist/cjs/esm/utils.mjs +43 -0
  19. package/dist/cjs/index.js +8 -8
  20. package/dist/cjs/locale/index.js +1 -1
  21. package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
  22. package/dist/cjs/plugins/analyze/index.js +9 -9
  23. package/dist/cjs/plugins/analyze/utils.js +1 -1
  24. package/dist/cjs/plugins/deploy/dependencies/index.js +2 -1
  25. package/dist/cjs/plugins/deploy/dependencies/utils.js +13 -2
  26. package/dist/cjs/plugins/deploy/index.js +2 -2
  27. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
  28. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  29. package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
  30. package/dist/cjs/plugins/deploy/platforms/netlify.js +15 -6
  31. package/dist/cjs/plugins/deploy/platforms/node.js +14 -5
  32. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
  33. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  34. package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +4 -1
  35. package/dist/cjs/plugins/deploy/platforms/vercel.js +15 -6
  36. package/dist/cjs/plugins/serverBuild.js +2 -2
  37. package/dist/cjs/utils/config.js +1 -1
  38. package/dist/cjs/utils/createServer.js +1 -1
  39. package/dist/cjs/utils/loadPlugins.js +1 -1
  40. package/dist/cjs/utils/register.js +50 -23
  41. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +2 -2
  42. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  43. package/dist/types/builder/builder-webpack/adapterModern.d.ts +2 -2
  44. package/dist/types/builder/builder-webpack/index.d.ts +1 -1
  45. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
  46. package/dist/types/builder/generator/index.d.ts +3 -3
  47. package/dist/types/builder/index.d.ts +1 -1
  48. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  49. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  50. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
  51. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
  52. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  53. package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
  54. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
  55. package/dist/types/builder/shared/types.d.ts +1 -1
  56. package/dist/types/commands/build.d.ts +2 -2
  57. package/dist/types/commands/dev.d.ts +3 -3
  58. package/dist/types/commands/index.d.ts +3 -3
  59. package/dist/types/commands/inspect.d.ts +1 -1
  60. package/dist/types/config/default.d.ts +1 -1
  61. package/dist/types/config/initialize/inits.d.ts +1 -1
  62. package/dist/types/config/legacy/createHtmlConfig.d.ts +1 -1
  63. package/dist/types/config/legacy/createOutputConfig.d.ts +1 -1
  64. package/dist/types/config/legacy/createSourceConfig.d.ts +1 -1
  65. package/dist/types/config/legacy/createToolsConfig.d.ts +1 -1
  66. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  67. package/dist/types/esm/register-esm.d.mts +5 -0
  68. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  69. package/dist/types/esm/utils.d.mts +6 -0
  70. package/dist/types/exports/server.d.ts +1 -1
  71. package/dist/types/hooks.d.ts +1 -1
  72. package/dist/types/index.d.ts +2 -2
  73. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  74. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  75. package/dist/types/plugins/analyze/index.d.ts +1 -1
  76. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
  77. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
  78. package/dist/types/plugins/deploy/index.d.ts +2 -2
  79. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
  80. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
  81. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
  82. package/dist/types/plugins/deploy/platforms/netlify.d.ts +1 -1
  83. package/dist/types/plugins/deploy/platforms/node.d.ts +1 -1
  84. package/dist/types/plugins/deploy/platforms/platform.d.ts +2 -2
  85. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
  86. package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +2 -0
  87. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
  88. package/dist/types/plugins/deploy/platforms/vercel.d.ts +1 -1
  89. package/dist/types/plugins/deploy/utils.d.ts +1 -1
  90. package/dist/types/plugins/initialize/index.d.ts +1 -1
  91. package/dist/types/plugins/serverBuild.d.ts +1 -1
  92. package/dist/types/types/config/index.d.ts +8 -8
  93. package/dist/types/types/config/output.d.ts +1 -1
  94. package/dist/types/types/config/tools.d.ts +3 -3
  95. package/dist/types/types/hooks.d.ts +3 -3
  96. package/dist/types/types/index.d.ts +3 -3
  97. package/dist/types/types/legacyConfig/index.d.ts +3 -3
  98. package/dist/types/types/legacyConfig/tools.d.ts +1 -1
  99. package/dist/types/utils/createServer.d.ts +1 -1
  100. package/dist/types/utils/generateWatchFiles.d.ts +1 -1
  101. package/dist/types/utils/getSelectedEntries.d.ts +1 -1
  102. package/dist/types/utils/loadPlugins.d.ts +3 -3
  103. package/dist/types/utils/printInstructions.d.ts +1 -1
  104. package/dist/types/utils/register.d.ts +2 -2
  105. package/dist/types/utils/restart.d.ts +2 -2
  106. package/lib/types.d.ts +15 -0
  107. package/package.json +20 -20
  108. package/dist/esm/builder/builder-rspack/adapterCopy.js +0 -166
  109. package/dist/esm/builder/builder-rspack/index.js +0 -34
  110. package/dist/esm/builder/builder-webpack/adapterModern.js +0 -29
  111. package/dist/esm/builder/builder-webpack/createCopyPattern.js +0 -44
  112. package/dist/esm/builder/builder-webpack/index.js +0 -52
  113. package/dist/esm/builder/generator/createBuilderProviderConfig.js +0 -37
  114. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -81
  115. package/dist/esm/builder/generator/index.js +0 -94
  116. package/dist/esm/builder/index.js +0 -45
  117. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +0 -85
  118. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +0 -126
  119. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +0 -270
  120. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +0 -43
  121. package/dist/esm/builder/shared/builderPlugins/index.js +0 -4
  122. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -51
  123. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -37
  124. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +0 -317
  125. package/dist/esm/builder/shared/bundlerPlugins/index.js +0 -3
  126. package/dist/esm/builder/shared/createCopyInfo.js +0 -14
  127. package/dist/esm/builder/shared/index.js +0 -3
  128. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +0 -7
  129. package/dist/esm/builder/shared/types.js +0 -0
  130. package/dist/esm/commands/build.js +0 -117
  131. package/dist/esm/commands/deploy.js +0 -48
  132. package/dist/esm/commands/dev.js +0 -169
  133. package/dist/esm/commands/index.js +0 -411
  134. package/dist/esm/commands/inspect.js +0 -28
  135. package/dist/esm/commands/serve.js +0 -93
  136. package/dist/esm/config/default.js +0 -190
  137. package/dist/esm/config/index.js +0 -3
  138. package/dist/esm/config/initialize/index.js +0 -9
  139. package/dist/esm/config/initialize/inits.js +0 -85
  140. package/dist/esm/config/legacy/createHtmlConfig.js +0 -21
  141. package/dist/esm/config/legacy/createOutputConfig.js +0 -45
  142. package/dist/esm/config/legacy/createSourceConfig.js +0 -46
  143. package/dist/esm/config/legacy/createToolsConfig.js +0 -28
  144. package/dist/esm/config/legacy/index.js +0 -43
  145. package/dist/esm/defineConfig.js +0 -16
  146. package/dist/esm/exports/server.js +0 -4
  147. package/dist/esm/hooks.js +0 -34
  148. package/dist/esm/index.js +0 -239
  149. package/dist/esm/locale/en.js +0 -43
  150. package/dist/esm/locale/index.js +0 -12
  151. package/dist/esm/locale/zh.js +0 -43
  152. package/dist/esm/plugins/analyze/constants.js +0 -14
  153. package/dist/esm/plugins/analyze/getBundleEntry.js +0 -102
  154. package/dist/esm/plugins/analyze/getFileSystemEntry.js +0 -238
  155. package/dist/esm/plugins/analyze/getHtmlTemplate.js +0 -178
  156. package/dist/esm/plugins/analyze/getServerRoutes.js +0 -132
  157. package/dist/esm/plugins/analyze/index.js +0 -380
  158. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +0 -49
  159. package/dist/esm/plugins/analyze/templates.js +0 -6
  160. package/dist/esm/plugins/analyze/utils.js +0 -101
  161. package/dist/esm/plugins/deploy/dependencies/index.js +0 -614
  162. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -394
  163. package/dist/esm/plugins/deploy/exports.js +0 -4
  164. package/dist/esm/plugins/deploy/index.js +0 -135
  165. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -299
  166. package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +0 -203
  167. package/dist/esm/plugins/deploy/platforms/node.js +0 -133
  168. package/dist/esm/plugins/deploy/platforms/nodeEntry.js +0 -108
  169. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  170. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -233
  171. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -203
  172. package/dist/esm/plugins/deploy/utils.js +0 -47
  173. package/dist/esm/plugins/initialize/index.js +0 -119
  174. package/dist/esm/plugins/serverBuild.js +0 -87
  175. package/dist/esm/types/config/deploy.js +0 -0
  176. package/dist/esm/types/config/dev.js +0 -0
  177. package/dist/esm/types/config/experiments.js +0 -0
  178. package/dist/esm/types/config/html.js +0 -0
  179. package/dist/esm/types/config/index.js +0 -1
  180. package/dist/esm/types/config/output.js +0 -0
  181. package/dist/esm/types/config/performance.js +0 -0
  182. package/dist/esm/types/config/security.js +0 -0
  183. package/dist/esm/types/config/source.js +0 -0
  184. package/dist/esm/types/config/testing.js +0 -0
  185. package/dist/esm/types/config/tools.js +0 -0
  186. package/dist/esm/types/hooks.js +0 -0
  187. package/dist/esm/types/index.js +0 -3
  188. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  189. package/dist/esm/types/legacyConfig/dev.js +0 -0
  190. package/dist/esm/types/legacyConfig/index.js +0 -0
  191. package/dist/esm/types/legacyConfig/output.js +0 -0
  192. package/dist/esm/types/legacyConfig/source.js +0 -0
  193. package/dist/esm/types/legacyConfig/testing.js +0 -0
  194. package/dist/esm/types/legacyConfig/tools.js +0 -0
  195. package/dist/esm/types/utils.js +0 -0
  196. package/dist/esm/utils/config.js +0 -122
  197. package/dist/esm/utils/createServer.js +0 -58
  198. package/dist/esm/utils/env.js +0 -16
  199. package/dist/esm/utils/generateWatchFiles.js +0 -71
  200. package/dist/esm/utils/getSelectedEntries.js +0 -67
  201. package/dist/esm/utils/loadPlugins.js +0 -69
  202. package/dist/esm/utils/printInstructions.js +0 -32
  203. package/dist/esm/utils/register.js +0 -129
  204. package/dist/esm/utils/restart.js +0 -67
  205. package/dist/esm/utils/routes.js +0 -42
  206. package/dist/esm/utils/types.js +0 -0
  207. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +0 -67
  208. package/dist/esm-node/builder/builder-rspack/index.js +0 -12
  209. package/dist/esm-node/builder/builder-webpack/adapterModern.js +0 -26
  210. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +0 -42
  211. package/dist/esm-node/builder/builder-webpack/index.js +0 -20
  212. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +0 -44
  213. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +0 -60
  214. package/dist/esm-node/builder/generator/index.js +0 -37
  215. package/dist/esm-node/builder/index.js +0 -11
  216. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +0 -48
  217. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +0 -60
  218. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +0 -156
  219. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +0 -27
  220. package/dist/esm-node/builder/shared/builderPlugins/index.js +0 -4
  221. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -30
  222. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -31
  223. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +0 -231
  224. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +0 -3
  225. package/dist/esm-node/builder/shared/createCopyInfo.js +0 -14
  226. package/dist/esm-node/builder/shared/index.js +0 -3
  227. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +0 -7
  228. package/dist/esm-node/builder/shared/types.js +0 -0
  229. package/dist/esm-node/commands/build.js +0 -55
  230. package/dist/esm-node/commands/deploy.js +0 -12
  231. package/dist/esm-node/commands/dev.js +0 -95
  232. package/dist/esm-node/commands/index.js +0 -92
  233. package/dist/esm-node/commands/inspect.js +0 -15
  234. package/dist/esm-node/commands/serve.js +0 -51
  235. package/dist/esm-node/config/default.js +0 -197
  236. package/dist/esm-node/config/index.js +0 -3
  237. package/dist/esm-node/config/initialize/index.js +0 -9
  238. package/dist/esm-node/config/initialize/inits.js +0 -79
  239. package/dist/esm-node/config/legacy/createHtmlConfig.js +0 -21
  240. package/dist/esm-node/config/legacy/createOutputConfig.js +0 -45
  241. package/dist/esm-node/config/legacy/createSourceConfig.js +0 -29
  242. package/dist/esm-node/config/legacy/createToolsConfig.js +0 -28
  243. package/dist/esm-node/config/legacy/index.js +0 -43
  244. package/dist/esm-node/defineConfig.js +0 -13
  245. package/dist/esm-node/exports/server.js +0 -4
  246. package/dist/esm-node/hooks.js +0 -34
  247. package/dist/esm-node/index.js +0 -124
  248. package/dist/esm-node/locale/en.js +0 -43
  249. package/dist/esm-node/locale/index.js +0 -12
  250. package/dist/esm-node/locale/zh.js +0 -43
  251. package/dist/esm-node/plugins/analyze/constants.js +0 -14
  252. package/dist/esm-node/plugins/analyze/getBundleEntry.js +0 -61
  253. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +0 -100
  254. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +0 -74
  255. package/dist/esm-node/plugins/analyze/getServerRoutes.js +0 -132
  256. package/dist/esm-node/plugins/analyze/index.js +0 -166
  257. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +0 -47
  258. package/dist/esm-node/plugins/analyze/templates.js +0 -24
  259. package/dist/esm-node/plugins/analyze/utils.js +0 -68
  260. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -201
  261. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -126
  262. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  263. package/dist/esm-node/plugins/deploy/index.js +0 -44
  264. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -108
  265. package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +0 -69
  266. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -63
  267. package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +0 -44
  268. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  269. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -120
  270. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -69
  271. package/dist/esm-node/plugins/deploy/utils.js +0 -44
  272. package/dist/esm-node/plugins/initialize/index.js +0 -84
  273. package/dist/esm-node/plugins/serverBuild.js +0 -58
  274. package/dist/esm-node/types/config/deploy.js +0 -0
  275. package/dist/esm-node/types/config/dev.js +0 -0
  276. package/dist/esm-node/types/config/experiments.js +0 -0
  277. package/dist/esm-node/types/config/html.js +0 -0
  278. package/dist/esm-node/types/config/index.js +0 -1
  279. package/dist/esm-node/types/config/output.js +0 -0
  280. package/dist/esm-node/types/config/performance.js +0 -0
  281. package/dist/esm-node/types/config/security.js +0 -0
  282. package/dist/esm-node/types/config/source.js +0 -0
  283. package/dist/esm-node/types/config/testing.js +0 -0
  284. package/dist/esm-node/types/config/tools.js +0 -0
  285. package/dist/esm-node/types/hooks.js +0 -0
  286. package/dist/esm-node/types/index.js +0 -3
  287. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  288. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  289. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  290. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  291. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  292. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  293. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  294. package/dist/esm-node/types/utils.js +0 -0
  295. package/dist/esm-node/utils/config.js +0 -49
  296. package/dist/esm-node/utils/createServer.js +0 -26
  297. package/dist/esm-node/utils/env.js +0 -16
  298. package/dist/esm-node/utils/generateWatchFiles.js +0 -30
  299. package/dist/esm-node/utils/getSelectedEntries.js +0 -34
  300. package/dist/esm-node/utils/loadPlugins.js +0 -22
  301. package/dist/esm-node/utils/printInstructions.js +0 -11
  302. package/dist/esm-node/utils/register.js +0 -69
  303. package/dist/esm-node/utils/restart.js +0 -22
  304. package/dist/esm-node/utils/routes.js +0 -21
  305. package/dist/esm-node/utils/types.js +0 -0
  306. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
  307. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  308. /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
  309. /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -1,126 +0,0 @@
1
- import path from "path";
2
- import os from "node:os";
3
- import { fs as fse } from "@modern-js/utils";
4
- import { parseNodeModulePath } from "mlly";
5
- import { nodeFileTrace } from "@vercel/nft";
6
- function applyPublicCondition(pkg) {
7
- var _pkg_publishConfig;
8
- if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
9
- var _pkg_publishConfig1;
10
- pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
11
- }
12
- }
13
- const writePackage = async (options) => {
14
- const { pkg, version, projectDir, _pkgPath } = options;
15
- const pkgPath = _pkgPath || pkg.name;
16
- for (const src of pkg.versions[version].files) {
17
- if (src.includes("node_modules")) {
18
- const { subpath } = parseNodeModulePath(src);
19
- const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
20
- const dirname = path.dirname(dest);
21
- await fse.ensureDir(dirname);
22
- await fse.copyFile(src, dest);
23
- } else {
24
- const subpath = path.relative(pkg.versions[version].path, src);
25
- const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
26
- const dirname = path.dirname(dest);
27
- await fse.ensureDir(dirname);
28
- await fse.copyFile(src, dest);
29
- }
30
- }
31
- const { pkgJSON } = pkg.versions[version];
32
- applyPublicCondition(pkgJSON);
33
- const packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
34
- await fse.ensureDir(path.dirname(packageJsonPath));
35
- await fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
36
- };
37
- const isWindows = os.platform() === "win32";
38
- const linkPackage = async (from, to, projectRootDir) => {
39
- const src = path.join(projectRootDir, "node_modules", from);
40
- const dest = path.join(projectRootDir, "node_modules", to);
41
- const dstStat = await fse.lstat(dest).catch(() => null);
42
- const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
43
- if (exists) {
44
- return;
45
- }
46
- await fse.mkdir(path.dirname(dest), {
47
- recursive: true
48
- });
49
- await fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
50
- console.error("Cannot link", from, "to", to, error);
51
- });
52
- };
53
- const readDirRecursive = async (dir, options = {}) => {
54
- const { filter } = options;
55
- const files = await fse.readdir(dir, {
56
- withFileTypes: true
57
- });
58
- const filesAndDirs = await Promise.all(files.map(async (file) => {
59
- const resolvedPath = path.resolve(dir, file.name);
60
- if (file.isDirectory()) {
61
- return readDirRecursive(resolvedPath, options);
62
- } else {
63
- return filter && !filter(resolvedPath) ? [] : resolvedPath;
64
- }
65
- }));
66
- return filesAndDirs.flat();
67
- };
68
- const isFile = async (file) => {
69
- try {
70
- const stat = await fse.stat(file);
71
- return stat.isFile();
72
- } catch (error) {
73
- if (error.code === "ENOENT") {
74
- return false;
75
- }
76
- throw error;
77
- }
78
- };
79
- const findEntryFiles = async (rootDir, entryFilter) => {
80
- const files = await readDirRecursive(rootDir, {
81
- filter: entryFilter
82
- });
83
- return files.filter((file) => file.endsWith(".mjs") || file.endsWith(".cjs") || file.endsWith(".js"));
84
- };
85
- const findPackageParents = (pkg, version, tracedFiles) => {
86
- const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
87
- const parentPkgs = [
88
- ...new Set(versionFiles.flatMap((file) => (
89
- // Because it supports copyWholePackage configuration, not all files exist.
90
- file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
91
- const parentFile = tracedFiles[parentPath];
92
- if (!parentFile || parentFile.pkgName === pkg.name) {
93
- return null;
94
- }
95
- return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
96
- }).filter(Boolean)
97
- )))
98
- ];
99
- return parentPkgs.filter((parentPkg) => parentPkg);
100
- };
101
- const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
102
- return await nodeFileTrace(entryFiles, {
103
- base,
104
- processCwd: serverRootDir,
105
- ...traceOptions
106
- });
107
- };
108
- const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
109
- const isSubPath = (parentPath, childPath) => {
110
- if (!parentPath || !childPath) {
111
- return false;
112
- }
113
- const relative = path.relative(parentPath, childPath);
114
- return relative && !relative.startsWith("..");
115
- };
116
- export {
117
- findEntryFiles,
118
- findPackageParents,
119
- isFile,
120
- isSubPath,
121
- linkPackage,
122
- readDirRecursive,
123
- resolveTracedPath,
124
- traceFiles,
125
- writePackage
126
- };
@@ -1,4 +0,0 @@
1
- import { handleDependencies } from "./dependencies";
2
- export {
3
- handleDependencies
4
- };
@@ -1,44 +0,0 @@
1
- import { provider } from "std-env";
2
- import { getProjectUsage } from "./utils";
3
- import { createNodePreset } from "./platforms/node";
4
- import { createVercelPreset } from "./platforms/vercel";
5
- import { createNetlifyPreset } from "./platforms/netlify";
6
- const deployPresets = {
7
- node: createNodePreset,
8
- vercel: createVercelPreset,
9
- netlify: createNetlifyPreset
10
- };
11
- async function getDeployPreset(appContext, modernConfig, deployTarget) {
12
- const { appDirectory, distDirectory } = appContext;
13
- const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
14
- const needModernServer = useSSR || useAPI || useWebServer;
15
- const createPreset = deployPresets[deployTarget];
16
- if (!createPreset) {
17
- throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
18
- }
19
- return createPreset(appContext, modernConfig, needModernServer);
20
- }
21
- var deploy_default = () => ({
22
- name: "@modern-js/plugin-deploy",
23
- setup: (api) => {
24
- const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
25
- return {
26
- async deploy() {
27
- const appContext = api.useAppContext();
28
- const { metaName } = appContext;
29
- if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
30
- return;
31
- }
32
- const modernConfig = api.useResolvedConfigContext();
33
- const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
34
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
35
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
36
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
37
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
38
- }
39
- };
40
- }
41
- });
42
- export {
43
- deploy_default as default
44
- };
@@ -1,108 +0,0 @@
1
- import path from "node:path";
2
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
3
- import { isMainEntry } from "../../../utils/routes";
4
- import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
5
- import { handleDependencies } from "../dependencies";
6
- async function cleanDistDirectory(dir) {
7
- try {
8
- const items = await fse.readdir(dir);
9
- for (const item of items) {
10
- const fullPath = path.join(dir, item);
11
- if (item !== "static" && item !== "_redirects" && item !== "html") {
12
- await fse.remove(fullPath);
13
- }
14
- }
15
- } catch (error) {
16
- console.error("Error cleaning directory:", error);
17
- }
18
- }
19
- const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
20
- const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
21
- const plugins = serverPlugins.map((plugin) => plugin.name);
22
- const netlifyOutput = path.join(appDirectory, ".netlify");
23
- const funcsDirectory = path.join(netlifyOutput, "functions");
24
- const entryFilePath = path.join(funcsDirectory, "index.js");
25
- return {
26
- async prepare() {
27
- await fse.remove(netlifyOutput);
28
- },
29
- async writeOutput() {
30
- const routes = [];
31
- const { source: { mainEntryName } } = modernConfig;
32
- if (!needModernServer) {
33
- entrypoints.forEach((entry) => {
34
- const isMain = isMainEntry(entry.entryName, mainEntryName);
35
- routes.push({
36
- src: `/${isMain ? "" : `${entry.entryName}/`}*`,
37
- dest: `/html/${entry.entryName}/index.html`,
38
- status: 200
39
- });
40
- });
41
- } else {
42
- routes.push({
43
- src: "/*",
44
- dest: `/.netlify/functions/index`,
45
- status: 200
46
- });
47
- }
48
- const redirectContent = routes.map((route) => {
49
- return `${route.src} ${route.dest} ${route.status}`;
50
- }).join("\n");
51
- if (needModernServer) {
52
- await fse.ensureDir(funcsDirectory);
53
- await fse.copy(distDirectory, funcsDirectory, {
54
- filter: (src) => {
55
- const distStaticDirectory = path.join(distDirectory, `static`);
56
- return !src.includes(distStaticDirectory);
57
- }
58
- });
59
- }
60
- const redirectFilePath = path.join(distDirectory, "_redirects");
61
- await fse.writeFile(redirectFilePath, redirectContent);
62
- },
63
- async genEntry() {
64
- var _modernConfig_bff;
65
- if (!needModernServer) {
66
- return;
67
- }
68
- const serverConfig = {
69
- bff: {
70
- prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
71
- },
72
- output: {
73
- path: "."
74
- }
75
- };
76
- const pluginImportCode = genPluginImportsCode(plugins || []);
77
- const dynamicProdOptions = {
78
- config: serverConfig,
79
- serverConfigFile: DEFAULT_SERVER_CONFIG
80
- };
81
- const pluginsCode = `[${plugins.map((plugin, index) => {
82
- return `plugin_${index}()`;
83
- }).join(",")}]`;
84
- let entryCode = (await fse.readFile(path.join(__dirname, "./netlifyEntry.js"))).toString();
85
- const serverAppContext = serverAppContenxtTemplate(appContext);
86
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${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);
87
- await fse.writeFile(entryFilePath, entryCode);
88
- },
89
- async end() {
90
- if (process.env.NODE_ENV !== "development") {
91
- await cleanDistDirectory(distDirectory);
92
- }
93
- if (!needModernServer) {
94
- return;
95
- }
96
- await handleDependencies({
97
- appDir: appDirectory,
98
- serverRootDir: funcsDirectory,
99
- includeEntries: [
100
- require.resolve("@modern-js/prod-server")
101
- ]
102
- });
103
- }
104
- };
105
- };
106
- export {
107
- createNetlifyPreset
108
- };
@@ -1,69 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
- var require_netlifyEntry = __commonJS({
6
- "src/plugins/deploy/platforms/netlifyEntry.js"(exports, module) {
7
- const fs = require("node:fs/promises");
8
- const path = require("node:path");
9
- const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
10
- p_genPluginImportsCode;
11
- if (!process.env.NODE_ENV) {
12
- process.env.NODE_ENV = "production";
13
- }
14
- let requestHandler = null;
15
- let handlerCreationPromise = null;
16
- async function loadRoutes(routeFilepath) {
17
- try {
18
- await fs.access(routeFilepath);
19
- const content = await fs.readFile(routeFilepath, "utf-8");
20
- const routeSpec = JSON.parse(content);
21
- return routeSpec.routes || [];
22
- } catch (error) {
23
- console.warn("route.json not found or invalid, continuing with empty routes.");
24
- return [];
25
- }
26
- }
27
- async function initServer() {
28
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
29
- const routes = await loadRoutes(routeFilepath);
30
- const dynamicProdOptions = p_dynamicProdOptions;
31
- const prodServerOptions = {
32
- pwd: __dirname,
33
- routes,
34
- disableCustomHook: true,
35
- appContext: {
36
- sharedDirectory: p_sharedDirectory,
37
- apiDirectory: p_apiDirectory,
38
- lambdaDirectory: p_lambdaDirectory
39
- },
40
- plugins: p_plugins,
41
- ...dynamicProdOptions
42
- };
43
- const requestHandler2 = await createNetlifyFunction(prodServerOptions);
44
- return requestHandler2;
45
- }
46
- async function createHandler() {
47
- if (!handlerCreationPromise) {
48
- handlerCreationPromise = (async () => {
49
- try {
50
- requestHandler = await initServer();
51
- } catch (error) {
52
- console.error("Error creating server:", error);
53
- process.exit(1);
54
- }
55
- })();
56
- }
57
- await handlerCreationPromise;
58
- return requestHandler;
59
- }
60
- createHandler();
61
- module.exports.default = async (request, context) => {
62
- if (!requestHandler) {
63
- await createHandler();
64
- }
65
- return requestHandler(request, context);
66
- };
67
- }
68
- });
69
- export default require_netlifyEntry();
@@ -1,63 +0,0 @@
1
- import path from "node:path";
2
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, chalk } from "@modern-js/utils";
3
- import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
4
- import { handleDependencies } from "../dependencies";
5
- const createNodePreset = (appContext, config) => {
6
- const { appDirectory, distDirectory, serverPlugins } = appContext;
7
- const plugins = serverPlugins.map((plugin) => plugin.name);
8
- const outputDirectory = path.join(appDirectory, ".output");
9
- const staticDirectory = path.join(outputDirectory, "static");
10
- const entryFilePath = path.join(outputDirectory, "index.js");
11
- return {
12
- async prepare() {
13
- await fse.remove(outputDirectory);
14
- },
15
- async writeOutput() {
16
- await fse.copy(distDirectory, outputDirectory);
17
- },
18
- async genEntry() {
19
- var _config_bff;
20
- const serverConfig = {
21
- server: {
22
- port: 8080
23
- },
24
- bff: {
25
- prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
26
- },
27
- output: {
28
- path: "."
29
- }
30
- };
31
- const pluginImportCode = genPluginImportsCode(plugins || []);
32
- const dynamicProdOptions = {
33
- config: serverConfig,
34
- serverConfigFile: DEFAULT_SERVER_CONFIG
35
- };
36
- const pluginsCode = `[${plugins.map((plugin, index) => {
37
- return `plugin_${index}()`;
38
- }).join(",")}]`;
39
- let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
40
- const serverAppContext = serverAppContenxtTemplate(appContext);
41
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${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);
42
- await fse.writeFile(entryFilePath, entryCode);
43
- },
44
- async end() {
45
- console.log("Static directory:", chalk.blue(path.relative(appDirectory, staticDirectory)));
46
- console.log(`You can preview this build by`, chalk.blue(`node .output/index`));
47
- const filter = (filePath) => {
48
- return !filePath.startsWith(staticDirectory);
49
- };
50
- await handleDependencies({
51
- appDir: appDirectory,
52
- serverRootDir: outputDirectory,
53
- includeEntries: [
54
- require.resolve("@modern-js/prod-server")
55
- ],
56
- entryFilter: filter
57
- });
58
- }
59
- };
60
- };
61
- export {
62
- createNodePreset
63
- };
@@ -1,44 +0,0 @@
1
- const fs = require("node:fs/promises");
2
- const path = require("node:path");
3
- const { createProdServer } = require("@modern-js/prod-server");
4
- p_genPluginImportsCode;
5
- if (!process.env.NODE_ENV) {
6
- process.env.NODE_ENV = "production";
7
- }
8
- async function loadRoutes(routeFilepath) {
9
- try {
10
- await fs.access(routeFilepath);
11
- const content = await fs.readFile(routeFilepath, "utf-8");
12
- const routeSpec = JSON.parse(content);
13
- return routeSpec.routes || [];
14
- } catch (error) {
15
- console.warn("route.json not found or invalid, continuing with empty routes.");
16
- return [];
17
- }
18
- }
19
- async function main() {
20
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
21
- const routes = await loadRoutes(routeFilepath);
22
- const dynamicProdOptions = p_dynamicProdOptions;
23
- const prodServerOptions = {
24
- pwd: __dirname,
25
- routes,
26
- disableCustomHook: true,
27
- appContext: {
28
- sharedDirectory: p_sharedDirectory,
29
- apiDirectory: p_apiDirectory,
30
- lambdaDirectory: p_lambdaDirectory
31
- },
32
- plugins: p_plugins,
33
- ...dynamicProdOptions
34
- };
35
- const app = await createProdServer(prodServerOptions);
36
- const port = process.env.PORT || 8080;
37
- app.listen({
38
- host: "::",
39
- port
40
- }, () => {
41
- console.log(`\x1B[32mServer is listening on http://[::]:${port}`, "\x1B[0m");
42
- });
43
- }
44
- main();
@@ -1,120 +0,0 @@
1
- import path from "node:path";
2
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
3
- import { isMainEntry } from "../../../utils/routes";
4
- import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
5
- import { handleDependencies } from "../dependencies";
6
- const createVercelPreset = (appContext, modernConfig, needModernServer) => {
7
- const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
8
- const plugins = serverPlugins.map((plugin) => plugin.name);
9
- const vercelOutput = path.join(appDirectory, ".vercel");
10
- const outputDirectory = path.join(vercelOutput, "output");
11
- const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
12
- const entryFilePath = path.join(funcsDirectory, "index.js");
13
- return {
14
- async prepare() {
15
- await fse.remove(vercelOutput);
16
- },
17
- async writeOutput() {
18
- const config = {
19
- version: 3,
20
- routes: [
21
- {
22
- src: "/static/(.*)",
23
- headers: {
24
- "cache-control": "s-maxage=31536000, immutable"
25
- },
26
- continue: true
27
- },
28
- {
29
- handle: "filesystem"
30
- }
31
- ]
32
- };
33
- if (!needModernServer) {
34
- const { source: { mainEntryName } } = modernConfig;
35
- entrypoints.forEach((entry) => {
36
- const isMain = isMainEntry(entry.entryName, mainEntryName);
37
- config.routes.push({
38
- src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
39
- headers: {
40
- "cache-control": "s-maxage=0"
41
- },
42
- dest: `/html/${entry.entryName}/index.html`
43
- });
44
- });
45
- } else {
46
- config.routes.push({
47
- src: "/(.*)",
48
- dest: `/index`
49
- });
50
- }
51
- await fse.ensureDir(outputDirectory);
52
- await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
53
- spaces: 2
54
- });
55
- const staticDirectory = path.join(outputDirectory, "static/static");
56
- await fse.copy(path.join(distDirectory, "static"), staticDirectory);
57
- if (!needModernServer) {
58
- const destHtmlDirectory = path.join(distDirectory, "html");
59
- const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
60
- await fse.copy(destHtmlDirectory, outputHtmlDirectory);
61
- } else {
62
- await fse.ensureDir(funcsDirectory);
63
- await fse.copy(distDirectory, funcsDirectory, {
64
- filter: (src) => {
65
- const distStaticDirectory = path.join(distDirectory, "static");
66
- return !src.includes(distStaticDirectory);
67
- }
68
- });
69
- await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
70
- runtime: "nodejs16.x",
71
- handler: "index.js",
72
- launcherType: "Nodejs",
73
- shouldAddHelpers: false,
74
- supportsResponseStreaming: true
75
- });
76
- }
77
- },
78
- async genEntry() {
79
- var _modernConfig_bff;
80
- if (!needModernServer) {
81
- return;
82
- }
83
- const serverConfig = {
84
- bff: {
85
- prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
86
- },
87
- output: {
88
- path: "."
89
- }
90
- };
91
- const pluginImportCode = genPluginImportsCode(plugins || []);
92
- const dynamicProdOptions = {
93
- config: serverConfig,
94
- serverConfigFile: DEFAULT_SERVER_CONFIG
95
- };
96
- const pluginsCode = `[${plugins.map((plugin, index) => {
97
- return `plugin_${index}()`;
98
- }).join(",")}]`;
99
- const serverAppContext = serverAppContenxtTemplate(appContext);
100
- let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
101
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${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);
102
- await fse.writeFile(entryFilePath, entryCode);
103
- },
104
- async end() {
105
- if (!needModernServer) {
106
- return;
107
- }
108
- await handleDependencies({
109
- appDir: appDirectory,
110
- serverRootDir: funcsDirectory,
111
- includeEntries: [
112
- require.resolve("@modern-js/prod-server")
113
- ]
114
- });
115
- }
116
- };
117
- };
118
- export {
119
- createVercelPreset
120
- };
@@ -1,69 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
- var require_vercelEntry = __commonJS({
6
- "src/plugins/deploy/platforms/vercelEntry.js"(exports, module) {
7
- const fs = require("node:fs/promises");
8
- const path = require("node:path");
9
- const { createProdServer } = require("@modern-js/prod-server");
10
- p_genPluginImportsCode;
11
- if (!process.env.NODE_ENV) {
12
- process.env.NODE_ENV = "production";
13
- }
14
- let requestHandler = null;
15
- let handlerCreationPromise = null;
16
- async function loadRoutes(routeFilepath) {
17
- try {
18
- await fs.access(routeFilepath);
19
- const content = await fs.readFile(routeFilepath, "utf-8");
20
- const routeSpec = JSON.parse(content);
21
- return routeSpec.routes || [];
22
- } catch (error) {
23
- console.warn("route.json not found or invalid, continuing with empty routes.");
24
- return [];
25
- }
26
- }
27
- async function initServer() {
28
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
29
- const routes = await loadRoutes(routeFilepath);
30
- const dynamicProdOptions = p_dynamicProdOptions;
31
- const prodServerOptions = {
32
- pwd: __dirname,
33
- routes,
34
- disableCustomHook: true,
35
- appContext: {
36
- sharedDirectory: p_sharedDirectory,
37
- apiDirectory: p_apiDirectory,
38
- lambdaDirectory: p_lambdaDirectory
39
- },
40
- plugins: p_plugins,
41
- ...dynamicProdOptions
42
- };
43
- const app = await createProdServer(prodServerOptions);
44
- return app.getRequestListener();
45
- }
46
- async function createHandler() {
47
- if (!handlerCreationPromise) {
48
- handlerCreationPromise = (async () => {
49
- try {
50
- requestHandler = await initServer();
51
- } catch (error) {
52
- console.error("Error creating server:", error);
53
- process.exit(1);
54
- }
55
- })();
56
- }
57
- await handlerCreationPromise;
58
- return requestHandler;
59
- }
60
- createHandler();
61
- module.exports = async (req, res) => {
62
- if (!requestHandler) {
63
- await createHandler();
64
- }
65
- return requestHandler(req, res);
66
- };
67
- }
68
- });
69
- export default require_vercelEntry();