@modern-js/prod-server 2.48.0 → 2.48.1
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/libs/context/context.js +4 -8
- package/dist/cjs/libs/hook-api/base.js +0 -11
- package/dist/cjs/libs/hook-api/index.worker.js +0 -3
- package/dist/cjs/libs/hook-api/route.js +0 -4
- package/dist/cjs/libs/hook-api/template.js +0 -2
- package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -5
- package/dist/cjs/libs/render/ssrCache/manager.js +2 -3
- package/dist/cjs/libs/route/index.js +1 -3
- package/dist/cjs/libs/route/matcher.js +1 -5
- package/dist/cjs/libs/route/route.js +1 -10
- package/dist/cjs/libs/serverTiming.js +0 -3
- package/dist/cjs/renderHtml.js +0 -7
- package/dist/cjs/server/index.js +1 -7
- package/dist/cjs/server/modernServer.js +4 -20
- package/dist/cjs/workerServer.js +4 -8
- package/dist/esm/libs/context/context.js +66 -98
- package/dist/esm/libs/hook-api/base.js +36 -71
- package/dist/esm/libs/hook-api/index.worker.js +15 -29
- package/dist/esm/libs/hook-api/route.js +12 -27
- package/dist/esm/libs/hook-api/template.js +33 -61
- package/dist/esm/libs/render/ssrCache/cacheMod.js +10 -18
- package/dist/esm/libs/render/ssrCache/manager.js +145 -157
- package/dist/esm/libs/route/index.js +62 -96
- package/dist/esm/libs/route/matcher.js +58 -94
- package/dist/esm/libs/route/route.js +1 -10
- package/dist/esm/libs/serverTiming.js +8 -16
- package/dist/esm/renderHtml.js +22 -39
- package/dist/esm/server/index.js +307 -383
- package/dist/esm/server/modernServer.js +802 -942
- package/dist/esm/server/modernServerSplit.js +61 -86
- package/dist/esm/workerServer.js +87 -82
- package/dist/esm-node/libs/context/context.js +4 -8
- package/dist/esm-node/libs/hook-api/base.js +0 -11
- package/dist/esm-node/libs/hook-api/index.worker.js +0 -3
- package/dist/esm-node/libs/hook-api/route.js +0 -4
- package/dist/esm-node/libs/hook-api/template.js +0 -2
- package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -5
- package/dist/esm-node/libs/render/ssrCache/manager.js +2 -3
- package/dist/esm-node/libs/route/index.js +1 -3
- package/dist/esm-node/libs/route/matcher.js +1 -5
- package/dist/esm-node/libs/route/route.js +1 -10
- package/dist/esm-node/libs/serverTiming.js +0 -3
- package/dist/esm-node/renderHtml.js +0 -7
- package/dist/esm-node/server/index.js +1 -7
- package/dist/esm-node/server/modernServer.js +4 -20
- package/dist/esm-node/workerServer.js +4 -8
- package/package.json +8 -8
package/dist/esm/server/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
4
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
5
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
6
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
7
5
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
@@ -17,12 +15,7 @@ var Server = /* @__PURE__ */ function() {
|
|
|
17
15
|
"use strict";
|
|
18
16
|
function Server2(options) {
|
|
19
17
|
_class_call_check(this, Server2);
|
|
20
|
-
|
|
21
|
-
_define_property(this, "serverImpl", createProdServer);
|
|
22
|
-
_define_property(this, "server", void 0);
|
|
23
|
-
_define_property(this, "app", void 0);
|
|
24
|
-
_define_property(this, "runner", void 0);
|
|
25
|
-
_define_property(this, "serverConfig", void 0);
|
|
18
|
+
this.serverImpl = createProdServer;
|
|
26
19
|
options.logger = options.logger || createLogger({
|
|
27
20
|
level: "warn"
|
|
28
21
|
});
|
|
@@ -30,395 +23,326 @@ var Server = /* @__PURE__ */ function() {
|
|
|
30
23
|
this.options = options;
|
|
31
24
|
this.serverConfig = {};
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* - 获取最终的配置
|
|
46
|
-
* - 设置配置到 context
|
|
47
|
-
* - 初始化 server
|
|
48
|
-
* - 执行 prepare hook
|
|
49
|
-
* - 执行 server init
|
|
50
|
-
*/
|
|
51
|
-
function init() {
|
|
52
|
-
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
53
|
-
disableHttpServer: false
|
|
54
|
-
}, _ref_disableHttpServer = _ref.disableHttpServer, disableHttpServer = _ref_disableHttpServer === void 0 ? false : _ref_disableHttpServer;
|
|
55
|
-
var _this = this;
|
|
56
|
-
return _async_to_generator(function() {
|
|
57
|
-
var options, result, ref, ref1, result1, ref2, ref3;
|
|
58
|
-
return _ts_generator(this, function(_state) {
|
|
59
|
-
switch (_state.label) {
|
|
60
|
-
case 0:
|
|
61
|
-
options = _this.options;
|
|
62
|
-
return [
|
|
63
|
-
4,
|
|
64
|
-
_this.loadServerEnv(options)
|
|
65
|
-
];
|
|
66
|
-
case 1:
|
|
67
|
-
_state.sent();
|
|
68
|
-
_this.initServerConfig(options);
|
|
69
|
-
return [
|
|
70
|
-
4,
|
|
71
|
-
_this.injectContext(_this.runner, options)
|
|
72
|
-
];
|
|
73
|
-
case 2:
|
|
74
|
-
_state.sent();
|
|
75
|
-
return [
|
|
76
|
-
4,
|
|
77
|
-
_this.createHookRunner()
|
|
78
|
-
];
|
|
79
|
-
case 3:
|
|
80
|
-
_this.runner = _state.sent();
|
|
81
|
-
return [
|
|
82
|
-
4,
|
|
83
|
-
_this.initConfig(_this.runner, options)
|
|
84
|
-
];
|
|
85
|
-
case 4:
|
|
86
|
-
_state.sent();
|
|
87
|
-
return [
|
|
88
|
-
4,
|
|
89
|
-
_this.injectContext(_this.runner, options)
|
|
90
|
-
];
|
|
91
|
-
case 5:
|
|
92
|
-
_state.sent();
|
|
93
|
-
_this.server = _this.serverImpl(options);
|
|
94
|
-
return [
|
|
95
|
-
4,
|
|
96
|
-
_this.runPrepareHook(_this.runner)
|
|
97
|
-
];
|
|
98
|
-
case 6:
|
|
99
|
-
_state.sent();
|
|
100
|
-
if (!!disableHttpServer)
|
|
101
|
-
return [
|
|
102
|
-
3,
|
|
103
|
-
8
|
|
104
|
-
];
|
|
105
|
-
return [
|
|
106
|
-
4,
|
|
107
|
-
_this.server.createHTTPServer(_this.getRequestHandler())
|
|
108
|
-
];
|
|
109
|
-
case 7:
|
|
110
|
-
_this.app = _state.sent();
|
|
111
|
-
_state.label = 8;
|
|
112
|
-
case 8:
|
|
113
|
-
return [
|
|
114
|
-
4,
|
|
115
|
-
_this.runner.beforeServerInit({
|
|
116
|
-
app: _this.app,
|
|
117
|
-
server: _this.server
|
|
118
|
-
})
|
|
119
|
-
];
|
|
120
|
-
case 9:
|
|
121
|
-
result = _state.sent();
|
|
122
|
-
ref = result, ref1 = ref.app, _this.app = ref1 === void 0 ? _this.app : ref1, _this.server = ref.server, ref;
|
|
123
|
-
return [
|
|
124
|
-
4,
|
|
125
|
-
_this.server.onInit(_this.runner, _this.app)
|
|
126
|
-
];
|
|
127
|
-
case 10:
|
|
128
|
-
_state.sent();
|
|
129
|
-
return [
|
|
130
|
-
4,
|
|
131
|
-
_this.runner.afterServerInit({
|
|
132
|
-
app: _this.app,
|
|
133
|
-
server: _this.server
|
|
134
|
-
})
|
|
135
|
-
];
|
|
136
|
-
case 11:
|
|
137
|
-
result1 = _state.sent();
|
|
138
|
-
ref2 = result1, ref3 = ref2.app, _this.app = ref3 === void 0 ? _this.app : ref3, _this.server = ref2.server, ref2;
|
|
139
|
-
return [
|
|
140
|
-
2,
|
|
141
|
-
_this
|
|
142
|
-
];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
})();
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
key: "runConfigHook",
|
|
151
|
-
value: (
|
|
152
|
-
/**
|
|
153
|
-
* Execute config hooks
|
|
154
|
-
* @param runner
|
|
155
|
-
* @param options
|
|
156
|
-
*/
|
|
157
|
-
function runConfigHook(runner, serverConfig) {
|
|
158
|
-
var newServerConfig = runner.config(serverConfig || {});
|
|
159
|
-
return newServerConfig;
|
|
160
|
-
}
|
|
161
|
-
)
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
key: "runPrepareHook",
|
|
165
|
-
value: function runPrepareHook(runner) {
|
|
166
|
-
return _async_to_generator(function() {
|
|
167
|
-
return _ts_generator(this, function(_state) {
|
|
168
|
-
runner.prepare();
|
|
26
|
+
var _proto = Server2.prototype;
|
|
27
|
+
_proto.init = function init() {
|
|
28
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
29
|
+
disableHttpServer: false
|
|
30
|
+
}, _ref_disableHttpServer = _ref.disableHttpServer, disableHttpServer = _ref_disableHttpServer === void 0 ? false : _ref_disableHttpServer;
|
|
31
|
+
var _this = this;
|
|
32
|
+
return _async_to_generator(function() {
|
|
33
|
+
var options, result, ref, ref1, result1, ref2, ref3;
|
|
34
|
+
return _ts_generator(this, function(_state) {
|
|
35
|
+
switch (_state.label) {
|
|
36
|
+
case 0:
|
|
37
|
+
options = _this.options;
|
|
169
38
|
return [
|
|
170
|
-
|
|
39
|
+
4,
|
|
40
|
+
_this.loadServerEnv(options)
|
|
171
41
|
];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
42
|
+
case 1:
|
|
43
|
+
_state.sent();
|
|
44
|
+
_this.initServerConfig(options);
|
|
45
|
+
return [
|
|
46
|
+
4,
|
|
47
|
+
_this.injectContext(_this.runner, options)
|
|
48
|
+
];
|
|
49
|
+
case 2:
|
|
50
|
+
_state.sent();
|
|
51
|
+
return [
|
|
52
|
+
4,
|
|
53
|
+
_this.createHookRunner()
|
|
54
|
+
];
|
|
55
|
+
case 3:
|
|
56
|
+
_this.runner = _state.sent();
|
|
57
|
+
return [
|
|
58
|
+
4,
|
|
59
|
+
_this.initConfig(_this.runner, options)
|
|
60
|
+
];
|
|
61
|
+
case 4:
|
|
62
|
+
_state.sent();
|
|
63
|
+
return [
|
|
64
|
+
4,
|
|
65
|
+
_this.injectContext(_this.runner, options)
|
|
66
|
+
];
|
|
67
|
+
case 5:
|
|
68
|
+
_state.sent();
|
|
69
|
+
_this.server = _this.serverImpl(options);
|
|
70
|
+
return [
|
|
71
|
+
4,
|
|
72
|
+
_this.runPrepareHook(_this.runner)
|
|
73
|
+
];
|
|
74
|
+
case 6:
|
|
75
|
+
_state.sent();
|
|
76
|
+
if (!!disableHttpServer)
|
|
207
77
|
return [
|
|
208
|
-
|
|
78
|
+
3,
|
|
79
|
+
8
|
|
209
80
|
];
|
|
210
|
-
|
|
211
|
-
|
|
81
|
+
return [
|
|
82
|
+
4,
|
|
83
|
+
_this.server.createHTTPServer(_this.getRequestHandler())
|
|
84
|
+
];
|
|
85
|
+
case 7:
|
|
86
|
+
_this.app = _state.sent();
|
|
87
|
+
_state.label = 8;
|
|
88
|
+
case 8:
|
|
89
|
+
return [
|
|
90
|
+
4,
|
|
91
|
+
_this.runner.beforeServerInit({
|
|
92
|
+
app: _this.app,
|
|
93
|
+
server: _this.server
|
|
94
|
+
})
|
|
95
|
+
];
|
|
96
|
+
case 9:
|
|
97
|
+
result = _state.sent();
|
|
98
|
+
ref = result, ref1 = ref.app, _this.app = ref1 === void 0 ? _this.app : ref1, _this.server = ref.server, ref;
|
|
99
|
+
return [
|
|
100
|
+
4,
|
|
101
|
+
_this.server.onInit(_this.runner, _this.app)
|
|
102
|
+
];
|
|
103
|
+
case 10:
|
|
104
|
+
_state.sent();
|
|
105
|
+
return [
|
|
106
|
+
4,
|
|
107
|
+
_this.runner.afterServerInit({
|
|
108
|
+
app: _this.app,
|
|
109
|
+
server: _this.server
|
|
110
|
+
})
|
|
111
|
+
];
|
|
112
|
+
case 11:
|
|
113
|
+
result1 = _state.sent();
|
|
114
|
+
ref2 = result1, ref3 = ref2.app, _this.app = ref3 === void 0 ? _this.app : ref3, _this.server = ref2.server, ref2;
|
|
115
|
+
return [
|
|
116
|
+
2,
|
|
117
|
+
_this
|
|
118
|
+
];
|
|
212
119
|
}
|
|
213
|
-
)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
{
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
120
|
+
});
|
|
121
|
+
})();
|
|
122
|
+
};
|
|
123
|
+
_proto.runConfigHook = function runConfigHook(runner, serverConfig) {
|
|
124
|
+
var newServerConfig = runner.config(serverConfig || {});
|
|
125
|
+
return newServerConfig;
|
|
126
|
+
};
|
|
127
|
+
_proto.runPrepareHook = function runPrepareHook(runner) {
|
|
128
|
+
return _async_to_generator(function() {
|
|
129
|
+
return _ts_generator(this, function(_state) {
|
|
130
|
+
runner.prepare();
|
|
131
|
+
return [
|
|
132
|
+
2
|
|
133
|
+
];
|
|
134
|
+
});
|
|
135
|
+
})();
|
|
136
|
+
};
|
|
137
|
+
_proto.initServerConfig = function initServerConfig(options) {
|
|
138
|
+
var pwd = options.pwd, serverConfigFile = options.serverConfigFile;
|
|
139
|
+
var distDirectory = path.join(pwd, options.config.output.path || "dist");
|
|
140
|
+
var serverConfigPath = getServerConfigPath(distDirectory, serverConfigFile);
|
|
141
|
+
var serverConfig = requireConfig(serverConfigPath);
|
|
142
|
+
this.serverConfig = serverConfig;
|
|
143
|
+
};
|
|
144
|
+
_proto.initConfig = function initConfig(runner, options) {
|
|
145
|
+
var _this = this;
|
|
146
|
+
return _async_to_generator(function() {
|
|
147
|
+
var pwd, config, serverConfig, finalServerConfig, resolvedConfigPath;
|
|
148
|
+
return _ts_generator(this, function(_state) {
|
|
149
|
+
pwd = options.pwd, config = options.config;
|
|
150
|
+
serverConfig = _this.serverConfig;
|
|
151
|
+
finalServerConfig = _this.runConfigHook(runner, serverConfig);
|
|
152
|
+
resolvedConfigPath = ensureAbsolutePath(pwd, path.join(config.output.path || "dist", OUTPUT_CONFIG_FILE));
|
|
153
|
+
options.config = loadConfig({
|
|
154
|
+
cliConfig: config,
|
|
155
|
+
serverConfig: finalServerConfig,
|
|
156
|
+
resolvedConfigPath
|
|
157
|
+
});
|
|
158
|
+
return [
|
|
159
|
+
2
|
|
160
|
+
];
|
|
161
|
+
});
|
|
162
|
+
})();
|
|
163
|
+
};
|
|
164
|
+
_proto.close = function close() {
|
|
165
|
+
var _this = this;
|
|
166
|
+
return _async_to_generator(function() {
|
|
167
|
+
var _this_server_close, _this_server;
|
|
168
|
+
return _ts_generator(this, function(_state) {
|
|
169
|
+
switch (_state.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
return [
|
|
172
|
+
4,
|
|
173
|
+
(_this_server_close = (_this_server = _this.server).close) === null || _this_server_close === void 0 ? void 0 : _this_server_close.call(_this_server)
|
|
174
|
+
];
|
|
175
|
+
case 1:
|
|
176
|
+
_state.sent();
|
|
177
|
+
_this.app.close();
|
|
178
|
+
return [
|
|
179
|
+
2
|
|
180
|
+
];
|
|
254
181
|
}
|
|
182
|
+
});
|
|
183
|
+
})();
|
|
184
|
+
};
|
|
185
|
+
_proto.listen = function listen(options, listener) {
|
|
186
|
+
var callback = function() {
|
|
187
|
+
listener === null || listener === void 0 ? void 0 : listener();
|
|
188
|
+
};
|
|
189
|
+
if (typeof options === "object") {
|
|
190
|
+
if (process.env.PORT) {
|
|
191
|
+
Object.assign(options, {
|
|
192
|
+
port: process.env.PORT
|
|
193
|
+
});
|
|
255
194
|
}
|
|
256
|
-
|
|
257
|
-
{
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
195
|
+
this.app.listen(options, callback);
|
|
196
|
+
} else {
|
|
197
|
+
this.app.listen(process.env.PORT || options || 8080, callback);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
_proto.getRequestHandler = function getRequestHandler() {
|
|
201
|
+
var _this = this;
|
|
202
|
+
return function(req, res, next) {
|
|
203
|
+
var requestHandler = _this.server.getRequestHandler();
|
|
204
|
+
return requestHandler(req, res, next);
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
_proto.render = function render(req, res, url) {
|
|
208
|
+
var _this = this;
|
|
209
|
+
return _async_to_generator(function() {
|
|
210
|
+
return _ts_generator(this, function(_state) {
|
|
211
|
+
return [
|
|
212
|
+
2,
|
|
213
|
+
_this.server.render(req, res, url)
|
|
214
|
+
];
|
|
215
|
+
});
|
|
216
|
+
})();
|
|
217
|
+
};
|
|
218
|
+
_proto.createHookRunner = function createHookRunner() {
|
|
219
|
+
var _this = this;
|
|
220
|
+
return _async_to_generator(function() {
|
|
221
|
+
var options, _options_internalPlugins, internalPlugins, pwd, _options_plugins, plugins, serverPlugins, loadedPlugins, hooksRunner;
|
|
222
|
+
return _ts_generator(this, function(_state) {
|
|
223
|
+
switch (_state.label) {
|
|
224
|
+
case 0:
|
|
225
|
+
serverManager.clear();
|
|
226
|
+
options = _this.options;
|
|
227
|
+
_options_internalPlugins = options.internalPlugins, internalPlugins = _options_internalPlugins === void 0 ? INTERNAL_SERVER_PLUGINS : _options_internalPlugins, pwd = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins;
|
|
228
|
+
serverPlugins = _this.serverConfig.plugins || [];
|
|
229
|
+
loadedPlugins = loadPlugins(pwd, _to_consumable_array(serverPlugins).concat(_to_consumable_array(plugins)), {
|
|
230
|
+
internalPlugins
|
|
231
|
+
});
|
|
232
|
+
debug("plugins", loadedPlugins);
|
|
233
|
+
loadedPlugins.forEach(function(p) {
|
|
234
|
+
serverManager.usePlugin(p);
|
|
235
|
+
});
|
|
236
|
+
return [
|
|
237
|
+
4,
|
|
238
|
+
serverManager.init()
|
|
239
|
+
];
|
|
240
|
+
case 1:
|
|
241
|
+
hooksRunner = _state.sent();
|
|
273
242
|
return [
|
|
274
243
|
2,
|
|
275
|
-
|
|
244
|
+
hooksRunner
|
|
276
245
|
];
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
})();
|
|
249
|
+
};
|
|
250
|
+
_proto.injectContext = function injectContext(runner, options) {
|
|
251
|
+
var _this = this;
|
|
252
|
+
return _async_to_generator(function() {
|
|
253
|
+
var appContext, config, pwd;
|
|
254
|
+
return _ts_generator(this, function(_state) {
|
|
255
|
+
appContext = _this.initAppContext();
|
|
256
|
+
config = options.config, pwd = options.pwd;
|
|
257
|
+
ConfigContext.set(config);
|
|
258
|
+
AppContext.set(_object_spread_props(_object_spread({}, appContext), {
|
|
259
|
+
distDirectory: path.join(pwd, config.output.path || "dist")
|
|
260
|
+
}));
|
|
261
|
+
return [
|
|
262
|
+
2
|
|
263
|
+
];
|
|
264
|
+
});
|
|
265
|
+
})();
|
|
266
|
+
};
|
|
267
|
+
_proto.initAppContext = function initAppContext() {
|
|
268
|
+
var options = this.options;
|
|
269
|
+
var appDirectory = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins, config = options.config, appContext = options.appContext;
|
|
270
|
+
var serverPlugins = plugins.map(function(p) {
|
|
271
|
+
return {
|
|
272
|
+
server: p
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
appDirectory,
|
|
277
|
+
apiDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory,
|
|
278
|
+
lambdaDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.lambdaDirectory,
|
|
279
|
+
sharedDirectory: (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || path.resolve(appDirectory, SHARED_DIR),
|
|
280
|
+
distDirectory: path.join(appDirectory, config.output.path || "dist"),
|
|
281
|
+
plugins: serverPlugins
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
_proto.loadServerEnv = function loadServerEnv(options) {
|
|
285
|
+
return _async_to_generator(function() {
|
|
286
|
+
var appDirectory, serverEnv, defaultEnvPath, serverEnvPath, _i, _iter, envPath, _tmp, envConfig;
|
|
287
|
+
return _ts_generator(this, function(_state) {
|
|
288
|
+
switch (_state.label) {
|
|
289
|
+
case 0:
|
|
290
|
+
appDirectory = options.pwd;
|
|
291
|
+
serverEnv = process.env.MODERN_ENV;
|
|
292
|
+
defaultEnvPath = path.resolve(appDirectory, ".env");
|
|
293
|
+
serverEnvPath = path.resolve(appDirectory, ".env.".concat(serverEnv));
|
|
294
|
+
_i = 0, _iter = [
|
|
295
|
+
serverEnvPath,
|
|
296
|
+
defaultEnvPath
|
|
297
|
+
];
|
|
298
|
+
_state.label = 1;
|
|
299
|
+
case 1:
|
|
300
|
+
if (!(_i < _iter.length))
|
|
301
|
+
return [
|
|
302
|
+
3,
|
|
303
|
+
6
|
|
304
|
+
];
|
|
305
|
+
envPath = _iter[_i];
|
|
306
|
+
return [
|
|
307
|
+
4,
|
|
308
|
+
fs.pathExists(envPath)
|
|
309
|
+
];
|
|
310
|
+
case 2:
|
|
311
|
+
_tmp = _state.sent();
|
|
312
|
+
if (!_tmp)
|
|
313
|
+
return [
|
|
314
|
+
3,
|
|
315
|
+
4
|
|
316
|
+
];
|
|
317
|
+
return [
|
|
318
|
+
4,
|
|
319
|
+
fs.stat(envPath)
|
|
320
|
+
];
|
|
321
|
+
case 3:
|
|
322
|
+
_tmp = !_state.sent().isDirectory();
|
|
323
|
+
_state.label = 4;
|
|
324
|
+
case 4:
|
|
325
|
+
if (_tmp) {
|
|
326
|
+
envConfig = dotenv.config({
|
|
327
|
+
path: envPath
|
|
328
|
+
});
|
|
329
|
+
dotenvExpand(envConfig);
|
|
311
330
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
return _async_to_generator(function() {
|
|
321
|
-
var appContext, config, pwd;
|
|
322
|
-
return _ts_generator(this, function(_state) {
|
|
323
|
-
appContext = _this.initAppContext();
|
|
324
|
-
config = options.config, pwd = options.pwd;
|
|
325
|
-
ConfigContext.set(config);
|
|
326
|
-
AppContext.set(_object_spread_props(_object_spread({}, appContext), {
|
|
327
|
-
distDirectory: path.join(pwd, config.output.path || "dist")
|
|
328
|
-
}));
|
|
331
|
+
_state.label = 5;
|
|
332
|
+
case 5:
|
|
333
|
+
_i++;
|
|
334
|
+
return [
|
|
335
|
+
3,
|
|
336
|
+
1
|
|
337
|
+
];
|
|
338
|
+
case 6:
|
|
329
339
|
return [
|
|
330
340
|
2
|
|
331
341
|
];
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
{
|
|
337
|
-
key: "initAppContext",
|
|
338
|
-
value: function initAppContext() {
|
|
339
|
-
var options = this.options;
|
|
340
|
-
var appDirectory = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins, config = options.config, appContext = options.appContext;
|
|
341
|
-
var serverPlugins = plugins.map(function(p) {
|
|
342
|
-
return {
|
|
343
|
-
server: p
|
|
344
|
-
};
|
|
345
|
-
});
|
|
346
|
-
return {
|
|
347
|
-
appDirectory,
|
|
348
|
-
apiDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory,
|
|
349
|
-
lambdaDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.lambdaDirectory,
|
|
350
|
-
sharedDirectory: (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || path.resolve(appDirectory, SHARED_DIR),
|
|
351
|
-
distDirectory: path.join(appDirectory, config.output.path || "dist"),
|
|
352
|
-
plugins: serverPlugins
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
key: "loadServerEnv",
|
|
358
|
-
value: function loadServerEnv(options) {
|
|
359
|
-
return _async_to_generator(function() {
|
|
360
|
-
var appDirectory, serverEnv, defaultEnvPath, serverEnvPath, _i, _iter, envPath, _tmp, envConfig;
|
|
361
|
-
return _ts_generator(this, function(_state) {
|
|
362
|
-
switch (_state.label) {
|
|
363
|
-
case 0:
|
|
364
|
-
appDirectory = options.pwd;
|
|
365
|
-
serverEnv = process.env.MODERN_ENV;
|
|
366
|
-
defaultEnvPath = path.resolve(appDirectory, ".env");
|
|
367
|
-
serverEnvPath = path.resolve(appDirectory, ".env.".concat(serverEnv));
|
|
368
|
-
_i = 0, _iter = [
|
|
369
|
-
serverEnvPath,
|
|
370
|
-
defaultEnvPath
|
|
371
|
-
];
|
|
372
|
-
_state.label = 1;
|
|
373
|
-
case 1:
|
|
374
|
-
if (!(_i < _iter.length))
|
|
375
|
-
return [
|
|
376
|
-
3,
|
|
377
|
-
6
|
|
378
|
-
];
|
|
379
|
-
envPath = _iter[_i];
|
|
380
|
-
return [
|
|
381
|
-
4,
|
|
382
|
-
fs.pathExists(envPath)
|
|
383
|
-
];
|
|
384
|
-
case 2:
|
|
385
|
-
_tmp = _state.sent();
|
|
386
|
-
if (!_tmp)
|
|
387
|
-
return [
|
|
388
|
-
3,
|
|
389
|
-
4
|
|
390
|
-
];
|
|
391
|
-
return [
|
|
392
|
-
4,
|
|
393
|
-
fs.stat(envPath)
|
|
394
|
-
];
|
|
395
|
-
case 3:
|
|
396
|
-
_tmp = !_state.sent().isDirectory();
|
|
397
|
-
_state.label = 4;
|
|
398
|
-
case 4:
|
|
399
|
-
if (_tmp) {
|
|
400
|
-
envConfig = dotenv.config({
|
|
401
|
-
path: envPath
|
|
402
|
-
});
|
|
403
|
-
dotenvExpand(envConfig);
|
|
404
|
-
}
|
|
405
|
-
_state.label = 5;
|
|
406
|
-
case 5:
|
|
407
|
-
_i++;
|
|
408
|
-
return [
|
|
409
|
-
3,
|
|
410
|
-
1
|
|
411
|
-
];
|
|
412
|
-
case 6:
|
|
413
|
-
return [
|
|
414
|
-
2
|
|
415
|
-
];
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
})();
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
]);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
})();
|
|
345
|
+
};
|
|
422
346
|
return Server2;
|
|
423
347
|
}();
|
|
424
348
|
export {
|