@modern-js/app-tools 2.50.0 → 2.51.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/commands/deploy.js +1 -0
- package/dist/cjs/hooks.js +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +217 -0
- package/dist/cjs/plugins/deploy/dependencies/utils.js +165 -0
- package/dist/cjs/plugins/deploy/index.js +64 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +136 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +44 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +148 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +81 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/commands/deploy.js +7 -1
- package/dist/esm/hooks.js +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +580 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +407 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +291 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +124 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +107 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +225 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/commands/deploy.js +1 -0
- package/dist/esm-node/hooks.js +1 -0
- package/dist/esm-node/index.js +3 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +183 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +124 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +102 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +43 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +114 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -0
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +31 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +20 -0
- package/dist/types/types/hooks.d.ts +1 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +26 -22
@@ -0,0 +1,291 @@
|
|
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 "node:path";
|
4
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { isMainEntry } from "../../../utils/routes";
|
6
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
7
|
+
import { handleDependencies } from "../dependencies";
|
8
|
+
function cleanDistDirectory(dir) {
|
9
|
+
return _cleanDistDirectory.apply(this, arguments);
|
10
|
+
}
|
11
|
+
function _cleanDistDirectory() {
|
12
|
+
_cleanDistDirectory = _async_to_generator(function(dir) {
|
13
|
+
var items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, fullPath, err, error;
|
14
|
+
return _ts_generator(this, function(_state) {
|
15
|
+
switch (_state.label) {
|
16
|
+
case 0:
|
17
|
+
_state.trys.push([
|
18
|
+
0,
|
19
|
+
10,
|
20
|
+
,
|
21
|
+
11
|
22
|
+
]);
|
23
|
+
return [
|
24
|
+
4,
|
25
|
+
fse.readdir(dir)
|
26
|
+
];
|
27
|
+
case 1:
|
28
|
+
items = _state.sent();
|
29
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
30
|
+
_state.label = 2;
|
31
|
+
case 2:
|
32
|
+
_state.trys.push([
|
33
|
+
2,
|
34
|
+
7,
|
35
|
+
8,
|
36
|
+
9
|
37
|
+
]);
|
38
|
+
_iterator = items[Symbol.iterator]();
|
39
|
+
_state.label = 3;
|
40
|
+
case 3:
|
41
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
42
|
+
return [
|
43
|
+
3,
|
44
|
+
6
|
45
|
+
];
|
46
|
+
item = _step.value;
|
47
|
+
fullPath = path.join(dir, item);
|
48
|
+
if (!(item !== "static" && item !== "_redirects"))
|
49
|
+
return [
|
50
|
+
3,
|
51
|
+
5
|
52
|
+
];
|
53
|
+
return [
|
54
|
+
4,
|
55
|
+
fse.remove(fullPath)
|
56
|
+
];
|
57
|
+
case 4:
|
58
|
+
_state.sent();
|
59
|
+
_state.label = 5;
|
60
|
+
case 5:
|
61
|
+
_iteratorNormalCompletion = true;
|
62
|
+
return [
|
63
|
+
3,
|
64
|
+
3
|
65
|
+
];
|
66
|
+
case 6:
|
67
|
+
return [
|
68
|
+
3,
|
69
|
+
9
|
70
|
+
];
|
71
|
+
case 7:
|
72
|
+
err = _state.sent();
|
73
|
+
_didIteratorError = true;
|
74
|
+
_iteratorError = err;
|
75
|
+
return [
|
76
|
+
3,
|
77
|
+
9
|
78
|
+
];
|
79
|
+
case 8:
|
80
|
+
try {
|
81
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
82
|
+
_iterator.return();
|
83
|
+
}
|
84
|
+
} finally {
|
85
|
+
if (_didIteratorError) {
|
86
|
+
throw _iteratorError;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return [
|
90
|
+
7
|
91
|
+
];
|
92
|
+
case 9:
|
93
|
+
return [
|
94
|
+
3,
|
95
|
+
11
|
96
|
+
];
|
97
|
+
case 10:
|
98
|
+
error = _state.sent();
|
99
|
+
console.error("Error cleaning directory:", error);
|
100
|
+
return [
|
101
|
+
3,
|
102
|
+
11
|
103
|
+
];
|
104
|
+
case 11:
|
105
|
+
return [
|
106
|
+
2
|
107
|
+
];
|
108
|
+
}
|
109
|
+
});
|
110
|
+
});
|
111
|
+
return _cleanDistDirectory.apply(this, arguments);
|
112
|
+
}
|
113
|
+
var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
114
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
|
115
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
116
|
+
var netlifyOutput = path.join(appDirectory, ".netlify");
|
117
|
+
var funcsDirectory = path.join(netlifyOutput, "functions");
|
118
|
+
var entryFilePath = path.join(funcsDirectory, "index.js");
|
119
|
+
return {
|
120
|
+
prepare: function prepare() {
|
121
|
+
return _async_to_generator(function() {
|
122
|
+
return _ts_generator(this, function(_state) {
|
123
|
+
switch (_state.label) {
|
124
|
+
case 0:
|
125
|
+
return [
|
126
|
+
4,
|
127
|
+
fse.remove(netlifyOutput)
|
128
|
+
];
|
129
|
+
case 1:
|
130
|
+
_state.sent();
|
131
|
+
return [
|
132
|
+
2
|
133
|
+
];
|
134
|
+
}
|
135
|
+
});
|
136
|
+
})();
|
137
|
+
},
|
138
|
+
writeOutput: function writeOutput() {
|
139
|
+
return _async_to_generator(function() {
|
140
|
+
var routes, mainEntryName, redirectContent, redirectFilePath;
|
141
|
+
return _ts_generator(this, function(_state) {
|
142
|
+
switch (_state.label) {
|
143
|
+
case 0:
|
144
|
+
routes = [];
|
145
|
+
mainEntryName = modernConfig.source.mainEntryName;
|
146
|
+
if (!needModernServer) {
|
147
|
+
entrypoints.forEach(function(entry) {
|
148
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
149
|
+
routes.push({
|
150
|
+
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
151
|
+
dest: "/html/".concat(entry.entryName, "/index.html"),
|
152
|
+
status: 200
|
153
|
+
});
|
154
|
+
});
|
155
|
+
} else {
|
156
|
+
routes.push({
|
157
|
+
src: "/*",
|
158
|
+
dest: "/.netlify/functions/index",
|
159
|
+
status: 200
|
160
|
+
});
|
161
|
+
}
|
162
|
+
redirectContent = routes.map(function(route) {
|
163
|
+
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
164
|
+
}).join("\n");
|
165
|
+
if (!needModernServer)
|
166
|
+
return [
|
167
|
+
3,
|
168
|
+
3
|
169
|
+
];
|
170
|
+
return [
|
171
|
+
4,
|
172
|
+
fse.ensureDir(funcsDirectory)
|
173
|
+
];
|
174
|
+
case 1:
|
175
|
+
_state.sent();
|
176
|
+
return [
|
177
|
+
4,
|
178
|
+
fse.copy(distDirectory, funcsDirectory, {
|
179
|
+
filter: function(src) {
|
180
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
181
|
+
return !src.includes(distStaticDirectory);
|
182
|
+
}
|
183
|
+
})
|
184
|
+
];
|
185
|
+
case 2:
|
186
|
+
_state.sent();
|
187
|
+
_state.label = 3;
|
188
|
+
case 3:
|
189
|
+
redirectFilePath = path.join(distDirectory, "_redirects");
|
190
|
+
return [
|
191
|
+
4,
|
192
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
193
|
+
];
|
194
|
+
case 4:
|
195
|
+
_state.sent();
|
196
|
+
return [
|
197
|
+
2
|
198
|
+
];
|
199
|
+
}
|
200
|
+
});
|
201
|
+
})();
|
202
|
+
},
|
203
|
+
genEntry: function genEntry() {
|
204
|
+
return _async_to_generator(function() {
|
205
|
+
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
206
|
+
return _ts_generator(this, function(_state) {
|
207
|
+
switch (_state.label) {
|
208
|
+
case 0:
|
209
|
+
if (!needModernServer) {
|
210
|
+
return [
|
211
|
+
2
|
212
|
+
];
|
213
|
+
}
|
214
|
+
serverConfig = {
|
215
|
+
bff: {
|
216
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
217
|
+
},
|
218
|
+
output: {
|
219
|
+
path: "."
|
220
|
+
}
|
221
|
+
};
|
222
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
223
|
+
dynamicProdOptions = {
|
224
|
+
config: serverConfig,
|
225
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
226
|
+
plugins
|
227
|
+
};
|
228
|
+
return [
|
229
|
+
4,
|
230
|
+
fse.readFile(path.join(__dirname, "./netlifyEntry.js"))
|
231
|
+
];
|
232
|
+
case 1:
|
233
|
+
entryCode = _state.sent().toString();
|
234
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
235
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
236
|
+
return [
|
237
|
+
4,
|
238
|
+
fse.writeFile(entryFilePath, entryCode)
|
239
|
+
];
|
240
|
+
case 2:
|
241
|
+
_state.sent();
|
242
|
+
return [
|
243
|
+
2
|
244
|
+
];
|
245
|
+
}
|
246
|
+
});
|
247
|
+
})();
|
248
|
+
},
|
249
|
+
end: function end() {
|
250
|
+
return _async_to_generator(function() {
|
251
|
+
return _ts_generator(this, function(_state) {
|
252
|
+
switch (_state.label) {
|
253
|
+
case 0:
|
254
|
+
if (!(process.env.NODE_ENV !== "test" && process.env.NODE_ENV !== "development"))
|
255
|
+
return [
|
256
|
+
3,
|
257
|
+
2
|
258
|
+
];
|
259
|
+
return [
|
260
|
+
4,
|
261
|
+
cleanDistDirectory(distDirectory)
|
262
|
+
];
|
263
|
+
case 1:
|
264
|
+
_state.sent();
|
265
|
+
_state.label = 2;
|
266
|
+
case 2:
|
267
|
+
if (!needModernServer) {
|
268
|
+
return [
|
269
|
+
2
|
270
|
+
];
|
271
|
+
}
|
272
|
+
return [
|
273
|
+
4,
|
274
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
275
|
+
"@modern-js/prod-server"
|
276
|
+
])
|
277
|
+
];
|
278
|
+
case 3:
|
279
|
+
_state.sent();
|
280
|
+
return [
|
281
|
+
2
|
282
|
+
];
|
283
|
+
}
|
284
|
+
});
|
285
|
+
})();
|
286
|
+
}
|
287
|
+
};
|
288
|
+
};
|
289
|
+
export {
|
290
|
+
createNetlifyPreset
|
291
|
+
};
|
@@ -0,0 +1,202 @@
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
4
|
+
};
|
5
|
+
var require_netlifyEntry = __commonJS({
|
6
|
+
"src/plugins/deploy/platforms/netlifyEntry.js"(exports, module) {
|
7
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
8
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
9
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
10
|
+
var fs = require("node:fs/promises");
|
11
|
+
var path = require("node:path");
|
12
|
+
var createNetlifyFunction = require("@modern-js/prod-server/netlify").createNetlifyFunction;
|
13
|
+
p_genPluginImportsCode;
|
14
|
+
if (!process.env.NODE_ENV) {
|
15
|
+
process.env.NODE_ENV = "production";
|
16
|
+
}
|
17
|
+
var requestHandler = null;
|
18
|
+
var handlerCreationPromise = null;
|
19
|
+
function loadRoutes(routeFilepath) {
|
20
|
+
return _loadRoutes.apply(this, arguments);
|
21
|
+
}
|
22
|
+
function _loadRoutes() {
|
23
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
24
|
+
var content, routeSpec, error;
|
25
|
+
return _ts_generator._(this, function(_state) {
|
26
|
+
switch (_state.label) {
|
27
|
+
case 0:
|
28
|
+
_state.trys.push([
|
29
|
+
0,
|
30
|
+
3,
|
31
|
+
,
|
32
|
+
4
|
33
|
+
]);
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
fs.access(routeFilepath)
|
37
|
+
];
|
38
|
+
case 1:
|
39
|
+
_state.sent();
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
fs.readFile(routeFilepath, "utf-8")
|
43
|
+
];
|
44
|
+
case 2:
|
45
|
+
content = _state.sent();
|
46
|
+
routeSpec = JSON.parse(content);
|
47
|
+
return [
|
48
|
+
2,
|
49
|
+
routeSpec.routes || []
|
50
|
+
];
|
51
|
+
case 3:
|
52
|
+
error = _state.sent();
|
53
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
54
|
+
return [
|
55
|
+
2,
|
56
|
+
[]
|
57
|
+
];
|
58
|
+
case 4:
|
59
|
+
return [
|
60
|
+
2
|
61
|
+
];
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
return _loadRoutes.apply(this, arguments);
|
66
|
+
}
|
67
|
+
function initServer() {
|
68
|
+
return _initServer.apply(this, arguments);
|
69
|
+
}
|
70
|
+
function _initServer() {
|
71
|
+
_initServer = _async_to_generator._(function() {
|
72
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, requestHandler2;
|
73
|
+
return _ts_generator._(this, function(_state) {
|
74
|
+
switch (_state.label) {
|
75
|
+
case 0:
|
76
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
77
|
+
return [
|
78
|
+
4,
|
79
|
+
loadRoutes(routeFilepath)
|
80
|
+
];
|
81
|
+
case 1:
|
82
|
+
routes = _state.sent();
|
83
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
84
|
+
prodServerOptions = _object_spread._({
|
85
|
+
pwd: __dirname,
|
86
|
+
routes,
|
87
|
+
disableCustomHook: true,
|
88
|
+
appContext: {
|
89
|
+
sharedDirectory: p_sharedDirectory,
|
90
|
+
apiDirectory: p_apiDirectory,
|
91
|
+
lambdaDirectory: p_lambdaDirectory
|
92
|
+
}
|
93
|
+
}, dynamicProdOptions);
|
94
|
+
return [
|
95
|
+
4,
|
96
|
+
createNetlifyFunction(prodServerOptions)
|
97
|
+
];
|
98
|
+
case 2:
|
99
|
+
requestHandler2 = _state.sent();
|
100
|
+
return [
|
101
|
+
2,
|
102
|
+
requestHandler2
|
103
|
+
];
|
104
|
+
}
|
105
|
+
});
|
106
|
+
});
|
107
|
+
return _initServer.apply(this, arguments);
|
108
|
+
}
|
109
|
+
function createHandler() {
|
110
|
+
return _createHandler.apply(this, arguments);
|
111
|
+
}
|
112
|
+
function _createHandler() {
|
113
|
+
_createHandler = _async_to_generator._(function() {
|
114
|
+
return _ts_generator._(this, function(_state) {
|
115
|
+
switch (_state.label) {
|
116
|
+
case 0:
|
117
|
+
if (!handlerCreationPromise) {
|
118
|
+
handlerCreationPromise = _async_to_generator._(function() {
|
119
|
+
var error;
|
120
|
+
return _ts_generator._(this, function(_state2) {
|
121
|
+
switch (_state2.label) {
|
122
|
+
case 0:
|
123
|
+
_state2.trys.push([
|
124
|
+
0,
|
125
|
+
2,
|
126
|
+
,
|
127
|
+
3
|
128
|
+
]);
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
initServer()
|
132
|
+
];
|
133
|
+
case 1:
|
134
|
+
requestHandler = _state2.sent();
|
135
|
+
return [
|
136
|
+
3,
|
137
|
+
3
|
138
|
+
];
|
139
|
+
case 2:
|
140
|
+
error = _state2.sent();
|
141
|
+
console.error("Error creating server:", error);
|
142
|
+
process.exit(1);
|
143
|
+
return [
|
144
|
+
3,
|
145
|
+
3
|
146
|
+
];
|
147
|
+
case 3:
|
148
|
+
return [
|
149
|
+
2
|
150
|
+
];
|
151
|
+
}
|
152
|
+
});
|
153
|
+
})();
|
154
|
+
}
|
155
|
+
return [
|
156
|
+
4,
|
157
|
+
handlerCreationPromise
|
158
|
+
];
|
159
|
+
case 1:
|
160
|
+
_state.sent();
|
161
|
+
return [
|
162
|
+
2,
|
163
|
+
requestHandler
|
164
|
+
];
|
165
|
+
}
|
166
|
+
});
|
167
|
+
});
|
168
|
+
return _createHandler.apply(this, arguments);
|
169
|
+
}
|
170
|
+
createHandler();
|
171
|
+
module.exports.default = function() {
|
172
|
+
var _ref = _async_to_generator._(function(request, context) {
|
173
|
+
return _ts_generator._(this, function(_state) {
|
174
|
+
switch (_state.label) {
|
175
|
+
case 0:
|
176
|
+
if (!!requestHandler)
|
177
|
+
return [
|
178
|
+
3,
|
179
|
+
2
|
180
|
+
];
|
181
|
+
return [
|
182
|
+
4,
|
183
|
+
createHandler()
|
184
|
+
];
|
185
|
+
case 1:
|
186
|
+
_state.sent();
|
187
|
+
_state.label = 2;
|
188
|
+
case 2:
|
189
|
+
return [
|
190
|
+
2,
|
191
|
+
requestHandler(request, context)
|
192
|
+
];
|
193
|
+
}
|
194
|
+
});
|
195
|
+
});
|
196
|
+
return function(request, context) {
|
197
|
+
return _ref.apply(this, arguments);
|
198
|
+
};
|
199
|
+
}();
|
200
|
+
}
|
201
|
+
});
|
202
|
+
export default require_netlifyEntry();
|
@@ -0,0 +1,124 @@
|
|
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 "node:path";
|
4
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins, chalk } from "@modern-js/utils";
|
5
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
6
|
+
import { handleDependencies } from "../dependencies";
|
7
|
+
var createNodePreset = function(appContext, config) {
|
8
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins;
|
9
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
10
|
+
var outputDirectory = path.join(appDirectory, ".output");
|
11
|
+
var staticDirectory = path.join(outputDirectory, "static");
|
12
|
+
var entryFilePath = path.join(outputDirectory, "index.js");
|
13
|
+
return {
|
14
|
+
prepare: function prepare() {
|
15
|
+
return _async_to_generator(function() {
|
16
|
+
return _ts_generator(this, function(_state) {
|
17
|
+
switch (_state.label) {
|
18
|
+
case 0:
|
19
|
+
return [
|
20
|
+
4,
|
21
|
+
fse.remove(outputDirectory)
|
22
|
+
];
|
23
|
+
case 1:
|
24
|
+
_state.sent();
|
25
|
+
return [
|
26
|
+
2
|
27
|
+
];
|
28
|
+
}
|
29
|
+
});
|
30
|
+
})();
|
31
|
+
},
|
32
|
+
writeOutput: function writeOutput() {
|
33
|
+
return _async_to_generator(function() {
|
34
|
+
return _ts_generator(this, function(_state) {
|
35
|
+
switch (_state.label) {
|
36
|
+
case 0:
|
37
|
+
return [
|
38
|
+
4,
|
39
|
+
fse.copy(distDirectory, outputDirectory)
|
40
|
+
];
|
41
|
+
case 1:
|
42
|
+
_state.sent();
|
43
|
+
return [
|
44
|
+
2
|
45
|
+
];
|
46
|
+
}
|
47
|
+
});
|
48
|
+
})();
|
49
|
+
},
|
50
|
+
genEntry: function genEntry() {
|
51
|
+
return _async_to_generator(function() {
|
52
|
+
var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
53
|
+
return _ts_generator(this, function(_state) {
|
54
|
+
switch (_state.label) {
|
55
|
+
case 0:
|
56
|
+
serverConfig = {
|
57
|
+
server: {
|
58
|
+
port: 8080
|
59
|
+
},
|
60
|
+
bff: {
|
61
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
62
|
+
},
|
63
|
+
output: {
|
64
|
+
path: "."
|
65
|
+
}
|
66
|
+
};
|
67
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
68
|
+
dynamicProdOptions = {
|
69
|
+
config: serverConfig,
|
70
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
71
|
+
plugins
|
72
|
+
};
|
73
|
+
return [
|
74
|
+
4,
|
75
|
+
fse.readFile(path.join(__dirname, "./nodeEntry.js"))
|
76
|
+
];
|
77
|
+
case 1:
|
78
|
+
entryCode = _state.sent().toString();
|
79
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
80
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
81
|
+
return [
|
82
|
+
4,
|
83
|
+
fse.writeFile(entryFilePath, entryCode)
|
84
|
+
];
|
85
|
+
case 2:
|
86
|
+
_state.sent();
|
87
|
+
return [
|
88
|
+
2
|
89
|
+
];
|
90
|
+
}
|
91
|
+
});
|
92
|
+
})();
|
93
|
+
},
|
94
|
+
end: function end() {
|
95
|
+
return _async_to_generator(function() {
|
96
|
+
var filter;
|
97
|
+
return _ts_generator(this, function(_state) {
|
98
|
+
switch (_state.label) {
|
99
|
+
case 0:
|
100
|
+
console.log("Static directory:", chalk.blue(path.relative(appDirectory, staticDirectory)));
|
101
|
+
console.log("You can preview this build by", chalk.blue("node .output/index"));
|
102
|
+
filter = function(filePath) {
|
103
|
+
return !filePath.startsWith(staticDirectory);
|
104
|
+
};
|
105
|
+
return [
|
106
|
+
4,
|
107
|
+
handleDependencies(appDirectory, outputDirectory, [
|
108
|
+
"@modern-js/prod-server"
|
109
|
+
], filter)
|
110
|
+
];
|
111
|
+
case 1:
|
112
|
+
_state.sent();
|
113
|
+
return [
|
114
|
+
2
|
115
|
+
];
|
116
|
+
}
|
117
|
+
});
|
118
|
+
})();
|
119
|
+
}
|
120
|
+
};
|
121
|
+
};
|
122
|
+
export {
|
123
|
+
createNodePreset
|
124
|
+
};
|