@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.
- package/dist/cjs/commands/dev.js +2 -1
- package/dist/cjs/commands/serve.js +2 -1
- package/dist/cjs/plugins/deploy/index.js +5 -3
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +91 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +3 -1
- package/dist/cjs/plugins/deploy/platforms/netlify.js +4 -2
- package/dist/cjs/plugins/deploy/platforms/node-entry.js +3 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +4 -2
- package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +1 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +6 -3
- package/dist/cjs/plugins/deploy/utils.js +13 -4
- package/dist/cjs/run/index.js +2 -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 +6 -4
- package/dist/esm/plugins/deploy/platforms/gh-pages.js +184 -0
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +4 -2
- package/dist/esm/plugins/deploy/platforms/netlify.js +6 -4
- package/dist/esm/plugins/deploy/platforms/node-entry.js +4 -2
- package/dist/esm/plugins/deploy/platforms/node.js +6 -4
- package/dist/esm/plugins/deploy/platforms/vercel-handler.js +2 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +9 -6
- package/dist/esm/plugins/deploy/utils.js +14 -5
- package/dist/esm/run/index.js +2 -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 +5 -3
- package/dist/esm-node/plugins/deploy/platforms/gh-pages.js +57 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +3 -1
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +5 -3
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +3 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +5 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +1 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +7 -4
- package/dist/esm-node/plugins/deploy/utils.js +14 -5
- package/dist/esm-node/run/index.js +2 -2
- package/dist/esm-node/utils/initAppContext.js +2 -1
- package/dist/types/exports/server.d.ts +1 -2
- package/dist/types/plugins/deploy/platforms/gh-pages.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +3 -1
- package/dist/types/types/new.d.ts +5 -0
- package/dist/types/utils/initAppContext.d.ts +1 -0
- package/package.json +16 -16
@@ -80,9 +80,11 @@ 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
|
-
plugins: p_plugins
|
86
|
+
plugins: p_plugins,
|
87
|
+
serverConfigPath: p_serverDirectory
|
86
88
|
}, dynamicProdOptions);
|
87
89
|
return [
|
88
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_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,
|
@@ -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 [
|
@@ -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,
|
@@ -156,7 +157,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
156
157
|
},
|
157
158
|
genEntry: function genEntry() {
|
158
159
|
return _async_to_generator(function() {
|
159
|
-
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, serverAppContext, handlerCode;
|
160
|
+
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, meta, serverConfigPath, pluginsCode, serverAppContext, handlerCode;
|
160
161
|
return _ts_generator(this, function(_state) {
|
161
162
|
switch (_state.label) {
|
162
163
|
case 0:
|
@@ -180,6 +181,8 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
180
181
|
config: serverConfig,
|
181
182
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
182
183
|
};
|
184
|
+
meta = getMeta(metaName);
|
185
|
+
serverConfigPath = 'path.join(__dirname, "'.concat(SERVER_DIR, '", "').concat(meta, '.server")');
|
183
186
|
pluginsCode = getPluginsCode(plugins || []);
|
184
187
|
serverAppContext = serverAppContenxtTemplate(appContext);
|
185
188
|
return [
|
@@ -188,7 +191,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
188
191
|
];
|
189
192
|
case 1:
|
190
193
|
handlerCode = _state.sent().toString();
|
191
|
-
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);
|
192
195
|
return [
|
193
196
|
4,
|
194
197
|
fse.writeFile(handlerFilePath, handlerCode)
|
@@ -1,13 +1,14 @@
|
|
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
|
-
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) {
|
@@ -22,7 +23,7 @@ var getPluginsCode = function(plugins) {
|
|
22
23
|
return "plugin_".concat(index, "(").concat(options ? JSON.stringify(options) : "", ")");
|
23
24
|
}).join(","), "]");
|
24
25
|
};
|
25
|
-
var getProjectUsage = function(appDirectory, distDirectory) {
|
26
|
+
var getProjectUsage = function(appDirectory, distDirectory, metaName) {
|
26
27
|
var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
27
28
|
var routes = fse.readJSONSync(routeJSON).routes;
|
28
29
|
var useSSR = false;
|
@@ -35,7 +36,15 @@ var getProjectUsage = function(appDirectory, distDirectory) {
|
|
35
36
|
useAPI = true;
|
36
37
|
}
|
37
38
|
});
|
38
|
-
var
|
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;
|
39
48
|
return {
|
40
49
|
useSSR,
|
41
50
|
useAPI,
|
package/dist/esm/run/index.js
CHANGED
@@ -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
|
})) {
|
@@ -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,11 +7,12 @@ 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
|
-
const { appDirectory, distDirectory } = appContext;
|
13
|
-
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
14
|
+
const { appDirectory, distDirectory, metaName } = appContext;
|
15
|
+
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
|
14
16
|
const needModernServer = useSSR || useAPI || useWebServer;
|
15
17
|
const createPreset = deployPresets[deployTarget];
|
16
18
|
if (!createPreset) {
|
@@ -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
|
+
};
|
@@ -35,9 +35,11 @@ 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,
|
42
|
+
serverConfigPath: p_serverDirectory,
|
41
43
|
...dynamicProdOptions
|
42
44
|
};
|
43
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_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);
|
@@ -27,9 +27,11 @@ 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,
|
34
|
+
serverConfigPath: p_serverDirectory,
|
33
35
|
...dynamicProdOptions
|
34
36
|
};
|
35
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_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);
|
@@ -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,
|
@@ -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,
|
@@ -100,10 +101,12 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
100
101
|
config: serverConfig,
|
101
102
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
102
103
|
};
|
104
|
+
const meta = getMeta(metaName);
|
105
|
+
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
103
106
|
const pluginsCode = getPluginsCode(plugins || []);
|
104
107
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
105
108
|
let handlerCode = (await fse.readFile(path.join(__dirname, "./vercel-handler.js"))).toString();
|
106
|
-
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);
|
107
110
|
await fse.writeFile(handlerFilePath, handlerCode);
|
108
111
|
if (isEsmProject) {
|
109
112
|
await fse.copy(path.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
|
@@ -1,12 +1,13 @@
|
|
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
|
-
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) => {
|
@@ -18,7 +19,7 @@ const genPluginImportsCode = (plugins) => {
|
|
18
19
|
const getPluginsCode = (plugins) => {
|
19
20
|
return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
|
20
21
|
};
|
21
|
-
const getProjectUsage = (appDirectory, distDirectory) => {
|
22
|
+
const getProjectUsage = (appDirectory, distDirectory, metaName) => {
|
22
23
|
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
23
24
|
const { routes } = fse.readJSONSync(routeJSON);
|
24
25
|
let useSSR = false;
|
@@ -31,7 +32,15 @@ const getProjectUsage = (appDirectory, distDirectory) => {
|
|
31
32
|
useAPI = true;
|
32
33
|
}
|
33
34
|
});
|
34
|
-
const
|
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;
|
35
44
|
return {
|
36
45
|
useSSR,
|
37
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
|
|
@@ -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 {
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import type {
|
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';
|
@@ -4,17 +4,19 @@ 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;
|
16
18
|
export declare const getPluginsCode: (plugins: PluginItem[]) => string;
|
17
|
-
export declare const getProjectUsage: (appDirectory: string, distDirectory: string) => {
|
19
|
+
export declare const getProjectUsage: (appDirectory: string, distDirectory: string, metaName: string) => {
|
18
20
|
useSSR: boolean;
|
19
21
|
useAPI: boolean;
|
20
22
|
useWebServer: boolean;
|
@@ -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;
|