@modern-js/app-tools 2.54.6 → 2.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +84 -0
  2. package/dist/cjs/builder/generator/index.js +6 -5
  3. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +7 -14
  4. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +8 -8
  5. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -8
  6. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +5 -3
  7. package/dist/cjs/commands/index.js +2 -2
  8. package/dist/cjs/commands/inspect.js +1 -2
  9. package/dist/cjs/commands/serve.js +1 -0
  10. package/dist/cjs/config/default.js +2 -2
  11. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  12. package/dist/cjs/config/legacy/index.js +1 -0
  13. package/dist/cjs/hooks.js +2 -5
  14. package/dist/cjs/plugins/analyze/constants.js +3 -18
  15. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
  17. package/dist/cjs/plugins/analyze/index.js +7 -64
  18. package/dist/cjs/plugins/analyze/templates.js +2 -55
  19. package/dist/cjs/plugins/analyze/utils.js +0 -86
  20. package/dist/esm/builder/generator/{createBuilderOptions.js → getBuilderEnvironments.js} +43 -7
  21. package/dist/esm/builder/generator/index.js +9 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +7 -14
  23. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +8 -8
  24. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -8
  25. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +6 -4
  26. package/dist/esm/commands/index.js +1 -1
  27. package/dist/esm/commands/inspect.js +1 -2
  28. package/dist/esm/commands/serve.js +1 -0
  29. package/dist/esm/config/default.js +2 -5
  30. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  31. package/dist/esm/config/legacy/index.js +1 -0
  32. package/dist/esm/hooks.js +2 -5
  33. package/dist/esm/plugins/analyze/constants.js +2 -12
  34. package/dist/esm/plugins/analyze/getBundleEntry.js +2 -1
  35. package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
  36. package/dist/esm/plugins/analyze/index.js +25 -128
  37. package/dist/esm/plugins/analyze/templates.js +1 -17
  38. package/dist/esm/plugins/analyze/utils.js +1 -87
  39. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  40. package/dist/esm-node/builder/generator/index.js +6 -5
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +7 -14
  42. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +7 -7
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +5 -7
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +5 -3
  45. package/dist/esm-node/commands/index.js +1 -1
  46. package/dist/esm-node/commands/inspect.js +1 -2
  47. package/dist/esm-node/commands/serve.js +1 -0
  48. package/dist/esm-node/config/default.js +2 -2
  49. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  50. package/dist/esm-node/config/legacy/index.js +1 -0
  51. package/dist/esm-node/hooks.js +2 -5
  52. package/dist/esm-node/plugins/analyze/constants.js +2 -12
  53. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -1
  54. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
  55. package/dist/esm-node/plugins/analyze/index.js +10 -67
  56. package/dist/esm-node/plugins/analyze/templates.js +1 -52
  57. package/dist/esm-node/plugins/analyze/utils.js +1 -86
  58. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  59. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +5 -0
  60. package/dist/types/builder/generator/index.d.ts +1 -2
  61. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  62. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  63. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  64. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
  65. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  66. package/dist/types/commands/inspect.d.ts +1 -1
  67. package/dist/types/plugins/analyze/constants.d.ts +1 -6
  68. package/dist/types/plugins/analyze/templates.d.ts +0 -14
  69. package/dist/types/plugins/analyze/utils.d.ts +0 -11
  70. package/dist/types/types/config/index.d.ts +2 -0
  71. package/dist/types/types/config/source.d.ts +11 -0
  72. package/dist/types/types/hooks.d.ts +7 -27
  73. package/dist/types/types/index.d.ts +1 -1
  74. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  75. package/dist/types/types/legacyConfig/source.d.ts +4 -0
  76. package/dist/types/utils/register.d.ts +1 -1
  77. package/package.json +22 -23
  78. package/dist/cjs/builder/generator/createBuilderOptions.js +0 -50
  79. package/dist/cjs/builder/generator/getBuilderTargets.js +0 -42
  80. package/dist/cjs/plugins/analyze/generateCode.js +0 -185
  81. package/dist/esm/builder/generator/getBuilderTargets.js +0 -18
  82. package/dist/esm/plugins/analyze/generateCode.js +0 -296
  83. package/dist/esm-node/builder/generator/createBuilderOptions.js +0 -26
  84. package/dist/esm-node/builder/generator/getBuilderTargets.js +0 -18
  85. package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
  86. package/dist/types/builder/generator/createBuilderOptions.d.ts +0 -4
  87. package/dist/types/builder/generator/getBuilderTargets.d.ts +0 -3
  88. package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -1,296 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import path from "path";
5
- import { findExists, fs, getEntryOptions, JS_EXTENSIONS, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
6
- import * as templates from "./templates";
7
- import { ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
8
- import { getDefaultImports } from "./utils";
9
- var createImportSpecifier = function(specifiers) {
10
- var defaults = "";
11
- var named = [];
12
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
13
- try {
14
- for (var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
15
- var _step_value = _step.value, local = _step_value.local, imported = _step_value.imported;
16
- if (local && imported) {
17
- named.push("".concat(imported, " as ").concat(local));
18
- } else if (local) {
19
- defaults = local;
20
- } else {
21
- named.push(imported);
22
- }
23
- }
24
- } catch (err) {
25
- _didIteratorError = true;
26
- _iteratorError = err;
27
- } finally {
28
- try {
29
- if (!_iteratorNormalCompletion && _iterator.return != null) {
30
- _iterator.return();
31
- }
32
- } finally {
33
- if (_didIteratorError) {
34
- throw _iteratorError;
35
- }
36
- }
37
- }
38
- if (defaults && named.length) {
39
- return "".concat(defaults, ", { ").concat(named.join(", "), " }");
40
- } else if (defaults) {
41
- return defaults;
42
- } else {
43
- return "{ ".concat(named.join(", "), " }");
44
- }
45
- };
46
- var createImportStatements = function(statements) {
47
- var deDuplicated = [];
48
- var seen = /* @__PURE__ */ new Map();
49
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
50
- try {
51
- var _loop = function() {
52
- var _step_value = _step.value, value = _step_value.value, specifiers = _step_value.specifiers, initialize = _step_value.initialize;
53
- if (!seen.has(value)) {
54
- deDuplicated.push({
55
- value,
56
- specifiers,
57
- initialize
58
- });
59
- seen.set(value, specifiers);
60
- } else {
61
- var _seen_get;
62
- var _deDuplicated_modifyIndex;
63
- (_seen_get = seen.get(value)).push.apply(_seen_get, _to_consumable_array(specifiers));
64
- var modifyIndex = deDuplicated.findIndex(function(v) {
65
- return v.value === value;
66
- });
67
- var _deDuplicated_modifyIndex_initialize;
68
- var originInitialize = (_deDuplicated_modifyIndex_initialize = (_deDuplicated_modifyIndex = deDuplicated[modifyIndex]) === null || _deDuplicated_modifyIndex === void 0 ? void 0 : _deDuplicated_modifyIndex.initialize) !== null && _deDuplicated_modifyIndex_initialize !== void 0 ? _deDuplicated_modifyIndex_initialize : "";
69
- deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
70
- }
71
- };
72
- for (var _iterator = statements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
73
- _loop();
74
- } catch (err) {
75
- _didIteratorError = true;
76
- _iteratorError = err;
77
- } finally {
78
- try {
79
- if (!_iteratorNormalCompletion && _iterator.return != null) {
80
- _iterator.return();
81
- }
82
- } finally {
83
- if (_didIteratorError) {
84
- throw _iteratorError;
85
- }
86
- }
87
- }
88
- return deDuplicated.map(function(param) {
89
- var value = param.value, specifiers = param.specifiers, initialize = param.initialize;
90
- return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
91
- }).join("\n");
92
- };
93
- var generateCode = function() {
94
- var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
95
- var internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile, hookRunners, customRuntimeConfig, importsStatemets;
96
- function generateEntryCode(entrypoint, customRuntimeConfig2) {
97
- return _generateEntryCode.apply(this, arguments);
98
- }
99
- function _generateEntryCode() {
100
- _generateEntryCode = _async_to_generator(function(entrypoint, customRuntimeConfig2) {
101
- var entryName, isAutoMount, imports, entryFile;
102
- return _ts_generator(this, function(_state) {
103
- switch (_state.label) {
104
- case 0:
105
- entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount;
106
- if (!isAutoMount)
107
- return [
108
- 3,
109
- 2
110
- ];
111
- return [
112
- 4,
113
- hookRunners.modifyEntryImports({
114
- entrypoint,
115
- imports: getDefaultImports({
116
- entrypoint,
117
- srcDirectory,
118
- appDirectory,
119
- internalSrcAlias,
120
- internalDirAlias,
121
- runtimeConfigFile,
122
- customRuntimeConfig: customRuntimeConfig2
123
- })
124
- })
125
- ];
126
- case 1:
127
- imports = _state.sent().imports;
128
- importsStatemets.set(entryName, imports);
129
- entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
130
- entrypoint.internalEntry = entryFile;
131
- _state.label = 2;
132
- case 2:
133
- return [
134
- 2
135
- ];
136
- }
137
- });
138
- });
139
- return _generateEntryCode.apply(this, arguments);
140
- }
141
- return _ts_generator(this, function(_state) {
142
- switch (_state.label) {
143
- case 0:
144
- internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, appDirectory = appContext.appDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, runtimeConfigFile = appContext.runtimeConfigFile;
145
- hookRunners = api.useHookRunners();
146
- customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
147
- return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
148
- }));
149
- importsStatemets = /* @__PURE__ */ new Map();
150
- return [
151
- 4,
152
- Promise.all(entrypoints.map(function(entrypoint) {
153
- return generateEntryCode(entrypoint, customRuntimeConfig);
154
- }))
155
- ];
156
- case 1:
157
- _state.sent();
158
- return [
159
- 2,
160
- {
161
- importsStatemets
162
- }
163
- ];
164
- }
165
- });
166
- });
167
- return function generateCode2(appContext, config, entrypoints, api) {
168
- return _ref.apply(this, arguments);
169
- };
170
- }();
171
- var generateIndexCode = function() {
172
- var _ref = _async_to_generator(function(param) {
173
- var appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, hookRunners, mountId, internalDirectory, packageName, srcDirectory, runtimeConfigFile, customRuntimeConfig;
174
- return _ts_generator(this, function(_state) {
175
- switch (_state.label) {
176
- case 0:
177
- appContext = param.appContext, api = param.api, entrypoints = param.entrypoints, config = param.config, importsStatemets = param.importsStatemets, bundlerConfigs = param.bundlerConfigs;
178
- hookRunners = api.useHookRunners();
179
- mountId = config.html.mountId;
180
- internalDirectory = appContext.internalDirectory, packageName = appContext.packageName, srcDirectory = appContext.srcDirectory, runtimeConfigFile = appContext.runtimeConfigFile;
181
- customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
182
- return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
183
- }));
184
- return [
185
- 4,
186
- Promise.all(entrypoints.map(function() {
187
- var _ref2 = _async_to_generator(function(entrypoint) {
188
- var entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes, plugins, _ref3, renderFunction, exportStatement, imports, code, entryFile, rawAsyncEntryCode, ssr, _ref1, asyncEntryCode, bootstrapFile;
189
- return _ts_generator(this, function(_state2) {
190
- switch (_state2.label) {
191
- case 0:
192
- entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
193
- if (!isAutoMount)
194
- return [
195
- 3,
196
- 6
197
- ];
198
- return [
199
- 4,
200
- hookRunners.modifyEntryRuntimePlugins({
201
- entrypoint,
202
- plugins: [],
203
- bundlerConfigs
204
- })
205
- ];
206
- case 1:
207
- plugins = _state2.sent().plugins;
208
- return [
209
- 4,
210
- hookRunners.modifyEntryRenderFunction({
211
- entrypoint,
212
- code: templates.renderFunction({
213
- plugins,
214
- customBootstrap,
215
- customRuntimeConfig,
216
- fileSystemRoutes
217
- })
218
- })
219
- ];
220
- case 2:
221
- _ref3 = _state2.sent(), renderFunction = _ref3.code;
222
- return [
223
- 4,
224
- hookRunners.modifyEntryExport({
225
- entrypoint,
226
- exportStatement: "export default AppWrapper;"
227
- })
228
- ];
229
- case 3:
230
- exportStatement = _state2.sent().exportStatement;
231
- imports = importsStatemets.get(entryName);
232
- code = templates.index({
233
- mountId,
234
- imports: createImportStatements(imports),
235
- renderFunction,
236
- exportStatement
237
- });
238
- entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
239
- if (!config.source.enableAsyncEntry)
240
- return [
241
- 3,
242
- 5
243
- ];
244
- rawAsyncEntryCode = "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');");
245
- ssr = getEntryOptions(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
246
- if (ssr) {
247
- rawAsyncEntryCode = "\n export const ".concat(SERVER_RENDER_FUNCTION_NAME, " = async (...args) => {\n let entry = await ").concat(rawAsyncEntryCode, ";\n if (entry.default instanceof Promise){\n entry = await entry.default;\n return entry.default.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n }\n return entry.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n };\n if(typeof window!=='undefined'){\n ").concat(rawAsyncEntryCode, "\n }\n ");
248
- }
249
- return [
250
- 4,
251
- hookRunners.modifyAsyncEntry({
252
- entrypoint,
253
- code: rawAsyncEntryCode
254
- })
255
- ];
256
- case 4:
257
- _ref1 = _state2.sent(), asyncEntryCode = _ref1.code;
258
- fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
259
- bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
260
- fs.outputFileSync(bootstrapFile, code, "utf8");
261
- return [
262
- 3,
263
- 6
264
- ];
265
- case 5:
266
- fs.outputFileSync(entryFile, code, "utf8");
267
- _state2.label = 6;
268
- case 6:
269
- return [
270
- 2
271
- ];
272
- }
273
- });
274
- });
275
- return function(entrypoint) {
276
- return _ref2.apply(this, arguments);
277
- };
278
- }()))
279
- ];
280
- case 1:
281
- _state.sent();
282
- return [
283
- 2
284
- ];
285
- }
286
- });
287
- });
288
- return function generateIndexCode2(_) {
289
- return _ref.apply(this, arguments);
290
- };
291
- }();
292
- export {
293
- createImportStatements,
294
- generateCode,
295
- generateIndexCode
296
- };
@@ -1,26 +0,0 @@
1
- function createBuilderOptions(target, appContext) {
2
- const entries = {};
3
- const { entrypoints = [], checkedEntries } = appContext;
4
- for (const { entryName, internalEntry, entry } of entrypoints) {
5
- if (checkedEntries && !checkedEntries.includes(entryName)) {
6
- continue;
7
- }
8
- const finalEntry = internalEntry || entry;
9
- if (entryName in entries) {
10
- entries[entryName].push(finalEntry);
11
- } else {
12
- entries[entryName] = [
13
- finalEntry
14
- ];
15
- }
16
- }
17
- return {
18
- cwd: appContext.appDirectory,
19
- target,
20
- frameworkConfigPath: appContext.configFile || void 0,
21
- entry: entries
22
- };
23
- }
24
- export {
25
- createBuilderOptions
26
- };
@@ -1,18 +0,0 @@
1
- import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
2
- function getBuilderTargets(normalizedConfig) {
3
- const targets = [
4
- "web"
5
- ];
6
- const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
7
- if (useNodeTarget) {
8
- targets.push("node");
9
- }
10
- const useWorkerTarget = isServiceWorker(normalizedConfig);
11
- if (useWorkerTarget) {
12
- targets.push("service-worker");
13
- }
14
- return targets;
15
- }
16
- export {
17
- getBuilderTargets
18
- };
@@ -1,149 +0,0 @@
1
- import path from "path";
2
- import { findExists, fs, getEntryOptions, JS_EXTENSIONS, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
3
- import * as templates from "./templates";
4
- import { ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
5
- import { getDefaultImports } from "./utils";
6
- const createImportSpecifier = (specifiers) => {
7
- let defaults = "";
8
- const named = [];
9
- for (const { local, imported } of specifiers) {
10
- if (local && imported) {
11
- named.push(`${imported} as ${local}`);
12
- } else if (local) {
13
- defaults = local;
14
- } else {
15
- named.push(imported);
16
- }
17
- }
18
- if (defaults && named.length) {
19
- return `${defaults}, { ${named.join(", ")} }`;
20
- } else if (defaults) {
21
- return defaults;
22
- } else {
23
- return `{ ${named.join(", ")} }`;
24
- }
25
- };
26
- const createImportStatements = (statements) => {
27
- const deDuplicated = [];
28
- const seen = /* @__PURE__ */ new Map();
29
- for (const { value, specifiers, initialize } of statements) {
30
- if (!seen.has(value)) {
31
- deDuplicated.push({
32
- value,
33
- specifiers,
34
- initialize
35
- });
36
- seen.set(value, specifiers);
37
- } else {
38
- var _deDuplicated_modifyIndex;
39
- seen.get(value).push(...specifiers);
40
- const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
41
- var _deDuplicated_modifyIndex_initialize;
42
- const originInitialize = (_deDuplicated_modifyIndex_initialize = (_deDuplicated_modifyIndex = deDuplicated[modifyIndex]) === null || _deDuplicated_modifyIndex === void 0 ? void 0 : _deDuplicated_modifyIndex.initialize) !== null && _deDuplicated_modifyIndex_initialize !== void 0 ? _deDuplicated_modifyIndex_initialize : "";
43
- deDuplicated[modifyIndex].initialize = originInitialize.concat(`
44
- ${initialize || ""}`);
45
- }
46
- }
47
- return deDuplicated.map(({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
48
- ${initialize || ""}`).join("\n");
49
- };
50
- const generateCode = async (appContext, config, entrypoints, api) => {
51
- const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile } = appContext;
52
- const hookRunners = api.useHookRunners();
53
- const customRuntimeConfig = findExists(JS_EXTENSIONS.map((ext) => path.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
54
- const importsStatemets = /* @__PURE__ */ new Map();
55
- await Promise.all(entrypoints.map((entrypoint) => generateEntryCode(entrypoint, customRuntimeConfig)));
56
- return {
57
- importsStatemets
58
- };
59
- async function generateEntryCode(entrypoint, customRuntimeConfig2) {
60
- const { entryName, isAutoMount } = entrypoint;
61
- if (isAutoMount) {
62
- const { imports } = await hookRunners.modifyEntryImports({
63
- entrypoint,
64
- imports: getDefaultImports({
65
- entrypoint,
66
- srcDirectory,
67
- appDirectory,
68
- internalSrcAlias,
69
- internalDirAlias,
70
- runtimeConfigFile,
71
- customRuntimeConfig: customRuntimeConfig2
72
- })
73
- });
74
- importsStatemets.set(entryName, imports);
75
- const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
76
- entrypoint.internalEntry = entryFile;
77
- }
78
- }
79
- };
80
- const generateIndexCode = async ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs }) => {
81
- const hookRunners = api.useHookRunners();
82
- const { mountId } = config.html;
83
- const { internalDirectory, packageName, srcDirectory, runtimeConfigFile } = appContext;
84
- const customRuntimeConfig = findExists(JS_EXTENSIONS.map((ext) => path.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
85
- await Promise.all(entrypoints.map(async (entrypoint) => {
86
- const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
87
- if (isAutoMount) {
88
- const { plugins } = await hookRunners.modifyEntryRuntimePlugins({
89
- entrypoint,
90
- plugins: [],
91
- bundlerConfigs
92
- });
93
- const { code: renderFunction } = await hookRunners.modifyEntryRenderFunction({
94
- entrypoint,
95
- code: templates.renderFunction({
96
- plugins,
97
- customBootstrap,
98
- customRuntimeConfig,
99
- fileSystemRoutes
100
- })
101
- });
102
- const { exportStatement } = await hookRunners.modifyEntryExport({
103
- entrypoint,
104
- exportStatement: "export default AppWrapper;"
105
- });
106
- const imports = importsStatemets.get(entryName);
107
- const code = templates.index({
108
- mountId,
109
- imports: createImportStatements(imports),
110
- renderFunction,
111
- exportStatement
112
- });
113
- const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
114
- if (config.source.enableAsyncEntry) {
115
- let rawAsyncEntryCode = `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`;
116
- const ssr = getEntryOptions(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
117
- if (ssr) {
118
- rawAsyncEntryCode = `
119
- export const ${SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
120
- let entry = await ${rawAsyncEntryCode};
121
- if (entry.default instanceof Promise){
122
- entry = await entry.default;
123
- return entry.default.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
124
- }
125
- return entry.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
126
- };
127
- if(typeof window!=='undefined'){
128
- ${rawAsyncEntryCode}
129
- }
130
- `;
131
- }
132
- const { code: asyncEntryCode } = await hookRunners.modifyAsyncEntry({
133
- entrypoint,
134
- code: rawAsyncEntryCode
135
- });
136
- fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
137
- const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
138
- fs.outputFileSync(bootstrapFile, code, "utf8");
139
- } else {
140
- fs.outputFileSync(entryFile, code, "utf8");
141
- }
142
- }
143
- }));
144
- };
145
- export {
146
- createImportStatements,
147
- generateCode,
148
- generateIndexCode
149
- };
@@ -1,4 +0,0 @@
1
- import type { CreateUniBuilderOptions } from '@modern-js/uni-builder';
2
- import type { RsbuildTarget } from '@rsbuild/shared';
3
- import type { IAppContext } from '@modern-js/core';
4
- export declare function createBuilderOptions(target: RsbuildTarget | RsbuildTarget[], appContext: IAppContext): Omit<CreateUniBuilderOptions, 'bundlerType' | 'config'>;
@@ -1,3 +0,0 @@
1
- import type { RsbuildTarget } from '@rsbuild/shared';
2
- import type { AppNormalizedConfig } from '../../types';
3
- export declare function getBuilderTargets(normalizedConfig: AppNormalizedConfig<'shared'>): RsbuildTarget[];
@@ -1,16 +0,0 @@
1
- import { IAppContext, PluginAPI } from '@modern-js/core';
2
- import type { Entrypoint } from '@modern-js/types';
3
- import { RspackConfig, WebpackConfig } from '@rsbuild/shared';
4
- import { AppNormalizedConfig, AppTools, ImportStatement } from '../../types';
5
- export declare const createImportStatements: (statements: ImportStatement[]) => string;
6
- export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<{
7
- importsStatemets: Map<string, ImportStatement[]>;
8
- }>;
9
- export declare const generateIndexCode: ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, }: {
10
- appContext: IAppContext;
11
- api: PluginAPI<AppTools<'shared'>>;
12
- entrypoints: Entrypoint[];
13
- config: AppNormalizedConfig<'shared'>;
14
- importsStatemets: Map<string, ImportStatement[]>;
15
- bundlerConfigs?: RspackConfig[] | WebpackConfig[] | undefined;
16
- }) => Promise<void>;