@modern-js/app-tools 3.0.3 → 3.0.5

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.
package/dist/cjs/index.js CHANGED
@@ -36,6 +36,9 @@ var __webpack_modules__ = {
36
36
  "./plugins/serverRuntime" (module) {
37
37
  module.exports = require("./plugins/serverRuntime.js");
38
38
  },
39
+ "./rsbuild" (module) {
40
+ module.exports = require("./rsbuild.js");
41
+ },
39
42
  "./types?6efa" (module) {
40
43
  module.exports = require("./types/index.js");
41
44
  },
@@ -117,7 +120,8 @@ var __webpack_exports__ = {};
117
120
  dev: ()=>_commands_dev__rspack_import_18.dev,
118
121
  generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_14.generateWatchFiles,
119
122
  initAppContext: ()=>_utils_initAppContext__rspack_import_15.initAppContext,
120
- mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_21.mergeConfig,
123
+ mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_22.mergeConfig,
124
+ resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_20.resolveModernRsbuildConfig,
121
125
  serve: ()=>_commands_serve__rspack_import_19.serve
122
126
  });
123
127
  var path__rspack_import_0 = __webpack_require__("path");
@@ -147,6 +151,7 @@ var __webpack_exports__ = {};
147
151
  var __rspack_reexport = {};
148
152
  for(const __rspack_import_key in _defineConfig__rspack_import_17)if ([
149
153
  "dev",
154
+ "resolveModernRsbuildConfig",
150
155
  "mergeConfig",
151
156
  "appTools",
152
157
  "default",
@@ -158,10 +163,12 @@ var __webpack_exports__ = {};
158
163
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
159
164
  var _commands_dev__rspack_import_18 = __webpack_require__("./commands/dev");
160
165
  var _commands_serve__rspack_import_19 = __webpack_require__("./commands/serve");
161
- var _types__rspack_import_20 = __webpack_require__("./types?6efa");
166
+ var _rsbuild__rspack_import_20 = __webpack_require__("./rsbuild");
167
+ var _types__rspack_import_21 = __webpack_require__("./types?6efa");
162
168
  var __rspack_reexport = {};
163
- for(const __rspack_import_key in _types__rspack_import_20)if ([
169
+ for(const __rspack_import_key in _types__rspack_import_21)if ([
164
170
  "dev",
171
+ "resolveModernRsbuildConfig",
165
172
  "mergeConfig",
166
173
  "appTools",
167
174
  "default",
@@ -169,9 +176,9 @@ var __webpack_exports__ = {};
169
176
  "generateWatchFiles",
170
177
  "initAppContext",
171
178
  "defineConfig"
172
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_20[__rspack_import_key];
179
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_21[__rspack_import_key];
173
180
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
174
- var _modern_js_plugin_cli__rspack_import_21 = __webpack_require__("@modern-js/plugin/cli");
181
+ var _modern_js_plugin_cli__rspack_import_22 = __webpack_require__("@modern-js/plugin/cli");
175
182
  const appTools = ()=>({
176
183
  name: '@modern-js/app-tools',
177
184
  usePlugins: [
@@ -278,6 +285,7 @@ exports.dev = __webpack_exports__.dev;
278
285
  exports.generateWatchFiles = __webpack_exports__.generateWatchFiles;
279
286
  exports.initAppContext = __webpack_exports__.initAppContext;
280
287
  exports.mergeConfig = __webpack_exports__.mergeConfig;
288
+ exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildConfig;
281
289
  exports.serve = __webpack_exports__.serve;
282
290
  for(var __rspack_i in __webpack_exports__)if (-1 === [
283
291
  "appTools",
@@ -287,6 +295,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
287
295
  "generateWatchFiles",
288
296
  "initAppContext",
289
297
  "mergeConfig",
298
+ "resolveModernRsbuildConfig",
290
299
  "serve"
291
300
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
292
301
  Object.defineProperty(exports, '__esModule', {
@@ -26,6 +26,7 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  default: ()=>analyze
28
28
  });
29
+ const types_namespaceObject = require("node:util/types");
29
30
  const external_path_namespaceObject = require("path");
30
31
  const utils_namespaceObject = require("@modern-js/utils");
31
32
  const index_js_namespaceObject = require("../../builder/index.js");
@@ -198,7 +199,16 @@ const analyze = ()=>({
198
199
  port
199
200
  });
200
201
  });
201
- builder.addPlugins(resolvedConfig.builderPlugins);
202
+ const getFlattenedPlugins = async (pluginOptions)=>{
203
+ let plugins = pluginOptions;
204
+ do plugins = (await Promise.all(plugins)).flat(1 / 0);
205
+ while (plugins.some((v)=>(0, types_namespaceObject.isPromise)(v)));
206
+ return plugins;
207
+ };
208
+ if (resolvedConfig.builderPlugins) {
209
+ const plugins = await getFlattenedPlugins(resolvedConfig.builderPlugins);
210
+ builder.addPlugins(plugins);
211
+ }
202
212
  api.updateAppContext({
203
213
  builder
204
214
  });
@@ -120,8 +120,8 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
120
120
  const serverAppContext = (0, external_utils_js_namespaceObject.serverAppContenxtTemplate)(appContext);
121
121
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${utils_namespaceObject.ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
122
122
  await utils_namespaceObject.fs.writeFile(handlerFilePath, handlerCode);
123
- if (isEsmProject) await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './netlify-entry.mjs'), entryFilePath);
124
- else await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './netlify-entry.js'), entryFilePath);
123
+ if (isEsmProject) await utils_namespaceObject.fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
124
+ else await utils_namespaceObject.fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
125
125
  },
126
126
  async end () {
127
127
  if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
@@ -142,8 +142,8 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
142
142
  let handlerCode = (await utils_namespaceObject.fs.readFile(external_node_path_default().join(__dirname, './vercel-handler.js'))).toString();
143
143
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${utils_namespaceObject.ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
144
144
  await utils_namespaceObject.fs.writeFile(handlerFilePath, handlerCode);
145
- if (isEsmProject) await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './vercel-entry.mjs'), entryFilePath);
146
- else await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './vercel-entry.js'), entryFilePath);
145
+ if (isEsmProject) await utils_namespaceObject.fs.writeFile(entryFilePath, "import { handler } from './vercel-handler.cjs';\nexport default handler;\n");
146
+ else await utils_namespaceObject.fs.writeFile(entryFilePath, "const { handler } = require('./vercel-handler.cjs');\nmodule.exports = handler;\n");
147
147
  },
148
148
  async end () {
149
149
  if (!needModernServer) return;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ resolveModernRsbuildConfig: ()=>resolveModernRsbuildConfig
28
+ });
29
+ const builder_namespaceObject = require("@modern-js/builder");
30
+ const cli_namespaceObject = require("@modern-js/plugin/cli");
31
+ const index_js_namespaceObject = require("./builder/shared/builderPlugins/index.js");
32
+ const external_constants_js_namespaceObject = require("./constants.js");
33
+ const getConfigFile_js_namespaceObject = require("./utils/getConfigFile.js");
34
+ const MODERN_META_NAME = 'modern-js';
35
+ async function resolveModernRsbuildConfig(options) {
36
+ const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
37
+ const configFile = options.configPath || (0, getConfigFile_js_namespaceObject.getConfigFile)(void 0, cwd);
38
+ if (!configFile) throw new Error(`Cannot find config file in ${cwd}. Please make sure you have a ${external_constants_js_namespaceObject.DEFAULT_CONFIG_FILE} file in your project.`);
39
+ const { config: modernConfig, getAppContext } = await (0, cli_namespaceObject.createConfigOptions)({
40
+ command: options.command,
41
+ cwd,
42
+ configFile,
43
+ metaName,
44
+ modifyModernConfig: options.modifyModernConfig
45
+ });
46
+ const nonStandardConfig = {
47
+ ...modernConfig,
48
+ plugins: modernConfig.builderPlugins
49
+ };
50
+ const appContext = getAppContext();
51
+ const { rsbuildConfig, rsbuildPlugins } = await (0, builder_namespaceObject.parseRspackConfig)(nonStandardConfig, {
52
+ cwd
53
+ });
54
+ const adapterParams = {
55
+ appContext,
56
+ normalizedConfig: modernConfig
57
+ };
58
+ rsbuildConfig.plugins = [
59
+ ...rsbuildPlugins,
60
+ ...rsbuildConfig.plugins || [],
61
+ (0, index_js_namespaceObject.builderPluginAdapterBasic)(adapterParams),
62
+ (0, index_js_namespaceObject.builderPluginAdapterHooks)(adapterParams)
63
+ ];
64
+ return {
65
+ rsbuildConfig
66
+ };
67
+ }
68
+ exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildConfig;
69
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "resolveModernRsbuildConfig"
71
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
72
+ Object.defineProperty(exports, '__esModule', {
73
+ value: true
74
+ });
@@ -39,7 +39,7 @@ const external_path_namespaceObject = require("path");
39
39
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
40
40
  const utils_namespaceObject = require("@modern-js/utils");
41
41
  const external_constants_js_namespaceObject = require("../constants.js");
42
- const getConfigFile = (configFile)=>(0, utils_namespaceObject.findExists)(utils_namespaceObject.CONFIG_FILE_EXTENSIONS.map((extension)=>external_path_default().resolve(process.cwd(), `${configFile || external_constants_js_namespaceObject.DEFAULT_CONFIG_FILE}${extension}`)));
42
+ const getConfigFile = (configFile, cwd = process.cwd())=>(0, utils_namespaceObject.findExists)(utils_namespaceObject.CONFIG_FILE_EXTENSIONS.map((extension)=>external_path_default().resolve(cwd, `${configFile || external_constants_js_namespaceObject.DEFAULT_CONFIG_FILE}${extension}`)));
43
43
  exports.getConfigFile = __webpack_exports__.getConfigFile;
44
44
  for(var __rspack_i in __webpack_exports__)if (-1 === [
45
45
  "getConfigFile"
@@ -18,6 +18,7 @@ import { restart } from "./utils/restart.mjs";
18
18
  import { defineConfig } from "./defineConfig.mjs";
19
19
  import { dev } from "./commands/dev.mjs";
20
20
  import { serve } from "./commands/serve.mjs";
21
+ import { resolveModernRsbuildConfig } from "./rsbuild.mjs";
21
22
  import { mergeConfig } from "@modern-js/plugin/cli";
22
23
  export * from "./defineConfig.mjs";
23
24
  export * from "./types/index.mjs";
@@ -119,4 +120,4 @@ const appTools = ()=>({
119
120
  }
120
121
  });
121
122
  const src = appTools;
122
- export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, serve };
123
+ export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, resolveModernRsbuildConfig, serve };
@@ -1,3 +1,4 @@
1
+ import { isPromise } from "node:util/types";
1
2
  import { extname, resolve } from "path";
2
3
  import { createDebugger, fs, getArgv, getMeta, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
3
4
  import { createBuilderGenerator } from "../../builder/index.mjs";
@@ -170,7 +171,16 @@ const analyze = ()=>({
170
171
  port
171
172
  });
172
173
  });
173
- builder.addPlugins(resolvedConfig.builderPlugins);
174
+ const getFlattenedPlugins = async (pluginOptions)=>{
175
+ let plugins = pluginOptions;
176
+ do plugins = (await Promise.all(plugins)).flat(1 / 0);
177
+ while (plugins.some((v)=>isPromise(v)));
178
+ return plugins;
179
+ };
180
+ if (resolvedConfig.builderPlugins) {
181
+ const plugins = await getFlattenedPlugins(resolvedConfig.builderPlugins);
182
+ builder.addPlugins(plugins);
183
+ }
174
184
  api.updateAppContext({
175
185
  builder
176
186
  });
@@ -82,8 +82,8 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
82
82
  const serverAppContext = serverAppContenxtTemplate(appContext);
83
83
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
84
84
  await fs.writeFile(handlerFilePath, handlerCode);
85
- if (isEsmProject) await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './netlify-entry.mjs'), entryFilePath);
86
- else await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './netlify-entry.js'), entryFilePath);
85
+ if (isEsmProject) await fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
86
+ else await fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
87
87
  },
88
88
  async end () {
89
89
  if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
@@ -104,8 +104,8 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
104
104
  let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './vercel-handler.js'))).toString();
105
105
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
106
106
  await fs.writeFile(handlerFilePath, handlerCode);
107
- if (isEsmProject) await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './vercel-entry.mjs'), entryFilePath);
108
- else await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './vercel-entry.js'), entryFilePath);
107
+ if (isEsmProject) await fs.writeFile(entryFilePath, "import { handler } from './vercel-handler.cjs';\nexport default handler;\n");
108
+ else await fs.writeFile(entryFilePath, "const { handler } = require('./vercel-handler.cjs');\nmodule.exports = handler;\n");
109
109
  },
110
110
  async end () {
111
111
  if (!needModernServer) return;
@@ -0,0 +1,40 @@
1
+ import { parseRspackConfig } from "@modern-js/builder";
2
+ import { createConfigOptions } from "@modern-js/plugin/cli";
3
+ import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
4
+ import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
5
+ import { getConfigFile } from "./utils/getConfigFile.mjs";
6
+ const MODERN_META_NAME = 'modern-js';
7
+ async function resolveModernRsbuildConfig(options) {
8
+ const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
9
+ const configFile = options.configPath || getConfigFile(void 0, cwd);
10
+ if (!configFile) throw new Error(`Cannot find config file in ${cwd}. Please make sure you have a ${DEFAULT_CONFIG_FILE} file in your project.`);
11
+ const { config: modernConfig, getAppContext } = await createConfigOptions({
12
+ command: options.command,
13
+ cwd,
14
+ configFile,
15
+ metaName,
16
+ modifyModernConfig: options.modifyModernConfig
17
+ });
18
+ const nonStandardConfig = {
19
+ ...modernConfig,
20
+ plugins: modernConfig.builderPlugins
21
+ };
22
+ const appContext = getAppContext();
23
+ const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, {
24
+ cwd
25
+ });
26
+ const adapterParams = {
27
+ appContext,
28
+ normalizedConfig: modernConfig
29
+ };
30
+ rsbuildConfig.plugins = [
31
+ ...rsbuildPlugins,
32
+ ...rsbuildConfig.plugins || [],
33
+ builderPluginAdapterBasic(adapterParams),
34
+ builderPluginAdapterHooks(adapterParams)
35
+ ];
36
+ return {
37
+ rsbuildConfig
38
+ };
39
+ }
40
+ export { resolveModernRsbuildConfig };
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
2
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
3
  import { DEFAULT_CONFIG_FILE } from "../constants.mjs";
4
- const getConfigFile = (configFile)=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
4
+ const getConfigFile = (configFile, cwd = process.cwd())=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(cwd, `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
5
5
  export { getConfigFile };
@@ -20,6 +20,7 @@ import { restart } from "./utils/restart.mjs";
20
20
  import { defineConfig } from "./defineConfig.mjs";
21
21
  import { dev } from "./commands/dev.mjs";
22
22
  import { serve } from "./commands/serve.mjs";
23
+ import { resolveModernRsbuildConfig } from "./rsbuild.mjs";
23
24
  import { mergeConfig } from "@modern-js/plugin/cli";
24
25
  export * from "./defineConfig.mjs";
25
26
  export * from "./types/index.mjs";
@@ -121,4 +122,4 @@ const appTools = ()=>({
121
122
  }
122
123
  });
123
124
  const src = appTools;
124
- export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, serve };
125
+ export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, resolveModernRsbuildConfig, serve };
@@ -1,4 +1,5 @@
1
1
  import "node:module";
2
+ import { isPromise } from "node:util/types";
2
3
  import { extname, resolve } from "path";
3
4
  import { createDebugger, fs, getArgv, getMeta, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
4
5
  import { createBuilderGenerator } from "../../builder/index.mjs";
@@ -171,7 +172,16 @@ const analyze = ()=>({
171
172
  port
172
173
  });
173
174
  });
174
- builder.addPlugins(resolvedConfig.builderPlugins);
175
+ const getFlattenedPlugins = async (pluginOptions)=>{
176
+ let plugins = pluginOptions;
177
+ do plugins = (await Promise.all(plugins)).flat(1 / 0);
178
+ while (plugins.some((v)=>isPromise(v)));
179
+ return plugins;
180
+ };
181
+ if (resolvedConfig.builderPlugins) {
182
+ const plugins = await getFlattenedPlugins(resolvedConfig.builderPlugins);
183
+ builder.addPlugins(plugins);
184
+ }
175
185
  api.updateAppContext({
176
186
  builder
177
187
  });
@@ -87,8 +87,8 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
87
87
  const serverAppContext = serverAppContenxtTemplate(appContext);
88
88
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
89
89
  await fs.writeFile(handlerFilePath, handlerCode);
90
- if (isEsmProject) await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(netlify_dirname, './netlify-entry.mjs'), entryFilePath);
91
- else await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(netlify_dirname, './netlify-entry.js'), entryFilePath);
90
+ if (isEsmProject) await fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
91
+ else await fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
92
92
  },
93
93
  async end () {
94
94
  if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
@@ -109,8 +109,8 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
109
109
  let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(vercel_dirname, './vercel-handler.js'))).toString();
110
110
  handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
111
111
  await fs.writeFile(handlerFilePath, handlerCode);
112
- if (isEsmProject) await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(vercel_dirname, './vercel-entry.mjs'), entryFilePath);
113
- else await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(vercel_dirname, './vercel-entry.js'), entryFilePath);
112
+ if (isEsmProject) await fs.writeFile(entryFilePath, "import { handler } from './vercel-handler.cjs';\nexport default handler;\n");
113
+ else await fs.writeFile(entryFilePath, "const { handler } = require('./vercel-handler.cjs');\nmodule.exports = handler;\n");
114
114
  },
115
115
  async end () {
116
116
  if (!needModernServer) return;
@@ -0,0 +1,41 @@
1
+ import "node:module";
2
+ import { parseRspackConfig } from "@modern-js/builder";
3
+ import { createConfigOptions } from "@modern-js/plugin/cli";
4
+ import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
5
+ import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
6
+ import { getConfigFile } from "./utils/getConfigFile.mjs";
7
+ const MODERN_META_NAME = 'modern-js';
8
+ async function resolveModernRsbuildConfig(options) {
9
+ const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
10
+ const configFile = options.configPath || getConfigFile(void 0, cwd);
11
+ if (!configFile) throw new Error(`Cannot find config file in ${cwd}. Please make sure you have a ${DEFAULT_CONFIG_FILE} file in your project.`);
12
+ const { config: modernConfig, getAppContext } = await createConfigOptions({
13
+ command: options.command,
14
+ cwd,
15
+ configFile,
16
+ metaName,
17
+ modifyModernConfig: options.modifyModernConfig
18
+ });
19
+ const nonStandardConfig = {
20
+ ...modernConfig,
21
+ plugins: modernConfig.builderPlugins
22
+ };
23
+ const appContext = getAppContext();
24
+ const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, {
25
+ cwd
26
+ });
27
+ const adapterParams = {
28
+ appContext,
29
+ normalizedConfig: modernConfig
30
+ };
31
+ rsbuildConfig.plugins = [
32
+ ...rsbuildPlugins,
33
+ ...rsbuildConfig.plugins || [],
34
+ builderPluginAdapterBasic(adapterParams),
35
+ builderPluginAdapterHooks(adapterParams)
36
+ ];
37
+ return {
38
+ rsbuildConfig
39
+ };
40
+ }
41
+ export { resolveModernRsbuildConfig };
@@ -2,5 +2,5 @@ import "node:module";
2
2
  import path from "path";
3
3
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
4
4
  import { DEFAULT_CONFIG_FILE } from "../constants.mjs";
5
- const getConfigFile = (configFile)=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
5
+ const getConfigFile = (configFile, cwd = process.cwd())=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(cwd, `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
6
6
  export { getConfigFile };
@@ -7,6 +7,7 @@ export { dev } from './commands/dev';
7
7
  export { serve } from './commands/serve';
8
8
  export type { DevOptions } from './utils/types';
9
9
  export { generateWatchFiles } from './utils/generateWatchFiles';
10
+ export { resolveModernRsbuildConfig, type ResolveModernRsbuildConfigOptions, } from './rsbuild';
10
11
  export * from './types';
11
12
  export { initAppContext };
12
13
  export default appTools;
@@ -0,0 +1,12 @@
1
+ import type { AppUserConfig } from './types';
2
+ type ResolveModernRsbuildConfigOptions = {
3
+ command: string;
4
+ configPath?: string;
5
+ cwd?: string;
6
+ metaName?: string;
7
+ modifyModernConfig?: (config: AppUserConfig) => AppUserConfig | Promise<AppUserConfig>;
8
+ };
9
+ export declare function resolveModernRsbuildConfig(options: ResolveModernRsbuildConfigOptions): Promise<{
10
+ rsbuildConfig: import("@modern-js/builder").RsbuildConfig;
11
+ }>;
12
+ export type { ResolveModernRsbuildConfigOptions };
@@ -1,4 +1,4 @@
1
- import type { RsbuildPlugin } from '@modern-js/builder';
1
+ import type { RsbuildPlugins } from '@modern-js/builder';
2
2
  import type { CLIPlugin, CLIPluginExtends } from '@modern-js/plugin';
3
3
  import type { BffUserConfig, ServerUserConfig } from '@modern-js/server-core';
4
4
  import type { RsbuildConfig } from '@rsbuild/core';
@@ -33,7 +33,7 @@ export interface AppToolsUserConfig {
33
33
  tools?: ToolsUserConfig;
34
34
  security?: SecurityUserConfig;
35
35
  testing?: TestingUserConfig;
36
- builderPlugins?: Array<RsbuildPlugin>;
36
+ builderPlugins?: RsbuildPlugins;
37
37
  performance?: PerformanceUserConfig;
38
38
  environments?: RsbuildConfig['environments'];
39
39
  splitChunks?: RsbuildConfig['splitChunks'];
@@ -1 +1 @@
1
- export declare const getConfigFile: (configFile?: string) => string | false;
1
+ export declare const getConfigFile: (configFile?: string, cwd?: string) => string | false;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.0.3",
18
+ "version": "3.0.5",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -80,29 +80,29 @@
80
80
  "modern-app": "./bin/modern.js"
81
81
  },
82
82
  "dependencies": {
83
- "@babel/parser": "^7.28.6",
84
- "@babel/traverse": "^7.28.6",
85
- "@babel/types": "^7.28.6",
83
+ "@babel/parser": "^7.29.0",
84
+ "@babel/traverse": "^7.29.0",
85
+ "@babel/types": "^7.29.0",
86
86
  "@rsbuild/core": "2.0.0-beta.4",
87
87
  "@swc/helpers": "^0.5.17",
88
88
  "es-module-lexer": "^1.7.0",
89
89
  "esbuild": "0.25.5",
90
90
  "esbuild-register": "^3.6.0",
91
- "flatted": "^3.3.3",
91
+ "flatted": "^3.4.0",
92
92
  "mlly": "^1.8.0",
93
93
  "ndepe": "^0.1.13",
94
94
  "pkg-types": "^1.3.1",
95
95
  "std-env": "^3.10.0",
96
- "@modern-js/builder": "3.0.3",
97
- "@modern-js/i18n-utils": "3.0.3",
98
- "@modern-js/plugin": "3.0.3",
99
- "@modern-js/plugin-data-loader": "3.0.3",
100
- "@modern-js/prod-server": "3.0.3",
101
- "@modern-js/server": "3.0.3",
102
- "@modern-js/server-core": "3.0.3",
103
- "@modern-js/server-utils": "3.0.3",
104
- "@modern-js/types": "3.0.3",
105
- "@modern-js/utils": "3.0.3"
96
+ "@modern-js/builder": "3.0.5",
97
+ "@modern-js/i18n-utils": "3.0.5",
98
+ "@modern-js/plugin": "3.0.5",
99
+ "@modern-js/plugin-data-loader": "3.0.5",
100
+ "@modern-js/prod-server": "3.0.5",
101
+ "@modern-js/server": "3.0.5",
102
+ "@modern-js/server-core": "3.0.5",
103
+ "@modern-js/server-utils": "3.0.5",
104
+ "@modern-js/types": "3.0.5",
105
+ "@modern-js/utils": "3.0.5"
106
106
  },
107
107
  "devDependencies": {
108
108
  "@rslib/core": "0.19.6",
@@ -111,8 +111,8 @@
111
111
  "ts-node": "^10.9.2",
112
112
  "tsconfig-paths": "^4.2.0",
113
113
  "typescript": "^5",
114
- "@scripts/rstest-config": "2.66.0",
115
- "@modern-js/rslib": "2.68.10"
114
+ "@modern-js/rslib": "2.68.10",
115
+ "@scripts/rstest-config": "2.66.0"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "ts-node": "^10.9.2",