@modern-js/app-tools 2.58.2 → 2.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
  2. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -3
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
  5. package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
  6. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  7. package/dist/cjs/commands/build.js +2 -2
  8. package/dist/cjs/commands/dev.js +6 -5
  9. package/dist/cjs/commands/index.js +1 -1
  10. package/dist/cjs/commands/serve.js +4 -3
  11. package/dist/cjs/config/legacy/index.js +3 -3
  12. package/dist/cjs/esm/register-esm.mjs +2 -3
  13. package/dist/cjs/esm/utils.mjs +2 -2
  14. package/dist/cjs/index.js +17 -10
  15. package/dist/cjs/locale/index.js +1 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
  17. package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
  18. package/dist/cjs/plugins/analyze/index.js +6 -6
  19. package/dist/cjs/plugins/analyze/utils.js +1 -1
  20. package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
  21. package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
  22. package/dist/cjs/plugins/deploy/index.js +2 -2
  23. package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
  24. package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
  25. package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
  26. package/dist/cjs/plugins/serverBuild.js +2 -2
  27. package/dist/cjs/utils/createServer.js +1 -1
  28. package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
  29. package/dist/esm/builder/builder-rspack/index.js +34 -0
  30. package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
  31. package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
  32. package/dist/esm/builder/builder-webpack/index.js +52 -0
  33. package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
  34. package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
  35. package/dist/esm/builder/generator/index.js +93 -0
  36. package/dist/esm/builder/index.js +45 -0
  37. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
  38. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
  39. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
  40. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  41. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
  42. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
  43. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
  44. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  45. package/dist/esm/builder/shared/createCopyInfo.js +14 -0
  46. package/dist/esm/builder/shared/index.js +3 -0
  47. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
  48. package/dist/esm/builder/shared/types.js +0 -0
  49. package/dist/esm/commands/build.js +140 -0
  50. package/dist/esm/commands/deploy.js +48 -0
  51. package/dist/esm/commands/dev.js +193 -0
  52. package/dist/esm/commands/index.js +411 -0
  53. package/dist/esm/commands/inspect.js +28 -0
  54. package/dist/esm/commands/serve.js +94 -0
  55. package/dist/esm/config/default.js +190 -0
  56. package/dist/esm/config/index.js +3 -0
  57. package/dist/esm/config/initialize/index.js +9 -0
  58. package/dist/esm/config/initialize/inits.js +89 -0
  59. package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
  60. package/dist/esm/config/legacy/createOutputConfig.js +45 -0
  61. package/dist/esm/config/legacy/createSourceConfig.js +46 -0
  62. package/dist/esm/config/legacy/createToolsConfig.js +28 -0
  63. package/dist/esm/config/legacy/index.js +43 -0
  64. package/dist/esm/defineConfig.js +16 -0
  65. package/dist/esm/esm/esbuild-loader.mjs +20 -0
  66. package/dist/esm/esm/register-esm.mjs +66 -0
  67. package/dist/esm/esm/ts-node-loader.mjs +21 -0
  68. package/dist/esm/esm/utils.mjs +43 -0
  69. package/dist/esm/exports/server.js +4 -0
  70. package/dist/esm/hooks.js +34 -0
  71. package/dist/esm/index.js +246 -0
  72. package/dist/esm/locale/en.js +43 -0
  73. package/dist/esm/locale/index.js +12 -0
  74. package/dist/esm/locale/zh.js +43 -0
  75. package/dist/esm/plugins/analyze/constants.js +14 -0
  76. package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
  77. package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
  78. package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
  79. package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
  80. package/dist/esm/plugins/analyze/index.js +380 -0
  81. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
  82. package/dist/esm/plugins/analyze/templates.js +6 -0
  83. package/dist/esm/plugins/analyze/utils.js +101 -0
  84. package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
  85. package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
  86. package/dist/esm/plugins/deploy/exports.js +4 -0
  87. package/dist/esm/plugins/deploy/index.js +135 -0
  88. package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
  89. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  90. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
  91. package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
  92. package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
  93. package/dist/esm/plugins/deploy/platforms/node.js +161 -0
  94. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  95. package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
  96. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  97. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
  98. package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
  99. package/dist/esm/plugins/deploy/utils.js +47 -0
  100. package/dist/esm/plugins/initialize/index.js +119 -0
  101. package/dist/esm/plugins/serverBuild.js +87 -0
  102. package/dist/esm/types/config/deploy.js +0 -0
  103. package/dist/esm/types/config/dev.js +0 -0
  104. package/dist/esm/types/config/experiments.js +0 -0
  105. package/dist/esm/types/config/html.js +0 -0
  106. package/dist/esm/types/config/index.js +1 -0
  107. package/dist/esm/types/config/output.js +0 -0
  108. package/dist/esm/types/config/performance.js +0 -0
  109. package/dist/esm/types/config/security.js +0 -0
  110. package/dist/esm/types/config/source.js +0 -0
  111. package/dist/esm/types/config/testing.js +0 -0
  112. package/dist/esm/types/config/tools.js +0 -0
  113. package/dist/esm/types/hooks.js +0 -0
  114. package/dist/esm/types/index.js +3 -0
  115. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  116. package/dist/esm/types/legacyConfig/dev.js +0 -0
  117. package/dist/esm/types/legacyConfig/index.js +0 -0
  118. package/dist/esm/types/legacyConfig/output.js +0 -0
  119. package/dist/esm/types/legacyConfig/source.js +0 -0
  120. package/dist/esm/types/legacyConfig/testing.js +0 -0
  121. package/dist/esm/types/legacyConfig/tools.js +0 -0
  122. package/dist/esm/types/utils.js +0 -0
  123. package/dist/esm/utils/config.js +122 -0
  124. package/dist/esm/utils/createServer.js +58 -0
  125. package/dist/esm/utils/env.js +16 -0
  126. package/dist/esm/utils/generateWatchFiles.js +71 -0
  127. package/dist/esm/utils/getSelectedEntries.js +67 -0
  128. package/dist/esm/utils/loadPlugins.js +74 -0
  129. package/dist/esm/utils/printInstructions.js +32 -0
  130. package/dist/esm/utils/register.js +188 -0
  131. package/dist/esm/utils/restart.js +67 -0
  132. package/dist/esm/utils/routes.js +42 -0
  133. package/dist/esm/utils/types.js +0 -0
  134. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
  135. package/dist/esm-node/builder/builder-rspack/index.js +12 -0
  136. package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
  137. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
  138. package/dist/esm-node/builder/builder-webpack/index.js +20 -0
  139. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
  140. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  141. package/dist/esm-node/builder/generator/index.js +36 -0
  142. package/dist/esm-node/builder/index.js +11 -0
  143. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
  144. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
  145. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
  146. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  147. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
  148. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
  149. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
  150. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  151. package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
  152. package/dist/esm-node/builder/shared/index.js +3 -0
  153. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
  154. package/dist/esm-node/builder/shared/types.js +0 -0
  155. package/dist/esm-node/commands/build.js +64 -0
  156. package/dist/esm-node/commands/deploy.js +12 -0
  157. package/dist/esm-node/commands/dev.js +105 -0
  158. package/dist/esm-node/commands/index.js +92 -0
  159. package/dist/esm-node/commands/inspect.js +15 -0
  160. package/dist/esm-node/commands/serve.js +52 -0
  161. package/dist/esm-node/config/default.js +197 -0
  162. package/dist/esm-node/config/index.js +3 -0
  163. package/dist/esm-node/config/initialize/index.js +9 -0
  164. package/dist/esm-node/config/initialize/inits.js +79 -0
  165. package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
  166. package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
  167. package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
  168. package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
  169. package/dist/esm-node/config/legacy/index.js +43 -0
  170. package/dist/esm-node/defineConfig.js +13 -0
  171. package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
  172. package/dist/esm-node/esm/register-esm.mjs +66 -0
  173. package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
  174. package/dist/esm-node/esm/utils.mjs +43 -0
  175. package/dist/esm-node/exports/server.js +4 -0
  176. package/dist/esm-node/hooks.js +34 -0
  177. package/dist/esm-node/index.js +131 -0
  178. package/dist/esm-node/locale/en.js +43 -0
  179. package/dist/esm-node/locale/index.js +12 -0
  180. package/dist/esm-node/locale/zh.js +43 -0
  181. package/dist/esm-node/plugins/analyze/constants.js +14 -0
  182. package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
  183. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
  184. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
  185. package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
  186. package/dist/esm-node/plugins/analyze/index.js +166 -0
  187. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
  188. package/dist/esm-node/plugins/analyze/templates.js +24 -0
  189. package/dist/esm-node/plugins/analyze/utils.js +68 -0
  190. package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
  191. package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
  192. package/dist/esm-node/plugins/deploy/exports.js +4 -0
  193. package/dist/esm-node/plugins/deploy/index.js +44 -0
  194. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
  195. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  196. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
  197. package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
  198. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
  199. package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
  200. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  201. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
  202. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  203. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
  204. package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
  205. package/dist/esm-node/plugins/deploy/utils.js +44 -0
  206. package/dist/esm-node/plugins/initialize/index.js +84 -0
  207. package/dist/esm-node/plugins/serverBuild.js +58 -0
  208. package/dist/esm-node/types/config/deploy.js +0 -0
  209. package/dist/esm-node/types/config/dev.js +0 -0
  210. package/dist/esm-node/types/config/experiments.js +0 -0
  211. package/dist/esm-node/types/config/html.js +0 -0
  212. package/dist/esm-node/types/config/index.js +1 -0
  213. package/dist/esm-node/types/config/output.js +0 -0
  214. package/dist/esm-node/types/config/performance.js +0 -0
  215. package/dist/esm-node/types/config/security.js +0 -0
  216. package/dist/esm-node/types/config/source.js +0 -0
  217. package/dist/esm-node/types/config/testing.js +0 -0
  218. package/dist/esm-node/types/config/tools.js +0 -0
  219. package/dist/esm-node/types/hooks.js +0 -0
  220. package/dist/esm-node/types/index.js +3 -0
  221. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  222. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  223. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  224. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  225. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  226. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  227. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  228. package/dist/esm-node/types/utils.js +0 -0
  229. package/dist/esm-node/utils/config.js +49 -0
  230. package/dist/esm-node/utils/createServer.js +26 -0
  231. package/dist/esm-node/utils/env.js +16 -0
  232. package/dist/esm-node/utils/generateWatchFiles.js +30 -0
  233. package/dist/esm-node/utils/getSelectedEntries.js +34 -0
  234. package/dist/esm-node/utils/loadPlugins.js +22 -0
  235. package/dist/esm-node/utils/printInstructions.js +11 -0
  236. package/dist/esm-node/utils/register.js +96 -0
  237. package/dist/esm-node/utils/restart.js +22 -0
  238. package/dist/esm-node/utils/routes.js +21 -0
  239. package/dist/esm-node/utils/types.js +0 -0
  240. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
  241. package/dist/types/builder/generator/index.d.ts +2 -2
  242. package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
  243. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
  244. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
  245. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  246. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
  247. package/dist/types/builder/shared/types.d.ts +1 -1
  248. package/dist/types/commands/build.d.ts +1 -1
  249. package/dist/types/commands/dev.d.ts +1 -1
  250. package/dist/types/commands/inspect.d.ts +1 -1
  251. package/dist/types/config/default.d.ts +1 -1
  252. package/dist/types/index.d.ts +1 -1
  253. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  254. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  255. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
  256. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
  257. package/dist/types/plugins/initialize/index.d.ts +1 -1
  258. package/dist/types/plugins/serverBuild.d.ts +1 -1
  259. package/dist/types/types/config/index.d.ts +8 -8
  260. package/dist/types/types/config/output.d.ts +1 -1
  261. package/dist/types/types/config/tools.d.ts +3 -3
  262. package/dist/types/types/hooks.d.ts +2 -2
  263. package/dist/types/types/index.d.ts +2 -2
  264. package/dist/types/types/legacyConfig/index.d.ts +3 -3
  265. package/dist/types/types/legacyConfig/tools.d.ts +1 -1
  266. package/dist/types/utils/printInstructions.d.ts +1 -1
  267. package/package.json +20 -20
  268. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
  269. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -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 { createRequire } from 'module';
2
+ import path from 'path';
3
+ import { getAliasConfig } from '@modern-js/utils';
4
+ import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
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
+ }
@@ -0,0 +1,4 @@
1
+ import { defineServerConfig } from "../utils/config";
2
+ export {
3
+ defineServerConfig as defineConfig
4
+ };
@@ -0,0 +1,34 @@
1
+ import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
+ var hooks = {
3
+ _internalRuntimePlugins: createAsyncWaterfall(),
4
+ modifyFileSystemRoutes: createAsyncWaterfall(),
5
+ modifyServerRoutes: createAsyncWaterfall(),
6
+ /** add entry point info to entrypoints array */
7
+ modifyEntrypoints: createAsyncWaterfall(),
8
+ /** add entry type */
9
+ checkEntryPoint: createAsyncWaterfall(),
10
+ generateEntryCode: createAsyncWorkflow(),
11
+ htmlPartials: createAsyncWaterfall(),
12
+ beforeGenerateRoutes: createAsyncWaterfall(),
13
+ addDefineTypes: createAsyncWaterfall(),
14
+ collectServerPlugins: createAsyncWaterfall(),
15
+ _internalServerPlugins: createAsyncWaterfall(),
16
+ beforeDev: createAsyncWorkflow(),
17
+ afterDev: createAsyncWorkflow(),
18
+ beforeCreateCompiler: createAsyncWorkflow(),
19
+ afterCreateCompiler: createAsyncWorkflow(),
20
+ beforePrintInstructions: createAsyncWaterfall(),
21
+ beforeBuild: createAsyncWorkflow(),
22
+ afterBuild: createAsyncWorkflow(),
23
+ beforeDeploy: createAsyncWorkflow(),
24
+ deploy: createAsyncWorkflow(),
25
+ afterDeploy: createAsyncWorkflow(),
26
+ beforeRestart: createAsyncWorkflow(),
27
+ registerDev: createParallelWorkflow(),
28
+ beforeDevTask: createParallelWorkflow(),
29
+ registerBuildPlatform: createParallelWorkflow(),
30
+ beforeBuildPlatform: createParallelWorkflow()
31
+ };
32
+ export {
33
+ hooks
34
+ };
@@ -0,0 +1,246 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import path from "path";
6
+ import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
7
+ import { lintPlugin } from "@modern-js/plugin-lint";
8
+ import { cleanRequireCache, emptyDir, getArgv, getCommand } from "@modern-js/utils";
9
+ import { hooks } from "./hooks";
10
+ import { i18n } from "./locale";
11
+ import analyzePlugin from "./plugins/analyze";
12
+ import deployPlugin from "./plugins/deploy";
13
+ import initializePlugin from "./plugins/initialize";
14
+ import serverBuildPlugin from "./plugins/serverBuild";
15
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
16
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
17
+ import { restart } from "./utils/restart";
18
+ import { dev } from "./commands/dev";
19
+ import { mergeConfig } from "@modern-js/core";
20
+ export * from "./defineConfig";
21
+ export * from "./types";
22
+ var appTools = function() {
23
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
24
+ // default webpack to be compatible with original projects
25
+ bundler: "webpack"
26
+ };
27
+ return {
28
+ name: "@modern-js/app-tools",
29
+ post: [
30
+ "@modern-js/plugin-initialize",
31
+ "@modern-js/plugin-analyze",
32
+ "@modern-js/plugin-ssr",
33
+ "@modern-js/plugin-document",
34
+ "@modern-js/plugin-state",
35
+ "@modern-js/plugin-router",
36
+ "@modern-js/plugin-router-v5",
37
+ "@modern-js/plugin-polyfill"
38
+ ],
39
+ registerHook: hooks,
40
+ usePlugins: [
41
+ initializePlugin({
42
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
43
+ "rspack",
44
+ "experimental-rspack"
45
+ ].includes(options.bundler) ? "rspack" : "webpack"
46
+ }),
47
+ analyzePlugin({
48
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
49
+ "rspack",
50
+ "experimental-rspack"
51
+ ].includes(options.bundler) ? "rspack" : "webpack"
52
+ }),
53
+ serverBuildPlugin(),
54
+ lintPlugin(),
55
+ deployPlugin()
56
+ ],
57
+ setup: function(api) {
58
+ var appContext = api.useAppContext();
59
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
60
+ toolsType: "app-tools"
61
+ }));
62
+ var locale = getLocaleLanguage();
63
+ i18n.changeLanguage({
64
+ locale
65
+ });
66
+ return {
67
+ beforeConfig: function beforeConfig() {
68
+ return _async_to_generator(function() {
69
+ var _userConfig_output, userConfig, appContext2;
70
+ return _ts_generator(this, function(_state) {
71
+ userConfig = api.useConfigContext();
72
+ appContext2 = api.useAppContext();
73
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
74
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
75
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
76
+ }));
77
+ }
78
+ return [
79
+ 2
80
+ ];
81
+ });
82
+ })();
83
+ },
84
+ commands: function commands(param) {
85
+ var program = param.program;
86
+ return _async_to_generator(function() {
87
+ return _ts_generator(this, function(_state) {
88
+ switch (_state.label) {
89
+ case 0:
90
+ return [
91
+ 4,
92
+ devCommand(program, api)
93
+ ];
94
+ case 1:
95
+ _state.sent();
96
+ return [
97
+ 4,
98
+ buildCommand(program, api)
99
+ ];
100
+ case 2:
101
+ _state.sent();
102
+ serverCommand(program, api);
103
+ deployCommand(program, api);
104
+ newCommand(program, locale);
105
+ inspectCommand(program, api);
106
+ upgradeCommand(program);
107
+ return [
108
+ 2
109
+ ];
110
+ }
111
+ });
112
+ })();
113
+ },
114
+ prepare: function prepare() {
115
+ return _async_to_generator(function() {
116
+ var command, isSkipBuild, resolvedConfig, appContext2;
117
+ return _ts_generator(this, function(_state) {
118
+ switch (_state.label) {
119
+ case 0:
120
+ command = getCommand();
121
+ if (command === "deploy") {
122
+ isSkipBuild = [
123
+ "-s",
124
+ "--skip-build"
125
+ ].some(function(tag) {
126
+ return getArgv().includes(tag);
127
+ });
128
+ if (isSkipBuild) {
129
+ return [
130
+ 2
131
+ ];
132
+ }
133
+ }
134
+ if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
135
+ return [
136
+ 3,
137
+ 2
138
+ ];
139
+ resolvedConfig = api.useResolvedConfigContext();
140
+ if (!resolvedConfig.output.cleanDistPath)
141
+ return [
142
+ 3,
143
+ 2
144
+ ];
145
+ appContext2 = api.useAppContext();
146
+ return [
147
+ 4,
148
+ emptyDir(appContext2.distDirectory)
149
+ ];
150
+ case 1:
151
+ _state.sent();
152
+ _state.label = 2;
153
+ case 2:
154
+ return [
155
+ 2
156
+ ];
157
+ }
158
+ });
159
+ })();
160
+ },
161
+ watchFiles: function watchFiles() {
162
+ return _async_to_generator(function() {
163
+ var appContext2, config;
164
+ return _ts_generator(this, function(_state) {
165
+ switch (_state.label) {
166
+ case 0:
167
+ appContext2 = api.useAppContext();
168
+ config = api.useResolvedConfigContext();
169
+ return [
170
+ 4,
171
+ generateWatchFiles(appContext2, config.source.configDir)
172
+ ];
173
+ case 1:
174
+ return [
175
+ 2,
176
+ _state.sent()
177
+ ];
178
+ }
179
+ });
180
+ })();
181
+ },
182
+ fileChange: (
183
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
184
+ function fileChange(e) {
185
+ return _async_to_generator(function() {
186
+ var filename, eventType, isPrivate, closeServer;
187
+ return _ts_generator(this, function(_state) {
188
+ switch (_state.label) {
189
+ case 0:
190
+ filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
191
+ if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
192
+ return [
193
+ 3,
194
+ 4
195
+ ];
196
+ return [
197
+ 4,
198
+ import("./utils/createServer.js")
199
+ ];
200
+ case 1:
201
+ closeServer = _state.sent().closeServer;
202
+ return [
203
+ 4,
204
+ closeServer()
205
+ ];
206
+ case 2:
207
+ _state.sent();
208
+ return [
209
+ 4,
210
+ restart(api.useHookRunners(), filename)
211
+ ];
212
+ case 3:
213
+ _state.sent();
214
+ _state.label = 4;
215
+ case 4:
216
+ return [
217
+ 2
218
+ ];
219
+ }
220
+ });
221
+ })();
222
+ }
223
+ ),
224
+ beforeRestart: function beforeRestart() {
225
+ return _async_to_generator(function() {
226
+ return _ts_generator(this, function(_state) {
227
+ cleanRequireCache([
228
+ require.resolve("./plugins/analyze")
229
+ ]);
230
+ return [
231
+ 2
232
+ ];
233
+ });
234
+ })();
235
+ }
236
+ };
237
+ }
238
+ };
239
+ };
240
+ var src_default = appTools;
241
+ export {
242
+ appTools,
243
+ src_default as default,
244
+ dev,
245
+ mergeConfig
246
+ };
@@ -0,0 +1,43 @@
1
+ var EN_LOCALE = {
2
+ command: {
3
+ shared: {
4
+ analyze: "analyze bundle size",
5
+ config: "specify the configuration file, which can be a relative or absolute path",
6
+ skipBuild: "skip the build phase",
7
+ noNeedInstall: "not run install command"
8
+ },
9
+ dev: {
10
+ describe: "starting the dev server",
11
+ entry: "compiler by entry",
12
+ apiOnly: "start api server only",
13
+ webOnly: "start web server only",
14
+ selectEntry: "Please select the entry that needs to be built",
15
+ requireEntry: "You must choose at least one entry"
16
+ },
17
+ build: {
18
+ describe: "build the app for production"
19
+ },
20
+ serve: {
21
+ describe: "preview the production build locally"
22
+ },
23
+ deploy: {
24
+ describe: "deploy the application"
25
+ },
26
+ new: {
27
+ describe: "enable optional features or add a new entry",
28
+ debug: "using debug mode to log something",
29
+ config: "set default generator config(json string)",
30
+ distTag: "use specified tag version for it's generator",
31
+ registry: "set npm registry url to run npm command",
32
+ lang: "set new command language(en or zh)"
33
+ },
34
+ inspect: {
35
+ env: "specify env mode",
36
+ output: "specify inspect content output path",
37
+ verbose: "show full function definitions in output"
38
+ }
39
+ }
40
+ };
41
+ export {
42
+ EN_LOCALE
43
+ };
@@ -0,0 +1,12 @@
1
+ import { I18n } from "@modern-js/plugin-i18n";
2
+ import { EN_LOCALE } from "./en";
3
+ import { ZH_LOCALE } from "./zh";
4
+ var i18n = new I18n();
5
+ var localeKeys = i18n.init("en", {
6
+ zh: ZH_LOCALE,
7
+ en: EN_LOCALE
8
+ });
9
+ export {
10
+ i18n,
11
+ localeKeys
12
+ };
@@ -0,0 +1,43 @@
1
+ var ZH_LOCALE = {
2
+ command: {
3
+ shared: {
4
+ analyze: "分析构建产物体积,查看各个模块打包后的大小",
5
+ config: "指定配置文件路径,可以为相对路径或绝对路径",
6
+ skipBuild: "跳过构建阶段",
7
+ noNeedInstall: "无需安装依赖"
8
+ },
9
+ dev: {
10
+ describe: "启动开发服务器",
11
+ entry: "指定入口,编译特定的页面",
12
+ apiOnly: "仅启动 API 接口服务",
13
+ webOnly: "仅启动 Web 服务",
14
+ selectEntry: "请选择需要构建的入口",
15
+ requireEntry: "请至少选择一个入口"
16
+ },
17
+ build: {
18
+ describe: "构建生产环境产物"
19
+ },
20
+ serve: {
21
+ describe: "启动生产环境服务"
22
+ },
23
+ deploy: {
24
+ describe: "部署应用"
25
+ },
26
+ new: {
27
+ describe: "Web App 项目中执行生成器",
28
+ debug: "开启 Debug 模式,打印调试日志信息",
29
+ config: "生成器运行默认配置(JSON 字符串)",
30
+ distTag: "生成器使用特殊的 npm Tag 版本",
31
+ registry: "生成器运行过程中定制 npm Registry",
32
+ lang: "设置 new 命令执行语言(zh 或者 en)"
33
+ },
34
+ inspect: {
35
+ env: "查看指定环境下的配置",
36
+ output: "指定在 dist 目录下输出的路径",
37
+ verbose: "在结果中展示函数的完整内容"
38
+ }
39
+ }
40
+ };
41
+ export {
42
+ ZH_LOCALE
43
+ };
@@ -0,0 +1,14 @@
1
+ var INDEX_FILE_NAME = "index";
2
+ var ENTRY_FILE_NAME = "entry";
3
+ var HTML_PARTIALS_FOLDER = "html";
4
+ var HTML_PARTIALS_EXTENSIONS = [
5
+ ".htm",
6
+ ".html",
7
+ ".ejs"
8
+ ];
9
+ export {
10
+ ENTRY_FILE_NAME,
11
+ HTML_PARTIALS_EXTENSIONS,
12
+ HTML_PARTIALS_FOLDER,
13
+ INDEX_FILE_NAME
14
+ };
@@ -0,0 +1,102 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import path from "path";
4
+ import { fs, JS_EXTENSIONS, MAIN_ENTRY_NAME, ensureAbsolutePath, findExists } from "@modern-js/utils";
5
+ import { getFileSystemEntry } from "./getFileSystemEntry";
6
+ import { isSubDirOrEqual } from "./utils";
7
+ var ensureExtensions = function(file) {
8
+ if (!path.extname(file)) {
9
+ return findExists(JS_EXTENSIONS.map(function(ext) {
10
+ return "".concat(file).concat(ext);
11
+ })) || file;
12
+ }
13
+ return file;
14
+ };
15
+ var isDirectory = function(file) {
16
+ return !path.extname(file);
17
+ };
18
+ var ifAlreadyExists = function(entrypoints, checked) {
19
+ return entrypoints.some(function(entrypoint) {
20
+ if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
21
+ checked.entryName = entrypoint.entryName;
22
+ return true;
23
+ }
24
+ if (isSubDirOrEqual(entrypoint.entry, checked.entry) || isSubDirOrEqual(checked.entry, entrypoint.entry)) {
25
+ throw new Error("Entry configuration conflicts\n Your configuration: ".concat(checked.entry, ".\n Default entrypoint: ").concat(entrypoint.entry, "\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules."));
26
+ }
27
+ return false;
28
+ });
29
+ };
30
+ var getBundleEntry = function() {
31
+ var _ref = _async_to_generator(function(hookRunners, appContext, config) {
32
+ var appDirectory, packageName, _config_source, disableDefaultEntries, entries, entriesDir, mainEntryName, defaults, _tmp, entriesDirAbs, found;
33
+ return _ts_generator(this, function(_state) {
34
+ switch (_state.label) {
35
+ case 0:
36
+ appDirectory = appContext.appDirectory, packageName = appContext.packageName;
37
+ _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir, mainEntryName = _config_source.mainEntryName;
38
+ if (!disableDefaultEntries)
39
+ return [
40
+ 3,
41
+ 1
42
+ ];
43
+ _tmp = [];
44
+ return [
45
+ 3,
46
+ 3
47
+ ];
48
+ case 1:
49
+ return [
50
+ 4,
51
+ getFileSystemEntry(hookRunners, appContext, config)
52
+ ];
53
+ case 2:
54
+ _tmp = _state.sent();
55
+ _state.label = 3;
56
+ case 3:
57
+ defaults = _tmp;
58
+ if (entries) {
59
+ Object.keys(entries).forEach(function(name) {
60
+ var value = entries[name];
61
+ var entryName = typeof value === "string" ? value : value.entry;
62
+ var isAutoMount = typeof value === "string" ? true : !value.disableMount;
63
+ var entrypoint = {
64
+ entryName: name,
65
+ isMainEntry: false,
66
+ entry: ensureAbsolutePath(appDirectory, entryName),
67
+ absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
68
+ isAutoMount,
69
+ customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
70
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0,
71
+ isCustomSourceEntry: true
72
+ };
73
+ if (!ifAlreadyExists(defaults, entrypoint)) {
74
+ defaults.push(entrypoint);
75
+ }
76
+ });
77
+ }
78
+ if (!disableDefaultEntries) {
79
+ entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
80
+ found = defaults.find(function(param) {
81
+ var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
82
+ return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
83
+ });
84
+ if (found) {
85
+ found.entryName = mainEntryName || MAIN_ENTRY_NAME;
86
+ found.isMainEntry = true;
87
+ }
88
+ }
89
+ return [
90
+ 2,
91
+ defaults
92
+ ];
93
+ }
94
+ });
95
+ });
96
+ return function getBundleEntry2(hookRunners, appContext, config) {
97
+ return _ref.apply(this, arguments);
98
+ };
99
+ }();
100
+ export {
101
+ getBundleEntry
102
+ };