@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
@@ -3,15 +3,26 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
6
- import { INDEX_FILE_NAME } from "./constants";
6
+ import { ENTRY_FILE_NAME, INDEX_FILE_NAME } from "./constants";
7
7
  import { isDefaultExportFunction } from "./isDefaultExportFunction";
8
8
  var hasIndex = function(dir) {
9
9
  return findExists(JS_EXTENSIONS.map(function(ext) {
10
10
  return path.resolve(dir, "".concat(INDEX_FILE_NAME).concat(ext));
11
11
  }));
12
12
  };
13
+ var hasEntry = function(dir) {
14
+ return findExists(JS_EXTENSIONS.map(function(ext) {
15
+ return path.resolve(dir, "".concat(ENTRY_FILE_NAME).concat(ext));
16
+ }));
17
+ };
18
+ var hasServerEntry = function(dir) {
19
+ return findExists(JS_EXTENSIONS.map(function(ext) {
20
+ return path.resolve(dir, "".concat(ENTRY_FILE_NAME, ".server").concat(ext));
21
+ }));
22
+ };
13
23
  var isBundleEntry = function() {
14
- var _ref = _async_to_generator(function(hookRunners, dir) {
24
+ var _ref = _async_to_generator(function(hookRunners, dir, enableCustomEntry) {
25
+ var entry, customEntry;
15
26
  return _ts_generator(this, function(_state) {
16
27
  switch (_state.label) {
17
28
  case 0:
@@ -23,27 +34,43 @@ var isBundleEntry = function() {
23
34
  })
24
35
  ];
25
36
  case 1:
37
+ entry = _state.sent().entry;
38
+ if (entry) {
39
+ return [
40
+ 2,
41
+ entry
42
+ ];
43
+ }
44
+ customEntry = hasEntry(dir);
45
+ if (enableCustomEntry && customEntry) {
46
+ return [
47
+ 2,
48
+ customEntry
49
+ ];
50
+ }
26
51
  return [
27
52
  2,
28
- _state.sent().entry || hasIndex(dir)
53
+ hasIndex(dir)
29
54
  ];
30
55
  }
31
56
  });
32
57
  });
33
- return function isBundleEntry2(hookRunners, dir) {
58
+ return function isBundleEntry2(hookRunners, dir, enableCustomEntry) {
34
59
  return _ref.apply(this, arguments);
35
60
  };
36
61
  }();
37
- var scanDir = function(hookRunners, dirs) {
62
+ var scanDir = function(hookRunners, dirs, enableCustomEntry) {
38
63
  return Promise.all(dirs.map(function() {
39
64
  var _ref = _async_to_generator(function(dir) {
40
- var indexFile, customBootstrap, entryName, entryFile;
65
+ var indexFile, customBootstrap, entryName, customEntryFile, customServerEntry, entryFile;
41
66
  return _ts_generator(this, function(_state) {
42
67
  switch (_state.label) {
43
68
  case 0:
44
69
  indexFile = hasIndex(dir);
45
70
  customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
46
71
  entryName = path.basename(dir);
72
+ customEntryFile = hasEntry(dir);
73
+ customServerEntry = hasServerEntry(dir);
47
74
  if (indexFile && !customBootstrap) {
48
75
  return [
49
76
  2,
@@ -72,10 +99,26 @@ var scanDir = function(hookRunners, dirs) {
72
99
  {
73
100
  entryName,
74
101
  isMainEntry: false,
75
- entry: entryFile,
102
+ entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
103
+ customServerEntry,
76
104
  absoluteEntryDir: path.resolve(dir),
77
105
  isAutoMount: true,
78
- customBootstrap
106
+ customBootstrap,
107
+ customEntry: enableCustomEntry ? Boolean(customEntryFile) : false
108
+ }
109
+ ];
110
+ }
111
+ if (enableCustomEntry && customEntryFile) {
112
+ return [
113
+ 2,
114
+ {
115
+ entryName,
116
+ isMainEntry: false,
117
+ entry: customEntryFile,
118
+ customServerEntry,
119
+ absoluteEntryDir: path.resolve(dir),
120
+ isAutoMount: false,
121
+ customEntry: Boolean(customEntryFile)
79
122
  }
80
123
  ];
81
124
  }
@@ -90,12 +133,12 @@ var scanDir = function(hookRunners, dirs) {
90
133
  };
91
134
  var getFileSystemEntry = function() {
92
135
  var _ref = _async_to_generator(function(hookRunners, appContext, config) {
93
- var appDirectory, _config_source, entriesDir, disableEntryDirs, disabledDirs, src, dirs;
136
+ var appDirectory, _config_source, entriesDir, disableEntryDirs, enableCustomEntry, disabledDirs, src, dirs;
94
137
  return _ts_generator(this, function(_state) {
95
138
  switch (_state.label) {
96
139
  case 0:
97
140
  appDirectory = appContext.appDirectory;
98
- _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
141
+ _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs, enableCustomEntry = _config_source.enableCustomEntry;
99
142
  disabledDirs = [];
100
143
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
101
144
  disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
@@ -115,7 +158,7 @@ var getFileSystemEntry = function() {
115
158
  ];
116
159
  return [
117
160
  4,
118
- isBundleEntry(hookRunners, src)
161
+ isBundleEntry(hookRunners, src, enableCustomEntry)
119
162
  ];
120
163
  case 1:
121
164
  if (_state.sent()) {
@@ -123,7 +166,7 @@ var getFileSystemEntry = function() {
123
166
  2,
124
167
  scanDir(hookRunners, [
125
168
  src
126
- ])
169
+ ], enableCustomEntry)
127
170
  ];
128
171
  }
129
172
  dirs = [];
@@ -144,7 +187,7 @@ var getFileSystemEntry = function() {
144
187
  ];
145
188
  return [
146
189
  4,
147
- isBundleEntry(hookRunners, file)
190
+ isBundleEntry(hookRunners, file, enableCustomEntry)
148
191
  ];
149
192
  case 1:
150
193
  _tmp = _state2.sent();
@@ -168,7 +211,7 @@ var getFileSystemEntry = function() {
168
211
  _state.sent();
169
212
  return [
170
213
  2,
171
- scanDir(hookRunners, dirs)
214
+ scanDir(hookRunners, dirs, enableCustomEntry)
172
215
  ];
173
216
  case 3:
174
217
  throw Error("source.entriesDir accept a directory.");
@@ -4,28 +4,29 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
5
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
6
  import * as path from "path";
7
- import { createDebugger, findExists, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
7
+ import { createDebugger, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
8
8
  import { printInstructions } from "../../utils/printInstructions";
9
- import { generateRoutes, getPathWithoutExt } from "../../utils/routes";
9
+ import { generateRoutes } from "../../utils/routes";
10
10
  import { emitResolvedConfig } from "../../utils/config";
11
11
  import { getSelectedEntries } from "../../utils/getSelectedEntries";
12
12
  import { initialNormalizedConfig } from "../../config";
13
13
  import { createBuilderGenerator } from "../../builder";
14
- import { checkIsBuildCommands, parseModule, replaceWithAlias } from "./utils";
15
- import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
16
- import { generateIndexCode } from "./generateCode";
14
+ import { checkIsBuildCommands } from "./utils";
17
15
  var debug = createDebugger("plugin-analyze");
18
16
  function analyze_default(param) {
19
17
  var bundler = param.bundler;
20
18
  return {
21
19
  name: "@modern-js/plugin-analyze",
20
+ post: [
21
+ "@modern-js/runtime"
22
+ ],
22
23
  setup: function(api) {
23
24
  var pagesDir = [];
24
25
  var nestedRouteEntries = [];
25
26
  return {
26
27
  prepare: function prepare() {
27
28
  return _async_to_generator(function() {
28
- var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, _, _tmp, initialRoutes, routes1, importsStatemets, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
29
+ var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, getHtmlTemplate, entrypoints, _, _tmp, initialRoutes, routes1, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
29
30
  return _ts_generator(this, function(_state) {
30
31
  switch (_state.label) {
31
32
  case 0:
@@ -78,15 +79,14 @@ function analyze_default(param) {
78
79
  Promise.all([
79
80
  import("./getBundleEntry"),
80
81
  import("./getServerRoutes"),
81
- import("./generateCode"),
82
82
  import("./getHtmlTemplate")
83
83
  ])
84
84
  ];
85
85
  case 5:
86
86
  _ref = _sliced_to_array.apply(void 0, [
87
87
  _state.sent(),
88
- 4
89
- ]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes, generateCode = _ref[2].generateCode, getHtmlTemplate = _ref[3].getHtmlTemplate;
88
+ 3
89
+ ]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes, getHtmlTemplate = _ref[2].getHtmlTemplate;
90
90
  _ = hookRunners.modifyEntrypoints;
91
91
  _tmp = {};
92
92
  return [
@@ -129,12 +129,6 @@ function analyze_default(param) {
129
129
  }).filter(function(entry2) {
130
130
  return entry2 && !path.extname(entry2);
131
131
  }).concat(nestedRouteEntries);
132
- return [
133
- 4,
134
- generateCode(appContext, resolvedConfig, entrypoints, api)
135
- ];
136
- case 9:
137
- importsStatemets = _state.sent().importsStatemets;
138
132
  return [
139
133
  4,
140
134
  getHtmlTemplate(entrypoints, api, {
@@ -142,14 +136,14 @@ function analyze_default(param) {
142
136
  config: resolvedConfig
143
137
  })
144
138
  ];
145
- case 10:
139
+ case 9:
146
140
  htmlTemplates = _state.sent();
147
141
  debug("html templates: %o", htmlTemplates);
148
142
  return [
149
143
  4,
150
144
  hookRunners.addDefineTypes()
151
145
  ];
152
- case 11:
146
+ case 10:
153
147
  _state.sent();
154
148
  debug("add Define Types");
155
149
  checkedEntries = entrypoints.map(function(point) {
@@ -158,17 +152,17 @@ function analyze_default(param) {
158
152
  if (!isDevCommand())
159
153
  return [
160
154
  3,
161
- 13
155
+ 12
162
156
  ];
163
157
  entry = minimist(getArgv()).entry;
164
158
  return [
165
159
  4,
166
160
  getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
167
161
  ];
168
- case 12:
162
+ case 11:
169
163
  checkedEntries = _state.sent();
170
- _state.label = 13;
171
- case 13:
164
+ _state.label = 12;
165
+ case 12:
172
166
  appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
173
167
  entrypoints,
174
168
  checkedEntries,
@@ -182,6 +176,14 @@ function analyze_default(param) {
182
176
  3,
183
177
  16
184
178
  ];
179
+ return [
180
+ 4,
181
+ hookRunners.generateEntryCode({
182
+ entrypoints
183
+ })
184
+ ];
185
+ case 13:
186
+ _state.sent();
185
187
  normalizedConfig = api.useResolvedConfigContext();
186
188
  return [
187
189
  4,
@@ -291,26 +293,13 @@ function analyze_default(param) {
291
293
  case 0:
292
294
  bundlerConfigs = param2.bundlerConfigs;
293
295
  hookRunners2 = api.useHookRunners();
294
- return [
295
- 4,
296
- generateIndexCode({
297
- appContext,
298
- config: resolvedConfig,
299
- entrypoints,
300
- api,
301
- importsStatemets,
302
- bundlerConfigs
303
- })
304
- ];
305
- case 1:
306
- _state2.sent();
307
296
  return [
308
297
  4,
309
298
  hookRunners2.beforeCreateCompiler({
310
299
  bundlerConfigs
311
300
  })
312
301
  ];
313
- case 2:
302
+ case 1:
314
303
  _state2.sent();
315
304
  return [
316
305
  2
@@ -375,99 +364,7 @@ function analyze_default(param) {
375
364
  return {
376
365
  resolved: config
377
366
  };
378
- },
379
- modifyEntryImports: (
380
- // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
381
- function modifyEntryImports(param2) {
382
- var entrypoint = param2.entrypoint, imports = param2.imports;
383
- return _async_to_generator(function() {
384
- var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, _ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
385
- return _ts_generator(this, function(_state) {
386
- switch (_state.label) {
387
- case 0:
388
- appContext = api.useAppContext();
389
- srcDirectory = appContext.srcDirectory, internalSrcAlias = appContext.internalSrcAlias;
390
- fileSystemRoutes = entrypoint.fileSystemRoutes, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
391
- if (!(fileSystemRoutes && nestedRoutesEntry))
392
- return [
393
- 3,
394
- 3
395
- ];
396
- rootLayoutPath = path.join(nestedRoutesEntry, "layout");
397
- rootLayoutFile = findExists([
398
- ".js",
399
- ".ts",
400
- ".jsx",
401
- ".tsx"
402
- ].map(function(ext) {
403
- return "".concat(rootLayoutPath).concat(ext);
404
- }));
405
- if (!rootLayoutFile)
406
- return [
407
- 3,
408
- 3
409
- ];
410
- return [
411
- 4,
412
- fs.readFile(rootLayoutFile)
413
- ];
414
- case 1:
415
- rootLayoutBuffer = _state.sent();
416
- rootLayout = rootLayoutBuffer.toString();
417
- return [
418
- 4,
419
- parseModule({
420
- source: rootLayout.toString(),
421
- filename: rootLayoutFile
422
- })
423
- ];
424
- case 2:
425
- _ref = _sliced_to_array.apply(void 0, [
426
- _state.sent(),
427
- 2
428
- ]), moduleExports = _ref[1];
429
- hasAppConfig = moduleExports.some(function(e) {
430
- return e.n === APP_CONFIG_NAME;
431
- });
432
- generateLayoutPath = getPathWithoutExt(replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias));
433
- if (hasAppConfig) {
434
- imports.push({
435
- value: generateLayoutPath,
436
- specifiers: [
437
- {
438
- imported: APP_CONFIG_NAME
439
- }
440
- ]
441
- });
442
- }
443
- hasAppInit = moduleExports.some(function(e) {
444
- return e.n === APP_INIT_EXPORTED;
445
- });
446
- if (hasAppInit) {
447
- imports.push({
448
- value: generateLayoutPath,
449
- specifiers: [
450
- {
451
- imported: APP_INIT_EXPORTED,
452
- local: APP_INIT_IMPORTED
453
- }
454
- ]
455
- });
456
- }
457
- _state.label = 3;
458
- case 3:
459
- return [
460
- 2,
461
- {
462
- entrypoint,
463
- imports
464
- }
465
- ];
466
- }
467
- });
468
- })();
469
- }
470
- )
367
+ }
471
368
  };
472
369
  }
473
370
  };
@@ -1,22 +1,6 @@
1
- import { APP_CONFIG_NAME } from "./constants";
2
- var index = function(param) {
3
- var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
4
- return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
5
- };
6
- var renderFunction = function(param) {
7
- var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes = param.fileSystemRoutes, customRuntimeConfig = param.customRuntimeConfig;
8
- var bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
9
- var runtimePlugins = "...(runtimeConfig?.plugins || []),";
10
- return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param2) {
11
- var name = param2.name, options = param2.options, args = param2.args;
12
- return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
13
- }).join("\n"), "\n ").concat(customRuntimeConfig ? runtimePlugins : "", "\n ]\n })(").concat(fileSystemRoutes ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper, () => ".concat(bootstrap, ");") : "".concat(bootstrap, ";"), "\n }\n\n return AppWrapper\n");
14
- };
15
1
  var html = function(partials) {
16
2
  return "\n<!DOCTYPE html>\n<html>\n<head>\n\n ".concat(partials.top.join("\n"), "\n\n ").concat(partials.head.join("\n"), '\n\n</head>\n\n<body>\n <div id="<%= mountId %>"><!--<?- html ?>--></div>\n ').concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
17
3
  };
18
4
  export {
19
- html,
20
- index,
21
- renderFunction
5
+ html
22
6
  };
@@ -3,10 +3,9 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
- import { isReact18, normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
6
+ import { normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
7
7
  import { transform } from "esbuild";
8
8
  import { parse } from "es-module-lexer";
9
- import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
10
9
  var walkDirectory = function(dir) {
11
10
  return fs.readdirSync(dir).reduce(function(previous, filename) {
12
11
  var filePath = path.join(dir, filename);
@@ -19,90 +18,6 @@ var walkDirectory = function(dir) {
19
18
  }
20
19
  }, []);
21
20
  };
22
- var getDefaultImports = function(param) {
23
- var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias, runtimeConfigFile = param.runtimeConfigFile, customRuntimeConfig = param.customRuntimeConfig;
24
- var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes, customBootstrap = entrypoint.customBootstrap, entry = entrypoint.entry;
25
- var imports = [
26
- {
27
- specifiers: [
28
- {
29
- local: "React"
30
- }
31
- ],
32
- value: "react"
33
- },
34
- {
35
- specifiers: [
36
- {
37
- local: "ReactDOM"
38
- }
39
- ],
40
- value: isReact18(path.join(appDirectory)) ? "react-dom/client" : "react-dom"
41
- },
42
- {
43
- specifiers: [
44
- {
45
- imported: "createApp"
46
- },
47
- {
48
- imported: "bootstrap"
49
- }
50
- ],
51
- value: "@modern-js/runtime"
52
- },
53
- customBootstrap && {
54
- specifiers: [
55
- {
56
- local: "customBootstrap"
57
- }
58
- ],
59
- value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
60
- }
61
- ].filter(Boolean);
62
- if (fileSystemRoutes) {
63
- var route = {
64
- specifiers: [
65
- {
66
- imported: "routes"
67
- }
68
- ],
69
- value: normalizeToPosixPath("".concat(internalDirAlias, "/").concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME.replace(".js", "")))
70
- };
71
- if (fileSystemRoutes.globalApp) {
72
- imports.push({
73
- specifiers: [
74
- {
75
- local: "App"
76
- }
77
- ],
78
- value: normalizeToPosixPath(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
79
- });
80
- } else {
81
- route.initialize = "const App = false;";
82
- }
83
- imports.push(route);
84
- } else {
85
- imports.push({
86
- specifiers: [
87
- {
88
- local: "App"
89
- }
90
- ],
91
- value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
92
- });
93
- }
94
- if (customRuntimeConfig) {
95
- imports.push({
96
- specifiers: [
97
- {
98
- local: "runtimeConfig"
99
- }
100
- ],
101
- value: path.join(internalSrcAlias, runtimeConfigFile || "")
102
- });
103
- }
104
- return imports;
105
- };
106
21
  var replaceWithAlias = function(base, filePath, alias) {
107
22
  if (filePath.includes(base)) {
108
23
  return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
@@ -178,7 +93,6 @@ var isSubDirOrEqual = function(parent, child) {
178
93
  };
179
94
  export {
180
95
  checkIsBuildCommands,
181
- getDefaultImports,
182
96
  getServerCombinedModueFile,
183
97
  isSubDirOrEqual,
184
98
  parseModule,
@@ -0,0 +1,60 @@
1
+ import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
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"));
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
+ };
@@ -1,14 +1,15 @@
1
1
  import { createUniBuilder } from "@modern-js/uni-builder";
2
+ import { mergeRsbuildConfig } from "@rsbuild/core";
2
3
  import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
3
- import { getBuilderTargets } from "./getBuilderTargets";
4
- import { createBuilderOptions } from "./createBuilderOptions";
4
+ import { getBuilderEnvironments } from "./getBuilderEnvironments";
5
5
  async function generateBuilder(options, bundlerType) {
6
6
  const { normalizedConfig, appContext } = options;
7
7
  const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
8
- const target = getBuilderTargets(normalizedConfig);
9
- const builderOptions = createBuilderOptions(target, appContext);
8
+ const environments = getBuilderEnvironments(normalizedConfig, appContext);
9
+ builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
10
10
  const builder = await createUniBuilder({
11
- ...builderOptions,
11
+ cwd: appContext.appDirectory,
12
+ frameworkConfigPath: appContext.configFile || void 0,
12
13
  bundlerType,
13
14
  config: builderConfig
14
15
  });
@@ -1,19 +1,12 @@
1
1
  import path from "path";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
3
  const builderPluginAdapterBasic = () => ({
3
4
  name: "builder-plugin-adapter-modern-basic",
4
5
  setup(api) {
5
- api.modifyBundlerChain((chain, { target, CHAIN_ID }) => {
6
- if (target === "node") {
7
- chain.name("server");
8
- } else if (target === "service-worker") {
9
- chain.name("service-worker");
10
- } else if (target === "web-worker") {
11
- chain.name("worker");
12
- } else {
13
- chain.name("client");
14
- }
15
- if (target === "node" || target === "service-worker") {
16
- applyNodeCompat(target, chain);
6
+ api.modifyBundlerChain((chain, { target, CHAIN_ID, environment }) => {
7
+ const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
8
+ if (target === "node" || isServiceWorker) {
9
+ applyNodeCompat(isServiceWorker, chain);
17
10
  }
18
11
  if (target === "web") {
19
12
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
@@ -24,7 +17,7 @@ const builderPluginAdapterBasic = () => ({
24
17
  });
25
18
  }
26
19
  });
27
- function applyNodeCompat(target, chain) {
20
+ function applyNodeCompat(isServiceWorker, chain) {
28
21
  const nodeExts = [
29
22
  ".node.js",
30
23
  ".node.jsx",
@@ -44,7 +37,7 @@ function applyNodeCompat(target, chain) {
44
37
  for (const ext of nodeExts) {
45
38
  chain.resolve.extensions.prepend(ext);
46
39
  }
47
- if (target === "service-worker") {
40
+ if (isServiceWorker) {
48
41
  for (const ext of webWorkerExts) {
49
42
  chain.resolve.extensions.prepend(ext);
50
43
  }