@modern-js/app-tools 3.0.4 → 3.1.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 (113) hide show
  1. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  2. package/dist/cjs/config/default.js +1 -1
  3. package/dist/cjs/index.js +14 -5
  4. package/dist/cjs/plugins/analyze/utils.js +6 -6
  5. package/dist/cjs/plugins/deploy/index.js +10 -5
  6. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +1 -1
  7. package/dist/cjs/plugins/deploy/platforms/netlify.js +17 -33
  8. package/dist/cjs/plugins/deploy/platforms/node.js +17 -38
  9. package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  10. package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  11. package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  12. package/dist/{esm/plugins/deploy/platforms → cjs/plugins/deploy/platforms/templates}/node-entry.mjs +5 -27
  13. package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  14. package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  15. package/dist/cjs/plugins/deploy/platforms/vercel.js +15 -32
  16. package/dist/cjs/plugins/deploy/types.js +18 -0
  17. package/dist/cjs/plugins/deploy/utils/generator.js +103 -0
  18. package/dist/cjs/plugins/deploy/{utils.js → utils/index.js} +28 -24
  19. package/dist/cjs/rsbuild.js +74 -0
  20. package/dist/cjs/utils/getConfigFile.js +1 -1
  21. package/dist/cjs/utils/register.js +1 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
  23. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  24. package/dist/esm/commands/build.mjs +3 -3
  25. package/dist/esm/commands/dev.mjs +5 -5
  26. package/dist/esm/commands/serve.mjs +2 -2
  27. package/dist/esm/config/default.mjs +1 -1
  28. package/dist/esm/esm/register-esm.mjs +3 -3
  29. package/dist/esm/index.mjs +2 -1
  30. package/dist/esm/plugins/analyze/utils.mjs +2 -2
  31. package/dist/esm/plugins/deploy/index.mjs +9 -4
  32. package/dist/esm/plugins/deploy/platforms/gh-pages.mjs +1 -1
  33. package/dist/esm/plugins/deploy/platforms/netlify.mjs +25 -41
  34. package/dist/esm/plugins/deploy/platforms/node.mjs +22 -43
  35. package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  36. package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  37. package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  38. package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
  39. package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  40. package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  41. package/dist/esm/plugins/deploy/platforms/vercel.mjs +28 -45
  42. package/dist/esm/plugins/deploy/types.mjs +0 -0
  43. package/dist/esm/plugins/deploy/utils/generator.mjs +47 -0
  44. package/dist/esm/plugins/deploy/utils/index.mjs +40 -0
  45. package/dist/esm/rsbuild.mjs +40 -0
  46. package/dist/esm/utils/getConfigFile.mjs +1 -1
  47. package/dist/esm/utils/loadPlugins.mjs +4 -4
  48. package/dist/esm/utils/register.mjs +6 -14
  49. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  51. package/dist/esm-node/commands/build.mjs +3 -3
  52. package/dist/esm-node/commands/dev.mjs +5 -5
  53. package/dist/esm-node/commands/serve.mjs +2 -2
  54. package/dist/esm-node/config/default.mjs +1 -1
  55. package/dist/esm-node/esm/register-esm.mjs +3 -3
  56. package/dist/esm-node/index.mjs +2 -1
  57. package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
  58. package/dist/esm-node/plugins/deploy/index.mjs +9 -4
  59. package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +1 -1
  60. package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +25 -44
  61. package/dist/esm-node/plugins/deploy/platforms/node.mjs +22 -46
  62. package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  63. package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  64. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  65. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
  66. package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  67. package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  68. package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +28 -48
  69. package/dist/esm-node/plugins/deploy/types.mjs +1 -0
  70. package/dist/esm-node/plugins/deploy/utils/generator.mjs +48 -0
  71. package/dist/esm-node/plugins/deploy/utils/index.mjs +44 -0
  72. package/dist/esm-node/rsbuild.mjs +41 -0
  73. package/dist/esm-node/utils/getConfigFile.mjs +1 -1
  74. package/dist/esm-node/utils/loadPlugins.mjs +4 -4
  75. package/dist/esm-node/utils/register.mjs +6 -14
  76. package/dist/types/index.d.ts +1 -0
  77. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  78. package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -1
  79. package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.mts +2 -0
  80. package/dist/types/plugins/deploy/platforms/templates/node-entry.d.mts +1 -0
  81. package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.cts +2 -0
  82. package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.mts +2 -0
  83. package/dist/types/plugins/deploy/types.d.ts +3 -0
  84. package/dist/types/plugins/deploy/utils/generator.d.ts +24 -0
  85. package/dist/types/plugins/deploy/utils/index.d.ts +16 -0
  86. package/dist/types/rsbuild.d.ts +12 -0
  87. package/dist/types/utils/getConfigFile.d.ts +1 -1
  88. package/package.json +16 -15
  89. package/rslib.config.mts +19 -0
  90. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -36
  91. package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +0 -89
  92. package/dist/cjs/plugins/deploy/platforms/node-entry.js +0 -75
  93. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -37
  94. package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +0 -89
  95. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +0 -2
  96. package/dist/esm/plugins/deploy/platforms/netlify-handler.mjs +0 -85
  97. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +0 -3
  98. package/dist/esm/plugins/deploy/platforms/vercel-handler.mjs +0 -85
  99. package/dist/esm/plugins/deploy/utils.mjs +0 -39
  100. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +0 -3
  101. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +0 -89
  102. package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +0 -72
  103. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +0 -4
  104. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +0 -89
  105. package/dist/esm-node/plugins/deploy/utils.mjs +0 -40
  106. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -2
  107. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
  108. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
  109. package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +0 -2
  110. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
  111. package/dist/types/plugins/deploy/utils.d.ts +0 -23
  112. /package/dist/types/plugins/deploy/platforms/{netlify-handler.d.cts → templates/netlify-entry.d.cts} +0 -0
  113. /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → templates/node-entry.d.cts} +0 -0
@@ -1,20 +1,16 @@
1
- import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta, removeModuleSyncFromExports } from "@modern-js/utils";
1
+ import node_path from "node:path";
2
+ import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
2
3
  import { nodeDepEmit } from "ndepe";
3
4
  import { isMainEntry } from "../../../utils/routes.mjs";
4
- import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils.mjs";
5
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
6
- const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
7
- const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
5
+ import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
6
+ import { generateHandler } from "../utils/generator.mjs";
7
+ const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
8
+ const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
8
9
  const isEsmProject = 'module' === moduleType;
9
- const plugins = serverPlugins.map((plugin)=>[
10
- plugin.name,
11
- plugin.options
12
- ]);
13
- const vercelOutput = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.vercel');
14
- const outputDirectory = __rspack_external_node_path_c5b9b54f["default"].join(vercelOutput, 'output');
15
- const funcsDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'functions', 'index.func');
16
- const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'index.js');
17
- const handlerFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'vercel-handler.cjs');
10
+ const vercelOutput = node_path.join(appDirectory, '.vercel');
11
+ const outputDirectory = node_path.join(vercelOutput, 'output');
12
+ const funcsDirectory = node_path.join(outputDirectory, 'functions', 'index.func');
13
+ const entryFilePath = node_path.join(funcsDirectory, 'index.js');
18
14
  return {
19
15
  async prepare () {
20
16
  await fs.remove(vercelOutput);
@@ -54,21 +50,21 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
54
50
  });
55
51
  }
56
52
  await fs.ensureDir(outputDirectory);
57
- await fs.writeJSON(__rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'config.json'), config, {
53
+ await fs.writeJSON(node_path.join(outputDirectory, 'config.json'), config, {
58
54
  spaces: 2
59
55
  });
60
- const staticDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'static/static');
61
- await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(distDirectory, 'static'), staticDirectory);
56
+ const staticDirectory = node_path.join(outputDirectory, 'static/static');
57
+ await fs.copy(node_path.join(distDirectory, 'static'), staticDirectory);
62
58
  if (needModernServer) {
63
59
  await fs.ensureDir(funcsDirectory);
64
60
  await fs.copy(distDirectory, funcsDirectory, {
65
61
  filter: (src)=>{
66
- const distStaticDirectory = __rspack_external_node_path_c5b9b54f["default"].join(distDirectory, 'static');
62
+ const distStaticDirectory = node_path.join(distDirectory, 'static');
67
63
  return !src.includes(distStaticDirectory);
68
64
  }
69
65
  });
70
66
  const nodeVersion = process.versions.node.split('.')[0];
71
- await fs.writeJSON(__rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, '.vc-config.json'), {
67
+ await fs.writeJSON(node_path.join(funcsDirectory, '.vc-config.json'), {
72
68
  runtime: `nodejs${nodeVersion}.x`,
73
69
  handler: 'index.js',
74
70
  launcherType: 'Nodejs',
@@ -76,44 +72,31 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
76
72
  supportsResponseStreaming: true
77
73
  });
78
74
  } else {
79
- const destHtmlDirectory = __rspack_external_node_path_c5b9b54f["default"].join(distDirectory, 'html');
80
- const outputHtmlDirectory = __rspack_external_node_path_c5b9b54f["default"].join(__rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'static'), 'html');
75
+ const destHtmlDirectory = node_path.join(distDirectory, 'html');
76
+ const outputHtmlDirectory = node_path.join(node_path.join(outputDirectory, 'static'), 'html');
81
77
  await fs.copy(destHtmlDirectory, outputHtmlDirectory);
82
78
  }
83
79
  },
84
80
  async genEntry () {
85
81
  if (!needModernServer) return;
86
- const serverConfig = {
87
- bff: {
88
- prefix: modernConfig?.bff?.prefix
89
- },
90
- output: {
91
- distPath: {
92
- root: '.'
93
- }
94
- }
95
- };
96
- const pluginImportCode = genPluginImportsCode(plugins || []);
97
- const dynamicProdOptions = {
98
- config: serverConfig
99
- };
100
- const meta = getMeta(metaName);
101
- const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
102
- const pluginsCode = getPluginsCode(plugins || []);
103
- const serverAppContext = serverAppContenxtTemplate(appContext);
104
- let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './vercel-handler.js'))).toString();
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
- 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);
82
+ const template = await readTemplate(`vercel-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
83
+ const code = await generateHandler({
84
+ template,
85
+ appContext,
86
+ config: modernConfig,
87
+ isESM: isEsmProject
88
+ });
89
+ await fs.writeFile(entryFilePath, code);
109
90
  },
110
91
  async end () {
111
92
  if (!needModernServer) return;
93
+ const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
94
+ if (!entry) throw new Error('Cannot find @modern-js/prod-server');
112
95
  await nodeDepEmit({
113
96
  appDir: appDirectory,
114
97
  sourceDir: funcsDirectory,
115
98
  includeEntries: [
116
- require.resolve('@modern-js/prod-server')
99
+ entry
117
100
  ],
118
101
  copyWholePackage (pkgName) {
119
102
  return '@modern-js/utils' === pkgName;
File without changes
@@ -0,0 +1,47 @@
1
+ import node_path from "node:path";
2
+ import { ROUTE_SPEC_FILE, SERVER_DIR, getMeta } from "@modern-js/utils";
3
+ import { merge } from "@modern-js/utils/lodash";
4
+ import { normalizePath } from "./index.mjs";
5
+ const serverAppContextTemplate = (appContext)=>{
6
+ const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
7
+ return {
8
+ sharedDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, sharedDirectory))}")`,
9
+ apiDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, apiDirectory))}")`,
10
+ lambdaDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, lambdaDirectory))}")`,
11
+ metaName,
12
+ bffRuntimeFramework: bffRuntimeFramework || 'hono'
13
+ };
14
+ };
15
+ const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
16
+ const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
17
+ return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
18
+ }).join(';\n');
19
+ const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
20
+ const getServerConfigPath = (meta)=>`"${normalizePath(node_path.join(SERVER_DIR, `${meta}.server`))}"`;
21
+ const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
22
+ const { serverPlugins, metaName } = appContext;
23
+ const plugins = serverPlugins.map((plugin)=>[
24
+ plugin.name,
25
+ plugin.options
26
+ ]);
27
+ const serverConfig = merge({
28
+ bff: {
29
+ prefix: config?.bff?.prefix
30
+ },
31
+ output: {
32
+ distPath: {
33
+ root: '.'
34
+ }
35
+ }
36
+ }, modifyServerConfig || {});
37
+ const meta = getMeta(metaName);
38
+ const pluginImportCode = genPluginImports(plugins || [], Boolean(isESM));
39
+ const dynamicProdOptions = {
40
+ config: serverConfig
41
+ };
42
+ const serverConfigPath = getServerConfigPath(meta);
43
+ const pluginsCode = getPluginsCode(plugins);
44
+ const serverAppContext = genAppContextTemplate(appContext);
45
+ return template.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);
46
+ };
47
+ export { genPluginImportsCode, generateHandler, getPluginsCode, getServerConfigPath, serverAppContextTemplate };
@@ -0,0 +1,40 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import path from "path";
3
+ import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
4
+ const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
5
+ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
6
+ const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
7
+ const { routes } = fs.readJSONSync(routeJSON);
8
+ let useSSR = false;
9
+ let useAPI = false;
10
+ routes.forEach((route)=>{
11
+ if (route.isSSR) useSSR = true;
12
+ if (route.isApi) useAPI = true;
13
+ });
14
+ const meta = getMeta(metaName);
15
+ const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
16
+ const isServerConfigExists = [
17
+ '.ts',
18
+ '.js'
19
+ ].some((ex)=>fs.existsSync(`${serverConfigPath}${ex}`));
20
+ return {
21
+ useSSR,
22
+ useAPI,
23
+ useWebServer: isServerConfigExists
24
+ };
25
+ };
26
+ const getTemplatePath = (file)=>path.join(__dirname, '../platforms/templates', file);
27
+ const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
28
+ const resolveESMDependency = async (entry)=>{
29
+ const conditions = new Set([
30
+ 'node',
31
+ 'import',
32
+ 'module',
33
+ 'default'
34
+ ]);
35
+ try {
36
+ const { moduleResolve } = await import("import-meta-resolve");
37
+ return normalizePath(moduleResolve(entry, pathToFileURL(`${__dirname}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:'));
38
+ } catch (err) {}
39
+ };
40
+ export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
@@ -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 };
@@ -1,5 +1,5 @@
1
+ import { loadServerPlugins } from "@modern-js/prod-server";
1
2
  import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
2
- import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
3
3
  const debug = createDebugger('load-plugins');
4
4
  async function getServerPlugins(api, metaName = 'modern-js') {
5
5
  const hooks = api.getHooks();
@@ -12,9 +12,9 @@ async function getServerPlugins(api, metaName = 'modern-js') {
12
12
  });
13
13
  return filtedPlugins;
14
14
  }
15
- async function loadServerPlugins(api, appDirectory, metaName) {
15
+ async function loadPlugins_loadServerPlugins(api, appDirectory, metaName) {
16
16
  const plugins = await getServerPlugins(api, metaName);
17
- const instances = await (0, __rspack_external__modern_js_prod_server_057184e2.loadServerPlugins)(plugins, appDirectory);
17
+ const instances = await loadServerPlugins(plugins, appDirectory);
18
18
  return instances;
19
19
  }
20
20
  const resolveCliPlugin = async (p, appDirectory)=>{
@@ -42,4 +42,4 @@ const loadInternalPlugins = async (appDirectory, internalPlugins)=>{
42
42
  }));
43
43
  return loadedPlugins;
44
44
  };
45
- export { getServerPlugins, loadInternalPlugins, loadServerPlugins };
45
+ export { getServerPlugins, loadInternalPlugins, loadPlugins_loadServerPlugins as loadServerPlugins };
@@ -1,18 +1,10 @@
1
- import { fs, getAliasConfig, loadFromProject, readTsConfigByFile, tryResolve } from "@modern-js/utils";
2
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
3
- const checkDepExist = (dep, appDir)=>{
4
- try {
5
- tryResolve(dep, appDir, process.cwd());
6
- return true;
7
- } catch {
8
- return false;
9
- }
10
- };
1
+ import node_path from "node:path";
2
+ import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
11
3
  const setupTsRuntime = async (appDir, distDir, alias)=>{
12
4
  const TS_CONFIG_FILENAME = "tsconfig.json";
13
- const tsconfigPath = __rspack_external_node_path_c5b9b54f["default"].resolve(appDir, TS_CONFIG_FILENAME);
5
+ const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
14
6
  const isTsProject = await fs.pathExists(tsconfigPath);
15
- const hasTsNode = checkDepExist('ts-node', appDir);
7
+ const hasTsNode = isDepExists(appDir, 'ts-node');
16
8
  if (!isTsProject || !hasTsNode) return;
17
9
  const aliasConfig = getAliasConfig(alias, {
18
10
  appDirectory: appDir,
@@ -29,7 +21,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
29
21
  ]
30
22
  });
31
23
  } catch {}
32
- if ('string' == typeof tsPath && __rspack_external_node_path_c5b9b54f["default"].isAbsolute(tsPath)) tsPath = __rspack_external_node_path_c5b9b54f["default"].relative(absoluteBaseUrl, tsPath);
24
+ if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
33
25
  if ('string' == typeof tsPath) tsPath = [
34
26
  tsPath
35
27
  ];
@@ -48,7 +40,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
48
40
  transpileOnly: true,
49
41
  ignore: [
50
42
  '(?:^|/)node_modules/',
51
- `(?:^|/)${__rspack_external_node_path_c5b9b54f["default"].relative(appDir, distDir)}/`
43
+ `(?:^|/)${node_path.relative(appDir, distDir)}/`
52
44
  ],
53
45
  ...tsNodeOptions
54
46
  });
@@ -1,8 +1,8 @@
1
1
  import "node:module";
2
2
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
3
3
  import { dirname as __rspack_dirname } from "node:path";
4
+ import node_path from "node:path";
4
5
  import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/builder";
5
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
6
6
  var adapterBasic_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
7
  const builderPluginAdapterBasic = (options)=>({
8
8
  name: 'builder-plugin-adapter-modern-basic',
@@ -14,7 +14,7 @@ const builderPluginAdapterBasic = (options)=>({
14
14
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
15
15
  const depExt = 'mjs';
16
16
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
17
- chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(__rspack_external_node_path_c5b9b54f["default"].join(adapterBasic_dirname, `../loaders/serverModuleLoader.${depExt}`));
17
+ chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(node_path.join(adapterBasic_dirname, `../loaders/serverModuleLoader.${depExt}`));
18
18
  }
19
19
  const { appContext } = options;
20
20
  const { metaName } = appContext;
@@ -4,7 +4,7 @@ import { resolve, sep } from "path";
4
4
  import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
5
5
  import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
6
6
  import { mergeRsbuildConfig } from "@rsbuild/core";
7
- import { getServerCombinedModueFile } from "../../../plugins/analyze/utils.mjs";
7
+ import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
8
8
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
9
9
  const builderPluginAdapterSSR = (options)=>({
10
10
  name: 'builder-plugin-adapter-modern-ssr',
@@ -101,7 +101,7 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
101
101
  const { entrypoints } = appContext;
102
102
  await Promise.all(entrypoints.map(async (entrypoint)=>{
103
103
  const { entryName } = entrypoint;
104
- const serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
104
+ const serverLoadersFile = getServerCombinedModuleFile(internalDirectory, entryName);
105
105
  if (isServer) try {
106
106
  await fs.access(serverLoadersFile, fs.constants.F_OK);
107
107
  chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
+ import node_path from "node:path";
2
3
  import { fs, logger } from "@modern-js/utils";
3
4
  import { loadServerPlugins } from "../utils/loadPlugins.mjs";
4
5
  import { setupTsRuntime } from "../utils/register.mjs";
5
6
  import { generateRoutes } from "../utils/routes.mjs";
6
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
7
7
  async function copyEnvFiles(appDirectory, distDirectory) {
8
8
  try {
9
9
  const files = await fs.readdir(appDirectory);
@@ -11,8 +11,8 @@ async function copyEnvFiles(appDirectory, distDirectory) {
11
11
  const envFiles = files.filter((file)=>envFileRegex.test(file));
12
12
  if (0 === envFiles.length) return void logger.debug('No .env files found to copy');
13
13
  const copyPromises = envFiles.map(async (envFile)=>{
14
- const sourcePath = __rspack_external_node_path_c5b9b54f["default"].resolve(appDirectory, envFile);
15
- const targetPath = __rspack_external_node_path_c5b9b54f["default"].resolve(distDirectory, envFile);
14
+ const sourcePath = node_path.resolve(appDirectory, envFile);
15
+ const targetPath = node_path.resolve(distDirectory, envFile);
16
16
  try {
17
17
  const stat = await fs.stat(sourcePath);
18
18
  if (stat.isDirectory()) return;
@@ -1,4 +1,6 @@
1
1
  import "node:module";
2
+ import node_path from "node:path";
3
+ import { applyPlugins } from "@modern-js/prod-server";
2
4
  import { createDevServer } from "@modern-js/server";
3
5
  import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
4
6
  import { setServer } from "../utils/createServer.mjs";
@@ -6,8 +8,6 @@ import { loadServerPlugins } from "../utils/loadPlugins.mjs";
6
8
  import { printInstructions } from "../utils/printInstructions.mjs";
7
9
  import { setupTsRuntime } from "../utils/register.mjs";
8
10
  import { generateRoutes } from "../utils/routes.mjs";
9
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
10
- import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
11
11
  const dev = async (api, options, devServerOptions)=>{
12
12
  if (options.analyze) process.env.BUNDLE_ANALYZE = 'true';
13
13
  const normalizedConfig = api.getNormalizedConfig();
@@ -25,7 +25,7 @@ const dev = async (api, options, devServerOptions)=>{
25
25
  await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
26
26
  const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
27
27
  const meta = getMeta(metaName);
28
- const serverConfigPath = __rspack_external_node_path_c5b9b54f["default"].resolve(appDirectory, SERVER_DIR, `${meta}.server`);
28
+ const serverConfigPath = node_path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
29
29
  await hooks.onBeforeDev.call();
30
30
  if (!appContext.builder && !apiOnly) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
31
31
  await generateRoutes(appContext);
@@ -56,7 +56,7 @@ const dev = async (api, options, devServerOptions)=>{
56
56
  const { server } = await createDevServer({
57
57
  ...serverOptions,
58
58
  runCompile: false
59
- }, devServerOptions?.applyPlugins || __rspack_external__modern_js_prod_server_057184e2.applyPlugins);
59
+ }, devServerOptions?.applyPlugins || applyPlugins);
60
60
  server.listen({
61
61
  port,
62
62
  host
@@ -68,7 +68,7 @@ const dev = async (api, options, devServerOptions)=>{
68
68
  const { server, afterListen } = await createDevServer({
69
69
  ...serverOptions,
70
70
  builder: appContext.builder
71
- }, devServerOptions?.applyPlugins || __rspack_external__modern_js_prod_server_057184e2.applyPlugins);
71
+ }, devServerOptions?.applyPlugins || applyPlugins);
72
72
  server.listen({
73
73
  port,
74
74
  host
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
2
  import path from "path";
3
+ import { createProdServer } from "@modern-js/prod-server";
3
4
  import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
4
5
  import { loadServerPlugins } from "../utils/loadPlugins.mjs";
5
6
  import { printInstructions } from "../utils/printInstructions.mjs";
6
- import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
7
7
  const serve = async (api, serverOptions)=>{
8
8
  const appContext = api.getAppContext();
9
9
  const userConfig = api.getNormalizedConfig();
@@ -17,7 +17,7 @@ const serve = async (api, serverOptions)=>{
17
17
  const meta = getMeta(metaName);
18
18
  const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
19
19
  const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
20
- const app = await (serverOptions?.launcher || __rspack_external__modern_js_prod_server_057184e2.createProdServer)({
20
+ const app = await (serverOptions?.launcher || createProdServer)({
21
21
  metaName,
22
22
  pwd: distDirectory,
23
23
  config: {
@@ -5,7 +5,7 @@ function createDefaultConfig(appContext) {
5
5
  const dev = {
6
6
  cliShortcuts: {
7
7
  help: false,
8
- custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key)
8
+ custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key && 'o' !== key)
9
9
  }
10
10
  };
11
11
  const output = {
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
+ import node_path from "node:path";
2
3
  import { fs } from "@modern-js/utils";
3
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
4
4
  const checkDepExist = async (dep)=>{
5
5
  try {
6
6
  await import(dep);
@@ -11,7 +11,7 @@ const checkDepExist = async (dep)=>{
11
11
  };
12
12
  const registerModuleHooks = async ({ appDir, distDir, alias })=>{
13
13
  const TS_CONFIG_FILENAME = "tsconfig.json";
14
- const tsconfigPath = __rspack_external_node_path_c5b9b54f["default"].resolve(appDir, TS_CONFIG_FILENAME);
14
+ const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
15
15
  const hasTsconfig = await fs.pathExists(tsconfigPath);
16
16
  const hasTsNode = await checkDepExist('ts-node');
17
17
  if (!hasTsconfig || !hasTsNode) return;
@@ -20,7 +20,7 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
20
20
  process.env.TS_NODE_PROJECT = tsconfigPath;
21
21
  process.env.TS_NODE_SCOPE = true;
22
22
  process.env.TS_NODE_FILES = true;
23
- process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${__rspack_external_node_path_c5b9b54f["default"].relative(appDir, distDir)}/`;
23
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${node_path.relative(appDir, distDir)}/`;
24
24
  register('./ts-node-loader.mjs', import.meta.url, {
25
25
  data: {
26
26
  appDir,
@@ -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 };
@@ -30,7 +30,7 @@ const parseModule = async ({ source, filename })=>{
30
30
  }
31
31
  return await parse(content);
32
32
  };
33
- const getServerCombinedModueFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
33
+ const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
34
34
  const checkIsBuildCommands = ()=>{
35
35
  const buildCommands = [
36
36
  'dev',
@@ -53,4 +53,4 @@ const isSubDirOrEqual = (parent, child)=>{
53
53
  const isSubdir = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
54
54
  return Boolean(isSubdir);
55
55
  };
56
- export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModueFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
56
+ export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModuleFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
@@ -4,20 +4,25 @@ import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
4
4
  import { createNetlifyPreset } from "./platforms/netlify.mjs";
5
5
  import { createNodePreset } from "./platforms/node.mjs";
6
6
  import { createVercelPreset } from "./platforms/vercel.mjs";
7
- import { getProjectUsage } from "./utils.mjs";
7
+ import { getProjectUsage } from "./utils/index.mjs";
8
8
  const deployPresets = {
9
9
  node: createNodePreset,
10
10
  vercel: createVercelPreset,
11
11
  netlify: createNetlifyPreset,
12
12
  ghPages: createGhPagesPreset
13
13
  };
14
- async function getDeployPreset(appContext, modernConfig, deployTarget) {
14
+ async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
15
15
  const { appDirectory, distDirectory, metaName } = appContext;
16
16
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
17
17
  const needModernServer = useSSR || useAPI || useWebServer;
18
18
  const createPreset = deployPresets[deployTarget];
19
19
  if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
20
- return createPreset(appContext, modernConfig, needModernServer);
20
+ return createPreset({
21
+ appContext,
22
+ modernConfig,
23
+ needModernServer,
24
+ api
25
+ });
21
26
  }
22
27
  const deploy = ()=>({
23
28
  name: '@modern-js/plugin-deploy',
@@ -28,7 +33,7 @@ const deploy = ()=>({
28
33
  const { metaName } = appContext;
29
34
  if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
30
35
  const modernConfig = api.getNormalizedConfig();
31
- const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
36
+ const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
32
37
  deployPreset?.prepare && await deployPreset?.prepare();
33
38
  deployPreset?.writeOutput && await deployPreset?.writeOutput();
34
39
  deployPreset?.genEntry && await deployPreset?.genEntry();
@@ -24,7 +24,7 @@ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = '/') {
24
24
  });
25
25
  await Promise.all(copyPromises);
26
26
  }
27
- const createGhPagesPreset = (appContext, modernConfig)=>{
27
+ const createGhPagesPreset = ({ appContext, modernConfig })=>{
28
28
  const { serverRoutes, appDirectory, distDirectory } = appContext;
29
29
  const { server: { baseUrl } } = modernConfig;
30
30
  const outputDirectory = path.join(appDirectory, '.output');