@modern-js/app-tools 2.67.1 → 2.67.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/commands/dev.js +2 -1
- package/dist/cjs/commands/serve.js +2 -1
- package/dist/cjs/plugins/deploy/index.js +3 -1
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +91 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +2 -1
- package/dist/cjs/plugins/deploy/platforms/netlify.js +3 -2
- package/dist/cjs/plugins/deploy/platforms/node-entry.js +2 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -1
- package/dist/cjs/plugins/deploy/utils.js +3 -2
- package/dist/cjs/utils/initAppContext.js +2 -1
- package/dist/esm/commands/dev.js +2 -1
- package/dist/esm/commands/serve.js +2 -1
- package/dist/esm/plugins/deploy/index.js +3 -1
- package/dist/esm/plugins/deploy/platforms/gh-pages.js +184 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.js +1 -1
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +2 -1
- package/dist/esm/plugins/deploy/platforms/netlify.js +3 -2
- package/dist/esm/plugins/deploy/platforms/node-entry.js +2 -1
- package/dist/esm/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +3 -2
- package/dist/esm/plugins/deploy/utils.js +3 -2
- package/dist/esm/utils/initAppContext.js +2 -1
- package/dist/esm-node/commands/dev.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -1
- package/dist/esm-node/plugins/deploy/index.js +3 -1
- package/dist/esm-node/plugins/deploy/platforms/gh-pages.js +57 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +2 -1
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -2
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +2 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +2 -1
- package/dist/esm-node/plugins/deploy/utils.js +3 -2
- package/dist/esm-node/utils/initAppContext.js +2 -1
- package/dist/types/plugins/deploy/platforms/gh-pages.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
- package/dist/types/plugins/deploy/utils.d.ts +2 -0
- package/dist/types/types/new.d.ts +5 -0
- package/dist/types/utils/initAppContext.d.ts +1 -0
- package/package.json +19 -19
package/dist/cjs/commands/dev.js
CHANGED
@@ -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,7 +30,8 @@ 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
37
|
const { appDirectory, distDirectory } = appContext;
|
@@ -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,7 +30,8 @@ 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,
|
36
37
|
...dynamicProdOptions
|
@@ -121,7 +121,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
121
121
|
const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
|
122
122
|
let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlify-handler.js"))).toString();
|
123
123
|
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);
|
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);
|
125
125
|
await import_utils.fs.writeFile(handlerFilePath, handlerCode);
|
126
126
|
if (isEsmProject) {
|
127
127
|
await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
|
@@ -140,7 +140,8 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
140
140
|
appDir: appDirectory,
|
141
141
|
sourceDir: funcsDirectory,
|
142
142
|
includeEntries: [
|
143
|
-
require.resolve("@modern-js/prod-server")
|
143
|
+
require.resolve("@modern-js/prod-server"),
|
144
|
+
require.resolve("@modern-js/prod-server/netlify")
|
144
145
|
],
|
145
146
|
copyWholePackage(pkgName) {
|
146
147
|
return pkgName === "@modern-js/utils";
|
@@ -28,7 +28,8 @@ 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,
|
34
35
|
...dynamicProdOptions
|
@@ -75,7 +75,7 @@ const createNodePreset = (appContext, config) => {
|
|
75
75
|
const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
|
76
76
|
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./node-entry.js"))).toString();
|
77
77
|
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);
|
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);
|
79
79
|
if (isEsmProject) {
|
80
80
|
const cjsEntryFilePath = import_node_path.default.join(outputDirectory, "index.cjs");
|
81
81
|
await import_utils.fs.writeFile(cjsEntryFilePath, entryCode);
|
@@ -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:
|
109
|
+
runtime: `nodejs${nodeVersion}.x`,
|
109
110
|
handler: "index.js",
|
110
111
|
launcherType: "Nodejs",
|
111
112
|
shouldAddHelpers: false,
|
@@ -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) => {
|
@@ -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:
|
package/dist/esm/commands/dev.js
CHANGED
@@ -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,7 +9,8 @@ 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);
|
@@ -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
|
+
};
|
@@ -4,7 +4,7 @@ var __commonJS = (cb, mod) => function __require() {
|
|
4
4
|
};
|
5
5
|
var require_netlify_entry = __commonJS({
|
6
6
|
"src/plugins/deploy/platforms/netlify-entry.cjs"(exports, module) {
|
7
|
-
var handler = require("./netlify-handler").handler;
|
7
|
+
var handler = require("./netlify-handler.cjs").handler;
|
8
8
|
module.exports.default = handler;
|
9
9
|
}
|
10
10
|
});
|
@@ -88,7 +88,8 @@ 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
94
|
plugins: p_plugins
|
94
95
|
}, dynamicProdOptions);
|
@@ -241,7 +241,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
241
241
|
case 1:
|
242
242
|
handlerCode = _state.sent().toString();
|
243
243
|
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);
|
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);
|
245
245
|
return [
|
246
246
|
4,
|
247
247
|
fse.writeFile(handlerFilePath, handlerCode)
|
@@ -308,7 +308,8 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
308
308
|
appDir: appDirectory,
|
309
309
|
sourceDir: funcsDirectory,
|
310
310
|
includeEntries: [
|
311
|
-
require.resolve("@modern-js/prod-server")
|
311
|
+
require.resolve("@modern-js/prod-server"),
|
312
|
+
require.resolve("@modern-js/prod-server/netlify")
|
312
313
|
],
|
313
314
|
copyWholePackage: function copyWholePackage(pkgName) {
|
314
315
|
return pkgName === "@modern-js/utils";
|
@@ -80,7 +80,8 @@ function _main() {
|
|
80
80
|
appContext: {
|
81
81
|
sharedDirectory: p_sharedDirectory,
|
82
82
|
apiDirectory: p_apiDirectory,
|
83
|
-
lambdaDirectory: p_lambdaDirectory
|
83
|
+
lambdaDirectory: p_lambdaDirectory,
|
84
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
84
85
|
},
|
85
86
|
plugins: p_plugins
|
86
87
|
}, dynamicProdOptions);
|
@@ -85,7 +85,7 @@ var createNodePreset = function(appContext, config) {
|
|
85
85
|
case 1:
|
86
86
|
entryCode = _state.sent().toString();
|
87
87
|
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_lambdaDirectory", serverAppContext.lambdaDirectory);
|
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);
|
89
89
|
if (!isEsmProject)
|
90
90
|
return [
|
91
91
|
3,
|
@@ -40,7 +40,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
40
40
|
},
|
41
41
|
writeOutput: function writeOutput() {
|
42
42
|
return _async_to_generator(function() {
|
43
|
-
var config, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
|
43
|
+
var config, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory, nodeVersion;
|
44
44
|
return _ts_generator(this, function(_state) {
|
45
45
|
switch (_state.label) {
|
46
46
|
case 0:
|
@@ -133,10 +133,11 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
133
133
|
];
|
134
134
|
case 7:
|
135
135
|
_state.sent();
|
136
|
+
nodeVersion = process.versions.node.split(".")[0];
|
136
137
|
return [
|
137
138
|
4,
|
138
139
|
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
139
|
-
runtime: "
|
140
|
+
runtime: "nodejs".concat(nodeVersion, ".x"),
|
140
141
|
handler: "index.js",
|
141
142
|
launcherType: "Nodejs",
|
142
143
|
shouldAddHelpers: false,
|
@@ -2,12 +2,13 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
2
|
import path from "path";
|
3
3
|
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
4
4
|
var serverAppContenxtTemplate = function(appContext) {
|
5
|
-
var appDirectory = appContext.appDirectory, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
|
5
|
+
var appDirectory = appContext.appDirectory, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, bffRuntimeFramework = appContext.bffRuntimeFramework;
|
6
6
|
return {
|
7
7
|
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
8
8
|
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
9
9
|
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
10
|
-
metaName
|
10
|
+
metaName,
|
11
|
+
bffRuntimeFramework: bffRuntimeFramework || "hono"
|
11
12
|
};
|
12
13
|
};
|
13
14
|
var genPluginImportsCode = function(plugins) {
|
@@ -21,7 +21,8 @@ var initAppContext = function(param) {
|
|
21
21
|
checkedEntries: [],
|
22
22
|
apiOnly: false,
|
23
23
|
internalDirAlias: "@_".concat(metaName.replace(/-/g, "_"), "_internal"),
|
24
|
-
internalSrcAlias: "@_".concat(metaName.replace(/-/g, "_"), "_src")
|
24
|
+
internalSrcAlias: "@_".concat(metaName.replace(/-/g, "_"), "_src"),
|
25
|
+
bffRuntimeFramework: "hono"
|
25
26
|
};
|
26
27
|
};
|
27
28
|
export {
|
@@ -63,7 +63,8 @@ const dev = async (api, options, devServerOptions) => {
|
|
63
63
|
internalDirectory: appContext.internalDirectory,
|
64
64
|
apiDirectory: appContext.apiDirectory,
|
65
65
|
lambdaDirectory: appContext.lambdaDirectory,
|
66
|
-
sharedDirectory: appContext.sharedDirectory
|
66
|
+
sharedDirectory: appContext.sharedDirectory,
|
67
|
+
bffRuntimeFramework: appContext.bffRuntimeFramework
|
67
68
|
},
|
68
69
|
serverConfigPath,
|
69
70
|
routes: serverRoutes,
|
@@ -40,7 +40,8 @@ const serve = async (api, serverOptions) => {
|
|
40
40
|
internalDirectory,
|
41
41
|
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
42
42
|
apiDirectory: isCrossProjectServer ? appContext.apiDirectory : getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
43
|
-
lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
43
|
+
lambdaDirectory: isCrossProjectServer ? appContext.lambdaDirectory : getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory),
|
44
|
+
bffRuntimeFramework: appContext.bffRuntimeFramework
|
44
45
|
},
|
45
46
|
runMode
|
46
47
|
});
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { provider } from "std-env";
|
2
|
+
import { createGhPagesPreset } from "./platforms/gh-pages";
|
2
3
|
import { createNetlifyPreset } from "./platforms/netlify";
|
3
4
|
import { createNodePreset } from "./platforms/node";
|
4
5
|
import { createVercelPreset } from "./platforms/vercel";
|
@@ -6,7 +7,8 @@ import { getProjectUsage } from "./utils";
|
|
6
7
|
const deployPresets = {
|
7
8
|
node: createNodePreset,
|
8
9
|
vercel: createVercelPreset,
|
9
|
-
netlify: createNetlifyPreset
|
10
|
+
netlify: createNetlifyPreset,
|
11
|
+
ghPages: createGhPagesPreset
|
10
12
|
};
|
11
13
|
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
12
14
|
const { appDirectory, distDirectory } = appContext;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { fs } from "@modern-js/utils";
|
3
|
+
import { logger } from "@modern-js/utils";
|
4
|
+
async function reorganizeHtmlFiles(routes, baseDir, baseUrl = "/") {
|
5
|
+
if (!routes || !Array.isArray(routes)) {
|
6
|
+
logger.error("Invalid server routes");
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
await fs.ensureDir(baseDir);
|
10
|
+
const baseUrlRegexp = new RegExp(`^${baseUrl}\\/?`);
|
11
|
+
const collectedEntryPaths = /* @__PURE__ */ new Set();
|
12
|
+
const copyPromises = routes.map(async (route) => {
|
13
|
+
const { urlPath, entryPath } = route;
|
14
|
+
if (!entryPath) {
|
15
|
+
logger.warn(`Route ${urlPath} does not specify entryPath, skipping`);
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
if (collectedEntryPaths.has(entryPath)) {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
collectedEntryPaths.add(entryPath);
|
22
|
+
const sourceHtmlPath = path.join(baseDir, entryPath);
|
23
|
+
if (!await fs.pathExists(sourceHtmlPath)) {
|
24
|
+
logger.error(`Source HTML file does not exist: ${sourceHtmlPath}`);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
const targetDir = urlPath.replace(baseUrlRegexp, "");
|
28
|
+
await fs.ensureDir(path.dirname(targetDir));
|
29
|
+
const targetHtmlPath = path.join(baseDir, targetDir, "index.html");
|
30
|
+
try {
|
31
|
+
await fs.move(sourceHtmlPath, targetHtmlPath);
|
32
|
+
} catch (error) {
|
33
|
+
logger.error(`Failed to copy HTML file: ${error.message}`);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
await Promise.all(copyPromises);
|
37
|
+
}
|
38
|
+
const createGhPagesPreset = (appContext, modernConfig) => {
|
39
|
+
const { serverRoutes, appDirectory, distDirectory } = appContext;
|
40
|
+
const { server: { baseUrl } } = modernConfig;
|
41
|
+
const outputDirectory = path.join(appDirectory, ".output");
|
42
|
+
return {
|
43
|
+
name: "gh-pages",
|
44
|
+
async prepare() {
|
45
|
+
await fs.remove(outputDirectory);
|
46
|
+
},
|
47
|
+
async writeOutput() {
|
48
|
+
await fs.copy(distDirectory, outputDirectory);
|
49
|
+
},
|
50
|
+
async end() {
|
51
|
+
await reorganizeHtmlFiles(serverRoutes, outputDirectory, Array.isArray(baseUrl) ? baseUrl[0] : baseUrl);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
};
|
55
|
+
export {
|
56
|
+
createGhPagesPreset
|
57
|
+
};
|
@@ -4,7 +4,7 @@ var __commonJS = (cb, mod) => function __require() {
|
|
4
4
|
};
|
5
5
|
var require_netlify_entry = __commonJS({
|
6
6
|
"src/plugins/deploy/platforms/netlify-entry.cjs"(exports, module) {
|
7
|
-
const { handler } = require("./netlify-handler");
|
7
|
+
const { handler } = require("./netlify-handler.cjs");
|
8
8
|
module.exports.default = handler;
|
9
9
|
}
|
10
10
|
});
|
@@ -35,7 +35,8 @@ var require_netlify_handler = __commonJS({
|
|
35
35
|
appContext: {
|
36
36
|
sharedDirectory: p_sharedDirectory,
|
37
37
|
apiDirectory: p_apiDirectory,
|
38
|
-
lambdaDirectory: p_lambdaDirectory
|
38
|
+
lambdaDirectory: p_lambdaDirectory,
|
39
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
39
40
|
},
|
40
41
|
plugins: p_plugins,
|
41
42
|
...dynamicProdOptions
|
@@ -88,7 +88,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
88
88
|
const pluginsCode = getPluginsCode(plugins);
|
89
89
|
let handlerCode = (await fse.readFile(path.join(__dirname, "./netlify-handler.js"))).toString();
|
90
90
|
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_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
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);
|
92
92
|
await fse.writeFile(handlerFilePath, handlerCode);
|
93
93
|
if (isEsmProject) {
|
94
94
|
await fse.copy(path.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
|
@@ -107,7 +107,8 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
107
107
|
appDir: appDirectory,
|
108
108
|
sourceDir: funcsDirectory,
|
109
109
|
includeEntries: [
|
110
|
-
require.resolve("@modern-js/prod-server")
|
110
|
+
require.resolve("@modern-js/prod-server"),
|
111
|
+
require.resolve("@modern-js/prod-server/netlify")
|
111
112
|
],
|
112
113
|
copyWholePackage(pkgName) {
|
113
114
|
return pkgName === "@modern-js/utils";
|
@@ -27,7 +27,8 @@ async function main() {
|
|
27
27
|
appContext: {
|
28
28
|
sharedDirectory: p_sharedDirectory,
|
29
29
|
apiDirectory: p_apiDirectory,
|
30
|
-
lambdaDirectory: p_lambdaDirectory
|
30
|
+
lambdaDirectory: p_lambdaDirectory,
|
31
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
31
32
|
},
|
32
33
|
plugins: p_plugins,
|
33
34
|
...dynamicProdOptions
|
@@ -42,7 +42,7 @@ const createNodePreset = (appContext, config) => {
|
|
42
42
|
const pluginsCode = getPluginsCode(plugins);
|
43
43
|
let entryCode = (await fse.readFile(path.join(__dirname, "./node-entry.js"))).toString();
|
44
44
|
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_lambdaDirectory", serverAppContext.lambdaDirectory);
|
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);
|
46
46
|
if (isEsmProject) {
|
47
47
|
const cjsEntryFilePath = path.join(outputDirectory, "index.cjs");
|
48
48
|
await fse.writeFile(cjsEntryFilePath, entryCode);
|
@@ -71,8 +71,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
71
71
|
return !src.includes(distStaticDirectory);
|
72
72
|
}
|
73
73
|
});
|
74
|
+
const nodeVersion = process.versions.node.split(".")[0];
|
74
75
|
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
75
|
-
runtime:
|
76
|
+
runtime: `nodejs${nodeVersion}.x`,
|
76
77
|
handler: "index.js",
|
77
78
|
launcherType: "Nodejs",
|
78
79
|
shouldAddHelpers: false,
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
3
3
|
const serverAppContenxtTemplate = (appContext) => {
|
4
|
-
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
4
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
|
5
5
|
return {
|
6
6
|
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
7
7
|
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
8
8
|
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
9
|
-
metaName
|
9
|
+
metaName,
|
10
|
+
bffRuntimeFramework: bffRuntimeFramework || "hono"
|
10
11
|
};
|
11
12
|
};
|
12
13
|
const genPluginImportsCode = (plugins) => {
|
@@ -20,7 +20,8 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, se
|
|
20
20
|
checkedEntries: [],
|
21
21
|
apiOnly: false,
|
22
22
|
internalDirAlias: `@_${metaName.replace(/-/g, "_")}_internal`,
|
23
|
-
internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src
|
23
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src`,
|
24
|
+
bffRuntimeFramework: "hono"
|
24
25
|
};
|
25
26
|
};
|
26
27
|
export {
|
@@ -4,12 +4,14 @@ export type ServerAppContext = {
|
|
4
4
|
apiDirectory: string;
|
5
5
|
lambdaDirectory: string;
|
6
6
|
metaName: string;
|
7
|
+
bffRuntimeFramework: string;
|
7
8
|
};
|
8
9
|
export declare const serverAppContenxtTemplate: (appContext: AppToolsContext<"shared">) => {
|
9
10
|
sharedDirectory: string;
|
10
11
|
apiDirectory: string;
|
11
12
|
lambdaDirectory: string;
|
12
13
|
metaName: string;
|
14
|
+
bffRuntimeFramework: string;
|
13
15
|
};
|
14
16
|
export type PluginItem = [string, Record<string, any> | undefined];
|
15
17
|
export declare const genPluginImportsCode: (plugins: PluginItem[]) => string;
|
@@ -133,6 +133,11 @@ export interface AppToolsExtendContext<B extends Bundler = 'webpack'> {
|
|
133
133
|
* @deprecated compat old plugin, default is app tools
|
134
134
|
*/
|
135
135
|
toolsType?: string;
|
136
|
+
/**
|
137
|
+
* Identification for bff runtime framework
|
138
|
+
* @private
|
139
|
+
*/
|
140
|
+
bffRuntimeFramework?: string;
|
136
141
|
}
|
137
142
|
export type AppToolsContext<B extends Bundler = 'webpack'> = AppContext<AppTools<B>> & AppToolsExtendContext<B>;
|
138
143
|
export type AppToolsHooks<B extends Bundler = 'webpack'> = Hooks<AppToolsUserConfig<B>, AppToolsNormalizedConfig, {}, {}> & AppToolsExtendHooks;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.67.
|
18
|
+
"version": "2.67.3",
|
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.
|
83
|
+
"@rsbuild/core": "1.3.10",
|
84
84
|
"@rsbuild/plugin-node-polyfill": "1.3.0",
|
85
85
|
"@swc/helpers": "0.5.13",
|
86
86
|
"es-module-lexer": "^1.1.0",
|
@@ -88,23 +88,23 @@
|
|
88
88
|
"esbuild-register": "^3.5.0",
|
89
89
|
"flatted": "^3.2.9",
|
90
90
|
"mlly": "^1.6.1",
|
91
|
-
"ndepe": "0.1.8",
|
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.
|
95
|
-
"@modern-js/plugin": "2.67.
|
96
|
-
"@modern-js/node-bundle-require": "2.67.
|
97
|
-
"@modern-js/plugin-data-loader": "2.67.
|
98
|
-
"@modern-js/plugin-i18n": "2.67.
|
99
|
-
"@modern-js/plugin-v2": "2.67.
|
100
|
-
"@modern-js/prod-server": "2.67.
|
101
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.67.
|
102
|
-
"@modern-js/server": "2.67.
|
103
|
-
"@modern-js/server-core": "2.67.
|
104
|
-
"@modern-js/server-utils": "2.67.
|
105
|
-
"@modern-js/types": "2.67.
|
106
|
-
"@modern-js/uni-builder": "2.67.
|
107
|
-
"@modern-js/utils": "2.67.
|
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"
|
108
108
|
},
|
109
109
|
"devDependencies": {
|
110
110
|
"@rsbuild/plugin-webpack-swc": "1.1.0",
|
@@ -116,8 +116,8 @@
|
|
116
116
|
"tsconfig-paths": "^4.2.0",
|
117
117
|
"typescript": "^5",
|
118
118
|
"webpack": "^5.98.0",
|
119
|
-
"@scripts/
|
120
|
-
"@scripts/
|
119
|
+
"@scripts/build": "2.66.0",
|
120
|
+
"@scripts/jest-config": "2.66.0"
|
121
121
|
},
|
122
122
|
"peerDependencies": {
|
123
123
|
"ts-node": "^10.7.0",
|