@modern-js/app-tools 2.60.1-alpha.0 → 2.60.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -4
- package/dist/cjs/plugins/deploy/platforms/node.js +5 -4
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -4
- package/dist/cjs/plugins/deploy/utils.js +5 -3
- package/dist/esm/index.js +2 -3
- package/dist/esm/plugins/deploy/platforms/netlify.js +6 -5
- package/dist/esm/plugins/deploy/platforms/node.js +6 -5
- package/dist/esm/plugins/deploy/platforms/vercel.js +6 -5
- package/dist/esm/plugins/deploy/utils.js +10 -7
- package/dist/esm-node/index.js +2 -3
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -5
- package/dist/esm-node/plugins/deploy/platforms/node.js +6 -5
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -5
- package/dist/esm-node/plugins/deploy/utils.js +5 -3
- package/dist/types/plugins/deploy/utils.d.ts +3 -2
- package/package.json +21 -18
package/dist/cjs/index.js
CHANGED
|
@@ -37,7 +37,6 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_path = __toESM(require("path"));
|
|
39
39
|
var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
|
|
40
|
-
var import_plugin_lint = require("@modern-js/plugin-lint");
|
|
41
40
|
var import_utils = require("@modern-js/utils");
|
|
42
41
|
var import_hooks = require("./hooks");
|
|
43
42
|
var import_locale = require("./locale");
|
|
@@ -82,7 +81,6 @@ const appTools = (options = {
|
|
|
82
81
|
].includes(options.bundler) ? "rspack" : "webpack"
|
|
83
82
|
}),
|
|
84
83
|
(0, import_serverBuild.default)(),
|
|
85
|
-
(0, import_plugin_lint.lintPlugin)(),
|
|
86
84
|
(0, import_deploy.default)()
|
|
87
85
|
],
|
|
88
86
|
setup: (api) => {
|
|
@@ -115,6 +113,7 @@ const appTools = (options = {
|
|
|
115
113
|
(0, import_commands.newCommand)(program, locale);
|
|
116
114
|
(0, import_commands.inspectCommand)(program, api);
|
|
117
115
|
(0, import_commands.upgradeCommand)(program);
|
|
116
|
+
(0, import_utils.deprecatedCommands)(program);
|
|
118
117
|
},
|
|
119
118
|
async prepare() {
|
|
120
119
|
const command = (0, import_utils.getCommand)();
|
|
@@ -52,7 +52,10 @@ async function cleanDistDirectory(dir) {
|
|
|
52
52
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
53
53
|
const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
|
|
54
54
|
const isEsmProject = moduleType === "module";
|
|
55
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
55
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
56
|
+
plugin.name,
|
|
57
|
+
plugin.options
|
|
58
|
+
]);
|
|
56
59
|
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
|
57
60
|
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
|
58
61
|
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
|
@@ -115,9 +118,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
115
118
|
config: serverConfig,
|
|
116
119
|
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
117
120
|
};
|
|
118
|
-
const pluginsCode =
|
|
119
|
-
return `plugin_${index}()`;
|
|
120
|
-
}).join(",")}]`;
|
|
121
|
+
const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
|
|
121
122
|
let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlify-handler.js"))).toString();
|
|
122
123
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
123
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);
|
|
@@ -38,7 +38,10 @@ var import_utils2 = require("../utils");
|
|
|
38
38
|
const createNodePreset = (appContext, config) => {
|
|
39
39
|
const { appDirectory, distDirectory, serverPlugins, moduleType } = appContext;
|
|
40
40
|
const isEsmProject = moduleType === "module";
|
|
41
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
41
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
42
|
+
plugin.name,
|
|
43
|
+
plugin.options
|
|
44
|
+
]);
|
|
42
45
|
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
|
43
46
|
const staticDirectory = import_node_path.default.join(outputDirectory, "static");
|
|
44
47
|
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
|
@@ -69,9 +72,7 @@ const createNodePreset = (appContext, config) => {
|
|
|
69
72
|
config: serverConfig,
|
|
70
73
|
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
71
74
|
};
|
|
72
|
-
const pluginsCode =
|
|
73
|
-
return `plugin_${index}()`;
|
|
74
|
-
}).join(",")}]`;
|
|
75
|
+
const pluginsCode = (0, import_utils2.getPluginsCode)(plugins);
|
|
75
76
|
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./node-entry.js"))).toString();
|
|
76
77
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
77
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);
|
|
@@ -39,7 +39,10 @@ var import_utils2 = require("../utils");
|
|
|
39
39
|
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
40
40
|
const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
|
|
41
41
|
const isEsmProject = moduleType === "module";
|
|
42
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
42
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
43
|
+
plugin.name,
|
|
44
|
+
plugin.options
|
|
45
|
+
]);
|
|
43
46
|
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
|
44
47
|
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
|
45
48
|
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
|
@@ -130,9 +133,7 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
130
133
|
config: serverConfig,
|
|
131
134
|
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
132
135
|
};
|
|
133
|
-
const pluginsCode =
|
|
134
|
-
return `plugin_${index}()`;
|
|
135
|
-
}).join(",")}]`;
|
|
136
|
+
const pluginsCode = (0, import_utils2.getPluginsCode)(plugins || []);
|
|
136
137
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
137
138
|
let handlerCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercel-handler.js"))).toString();
|
|
138
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);
|
|
@@ -45,13 +45,15 @@ const serverAppContenxtTemplate = (appContext) => {
|
|
|
45
45
|
metaName
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
|
-
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
|
49
48
|
const genPluginImportsCode = (plugins) => {
|
|
50
|
-
return plugins.map((
|
|
51
|
-
let plugin_${index} = require('${
|
|
49
|
+
return plugins.map(([name, options], index) => `
|
|
50
|
+
let plugin_${index} = require('${name}')
|
|
52
51
|
plugin_${index} = plugin_${index}.default || plugin_${index}
|
|
53
52
|
`).join(";\n");
|
|
54
53
|
};
|
|
54
|
+
const getPluginsCode = (plugins) => {
|
|
55
|
+
return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
|
|
56
|
+
};
|
|
55
57
|
const getProjectUsage = (appDirectory, distDirectory) => {
|
|
56
58
|
const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
|
|
57
59
|
const { routes } = import_utils.fs.readJSONSync(routeJSON);
|
package/dist/esm/index.js
CHANGED
|
@@ -4,8 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
7
|
-
import {
|
|
8
|
-
import { cleanRequireCache, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
7
|
+
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
9
8
|
import { hooks } from "./hooks";
|
|
10
9
|
import { i18n } from "./locale";
|
|
11
10
|
import analyzePlugin from "./plugins/analyze";
|
|
@@ -51,7 +50,6 @@ var appTools = function() {
|
|
|
51
50
|
].includes(options.bundler) ? "rspack" : "webpack"
|
|
52
51
|
}),
|
|
53
52
|
serverBuildPlugin(),
|
|
54
|
-
lintPlugin(),
|
|
55
53
|
deployPlugin()
|
|
56
54
|
],
|
|
57
55
|
setup: function(api) {
|
|
@@ -104,6 +102,7 @@ var appTools = function() {
|
|
|
104
102
|
newCommand(program, locale);
|
|
105
103
|
inspectCommand(program, api);
|
|
106
104
|
upgradeCommand(program);
|
|
105
|
+
deprecatedCommands(program);
|
|
107
106
|
return [
|
|
108
107
|
2
|
|
109
108
|
];
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
|
|
5
5
|
import { isMainEntry } from "../../../utils/routes";
|
|
6
6
|
import { handleDependencies } from "../dependencies";
|
|
7
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
7
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
8
8
|
function cleanDistDirectory(dir) {
|
|
9
9
|
return _cleanDistDirectory.apply(this, arguments);
|
|
10
10
|
}
|
|
@@ -114,7 +114,10 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
|
114
114
|
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
|
|
115
115
|
var isEsmProject = moduleType === "module";
|
|
116
116
|
var plugins = serverPlugins.map(function(plugin) {
|
|
117
|
-
return
|
|
117
|
+
return [
|
|
118
|
+
plugin.name,
|
|
119
|
+
plugin.options
|
|
120
|
+
];
|
|
118
121
|
});
|
|
119
122
|
var netlifyOutput = path.join(appDirectory, ".netlify");
|
|
120
123
|
var funcsDirectory = path.join(netlifyOutput, "functions");
|
|
@@ -230,9 +233,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
|
230
233
|
config: serverConfig,
|
|
231
234
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
232
235
|
};
|
|
233
|
-
pluginsCode =
|
|
234
|
-
return "plugin_".concat(index, "()");
|
|
235
|
-
}).join(","), "]");
|
|
236
|
+
pluginsCode = getPluginsCode(plugins);
|
|
236
237
|
return [
|
|
237
238
|
4,
|
|
238
239
|
fse.readFile(path.join(__dirname, "./netlify-handler.js"))
|
|
@@ -3,12 +3,15 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, chalk, fs as fse } from "@modern-js/utils";
|
|
5
5
|
import { handleDependencies } from "../dependencies";
|
|
6
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
6
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
7
7
|
var createNodePreset = function(appContext, config) {
|
|
8
8
|
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
|
|
9
9
|
var isEsmProject = moduleType === "module";
|
|
10
10
|
var plugins = serverPlugins.map(function(plugin) {
|
|
11
|
-
return
|
|
11
|
+
return [
|
|
12
|
+
plugin.name,
|
|
13
|
+
plugin.options
|
|
14
|
+
];
|
|
12
15
|
});
|
|
13
16
|
var outputDirectory = path.join(appDirectory, ".output");
|
|
14
17
|
var staticDirectory = path.join(outputDirectory, "static");
|
|
@@ -74,9 +77,7 @@ var createNodePreset = function(appContext, config) {
|
|
|
74
77
|
config: serverConfig,
|
|
75
78
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
76
79
|
};
|
|
77
|
-
pluginsCode =
|
|
78
|
-
return "plugin_".concat(index, "()");
|
|
79
|
-
}).join(","), "]");
|
|
80
|
+
pluginsCode = getPluginsCode(plugins);
|
|
80
81
|
return [
|
|
81
82
|
4,
|
|
82
83
|
fse.readFile(path.join(__dirname, "./node-entry.js"))
|
|
@@ -4,12 +4,15 @@ import path from "node:path";
|
|
|
4
4
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
|
|
5
5
|
import { isMainEntry } from "../../../utils/routes";
|
|
6
6
|
import { handleDependencies } from "../dependencies";
|
|
7
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
7
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
8
8
|
var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
9
9
|
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, entrypoints = appContext.entrypoints, serverPlugins = appContext.serverPlugins, moduleType = appContext.moduleType;
|
|
10
10
|
var isEsmProject = moduleType === "module";
|
|
11
11
|
var plugins = serverPlugins.map(function(plugin) {
|
|
12
|
-
return
|
|
12
|
+
return [
|
|
13
|
+
plugin.name,
|
|
14
|
+
plugin.options
|
|
15
|
+
];
|
|
13
16
|
});
|
|
14
17
|
var vercelOutput = path.join(appDirectory, ".vercel");
|
|
15
18
|
var outputDirectory = path.join(vercelOutput, "output");
|
|
@@ -177,9 +180,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
|
177
180
|
config: serverConfig,
|
|
178
181
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
179
182
|
};
|
|
180
|
-
pluginsCode =
|
|
181
|
-
return "plugin_".concat(index, "()");
|
|
182
|
-
}).join(","), "]");
|
|
183
|
+
pluginsCode = getPluginsCode(plugins || []);
|
|
183
184
|
serverAppContext = serverAppContenxtTemplate(appContext);
|
|
184
185
|
return [
|
|
185
186
|
4,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
|
3
4
|
var serverAppContenxtTemplate = function(appContext) {
|
|
@@ -9,16 +10,18 @@ var serverAppContenxtTemplate = function(appContext) {
|
|
|
9
10
|
metaName
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
|
-
var getPluginsCode = function(plugins) {
|
|
13
|
-
return "[".concat(plugins.map(function(_, index) {
|
|
14
|
-
return "plugin_".concat(index, "()");
|
|
15
|
-
}).join(","), "]");
|
|
16
|
-
};
|
|
17
13
|
var genPluginImportsCode = function(plugins) {
|
|
18
|
-
return plugins.map(function(
|
|
19
|
-
|
|
14
|
+
return plugins.map(function(param, index) {
|
|
15
|
+
var _param = _sliced_to_array(param, 2), name = _param[0], options = _param[1];
|
|
16
|
+
return "\n let plugin_".concat(index, " = require('").concat(name, "')\n plugin_").concat(index, " = plugin_").concat(index, ".default || plugin_").concat(index, "\n ");
|
|
20
17
|
}).join(";\n");
|
|
21
18
|
};
|
|
19
|
+
var getPluginsCode = function(plugins) {
|
|
20
|
+
return "[".concat(plugins.map(function(param, index) {
|
|
21
|
+
var _param = _sliced_to_array(param, 2), options = _param[1];
|
|
22
|
+
return "plugin_".concat(index, "(").concat(options ? JSON.stringify(options) : "", ")");
|
|
23
|
+
}).join(","), "]");
|
|
24
|
+
};
|
|
22
25
|
var getProjectUsage = function(appDirectory, distDirectory) {
|
|
23
26
|
var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
24
27
|
var routes = fse.readJSONSync(routeJSON).routes;
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
3
|
-
import {
|
|
4
|
-
import { cleanRequireCache, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
3
|
+
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
5
4
|
import { hooks } from "./hooks";
|
|
6
5
|
import { i18n } from "./locale";
|
|
7
6
|
import analyzePlugin from "./plugins/analyze";
|
|
@@ -45,7 +44,6 @@ const appTools = (options = {
|
|
|
45
44
|
].includes(options.bundler) ? "rspack" : "webpack"
|
|
46
45
|
}),
|
|
47
46
|
serverBuildPlugin(),
|
|
48
|
-
lintPlugin(),
|
|
49
47
|
deployPlugin()
|
|
50
48
|
],
|
|
51
49
|
setup: (api) => {
|
|
@@ -78,6 +76,7 @@ const appTools = (options = {
|
|
|
78
76
|
newCommand(program, locale);
|
|
79
77
|
inspectCommand(program, api);
|
|
80
78
|
upgradeCommand(program);
|
|
79
|
+
deprecatedCommands(program);
|
|
81
80
|
},
|
|
82
81
|
async prepare() {
|
|
83
82
|
const command = getCommand();
|
|
@@ -2,7 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
|
|
3
3
|
import { isMainEntry } from "../../../utils/routes";
|
|
4
4
|
import { handleDependencies } from "../dependencies";
|
|
5
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
5
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
6
6
|
async function cleanDistDirectory(dir) {
|
|
7
7
|
try {
|
|
8
8
|
const items = await fse.readdir(dir);
|
|
@@ -19,7 +19,10 @@ async function cleanDistDirectory(dir) {
|
|
|
19
19
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
20
20
|
const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
|
|
21
21
|
const isEsmProject = moduleType === "module";
|
|
22
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
22
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
23
|
+
plugin.name,
|
|
24
|
+
plugin.options
|
|
25
|
+
]);
|
|
23
26
|
const netlifyOutput = path.join(appDirectory, ".netlify");
|
|
24
27
|
const funcsDirectory = path.join(netlifyOutput, "functions");
|
|
25
28
|
const entryFilePath = path.join(funcsDirectory, "index.js");
|
|
@@ -82,9 +85,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
82
85
|
config: serverConfig,
|
|
83
86
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
84
87
|
};
|
|
85
|
-
const pluginsCode =
|
|
86
|
-
return `plugin_${index}()`;
|
|
87
|
-
}).join(",")}]`;
|
|
88
|
+
const pluginsCode = getPluginsCode(plugins);
|
|
88
89
|
let handlerCode = (await fse.readFile(path.join(__dirname, "./netlify-handler.js"))).toString();
|
|
89
90
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
90
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);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, chalk, fs as fse } from "@modern-js/utils";
|
|
3
3
|
import { handleDependencies } from "../dependencies";
|
|
4
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
4
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
5
5
|
const createNodePreset = (appContext, config) => {
|
|
6
6
|
const { appDirectory, distDirectory, serverPlugins, moduleType } = appContext;
|
|
7
7
|
const isEsmProject = moduleType === "module";
|
|
8
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
8
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
9
|
+
plugin.name,
|
|
10
|
+
plugin.options
|
|
11
|
+
]);
|
|
9
12
|
const outputDirectory = path.join(appDirectory, ".output");
|
|
10
13
|
const staticDirectory = path.join(outputDirectory, "static");
|
|
11
14
|
const entryFilePath = path.join(outputDirectory, "index.js");
|
|
@@ -36,9 +39,7 @@ const createNodePreset = (appContext, config) => {
|
|
|
36
39
|
config: serverConfig,
|
|
37
40
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
38
41
|
};
|
|
39
|
-
const pluginsCode =
|
|
40
|
-
return `plugin_${index}()`;
|
|
41
|
-
}).join(",")}]`;
|
|
42
|
+
const pluginsCode = getPluginsCode(plugins);
|
|
42
43
|
let entryCode = (await fse.readFile(path.join(__dirname, "./node-entry.js"))).toString();
|
|
43
44
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
44
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);
|
|
@@ -2,11 +2,14 @@ import path from "node:path";
|
|
|
2
2
|
import { DEFAULT_SERVER_CONFIG, ROUTE_SPEC_FILE, fs as fse } from "@modern-js/utils";
|
|
3
3
|
import { isMainEntry } from "../../../utils/routes";
|
|
4
4
|
import { handleDependencies } from "../dependencies";
|
|
5
|
-
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
|
5
|
+
import { genPluginImportsCode, getPluginsCode, serverAppContenxtTemplate } from "../utils";
|
|
6
6
|
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
7
7
|
const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
|
|
8
8
|
const isEsmProject = moduleType === "module";
|
|
9
|
-
const plugins = serverPlugins.map((plugin) =>
|
|
9
|
+
const plugins = serverPlugins.map((plugin) => [
|
|
10
|
+
plugin.name,
|
|
11
|
+
plugin.options
|
|
12
|
+
]);
|
|
10
13
|
const vercelOutput = path.join(appDirectory, ".vercel");
|
|
11
14
|
const outputDirectory = path.join(vercelOutput, "output");
|
|
12
15
|
const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
|
@@ -97,9 +100,7 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
97
100
|
config: serverConfig,
|
|
98
101
|
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
99
102
|
};
|
|
100
|
-
const pluginsCode =
|
|
101
|
-
return `plugin_${index}()`;
|
|
102
|
-
}).join(",")}]`;
|
|
103
|
+
const pluginsCode = getPluginsCode(plugins || []);
|
|
103
104
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
104
105
|
let handlerCode = (await fse.readFile(path.join(__dirname, "./vercel-handler.js"))).toString();
|
|
105
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);
|
|
@@ -9,13 +9,15 @@ const serverAppContenxtTemplate = (appContext) => {
|
|
|
9
9
|
metaName
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
|
13
12
|
const genPluginImportsCode = (plugins) => {
|
|
14
|
-
return plugins.map((
|
|
15
|
-
let plugin_${index} = require('${
|
|
13
|
+
return plugins.map(([name, options], index) => `
|
|
14
|
+
let plugin_${index} = require('${name}')
|
|
16
15
|
plugin_${index} = plugin_${index}.default || plugin_${index}
|
|
17
16
|
`).join(";\n");
|
|
18
17
|
};
|
|
18
|
+
const getPluginsCode = (plugins) => {
|
|
19
|
+
return `[${plugins.map(([, options], index) => `plugin_${index}(${options ? JSON.stringify(options) : ""})`).join(",")}]`;
|
|
20
|
+
};
|
|
19
21
|
const getProjectUsage = (appDirectory, distDirectory) => {
|
|
20
22
|
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
21
23
|
const { routes } = fse.readJSONSync(routeJSON);
|
|
@@ -11,8 +11,9 @@ export declare const serverAppContenxtTemplate: (appContext: IAppContext) => {
|
|
|
11
11
|
lambdaDirectory: string;
|
|
12
12
|
metaName: string;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export declare const genPluginImportsCode: (plugins:
|
|
14
|
+
export type PluginItem = [string, Record<string, any> | undefined];
|
|
15
|
+
export declare const genPluginImportsCode: (plugins: PluginItem[]) => string;
|
|
16
|
+
export declare const getPluginsCode: (plugins: PluginItem[]) => string;
|
|
16
17
|
export declare const getProjectUsage: (appDirectory: string, distDirectory: string) => {
|
|
17
18
|
useSSR: boolean;
|
|
18
19
|
useAPI: boolean;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.60.
|
|
18
|
+
"version": "2.60.2-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -88,20 +88,19 @@
|
|
|
88
88
|
"mlly": "^1.6.1",
|
|
89
89
|
"pkg-types": "^1.1.0",
|
|
90
90
|
"std-env": "^3.7.0",
|
|
91
|
-
"@modern-js/node-bundle-require": "2.60.
|
|
92
|
-
"@modern-js/
|
|
93
|
-
"@modern-js/
|
|
94
|
-
"@modern-js/
|
|
95
|
-
"@modern-js/plugin-i18n": "2.60.
|
|
96
|
-
"@modern-js/
|
|
97
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.60.
|
|
98
|
-
"@modern-js/
|
|
99
|
-
"@modern-js/server": "2.60.
|
|
100
|
-
"@modern-js/
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@modern-js/
|
|
104
|
-
"@modern-js/uni-builder": "2.60.0"
|
|
91
|
+
"@modern-js/node-bundle-require": "2.60.1",
|
|
92
|
+
"@modern-js/core": "2.60.1",
|
|
93
|
+
"@modern-js/plugin": "2.60.1",
|
|
94
|
+
"@modern-js/prod-server": "2.60.1",
|
|
95
|
+
"@modern-js/plugin-i18n": "2.60.1",
|
|
96
|
+
"@modern-js/server": "2.60.1",
|
|
97
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.60.1",
|
|
98
|
+
"@modern-js/server-core": "2.60.1",
|
|
99
|
+
"@modern-js/server-utils": "2.60.1",
|
|
100
|
+
"@modern-js/types": "2.60.1",
|
|
101
|
+
"@modern-js/uni-builder": "2.60.1",
|
|
102
|
+
"@modern-js/utils": "2.60.1",
|
|
103
|
+
"@modern-js/plugin-data-loader": "2.60.1"
|
|
105
104
|
},
|
|
106
105
|
"devDependencies": {
|
|
107
106
|
"@rsbuild/plugin-webpack-swc": "1.0.2",
|
|
@@ -113,15 +112,19 @@
|
|
|
113
112
|
"tsconfig-paths": "^4.2.0",
|
|
114
113
|
"typescript": "^5",
|
|
115
114
|
"webpack": "^5.94.0",
|
|
116
|
-
"@scripts/build": "2.60.
|
|
117
|
-
"@scripts/jest-config": "2.60.
|
|
115
|
+
"@scripts/build": "2.60.1",
|
|
116
|
+
"@scripts/jest-config": "2.60.1"
|
|
118
117
|
},
|
|
119
118
|
"peerDependencies": {
|
|
120
|
-
"ts-node": "^10.7.0"
|
|
119
|
+
"ts-node": "^10.7.0",
|
|
120
|
+
"tsconfig-paths": "^4.2.0"
|
|
121
121
|
},
|
|
122
122
|
"peerDependenciesMeta": {
|
|
123
123
|
"ts-node": {
|
|
124
124
|
"optional": true
|
|
125
|
+
},
|
|
126
|
+
"tsconfig-paths": {
|
|
127
|
+
"optional": true
|
|
125
128
|
}
|
|
126
129
|
},
|
|
127
130
|
"sideEffects": false,
|