@modern-js/app-tools 2.49.3-alpha.14 → 2.49.3-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +13 -169
- package/dist/cjs/plugins/deploy/platforms/netlify.js +112 -64
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +40 -21
- package/dist/cjs/plugins/deploy/platforms/vercel.js +102 -19
- package/dist/cjs/plugins/deploy/utils.js +10 -8
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +17 -314
- package/dist/esm/plugins/deploy/platforms/netlify.js +203 -36
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +100 -46
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -43
- package/dist/esm/plugins/deploy/utils.js +9 -3
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +11 -157
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +103 -65
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +41 -22
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +103 -20
- package/dist/esm-node/plugins/deploy/utils.js +9 -7
- package/dist/types/plugins/deploy/index copy.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -5
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -8
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -4
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -8
- package/dist/types/plugins/deploy/utils.d.ts +7 -1
- package/package.json +7 -7
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
const fs = require("node:fs/promises");
|
3
|
+
const path = require("node:path");
|
4
|
+
const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
|
5
|
+
p_genPluginImportsCode;
|
6
|
+
if (!process.env.NODE_ENV) {
|
7
|
+
process.env.NODE_ENV = "production";
|
8
|
+
}
|
9
|
+
let requestHandler = null;
|
10
|
+
let handlerCreationPromise = null;
|
11
|
+
async function loadRoutes(routeFilepath) {
|
12
|
+
try {
|
13
|
+
await fs.access(routeFilepath);
|
14
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
15
|
+
const routeSpec = JSON.parse(content);
|
16
|
+
return routeSpec.routes || [];
|
17
|
+
} catch (error) {
|
18
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
19
|
+
return [];
|
20
|
+
}
|
21
|
+
}
|
22
|
+
async function initServer() {
|
23
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
24
|
+
const routes = await loadRoutes(routeFilepath);
|
25
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
26
|
+
const prodServerOptions = {
|
27
|
+
pwd: __dirname,
|
28
|
+
routes,
|
29
|
+
disableCustomHook: true,
|
30
|
+
appContext: {
|
31
|
+
sharedDirectory: p_sharedDirectory,
|
32
|
+
apiDirectory: p_apiDirectory,
|
33
|
+
lambdaDirectory: p_lambdaDirectory
|
34
|
+
},
|
35
|
+
...dynamicProdOptions
|
36
|
+
};
|
37
|
+
const app = await createNetlifyFunction(prodServerOptions);
|
38
|
+
return app.getRequestListener();
|
39
|
+
}
|
40
|
+
async function createHandler() {
|
41
|
+
if (!handlerCreationPromise) {
|
42
|
+
handlerCreationPromise = (async () => {
|
43
|
+
try {
|
44
|
+
requestHandler = await initServer();
|
45
|
+
} catch (error) {
|
46
|
+
console.error("Error creating server:", error);
|
47
|
+
process.exit(1);
|
48
|
+
}
|
49
|
+
})();
|
50
|
+
}
|
51
|
+
await handlerCreationPromise;
|
52
|
+
return requestHandler;
|
53
|
+
}
|
54
|
+
createHandler();
|
55
|
+
module.exports = async (request, context) => {
|
56
|
+
if (!requestHandler) {
|
57
|
+
await createHandler();
|
58
|
+
}
|
59
|
+
return requestHandler(request, context);
|
60
|
+
};
|
@@ -28,36 +28,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var node_exports = {};
|
30
30
|
__export(node_exports, {
|
31
|
-
|
31
|
+
createNodePreset: () => createNodePreset
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(node_exports);
|
34
34
|
var import_node_path = __toESM(require("node:path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
36
|
var import_utils2 = require("../utils");
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
37
|
+
var import_dependencies = require("../dependencies");
|
38
|
+
const createNodePreset = (appContext, config) => {
|
39
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
40
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
41
|
+
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
42
|
+
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
43
|
+
return {
|
44
|
+
async prepare() {
|
45
|
+
await import_utils.fs.remove(outputDirectory);
|
42
46
|
},
|
43
|
-
|
44
|
-
|
47
|
+
async writeOutput() {
|
48
|
+
await import_utils.fs.copy(distDirectory, outputDirectory);
|
45
49
|
},
|
46
|
-
|
47
|
-
|
50
|
+
async genEntry() {
|
51
|
+
var _config_bff;
|
52
|
+
const serverConfig = {
|
53
|
+
server: {
|
54
|
+
port: 8080
|
55
|
+
},
|
56
|
+
bff: {
|
57
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
58
|
+
},
|
59
|
+
output: {
|
60
|
+
path: "."
|
61
|
+
}
|
62
|
+
};
|
63
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
64
|
+
const dynamicProdOptions = {
|
65
|
+
config: serverConfig,
|
66
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
67
|
+
plugins
|
68
|
+
};
|
69
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
70
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
71
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
72
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
73
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
74
|
+
"@modern-js/prod-server"
|
75
|
+
]);
|
48
76
|
}
|
49
77
|
};
|
50
|
-
|
51
|
-
const dynamicProdOptions = {
|
52
|
-
config: serverConfig,
|
53
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
54
|
-
plugins
|
55
|
-
};
|
56
|
-
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
57
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
58
|
-
return entryCode;
|
59
|
-
}
|
78
|
+
};
|
60
79
|
// Annotate the CommonJS export names for ESM import in node:
|
61
80
|
0 && (module.exports = {
|
62
|
-
|
81
|
+
createNodePreset
|
63
82
|
});
|
@@ -28,33 +28,116 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var vercel_exports = {};
|
30
30
|
__export(vercel_exports, {
|
31
|
-
|
31
|
+
createVercelPreset: () => createVercelPreset
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(vercel_exports);
|
34
34
|
var import_node_path = __toESM(require("node:path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_routes = require("../../../utils/routes");
|
36
37
|
var import_utils2 = require("../utils");
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
38
|
+
var import_dependencies = require("../dependencies");
|
39
|
+
const createVercelPreset = (appContext, config, needModernServer) => {
|
40
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
41
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
42
|
+
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
43
|
+
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
44
|
+
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
45
|
+
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
46
|
+
return {
|
47
|
+
async prepare() {
|
48
|
+
await import_utils.fs.remove(vercelOutput);
|
42
49
|
},
|
43
|
-
|
44
|
-
|
50
|
+
async writeOutput() {
|
51
|
+
const config2 = {
|
52
|
+
version: 3,
|
53
|
+
routes: [
|
54
|
+
{
|
55
|
+
src: "/static/(.*)",
|
56
|
+
headers: {
|
57
|
+
"cache-control": "s-maxage=31536000, immutable"
|
58
|
+
},
|
59
|
+
continue: true
|
60
|
+
},
|
61
|
+
{
|
62
|
+
handle: "filesystem"
|
63
|
+
}
|
64
|
+
]
|
65
|
+
};
|
66
|
+
if (!needModernServer) {
|
67
|
+
const { source: { mainEntryName } } = config2;
|
68
|
+
entrypoints.forEach((entry) => {
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
70
|
+
config2.routes.push({
|
71
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
72
|
+
headers: {
|
73
|
+
"cache-control": "s-maxage=0"
|
74
|
+
},
|
75
|
+
dest: `/html/${entry.entryName}/index.html`
|
76
|
+
});
|
77
|
+
});
|
78
|
+
} else {
|
79
|
+
config2.routes.push({
|
80
|
+
src: "/(.*)",
|
81
|
+
dest: `/index`
|
82
|
+
});
|
83
|
+
}
|
84
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
85
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(outputDirectory, "config.json"), config2, {
|
86
|
+
spaces: 2
|
87
|
+
});
|
88
|
+
const staticDirectory = import_node_path.default.join(outputDirectory, "static/static");
|
89
|
+
await import_utils.fs.copy(import_node_path.default.join(distDirectory, "static"), staticDirectory);
|
90
|
+
if (!needModernServer) {
|
91
|
+
const destHtmlDirectory = import_node_path.default.join(distDirectory, "html");
|
92
|
+
const outputHtmlDirectory = import_node_path.default.join(import_node_path.default.join(outputDirectory, "static"), "html");
|
93
|
+
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
94
|
+
} else {
|
95
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
96
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
97
|
+
filter: (src) => {
|
98
|
+
const distStaticDirectory = import_node_path.default.join(distDirectory, "static");
|
99
|
+
return !src.includes(distStaticDirectory);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(funcsDirectory, ".vc-config.json"), {
|
103
|
+
runtime: "nodejs16.x",
|
104
|
+
handler: "index.js",
|
105
|
+
launcherType: "Nodejs",
|
106
|
+
shouldAddHelpers: false,
|
107
|
+
supportsResponseStreaming: true
|
108
|
+
});
|
109
|
+
}
|
110
|
+
},
|
111
|
+
async genEntry() {
|
112
|
+
var _config_bff;
|
113
|
+
if (!needModernServer) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
const serverConfig = {
|
117
|
+
bff: {
|
118
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
119
|
+
},
|
120
|
+
output: {
|
121
|
+
path: "."
|
122
|
+
}
|
123
|
+
};
|
124
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
125
|
+
const dynamicProdOptions = {
|
126
|
+
config: serverConfig,
|
127
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
128
|
+
plugins
|
129
|
+
};
|
130
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
131
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
132
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
133
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
134
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
135
|
+
"@modern-js/prod-server"
|
136
|
+
]);
|
45
137
|
}
|
46
138
|
};
|
47
|
-
|
48
|
-
const dynamicProdOptions = {
|
49
|
-
config: serverConfig,
|
50
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
51
|
-
plugins
|
52
|
-
};
|
53
|
-
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
54
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
55
|
-
return entryCode;
|
56
|
-
}
|
139
|
+
};
|
57
140
|
// Annotate the CommonJS export names for ESM import in node:
|
58
141
|
0 && (module.exports = {
|
59
|
-
|
142
|
+
createVercelPreset
|
60
143
|
});
|
@@ -34,7 +34,7 @@ __export(utils_exports, {
|
|
34
34
|
getPluginsCode: () => getPluginsCode,
|
35
35
|
getProjectUsage: () => getProjectUsage,
|
36
36
|
linkPackage: () => linkPackage,
|
37
|
-
|
37
|
+
serverAppContenxtTemplate: () => serverAppContenxtTemplate,
|
38
38
|
writePackage: () => writePackage
|
39
39
|
});
|
40
40
|
module.exports = __toCommonJS(utils_exports);
|
@@ -42,12 +42,14 @@ var import_path = __toESM(require("path"));
|
|
42
42
|
var import_node_os = __toESM(require("node:os"));
|
43
43
|
var import_utils = require("@modern-js/utils");
|
44
44
|
var import_mlly = require("mlly");
|
45
|
-
const
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
const serverAppContenxtTemplate = (appContext) => {
|
46
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
47
|
+
return {
|
48
|
+
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
49
|
+
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
50
|
+
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
51
|
+
metaName
|
52
|
+
};
|
51
53
|
};
|
52
54
|
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
53
55
|
const genPluginImportsCode = (plugins) => {
|
@@ -145,6 +147,6 @@ const linkPackage = async (from, to, projectRootDir) => {
|
|
145
147
|
getPluginsCode,
|
146
148
|
getProjectUsage,
|
147
149
|
linkPackage,
|
148
|
-
|
150
|
+
serverAppContenxtTemplate,
|
149
151
|
writePackage
|
150
152
|
});
|
@@ -0,0 +1,367 @@
|
|
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 as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { provider } from "std-env";
|
6
|
+
import { isMainEntry } from "../../utils/routes";
|
7
|
+
import { getProjectUsage } from "./utils";
|
8
|
+
import { handleDependencies } from "./dependencies";
|
9
|
+
function index_copy_default() {
|
10
|
+
return {
|
11
|
+
name: "@modern-js/plugin-deploy",
|
12
|
+
pre: [
|
13
|
+
"@modern-js/plugin-bff",
|
14
|
+
"@modern-js/plugin-server"
|
15
|
+
],
|
16
|
+
setup: function(api) {
|
17
|
+
var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
18
|
+
return {
|
19
|
+
beforeDeploy: function beforeDeploy() {
|
20
|
+
return _async_to_generator(function() {
|
21
|
+
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
22
|
+
return _ts_generator(this, function(_state) {
|
23
|
+
switch (_state.label) {
|
24
|
+
case 0:
|
25
|
+
appContext = api.useAppContext();
|
26
|
+
modernConfig = api.useResolvedConfigContext();
|
27
|
+
mainEntryName = modernConfig.source.mainEntryName;
|
28
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
29
|
+
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
30
|
+
needModernServer = useSSR || useAPI || useWebServer;
|
31
|
+
outputDirectory = path.join(appDirectory, ".output");
|
32
|
+
funcsDirectory = outputDirectory;
|
33
|
+
staticDirectory = path.join(outputDirectory, "static");
|
34
|
+
if (!(deployTarget === "node"))
|
35
|
+
return [
|
36
|
+
3,
|
37
|
+
3
|
38
|
+
];
|
39
|
+
return [
|
40
|
+
4,
|
41
|
+
fse.remove(outputDirectory)
|
42
|
+
];
|
43
|
+
case 1:
|
44
|
+
_state.sent();
|
45
|
+
return [
|
46
|
+
4,
|
47
|
+
fse.copy(distDirectory, outputDirectory)
|
48
|
+
];
|
49
|
+
case 2:
|
50
|
+
_state.sent();
|
51
|
+
_state.label = 3;
|
52
|
+
case 3:
|
53
|
+
if (!(deployTarget === "netlify"))
|
54
|
+
return [
|
55
|
+
3,
|
56
|
+
8
|
57
|
+
];
|
58
|
+
netlifyOutput = path.join(appDirectory, ".netlify");
|
59
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
60
|
+
routes = [];
|
61
|
+
if (!needModernServer) {
|
62
|
+
entrypoints.forEach(function(entry) {
|
63
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
64
|
+
routes.push({
|
65
|
+
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
66
|
+
dest: "/html/".concat(entry.entryName, "/index.html"),
|
67
|
+
status: 200
|
68
|
+
});
|
69
|
+
});
|
70
|
+
} else {
|
71
|
+
routes.push({
|
72
|
+
src: "/*",
|
73
|
+
dest: "/.netlify/functions/index",
|
74
|
+
status: 200
|
75
|
+
});
|
76
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supported, Support for SSR and BFF projects will be available later");
|
77
|
+
}
|
78
|
+
console.log("routes", routes, needModernServer);
|
79
|
+
redirectContent = routes.map(function(route) {
|
80
|
+
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
81
|
+
}).join("\n");
|
82
|
+
console.log("redirectContent", redirectContent);
|
83
|
+
return [
|
84
|
+
4,
|
85
|
+
fse.remove(outputDirectory)
|
86
|
+
];
|
87
|
+
case 4:
|
88
|
+
_state.sent();
|
89
|
+
return [
|
90
|
+
4,
|
91
|
+
fse.ensureDir(funcsDirectory)
|
92
|
+
];
|
93
|
+
case 5:
|
94
|
+
_state.sent();
|
95
|
+
return [
|
96
|
+
4,
|
97
|
+
fse.copy(distDirectory, funcsDirectory, {
|
98
|
+
filter: function(src) {
|
99
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
100
|
+
return !src.includes(distStaticDirectory);
|
101
|
+
}
|
102
|
+
})
|
103
|
+
];
|
104
|
+
case 6:
|
105
|
+
_state.sent();
|
106
|
+
redirectFilePath = path.join(distDirectory, "_redirects");
|
107
|
+
return [
|
108
|
+
4,
|
109
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
110
|
+
];
|
111
|
+
case 7:
|
112
|
+
_state.sent();
|
113
|
+
_state.label = 8;
|
114
|
+
case 8:
|
115
|
+
if (!(deployTarget === "vercel"))
|
116
|
+
return [
|
117
|
+
3,
|
118
|
+
18
|
119
|
+
];
|
120
|
+
vercelOutput = path.join(appDirectory, ".vercel");
|
121
|
+
return [
|
122
|
+
4,
|
123
|
+
fse.remove(vercelOutput)
|
124
|
+
];
|
125
|
+
case 9:
|
126
|
+
_state.sent();
|
127
|
+
outputDirectory = path.join(vercelOutput, "output");
|
128
|
+
config = {
|
129
|
+
version: 3,
|
130
|
+
routes: [
|
131
|
+
{
|
132
|
+
src: "/static/(.*)",
|
133
|
+
headers: {
|
134
|
+
"cache-control": "s-maxage=31536000, immutable"
|
135
|
+
},
|
136
|
+
continue: true
|
137
|
+
},
|
138
|
+
{
|
139
|
+
handle: "filesystem"
|
140
|
+
}
|
141
|
+
]
|
142
|
+
};
|
143
|
+
if (!needModernServer) {
|
144
|
+
entrypoints.forEach(function(entry) {
|
145
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
146
|
+
config.routes.push({
|
147
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
148
|
+
headers: {
|
149
|
+
"cache-control": "s-maxage=0"
|
150
|
+
},
|
151
|
+
dest: "/html/".concat(entry.entryName, "/index.html")
|
152
|
+
});
|
153
|
+
});
|
154
|
+
} else {
|
155
|
+
config.routes.push({
|
156
|
+
src: "/(.*)",
|
157
|
+
dest: "/index"
|
158
|
+
});
|
159
|
+
}
|
160
|
+
return [
|
161
|
+
4,
|
162
|
+
fse.ensureDir(outputDirectory)
|
163
|
+
];
|
164
|
+
case 10:
|
165
|
+
_state.sent();
|
166
|
+
return [
|
167
|
+
4,
|
168
|
+
fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
169
|
+
spaces: 2
|
170
|
+
})
|
171
|
+
];
|
172
|
+
case 11:
|
173
|
+
_state.sent();
|
174
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
175
|
+
return [
|
176
|
+
4,
|
177
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
178
|
+
];
|
179
|
+
case 12:
|
180
|
+
_state.sent();
|
181
|
+
if (!!needModernServer)
|
182
|
+
return [
|
183
|
+
3,
|
184
|
+
14
|
185
|
+
];
|
186
|
+
destHtmlDirectory = path.join(distDirectory, "html");
|
187
|
+
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
188
|
+
return [
|
189
|
+
4,
|
190
|
+
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
191
|
+
];
|
192
|
+
case 13:
|
193
|
+
_state.sent();
|
194
|
+
return [
|
195
|
+
3,
|
196
|
+
18
|
197
|
+
];
|
198
|
+
case 14:
|
199
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
200
|
+
return [
|
201
|
+
4,
|
202
|
+
fse.ensureDir(funcsDirectory)
|
203
|
+
];
|
204
|
+
case 15:
|
205
|
+
_state.sent();
|
206
|
+
return [
|
207
|
+
4,
|
208
|
+
fse.copy(distDirectory, funcsDirectory, {
|
209
|
+
filter: function(src) {
|
210
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
211
|
+
return !src.includes(distStaticDirectory);
|
212
|
+
}
|
213
|
+
})
|
214
|
+
];
|
215
|
+
case 16:
|
216
|
+
_state.sent();
|
217
|
+
return [
|
218
|
+
4,
|
219
|
+
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
220
|
+
runtime: "nodejs16.x",
|
221
|
+
handler: "index.js",
|
222
|
+
launcherType: "Nodejs",
|
223
|
+
shouldAddHelpers: false,
|
224
|
+
supportsResponseStreaming: true
|
225
|
+
})
|
226
|
+
];
|
227
|
+
case 17:
|
228
|
+
_state.sent();
|
229
|
+
_state.label = 18;
|
230
|
+
case 18:
|
231
|
+
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
232
|
+
serverAppContext = {
|
233
|
+
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
234
|
+
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
235
|
+
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
236
|
+
metaName
|
237
|
+
};
|
238
|
+
console.log("serverAppContext", serverAppContext);
|
239
|
+
code = "";
|
240
|
+
console.log("deployTarget111111111", deployTarget);
|
241
|
+
switch (deployTarget) {
|
242
|
+
case "node":
|
243
|
+
return [
|
244
|
+
3,
|
245
|
+
19
|
246
|
+
];
|
247
|
+
case "vercel":
|
248
|
+
return [
|
249
|
+
3,
|
250
|
+
22
|
251
|
+
];
|
252
|
+
case "netlify":
|
253
|
+
return [
|
254
|
+
3,
|
255
|
+
25
|
256
|
+
];
|
257
|
+
}
|
258
|
+
return [
|
259
|
+
3,
|
260
|
+
28
|
261
|
+
];
|
262
|
+
case 19:
|
263
|
+
return [
|
264
|
+
4,
|
265
|
+
import("./platforms/node")
|
266
|
+
];
|
267
|
+
case 20:
|
268
|
+
genNodeEntry = _state.sent().genNodeEntry;
|
269
|
+
return [
|
270
|
+
4,
|
271
|
+
genNodeEntry({
|
272
|
+
plugins,
|
273
|
+
config: modernConfig,
|
274
|
+
appContext: serverAppContext
|
275
|
+
})
|
276
|
+
];
|
277
|
+
case 21:
|
278
|
+
code = _state.sent();
|
279
|
+
return [
|
280
|
+
3,
|
281
|
+
29
|
282
|
+
];
|
283
|
+
case 22:
|
284
|
+
return [
|
285
|
+
4,
|
286
|
+
import("./platforms/vercel")
|
287
|
+
];
|
288
|
+
case 23:
|
289
|
+
genVercelEntry = _state.sent().genVercelEntry;
|
290
|
+
return [
|
291
|
+
4,
|
292
|
+
genVercelEntry({
|
293
|
+
plugins,
|
294
|
+
config: modernConfig,
|
295
|
+
appContext: serverAppContext
|
296
|
+
})
|
297
|
+
];
|
298
|
+
case 24:
|
299
|
+
code = _state.sent();
|
300
|
+
return [
|
301
|
+
3,
|
302
|
+
29
|
303
|
+
];
|
304
|
+
case 25:
|
305
|
+
return [
|
306
|
+
4,
|
307
|
+
import("./platforms/netlify")
|
308
|
+
];
|
309
|
+
case 26:
|
310
|
+
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
311
|
+
return [
|
312
|
+
4,
|
313
|
+
genNetlifyEntry({
|
314
|
+
plugins,
|
315
|
+
config: modernConfig,
|
316
|
+
appContext: serverAppContext
|
317
|
+
})
|
318
|
+
];
|
319
|
+
case 27:
|
320
|
+
code = _state.sent();
|
321
|
+
return [
|
322
|
+
3,
|
323
|
+
29
|
324
|
+
];
|
325
|
+
case 28:
|
326
|
+
{
|
327
|
+
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
328
|
+
}
|
329
|
+
_state.label = 29;
|
330
|
+
case 29:
|
331
|
+
entryFilePath = path.join(funcsDirectory, "index.js");
|
332
|
+
if (!needModernServer)
|
333
|
+
return [
|
334
|
+
3,
|
335
|
+
32
|
336
|
+
];
|
337
|
+
return [
|
338
|
+
4,
|
339
|
+
fse.writeFile(entryFilePath, code)
|
340
|
+
];
|
341
|
+
case 30:
|
342
|
+
_state.sent();
|
343
|
+
return [
|
344
|
+
4,
|
345
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
346
|
+
"@modern-js/prod-server"
|
347
|
+
])
|
348
|
+
];
|
349
|
+
case 31:
|
350
|
+
_state.sent();
|
351
|
+
_state.label = 32;
|
352
|
+
case 32:
|
353
|
+
return [
|
354
|
+
2
|
355
|
+
];
|
356
|
+
}
|
357
|
+
});
|
358
|
+
})();
|
359
|
+
}
|
360
|
+
};
|
361
|
+
}
|
362
|
+
};
|
363
|
+
}
|
364
|
+
;
|
365
|
+
export {
|
366
|
+
index_copy_default as default
|
367
|
+
};
|