@modern-js/app-tools 2.58.3 → 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 (222) hide show
  1. package/dist/cjs/builder/generator/index.js +2 -3
  2. package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
  3. package/dist/cjs/commands/dev.js +1 -1
  4. package/dist/cjs/index.js +10 -3
  5. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
  6. package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
  7. package/dist/esm/builder/builder-rspack/index.js +34 -0
  8. package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
  9. package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
  10. package/dist/esm/builder/builder-webpack/index.js +52 -0
  11. package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
  12. package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
  13. package/dist/esm/builder/generator/index.js +93 -0
  14. package/dist/esm/builder/index.js +45 -0
  15. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
  16. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
  17. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
  18. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  19. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
  20. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
  21. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
  22. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  23. package/dist/esm/builder/shared/createCopyInfo.js +14 -0
  24. package/dist/esm/builder/shared/index.js +3 -0
  25. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
  26. package/dist/esm/builder/shared/types.js +0 -0
  27. package/dist/esm/commands/build.js +140 -0
  28. package/dist/esm/commands/deploy.js +48 -0
  29. package/dist/esm/commands/dev.js +193 -0
  30. package/dist/esm/commands/index.js +411 -0
  31. package/dist/esm/commands/inspect.js +28 -0
  32. package/dist/esm/commands/serve.js +94 -0
  33. package/dist/esm/config/default.js +190 -0
  34. package/dist/esm/config/index.js +3 -0
  35. package/dist/esm/config/initialize/index.js +9 -0
  36. package/dist/esm/config/initialize/inits.js +89 -0
  37. package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
  38. package/dist/esm/config/legacy/createOutputConfig.js +45 -0
  39. package/dist/esm/config/legacy/createSourceConfig.js +46 -0
  40. package/dist/esm/config/legacy/createToolsConfig.js +28 -0
  41. package/dist/esm/config/legacy/index.js +43 -0
  42. package/dist/esm/defineConfig.js +16 -0
  43. package/dist/esm/esm/esbuild-loader.mjs +20 -0
  44. package/dist/esm/esm/register-esm.mjs +66 -0
  45. package/dist/esm/esm/ts-node-loader.mjs +21 -0
  46. package/dist/esm/esm/utils.mjs +43 -0
  47. package/dist/esm/exports/server.js +4 -0
  48. package/dist/esm/hooks.js +34 -0
  49. package/dist/esm/index.js +246 -0
  50. package/dist/esm/locale/en.js +43 -0
  51. package/dist/esm/locale/index.js +12 -0
  52. package/dist/esm/locale/zh.js +43 -0
  53. package/dist/esm/plugins/analyze/constants.js +14 -0
  54. package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
  55. package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
  56. package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
  57. package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
  58. package/dist/esm/plugins/analyze/index.js +380 -0
  59. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
  60. package/dist/esm/plugins/analyze/templates.js +6 -0
  61. package/dist/esm/plugins/analyze/utils.js +101 -0
  62. package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
  63. package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
  64. package/dist/esm/plugins/deploy/exports.js +4 -0
  65. package/dist/esm/plugins/deploy/index.js +135 -0
  66. package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
  67. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  68. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
  69. package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
  70. package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
  71. package/dist/esm/plugins/deploy/platforms/node.js +161 -0
  72. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  73. package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
  74. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  75. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
  76. package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
  77. package/dist/esm/plugins/deploy/utils.js +47 -0
  78. package/dist/esm/plugins/initialize/index.js +119 -0
  79. package/dist/esm/plugins/serverBuild.js +87 -0
  80. package/dist/esm/types/config/deploy.js +0 -0
  81. package/dist/esm/types/config/dev.js +0 -0
  82. package/dist/esm/types/config/experiments.js +0 -0
  83. package/dist/esm/types/config/html.js +0 -0
  84. package/dist/esm/types/config/index.js +1 -0
  85. package/dist/esm/types/config/output.js +0 -0
  86. package/dist/esm/types/config/performance.js +0 -0
  87. package/dist/esm/types/config/security.js +0 -0
  88. package/dist/esm/types/config/source.js +0 -0
  89. package/dist/esm/types/config/testing.js +0 -0
  90. package/dist/esm/types/config/tools.js +0 -0
  91. package/dist/esm/types/hooks.js +0 -0
  92. package/dist/esm/types/index.js +3 -0
  93. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  94. package/dist/esm/types/legacyConfig/dev.js +0 -0
  95. package/dist/esm/types/legacyConfig/index.js +0 -0
  96. package/dist/esm/types/legacyConfig/output.js +0 -0
  97. package/dist/esm/types/legacyConfig/source.js +0 -0
  98. package/dist/esm/types/legacyConfig/testing.js +0 -0
  99. package/dist/esm/types/legacyConfig/tools.js +0 -0
  100. package/dist/esm/types/utils.js +0 -0
  101. package/dist/esm/utils/config.js +122 -0
  102. package/dist/esm/utils/createServer.js +58 -0
  103. package/dist/esm/utils/env.js +16 -0
  104. package/dist/esm/utils/generateWatchFiles.js +71 -0
  105. package/dist/esm/utils/getSelectedEntries.js +67 -0
  106. package/dist/esm/utils/loadPlugins.js +74 -0
  107. package/dist/esm/utils/printInstructions.js +32 -0
  108. package/dist/esm/utils/register.js +188 -0
  109. package/dist/esm/utils/restart.js +67 -0
  110. package/dist/esm/utils/routes.js +42 -0
  111. package/dist/esm/utils/types.js +0 -0
  112. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
  113. package/dist/esm-node/builder/builder-rspack/index.js +12 -0
  114. package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
  115. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
  116. package/dist/esm-node/builder/builder-webpack/index.js +20 -0
  117. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
  118. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  119. package/dist/esm-node/builder/generator/index.js +36 -0
  120. package/dist/esm-node/builder/index.js +11 -0
  121. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
  122. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
  123. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
  124. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  125. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
  126. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
  127. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
  128. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  129. package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
  130. package/dist/esm-node/builder/shared/index.js +3 -0
  131. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
  132. package/dist/esm-node/builder/shared/types.js +0 -0
  133. package/dist/esm-node/commands/build.js +64 -0
  134. package/dist/esm-node/commands/deploy.js +12 -0
  135. package/dist/esm-node/commands/dev.js +105 -0
  136. package/dist/esm-node/commands/index.js +92 -0
  137. package/dist/esm-node/commands/inspect.js +15 -0
  138. package/dist/esm-node/commands/serve.js +52 -0
  139. package/dist/esm-node/config/default.js +197 -0
  140. package/dist/esm-node/config/index.js +3 -0
  141. package/dist/esm-node/config/initialize/index.js +9 -0
  142. package/dist/esm-node/config/initialize/inits.js +79 -0
  143. package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
  144. package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
  145. package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
  146. package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
  147. package/dist/esm-node/config/legacy/index.js +43 -0
  148. package/dist/esm-node/defineConfig.js +13 -0
  149. package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
  150. package/dist/esm-node/esm/register-esm.mjs +66 -0
  151. package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
  152. package/dist/esm-node/esm/utils.mjs +43 -0
  153. package/dist/esm-node/exports/server.js +4 -0
  154. package/dist/esm-node/hooks.js +34 -0
  155. package/dist/esm-node/index.js +131 -0
  156. package/dist/esm-node/locale/en.js +43 -0
  157. package/dist/esm-node/locale/index.js +12 -0
  158. package/dist/esm-node/locale/zh.js +43 -0
  159. package/dist/esm-node/plugins/analyze/constants.js +14 -0
  160. package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
  161. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
  162. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
  163. package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
  164. package/dist/esm-node/plugins/analyze/index.js +166 -0
  165. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
  166. package/dist/esm-node/plugins/analyze/templates.js +24 -0
  167. package/dist/esm-node/plugins/analyze/utils.js +68 -0
  168. package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
  169. package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
  170. package/dist/esm-node/plugins/deploy/exports.js +4 -0
  171. package/dist/esm-node/plugins/deploy/index.js +44 -0
  172. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
  173. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  174. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
  175. package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
  176. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
  177. package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
  178. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  179. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
  180. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  181. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
  182. package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
  183. package/dist/esm-node/plugins/deploy/utils.js +44 -0
  184. package/dist/esm-node/plugins/initialize/index.js +84 -0
  185. package/dist/esm-node/plugins/serverBuild.js +58 -0
  186. package/dist/esm-node/types/config/deploy.js +0 -0
  187. package/dist/esm-node/types/config/dev.js +0 -0
  188. package/dist/esm-node/types/config/experiments.js +0 -0
  189. package/dist/esm-node/types/config/html.js +0 -0
  190. package/dist/esm-node/types/config/index.js +1 -0
  191. package/dist/esm-node/types/config/output.js +0 -0
  192. package/dist/esm-node/types/config/performance.js +0 -0
  193. package/dist/esm-node/types/config/security.js +0 -0
  194. package/dist/esm-node/types/config/source.js +0 -0
  195. package/dist/esm-node/types/config/testing.js +0 -0
  196. package/dist/esm-node/types/config/tools.js +0 -0
  197. package/dist/esm-node/types/hooks.js +0 -0
  198. package/dist/esm-node/types/index.js +3 -0
  199. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  200. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  201. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  202. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  203. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  204. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  205. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  206. package/dist/esm-node/types/utils.js +0 -0
  207. package/dist/esm-node/utils/config.js +49 -0
  208. package/dist/esm-node/utils/createServer.js +26 -0
  209. package/dist/esm-node/utils/env.js +16 -0
  210. package/dist/esm-node/utils/generateWatchFiles.js +30 -0
  211. package/dist/esm-node/utils/getSelectedEntries.js +34 -0
  212. package/dist/esm-node/utils/loadPlugins.js +22 -0
  213. package/dist/esm-node/utils/printInstructions.js +11 -0
  214. package/dist/esm-node/utils/register.js +96 -0
  215. package/dist/esm-node/utils/restart.js +22 -0
  216. package/dist/esm-node/utils/routes.js +21 -0
  217. package/dist/esm-node/utils/types.js +0 -0
  218. package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
  219. package/dist/types/index.d.ts +1 -1
  220. package/package.json +20 -20
  221. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
  222. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,32 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { logger, prettyInstructions } from "@modern-js/utils";
4
+ var printInstructions = function() {
5
+ var _ref = _async_to_generator(function(hookRunners, appContext, config) {
6
+ var message, instructions;
7
+ return _ts_generator(this, function(_state) {
8
+ switch (_state.label) {
9
+ case 0:
10
+ message = prettyInstructions(appContext, config);
11
+ return [
12
+ 4,
13
+ hookRunners.beforePrintInstructions({
14
+ instructions: message
15
+ })
16
+ ];
17
+ case 1:
18
+ instructions = _state.sent().instructions;
19
+ logger.log(instructions);
20
+ return [
21
+ 2
22
+ ];
23
+ }
24
+ });
25
+ });
26
+ return function printInstructions2(hookRunners, appContext, config) {
27
+ return _ref.apply(this, arguments);
28
+ };
29
+ }();
30
+ export {
31
+ printInstructions
32
+ };
@@ -0,0 +1,188 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
5
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
+ import path from "node:path";
8
+ import { fs, getAliasConfig, readTsConfigByFile } from "@modern-js/utils";
9
+ var registerEsbuild = function() {
10
+ var _ref = _async_to_generator(function(param) {
11
+ var isTsProject, tsConfig, distDir, esbuildRegister;
12
+ return _ts_generator(this, function(_state) {
13
+ switch (_state.label) {
14
+ case 0:
15
+ isTsProject = param.isTsProject, tsConfig = param.tsConfig, distDir = param.distDir;
16
+ return [
17
+ 4,
18
+ import("esbuild-register/dist/node")
19
+ ];
20
+ case 1:
21
+ esbuildRegister = _state.sent();
22
+ esbuildRegister.register({
23
+ tsconfigRaw: isTsProject ? tsConfig : void 0,
24
+ hookIgnoreNodeModules: true,
25
+ hookMatcher: function(fileName) {
26
+ return !fileName.startsWith(distDir);
27
+ }
28
+ });
29
+ return [
30
+ 2
31
+ ];
32
+ }
33
+ });
34
+ });
35
+ return function registerEsbuild2(_) {
36
+ return _ref.apply(this, arguments);
37
+ };
38
+ }();
39
+ var registerCompiler = function() {
40
+ var _ref = _async_to_generator(function(appDir, distDir, alias) {
41
+ var TS_CONFIG_FILENAME, tsconfigPath, isTsProject, aliasConfig, _aliasConfig_paths, paths, _aliasConfig_absoluteBaseUrl, absoluteBaseUrl, tsPaths, tsConfig, MODERN_NODE_LOADER, tsNode, tsNodeOptions, error, tsConfigPaths, loaderRes;
42
+ return _ts_generator(this, function(_state) {
43
+ switch (_state.label) {
44
+ case 0:
45
+ TS_CONFIG_FILENAME = "tsconfig.json";
46
+ tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
47
+ return [
48
+ 4,
49
+ fs.pathExists(tsconfigPath)
50
+ ];
51
+ case 1:
52
+ isTsProject = _state.sent();
53
+ aliasConfig = getAliasConfig(alias, {
54
+ appDirectory: appDir,
55
+ tsconfigPath
56
+ });
57
+ _aliasConfig_paths = aliasConfig.paths, paths = _aliasConfig_paths === void 0 ? {} : _aliasConfig_paths, _aliasConfig_absoluteBaseUrl = aliasConfig.absoluteBaseUrl, absoluteBaseUrl = _aliasConfig_absoluteBaseUrl === void 0 ? "./" : _aliasConfig_absoluteBaseUrl;
58
+ tsPaths = Object.keys(paths).reduce(function(o, key) {
59
+ var tsPath = paths[key];
60
+ if (typeof tsPath === "string" && key.startsWith("@") && tsPath.startsWith("@")) {
61
+ try {
62
+ tsPath = require.resolve(tsPath, {
63
+ paths: [
64
+ process.cwd()
65
+ ].concat(_to_consumable_array(module.paths))
66
+ });
67
+ } catch (e) {
68
+ }
69
+ }
70
+ if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
71
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
72
+ }
73
+ if (typeof tsPath === "string") {
74
+ tsPath = [
75
+ tsPath
76
+ ];
77
+ }
78
+ return _object_spread_props(_object_spread({}, o), _define_property({}, "".concat(key), tsPath));
79
+ }, {});
80
+ tsConfig = {};
81
+ if (isTsProject) {
82
+ tsConfig = readTsConfigByFile(tsconfigPath);
83
+ }
84
+ MODERN_NODE_LOADER = process.env.MODERN_NODE_LOADER;
85
+ if (!(MODERN_NODE_LOADER !== "esbuild"))
86
+ return [
87
+ 3,
88
+ 7
89
+ ];
90
+ _state.label = 2;
91
+ case 2:
92
+ _state.trys.push([
93
+ 2,
94
+ 4,
95
+ ,
96
+ 6
97
+ ]);
98
+ return [
99
+ 4,
100
+ import("ts-node")
101
+ ];
102
+ case 3:
103
+ tsNode = _state.sent();
104
+ tsNodeOptions = tsConfig["ts-node"];
105
+ if (isTsProject) {
106
+ tsNode.register(_object_spread({
107
+ project: tsconfigPath,
108
+ scope: true,
109
+ // for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
110
+ files: true,
111
+ transpileOnly: true,
112
+ ignore: [
113
+ "(?:^|/)node_modules/",
114
+ "(?:^|/)".concat(path.relative(appDir, distDir), "/")
115
+ ]
116
+ }, tsNodeOptions));
117
+ }
118
+ return [
119
+ 3,
120
+ 6
121
+ ];
122
+ case 4:
123
+ error = _state.sent();
124
+ return [
125
+ 4,
126
+ registerEsbuild({
127
+ isTsProject,
128
+ tsConfig,
129
+ distDir
130
+ })
131
+ ];
132
+ case 5:
133
+ _state.sent();
134
+ return [
135
+ 3,
136
+ 6
137
+ ];
138
+ case 6:
139
+ return [
140
+ 3,
141
+ 9
142
+ ];
143
+ case 7:
144
+ return [
145
+ 4,
146
+ registerEsbuild({
147
+ isTsProject,
148
+ tsConfig,
149
+ distDir
150
+ })
151
+ ];
152
+ case 8:
153
+ _state.sent();
154
+ _state.label = 9;
155
+ case 9:
156
+ return [
157
+ 4,
158
+ import("@modern-js/utils/tsconfig-paths")
159
+ ];
160
+ case 10:
161
+ tsConfigPaths = _state.sent().default;
162
+ return [
163
+ 4,
164
+ fs.pathExists(appDir)
165
+ ];
166
+ case 11:
167
+ if (_state.sent()) {
168
+ loaderRes = tsConfigPaths.loadConfig(appDir);
169
+ if (loaderRes.resultType === "success") {
170
+ tsConfigPaths.register({
171
+ baseUrl: absoluteBaseUrl || "./",
172
+ paths: tsPaths
173
+ });
174
+ }
175
+ }
176
+ return [
177
+ 2
178
+ ];
179
+ }
180
+ });
181
+ });
182
+ return function registerCompiler2(appDir, distDir, alias) {
183
+ return _ref.apply(this, arguments);
184
+ };
185
+ }();
186
+ export {
187
+ registerCompiler
188
+ };
@@ -0,0 +1,67 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { cli } from "@modern-js/core";
4
+ import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
5
+ function restart(hooksRunner, filename) {
6
+ return _restart.apply(this, arguments);
7
+ }
8
+ function _restart() {
9
+ _restart = _async_to_generator(function(hooksRunner, filename) {
10
+ var hasGetError, err;
11
+ return _ts_generator(this, function(_state) {
12
+ switch (_state.label) {
13
+ case 0:
14
+ clearConsole();
15
+ logger.info("Restart because ".concat(chalk.yellow(filename), " is changed...\n"));
16
+ hasGetError = false;
17
+ return [
18
+ 4,
19
+ hooksRunner.beforeRestart()
20
+ ];
21
+ case 1:
22
+ _state.sent();
23
+ _state.label = 2;
24
+ case 2:
25
+ _state.trys.push([
26
+ 2,
27
+ 4,
28
+ 5,
29
+ 6
30
+ ]);
31
+ return [
32
+ 4,
33
+ cli.init(cli.getPrevInitOptions())
34
+ ];
35
+ case 3:
36
+ _state.sent();
37
+ return [
38
+ 3,
39
+ 6
40
+ ];
41
+ case 4:
42
+ err = _state.sent();
43
+ console.error(err);
44
+ hasGetError = true;
45
+ return [
46
+ 3,
47
+ 6
48
+ ];
49
+ case 5:
50
+ if (!hasGetError) {
51
+ program.parse(getFullArgv());
52
+ }
53
+ return [
54
+ 7
55
+ ];
56
+ case 6:
57
+ return [
58
+ 2
59
+ ];
60
+ }
61
+ });
62
+ });
63
+ return _restart.apply(this, arguments);
64
+ }
65
+ export {
66
+ restart
67
+ };
@@ -0,0 +1,42 @@
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, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE } from "@modern-js/utils";
5
+ var generateRoutes = function() {
6
+ var _ref = _async_to_generator(function(appContext) {
7
+ var serverRoutes, distDirectory, output;
8
+ return _ts_generator(this, function(_state) {
9
+ switch (_state.label) {
10
+ case 0:
11
+ serverRoutes = appContext.serverRoutes, distDirectory = appContext.distDirectory;
12
+ output = JSON.stringify({
13
+ routes: serverRoutes
14
+ }, null, 2);
15
+ return [
16
+ 4,
17
+ fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output)
18
+ ];
19
+ case 1:
20
+ _state.sent();
21
+ return [
22
+ 2
23
+ ];
24
+ }
25
+ });
26
+ });
27
+ return function generateRoutes2(appContext) {
28
+ return _ref.apply(this, arguments);
29
+ };
30
+ }();
31
+ var getPathWithoutExt = function(filename) {
32
+ var extname = path.extname(filename);
33
+ return filename.slice(0, -extname.length);
34
+ };
35
+ var isMainEntry = function(entryName, mainEntryName) {
36
+ return entryName === (mainEntryName || MAIN_ENTRY_NAME);
37
+ };
38
+ export {
39
+ generateRoutes,
40
+ getPathWithoutExt,
41
+ isMainEntry
42
+ };
File without changes
@@ -0,0 +1,67 @@
1
+ import path from "path";
2
+ import { logger, removeTailSlash } from "@modern-js/utils";
3
+ import fs from "@modern-js/utils/fs-extra";
4
+ import { createCopyInfo } from "../shared";
5
+ const builderPluginAdpaterCopy = (options) => ({
6
+ name: "builder-plugin-adapter-rspack-copy",
7
+ setup(api) {
8
+ let publicPath;
9
+ api.modifyBundlerChain((chain, { CHAIN_ID }) => {
10
+ chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
11
+ var _args_;
12
+ return [
13
+ {
14
+ patterns: [
15
+ ...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
16
+ ...createConfigBuiltinCopy(options)
17
+ ]
18
+ }
19
+ ];
20
+ });
21
+ });
22
+ api.modifyRspackConfig((config) => {
23
+ var _config_output;
24
+ publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
25
+ });
26
+ api.onDevCompileDone(async () => {
27
+ await transformHtmlFiles();
28
+ });
29
+ api.onAfterBuild(async () => {
30
+ await transformHtmlFiles();
31
+ });
32
+ async function transformHtmlFiles() {
33
+ var _normalizedConfig_output_distPath;
34
+ const { normalizedConfig } = options;
35
+ const publicDir = path.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
36
+ if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
37
+ return;
38
+ }
39
+ const HTML_REGEXP = /\.html?$/;
40
+ const filepaths = (await fs.readdir(publicDir)).map((file) => path.resolve(publicDir, file));
41
+ await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
42
+ const content = await fs.readFile(file, "utf-8");
43
+ if (publicPath && typeof publicPath === "string") {
44
+ await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(publicPath)));
45
+ } else {
46
+ logger.warn(`Expect get a string from \`publicPath\`, but receive \`${typeof publicPath}\`.`);
47
+ await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash("/")));
48
+ }
49
+ }));
50
+ }
51
+ }
52
+ });
53
+ function createConfigBuiltinCopy(options) {
54
+ const { normalizedConfig, appContext } = options;
55
+ const { publicDir } = createCopyInfo(appContext, normalizedConfig);
56
+ return [
57
+ {
58
+ from: "**/*",
59
+ to: "public",
60
+ context: publicDir,
61
+ noErrorOnMissing: true
62
+ }
63
+ ];
64
+ }
65
+ export {
66
+ builderPluginAdpaterCopy
67
+ };
@@ -0,0 +1,12 @@
1
+ import { generateBuilder } from "../generator";
2
+ import { builderPluginAdpaterCopy } from "./adapterCopy";
3
+ async function createRspackBuilderForModern(options) {
4
+ const builder = await generateBuilder(options, "rspack");
5
+ builder.addPlugins([
6
+ builderPluginAdpaterCopy(options)
7
+ ]);
8
+ return builder;
9
+ }
10
+ export {
11
+ createRspackBuilderForModern
12
+ };
@@ -0,0 +1,26 @@
1
+ import { createPublicPattern } from "./createCopyPattern";
2
+ const builderPluginAdapterModern = (options) => ({
3
+ name: "builder-plugin-adapter-modern",
4
+ setup(api) {
5
+ const { normalizedConfig: modernConfig, appContext } = options;
6
+ api.modifyWebpackChain((chain, { CHAIN_ID }) => {
7
+ if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
8
+ const defaultCopyPattern = createPublicPattern(appContext, modernConfig, chain);
9
+ chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
10
+ var _args_;
11
+ return [
12
+ {
13
+ patterns: [
14
+ ...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
15
+ defaultCopyPattern
16
+ ]
17
+ }
18
+ ];
19
+ });
20
+ }
21
+ });
22
+ }
23
+ });
24
+ export {
25
+ builderPluginAdapterModern
26
+ };
@@ -0,0 +1,41 @@
1
+ import { removeTailSlash } from "@modern-js/utils";
2
+ import { createCopyInfo } from "../shared";
3
+ const minifiedJsRexExp = /\.min\.js/;
4
+ const info = (file) => ({
5
+ // If the file name ends with `.min.js`, we assume it's a compressed file.
6
+ // So we don't want copy-webpack-plugin to minify it.
7
+ // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
8
+ minimized: minifiedJsRexExp.test(file.sourceFilename)
9
+ });
10
+ function createPublicPattern(appContext, config, chain) {
11
+ const { publicDir } = createCopyInfo(appContext, config);
12
+ return {
13
+ info,
14
+ from: "**/*",
15
+ to: "public",
16
+ context: publicDir,
17
+ noErrorOnMissing: true,
18
+ transform: (content, absoluteFrom) => {
19
+ if (!/\.html?$/.test(absoluteFrom)) {
20
+ return content;
21
+ }
22
+ return content.toString("utf8").replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(chain.output.get("publicPath")));
23
+ }
24
+ };
25
+ }
26
+ function createUploadPattern(appContext, config) {
27
+ const { uploadDir } = createCopyInfo(appContext, config);
28
+ return {
29
+ // rspack copy info structure is inconsistent with webpack, it only used in webpack mode
30
+ // @ts-expect-error
31
+ info,
32
+ from: "**/*",
33
+ to: "upload",
34
+ context: uploadDir,
35
+ noErrorOnMissing: true
36
+ };
37
+ }
38
+ export {
39
+ createPublicPattern,
40
+ createUploadPattern
41
+ };
@@ -0,0 +1,20 @@
1
+ import { generateBuilder } from "../generator";
2
+ import { builderPluginAdapterModern } from "./adapterModern";
3
+ async function createWebpackBuilderForModern(options) {
4
+ const builder = await generateBuilder(options, "webpack");
5
+ const { normalizedConfig } = options;
6
+ if (normalizedConfig.tools.esbuild) {
7
+ const { esbuild: esbuildOptions } = normalizedConfig.tools;
8
+ const { pluginEsbuild } = await import("@modern-js/rsbuild-plugin-esbuild");
9
+ builder.addPlugins([
10
+ pluginEsbuild(esbuildOptions)
11
+ ]);
12
+ }
13
+ builder.addPlugins([
14
+ builderPluginAdapterModern(options)
15
+ ]);
16
+ return builder;
17
+ }
18
+ export {
19
+ createWebpackBuilderForModern
20
+ };
@@ -0,0 +1,44 @@
1
+ import { createUploadPattern } from "../builder-webpack/createCopyPattern";
2
+ function modifyOutputConfig(config, appContext) {
3
+ const defaultCopyPattern = createUploadPattern(appContext, config);
4
+ const { copy } = config.output;
5
+ const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
6
+ const builderCopy = [
7
+ ...copyOptions || [],
8
+ defaultCopyPattern
9
+ ];
10
+ config.output = {
11
+ ...config.output,
12
+ copy: builderCopy
13
+ };
14
+ }
15
+ function createBuilderProviderConfig(resolveConfig, appContext) {
16
+ const htmlConfig = {
17
+ ...resolveConfig.html
18
+ };
19
+ if (!htmlConfig.template) {
20
+ htmlConfig.templateByEntries = {
21
+ ...appContext.htmlTemplates,
22
+ ...htmlConfig.templateByEntries
23
+ };
24
+ }
25
+ const config = {
26
+ ...resolveConfig,
27
+ plugins: [],
28
+ dev: {
29
+ ...resolveConfig.dev,
30
+ port: appContext.port
31
+ },
32
+ html: htmlConfig,
33
+ output: {
34
+ ...resolveConfig.output,
35
+ // We need to do this in the app-tools prepare hook because some files will be generated into the dist directory in the analyze process
36
+ cleanDistPath: false
37
+ }
38
+ };
39
+ modifyOutputConfig(config, appContext);
40
+ return config;
41
+ }
42
+ export {
43
+ createBuilderProviderConfig
44
+ };
@@ -0,0 +1,60 @@
1
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
+ import { isProd, isSSR, isServiceWorker, isUseSSRBundle } from "@modern-js/utils";
3
+ function getBuilderEnvironments(normalizedConfig, appContext) {
4
+ const entries = {};
5
+ const { entrypoints = [], checkedEntries } = appContext;
6
+ for (const { entryName, internalEntry, entry } of entrypoints) {
7
+ if (checkedEntries && !checkedEntries.includes(entryName)) {
8
+ continue;
9
+ }
10
+ const finalEntry = internalEntry || entry;
11
+ if (entryName in entries) {
12
+ entries[entryName].push(finalEntry);
13
+ } else {
14
+ entries[entryName] = [
15
+ finalEntry
16
+ ];
17
+ }
18
+ }
19
+ const serverEntries = {};
20
+ for (const entry in entries) {
21
+ const v = entries[entry];
22
+ serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
23
+ }
24
+ const environments = {
25
+ web: {
26
+ output: {
27
+ target: "web"
28
+ },
29
+ source: {
30
+ entry: entries
31
+ }
32
+ }
33
+ };
34
+ const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
35
+ if (useNodeTarget) {
36
+ environments.node = {
37
+ output: {
38
+ target: "node"
39
+ },
40
+ source: {
41
+ entry: serverEntries
42
+ }
43
+ };
44
+ }
45
+ const useWorkerTarget = isServiceWorker(normalizedConfig);
46
+ if (useWorkerTarget) {
47
+ environments[SERVICE_WORKER_ENVIRONMENT_NAME] = {
48
+ output: {
49
+ target: "web-worker"
50
+ },
51
+ source: {
52
+ entry: serverEntries
53
+ }
54
+ };
55
+ }
56
+ return environments;
57
+ }
58
+ export {
59
+ getBuilderEnvironments
60
+ };
@@ -0,0 +1,36 @@
1
+ import { createUniBuilder } from "@modern-js/uni-builder";
2
+ import { mergeRsbuildConfig } from "@rsbuild/core";
3
+ import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
4
+ import { getBuilderEnvironments } from "./getBuilderEnvironments";
5
+ async function generateBuilder(options, bundlerType) {
6
+ const { normalizedConfig, appContext } = options;
7
+ const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
8
+ const environments = getBuilderEnvironments(normalizedConfig, appContext);
9
+ builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
10
+ const builder = await createUniBuilder({
11
+ cwd: appContext.appDirectory,
12
+ frameworkConfigPath: appContext.configFile || void 0,
13
+ bundlerType,
14
+ config: builderConfig
15
+ });
16
+ await applyBuilderPlugins(builder, options);
17
+ return builder;
18
+ }
19
+ async function applyBuilderPlugins(builder, options) {
20
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins/index.js");
21
+ builder.addPlugins([
22
+ builderPluginAdapterBasic(),
23
+ builderPluginAdapterSSR(options),
24
+ builderPluginAdapterHtml(options)
25
+ ]);
26
+ const { normalizedConfig } = options;
27
+ if (!normalizedConfig.output.disableNodePolyfill) {
28
+ const { pluginNodePolyfill } = await import("@rsbuild/plugin-node-polyfill");
29
+ builder.addPlugins([
30
+ pluginNodePolyfill()
31
+ ]);
32
+ }
33
+ }
34
+ export {
35
+ generateBuilder
36
+ };
@@ -0,0 +1,11 @@
1
+ async function createBuilderGenerator(bundler) {
2
+ if (bundler === "rspack") {
3
+ const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
4
+ return createRspackBuilderForModern;
5
+ }
6
+ const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
7
+ return createWebpackBuilderForModern;
8
+ }
9
+ export {
10
+ createBuilderGenerator
11
+ };