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

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 (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
@@ -1,132 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
4
- import { isMainEntry } from "../../utils/routes";
5
- import { walkDirectory } from "./utils";
6
- const applyBaseUrl = (baseUrl, routes) => {
7
- if (baseUrl) {
8
- if (Array.isArray(baseUrl)) {
9
- return baseUrl.reduce((previous, current) => [
10
- ...previous,
11
- ...applyBaseUrl(current, routes)
12
- ], []);
13
- } else {
14
- return routes.map((route) => {
15
- const urlPath = urlJoin(baseUrl, route.urlPath);
16
- return {
17
- ...route,
18
- urlPath: urlPath === "/" ? urlPath : removeTailSlash(urlPath)
19
- };
20
- });
21
- }
22
- }
23
- return routes;
24
- };
25
- const applyRouteOptions = (original, routeOptions) => {
26
- const { route, disableSpa } = routeOptions;
27
- original.isSPA = !disableSpa;
28
- !original.isSPA && (original.entryPath = path.dirname(original.entryPath));
29
- let routes;
30
- if (route) {
31
- if (Array.isArray(route)) {
32
- routes = route.map((url) => {
33
- if (isPlainObject(url)) {
34
- const { path: urlPath, ...other } = url;
35
- return {
36
- ...original,
37
- ...other,
38
- urlPath
39
- };
40
- } else {
41
- return {
42
- ...original,
43
- urlPath: url
44
- };
45
- }
46
- });
47
- } else if (isPlainObject(route)) {
48
- const { path: urlPath, ...other } = route;
49
- routes = [
50
- {
51
- ...original,
52
- ...other,
53
- urlPath
54
- }
55
- ];
56
- } else {
57
- routes = [
58
- {
59
- ...original,
60
- urlPath: route
61
- }
62
- ];
63
- }
64
- } else {
65
- routes = [
66
- original
67
- ];
68
- }
69
- return routes;
70
- };
71
- const collectHtmlRoutes = (entrypoints, appContext, config) => {
72
- var _deploy_worker;
73
- const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
74
- const { packageName } = appContext;
75
- const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
76
- let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
77
- const isMain = isMainEntry(entryName, mainEntryName);
78
- const entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
79
- const isSSR = Boolean(entryOptions);
80
- const isWorker = Boolean(workerSSR);
81
- const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
82
- const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
83
- let route = {
84
- urlPath: `/${isMain ? "" : entryName}`,
85
- entryName,
86
- entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
87
- isSPA: true,
88
- isStream,
89
- isSSR,
90
- responseHeaders: resHeaders,
91
- worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
92
- bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
93
- };
94
- if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
95
- const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
96
- route: routes[entryName]
97
- };
98
- route = applyRouteOptions(route, routeOptions);
99
- }
100
- return Array.isArray(route) ? [
101
- ...previous,
102
- ...route
103
- ] : [
104
- ...previous,
105
- route
106
- ];
107
- }, []);
108
- htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
109
- return htmlRoutes;
110
- };
111
- const collectStaticRoutes = (appContext, config) => {
112
- const { appDirectory } = appContext;
113
- const { source: { configDir }, server: { publicRoutes = {} } } = config;
114
- const publicFolder = path.resolve(appDirectory, configDir || "", "public");
115
- return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map((filePath) => {
116
- const urlPath = `${urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
117
- return {
118
- urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
119
- isSPA: true,
120
- isSSR: false,
121
- entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir || ""), filePath))
122
- };
123
- }) : [];
124
- };
125
- const getServerRoutes = (entrypoints, { appContext, config }) => [
126
- ...collectHtmlRoutes(entrypoints, appContext, config),
127
- ...collectStaticRoutes(appContext, config)
128
- ];
129
- const toPosix = (pathStr) => pathStr.split(path.sep).join(path.posix.sep);
130
- export {
131
- getServerRoutes
132
- };
@@ -1,166 +0,0 @@
1
- import * as path from "path";
2
- import { createDebugger, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
3
- import { printInstructions } from "../../utils/printInstructions";
4
- import { generateRoutes } from "../../utils/routes";
5
- import { emitResolvedConfig } from "../../utils/config";
6
- import { getSelectedEntries } from "../../utils/getSelectedEntries";
7
- import { initialNormalizedConfig } from "../../config";
8
- import { createBuilderGenerator } from "../../builder";
9
- import { checkIsBuildCommands } from "./utils";
10
- const debug = createDebugger("plugin-analyze");
11
- var analyze_default = ({ bundler }) => ({
12
- name: "@modern-js/plugin-analyze",
13
- post: [
14
- "@modern-js/runtime"
15
- ],
16
- setup: (api) => {
17
- let pagesDir = [];
18
- let nestedRouteEntries = [];
19
- return {
20
- async prepare() {
21
- var _resolvedConfig_source;
22
- let appContext = api.useAppContext();
23
- const resolvedConfig = api.useResolvedConfigContext();
24
- const hookRunners = api.useHookRunners();
25
- try {
26
- if (checkIsBuildCommands()) {
27
- fs.emptydirSync(appContext.internalDirectory);
28
- }
29
- } catch {
30
- }
31
- const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
32
- await hookRunners.addRuntimeExports();
33
- if (apiOnly) {
34
- const { routes: routes2 } = await hookRunners.modifyServerRoutes({
35
- routes: []
36
- });
37
- debug(`server routes: %o`, routes2);
38
- appContext = {
39
- ...api.useAppContext(),
40
- apiOnly,
41
- serverRoutes: routes2
42
- };
43
- api.setAppContext(appContext);
44
- return;
45
- }
46
- const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
47
- import("./getBundleEntry"),
48
- import("./getServerRoutes"),
49
- import("./getHtmlTemplate")
50
- ]);
51
- const { entrypoints } = await hookRunners.modifyEntrypoints({
52
- entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
53
- });
54
- debug(`entrypoints: %o`, entrypoints);
55
- const initialRoutes = getServerRoutes(entrypoints, {
56
- appContext,
57
- config: resolvedConfig
58
- });
59
- const { routes } = await hookRunners.modifyServerRoutes({
60
- routes: initialRoutes
61
- });
62
- debug(`server routes: %o`, routes);
63
- appContext = {
64
- ...api.useAppContext(),
65
- entrypoints,
66
- serverRoutes: routes
67
- };
68
- api.setAppContext(appContext);
69
- nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
70
- pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
71
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
72
- appContext,
73
- config: resolvedConfig
74
- });
75
- debug(`html templates: %o`, htmlTemplates);
76
- await hookRunners.addDefineTypes();
77
- debug(`add Define Types`);
78
- let checkedEntries = entrypoints.map((point) => point.entryName);
79
- if (isDevCommand()) {
80
- const { entry } = minimist(getArgv());
81
- checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
82
- }
83
- appContext = {
84
- ...api.useAppContext(),
85
- entrypoints,
86
- checkedEntries,
87
- apiOnly,
88
- serverRoutes: routes,
89
- htmlTemplates
90
- };
91
- api.setAppContext(appContext);
92
- if (checkIsBuildCommands()) {
93
- await hookRunners.generateEntryCode({
94
- entrypoints
95
- });
96
- const normalizedConfig = api.useResolvedConfigContext();
97
- const createBuilderForModern = await createBuilderGenerator(bundler);
98
- const builder = await createBuilderForModern({
99
- normalizedConfig,
100
- appContext
101
- });
102
- builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
103
- if (!isFirstCompile) {
104
- return;
105
- }
106
- const hookRunners2 = api.useHookRunners();
107
- await generateRoutes(appContext);
108
- await hookRunners2.beforeBuild({
109
- bundlerConfigs
110
- });
111
- });
112
- builder.onAfterBuild(async ({ stats }) => {
113
- const hookRunners2 = api.useHookRunners();
114
- await hookRunners2.afterBuild({
115
- stats
116
- });
117
- await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
118
- });
119
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
120
- const hookRunners2 = api.useHookRunners();
121
- hookRunners2.afterDev({
122
- isFirstCompile
123
- });
124
- if (isFirstCompile) {
125
- printInstructions(hookRunners2, appContext, normalizedConfig);
126
- }
127
- });
128
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
129
- const hookRunners2 = api.useHookRunners();
130
- await hookRunners2.beforeCreateCompiler({
131
- bundlerConfigs
132
- });
133
- });
134
- builder.onAfterCreateCompiler(async ({ compiler }) => {
135
- const hookRunners2 = api.useHookRunners();
136
- await hookRunners2.afterCreateCompiler({
137
- compiler
138
- });
139
- });
140
- builder.addPlugins(resolvedConfig.builderPlugins);
141
- appContext = {
142
- ...api.useAppContext(),
143
- builder
144
- };
145
- api.setAppContext(appContext);
146
- }
147
- },
148
- watchFiles() {
149
- return {
150
- files: pagesDir,
151
- isPrivate: true
152
- };
153
- },
154
- resolvedConfig({ resolved }) {
155
- const appContext = api.useAppContext();
156
- const config = initialNormalizedConfig(resolved, appContext, bundler);
157
- return {
158
- resolved: config
159
- };
160
- }
161
- };
162
- }
163
- });
164
- export {
165
- analyze_default as default
166
- };
@@ -1,47 +0,0 @@
1
- import fs from "fs";
2
- import { parse } from "@babel/parser";
3
- import traverse from "@babel/traverse";
4
- import * as t from "@babel/types";
5
- const isFunction = (node) => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
6
- const isDefaultExportFunction = (file) => {
7
- if (!file || !fs.existsSync(file)) {
8
- return false;
9
- }
10
- const ast = parse(fs.readFileSync(file, "utf8"), {
11
- sourceType: "unambiguous",
12
- plugins: [
13
- "jsx",
14
- "typescript",
15
- "classProperties",
16
- "dynamicImport",
17
- "exportDefaultFrom",
18
- "exportNamespaceFrom",
19
- "decorators-legacy",
20
- "functionBind",
21
- "classPrivateMethods",
22
- [
23
- "pipelineOperator",
24
- {
25
- proposal: "minimal"
26
- }
27
- ],
28
- "optionalChaining",
29
- "optionalCatchBinding",
30
- "objectRestSpread",
31
- "numericSeparator"
32
- ]
33
- });
34
- let isExportFunction = false;
35
- traverse(ast, {
36
- ExportDefaultDeclaration: (path) => {
37
- const { declaration } = path.node;
38
- if (isFunction(declaration)) {
39
- isExportFunction = true;
40
- }
41
- }
42
- });
43
- return isExportFunction;
44
- };
45
- export {
46
- isDefaultExportFunction
47
- };
@@ -1,24 +0,0 @@
1
- const html = (partials) => `
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
-
6
- ${partials.top.join("\n")}
7
-
8
- ${partials.head.join("\n")}
9
-
10
- </head>
11
-
12
- <body>
13
- <div id="<%= mountId %>"><!--<?- html ?>--></div>
14
- ${partials.body.join("\n")}
15
- <!--<?- chunksMap.js ?>-->
16
- <!--<?- SSRDataScript ?>-->
17
- <!--<?- bottomTemplate ?>-->
18
- </body>
19
-
20
- </html>
21
- `;
22
- export {
23
- html
24
- };
@@ -1,68 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
4
- import { transform } from "esbuild";
5
- import { parse } from "es-module-lexer";
6
- const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
7
- const filePath = path.join(dir, filename);
8
- if (fs.statSync(filePath).isDirectory()) {
9
- return [
10
- ...previous,
11
- ...walkDirectory(filePath)
12
- ];
13
- } else {
14
- return [
15
- ...previous,
16
- filePath
17
- ];
18
- }
19
- }, []);
20
- const replaceWithAlias = (base, filePath, alias) => {
21
- if (filePath.includes(base)) {
22
- return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
23
- } else {
24
- return filePath;
25
- }
26
- };
27
- const parseModule = async ({ source, filename }) => {
28
- let content = source;
29
- if (JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
30
- const result = await transform(content, {
31
- loader: path.extname(filename).slice(1),
32
- format: "esm"
33
- });
34
- content = result.code;
35
- }
36
- return await parse(content);
37
- };
38
- const getServerCombinedModueFile = (internalDirectory, entryName) => {
39
- return path.join(internalDirectory, entryName, "server-loader-combined.js");
40
- };
41
- const checkIsBuildCommands = () => {
42
- const buildCommands = [
43
- "dev",
44
- "start",
45
- "build",
46
- "inspect",
47
- "deploy",
48
- "dev-worker"
49
- ];
50
- const command = getCommand();
51
- return buildCommands.includes(command);
52
- };
53
- const isSubDirOrEqual = (parent, child) => {
54
- if (parent === child) {
55
- return true;
56
- }
57
- const relative = path.relative(parent, child);
58
- const isSubdir = relative && !relative.startsWith("..") && !path.isAbsolute(relative);
59
- return Boolean(isSubdir);
60
- };
61
- export {
62
- checkIsBuildCommands,
63
- getServerCombinedModueFile,
64
- isSubDirOrEqual,
65
- parseModule,
66
- replaceWithAlias,
67
- walkDirectory
68
- };
@@ -1,215 +0,0 @@
1
- import path from "node:path";
2
- import { fs as fse, pkgUp, semver } from "@modern-js/utils";
3
- import { readPackageJSON } from "pkg-types";
4
- import { parseNodeModulePath } from "mlly";
5
- import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
6
- import { nodeFileTrace } from "@vercel/nft";
7
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
8
- cacheDir: ".modern-js/deploy",
9
- analysisCache: true,
10
- fileCache: false,
11
- symlinkCache: false
12
- }, traceOptions }) => {
13
- const base = "/";
14
- const startTime = Date.now();
15
- const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
16
- console.time("traceFiles");
17
- const fileTrace = await traceFiles({
18
- entryFiles: entryFiles.concat(includeEntries),
19
- serverRootDir,
20
- cacheOptions: {
21
- ...cacheOptions,
22
- cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
23
- },
24
- base,
25
- traceOptions
26
- });
27
- console.timeEnd("traceFiles");
28
- const currentProjectModules = path.join(appDir, "node_modules");
29
- const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
30
- const tracedFiles = Object.fromEntries(await Promise.all([
31
- ...fileTrace.reasons.entries()
32
- ].map(async ([_path, reasons]) => {
33
- if (reasons.ignored) {
34
- return;
35
- }
36
- const filePath = await resolveTracedPath(base, _path);
37
- if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
38
- return;
39
- }
40
- if (!await isFile(filePath)) {
41
- return;
42
- }
43
- let baseDir;
44
- let pkgName;
45
- let subpath;
46
- let pkgPath;
47
- if (filePath.includes("node_modules")) {
48
- const parsed = parseNodeModulePath(filePath);
49
- baseDir = parsed.dir;
50
- pkgName = parsed.name;
51
- subpath = parsed.subpath;
52
- pkgPath = path.join(baseDir, pkgName);
53
- } else {
54
- const MODERN_UTILS_PATH = "packages/toolkit/utils";
55
- const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
56
- const match = filePath.match(MODERN_UTILS_PATH_REGEX);
57
- const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
58
- cwd: path.dirname(filePath)
59
- });
60
- if (packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)) {
61
- const packageJson = await fse.readJSON(packageJsonPath);
62
- pkgPath = baseDir = path.dirname(packageJsonPath);
63
- subpath = path.relative(baseDir, filePath);
64
- pkgName = packageJson.name;
65
- }
66
- }
67
- if (!baseDir) {
68
- return;
69
- }
70
- const parents = await Promise.all([
71
- ...reasons.parents
72
- ].map((p) => resolveTracedPath(base, p)));
73
- const tracedFile = {
74
- path: filePath,
75
- parents,
76
- isDirectDep: parents.some((parent) => {
77
- return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
78
- }),
79
- subpath,
80
- pkgName,
81
- pkgPath
82
- };
83
- return [
84
- filePath,
85
- tracedFile
86
- ];
87
- })).then((r) => r.filter(Boolean)));
88
- const tracedPackages = {};
89
- for (const tracedFile of Object.values(tracedFiles)) {
90
- const { pkgName } = tracedFile;
91
- let tracedPackage = tracedPackages[pkgName];
92
- let pkgJSON = await readPackageJSON(tracedFile.pkgPath, {
93
- cache: true
94
- }).catch(() => {
95
- });
96
- if (!pkgJSON) {
97
- pkgJSON = {
98
- name: pkgName,
99
- version: "0.0.0"
100
- };
101
- }
102
- if (!tracedPackage) {
103
- tracedPackage = {
104
- name: pkgName,
105
- versions: {}
106
- };
107
- tracedPackages[pkgName] = tracedPackage;
108
- }
109
- let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
110
- if (!tracedPackageVersion) {
111
- tracedPackageVersion = {
112
- path: tracedFile.pkgPath,
113
- files: [],
114
- isDirectDep: false,
115
- pkgJSON
116
- };
117
- if (tracedFile.isDirectDep) {
118
- tracedPackageVersion.isDirectDep = tracedFile.isDirectDep;
119
- }
120
- tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
121
- }
122
- tracedFile.pkgName = pkgName;
123
- tracedFile.pkgVersion = pkgJSON.version;
124
- const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
125
- if (tracedFile.path.startsWith(tracedFile.pkgPath) && // Merged package files are based on the version, not on paths, to handle some boundary cases
126
- tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion) {
127
- if (shouldCopyWholePackage) {
128
- const allFiles = await readDirRecursive(tracedFile.pkgPath);
129
- tracedPackageVersion.files.push(...allFiles);
130
- } else {
131
- tracedPackageVersion.files.push(tracedFile.path);
132
- }
133
- }
134
- }
135
- const multiVersionPkgs = {};
136
- const singleVersionPackages = [];
137
- for (const tracedPackage of Object.values(tracedPackages)) {
138
- const versions = Object.keys(tracedPackage.versions);
139
- if (versions.length === 1) {
140
- singleVersionPackages.push(tracedPackage.name);
141
- continue;
142
- }
143
- multiVersionPkgs[tracedPackage.name] = {};
144
- for (const version of versions) {
145
- multiVersionPkgs[tracedPackage.name][version] = findPackageParents(tracedPackage, version, tracedFiles);
146
- }
147
- }
148
- await Promise.all(singleVersionPackages.map((pkgName) => {
149
- const pkg = tracedPackages[pkgName];
150
- const version = Object.keys(pkg.versions)[0];
151
- return writePackage({
152
- pkg,
153
- version,
154
- projectDir: serverRootDir
155
- });
156
- }));
157
- const projectPkgJson = await readPackageJSON(serverRootDir).catch(() => ({}));
158
- for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
159
- const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
160
- var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
161
- const shouldHoist1 = (_tracedPackages_pkgName = tracedPackages[pkgName]) === null || _tracedPackages_pkgName === void 0 ? void 0 : (_tracedPackages_pkgName_versions = _tracedPackages_pkgName.versions) === null || _tracedPackages_pkgName_versions === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v1 = _tracedPackages_pkgName_versions[v1]) === null || _tracedPackages_pkgName_versions_v1 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v1.isDirectDep;
162
- const shouldHoist2 = (_tracedPackages_pkgName1 = tracedPackages[pkgName]) === null || _tracedPackages_pkgName1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions1 = _tracedPackages_pkgName1.versions) === null || _tracedPackages_pkgName_versions1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v2 = _tracedPackages_pkgName_versions1[v2]) === null || _tracedPackages_pkgName_versions_v2 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v2.isDirectDep;
163
- if (shouldHoist1 && !shouldHoist2) {
164
- return -1;
165
- }
166
- if (!shouldHoist1 && shouldHoist2) {
167
- return 1;
168
- }
169
- if (p1.length === 0) {
170
- return -1;
171
- }
172
- if (p2.length === 0) {
173
- return 1;
174
- }
175
- return semver.lt(v1, v2, {
176
- loose: true
177
- }) ? 1 : -1;
178
- });
179
- for (const [version, parentPkgs] of versionEntires) {
180
- const pkg = tracedPackages[pkgName];
181
- const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
182
- await writePackage({
183
- pkg,
184
- version,
185
- projectDir: serverRootDir,
186
- _pkgPath: pkgDestPath
187
- });
188
- await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
189
- for (const parentPkg of parentPkgs) {
190
- const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
191
- await (multiVersionPkgs[parentPkgName] ? linkPackage(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : linkPackage(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
192
- }
193
- }
194
- }
195
- const outputPkgPath = path.join(serverRootDir, "package.json");
196
- const newPkgJson = {
197
- name: `${projectPkgJson.name || "modernjs-project"}-prod`,
198
- version: projectPkgJson.version || "0.0.0",
199
- private: true,
200
- dependencies: Object.fromEntries([
201
- ...Object.values(tracedPackages).map((pkg) => [
202
- pkg.name,
203
- Object.keys(pkg.versions)[0]
204
- ])
205
- ].sort(([a], [b]) => a.localeCompare(b)))
206
- };
207
- const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
208
- await fse.writeJSON(outputPkgPath, finalPkgJson);
209
- const endTime = Date.now();
210
- console.log("handleDependencies cost:", `${endTime - startTime}ms`);
211
- };
212
- export {
213
- handleDependencies,
214
- nodeFileTrace
215
- };