@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
  20. package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
  21. package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
  22. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  23. package/dist/cjs/plugins/serverBuild.js +10 -4
  24. package/dist/cjs/utils/createServer.js +1 -1
  25. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  28. package/dist/esm/commands/build.js +16 -9
  29. package/dist/esm/commands/deploy.js +2 -2
  30. package/dist/esm/commands/dev.js +13 -9
  31. package/dist/esm/commands/index.js +411 -3
  32. package/dist/esm/commands/serve.js +12 -8
  33. package/dist/esm/hooks.js +5 -0
  34. package/dist/esm/index.js +12 -394
  35. package/dist/esm/plugins/analyze/constants.js +24 -0
  36. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  39. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  40. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  41. package/dist/esm/plugins/analyze/templates.js +22 -0
  42. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -3
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
  46. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  47. package/dist/esm/plugins/serverBuild.js +13 -6
  48. package/dist/esm/utils/createServer.js +2 -2
  49. package/dist/esm/utils/loadPlugins.js +64 -0
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  51. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  52. package/dist/esm-node/commands/build.js +2 -0
  53. package/dist/esm-node/commands/deploy.js +2 -2
  54. package/dist/esm-node/commands/dev.js +11 -7
  55. package/dist/esm-node/commands/index.js +92 -3
  56. package/dist/esm-node/commands/serve.js +10 -6
  57. package/dist/esm-node/hooks.js +5 -0
  58. package/dist/esm-node/index.js +12 -79
  59. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  60. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  61. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  63. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  64. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  65. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  66. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  67. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
  68. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
  69. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
  70. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  71. package/dist/esm-node/plugins/serverBuild.js +11 -5
  72. package/dist/esm-node/utils/createServer.js +2 -2
  73. package/dist/esm-node/utils/loadPlugins.js +21 -0
  74. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  75. package/dist/types/commands/index.d.ts +10 -3
  76. package/dist/types/config/initialize/inits.d.ts +1 -1
  77. package/dist/types/exports/server.d.ts +4 -0
  78. package/dist/types/index.d.ts +2 -5
  79. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  80. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  81. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  82. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  83. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  84. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  85. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  86. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  87. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  88. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  89. package/dist/types/types/hooks.d.ts +11 -1
  90. package/dist/types/utils/loadPlugins.d.ts +5 -0
  91. package/package.json +22 -22
  92. package/dist/cjs/analyze/constants.js +0 -122
  93. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  94. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  95. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  96. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  97. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  98. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  99. package/dist/cjs/analyze/templates.js +0 -444
  100. package/dist/esm/analyze/constants.js +0 -76
  101. package/dist/esm/analyze/getBundleEntry.js +0 -75
  102. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  103. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  104. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  105. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  106. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  107. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  108. package/dist/esm/analyze/nestedRoutes.js +0 -398
  109. package/dist/esm/analyze/templates.js +0 -435
  110. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  111. package/dist/esm-node/analyze/constants.js +0 -76
  112. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  113. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  114. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  115. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  116. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  117. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  118. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  119. package/dist/esm-node/analyze/templates.js +0 -405
  120. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  121. package/dist/types/analyze/constants.d.ts +0 -42
  122. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  123. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  124. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  125. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  126. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  127. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  128. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  129. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  130. package/dist/types/analyze/templates.d.ts +0 -30
  131. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  132. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  133. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  134. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  135. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  136. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  137. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  138. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -5,14 +5,13 @@ 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
7
  import { createDebugger, findExists, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
8
- import { cloneDeep } from "@modern-js/utils/lodash";
9
- import { printInstructions } from "../utils/printInstructions";
10
- import { generateRoutes, getPathWithoutExt } from "../utils/routes";
11
- import { emitResolvedConfig } from "../utils/config";
12
- import { getSelectedEntries } from "../utils/getSelectedEntries";
13
- import { initialNormalizedConfig } from "../config";
14
- import { createBuilderGenerator } from "../builder";
15
- import { checkIsBuildCommands, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
8
+ import { printInstructions } from "../../utils/printInstructions";
9
+ import { generateRoutes, getPathWithoutExt } from "../../utils/routes";
10
+ import { emitResolvedConfig } from "../../utils/config";
11
+ import { getSelectedEntries } from "../../utils/getSelectedEntries";
12
+ import { initialNormalizedConfig } from "../../config";
13
+ import { createBuilderGenerator } from "../../builder";
14
+ import { checkIsBuildCommands, parseModule, replaceWithAlias } from "./utils";
16
15
  import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
17
16
  import { generateIndexCode } from "./generateCode";
18
17
  var debug = createDebugger("plugin-analyze");
@@ -23,11 +22,10 @@ function analyze_default(param) {
23
22
  setup: function(api) {
24
23
  var pagesDir = [];
25
24
  var nestedRouteEntries = [];
26
- var originEntrypoints = [];
27
25
  return {
28
26
  prepare: function prepare() {
29
27
  return _async_to_generator(function() {
30
- var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes1, importsStatemets, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
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;
31
29
  return _ts_generator(this, function(_state) {
32
30
  switch (_state.label) {
33
31
  case 0:
@@ -89,7 +87,21 @@ function analyze_default(param) {
89
87
  _state.sent(),
90
88
  4
91
89
  ]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes, generateCode = _ref[2].generateCode, getHtmlTemplate = _ref[3].getHtmlTemplate;
92
- entrypoints = getBundleEntry(appContext, resolvedConfig);
90
+ _ = hookRunners.modifyEntrypoints;
91
+ _tmp = {};
92
+ return [
93
+ 4,
94
+ getBundleEntry(hookRunners, appContext, resolvedConfig)
95
+ ];
96
+ case 6:
97
+ return [
98
+ 4,
99
+ _.apply(hookRunners, [
100
+ (_tmp.entrypoints = _state.sent(), _tmp)
101
+ ])
102
+ ];
103
+ case 7:
104
+ entrypoints = _state.sent().entrypoints;
93
105
  debug("entrypoints: %o", entrypoints);
94
106
  initialRoutes = getServerRoutes(entrypoints, {
95
107
  appContext,
@@ -101,7 +113,7 @@ function analyze_default(param) {
101
113
  routes: initialRoutes
102
114
  })
103
115
  ];
104
- case 6:
116
+ case 8:
105
117
  routes1 = _state.sent().routes;
106
118
  debug("server routes: %o", routes1);
107
119
  appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
@@ -117,12 +129,11 @@ function analyze_default(param) {
117
129
  }).filter(function(entry2) {
118
130
  return entry2 && !path.extname(entry2);
119
131
  }).concat(nestedRouteEntries);
120
- originEntrypoints = cloneDeep(entrypoints);
121
132
  return [
122
133
  4,
123
134
  generateCode(appContext, resolvedConfig, entrypoints, api)
124
135
  ];
125
- case 7:
136
+ case 9:
126
137
  importsStatemets = _state.sent().importsStatemets;
127
138
  return [
128
139
  4,
@@ -131,14 +142,14 @@ function analyze_default(param) {
131
142
  config: resolvedConfig
132
143
  })
133
144
  ];
134
- case 8:
145
+ case 10:
135
146
  htmlTemplates = _state.sent();
136
147
  debug("html templates: %o", htmlTemplates);
137
148
  return [
138
149
  4,
139
150
  hookRunners.addDefineTypes()
140
151
  ];
141
- case 9:
152
+ case 11:
142
153
  _state.sent();
143
154
  debug("add Define Types");
144
155
  checkedEntries = entrypoints.map(function(point) {
@@ -147,17 +158,17 @@ function analyze_default(param) {
147
158
  if (!isDevCommand())
148
159
  return [
149
160
  3,
150
- 11
161
+ 13
151
162
  ];
152
163
  entry = minimist(getArgv()).entry;
153
164
  return [
154
165
  4,
155
166
  getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
156
167
  ];
157
- case 10:
168
+ case 12:
158
169
  checkedEntries = _state.sent();
159
- _state.label = 11;
160
- case 11:
170
+ _state.label = 13;
171
+ case 13:
161
172
  appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
162
173
  entrypoints,
163
174
  checkedEntries,
@@ -169,14 +180,14 @@ function analyze_default(param) {
169
180
  if (!checkIsBuildCommands())
170
181
  return [
171
182
  3,
172
- 14
183
+ 16
173
184
  ];
174
185
  normalizedConfig = api.useResolvedConfigContext();
175
186
  return [
176
187
  4,
177
188
  createBuilderGenerator(bundler)
178
189
  ];
179
- case 12:
190
+ case 14:
180
191
  createBuilderForModern = _state.sent();
181
192
  return [
182
193
  4,
@@ -185,7 +196,7 @@ function analyze_default(param) {
185
196
  appContext
186
197
  })
187
198
  ];
188
- case 13:
199
+ case 15:
189
200
  builder = _state.sent();
190
201
  builder.onBeforeBuild(function() {
191
202
  var _ref2 = _async_to_generator(function(param2) {
@@ -215,7 +226,7 @@ function analyze_default(param) {
215
226
  }
216
227
  });
217
228
  });
218
- return function(_) {
229
+ return function(_2) {
219
230
  return _ref2.apply(this, arguments);
220
231
  };
221
232
  }());
@@ -247,7 +258,7 @@ function analyze_default(param) {
247
258
  }
248
259
  });
249
260
  });
250
- return function(_) {
261
+ return function(_2) {
251
262
  return _ref2.apply(this, arguments);
252
263
  };
253
264
  }());
@@ -268,7 +279,7 @@ function analyze_default(param) {
268
279
  ];
269
280
  });
270
281
  });
271
- return function(_) {
282
+ return function(_2) {
272
283
  return _ref2.apply(this, arguments);
273
284
  };
274
285
  }());
@@ -307,7 +318,7 @@ function analyze_default(param) {
307
318
  }
308
319
  });
309
320
  });
310
- return function(_) {
321
+ return function(_2) {
311
322
  return _ref2.apply(this, arguments);
312
323
  };
313
324
  }());
@@ -333,7 +344,7 @@ function analyze_default(param) {
333
344
  }
334
345
  });
335
346
  });
336
- return function(_) {
347
+ return function(_2) {
337
348
  return _ref2.apply(this, arguments);
338
349
  };
339
350
  }());
@@ -342,8 +353,8 @@ function analyze_default(param) {
342
353
  builder
343
354
  });
344
355
  api.setAppContext(appContext);
345
- _state.label = 14;
346
- case 14:
356
+ _state.label = 16;
357
+ case 16:
347
358
  return [
348
359
  2
349
360
  ];
@@ -456,46 +467,7 @@ function analyze_default(param) {
456
467
  });
457
468
  })();
458
469
  }
459
- ),
460
- fileChange: function fileChange(e) {
461
- return _async_to_generator(function() {
462
- var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
463
- return _ts_generator(this, function(_state) {
464
- switch (_state.label) {
465
- case 0:
466
- appContext = api.useAppContext();
467
- appDirectory = appContext.appDirectory;
468
- filename = e.filename, eventType = e.eventType;
469
- isPageFile = function(name) {
470
- return pagesDir.some(function(pageDir) {
471
- return name.includes(pageDir);
472
- });
473
- };
474
- absoluteFilePath = path.resolve(appDirectory, filename);
475
- isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
476
- if (!(isRouteComponent && (eventType === "add" || eventType === "unlink")))
477
- return [
478
- 3,
479
- 2
480
- ];
481
- resolvedConfig = api.useResolvedConfigContext();
482
- return [
483
- 4,
484
- import("./generateCode")
485
- ];
486
- case 1:
487
- generateCode = _state.sent().generateCode;
488
- entrypoints = cloneDeep(originEntrypoints);
489
- generateCode(appContext, resolvedConfig, entrypoints, api);
490
- _state.label = 2;
491
- case 2:
492
- return [
493
- 2
494
- ];
495
- }
496
- });
497
- })();
498
- }
470
+ )
499
471
  };
500
472
  }
501
473
  };
@@ -0,0 +1,22 @@
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
+ var html = function(partials) {
16
+ 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
+ };
18
+ export {
19
+ html,
20
+ index,
21
+ renderFunction
22
+ };
@@ -1,13 +1,12 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
4
  import fs from "fs";
6
5
  import path from "path";
7
- import { isReact18, normalizeToPosixPath, fs as fse, getCommand } from "@modern-js/utils";
6
+ import { isReact18, normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
8
7
  import { transform } from "esbuild";
9
8
  import { parse } from "es-module-lexer";
10
- import { ACTION_EXPORT_NAME, FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME } from "./constants";
9
+ import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
11
10
  var walkDirectory = function(dir) {
12
11
  return fs.readdirSync(dir).reduce(function(previous, filename) {
13
12
  var filePath = path.join(dir, filename);
@@ -21,7 +20,7 @@ var walkDirectory = function(dir) {
21
20
  }, []);
22
21
  };
23
22
  var getDefaultImports = function(param) {
24
- var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias;
23
+ var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias, runtimeConfigFile = param.runtimeConfigFile, customRuntimeConfig = param.customRuntimeConfig;
25
24
  var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes, customBootstrap = entrypoint.customBootstrap, entry = entrypoint.entry;
26
25
  var imports = [
27
26
  {
@@ -92,21 +91,17 @@ var getDefaultImports = function(param) {
92
91
  value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
93
92
  });
94
93
  }
95
- return imports;
96
- };
97
- var isPageComponentFile = function(filePath) {
98
- if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
99
- return false;
100
- }
101
- if ([
102
- ".js",
103
- ".jsx",
104
- ".ts",
105
- ".tsx"
106
- ].includes(path.extname(filePath))) {
107
- return true;
94
+ if (customRuntimeConfig) {
95
+ imports.push({
96
+ specifiers: [
97
+ {
98
+ local: "runtimeConfig"
99
+ }
100
+ ],
101
+ value: path.join(internalSrcAlias, runtimeConfigFile || "")
102
+ });
108
103
  }
109
- return false;
104
+ return imports;
110
105
  };
111
106
  var replaceWithAlias = function(base, filePath, alias) {
112
107
  if (filePath.includes(base)) {
@@ -158,119 +153,6 @@ var parseModule = function() {
158
153
  return _ref.apply(this, arguments);
159
154
  };
160
155
  }();
161
- var hasLoader = function() {
162
- var _ref = _async_to_generator(function(filename, source) {
163
- var content, _ref2, moduleExports;
164
- return _ts_generator(this, function(_state) {
165
- switch (_state.label) {
166
- case 0:
167
- content = source;
168
- if (!!source)
169
- return [
170
- 3,
171
- 2
172
- ];
173
- return [
174
- 4,
175
- fse.readFile(filename, "utf-8")
176
- ];
177
- case 1:
178
- content = _state.sent().toString();
179
- _state.label = 2;
180
- case 2:
181
- if (!content)
182
- return [
183
- 3,
184
- 4
185
- ];
186
- return [
187
- 4,
188
- parseModule({
189
- source: content.toString(),
190
- filename
191
- })
192
- ];
193
- case 3:
194
- _ref2 = _sliced_to_array.apply(void 0, [
195
- _state.sent(),
196
- 2
197
- ]), moduleExports = _ref2[1];
198
- return [
199
- 2,
200
- moduleExports.some(function(e) {
201
- return e.n === LOADER_EXPORT_NAME;
202
- })
203
- ];
204
- case 4:
205
- return [
206
- 2,
207
- false
208
- ];
209
- }
210
- });
211
- });
212
- return function hasLoader2(filename, source) {
213
- return _ref.apply(this, arguments);
214
- };
215
- }();
216
- var hasAction = function() {
217
- var _ref = _async_to_generator(function(filename, source) {
218
- var content, _ref2, moduleExports;
219
- return _ts_generator(this, function(_state) {
220
- switch (_state.label) {
221
- case 0:
222
- content = source;
223
- if (!!source)
224
- return [
225
- 3,
226
- 2
227
- ];
228
- return [
229
- 4,
230
- fse.readFile(filename, "utf-8")
231
- ];
232
- case 1:
233
- content = _state.sent().toString();
234
- _state.label = 2;
235
- case 2:
236
- if (!content)
237
- return [
238
- 3,
239
- 4
240
- ];
241
- return [
242
- 4,
243
- parseModule({
244
- source: content.toString(),
245
- filename
246
- })
247
- ];
248
- case 3:
249
- _ref2 = _sliced_to_array.apply(void 0, [
250
- _state.sent(),
251
- 2
252
- ]), moduleExports = _ref2[1];
253
- return [
254
- 2,
255
- moduleExports.some(function(e) {
256
- return e.n === ACTION_EXPORT_NAME;
257
- })
258
- ];
259
- case 4:
260
- return [
261
- 2,
262
- false
263
- ];
264
- }
265
- });
266
- });
267
- return function hasAction2(filename, source) {
268
- return _ref.apply(this, arguments);
269
- };
270
- }();
271
- var getServerLoadersFile = function(internalDirectory, entryName) {
272
- return path.join(internalDirectory, entryName, "route-server-loaders.js");
273
- };
274
156
  var getServerCombinedModueFile = function(internalDirectory, entryName) {
275
157
  return path.join(internalDirectory, entryName, "server-loader-combined.js");
276
158
  };
@@ -298,10 +180,6 @@ export {
298
180
  checkIsBuildCommands,
299
181
  getDefaultImports,
300
182
  getServerCombinedModueFile,
301
- getServerLoadersFile,
302
- hasAction,
303
- hasLoader,
304
- isPageComponentFile,
305
183
  isSubDirOrEqual,
306
184
  parseModule,
307
185
  replaceWithAlias,
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
4
+ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
5
5
  import { isMainEntry } from "../../../utils/routes";
6
6
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
7
7
  import { handleDependencies } from "../dependencies";
@@ -111,8 +111,10 @@ function _cleanDistDirectory() {
111
111
  return _cleanDistDirectory.apply(this, arguments);
112
112
  }
113
113
  var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
114
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
115
- var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
114
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins;
115
+ var plugins = serverPlugins.map(function(plugin) {
116
+ return plugin.name;
117
+ });
116
118
  var netlifyOutput = path.join(appDirectory, ".netlify");
117
119
  var funcsDirectory = path.join(netlifyOutput, "functions");
118
120
  var entryFilePath = path.join(funcsDirectory, "index.js");
@@ -1,12 +1,14 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins, chalk } from "@modern-js/utils";
4
+ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, chalk } from "@modern-js/utils";
5
5
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
6
6
  import { handleDependencies } from "../dependencies";
7
7
  var createNodePreset = function(appContext, config) {
8
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins;
9
- var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
8
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverPlugins = appContext.serverPlugins;
9
+ var plugins = serverPlugins.map(function(plugin) {
10
+ return plugin.name;
11
+ });
10
12
  var outputDirectory = path.join(appDirectory, ".output");
11
13
  var staticDirectory = path.join(outputDirectory, "static");
12
14
  var entryFilePath = path.join(outputDirectory, "index.js");
@@ -1,13 +1,15 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
4
+ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
5
5
  import { isMainEntry } from "../../../utils/routes";
6
6
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
7
7
  import { handleDependencies } from "../dependencies";
8
8
  var createVercelPreset = function(appContext, modernConfig, needModernServer) {
9
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
10
- var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
9
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins;
10
+ var plugins = serverPlugins.map(function(plugin) {
11
+ return plugin.name;
12
+ });
11
13
  var vercelOutput = path.join(appDirectory, ".vercel");
12
14
  var outputDirectory = path.join(vercelOutput, "output");
13
15
  var funcsDirectory = path.join(outputDirectory, "functions", "index.func");
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
6
- import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "../config";
6
+ import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "../../config";
7
7
  function initialize_default(param) {
8
8
  var bundler = param.bundler;
9
9
  return {
@@ -2,12 +2,19 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
- import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
5
+ import { SERVER_DIR, SHARED_DIR, getMeta } from "@modern-js/utils";
6
6
  import { compile } from "@modern-js/server-utils";
7
7
  var TS_CONFIG_FILENAME = "tsconfig.json";
8
8
  function checkHasCache(appDir) {
9
- var tsFilepath = path.resolve(appDir, "server", "cache.ts");
10
- var jsfilepath = path.resolve(appDir, "server", "cache.js");
9
+ var tsFilepath = path.resolve(appDir, SERVER_DIR, "cache.ts");
10
+ var jsfilepath = path.resolve(appDir, SERVER_DIR, "cache.js");
11
+ return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
12
+ }
13
+ function checkHasConfig(appDir) {
14
+ var metaName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "modern-js";
15
+ var meta = getMeta(metaName);
16
+ var tsFilepath = path.resolve(appDir, SERVER_DIR, "".concat(meta, ".server.ts"));
17
+ var jsfilepath = path.resolve(appDir, SERVER_DIR, "".concat(meta, ".server.js"));
11
18
  return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
12
19
  }
13
20
  function serverBuild_default() {
@@ -17,12 +24,12 @@ function serverBuild_default() {
17
24
  return {
18
25
  afterBuild: function afterBuild() {
19
26
  return _async_to_generator(function() {
20
- var _api_useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
27
+ var _api_useAppContext, appDirectory, distDirectory, metaName, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
21
28
  return _ts_generator(this, function(_state) {
22
29
  switch (_state.label) {
23
30
  case 0:
24
- _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
25
- if (!checkHasCache(appDirectory)) {
31
+ _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, metaName = _api_useAppContext.metaName;
32
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
26
33
  return [
27
34
  2
28
35
  ];
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { createDevServer } from "@modern-js/server";
4
- import { initProdMiddlewares } from "@modern-js/prod-server";
4
+ import { applyPlugins } from "@modern-js/prod-server";
5
5
  var server = null;
6
6
  var getServer = function() {
7
7
  return server;
@@ -35,7 +35,7 @@ var createServer = function() {
35
35
  }
36
36
  return [
37
37
  4,
38
- createDevServer(options, initProdMiddlewares)
38
+ createDevServer(options, applyPlugins)
39
39
  ];
40
40
  case 1:
41
41
  server = _state.sent();
@@ -0,0 +1,64 @@
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 { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
6
+ function getServerPlugins(api) {
7
+ return _getServerPlugins.apply(this, arguments);
8
+ }
9
+ function _getServerPlugins() {
10
+ _getServerPlugins = _async_to_generator(function(api) {
11
+ var runner, plugins;
12
+ return _ts_generator(this, function(_state) {
13
+ switch (_state.label) {
14
+ case 0:
15
+ runner = api.useHookRunners();
16
+ return [
17
+ 4,
18
+ runner._internalServerPlugins({
19
+ plugins: []
20
+ })
21
+ ];
22
+ case 1:
23
+ plugins = _state.sent().plugins;
24
+ api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
25
+ serverPlugins: plugins
26
+ }));
27
+ return [
28
+ 2,
29
+ plugins
30
+ ];
31
+ }
32
+ });
33
+ });
34
+ return _getServerPlugins.apply(this, arguments);
35
+ }
36
+ function loadServerPlugins(api, appDirectory) {
37
+ return _loadServerPlugins.apply(this, arguments);
38
+ }
39
+ function _loadServerPlugins() {
40
+ _loadServerPlugins = _async_to_generator(function(api, appDirectory) {
41
+ var plugins, instances;
42
+ return _ts_generator(this, function(_state) {
43
+ switch (_state.label) {
44
+ case 0:
45
+ return [
46
+ 4,
47
+ getServerPlugins(api)
48
+ ];
49
+ case 1:
50
+ plugins = _state.sent();
51
+ instances = loadServerPluginInstances(plugins, appDirectory);
52
+ return [
53
+ 2,
54
+ instances
55
+ ];
56
+ }
57
+ });
58
+ });
59
+ return _loadServerPlugins.apply(this, arguments);
60
+ }
61
+ export {
62
+ getServerPlugins,
63
+ loadServerPlugins
64
+ };
@@ -1,7 +1,8 @@
1
- import { isHtmlDisabled, createVirtualModule } from "@rsbuild/shared";
1
+ import { isHtmlDisabled } from "@rsbuild/shared";
2
2
  import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
3
3
  import { template as lodashTemplate } from "@modern-js/utils/lodash";
4
4
  import { BottomTemplatePlugin } from "../bundlerPlugins";
5
+ const createVirtualModule = (content) => `data:text/javascript,${content}`;
5
6
  const builderPluginAdapterHtml = (options) => ({
6
7
  name: "builder-plugin-adapter-modern-html",
7
8
  setup(api) {