@modern-js/app-tools 2.64.0 → 2.64.2

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 (50) hide show
  1. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -0
  2. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -0
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  5. package/dist/cjs/commands/dev.js +12 -3
  6. package/dist/cjs/commands/index.js +2 -2
  7. package/dist/cjs/commands/serve.js +4 -4
  8. package/dist/cjs/esm/register-esm.mjs +0 -6
  9. package/dist/cjs/index.js +4 -4
  10. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +2 -2
  11. package/dist/cjs/plugins/analyze/getServerRoutes.js +5 -3
  12. package/dist/cjs/run/index.js +3 -3
  13. package/dist/cjs/utils/generateWatchFiles.js +2 -2
  14. package/dist/cjs/utils/isAutoLoadPlugins.js +2 -1
  15. package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -0
  16. package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -2
  17. package/dist/esm/builder/generator/index.js +2 -0
  18. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  19. package/dist/esm/commands/dev.js +11 -5
  20. package/dist/esm/commands/index.js +3 -3
  21. package/dist/esm/commands/serve.js +5 -5
  22. package/dist/esm/esm/register-esm.mjs +0 -6
  23. package/dist/esm/index.js +3 -4
  24. package/dist/esm/plugins/analyze/getFileSystemEntry.js +2 -2
  25. package/dist/esm/plugins/analyze/getServerRoutes.js +5 -3
  26. package/dist/esm/run/index.js +4 -4
  27. package/dist/esm/utils/generateWatchFiles.js +1 -1
  28. package/dist/esm/utils/isAutoLoadPlugins.js +5 -6
  29. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -0
  30. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +2 -2
  31. package/dist/esm-node/builder/generator/index.js +2 -0
  32. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  33. package/dist/esm-node/commands/dev.js +12 -3
  34. package/dist/esm-node/commands/index.js +2 -2
  35. package/dist/esm-node/commands/serve.js +3 -3
  36. package/dist/esm-node/esm/register-esm.mjs +0 -6
  37. package/dist/esm-node/index.js +3 -4
  38. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +2 -2
  39. package/dist/esm-node/plugins/analyze/getServerRoutes.js +5 -3
  40. package/dist/esm-node/run/index.js +3 -3
  41. package/dist/esm-node/utils/generateWatchFiles.js +1 -1
  42. package/dist/esm-node/utils/isAutoLoadPlugins.js +3 -2
  43. package/dist/types/commands/dev.d.ts +2 -1
  44. package/dist/types/commands/serve.d.ts +6 -1
  45. package/dist/types/index.d.ts +1 -0
  46. package/dist/types/types/hooks.d.ts +4 -8
  47. package/dist/types/types/index.d.ts +2 -2
  48. package/dist/types/types/new.d.ts +1 -18
  49. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -1
  50. package/package.json +20 -21
@@ -52,6 +52,7 @@ function createBuilderProviderConfig(resolveConfig, appContext) {
52
52
  ...resolveConfig.dev,
53
53
  port: appContext.port
54
54
  },
55
+ server: resolveConfig.server,
55
56
  html: htmlConfig,
56
57
  output: {
57
58
  ...resolveConfig.output,
@@ -59,7 +59,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
59
59
  environments.web.output.copy = tempBuilderConfig.output.copy;
60
60
  delete tempBuilderConfig.output.copy;
61
61
  }
62
- const useNodeTarget = (0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig);
62
+ const useNodeTarget = (0, import_utils.isUseRsc)(normalizedConfig) || ((0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig));
63
63
  if (useNodeTarget) {
64
64
  environments.node = {
65
65
  output: {
@@ -43,6 +43,8 @@ async function generateBuilder(options, bundlerType) {
43
43
  builderConfig.environments = builderConfig.environments ? (0, import_core.mergeRsbuildConfig)(environments, builderConfig.environments) : environments;
44
44
  const builder = await (0, import_uni_builder.createUniBuilder)({
45
45
  cwd: appContext.appDirectory,
46
+ rscClientRuntimePath: `@${appContext.metaName}/runtime/rsc/client`,
47
+ rscServerRuntimePath: `@${appContext.metaName}/runtime/rsc/server`,
46
48
  frameworkConfigPath: appContext.configFile || void 0,
47
49
  bundlerType,
48
50
  config: builderConfig
@@ -150,7 +150,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
150
150
  }
151
151
  const { ssr, ssrByEntries } = serverConfig || {};
152
152
  entryNames.forEach((name) => {
153
- if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
153
+ if (!(serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.rsc) && !ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
154
154
  chain.entryPoints.delete(name);
155
155
  }
156
156
  });
@@ -80,13 +80,22 @@ const dev = async (api, options, devServerOptions) => {
80
80
  }
81
81
  await (0, import_routes.generateRoutes)(appContext);
82
82
  const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory, metaName);
83
+ const toolsDevServerConfig = (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer;
84
+ var _normalizedConfig_dev_host, _normalizedConfig_dev_https, _normalizedConfig_dev_hmr, _normalizedConfig_dev_setupMiddlewares;
83
85
  const serverOptions = {
84
86
  metaName,
85
87
  dev: {
88
+ // [`normalizedConfig.tools.devServer`](https://modernjs.dev/en/configure/app/tools/dev-server.html) already deprecated, we should using `normalizedConfig.dev` instead firstly.
89
+ // Oterwise, the `normalizedConfig.dev` can't be apply correctly.
90
+ ...toolsDevServerConfig,
91
+ devMiddleware: {
92
+ writeToDisk: normalizedConfig.dev.writeToDisk
93
+ },
86
94
  port,
87
- https: normalizedConfig.dev.https,
88
- host: normalizedConfig.dev.host,
89
- ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
95
+ host: (_normalizedConfig_dev_host = normalizedConfig.dev.host) !== null && _normalizedConfig_dev_host !== void 0 ? _normalizedConfig_dev_host : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.host,
96
+ https: (_normalizedConfig_dev_https = normalizedConfig.dev.https) !== null && _normalizedConfig_dev_https !== void 0 ? _normalizedConfig_dev_https : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.https,
97
+ hot: (_normalizedConfig_dev_hmr = normalizedConfig.dev.hmr) !== null && _normalizedConfig_dev_hmr !== void 0 ? _normalizedConfig_dev_hmr : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.hot,
98
+ setupMiddlewares: (_normalizedConfig_dev_setupMiddlewares = normalizedConfig.dev.setupMiddlewares) !== null && _normalizedConfig_dev_setupMiddlewares !== void 0 ? _normalizedConfig_dev_setupMiddlewares : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.setupMiddlewares
90
99
  },
91
100
  appContext: {
92
101
  appDirectory,
@@ -84,8 +84,8 @@ const buildCommand = async (program, api) => {
84
84
  };
85
85
  const serverCommand = (program, api) => {
86
86
  program.command("serve").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.serve.describe)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async () => {
87
- const { start } = await import("./serve.js");
88
- await start(api);
87
+ const { serve } = await import("./serve.js");
88
+ await serve(api);
89
89
  });
90
90
  };
91
91
  const deployCommand = (program, api) => {
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var serve_exports = {};
30
30
  __export(serve_exports, {
31
- start: () => start
31
+ serve: () => serve
32
32
  });
33
33
  module.exports = __toCommonJS(serve_exports);
34
34
  var import_path = __toESM(require("path"));
@@ -36,7 +36,7 @@ var import_prod_server = require("@modern-js/prod-server");
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_loadPlugins = require("../utils/loadPlugins");
38
38
  var import_printInstructions = require("../utils/printInstructions");
39
- const start = async (api) => {
39
+ const serve = async (api, serverOptions) => {
40
40
  var _userConfig_source, _userConfig_output_distPath;
41
41
  const appContext = api.getAppContext();
42
42
  const userConfig = api.getNormalizedConfig();
@@ -52,7 +52,7 @@ const start = async (api) => {
52
52
  const meta = (0, import_utils.getMeta)(metaName);
53
53
  const serverConfigPath = import_path.default.resolve(distDirectory, import_utils.SERVER_DIR, `${meta}.server`);
54
54
  const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory, metaName);
55
- const app = await (0, import_prod_server.createProdServer)({
55
+ const app = await ((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.launcher) || import_prod_server.createProdServer)({
56
56
  metaName,
57
57
  pwd: distDirectory,
58
58
  config: {
@@ -83,5 +83,5 @@ const start = async (api) => {
83
83
  };
84
84
  // Annotate the CommonJS export names for ESM import in node:
85
85
  0 && (module.exports = {
86
- start
86
+ serve
87
87
  });
@@ -48,12 +48,6 @@ export const registerEsm = async ({ appDir, distDir, alias }) => {
48
48
  if (hasTsconfig) {
49
49
  tsConfig = readTsConfigByFile(tsconfigPath);
50
50
  }
51
- const esbuildRegister = await import('esbuild-register/dist/node');
52
- esbuildRegister.register({
53
- tsconfigRaw: hasTsconfig ? tsConfig : undefined,
54
- hookIgnoreNodeModules: true,
55
- hookMatcher: fileName => !fileName.startsWith(distDir),
56
- });
57
51
  register('./esbuild-loader.mjs', import.meta.url, {
58
52
  data: {
59
53
  appDir,
package/dist/cjs/index.js CHANGED
@@ -36,7 +36,8 @@ __export(src_exports, {
36
36
  dev: () => import_dev.dev,
37
37
  generateWatchFiles: () => import_generateWatchFiles2.generateWatchFiles,
38
38
  initAppContext: () => import_initAppContext.initAppContext,
39
- mergeConfig: () => import_core.mergeConfig
39
+ mergeConfig: () => import_core.mergeConfig,
40
+ serve: () => import_serve.serve
40
41
  });
41
42
  module.exports = __toCommonJS(src_exports);
42
43
  var import_path = __toESM(require("path"));
@@ -59,6 +60,7 @@ __reExport(src_exports, require("./defineConfig"), module.exports);
59
60
  var import_defineConfig = require("./defineConfig");
60
61
  var import_core = require("@modern-js/core");
61
62
  var import_dev = require("./commands/dev");
63
+ var import_serve = require("./commands/serve");
62
64
  var import_generateWatchFiles2 = require("./utils/generateWatchFiles");
63
65
  __reExport(src_exports, require("./types"), module.exports);
64
66
  const appTools = (options = {
@@ -96,12 +98,9 @@ const appTools = (options = {
96
98
  registryHooks: {
97
99
  onAfterPrepare: (0, import_plugin_v2.createAsyncHook)(),
98
100
  deploy: (0, import_plugin_v2.createAsyncHook)(),
99
- _internalRuntimePlugins: (0, import_plugin_v2.createAsyncHook)(),
100
- _internalServerPlugins: (0, import_plugin_v2.createAsyncHook)(),
101
101
  checkEntryPoint: (0, import_plugin_v2.createAsyncHook)(),
102
102
  modifyEntrypoints: (0, import_plugin_v2.createAsyncHook)(),
103
103
  modifyFileSystemRoutes: (0, import_plugin_v2.createAsyncHook)(),
104
- modifyServerRoutes: (0, import_plugin_v2.createAsyncHook)(),
105
104
  generateEntryCode: (0, import_plugin_v2.createAsyncHook)(),
106
105
  onBeforeGenerateRoutes: (0, import_plugin_v2.createAsyncHook)(),
107
106
  onBeforePrintInstructions: (0, import_plugin_v2.createAsyncHook)(),
@@ -197,6 +196,7 @@ var src_default = appTools;
197
196
  generateWatchFiles,
198
197
  initAppContext,
199
198
  mergeConfig,
199
+ serve,
200
200
  ...require("./defineConfig"),
201
201
  ...require("./types")
202
202
  });
@@ -79,7 +79,7 @@ const scanDir = async (hooks, dirs, enableCustomEntry) => {
79
79
  entryName,
80
80
  isMainEntry: false,
81
81
  entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
82
- customServerEntry,
82
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
83
83
  absoluteEntryDir: import_path.default.resolve(dir),
84
84
  isAutoMount: true,
85
85
  customBootstrap,
@@ -91,7 +91,7 @@ const scanDir = async (hooks, dirs, enableCustomEntry) => {
91
91
  entryName,
92
92
  isMainEntry: false,
93
93
  entry: customEntryFile,
94
- customServerEntry,
94
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
95
95
  absoluteEntryDir: import_path.default.resolve(dir),
96
96
  isAutoMount: false,
97
97
  customEntry: Boolean(customEntryFile)
@@ -103,7 +103,7 @@ const applyRouteOptions = (original, routeOptions) => {
103
103
  };
104
104
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
105
105
  var _deploy_worker;
106
- const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
106
+ const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries, rsc }, deploy } = config;
107
107
  const { packageName } = appContext;
108
108
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
109
109
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
@@ -113,16 +113,18 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
113
113
  const isWorker = Boolean(workerSSR);
114
114
  const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
115
115
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
116
+ const isRSC = !!rsc;
116
117
  let route = {
117
118
  urlPath: `/${isMain ? "" : entryName}`,
118
119
  entryName,
119
120
  entryPath: (0, import_utils.removeLeadingSlash)(import_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
120
121
  isSPA: true,
121
- isStream,
122
+ isStream: isStream || isRSC,
122
123
  isSSR,
124
+ isRSC,
123
125
  responseHeaders: resHeaders,
124
126
  worker: isWorker ? `${import_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
125
- bundle: isSSR ? `${import_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
127
+ bundle: isSSR || isRSC ? `${import_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
126
128
  };
127
129
  if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
128
130
  const routeOptions = (0, import_utils.isPlainObject)(routes[entryName]) ? routes[entryName] : {
@@ -29,7 +29,7 @@ var import_constants = require("../constants");
29
29
  var import_getConfigFile = require("../utils/getConfigFile");
30
30
  var import_isAutoLoadPlugins = require("../utils/isAutoLoadPlugins");
31
31
  var import_loadPlugins = require("../utils/loadPlugins");
32
- async function run({ cwd, initialLog, metaName, version, internalPlugins, packageJsonConfig, configFile }) {
32
+ async function run({ cwd, initialLog, metaName = "MODERN", version, internalPlugins, packageJsonConfig = import_constants.PACKAGE_JSON_CONFIG_NAME, configFile }) {
33
33
  const command = process.argv[2];
34
34
  const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
35
35
  const SUPPORT_CONFIG_PARAM_COMMANDS = [
@@ -64,14 +64,14 @@ async function run({ cwd, initialLog, metaName, version, internalPlugins, packag
64
64
  }
65
65
  const appDirectory = await (0, import_cli.initAppDir)(cwd);
66
66
  const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
67
- const autoLoadPlugins = await (0, import_isAutoLoadPlugins.isAutoLoadPlugins)(appDirectory, finalConfigFile);
67
+ const autoLoadPlugins = await (0, import_isAutoLoadPlugins.isAutoLoadPlugins)(appDirectory, finalConfigFile, packageJsonConfig, metaName);
68
68
  const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
69
69
  await (0, import_run.run)({
70
70
  cwd,
71
71
  initialLog: initialLog || `Modern.js Framework v${version}`,
72
72
  configFile: finalConfigFile,
73
73
  metaName,
74
- packageJsonConfig: packageJsonConfig || import_constants.PACKAGE_JSON_CONFIG_NAME,
74
+ packageJsonConfig,
75
75
  internalPlugins: plugins,
76
76
  handleSetupResult: import_hooks.handleSetupResult
77
77
  });
@@ -34,10 +34,10 @@ __export(generateWatchFiles_exports, {
34
34
  module.exports = __toCommonJS(generateWatchFiles_exports);
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("@modern-js/utils");
37
+ var import_constants = require("../constants");
37
38
  const getPackageConfig = (appDirectory, packageJsonConfig) => {
38
- const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
39
39
  const json = JSON.parse(import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8"));
40
- return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
40
+ return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : import_constants.PACKAGE_JSON_CONFIG_NAME];
41
41
  };
42
42
  const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
43
43
  const serverConfig = await (0, import_utils.getServerConfig)(appDirectory, serverConfigFile);
@@ -22,8 +22,9 @@ __export(isAutoLoadPlugins_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(isAutoLoadPlugins_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
- async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
25
+ async function isAutoLoadPlugins(appDirectory, configFile, packageJsonConfig, metaName) {
26
26
  var _loaded_config;
27
+ (0, import_cli.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
27
28
  const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
28
29
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
29
30
  return autoLoadPlugins || false;
@@ -23,6 +23,7 @@ function createBuilderProviderConfig(resolveConfig, appContext) {
23
23
  dev: _object_spread_props(_object_spread({}, resolveConfig.dev), {
24
24
  port: appContext.port
25
25
  }),
26
+ server: resolveConfig.server,
26
27
  html: htmlConfig,
27
28
  output: _object_spread_props(_object_spread({}, resolveConfig.output), {
28
29
  // 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
@@ -1,5 +1,5 @@
1
1
  import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
- import { isProd, isSSR, isServiceWorker, isUseSSRBundle } from "@modern-js/utils";
2
+ import { isProd, isSSR, isServiceWorker, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
3
3
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
4
4
  var _tempBuilderConfig_output;
5
5
  var entries = {};
@@ -57,7 +57,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
57
57
  environments.web.output.copy = tempBuilderConfig.output.copy;
58
58
  delete tempBuilderConfig.output.copy;
59
59
  }
60
- var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
60
+ var useNodeTarget = isUseRsc(normalizedConfig) || (isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig));
61
61
  if (useNodeTarget) {
62
62
  environments.node = {
63
63
  output: {
@@ -22,6 +22,8 @@ function _generateBuilder() {
22
22
  4,
23
23
  createUniBuilder({
24
24
  cwd: appContext.appDirectory,
25
+ rscClientRuntimePath: "@".concat(appContext.metaName, "/runtime/rsc/client"),
26
+ rscServerRuntimePath: "@".concat(appContext.metaName, "/runtime/rsc/server"),
25
27
  frameworkConfigPath: appContext.configFile || void 0,
26
28
  bundlerType,
27
29
  config: builderConfig
@@ -170,7 +170,7 @@ function applyFilterEntriesBySSRConfig(param) {
170
170
  }
171
171
  var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
172
172
  entryNames.forEach(function(name) {
173
- if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
173
+ if (!(serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.rsc) && !ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
174
174
  chain.entryPoints.delete(name);
175
175
  }
176
176
  });
@@ -14,7 +14,7 @@ import { registerCompiler } from "../utils/register";
14
14
  import { generateRoutes } from "../utils/routes";
15
15
  var dev = function() {
16
16
  var _ref = _async_to_generator(function(api, options, devServerOptions) {
17
- var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hooks, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
17
+ var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hooks, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, toolsDevServerConfig, _normalizedConfig_dev_host, _normalizedConfig_dev_https, _normalizedConfig_dev_hmr, _normalizedConfig_dev_setupMiddlewares, serverOptions, host, server, _ref2, server1, afterListen;
18
18
  return _ts_generator(this, function(_state) {
19
19
  switch (_state.label) {
20
20
  case 0:
@@ -93,13 +93,19 @@ var dev = function() {
93
93
  ];
94
94
  case 8:
95
95
  pluginInstances = _state.sent();
96
+ toolsDevServerConfig = (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer;
96
97
  serverOptions = _object_spread({
97
98
  metaName,
98
- dev: _object_spread({
99
+ dev: _object_spread_props(_object_spread({}, toolsDevServerConfig), {
100
+ devMiddleware: {
101
+ writeToDisk: normalizedConfig.dev.writeToDisk
102
+ },
99
103
  port,
100
- https: normalizedConfig.dev.https,
101
- host: normalizedConfig.dev.host
102
- }, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
104
+ host: (_normalizedConfig_dev_host = normalizedConfig.dev.host) !== null && _normalizedConfig_dev_host !== void 0 ? _normalizedConfig_dev_host : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.host,
105
+ https: (_normalizedConfig_dev_https = normalizedConfig.dev.https) !== null && _normalizedConfig_dev_https !== void 0 ? _normalizedConfig_dev_https : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.https,
106
+ hot: (_normalizedConfig_dev_hmr = normalizedConfig.dev.hmr) !== null && _normalizedConfig_dev_hmr !== void 0 ? _normalizedConfig_dev_hmr : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.hot,
107
+ setupMiddlewares: (_normalizedConfig_dev_setupMiddlewares = normalizedConfig.dev.setupMiddlewares) !== null && _normalizedConfig_dev_setupMiddlewares !== void 0 ? _normalizedConfig_dev_setupMiddlewares : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.setupMiddlewares
108
+ }),
103
109
  appContext: {
104
110
  appDirectory,
105
111
  internalDirectory: appContext.internalDirectory,
@@ -249,7 +249,7 @@ var buildCommand = function() {
249
249
  }();
250
250
  var serverCommand = function(program, api) {
251
251
  program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(/* @__PURE__ */ _async_to_generator(function() {
252
- var start;
252
+ var serve;
253
253
  return _ts_generator(this, function(_state) {
254
254
  switch (_state.label) {
255
255
  case 0:
@@ -258,10 +258,10 @@ var serverCommand = function(program, api) {
258
258
  import("./serve.js")
259
259
  ];
260
260
  case 1:
261
- start = _state.sent().start;
261
+ serve = _state.sent().serve;
262
262
  return [
263
263
  4,
264
- start(api)
264
+ serve(api)
265
265
  ];
266
266
  case 2:
267
267
  _state.sent();
@@ -7,8 +7,8 @@ import { createProdServer } from "@modern-js/prod-server";
7
7
  import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
8
8
  import { loadServerPlugins } from "../utils/loadPlugins";
9
9
  import { printInstructions } from "../utils/printInstructions";
10
- var start = function() {
11
- var _ref = _async_to_generator(function(api) {
10
+ var serve = function() {
11
+ var _ref = _async_to_generator(function(api, serverOptions) {
12
12
  var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, isCrossProjectServer, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
13
13
  return _ts_generator(this, function(_state) {
14
14
  switch (_state.label) {
@@ -38,7 +38,7 @@ var start = function() {
38
38
  pluginInstances = _state.sent();
39
39
  return [
40
40
  4,
41
- createProdServer({
41
+ ((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.launcher) || createProdServer)({
42
42
  metaName,
43
43
  pwd: distDirectory,
44
44
  config: _object_spread_props(_object_spread({}, userConfig), {
@@ -86,10 +86,10 @@ var start = function() {
86
86
  }
87
87
  });
88
88
  });
89
- return function start2(api) {
89
+ return function serve2(api, serverOptions) {
90
90
  return _ref.apply(this, arguments);
91
91
  };
92
92
  }();
93
93
  export {
94
- start
94
+ serve
95
95
  };
@@ -48,12 +48,6 @@ export const registerEsm = async ({ appDir, distDir, alias }) => {
48
48
  if (hasTsconfig) {
49
49
  tsConfig = readTsConfigByFile(tsconfigPath);
50
50
  }
51
- const esbuildRegister = await import('esbuild-register/dist/node');
52
- esbuildRegister.register({
53
- tsconfigRaw: hasTsconfig ? tsConfig : undefined,
54
- hookIgnoreNodeModules: true,
55
- hookMatcher: fileName => !fileName.startsWith(distDir),
56
- });
57
51
  register('./esbuild-loader.mjs', import.meta.url, {
58
52
  data: {
59
53
  appDir,
package/dist/esm/index.js CHANGED
@@ -55,12 +55,9 @@ var appTools = function() {
55
55
  registryHooks: {
56
56
  onAfterPrepare: createAsyncHook(),
57
57
  deploy: createAsyncHook(),
58
- _internalRuntimePlugins: createAsyncHook(),
59
- _internalServerPlugins: createAsyncHook(),
60
58
  checkEntryPoint: createAsyncHook(),
61
59
  modifyEntrypoints: createAsyncHook(),
62
60
  modifyFileSystemRoutes: createAsyncHook(),
63
- modifyServerRoutes: createAsyncHook(),
64
61
  generateEntryCode: createAsyncHook(),
65
62
  onBeforeGenerateRoutes: createAsyncHook(),
66
63
  onBeforePrintInstructions: createAsyncHook(),
@@ -249,6 +246,7 @@ var appTools = function() {
249
246
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
250
247
  import { mergeConfig } from "@modern-js/core";
251
248
  import { dev } from "./commands/dev";
249
+ import { serve } from "./commands/serve";
252
250
  import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
253
251
  export * from "./types";
254
252
  var src_default = appTools;
@@ -260,5 +258,6 @@ export {
260
258
  dev,
261
259
  generateWatchFiles2 as generateWatchFiles,
262
260
  initAppContext,
263
- mergeConfig
261
+ mergeConfig,
262
+ serve
264
263
  };
@@ -107,7 +107,7 @@ var scanDir = function() {
107
107
  entryName,
108
108
  isMainEntry: false,
109
109
  entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
110
- customServerEntry,
110
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
111
111
  absoluteEntryDir: path.resolve(dir),
112
112
  isAutoMount: true,
113
113
  customBootstrap,
@@ -122,7 +122,7 @@ var scanDir = function() {
122
122
  entryName,
123
123
  isMainEntry: false,
124
124
  entry: customEntryFile,
125
- customServerEntry,
125
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
126
126
  absoluteEntryDir: path.resolve(dir),
127
127
  isAutoMount: false,
128
128
  customEntry: Boolean(customEntryFile)
@@ -70,7 +70,7 @@ var applyRouteOptions = function(original, routeOptions) {
70
70
  };
71
71
  var collectHtmlRoutes = function(entrypoints, appContext, config) {
72
72
  var _deploy_worker;
73
- var mainEntryName = config.source.mainEntryName, disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
73
+ var mainEntryName = config.source.mainEntryName, disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, rsc = _config_server.rsc, deploy = config.deploy;
74
74
  var packageName = appContext.packageName;
75
75
  var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
76
76
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
@@ -81,16 +81,18 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
81
81
  var isWorker = Boolean(workerSSR);
82
82
  var isStream = (typeof entryOptions === "undefined" ? "undefined" : _type_of(entryOptions)) === "object" && entryOptions.mode === "stream";
83
83
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
84
+ var isRSC = !!rsc;
84
85
  var route = {
85
86
  urlPath: "/".concat(isMain ? "" : entryName),
86
87
  entryName,
87
88
  entryPath: removeLeadingSlash(path.posix.normalize("".concat(htmlPath, "/").concat(entryName).concat(disableHtmlFolder ? ".html" : "/index.html"))),
88
89
  isSPA: true,
89
- isStream,
90
+ isStream: isStream || isRSC,
90
91
  isSSR,
92
+ isRSC,
91
93
  responseHeaders: resHeaders,
92
94
  worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
93
- bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
95
+ bundle: isSSR || isRSC ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
94
96
  };
95
97
  if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
96
98
  var routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
@@ -13,11 +13,11 @@ function run(_) {
13
13
  }
14
14
  function _run() {
15
15
  _run = _async_to_generator(function(param) {
16
- var cwd, initialLog, metaName, version, internalPlugins, packageJsonConfig, configFile, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, finalConfigFile, autoLoadPlugins, plugins;
16
+ var cwd, initialLog, _param_metaName, metaName, version, internalPlugins, _param_packageJsonConfig, packageJsonConfig, configFile, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, finalConfigFile, autoLoadPlugins, plugins;
17
17
  return _ts_generator(this, function(_state) {
18
18
  switch (_state.label) {
19
19
  case 0:
20
- cwd = param.cwd, initialLog = param.initialLog, metaName = param.metaName, version = param.version, internalPlugins = param.internalPlugins, packageJsonConfig = param.packageJsonConfig, configFile = param.configFile;
20
+ cwd = param.cwd, initialLog = param.initialLog, _param_metaName = param.metaName, metaName = _param_metaName === void 0 ? "MODERN" : _param_metaName, version = param.version, internalPlugins = param.internalPlugins, _param_packageJsonConfig = param.packageJsonConfig, packageJsonConfig = _param_packageJsonConfig === void 0 ? PACKAGE_JSON_CONFIG_NAME : _param_packageJsonConfig, configFile = param.configFile;
21
21
  command = process.argv[2];
22
22
  cliParams = minimist(process.argv.slice(2));
23
23
  SUPPORT_CONFIG_PARAM_COMMANDS = [
@@ -58,7 +58,7 @@ function _run() {
58
58
  finalConfigFile = customConfigFile || getConfigFile(configFile);
59
59
  return [
60
60
  4,
61
- isAutoLoadPlugins(appDirectory, finalConfigFile)
61
+ isAutoLoadPlugins(appDirectory, finalConfigFile, packageJsonConfig, metaName)
62
62
  ];
63
63
  case 2:
64
64
  autoLoadPlugins = _state.sent();
@@ -75,7 +75,7 @@ function _run() {
75
75
  initialLog: initialLog || "Modern.js Framework v".concat(version),
76
76
  configFile: finalConfigFile,
77
77
  metaName,
78
- packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME,
78
+ packageJsonConfig,
79
79
  internalPlugins: plugins,
80
80
  handleSetupResult
81
81
  })
@@ -3,8 +3,8 @@ 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 path from "path";
5
5
  import { fs, getServerConfig } from "@modern-js/utils";
6
+ import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
6
7
  var getPackageConfig = function(appDirectory, packageJsonConfig) {
7
- var PACKAGE_JSON_CONFIG_NAME = "modernConfig";
8
8
  var json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
9
9
  return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
10
10
  };
@@ -1,17 +1,16 @@
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
- import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
4
- function isAutoLoadPlugins(appDirectory) {
3
+ import { createLoadedConfig, loadEnv } from "@modern-js/plugin-v2/cli";
4
+ function isAutoLoadPlugins(appDirectory, configFile, packageJsonConfig, metaName) {
5
5
  return _isAutoLoadPlugins.apply(this, arguments);
6
6
  }
7
7
  function _isAutoLoadPlugins() {
8
- _isAutoLoadPlugins = _async_to_generator(function(appDirectory) {
9
- var configFile, packageJsonConfig, _loaded_config, loaded, autoLoadPlugins;
10
- var _arguments = arguments;
8
+ _isAutoLoadPlugins = _async_to_generator(function(appDirectory, configFile, packageJsonConfig, metaName) {
9
+ var _loaded_config, loaded, autoLoadPlugins;
11
10
  return _ts_generator(this, function(_state) {
12
11
  switch (_state.label) {
13
12
  case 0:
14
- configFile = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern.config.ts", packageJsonConfig = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : "ModernConfig";
13
+ loadEnv(appDirectory, process.env["".concat(metaName.toUpperCase(), "_ENV")]);
15
14
  return [
16
15
  4,
17
16
  createLoadedConfig(appDirectory, configFile, packageJsonConfig)
@@ -29,6 +29,7 @@ function createBuilderProviderConfig(resolveConfig, appContext) {
29
29
  ...resolveConfig.dev,
30
30
  port: appContext.port
31
31
  },
32
+ server: resolveConfig.server,
32
33
  html: htmlConfig,
33
34
  output: {
34
35
  ...resolveConfig.output,
@@ -1,5 +1,5 @@
1
1
  import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
- import { isProd, isSSR, isServiceWorker, isUseSSRBundle } from "@modern-js/utils";
2
+ import { isProd, isSSR, isServiceWorker, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
3
3
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
4
4
  var _tempBuilderConfig_output;
5
5
  const entries = {};
@@ -36,7 +36,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
36
36
  environments.web.output.copy = tempBuilderConfig.output.copy;
37
37
  delete tempBuilderConfig.output.copy;
38
38
  }
39
- const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
39
+ const useNodeTarget = isUseRsc(normalizedConfig) || (isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig));
40
40
  if (useNodeTarget) {
41
41
  environments.node = {
42
42
  output: {
@@ -10,6 +10,8 @@ async function generateBuilder(options, bundlerType) {
10
10
  builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
11
11
  const builder = await createUniBuilder({
12
12
  cwd: appContext.appDirectory,
13
+ rscClientRuntimePath: `@${appContext.metaName}/runtime/rsc/client`,
14
+ rscServerRuntimePath: `@${appContext.metaName}/runtime/rsc/server`,
13
15
  frameworkConfigPath: appContext.configFile || void 0,
14
16
  bundlerType,
15
17
  config: builderConfig
@@ -117,7 +117,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
117
117
  }
118
118
  const { ssr, ssrByEntries } = serverConfig || {};
119
119
  entryNames.forEach((name) => {
120
- if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
120
+ if (!(serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.rsc) && !ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
121
121
  chain.entryPoints.delete(name);
122
122
  }
123
123
  });
@@ -47,13 +47,22 @@ const dev = async (api, options, devServerOptions) => {
47
47
  }
48
48
  await generateRoutes(appContext);
49
49
  const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
50
+ const toolsDevServerConfig = (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer;
51
+ var _normalizedConfig_dev_host, _normalizedConfig_dev_https, _normalizedConfig_dev_hmr, _normalizedConfig_dev_setupMiddlewares;
50
52
  const serverOptions = {
51
53
  metaName,
52
54
  dev: {
55
+ // [`normalizedConfig.tools.devServer`](https://modernjs.dev/en/configure/app/tools/dev-server.html) already deprecated, we should using `normalizedConfig.dev` instead firstly.
56
+ // Oterwise, the `normalizedConfig.dev` can't be apply correctly.
57
+ ...toolsDevServerConfig,
58
+ devMiddleware: {
59
+ writeToDisk: normalizedConfig.dev.writeToDisk
60
+ },
53
61
  port,
54
- https: normalizedConfig.dev.https,
55
- host: normalizedConfig.dev.host,
56
- ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
62
+ host: (_normalizedConfig_dev_host = normalizedConfig.dev.host) !== null && _normalizedConfig_dev_host !== void 0 ? _normalizedConfig_dev_host : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.host,
63
+ https: (_normalizedConfig_dev_https = normalizedConfig.dev.https) !== null && _normalizedConfig_dev_https !== void 0 ? _normalizedConfig_dev_https : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.https,
64
+ hot: (_normalizedConfig_dev_hmr = normalizedConfig.dev.hmr) !== null && _normalizedConfig_dev_hmr !== void 0 ? _normalizedConfig_dev_hmr : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.hot,
65
+ setupMiddlewares: (_normalizedConfig_dev_setupMiddlewares = normalizedConfig.dev.setupMiddlewares) !== null && _normalizedConfig_dev_setupMiddlewares !== void 0 ? _normalizedConfig_dev_setupMiddlewares : toolsDevServerConfig === null || toolsDevServerConfig === void 0 ? void 0 : toolsDevServerConfig.setupMiddlewares
57
66
  },
58
67
  appContext: {
59
68
  appDirectory,
@@ -45,8 +45,8 @@ const buildCommand = async (program, api) => {
45
45
  };
46
46
  const serverCommand = (program, api) => {
47
47
  program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
48
- const { start } = await import("./serve.js");
49
- await start(api);
48
+ const { serve } = await import("./serve.js");
49
+ await serve(api);
50
50
  });
51
51
  };
52
52
  const deployCommand = (program, api) => {
@@ -3,7 +3,7 @@ import { createProdServer } from "@modern-js/prod-server";
3
3
  import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
4
4
  import { loadServerPlugins } from "../utils/loadPlugins";
5
5
  import { printInstructions } from "../utils/printInstructions";
6
- const start = async (api) => {
6
+ const serve = async (api, serverOptions) => {
7
7
  var _userConfig_source, _userConfig_output_distPath;
8
8
  const appContext = api.getAppContext();
9
9
  const userConfig = api.getNormalizedConfig();
@@ -19,7 +19,7 @@ const start = async (api) => {
19
19
  const meta = getMeta(metaName);
20
20
  const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
21
21
  const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
22
- const app = await createProdServer({
22
+ const app = await ((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.launcher) || createProdServer)({
23
23
  metaName,
24
24
  pwd: distDirectory,
25
25
  config: {
@@ -49,5 +49,5 @@ const start = async (api) => {
49
49
  });
50
50
  };
51
51
  export {
52
- start
52
+ serve
53
53
  };
@@ -48,12 +48,6 @@ export const registerEsm = async ({ appDir, distDir, alias }) => {
48
48
  if (hasTsconfig) {
49
49
  tsConfig = readTsConfigByFile(tsconfigPath);
50
50
  }
51
- const esbuildRegister = await import('esbuild-register/dist/node');
52
- esbuildRegister.register({
53
- tsconfigRaw: hasTsconfig ? tsConfig : undefined,
54
- hookIgnoreNodeModules: true,
55
- hookMatcher: fileName => !fileName.startsWith(distDir),
56
- });
57
51
  register('./esbuild-loader.mjs', import.meta.url, {
58
52
  data: {
59
53
  appDir,
@@ -50,12 +50,9 @@ const appTools = (options = {
50
50
  registryHooks: {
51
51
  onAfterPrepare: createAsyncHook(),
52
52
  deploy: createAsyncHook(),
53
- _internalRuntimePlugins: createAsyncHook(),
54
- _internalServerPlugins: createAsyncHook(),
55
53
  checkEntryPoint: createAsyncHook(),
56
54
  modifyEntrypoints: createAsyncHook(),
57
55
  modifyFileSystemRoutes: createAsyncHook(),
58
- modifyServerRoutes: createAsyncHook(),
59
56
  generateEntryCode: createAsyncHook(),
60
57
  onBeforeGenerateRoutes: createAsyncHook(),
61
58
  onBeforePrintInstructions: createAsyncHook(),
@@ -144,6 +141,7 @@ const appTools = (options = {
144
141
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
145
142
  import { mergeConfig } from "@modern-js/core";
146
143
  import { dev } from "./commands/dev";
144
+ import { serve } from "./commands/serve";
147
145
  import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
148
146
  export * from "./types";
149
147
  var src_default = appTools;
@@ -155,5 +153,6 @@ export {
155
153
  dev,
156
154
  generateWatchFiles2 as generateWatchFiles,
157
155
  initAppContext,
158
- mergeConfig
156
+ mergeConfig,
157
+ serve
159
158
  };
@@ -46,7 +46,7 @@ const scanDir = async (hooks, dirs, enableCustomEntry) => {
46
46
  entryName,
47
47
  isMainEntry: false,
48
48
  entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
49
- customServerEntry,
49
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
50
50
  absoluteEntryDir: path.resolve(dir),
51
51
  isAutoMount: true,
52
52
  customBootstrap,
@@ -58,7 +58,7 @@ const scanDir = async (hooks, dirs, enableCustomEntry) => {
58
58
  entryName,
59
59
  isMainEntry: false,
60
60
  entry: customEntryFile,
61
- customServerEntry,
61
+ customServerEntry: enableCustomEntry ? customServerEntry : false,
62
62
  absoluteEntryDir: path.resolve(dir),
63
63
  isAutoMount: false,
64
64
  customEntry: Boolean(customEntryFile)
@@ -69,7 +69,7 @@ const applyRouteOptions = (original, routeOptions) => {
69
69
  };
70
70
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
71
71
  var _deploy_worker;
72
- const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
72
+ const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries, rsc }, deploy } = config;
73
73
  const { packageName } = appContext;
74
74
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
75
75
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
@@ -79,16 +79,18 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
79
79
  const isWorker = Boolean(workerSSR);
80
80
  const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
81
81
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
82
+ const isRSC = !!rsc;
82
83
  let route = {
83
84
  urlPath: `/${isMain ? "" : entryName}`,
84
85
  entryName,
85
86
  entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
86
87
  isSPA: true,
87
- isStream,
88
+ isStream: isStream || isRSC,
88
89
  isSSR,
90
+ isRSC,
89
91
  responseHeaders: resHeaders,
90
92
  worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
91
- bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
93
+ bundle: isSSR || isRSC ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
92
94
  };
93
95
  if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
94
96
  const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
@@ -6,7 +6,7 @@ import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
6
6
  import { getConfigFile } from "../utils/getConfigFile";
7
7
  import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
8
8
  import { loadInternalPlugins } from "../utils/loadPlugins";
9
- async function run({ cwd, initialLog, metaName, version, internalPlugins, packageJsonConfig, configFile }) {
9
+ async function run({ cwd, initialLog, metaName = "MODERN", version, internalPlugins, packageJsonConfig = PACKAGE_JSON_CONFIG_NAME, configFile }) {
10
10
  const command = process.argv[2];
11
11
  const cliParams = minimist(process.argv.slice(2));
12
12
  const SUPPORT_CONFIG_PARAM_COMMANDS = [
@@ -41,14 +41,14 @@ async function run({ cwd, initialLog, metaName, version, internalPlugins, packag
41
41
  }
42
42
  const appDirectory = await initAppDir(cwd);
43
43
  const finalConfigFile = customConfigFile || getConfigFile(configFile);
44
- const autoLoadPlugins = await isAutoLoadPlugins(appDirectory, finalConfigFile);
44
+ const autoLoadPlugins = await isAutoLoadPlugins(appDirectory, finalConfigFile, packageJsonConfig, metaName);
45
45
  const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
46
46
  await CLIPluginRun({
47
47
  cwd,
48
48
  initialLog: initialLog || `Modern.js Framework v${version}`,
49
49
  configFile: finalConfigFile,
50
50
  metaName,
51
- packageJsonConfig: packageJsonConfig || PACKAGE_JSON_CONFIG_NAME,
51
+ packageJsonConfig,
52
52
  internalPlugins: plugins,
53
53
  handleSetupResult
54
54
  });
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import { fs, getServerConfig } from "@modern-js/utils";
3
+ import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
3
4
  const getPackageConfig = (appDirectory, packageJsonConfig) => {
4
- const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
5
5
  const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
6
6
  return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
7
7
  };
@@ -1,6 +1,7 @@
1
- import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
2
- async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
1
+ import { createLoadedConfig, loadEnv } from "@modern-js/plugin-v2/cli";
2
+ async function isAutoLoadPlugins(appDirectory, configFile, packageJsonConfig, metaName) {
3
3
  var _loaded_config;
4
+ loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
4
5
  const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
5
6
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
6
7
  return autoLoadPlugins || false;
@@ -2,7 +2,8 @@ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type ApplyPlugins } from '@modern-js/server';
3
3
  import type { AppTools } from '../types';
4
4
  import type { DevOptions } from '../utils/types';
5
- export interface ExtraServerOptions {
5
+ interface ExtraServerOptions {
6
6
  applyPlugins?: ApplyPlugins;
7
7
  }
8
8
  export declare const dev: (api: CLIPluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
9
+ export {};
@@ -1,3 +1,8 @@
1
1
  import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
+ import { createProdServer } from '@modern-js/prod-server';
2
3
  import type { AppTools } from '../types';
3
- export declare const start: (api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
4
+ type ExtraServerOptions = {
5
+ launcher?: typeof createProdServer;
6
+ };
7
+ export declare const serve: (api: CLIPluginAPI<AppTools<'shared'>>, serverOptions?: ExtraServerOptions) => Promise<void>;
8
+ export {};
@@ -6,6 +6,7 @@ export { defineConfig, defineLegacyConfig } from './defineConfig';
6
6
  export { mergeConfig } from '@modern-js/core';
7
7
  export type { RuntimeUserConfig } from './types/config';
8
8
  export { dev } from './commands/dev';
9
+ export { serve } from './commands/serve';
9
10
  export type { DevOptions } from './utils/types';
10
11
  export { generateWatchFiles } from './utils/generateWatchFiles';
11
12
  export * from './types';
@@ -1,21 +1,17 @@
1
1
  import type { DevToolData, RegisterBuildPlatformResult } from '@modern-js/core';
2
2
  import type { AsyncWaterfall, AsyncWorkflow, ParallelWorkflow } from '@modern-js/plugin';
3
- import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
3
+ import type { RuntimePluginConfig, ServerPluginConfig } from '@modern-js/plugin-v2';
4
+ import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerRoute } from '@modern-js/types';
4
5
  import type { MultiStats, Rspack, Stats, webpack } from '@modern-js/uni-builder';
5
6
  import type { Bundler } from './utils';
6
7
  export interface ImportSpecifier {
7
8
  local?: string;
8
9
  imported?: string;
9
10
  }
10
- export interface RuntimePlugin {
11
- name: string;
12
- path: string;
13
- config: Record<string, any>;
14
- }
15
11
  export type AppToolsHooks<B extends Bundler = 'webpack'> = {
16
12
  _internalRuntimePlugins: AsyncWaterfall<{
17
13
  entrypoint: Entrypoint;
18
- plugins: RuntimePlugin[];
14
+ plugins: RuntimePluginConfig[];
19
15
  }>;
20
16
  modifyFileSystemRoutes: AsyncWaterfall<{
21
17
  entrypoint: Entrypoint;
@@ -43,7 +39,7 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
43
39
  code: string;
44
40
  }>;
45
41
  _internalServerPlugins: AsyncWaterfall<{
46
- plugins: ServerPlugin[];
42
+ plugins: ServerPluginConfig[];
47
43
  }>;
48
44
  beforeDev: AsyncWorkflow<void, unknown>;
49
45
  afterDev: AsyncWorkflow<{
@@ -1,11 +1,11 @@
1
1
  import type { NormalizedConfig, UserConfig } from '@modern-js/core';
2
- import type { CLIPlugin, CLIPluginExtends } from '@modern-js/plugin-v2';
2
+ import type { CLIPlugin, CLIPluginExtends, RuntimePluginConfig, ServerPluginConfig } from '@modern-js/plugin-v2';
3
3
  import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
4
4
  import type { AppToolsHooks } from './hooks';
5
5
  import type { AppToolsLegacyNormalizedConfig, AppToolsLegacyUserConfig } from './legacyConfig';
6
6
  import type { AppToolsExtendAPI, AppToolsExtendContext, AppToolsExtendHooks } from './new';
7
7
  import type { Bundler } from './utils';
8
- export type { CLIPluginExtends };
8
+ export type { CLIPluginExtends, RuntimePluginConfig, ServerPluginConfig };
9
9
  export * from './hooks';
10
10
  export * from './config';
11
11
  export * from './legacyConfig';
@@ -5,16 +5,8 @@ import type { Entrypoint, HtmlPartials, HtmlTemplates, NestedRouteForCli, PageRo
5
5
  import type { AppTools } from '.';
6
6
  import type { getHookRunners } from '../compat/hooks';
7
7
  import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
8
- import type { RuntimePlugin } from './hooks';
9
8
  import type { Bundler } from './utils';
10
9
  export type AfterPrepareFn = () => Promise<void> | void;
11
- export type InternalRuntimePluginsFn = TransformFunction<{
12
- entrypoint: Entrypoint;
13
- plugins: RuntimePlugin[];
14
- }>;
15
- export type InternalServerPluginsFn = TransformFunction<{
16
- plugins: ServerPlugin[];
17
- }>;
18
10
  export type CheckEntryPointFn = TransformFunction<{
19
11
  path: string;
20
12
  entry: false | string;
@@ -26,9 +18,6 @@ export type ModifyFileSystemRoutesFn = TransformFunction<{
26
18
  entrypoint: Entrypoint;
27
19
  routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
28
20
  }>;
29
- export type ModifyServerRoutesFn = TransformFunction<{
30
- routes: ServerRoute[];
31
- }>;
32
21
  export type DeplpoyFn = () => Promise<void> | void;
33
22
  export type GenerateEntryCodeFn = (params: {
34
23
  entrypoints: Entrypoint[];
@@ -46,12 +35,9 @@ export type AddRuntimeExportsFn = () => Promise<void> | void;
46
35
  export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
47
36
  onAfterPrepare: PluginHookTap<AfterPrepareFn>;
48
37
  deploy: PluginHookTap<DeplpoyFn>;
49
- _internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
50
- _internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
51
38
  checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
52
39
  modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
53
40
  modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
54
- modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
55
41
  generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
56
42
  onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
57
43
  /**
@@ -90,12 +76,9 @@ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
90
76
  export interface AppToolsExtendHooks extends Record<string, PluginHook<(...args: any[]) => any>> {
91
77
  onAfterPrepare: AsyncHook<AfterPrepareFn>;
92
78
  deploy: AsyncHook<DeplpoyFn>;
93
- _internalRuntimePlugins: AsyncHook<InternalRuntimePluginsFn>;
94
- _internalServerPlugins: AsyncHook<InternalServerPluginsFn>;
95
79
  checkEntryPoint: AsyncHook<CheckEntryPointFn>;
96
80
  modifyEntrypoints: AsyncHook<ModifyEntrypointsFn>;
97
81
  modifyFileSystemRoutes: AsyncHook<ModifyFileSystemRoutesFn>;
98
- modifyServerRoutes: AsyncHook<ModifyServerRoutesFn>;
99
82
  generateEntryCode: AsyncHook<GenerateEntryCodeFn>;
100
83
  onBeforeGenerateRoutes: AsyncHook<BeforeGenerateRoutesFn>;
101
84
  /**
@@ -152,4 +135,4 @@ export interface AppToolsExtendContext<B extends Bundler = 'webpack'> {
152
135
  toolsType?: string;
153
136
  }
154
137
  export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<AppTools<B>> & AppToolsExtendContext<B>;
155
- export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig, {}> & AppToolsExtendHooks;
138
+ export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig, {}, {}> & AppToolsExtendHooks;
@@ -1 +1 @@
1
- export declare function isAutoLoadPlugins(appDirectory: string, configFile?: string, packageJsonConfig?: string): Promise<boolean>;
1
+ export declare function isAutoLoadPlugins(appDirectory: string, configFile: string, packageJsonConfig: string, metaName: string): Promise<boolean>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.64.0",
18
+ "version": "2.64.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -80,32 +80,31 @@
80
80
  "@babel/parser": "^7.22.15",
81
81
  "@babel/traverse": "^7.23.2",
82
82
  "@babel/types": "^7.26.0",
83
- "@rsbuild/core": "1.1.13",
84
- "@rsbuild/plugin-node-polyfill": "1.2.0",
83
+ "@rsbuild/core": "1.2.7",
84
+ "@rsbuild/plugin-node-polyfill": "1.3.0",
85
85
  "@swc/helpers": "0.5.13",
86
- "@vercel/nft": "^0.26.4",
87
86
  "es-module-lexer": "^1.1.0",
88
87
  "esbuild": "0.17.19",
89
88
  "esbuild-register": "^3.5.0",
90
89
  "flatted": "^3.2.9",
91
90
  "mlly": "^1.6.1",
92
- "pkg-types": "^1.1.0",
93
91
  "ndepe": "0.1.5",
92
+ "pkg-types": "^1.1.0",
94
93
  "std-env": "^3.7.0",
95
- "@modern-js/core": "2.64.0",
96
- "@modern-js/node-bundle-require": "2.64.0",
97
- "@modern-js/plugin-data-loader": "2.64.0",
98
- "@modern-js/plugin": "2.64.0",
99
- "@modern-js/plugin-i18n": "2.64.0",
100
- "@modern-js/plugin-v2": "2.64.0",
101
- "@modern-js/prod-server": "2.64.0",
102
- "@modern-js/rsbuild-plugin-esbuild": "2.64.0",
103
- "@modern-js/server": "2.64.0",
104
- "@modern-js/server-core": "2.64.0",
105
- "@modern-js/server-utils": "2.64.0",
106
- "@modern-js/types": "2.64.0",
107
- "@modern-js/uni-builder": "2.64.0",
108
- "@modern-js/utils": "2.64.0"
94
+ "@modern-js/core": "2.64.2",
95
+ "@modern-js/node-bundle-require": "2.64.2",
96
+ "@modern-js/plugin-data-loader": "2.64.2",
97
+ "@modern-js/plugin": "2.64.2",
98
+ "@modern-js/plugin-i18n": "2.64.2",
99
+ "@modern-js/plugin-v2": "2.64.2",
100
+ "@modern-js/rsbuild-plugin-esbuild": "2.64.2",
101
+ "@modern-js/prod-server": "2.64.2",
102
+ "@modern-js/server": "2.64.2",
103
+ "@modern-js/server-core": "2.64.2",
104
+ "@modern-js/server-utils": "2.64.2",
105
+ "@modern-js/types": "2.64.2",
106
+ "@modern-js/uni-builder": "2.64.2",
107
+ "@modern-js/utils": "2.64.2"
109
108
  },
110
109
  "devDependencies": {
111
110
  "@rsbuild/plugin-webpack-swc": "1.0.9",
@@ -117,8 +116,8 @@
117
116
  "tsconfig-paths": "^4.2.0",
118
117
  "typescript": "^5",
119
118
  "webpack": "^5.97.1",
120
- "@scripts/jest-config": "2.64.0",
121
- "@scripts/build": "2.64.0"
119
+ "@scripts/build": "2.64.2",
120
+ "@scripts/jest-config": "2.64.2"
122
121
  },
123
122
  "peerDependencies": {
124
123
  "ts-node": "^10.7.0",