@modern-js/app-tools 2.67.3 → 2.67.4

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 (30) hide show
  1. package/dist/cjs/plugins/deploy/index.js +2 -2
  2. package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +1 -0
  3. package/dist/cjs/plugins/deploy/platforms/netlify.js +4 -2
  4. package/dist/cjs/plugins/deploy/platforms/node-entry.js +1 -0
  5. package/dist/cjs/plugins/deploy/platforms/node.js +4 -2
  6. package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +1 -0
  7. package/dist/cjs/plugins/deploy/platforms/vercel.js +4 -2
  8. package/dist/cjs/plugins/deploy/utils.js +10 -2
  9. package/dist/cjs/run/index.js +2 -2
  10. package/dist/esm/plugins/deploy/index.js +3 -3
  11. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +2 -1
  12. package/dist/esm/plugins/deploy/platforms/netlify.js +6 -4
  13. package/dist/esm/plugins/deploy/platforms/node-entry.js +2 -1
  14. package/dist/esm/plugins/deploy/platforms/node.js +6 -4
  15. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +2 -1
  16. package/dist/esm/plugins/deploy/platforms/vercel.js +6 -4
  17. package/dist/esm/plugins/deploy/utils.js +11 -3
  18. package/dist/esm/run/index.js +2 -2
  19. package/dist/esm-node/plugins/deploy/index.js +2 -2
  20. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +1 -0
  21. package/dist/esm-node/plugins/deploy/platforms/netlify.js +5 -3
  22. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +1 -0
  23. package/dist/esm-node/plugins/deploy/platforms/node.js +5 -3
  24. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +1 -0
  25. package/dist/esm-node/plugins/deploy/platforms/vercel.js +5 -3
  26. package/dist/esm-node/plugins/deploy/utils.js +11 -3
  27. package/dist/esm-node/run/index.js +2 -2
  28. package/dist/types/exports/server.d.ts +1 -2
  29. package/dist/types/plugins/deploy/utils.d.ts +1 -1
  30. package/package.json +16 -16
@@ -34,8 +34,8 @@ const deployPresets = {
34
34
  ghPages: import_gh_pages.createGhPagesPreset
35
35
  };
36
36
  async function getDeployPreset(appContext, modernConfig, deployTarget) {
37
- const { appDirectory, distDirectory } = appContext;
38
- const { useSSR, useAPI, useWebServer } = (0, import_utils.getProjectUsage)(appDirectory, distDirectory);
37
+ const { appDirectory, distDirectory, metaName } = appContext;
38
+ const { useSSR, useAPI, useWebServer } = (0, import_utils.getProjectUsage)(appDirectory, distDirectory, metaName);
39
39
  const needModernServer = useSSR || useAPI || useWebServer;
40
40
  const createPreset = deployPresets[deployTarget];
41
41
  if (!createPreset) {
@@ -34,6 +34,7 @@ async function initServer() {
34
34
  bffRuntimeFramework: p_bffRuntimeFramework
35
35
  },
36
36
  plugins: p_plugins,
37
+ serverConfigPath: p_serverDirectory,
37
38
  ...dynamicProdOptions
38
39
  };
39
40
  const requestHandler2 = await createNetlifyFunction(prodServerOptions);
@@ -50,7 +50,7 @@ async function cleanDistDirectory(dir) {
50
50
  }
51
51
  }
52
52
  const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
53
- const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
53
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
54
54
  const isEsmProject = moduleType === "module";
55
55
  const plugins = serverPlugins.map((plugin) => [
56
56
  plugin.name,
@@ -113,15 +113,17 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
113
113
  }
114
114
  }
115
115
  };
116
+ const meta = (0, import_utils.getMeta)(metaName);
116
117
  const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
117
118
  const dynamicProdOptions = {
118
119
  config: serverConfig,
119
120
  serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
120
121
  };
122
+ const serverConfigPath = `path.join(__dirname, "${import_utils.SERVER_DIR}", "${meta}.server")`;
121
123
  const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
122
124
  let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlify-handler.js"))).toString();
123
125
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
124
- handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_bffRuntimeFramework", `"${serverAppContext.bffRuntimeFramework}"`).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
126
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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);
125
127
  await import_utils.fs.writeFile(handlerFilePath, handlerCode);
126
128
  if (isEsmProject) {
127
129
  await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
@@ -32,6 +32,7 @@ async function main() {
32
32
  bffRuntimeFramework: p_bffRuntimeFramework
33
33
  },
34
34
  plugins: p_plugins,
35
+ serverConfigPath: p_serverDirectory,
35
36
  ...dynamicProdOptions
36
37
  };
37
38
  const app = await createProdServer(prodServerOptions);
@@ -36,7 +36,7 @@ var import_utils = require("@modern-js/utils");
36
36
  var import_ndepe = require("ndepe");
37
37
  var import_utils2 = require("../utils");
38
38
  const createNodePreset = (appContext, config) => {
39
- const { appDirectory, distDirectory, serverPlugins, moduleType } = appContext;
39
+ const { appDirectory, distDirectory, serverPlugins, moduleType, metaName } = appContext;
40
40
  const isEsmProject = moduleType === "module";
41
41
  const plugins = serverPlugins.map((plugin) => [
42
42
  plugin.name,
@@ -72,10 +72,12 @@ const createNodePreset = (appContext, config) => {
72
72
  config: serverConfig,
73
73
  serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
74
74
  };
75
+ const meta = (0, import_utils.getMeta)(metaName);
76
+ const serverConfigPath = `path.join(__dirname, "${import_utils.SERVER_DIR}", "${meta}.server")`;
75
77
  const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
76
78
  let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./node-entry.js"))).toString();
77
79
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
78
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_bffRuntimeFramework", `"${serverAppContext.bffRuntimeFramework}"`).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
80
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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_bffRuntimeFramework", `"${serverAppContext.bffRuntimeFramework}"`).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
79
81
  if (isEsmProject) {
80
82
  const cjsEntryFilePath = import_node_path.default.join(outputDirectory, "index.cjs");
81
83
  await import_utils.fs.writeFile(cjsEntryFilePath, entryCode);
@@ -33,6 +33,7 @@ async function initServer() {
33
33
  lambdaDirectory: p_lambdaDirectory
34
34
  },
35
35
  plugins: p_plugins,
36
+ serverConfigPath: p_serverDirectory,
36
37
  ...dynamicProdOptions
37
38
  };
38
39
  const app = await createProdServer(prodServerOptions);
@@ -37,7 +37,7 @@ var import_ndepe = require("ndepe");
37
37
  var import_routes = require("../../../utils/routes");
38
38
  var import_utils2 = require("../utils");
39
39
  const createVercelPreset = (appContext, modernConfig, needModernServer) => {
40
- const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
40
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
41
41
  const isEsmProject = moduleType === "module";
42
42
  const plugins = serverPlugins.map((plugin) => [
43
43
  plugin.name,
@@ -134,10 +134,12 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
134
134
  config: serverConfig,
135
135
  serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
136
136
  };
137
+ const meta = (0, import_utils.getMeta)(metaName);
138
+ const serverConfigPath = `path.join(__dirname, "${import_utils.SERVER_DIR}", "${meta}.server")`;
137
139
  const pluginsCode = (0, import_utils2.getPluginsCode)(plugins || []);
138
140
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
139
141
  let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercel-handler.js"))).toString();
140
- handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
142
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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);
141
143
  await import_utils.fs.writeFile(handlerFilePath, handlerCode);
142
144
  if (isEsmProject) {
143
145
  await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
@@ -55,7 +55,7 @@ const genPluginImportsCode = (plugins) => {
55
55
  const getPluginsCode = (plugins) => {
56
56
  return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
57
57
  };
58
- const getProjectUsage = (appDirectory, distDirectory) => {
58
+ const getProjectUsage = (appDirectory, distDirectory, metaName) => {
59
59
  const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
60
60
  const { routes } = import_utils.fs.readJSONSync(routeJSON);
61
61
  let useSSR = false;
@@ -68,7 +68,15 @@ const getProjectUsage = (appDirectory, distDirectory) => {
68
68
  useAPI = true;
69
69
  }
70
70
  });
71
- const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server");
71
+ const meta = (0, import_utils.getMeta)(metaName);
72
+ const serverConfigPath = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR, `${meta}.server`);
73
+ const isServerConfigExists = [
74
+ ".ts",
75
+ ".js"
76
+ ].some((ex) => {
77
+ return import_utils.fs.existsSync(`${serverConfigPath}${ex}`);
78
+ });
79
+ const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server") || isServerConfigExists;
72
80
  return {
73
81
  useSSR,
74
82
  useAPI,
@@ -41,7 +41,7 @@ var import_getConfigFile = require("../utils/getConfigFile");
41
41
  var import_getUserConfig = require("../utils/getUserConfig");
42
42
  var import_loadPlugins = require("../utils/loadPlugins");
43
43
  async function run({ cwd, initialLog, metaName = "modern-js", version, internalPlugins, packageJsonConfig = import_constants.PACKAGE_JSON_CONFIG_NAME, statePluginName = import_constants.STATE_PLUGIN_NAME, configFile }) {
44
- var _userConfig_runtime, _userConfig_runtime1;
44
+ var _userConfig_runtime, _userConfig_runtime1, _userConfig_runtime_state, _userConfig_runtime2;
45
45
  const nodeVersion = process.versions.node;
46
46
  const versionArr = nodeVersion.split(".").map(Number);
47
47
  if (versionArr[0] <= 16) {
@@ -102,7 +102,7 @@ async function run({ cwd, initialLog, metaName = "modern-js", version, internalP
102
102
  const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
103
103
  const userConfig = await (0, import_getUserConfig.getUserConfig)(appDirectory, finalConfigFile, packageJsonConfig, metaName);
104
104
  const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, userConfig.autoLoadPlugins);
105
- if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || typeof ((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object")) {
105
+ if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || typeof ((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object" && !((_userConfig_runtime2 = userConfig.runtime) === null || _userConfig_runtime2 === void 0 ? void 0 : (_userConfig_runtime_state = _userConfig_runtime2.state) === null || _userConfig_runtime_state === void 0 ? void 0 : _userConfig_runtime_state.legacy))) {
106
106
  if (!userConfig.plugins.find((plugin) => plugin.name === statePluginName)) {
107
107
  console.warn(`${import_utils.chalk.red("\n[Warning]")} We will no longer support built-in \`runtime.state\`. If you want to use Reduck, you must run ${import_utils.chalk.yellow.bold(`\`pnpm add ${statePluginName}@${version}\``)} to install the state plugin dependency and manually register the plugin. After install state plugin, please add the following code to ${import_utils.chalk.yellow.bold(`\`${import_path.default.basename(finalConfigFile)}\``)}:
108
108
 
@@ -17,10 +17,10 @@ function getDeployPreset(appContext, modernConfig, deployTarget) {
17
17
  }
18
18
  function _getDeployPreset() {
19
19
  _getDeployPreset = _async_to_generator(function(appContext, modernConfig, deployTarget) {
20
- var appDirectory, distDirectory, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, createPreset;
20
+ var appDirectory, distDirectory, metaName, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, createPreset;
21
21
  return _ts_generator(this, function(_state) {
22
- appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
23
- _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
22
+ appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, metaName = appContext.metaName;
23
+ _getProjectUsage = getProjectUsage(appDirectory, distDirectory, metaName), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
24
24
  needModernServer = useSSR || useAPI || useWebServer;
25
25
  createPreset = deployPresets[deployTarget];
26
26
  if (!createPreset) {
@@ -91,7 +91,8 @@ var require_netlify_handler = __commonJS({
91
91
  lambdaDirectory: p_lambdaDirectory,
92
92
  bffRuntimeFramework: p_bffRuntimeFramework
93
93
  },
94
- plugins: p_plugins
94
+ plugins: p_plugins,
95
+ serverConfigPath: p_serverDirectory
95
96
  }, dynamicProdOptions);
96
97
  return [
97
98
  4,
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
4
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta } from "@modern-js/utils";
5
5
  import { nodeDepEmit as handleDependencies } from "ndepe";
6
6
  import { isMainEntry } from "../../../utils/routes";
7
7
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
@@ -111,7 +111,7 @@ function _cleanDistDirectory() {
111
111
  return _cleanDistDirectory.apply(this, arguments);
112
112
  }
113
113
  var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
114
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
114
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType, metaName = appContext.metaName;
115
115
  var isEsmProject = moduleType === "module";
116
116
  var plugins = serverPlugins.map(function(plugin) {
117
117
  return [
@@ -209,7 +209,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
209
209
  },
210
210
  genEntry: function genEntry() {
211
211
  return _async_to_generator(function() {
212
- var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, handlerCode, serverAppContext;
212
+ var _modernConfig_bff, serverConfig, meta, pluginImportCode, dynamicProdOptions, serverConfigPath, pluginsCode, handlerCode, serverAppContext;
213
213
  return _ts_generator(this, function(_state) {
214
214
  switch (_state.label) {
215
215
  case 0:
@@ -228,11 +228,13 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
228
228
  }
229
229
  }
230
230
  };
231
+ meta = getMeta(metaName);
231
232
  pluginImportCode = genPluginImportsCode(plugins || []);
232
233
  dynamicProdOptions = {
233
234
  config: serverConfig,
234
235
  serverConfigFile: DEFAULT_SERVER_CONFIG
235
236
  };
237
+ serverConfigPath = 'path.join(__dirname, "'.concat(SERVER_DIR, '", "').concat(meta, '.server")');
236
238
  pluginsCode = getPluginsCode(plugins);
237
239
  return [
238
240
  4,
@@ -241,7 +243,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
241
243
  case 1:
242
244
  handlerCode = _state.sent().toString();
243
245
  serverAppContext = serverAppContenxtTemplate(appContext);
244
- handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_bffRuntimeFramework", '"'.concat(serverAppContext.bffRuntimeFramework, '"')).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
246
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_bffRuntimeFramework", '"'.concat(serverAppContext.bffRuntimeFramework, '"')).replace("p_serverDirectory", serverConfigPath).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
245
247
  return [
246
248
  4,
247
249
  fse.writeFile(handlerFilePath, handlerCode)
@@ -83,7 +83,8 @@ function _main() {
83
83
  lambdaDirectory: p_lambdaDirectory,
84
84
  bffRuntimeFramework: p_bffRuntimeFramework
85
85
  },
86
- plugins: p_plugins
86
+ plugins: p_plugins,
87
+ serverConfigPath: p_serverDirectory
87
88
  }, dynamicProdOptions);
88
89
  return [
89
90
  4,
@@ -1,11 +1,11 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, chalk, fs as fse } from "@modern-js/utils";
4
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, chalk, fs as fse, getMeta } from "@modern-js/utils";
5
5
  import { nodeDepEmit as handleDependencies } from "ndepe";
6
6
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
7
7
  var createNodePreset = function(appContext, config) {
8
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
8
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType, metaName = appContext.metaName;
9
9
  var isEsmProject = moduleType === "module";
10
10
  var plugins = serverPlugins.map(function(plugin) {
11
11
  return [
@@ -55,7 +55,7 @@ var createNodePreset = function(appContext, config) {
55
55
  },
56
56
  genEntry: function genEntry() {
57
57
  return _async_to_generator(function() {
58
- var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, entryCode, serverAppContext, cjsEntryFilePath;
58
+ var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, meta, serverConfigPath, pluginsCode, entryCode, serverAppContext, cjsEntryFilePath;
59
59
  return _ts_generator(this, function(_state) {
60
60
  switch (_state.label) {
61
61
  case 0:
@@ -77,6 +77,8 @@ var createNodePreset = function(appContext, config) {
77
77
  config: serverConfig,
78
78
  serverConfigFile: DEFAULT_SERVER_CONFIG
79
79
  };
80
+ meta = getMeta(metaName);
81
+ serverConfigPath = 'path.join(__dirname, "'.concat(SERVER_DIR, '", "').concat(meta, '.server")');
80
82
  pluginsCode = getPluginsCode(plugins);
81
83
  return [
82
84
  4,
@@ -85,7 +87,7 @@ var createNodePreset = function(appContext, config) {
85
87
  case 1:
86
88
  entryCode = _state.sent().toString();
87
89
  serverAppContext = serverAppContenxtTemplate(appContext);
88
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_bffRuntimeFramework", '"'.concat(serverAppContext.bffRuntimeFramework, '"')).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
90
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(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_bffRuntimeFramework", '"'.concat(serverAppContext.bffRuntimeFramework, '"')).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
89
91
  if (!isEsmProject)
90
92
  return [
91
93
  3,
@@ -90,7 +90,8 @@ var require_vercel_handler = __commonJS({
90
90
  apiDirectory: p_apiDirectory,
91
91
  lambdaDirectory: p_lambdaDirectory
92
92
  },
93
- plugins: p_plugins
93
+ plugins: p_plugins,
94
+ serverConfigPath: p_serverDirectory
94
95
  }, dynamicProdOptions);
95
96
  return [
96
97
  4,
@@ -1,12 +1,12 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
4
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta } from "@modern-js/utils";
5
5
  import { nodeDepEmit as handleDependencies } from "ndepe";
6
6
  import { isMainEntry } from "../../../utils/routes";
7
7
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
8
8
  var createVercelPreset = function(appContext, modernConfig, needModernServer) {
9
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
9
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType, metaName = appContext.metaName;
10
10
  var isEsmProject = moduleType === "module";
11
11
  var plugins = serverPlugins.map(function(plugin) {
12
12
  return [
@@ -157,7 +157,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
157
157
  },
158
158
  genEntry: function genEntry() {
159
159
  return _async_to_generator(function() {
160
- var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, serverAppContext, handlerCode;
160
+ var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, meta, serverConfigPath, pluginsCode, serverAppContext, handlerCode;
161
161
  return _ts_generator(this, function(_state) {
162
162
  switch (_state.label) {
163
163
  case 0:
@@ -181,6 +181,8 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
181
181
  config: serverConfig,
182
182
  serverConfigFile: DEFAULT_SERVER_CONFIG
183
183
  };
184
+ meta = getMeta(metaName);
185
+ serverConfigPath = 'path.join(__dirname, "'.concat(SERVER_DIR, '", "').concat(meta, '.server")');
184
186
  pluginsCode = getPluginsCode(plugins || []);
185
187
  serverAppContext = serverAppContenxtTemplate(appContext);
186
188
  return [
@@ -189,7 +191,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
189
191
  ];
190
192
  case 1:
191
193
  handlerCode = _state.sent().toString();
192
- handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
194
+ handlerCode = handlerCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(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);
193
195
  return [
194
196
  4,
195
197
  fse.writeFile(handlerFilePath, handlerCode)
@@ -1,6 +1,6 @@
1
1
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
2
  import path from "path";
3
- import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
3
+ import { ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta, isDepExists } from "@modern-js/utils";
4
4
  var serverAppContenxtTemplate = function(appContext) {
5
5
  var appDirectory = appContext.appDirectory, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, bffRuntimeFramework = appContext.bffRuntimeFramework;
6
6
  return {
@@ -23,7 +23,7 @@ var getPluginsCode = function(plugins) {
23
23
  return "plugin_".concat(index, "(").concat(options ? JSON.stringify(options) : "", ")");
24
24
  }).join(","), "]");
25
25
  };
26
- var getProjectUsage = function(appDirectory, distDirectory) {
26
+ var getProjectUsage = function(appDirectory, distDirectory, metaName) {
27
27
  var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
28
28
  var routes = fse.readJSONSync(routeJSON).routes;
29
29
  var useSSR = false;
@@ -36,7 +36,15 @@ var getProjectUsage = function(appDirectory, distDirectory) {
36
36
  useAPI = true;
37
37
  }
38
38
  });
39
- var useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
39
+ var meta = getMeta(metaName);
40
+ var serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
41
+ var isServerConfigExists = [
42
+ ".ts",
43
+ ".js"
44
+ ].some(function(ex) {
45
+ return fse.existsSync("".concat(serverConfigPath).concat(ex));
46
+ });
47
+ var useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server") || isServerConfigExists;
40
48
  return {
41
49
  useSSR,
42
50
  useAPI,
@@ -15,7 +15,7 @@ function run(_) {
15
15
  }
16
16
  function _run() {
17
17
  _run = _async_to_generator(function(param) {
18
- var cwd, initialLog, _param_metaName, metaName, version, internalPlugins, _param_packageJsonConfig, packageJsonConfig, _param_statePluginName, statePluginName, configFile, _userConfig_runtime, _userConfig_runtime1, nodeVersion, versionArr, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, finalConfigFile, userConfig, plugins;
18
+ var cwd, initialLog, _param_metaName, metaName, version, internalPlugins, _param_packageJsonConfig, packageJsonConfig, _param_statePluginName, statePluginName, configFile, _userConfig_runtime, _userConfig_runtime1, _userConfig_runtime_state, _userConfig_runtime2, nodeVersion, versionArr, command, cliParams, SUPPORT_CONFIG_PARAM_COMMANDS, customConfigFile, appDirectory, finalConfigFile, userConfig, plugins;
19
19
  return _ts_generator(this, function(_state) {
20
20
  switch (_state.label) {
21
21
  case 0:
@@ -75,7 +75,7 @@ function _run() {
75
75
  ];
76
76
  case 3:
77
77
  plugins = _state.sent();
78
- if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || _type_of((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object")) {
78
+ if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || _type_of((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object" && !((_userConfig_runtime2 = userConfig.runtime) === null || _userConfig_runtime2 === void 0 ? void 0 : (_userConfig_runtime_state = _userConfig_runtime2.state) === null || _userConfig_runtime_state === void 0 ? void 0 : _userConfig_runtime_state.legacy))) {
79
79
  if (!userConfig.plugins.find(function(plugin) {
80
80
  return plugin.name === statePluginName;
81
81
  })) {
@@ -11,8 +11,8 @@ const deployPresets = {
11
11
  ghPages: createGhPagesPreset
12
12
  };
13
13
  async function getDeployPreset(appContext, modernConfig, deployTarget) {
14
- const { appDirectory, distDirectory } = appContext;
15
- const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
14
+ const { appDirectory, distDirectory, metaName } = appContext;
15
+ const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
16
16
  const needModernServer = useSSR || useAPI || useWebServer;
17
17
  const createPreset = deployPresets[deployTarget];
18
18
  if (!createPreset) {
@@ -39,6 +39,7 @@ var require_netlify_handler = __commonJS({
39
39
  bffRuntimeFramework: p_bffRuntimeFramework
40
40
  },
41
41
  plugins: p_plugins,
42
+ serverConfigPath: p_serverDirectory,
42
43
  ...dynamicProdOptions
43
44
  };
44
45
  const requestHandler2 = await createNetlifyFunction(prodServerOptions);
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
2
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta } from "@modern-js/utils";
3
3
  import { nodeDepEmit as handleDependencies } from "ndepe";
4
4
  import { isMainEntry } from "../../../utils/routes";
5
5
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
@@ -17,7 +17,7 @@ async function cleanDistDirectory(dir) {
17
17
  }
18
18
  }
19
19
  const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
20
- const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
20
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
21
21
  const isEsmProject = moduleType === "module";
22
22
  const plugins = serverPlugins.map((plugin) => [
23
23
  plugin.name,
@@ -80,15 +80,17 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
80
80
  }
81
81
  }
82
82
  };
83
+ const meta = getMeta(metaName);
83
84
  const pluginImportCode = genPluginImportsCode(plugins || []);
84
85
  const dynamicProdOptions = {
85
86
  config: serverConfig,
86
87
  serverConfigFile: DEFAULT_SERVER_CONFIG
87
88
  };
89
+ const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
88
90
  const pluginsCode = getPluginsCode(plugins);
89
91
  let handlerCode = (await fse.readFile(path.join(__dirname, "./netlify-handler.js"))).toString();
90
92
  const serverAppContext = serverAppContenxtTemplate(appContext);
91
- 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_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
93
+ 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);
92
94
  await fse.writeFile(handlerFilePath, handlerCode);
93
95
  if (isEsmProject) {
94
96
  await fse.copy(path.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
@@ -31,6 +31,7 @@ async function main() {
31
31
  bffRuntimeFramework: p_bffRuntimeFramework
32
32
  },
33
33
  plugins: p_plugins,
34
+ serverConfigPath: p_serverDirectory,
34
35
  ...dynamicProdOptions
35
36
  };
36
37
  const app = await createProdServer(prodServerOptions);
@@ -1,9 +1,9 @@
1
1
  import path from "node:path";
2
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, chalk, fs as fse } from "@modern-js/utils";
2
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, chalk, fs as fse, getMeta } from "@modern-js/utils";
3
3
  import { nodeDepEmit as handleDependencies } from "ndepe";
4
4
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
5
5
  const createNodePreset = (appContext, config) => {
6
- const { appDirectory, distDirectory, serverPlugins, moduleType } = appContext;
6
+ const { appDirectory, distDirectory, serverPlugins, moduleType, metaName } = appContext;
7
7
  const isEsmProject = moduleType === "module";
8
8
  const plugins = serverPlugins.map((plugin) => [
9
9
  plugin.name,
@@ -39,10 +39,12 @@ const createNodePreset = (appContext, config) => {
39
39
  config: serverConfig,
40
40
  serverConfigFile: DEFAULT_SERVER_CONFIG
41
41
  };
42
+ const meta = getMeta(metaName);
43
+ const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
42
44
  const pluginsCode = getPluginsCode(plugins);
43
45
  let entryCode = (await fse.readFile(path.join(__dirname, "./node-entry.js"))).toString();
44
46
  const serverAppContext = serverAppContenxtTemplate(appContext);
45
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_bffRuntimeFramework", `"${serverAppContext.bffRuntimeFramework}"`).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
47
+ entryCode = entryCode.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_bffRuntimeFramework", `"${serverAppContext.bffRuntimeFramework}"`).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
46
48
  if (isEsmProject) {
47
49
  const cjsEntryFilePath = path.join(outputDirectory, "index.cjs");
48
50
  await fse.writeFile(cjsEntryFilePath, entryCode);
@@ -38,6 +38,7 @@ var require_vercel_handler = __commonJS({
38
38
  lambdaDirectory: p_lambdaDirectory
39
39
  },
40
40
  plugins: p_plugins,
41
+ serverConfigPath: p_serverDirectory,
41
42
  ...dynamicProdOptions
42
43
  };
43
44
  const app = await createProdServer(prodServerOptions);
@@ -1,10 +1,10 @@
1
1
  import path from "node:path";
2
- import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
2
+ import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta } from "@modern-js/utils";
3
3
  import { nodeDepEmit as handleDependencies } from "ndepe";
4
4
  import { isMainEntry } from "../../../utils/routes";
5
5
  import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
6
6
  const createVercelPreset = (appContext, modernConfig, needModernServer) => {
7
- const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
7
+ const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
8
8
  const isEsmProject = moduleType === "module";
9
9
  const plugins = serverPlugins.map((plugin) => [
10
10
  plugin.name,
@@ -101,10 +101,12 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
101
101
  config: serverConfig,
102
102
  serverConfigFile: DEFAULT_SERVER_CONFIG
103
103
  };
104
+ const meta = getMeta(metaName);
105
+ const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
104
106
  const pluginsCode = getPluginsCode(plugins || []);
105
107
  const serverAppContext = serverAppContenxtTemplate(appContext);
106
108
  let handlerCode = (await fse.readFile(path.join(__dirname, "./vercel-handler.js"))).toString();
107
- 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_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
109
+ 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);
108
110
  await fse.writeFile(handlerFilePath, handlerCode);
109
111
  if (isEsmProject) {
110
112
  await fse.copy(path.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
2
+ import { ROUTE_SPEC_FILE, SERVER_DIR, fs as fse, getMeta, isDepExists } from "@modern-js/utils";
3
3
  const serverAppContenxtTemplate = (appContext) => {
4
4
  const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
5
5
  return {
@@ -19,7 +19,7 @@ const genPluginImportsCode = (plugins) => {
19
19
  const getPluginsCode = (plugins) => {
20
20
  return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
21
21
  };
22
- const getProjectUsage = (appDirectory, distDirectory) => {
22
+ const getProjectUsage = (appDirectory, distDirectory, metaName) => {
23
23
  const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
24
24
  const { routes } = fse.readJSONSync(routeJSON);
25
25
  let useSSR = false;
@@ -32,7 +32,15 @@ const getProjectUsage = (appDirectory, distDirectory) => {
32
32
  useAPI = true;
33
33
  }
34
34
  });
35
- const useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
35
+ const meta = getMeta(metaName);
36
+ const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
37
+ const isServerConfigExists = [
38
+ ".ts",
39
+ ".js"
40
+ ].some((ex) => {
41
+ return fse.existsSync(`${serverConfigPath}${ex}`);
42
+ });
43
+ const useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server") || isServerConfigExists;
36
44
  return {
37
45
  useSSR,
38
46
  useAPI,
@@ -8,7 +8,7 @@ import { getConfigFile } from "../utils/getConfigFile";
8
8
  import { getUserConfig } from "../utils/getUserConfig";
9
9
  import { loadInternalPlugins } from "../utils/loadPlugins";
10
10
  async function run({ cwd, initialLog, metaName = "modern-js", version, internalPlugins, packageJsonConfig = PACKAGE_JSON_CONFIG_NAME, statePluginName = STATE_PLUGIN_NAME, configFile }) {
11
- var _userConfig_runtime, _userConfig_runtime1;
11
+ var _userConfig_runtime, _userConfig_runtime1, _userConfig_runtime_state, _userConfig_runtime2;
12
12
  const nodeVersion = process.versions.node;
13
13
  const versionArr = nodeVersion.split(".").map(Number);
14
14
  if (versionArr[0] <= 16) {
@@ -69,7 +69,7 @@ async function run({ cwd, initialLog, metaName = "modern-js", version, internalP
69
69
  const finalConfigFile = customConfigFile || getConfigFile(configFile);
70
70
  const userConfig = await getUserConfig(appDirectory, finalConfigFile, packageJsonConfig, metaName);
71
71
  const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, userConfig.autoLoadPlugins);
72
- if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || typeof ((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object")) {
72
+ if (!userConfig.autoLoadPlugins && userConfig.runtime && typeof userConfig.runtime !== "boolean" && (((_userConfig_runtime = userConfig.runtime) === null || _userConfig_runtime === void 0 ? void 0 : _userConfig_runtime.state) === true || typeof ((_userConfig_runtime1 = userConfig.runtime) === null || _userConfig_runtime1 === void 0 ? void 0 : _userConfig_runtime1.state) === "object" && !((_userConfig_runtime2 = userConfig.runtime) === null || _userConfig_runtime2 === void 0 ? void 0 : (_userConfig_runtime_state = _userConfig_runtime2.state) === null || _userConfig_runtime_state === void 0 ? void 0 : _userConfig_runtime_state.legacy))) {
73
73
  if (!userConfig.plugins.find((plugin) => plugin.name === statePluginName)) {
74
74
  console.warn(`${chalk.red("\n[Warning]")} We will no longer support built-in \`runtime.state\`. If you want to use Reduck, you must run ${chalk.yellow.bold(`\`pnpm add ${statePluginName}@${version}\``)} to install the state plugin dependency and manually register the plugin. After install state plugin, please add the following code to ${chalk.yellow.bold(`\`${path.basename(finalConfigFile)}\``)}:
75
75
 
@@ -1,6 +1,5 @@
1
- import type { UnstableMiddleware, UnstableMiddlewareContext, UnstableNext } from '@modern-js/types';
1
+ import type { UnstableMiddlewareContext, UnstableNext } from '@modern-js/types';
2
2
  export type { ServerPlugin, ServerPluginLegacy } from '@modern-js/server-core';
3
- export type RenderMiddleware = UnstableMiddleware;
4
3
  export type RenderMiddlewareContext = UnstableMiddlewareContext;
5
4
  export type RenderNext = UnstableNext;
6
5
  export { defineServerConfig as defineConfig } from '../utils/config';
@@ -16,7 +16,7 @@ export declare const serverAppContenxtTemplate: (appContext: AppToolsContext<"sh
16
16
  export type PluginItem = [string, Record<string, any> | undefined];
17
17
  export declare const genPluginImportsCode: (plugins: PluginItem[]) => string;
18
18
  export declare const getPluginsCode: (plugins: PluginItem[]) => string;
19
- export declare const getProjectUsage: (appDirectory: string, distDirectory: string) => {
19
+ export declare const getProjectUsage: (appDirectory: string, distDirectory: string, metaName: string) => {
20
20
  useSSR: boolean;
21
21
  useAPI: boolean;
22
22
  useWebServer: boolean;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.67.3",
18
+ "version": "2.67.4",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -80,7 +80,7 @@
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.3.10",
83
+ "@rsbuild/core": "1.3.16",
84
84
  "@rsbuild/plugin-node-polyfill": "1.3.0",
85
85
  "@swc/helpers": "0.5.13",
86
86
  "es-module-lexer": "^1.1.0",
@@ -91,20 +91,20 @@
91
91
  "ndepe": "^0.1.8",
92
92
  "pkg-types": "^1.1.0",
93
93
  "std-env": "^3.7.0",
94
- "@modern-js/core": "2.67.3",
95
- "@modern-js/plugin": "2.67.3",
96
- "@modern-js/node-bundle-require": "2.67.3",
97
- "@modern-js/plugin-data-loader": "2.67.3",
98
- "@modern-js/plugin-i18n": "2.67.3",
99
- "@modern-js/plugin-v2": "2.67.3",
100
- "@modern-js/prod-server": "2.67.3",
101
- "@modern-js/rsbuild-plugin-esbuild": "2.67.3",
102
- "@modern-js/server": "2.67.3",
103
- "@modern-js/server-core": "2.67.3",
104
- "@modern-js/server-utils": "2.67.3",
105
- "@modern-js/types": "2.67.3",
106
- "@modern-js/uni-builder": "2.67.3",
107
- "@modern-js/utils": "2.67.3"
94
+ "@modern-js/core": "2.67.4",
95
+ "@modern-js/plugin": "2.67.4",
96
+ "@modern-js/node-bundle-require": "2.67.4",
97
+ "@modern-js/plugin-data-loader": "2.67.4",
98
+ "@modern-js/plugin-i18n": "2.67.4",
99
+ "@modern-js/plugin-v2": "2.67.4",
100
+ "@modern-js/prod-server": "2.67.4",
101
+ "@modern-js/rsbuild-plugin-esbuild": "2.67.4",
102
+ "@modern-js/server": "2.67.4",
103
+ "@modern-js/server-core": "2.67.4",
104
+ "@modern-js/types": "2.67.4",
105
+ "@modern-js/server-utils": "2.67.4",
106
+ "@modern-js/uni-builder": "2.67.4",
107
+ "@modern-js/utils": "2.67.4"
108
108
  },
109
109
  "devDependencies": {
110
110
  "@rsbuild/plugin-webpack-swc": "1.1.0",