@modern-js/app-tools 2.64.1 → 2.64.3-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) 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 +5 -2
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  5. package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +50 -0
  6. package/dist/cjs/builder/shared/builderPlugins/index.js +3 -1
  7. package/dist/cjs/commands/dev.js +12 -3
  8. package/dist/cjs/commands/index.js +2 -2
  9. package/dist/cjs/commands/serve.js +4 -4
  10. package/dist/cjs/esm/esbuild-loader.mjs +14 -1
  11. package/dist/cjs/esm/ts-node-loader.mjs +14 -1
  12. package/dist/cjs/index.js +4 -2
  13. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +2 -2
  14. package/dist/cjs/plugins/analyze/getServerRoutes.js +5 -3
  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 +6 -3
  18. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  19. package/dist/esm/builder/shared/builderPlugins/builderHooks.js +120 -0
  20. package/dist/esm/builder/shared/builderPlugins/index.js +1 -0
  21. package/dist/esm/commands/dev.js +11 -5
  22. package/dist/esm/commands/index.js +3 -3
  23. package/dist/esm/commands/serve.js +5 -5
  24. package/dist/esm/esm/esbuild-loader.mjs +14 -1
  25. package/dist/esm/esm/ts-node-loader.mjs +14 -1
  26. package/dist/esm/index.js +3 -2
  27. package/dist/esm/plugins/analyze/getFileSystemEntry.js +2 -2
  28. package/dist/esm/plugins/analyze/getServerRoutes.js +5 -3
  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 +5 -2
  32. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  33. package/dist/esm-node/builder/shared/builderPlugins/builderHooks.js +26 -0
  34. package/dist/esm-node/builder/shared/builderPlugins/index.js +1 -0
  35. package/dist/esm-node/commands/dev.js +12 -3
  36. package/dist/esm-node/commands/index.js +2 -2
  37. package/dist/esm-node/commands/serve.js +3 -3
  38. package/dist/esm-node/esm/esbuild-loader.mjs +14 -1
  39. package/dist/esm-node/esm/ts-node-loader.mjs +14 -1
  40. package/dist/esm-node/index.js +3 -2
  41. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +2 -2
  42. package/dist/esm-node/plugins/analyze/getServerRoutes.js +5 -3
  43. package/dist/types/builder/shared/builderPlugins/builderHooks.d.ts +4 -0
  44. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
  45. package/dist/types/commands/dev.d.ts +2 -1
  46. package/dist/types/commands/serve.d.ts +6 -1
  47. package/dist/types/esm/esbuild-loader.d.mts +1 -0
  48. package/dist/types/esm/ts-node-loader.d.mts +1 -0
  49. package/dist/types/index.d.ts +1 -0
  50. package/dist/types/types/new.d.ts +0 -5
  51. package/package.json +22 -24
@@ -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
@@ -51,11 +53,12 @@ async function generateBuilder(options, bundlerType) {
51
53
  return builder;
52
54
  }
53
55
  async function applyBuilderPlugins(builder, options) {
54
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins/index.js");
56
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderHookPlugin } = await import("../shared/builderPlugins/index.js");
55
57
  builder.addPlugins([
56
58
  builderPluginAdapterBasic(),
57
59
  builderPluginAdapterSSR(options),
58
- builderPluginAdapterHtml(options)
60
+ builderPluginAdapterHtml(options),
61
+ builderHookPlugin(options)
59
62
  ]);
60
63
  builder.addPlugins([
61
64
  (0, import_adapterCopy.builderPluginAdapterCopy)(options)
@@ -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
  });
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var builderHooks_exports = {};
20
+ __export(builderHooks_exports, {
21
+ builderHookPlugin: () => builderHookPlugin
22
+ });
23
+ module.exports = __toCommonJS(builderHooks_exports);
24
+ const builderHookPlugin = (options) => ({
25
+ name: "builder-plugin-support-modern-hooks",
26
+ setup(api) {
27
+ var _internalContext_pluginAPI;
28
+ const _internalContext = options.appContext._internalContext;
29
+ const hooks = (_internalContext_pluginAPI = _internalContext.pluginAPI) === null || _internalContext_pluginAPI === void 0 ? void 0 : _internalContext_pluginAPI.getHooks();
30
+ api.modifyBundlerChain(async (chain, utils) => {
31
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyBundlerChain.call(chain, utils));
32
+ });
33
+ api.modifyRsbuildConfig(async (config, utils) => {
34
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyRsbuildConfig.call(config, utils));
35
+ });
36
+ api.modifyRspackConfig(async (config, utils) => {
37
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyRspackConfig.call(config, utils));
38
+ });
39
+ api.modifyWebpackChain(async (chain, utils) => {
40
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackChain.call(chain, utils));
41
+ });
42
+ api.modifyWebpackConfig(async (config, utils) => {
43
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackConfig.call(config, utils));
44
+ });
45
+ }
46
+ });
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ builderHookPlugin
50
+ });
@@ -18,9 +18,11 @@ module.exports = __toCommonJS(builderPlugins_exports);
18
18
  __reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
19
19
  __reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
20
20
  __reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);
21
+ __reExport(builderPlugins_exports, require("./builderHooks"), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require("./adapterBasic"),
24
25
  ...require("./adapterHtml"),
25
- ...require("./adapterSSR")
26
+ ...require("./adapterSSR"),
27
+ ...require("./builderHooks")
26
28
  });
@@ -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
  });
@@ -1,4 +1,5 @@
1
1
  import { pathToFileURL } from 'url';
2
+ import { load as esbuildLoad } from 'esbuild-register/loader';
2
3
  import { createMatchPath } from './utils.mjs';
3
4
 
4
5
  let matchPath;
@@ -17,4 +18,16 @@ export function resolve(specifier, context, defaultResolve) {
17
18
  : defaultResolve(specifier, context);
18
19
  }
19
20
 
20
- export { load } from 'esbuild-register/loader';
21
+ export function load(url, context, defaultLoad) {
22
+ const filePath = new URL(url).pathname;
23
+
24
+ if (url.startsWith('node:')) {
25
+ return defaultLoad(url, context);
26
+ }
27
+
28
+ if (filePath.includes('node_modules')) {
29
+ return defaultLoad(url, context);
30
+ }
31
+
32
+ return esbuildLoad(url, context, defaultLoad);
33
+ }
@@ -1,5 +1,6 @@
1
1
  import { pathToFileURL } from 'url';
2
2
  import { resolve as tsNodeResolve } from 'ts-node/esm';
3
+ import { load as tsNodeLoad } from 'ts-node/esm';
3
4
  import { createMatchPath } from './utils.mjs';
4
5
 
5
6
  let matchPath;
@@ -18,4 +19,16 @@ export function resolve(specifier, context, defaultResolve) {
18
19
  : tsNodeResolve(specifier, context, defaultResolve);
19
20
  }
20
21
 
21
- export { transformSource, load } from 'ts-node/esm';
22
+ export function load(url, context, defaultLoad) {
23
+ const filePath = new URL(url).pathname;
24
+
25
+ if (url.startsWith('node:')) {
26
+ return defaultLoad(url, context);
27
+ }
28
+
29
+ if (filePath.includes('node_modules')) {
30
+ return defaultLoad(url, context);
31
+ }
32
+
33
+ return tsNodeLoad(url, context, defaultLoad);
34
+ }
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 = {
@@ -99,7 +101,6 @@ const appTools = (options = {
99
101
  checkEntryPoint: (0, import_plugin_v2.createAsyncHook)(),
100
102
  modifyEntrypoints: (0, import_plugin_v2.createAsyncHook)(),
101
103
  modifyFileSystemRoutes: (0, import_plugin_v2.createAsyncHook)(),
102
- modifyServerRoutes: (0, import_plugin_v2.createAsyncHook)(),
103
104
  generateEntryCode: (0, import_plugin_v2.createAsyncHook)(),
104
105
  onBeforeGenerateRoutes: (0, import_plugin_v2.createAsyncHook)(),
105
106
  onBeforePrintInstructions: (0, import_plugin_v2.createAsyncHook)(),
@@ -195,6 +196,7 @@ var src_default = appTools;
195
196
  generateWatchFiles,
196
197
  initAppContext,
197
198
  mergeConfig,
199
+ serve,
198
200
  ...require("./defineConfig"),
199
201
  ...require("./types")
200
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] : {
@@ -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
@@ -49,7 +51,7 @@ function applyBuilderPlugins(builder, options) {
49
51
  }
50
52
  function _applyBuilderPlugins() {
51
53
  _applyBuilderPlugins = _async_to_generator(function(builder, options) {
52
- var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, normalizedConfig, pluginNodePolyfill;
54
+ var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderHookPlugin, normalizedConfig, pluginNodePolyfill;
53
55
  return _ts_generator(this, function(_state) {
54
56
  switch (_state.label) {
55
57
  case 0:
@@ -58,11 +60,12 @@ function _applyBuilderPlugins() {
58
60
  import("../shared/builderPlugins/index.js")
59
61
  ];
60
62
  case 1:
61
- _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR;
63
+ _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR, builderHookPlugin = _ref.builderHookPlugin;
62
64
  builder.addPlugins([
63
65
  builderPluginAdapterBasic(),
64
66
  builderPluginAdapterSSR(options),
65
- builderPluginAdapterHtml(options)
67
+ builderPluginAdapterHtml(options),
68
+ builderHookPlugin(options)
66
69
  ]);
67
70
  builder.addPlugins([
68
71
  builderPluginAdapterCopy(options)
@@ -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
  });
@@ -0,0 +1,120 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ var builderHookPlugin = function(options) {
4
+ return {
5
+ name: "builder-plugin-support-modern-hooks",
6
+ setup: function setup(api) {
7
+ var _internalContext_pluginAPI;
8
+ var _internalContext = options.appContext._internalContext;
9
+ var hooks = (_internalContext_pluginAPI = _internalContext.pluginAPI) === null || _internalContext_pluginAPI === void 0 ? void 0 : _internalContext_pluginAPI.getHooks();
10
+ api.modifyBundlerChain(function() {
11
+ var _ref = _async_to_generator(function(chain, utils) {
12
+ return _ts_generator(this, function(_state) {
13
+ switch (_state.label) {
14
+ case 0:
15
+ return [
16
+ 4,
17
+ hooks === null || hooks === void 0 ? void 0 : hooks.modifyBundlerChain.call(chain, utils)
18
+ ];
19
+ case 1:
20
+ _state.sent();
21
+ return [
22
+ 2
23
+ ];
24
+ }
25
+ });
26
+ });
27
+ return function(chain, utils) {
28
+ return _ref.apply(this, arguments);
29
+ };
30
+ }());
31
+ api.modifyRsbuildConfig(function() {
32
+ var _ref = _async_to_generator(function(config, utils) {
33
+ return _ts_generator(this, function(_state) {
34
+ switch (_state.label) {
35
+ case 0:
36
+ return [
37
+ 4,
38
+ hooks === null || hooks === void 0 ? void 0 : hooks.modifyRsbuildConfig.call(config, utils)
39
+ ];
40
+ case 1:
41
+ _state.sent();
42
+ return [
43
+ 2
44
+ ];
45
+ }
46
+ });
47
+ });
48
+ return function(config, utils) {
49
+ return _ref.apply(this, arguments);
50
+ };
51
+ }());
52
+ api.modifyRspackConfig(function() {
53
+ var _ref = _async_to_generator(function(config, utils) {
54
+ return _ts_generator(this, function(_state) {
55
+ switch (_state.label) {
56
+ case 0:
57
+ return [
58
+ 4,
59
+ hooks === null || hooks === void 0 ? void 0 : hooks.modifyRspackConfig.call(config, utils)
60
+ ];
61
+ case 1:
62
+ _state.sent();
63
+ return [
64
+ 2
65
+ ];
66
+ }
67
+ });
68
+ });
69
+ return function(config, utils) {
70
+ return _ref.apply(this, arguments);
71
+ };
72
+ }());
73
+ api.modifyWebpackChain(function() {
74
+ var _ref = _async_to_generator(function(chain, utils) {
75
+ return _ts_generator(this, function(_state) {
76
+ switch (_state.label) {
77
+ case 0:
78
+ return [
79
+ 4,
80
+ hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackChain.call(chain, utils)
81
+ ];
82
+ case 1:
83
+ _state.sent();
84
+ return [
85
+ 2
86
+ ];
87
+ }
88
+ });
89
+ });
90
+ return function(chain, utils) {
91
+ return _ref.apply(this, arguments);
92
+ };
93
+ }());
94
+ api.modifyWebpackConfig(function() {
95
+ var _ref = _async_to_generator(function(config, utils) {
96
+ return _ts_generator(this, function(_state) {
97
+ switch (_state.label) {
98
+ case 0:
99
+ return [
100
+ 4,
101
+ hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackConfig.call(config, utils)
102
+ ];
103
+ case 1:
104
+ _state.sent();
105
+ return [
106
+ 2
107
+ ];
108
+ }
109
+ });
110
+ });
111
+ return function(config, utils) {
112
+ return _ref.apply(this, arguments);
113
+ };
114
+ }());
115
+ }
116
+ };
117
+ };
118
+ export {
119
+ builderHookPlugin
120
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./builderHooks";
@@ -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
  };
@@ -1,4 +1,5 @@
1
1
  import { pathToFileURL } from 'url';
2
+ import { load as esbuildLoad } from 'esbuild-register/loader';
2
3
  import { createMatchPath } from './utils.mjs';
3
4
 
4
5
  let matchPath;
@@ -17,4 +18,16 @@ export function resolve(specifier, context, defaultResolve) {
17
18
  : defaultResolve(specifier, context);
18
19
  }
19
20
 
20
- export { load } from 'esbuild-register/loader';
21
+ export function load(url, context, defaultLoad) {
22
+ const filePath = new URL(url).pathname;
23
+
24
+ if (url.startsWith('node:')) {
25
+ return defaultLoad(url, context);
26
+ }
27
+
28
+ if (filePath.includes('node_modules')) {
29
+ return defaultLoad(url, context);
30
+ }
31
+
32
+ return esbuildLoad(url, context, defaultLoad);
33
+ }
@@ -1,5 +1,6 @@
1
1
  import { pathToFileURL } from 'url';
2
2
  import { resolve as tsNodeResolve } from 'ts-node/esm';
3
+ import { load as tsNodeLoad } from 'ts-node/esm';
3
4
  import { createMatchPath } from './utils.mjs';
4
5
 
5
6
  let matchPath;
@@ -18,4 +19,16 @@ export function resolve(specifier, context, defaultResolve) {
18
19
  : tsNodeResolve(specifier, context, defaultResolve);
19
20
  }
20
21
 
21
- export { transformSource, load } from 'ts-node/esm';
22
+ export function load(url, context, defaultLoad) {
23
+ const filePath = new URL(url).pathname;
24
+
25
+ if (url.startsWith('node:')) {
26
+ return defaultLoad(url, context);
27
+ }
28
+
29
+ if (filePath.includes('node_modules')) {
30
+ return defaultLoad(url, context);
31
+ }
32
+
33
+ return tsNodeLoad(url, context, defaultLoad);
34
+ }
package/dist/esm/index.js CHANGED
@@ -58,7 +58,6 @@ var appTools = function() {
58
58
  checkEntryPoint: createAsyncHook(),
59
59
  modifyEntrypoints: createAsyncHook(),
60
60
  modifyFileSystemRoutes: createAsyncHook(),
61
- modifyServerRoutes: createAsyncHook(),
62
61
  generateEntryCode: createAsyncHook(),
63
62
  onBeforeGenerateRoutes: createAsyncHook(),
64
63
  onBeforePrintInstructions: createAsyncHook(),
@@ -247,6 +246,7 @@ var appTools = function() {
247
246
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
248
247
  import { mergeConfig } from "@modern-js/core";
249
248
  import { dev } from "./commands/dev";
249
+ import { serve } from "./commands/serve";
250
250
  import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
251
251
  export * from "./types";
252
252
  var src_default = appTools;
@@ -258,5 +258,6 @@ export {
258
258
  dev,
259
259
  generateWatchFiles2 as generateWatchFiles,
260
260
  initAppContext,
261
- mergeConfig
261
+ mergeConfig,
262
+ serve
262
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] : {
@@ -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
@@ -18,11 +20,12 @@ async function generateBuilder(options, bundlerType) {
18
20
  return builder;
19
21
  }
20
22
  async function applyBuilderPlugins(builder, options) {
21
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins/index.js");
23
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderHookPlugin } = await import("../shared/builderPlugins/index.js");
22
24
  builder.addPlugins([
23
25
  builderPluginAdapterBasic(),
24
26
  builderPluginAdapterSSR(options),
25
- builderPluginAdapterHtml(options)
27
+ builderPluginAdapterHtml(options),
28
+ builderHookPlugin(options)
26
29
  ]);
27
30
  builder.addPlugins([
28
31
  builderPluginAdapterCopy(options)
@@ -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
  });
@@ -0,0 +1,26 @@
1
+ const builderHookPlugin = (options) => ({
2
+ name: "builder-plugin-support-modern-hooks",
3
+ setup(api) {
4
+ var _internalContext_pluginAPI;
5
+ const _internalContext = options.appContext._internalContext;
6
+ const hooks = (_internalContext_pluginAPI = _internalContext.pluginAPI) === null || _internalContext_pluginAPI === void 0 ? void 0 : _internalContext_pluginAPI.getHooks();
7
+ api.modifyBundlerChain(async (chain, utils) => {
8
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyBundlerChain.call(chain, utils));
9
+ });
10
+ api.modifyRsbuildConfig(async (config, utils) => {
11
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyRsbuildConfig.call(config, utils));
12
+ });
13
+ api.modifyRspackConfig(async (config, utils) => {
14
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyRspackConfig.call(config, utils));
15
+ });
16
+ api.modifyWebpackChain(async (chain, utils) => {
17
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackChain.call(chain, utils));
18
+ });
19
+ api.modifyWebpackConfig(async (config, utils) => {
20
+ await (hooks === null || hooks === void 0 ? void 0 : hooks.modifyWebpackConfig.call(config, utils));
21
+ });
22
+ }
23
+ });
24
+ export {
25
+ builderHookPlugin
26
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./builderHooks";
@@ -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
  };
@@ -1,4 +1,5 @@
1
1
  import { pathToFileURL } from 'url';
2
+ import { load as esbuildLoad } from 'esbuild-register/loader';
2
3
  import { createMatchPath } from './utils.mjs';
3
4
 
4
5
  let matchPath;
@@ -17,4 +18,16 @@ export function resolve(specifier, context, defaultResolve) {
17
18
  : defaultResolve(specifier, context);
18
19
  }
19
20
 
20
- export { load } from 'esbuild-register/loader';
21
+ export function load(url, context, defaultLoad) {
22
+ const filePath = new URL(url).pathname;
23
+
24
+ if (url.startsWith('node:')) {
25
+ return defaultLoad(url, context);
26
+ }
27
+
28
+ if (filePath.includes('node_modules')) {
29
+ return defaultLoad(url, context);
30
+ }
31
+
32
+ return esbuildLoad(url, context, defaultLoad);
33
+ }
@@ -1,5 +1,6 @@
1
1
  import { pathToFileURL } from 'url';
2
2
  import { resolve as tsNodeResolve } from 'ts-node/esm';
3
+ import { load as tsNodeLoad } from 'ts-node/esm';
3
4
  import { createMatchPath } from './utils.mjs';
4
5
 
5
6
  let matchPath;
@@ -18,4 +19,16 @@ export function resolve(specifier, context, defaultResolve) {
18
19
  : tsNodeResolve(specifier, context, defaultResolve);
19
20
  }
20
21
 
21
- export { transformSource, load } from 'ts-node/esm';
22
+ export function load(url, context, defaultLoad) {
23
+ const filePath = new URL(url).pathname;
24
+
25
+ if (url.startsWith('node:')) {
26
+ return defaultLoad(url, context);
27
+ }
28
+
29
+ if (filePath.includes('node_modules')) {
30
+ return defaultLoad(url, context);
31
+ }
32
+
33
+ return tsNodeLoad(url, context, defaultLoad);
34
+ }
@@ -53,7 +53,6 @@ const appTools = (options = {
53
53
  checkEntryPoint: createAsyncHook(),
54
54
  modifyEntrypoints: createAsyncHook(),
55
55
  modifyFileSystemRoutes: createAsyncHook(),
56
- modifyServerRoutes: createAsyncHook(),
57
56
  generateEntryCode: createAsyncHook(),
58
57
  onBeforeGenerateRoutes: createAsyncHook(),
59
58
  onBeforePrintInstructions: createAsyncHook(),
@@ -142,6 +141,7 @@ const appTools = (options = {
142
141
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
143
142
  import { mergeConfig } from "@modern-js/core";
144
143
  import { dev } from "./commands/dev";
144
+ import { serve } from "./commands/serve";
145
145
  import { generateWatchFiles as generateWatchFiles2 } from "./utils/generateWatchFiles";
146
146
  export * from "./types";
147
147
  var src_default = appTools;
@@ -153,5 +153,6 @@ export {
153
153
  dev,
154
154
  generateWatchFiles2 as generateWatchFiles,
155
155
  initAppContext,
156
- mergeConfig
156
+ mergeConfig,
157
+ serve
157
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] : {
@@ -0,0 +1,4 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Bundler } from '../../../types';
3
+ import type { BuilderOptions } from '../types';
4
+ export declare const builderHookPlugin: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;
@@ -1,3 +1,4 @@
1
1
  export * from './adapterBasic';
2
2
  export * from './adapterHtml';
3
3
  export * from './adapterSSR';
4
+ export * from './builderHooks';
@@ -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 {};
@@ -4,3 +4,4 @@ export function initialize({ appDir, alias, tsconfigPath }: {
4
4
  tsconfigPath: any;
5
5
  }): Promise<void>;
6
6
  export function resolve(specifier: any, context: any, defaultResolve: any): any;
7
+ export function load(url: any, context: any, defaultLoad: any): any;
@@ -4,3 +4,4 @@ export function initialize({ appDir, alias, tsconfigPath }: {
4
4
  tsconfigPath: any;
5
5
  }): Promise<void>;
6
6
  export function resolve(specifier: any, context: any, defaultResolve: any): any;
7
+ export function load(url: any, context: any, defaultLoad: any): any;
@@ -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';
@@ -18,9 +18,6 @@ export type ModifyFileSystemRoutesFn = TransformFunction<{
18
18
  entrypoint: Entrypoint;
19
19
  routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
20
20
  }>;
21
- export type ModifyServerRoutesFn = TransformFunction<{
22
- routes: ServerRoute[];
23
- }>;
24
21
  export type DeplpoyFn = () => Promise<void> | void;
25
22
  export type GenerateEntryCodeFn = (params: {
26
23
  entrypoints: Entrypoint[];
@@ -41,7 +38,6 @@ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
41
38
  checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
42
39
  modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
43
40
  modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
44
- modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
45
41
  generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
46
42
  onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
47
43
  /**
@@ -83,7 +79,6 @@ export interface AppToolsExtendHooks extends Record<string, PluginHook<(...args:
83
79
  checkEntryPoint: AsyncHook<CheckEntryPointFn>;
84
80
  modifyEntrypoints: AsyncHook<ModifyEntrypointsFn>;
85
81
  modifyFileSystemRoutes: AsyncHook<ModifyFileSystemRoutesFn>;
86
- modifyServerRoutes: AsyncHook<ModifyServerRoutesFn>;
87
82
  generateEntryCode: AsyncHook<GenerateEntryCodeFn>;
88
83
  onBeforeGenerateRoutes: AsyncHook<BeforeGenerateRoutesFn>;
89
84
  /**
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.64.1",
18
+ "version": "2.64.3-alpha.0",
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.8",
84
+ "@rsbuild/plugin-node-polyfill": "1.3.0",
85
85
  "@swc/helpers": "0.5.13",
86
- "@vercel/nft": "^0.29.0",
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/node-bundle-require": "2.64.1",
96
- "@modern-js/core": "2.64.1",
97
- "@modern-js/plugin": "2.64.1",
98
- "@modern-js/plugin-data-loader": "2.64.1",
99
- "@modern-js/plugin-v2": "2.64.1",
100
- "@modern-js/plugin-i18n": "2.64.1",
101
- "@modern-js/rsbuild-plugin-esbuild": "2.64.1",
102
- "@modern-js/prod-server": "2.64.1",
103
- "@modern-js/server": "2.64.1",
104
- "@modern-js/server-core": "2.64.1",
105
- "@modern-js/server-utils": "2.64.1",
106
- "@modern-js/types": "2.64.1",
107
- "@modern-js/uni-builder": "2.64.1",
108
- "@modern-js/utils": "2.64.1"
94
+ "@modern-js/core": "2.64.3",
95
+ "@modern-js/plugin": "2.64.3",
96
+ "@modern-js/plugin-i18n": "2.64.3",
97
+ "@modern-js/plugin-v2": "2.64.3",
98
+ "@modern-js/prod-server": "2.64.3",
99
+ "@modern-js/server": "2.64.3",
100
+ "@modern-js/rsbuild-plugin-esbuild": "2.64.3",
101
+ "@modern-js/node-bundle-require": "2.64.3",
102
+ "@modern-js/server-core": "2.64.3",
103
+ "@modern-js/server-utils": "2.64.3",
104
+ "@modern-js/uni-builder": "2.64.3",
105
+ "@modern-js/types": "2.64.3",
106
+ "@modern-js/utils": "2.64.3",
107
+ "@modern-js/plugin-data-loader": "2.64.3"
109
108
  },
110
109
  "devDependencies": {
111
110
  "@rsbuild/plugin-webpack-swc": "1.0.9",
@@ -116,9 +115,9 @@
116
115
  "ts-node": "^10.9.1",
117
116
  "tsconfig-paths": "^4.2.0",
118
117
  "typescript": "^5",
119
- "webpack": "^5.97.1",
120
- "@scripts/build": "2.64.1",
121
- "@scripts/jest-config": "2.64.1"
118
+ "webpack": "^5.98.0",
119
+ "@scripts/build": "2.64.3",
120
+ "@scripts/jest-config": "2.64.3"
122
121
  },
123
122
  "peerDependencies": {
124
123
  "ts-node": "^10.7.0",
@@ -135,8 +134,7 @@
135
134
  "sideEffects": false,
136
135
  "publishConfig": {
137
136
  "registry": "https://registry.npmjs.org/",
138
- "access": "public",
139
- "provenance": true
137
+ "access": "public"
140
138
  },
141
139
  "scripts": {
142
140
  "new": "modern-lib new",