@modern-js/app-tools 2.67.2 → 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 (45) hide show
  1. package/dist/cjs/commands/dev.js +2 -1
  2. package/dist/cjs/commands/serve.js +2 -1
  3. package/dist/cjs/plugins/deploy/index.js +5 -3
  4. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +91 -0
  5. package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +3 -1
  6. package/dist/cjs/plugins/deploy/platforms/netlify.js +4 -2
  7. package/dist/cjs/plugins/deploy/platforms/node-entry.js +3 -1
  8. package/dist/cjs/plugins/deploy/platforms/node.js +4 -2
  9. package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +1 -0
  10. package/dist/cjs/plugins/deploy/platforms/vercel.js +6 -3
  11. package/dist/cjs/plugins/deploy/utils.js +13 -4
  12. package/dist/cjs/run/index.js +2 -2
  13. package/dist/cjs/utils/initAppContext.js +2 -1
  14. package/dist/esm/commands/dev.js +2 -1
  15. package/dist/esm/commands/serve.js +2 -1
  16. package/dist/esm/plugins/deploy/index.js +6 -4
  17. package/dist/esm/plugins/deploy/platforms/gh-pages.js +184 -0
  18. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +4 -2
  19. package/dist/esm/plugins/deploy/platforms/netlify.js +6 -4
  20. package/dist/esm/plugins/deploy/platforms/node-entry.js +4 -2
  21. package/dist/esm/plugins/deploy/platforms/node.js +6 -4
  22. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +2 -1
  23. package/dist/esm/plugins/deploy/platforms/vercel.js +9 -6
  24. package/dist/esm/plugins/deploy/utils.js +14 -5
  25. package/dist/esm/run/index.js +2 -2
  26. package/dist/esm/utils/initAppContext.js +2 -1
  27. package/dist/esm-node/commands/dev.js +2 -1
  28. package/dist/esm-node/commands/serve.js +2 -1
  29. package/dist/esm-node/plugins/deploy/index.js +5 -3
  30. package/dist/esm-node/plugins/deploy/platforms/gh-pages.js +57 -0
  31. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +3 -1
  32. package/dist/esm-node/plugins/deploy/platforms/netlify.js +5 -3
  33. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +3 -1
  34. package/dist/esm-node/plugins/deploy/platforms/node.js +5 -3
  35. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +1 -0
  36. package/dist/esm-node/plugins/deploy/platforms/vercel.js +7 -4
  37. package/dist/esm-node/plugins/deploy/utils.js +14 -5
  38. package/dist/esm-node/run/index.js +2 -2
  39. package/dist/esm-node/utils/initAppContext.js +2 -1
  40. package/dist/types/exports/server.d.ts +1 -2
  41. package/dist/types/plugins/deploy/platforms/gh-pages.d.ts +2 -0
  42. package/dist/types/plugins/deploy/utils.d.ts +3 -1
  43. package/dist/types/types/new.d.ts +5 -0
  44. package/dist/types/utils/initAppContext.d.ts +1 -0
  45. package/package.json +16 -16
@@ -96,7 +96,8 @@ const dev = async (api, options, devServerOptions) => {
96
96
  internalDirectory: appContext.internalDirectory,
97
97
  apiDirectory: appContext.apiDirectory,
98
98
  lambdaDirectory: appContext.lambdaDirectory,
99
- sharedDirectory: appContext.sharedDirectory
99
+ sharedDirectory: appContext.sharedDirectory,
100
+ bffRuntimeFramework: appContext.bffRuntimeFramework
100
101
  },
101
102
  serverConfigPath,
102
103
  routes: serverRoutes,
@@ -73,7 +73,8 @@ const serve = async (api, serverOptions) => {
73
73
  internalDirectory,
74
74
  sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
75
75
  apiDirectory: isCrossProjectServer ? appContext.apiDirectory : (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
76
- lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
76
+ lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory),
77
+ bffRuntimeFramework: appContext.bffRuntimeFramework
77
78
  },
78
79
  runMode
79
80
  });
@@ -22,6 +22,7 @@ __export(deploy_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(deploy_exports);
24
24
  var import_std_env = require("std-env");
25
+ var import_gh_pages = require("./platforms/gh-pages");
25
26
  var import_netlify = require("./platforms/netlify");
26
27
  var import_node = require("./platforms/node");
27
28
  var import_vercel = require("./platforms/vercel");
@@ -29,11 +30,12 @@ var import_utils = require("./utils");
29
30
  const deployPresets = {
30
31
  node: import_node.createNodePreset,
31
32
  vercel: import_vercel.createVercelPreset,
32
- netlify: import_netlify.createNetlifyPreset
33
+ netlify: import_netlify.createNetlifyPreset,
34
+ ghPages: import_gh_pages.createGhPagesPreset
33
35
  };
34
36
  async function getDeployPreset(appContext, modernConfig, deployTarget) {
35
- const { appDirectory, distDirectory } = appContext;
36
- 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);
37
39
  const needModernServer = useSSR || useAPI || useWebServer;
38
40
  const createPreset = deployPresets[deployTarget];
39
41
  if (!createPreset) {
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var gh_pages_exports = {};
30
+ __export(gh_pages_exports, {
31
+ createGhPagesPreset: () => createGhPagesPreset
32
+ });
33
+ module.exports = __toCommonJS(gh_pages_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_utils2 = require("@modern-js/utils");
37
+ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = "/") {
38
+ if (!routes || !Array.isArray(routes)) {
39
+ import_utils2.logger.error("Invalid server routes");
40
+ return;
41
+ }
42
+ await import_utils.fs.ensureDir(baseDir);
43
+ const baseUrlRegexp = new RegExp(`^${baseUrl}\\/?`);
44
+ const collectedEntryPaths = /* @__PURE__ */ new Set();
45
+ const copyPromises = routes.map(async (route) => {
46
+ const { urlPath, entryPath } = route;
47
+ if (!entryPath) {
48
+ import_utils2.logger.warn(`Route ${urlPath} does not specify entryPath, skipping`);
49
+ return;
50
+ }
51
+ if (collectedEntryPaths.has(entryPath)) {
52
+ return;
53
+ }
54
+ collectedEntryPaths.add(entryPath);
55
+ const sourceHtmlPath = import_path.default.join(baseDir, entryPath);
56
+ if (!await import_utils.fs.pathExists(sourceHtmlPath)) {
57
+ import_utils2.logger.error(`Source HTML file does not exist: ${sourceHtmlPath}`);
58
+ return;
59
+ }
60
+ const targetDir = urlPath.replace(baseUrlRegexp, "");
61
+ await import_utils.fs.ensureDir(import_path.default.dirname(targetDir));
62
+ const targetHtmlPath = import_path.default.join(baseDir, targetDir, "index.html");
63
+ try {
64
+ await import_utils.fs.move(sourceHtmlPath, targetHtmlPath);
65
+ } catch (error) {
66
+ import_utils2.logger.error(`Failed to copy HTML file: ${error.message}`);
67
+ }
68
+ });
69
+ await Promise.all(copyPromises);
70
+ }
71
+ const createGhPagesPreset = (appContext, modernConfig) => {
72
+ const { serverRoutes, appDirectory, distDirectory } = appContext;
73
+ const { server: { baseUrl } } = modernConfig;
74
+ const outputDirectory = import_path.default.join(appDirectory, ".output");
75
+ return {
76
+ name: "gh-pages",
77
+ async prepare() {
78
+ await import_utils.fs.remove(outputDirectory);
79
+ },
80
+ async writeOutput() {
81
+ await import_utils.fs.copy(distDirectory, outputDirectory);
82
+ },
83
+ async end() {
84
+ await reorganizeHtmlFiles(serverRoutes, outputDirectory, Array.isArray(baseUrl) ? baseUrl[0] : baseUrl);
85
+ }
86
+ };
87
+ };
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ createGhPagesPreset
91
+ });
@@ -30,9 +30,11 @@ async function initServer() {
30
30
  appContext: {
31
31
  sharedDirectory: p_sharedDirectory,
32
32
  apiDirectory: p_apiDirectory,
33
- lambdaDirectory: p_lambdaDirectory
33
+ lambdaDirectory: p_lambdaDirectory,
34
+ bffRuntimeFramework: p_bffRuntimeFramework
34
35
  },
35
36
  plugins: p_plugins,
37
+ serverConfigPath: p_serverDirectory,
36
38
  ...dynamicProdOptions
37
39
  };
38
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_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);
@@ -28,9 +28,11 @@ async function main() {
28
28
  appContext: {
29
29
  sharedDirectory: p_sharedDirectory,
30
30
  apiDirectory: p_apiDirectory,
31
- lambdaDirectory: p_lambdaDirectory
31
+ lambdaDirectory: p_lambdaDirectory,
32
+ bffRuntimeFramework: p_bffRuntimeFramework
32
33
  },
33
34
  plugins: p_plugins,
35
+ serverConfigPath: p_serverDirectory,
34
36
  ...dynamicProdOptions
35
37
  };
36
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_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,
@@ -104,8 +104,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
104
104
  return !src.includes(distStaticDirectory);
105
105
  }
106
106
  });
107
+ const nodeVersion = process.versions.node.split(".")[0];
107
108
  await import_utils.fs.writeJSON(import_node_path.default.join(funcsDirectory, ".vc-config.json"), {
108
- runtime: "nodejs16.x",
109
+ runtime: `nodejs${nodeVersion}.x`,
109
110
  handler: "index.js",
110
111
  launcherType: "Nodejs",
111
112
  shouldAddHelpers: false,
@@ -133,10 +134,12 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
133
134
  config: serverConfig,
134
135
  serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
135
136
  };
137
+ const meta = (0, import_utils.getMeta)(metaName);
138
+ const serverConfigPath = `path.join(__dirname, "${import_utils.SERVER_DIR}", "${meta}.server")`;
136
139
  const pluginsCode = (0, import_utils2.getPluginsCode)(plugins || []);
137
140
  const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
138
141
  let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercel-handler.js"))).toString();
139
- 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);
140
143
  await import_utils.fs.writeFile(handlerFilePath, handlerCode);
141
144
  if (isEsmProject) {
142
145
  await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
@@ -37,12 +37,13 @@ module.exports = __toCommonJS(utils_exports);
37
37
  var import_path = __toESM(require("path"));
38
38
  var import_utils = require("@modern-js/utils");
39
39
  const serverAppContenxtTemplate = (appContext) => {
40
- const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
40
+ const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
41
41
  return {
42
42
  sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
43
43
  apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
44
44
  lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
45
- metaName
45
+ metaName,
46
+ bffRuntimeFramework: bffRuntimeFramework || "hono"
46
47
  };
47
48
  };
48
49
  const genPluginImportsCode = (plugins) => {
@@ -54,7 +55,7 @@ const genPluginImportsCode = (plugins) => {
54
55
  const getPluginsCode = (plugins) => {
55
56
  return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
56
57
  };
57
- const getProjectUsage = (appDirectory, distDirectory) => {
58
+ const getProjectUsage = (appDirectory, distDirectory, metaName) => {
58
59
  const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
59
60
  const { routes } = import_utils.fs.readJSONSync(routeJSON);
60
61
  let useSSR = false;
@@ -67,7 +68,15 @@ const getProjectUsage = (appDirectory, distDirectory) => {
67
68
  useAPI = true;
68
69
  }
69
70
  });
70
- 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;
71
80
  return {
72
81
  useSSR,
73
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
 
@@ -53,7 +53,8 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, se
53
53
  checkedEntries: [],
54
54
  apiOnly: false,
55
55
  internalDirAlias: `@_${metaName.replace(/-/g, "_")}_internal`,
56
- internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src`
56
+ internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src`,
57
+ bffRuntimeFramework: "hono"
57
58
  };
58
59
  };
59
60
  // Annotate the CommonJS export names for ESM import in node:
@@ -106,7 +106,8 @@ var dev = function() {
106
106
  internalDirectory: appContext.internalDirectory,
107
107
  apiDirectory: appContext.apiDirectory,
108
108
  lambdaDirectory: appContext.lambdaDirectory,
109
- sharedDirectory: appContext.sharedDirectory
109
+ sharedDirectory: appContext.sharedDirectory,
110
+ bffRuntimeFramework: appContext.bffRuntimeFramework
110
111
  },
111
112
  serverConfigPath,
112
113
  routes: serverRoutes,
@@ -57,7 +57,8 @@ var serve = function() {
57
57
  internalDirectory,
58
58
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
59
59
  apiDirectory: isCrossProjectServer ? appContext.apiDirectory : getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
60
- lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
60
+ lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory),
61
+ bffRuntimeFramework: appContext.bffRuntimeFramework
61
62
  },
62
63
  runMode
63
64
  })
@@ -1,6 +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 { provider } from "std-env";
4
+ import { createGhPagesPreset } from "./platforms/gh-pages";
4
5
  import { createNetlifyPreset } from "./platforms/netlify";
5
6
  import { createNodePreset } from "./platforms/node";
6
7
  import { createVercelPreset } from "./platforms/vercel";
@@ -8,17 +9,18 @@ import { getProjectUsage } from "./utils";
8
9
  var deployPresets = {
9
10
  node: createNodePreset,
10
11
  vercel: createVercelPreset,
11
- netlify: createNetlifyPreset
12
+ netlify: createNetlifyPreset,
13
+ ghPages: createGhPagesPreset
12
14
  };
13
15
  function getDeployPreset(appContext, modernConfig, deployTarget) {
14
16
  return _getDeployPreset.apply(this, arguments);
15
17
  }
16
18
  function _getDeployPreset() {
17
19
  _getDeployPreset = _async_to_generator(function(appContext, modernConfig, deployTarget) {
18
- var appDirectory, distDirectory, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, createPreset;
20
+ var appDirectory, distDirectory, metaName, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, createPreset;
19
21
  return _ts_generator(this, function(_state) {
20
- appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
21
- _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;
22
24
  needModernServer = useSSR || useAPI || useWebServer;
23
25
  createPreset = deployPresets[deployTarget];
24
26
  if (!createPreset) {
@@ -0,0 +1,184 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import path from "path";
4
+ import { fs } from "@modern-js/utils";
5
+ import { logger } from "@modern-js/utils";
6
+ function reorganizeHtmlFiles(routes, baseDir) {
7
+ return _reorganizeHtmlFiles.apply(this, arguments);
8
+ }
9
+ function _reorganizeHtmlFiles() {
10
+ _reorganizeHtmlFiles = _async_to_generator(function(routes, baseDir) {
11
+ var baseUrl, baseUrlRegexp, collectedEntryPaths, copyPromises;
12
+ var _arguments = arguments;
13
+ return _ts_generator(this, function(_state) {
14
+ switch (_state.label) {
15
+ case 0:
16
+ baseUrl = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : "/";
17
+ if (!routes || !Array.isArray(routes)) {
18
+ logger.error("Invalid server routes");
19
+ return [
20
+ 2
21
+ ];
22
+ }
23
+ return [
24
+ 4,
25
+ fs.ensureDir(baseDir)
26
+ ];
27
+ case 1:
28
+ _state.sent();
29
+ baseUrlRegexp = new RegExp("^".concat(baseUrl, "\\/?"));
30
+ collectedEntryPaths = /* @__PURE__ */ new Set();
31
+ copyPromises = routes.map(function() {
32
+ var _ref = _async_to_generator(function(route) {
33
+ var urlPath, entryPath, sourceHtmlPath, targetDir, targetHtmlPath, error;
34
+ return _ts_generator(this, function(_state2) {
35
+ switch (_state2.label) {
36
+ case 0:
37
+ urlPath = route.urlPath, entryPath = route.entryPath;
38
+ if (!entryPath) {
39
+ logger.warn("Route ".concat(urlPath, " does not specify entryPath, skipping"));
40
+ return [
41
+ 2
42
+ ];
43
+ }
44
+ if (collectedEntryPaths.has(entryPath)) {
45
+ return [
46
+ 2
47
+ ];
48
+ }
49
+ collectedEntryPaths.add(entryPath);
50
+ sourceHtmlPath = path.join(baseDir, entryPath);
51
+ return [
52
+ 4,
53
+ fs.pathExists(sourceHtmlPath)
54
+ ];
55
+ case 1:
56
+ if (!_state2.sent()) {
57
+ logger.error("Source HTML file does not exist: ".concat(sourceHtmlPath));
58
+ return [
59
+ 2
60
+ ];
61
+ }
62
+ targetDir = urlPath.replace(baseUrlRegexp, "");
63
+ return [
64
+ 4,
65
+ fs.ensureDir(path.dirname(targetDir))
66
+ ];
67
+ case 2:
68
+ _state2.sent();
69
+ targetHtmlPath = path.join(baseDir, targetDir, "index.html");
70
+ _state2.label = 3;
71
+ case 3:
72
+ _state2.trys.push([
73
+ 3,
74
+ 5,
75
+ ,
76
+ 6
77
+ ]);
78
+ return [
79
+ 4,
80
+ fs.move(sourceHtmlPath, targetHtmlPath)
81
+ ];
82
+ case 4:
83
+ _state2.sent();
84
+ return [
85
+ 3,
86
+ 6
87
+ ];
88
+ case 5:
89
+ error = _state2.sent();
90
+ logger.error("Failed to copy HTML file: ".concat(error.message));
91
+ return [
92
+ 3,
93
+ 6
94
+ ];
95
+ case 6:
96
+ return [
97
+ 2
98
+ ];
99
+ }
100
+ });
101
+ });
102
+ return function(route) {
103
+ return _ref.apply(this, arguments);
104
+ };
105
+ }());
106
+ return [
107
+ 4,
108
+ Promise.all(copyPromises)
109
+ ];
110
+ case 2:
111
+ _state.sent();
112
+ return [
113
+ 2
114
+ ];
115
+ }
116
+ });
117
+ });
118
+ return _reorganizeHtmlFiles.apply(this, arguments);
119
+ }
120
+ var createGhPagesPreset = function(appContext, modernConfig) {
121
+ var serverRoutes = appContext.serverRoutes, appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
122
+ var baseUrl = modernConfig.server.baseUrl;
123
+ var outputDirectory = path.join(appDirectory, ".output");
124
+ return {
125
+ name: "gh-pages",
126
+ prepare: function prepare() {
127
+ return _async_to_generator(function() {
128
+ return _ts_generator(this, function(_state) {
129
+ switch (_state.label) {
130
+ case 0:
131
+ return [
132
+ 4,
133
+ fs.remove(outputDirectory)
134
+ ];
135
+ case 1:
136
+ _state.sent();
137
+ return [
138
+ 2
139
+ ];
140
+ }
141
+ });
142
+ })();
143
+ },
144
+ writeOutput: function writeOutput() {
145
+ return _async_to_generator(function() {
146
+ return _ts_generator(this, function(_state) {
147
+ switch (_state.label) {
148
+ case 0:
149
+ return [
150
+ 4,
151
+ fs.copy(distDirectory, outputDirectory)
152
+ ];
153
+ case 1:
154
+ _state.sent();
155
+ return [
156
+ 2
157
+ ];
158
+ }
159
+ });
160
+ })();
161
+ },
162
+ end: function end() {
163
+ return _async_to_generator(function() {
164
+ return _ts_generator(this, function(_state) {
165
+ switch (_state.label) {
166
+ case 0:
167
+ return [
168
+ 4,
169
+ reorganizeHtmlFiles(serverRoutes, outputDirectory, Array.isArray(baseUrl) ? baseUrl[0] : baseUrl)
170
+ ];
171
+ case 1:
172
+ _state.sent();
173
+ return [
174
+ 2
175
+ ];
176
+ }
177
+ });
178
+ })();
179
+ }
180
+ };
181
+ };
182
+ export {
183
+ createGhPagesPreset
184
+ };
@@ -88,9 +88,11 @@ var require_netlify_handler = __commonJS({
88
88
  appContext: {
89
89
  sharedDirectory: p_sharedDirectory,
90
90
  apiDirectory: p_apiDirectory,
91
- lambdaDirectory: p_lambdaDirectory
91
+ lambdaDirectory: p_lambdaDirectory,
92
+ bffRuntimeFramework: p_bffRuntimeFramework
92
93
  },
93
- plugins: p_plugins
94
+ plugins: p_plugins,
95
+ serverConfigPath: p_serverDirectory
94
96
  }, dynamicProdOptions);
95
97
  return [
96
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_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)