@modern-js/plugin-bff 2.14.0 → 2.16.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/esm/cli.js CHANGED
@@ -1,203 +1,219 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length)
3
+ len = arr.length;
4
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
5
+ arr2[i] = arr[i];
6
+ return arr2;
5
7
  }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ function _array_without_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return _array_like_to_array(arr);
8
11
  }
9
12
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+ if (info.done) {
21
+ resolve(value);
22
+ } else {
23
+ Promise.resolve(value).then(_next, _throw);
24
+ }
22
25
  }
23
- function _asyncToGenerator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
26
+ function _async_to_generator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(void 0);
38
+ });
39
+ };
37
40
  }
38
- function _defineProperty(obj, key, value) {
39
- if (key in obj) {
40
- Object.defineProperty(obj, key, {
41
- value: value,
42
- enumerable: true,
43
- configurable: true,
44
- writable: true
45
- });
46
- } else {
47
- obj[key] = value;
48
- }
49
- return obj;
41
+ function _define_property(obj, key, value) {
42
+ if (key in obj) {
43
+ Object.defineProperty(obj, key, {
44
+ value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ } else {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
50
53
  }
51
- function _iterableToArray(iter) {
52
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
54
+ function _iterable_to_array(iter) {
55
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
56
+ return Array.from(iter);
53
57
  }
54
- function _nonIterableSpread() {
55
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ function _non_iterable_spread() {
59
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
60
  }
57
- function _objectSpread(target) {
58
- for(var i = 1; i < arguments.length; i++){
59
- var source = arguments[i] != null ? arguments[i] : {};
60
- var ownKeys = Object.keys(source);
61
- if (typeof Object.getOwnPropertySymbols === "function") {
62
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
- }));
65
- }
66
- ownKeys.forEach(function(key) {
67
- _defineProperty(target, key, source[key]);
68
- });
61
+ function _object_spread(target) {
62
+ for (var i = 1; i < arguments.length; i++) {
63
+ var source = arguments[i] != null ? arguments[i] : {};
64
+ var ownKeys2 = Object.keys(source);
65
+ if (typeof Object.getOwnPropertySymbols === "function") {
66
+ ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
67
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
68
+ }));
69
69
  }
70
- return target;
70
+ ownKeys2.forEach(function(key) {
71
+ _define_property(target, key, source[key]);
72
+ });
73
+ }
74
+ return target;
71
75
  }
72
76
  function ownKeys(object, enumerableOnly) {
73
- var keys = Object.keys(object);
74
- if (Object.getOwnPropertySymbols) {
75
- var symbols = Object.getOwnPropertySymbols(object);
76
- if (enumerableOnly) {
77
- symbols = symbols.filter(function(sym) {
78
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
79
- });
80
- }
81
- keys.push.apply(keys, symbols);
77
+ var keys = Object.keys(object);
78
+ if (Object.getOwnPropertySymbols) {
79
+ var symbols = Object.getOwnPropertySymbols(object);
80
+ if (enumerableOnly) {
81
+ symbols = symbols.filter(function(sym) {
82
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
83
+ });
82
84
  }
83
- return keys;
85
+ keys.push.apply(keys, symbols);
86
+ }
87
+ return keys;
84
88
  }
85
- function _objectSpreadProps(target, source) {
86
- source = source != null ? source : {};
87
- if (Object.getOwnPropertyDescriptors) {
88
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
- } else {
90
- ownKeys(Object(source)).forEach(function(key) {
91
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
- });
93
- }
94
- return target;
89
+ function _object_spread_props(target, source) {
90
+ source = source != null ? source : {};
91
+ if (Object.getOwnPropertyDescriptors) {
92
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
93
+ } else {
94
+ ownKeys(Object(source)).forEach(function(key) {
95
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
96
+ });
97
+ }
98
+ return target;
95
99
  }
96
- function _toConsumableArray(arr) {
97
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
100
+ function _to_consumable_array(arr) {
101
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
98
102
  }
99
- function _unsupportedIterableToArray(o, minLen) {
100
- if (!o) return;
101
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
102
- var n = Object.prototype.toString.call(o).slice(8, -1);
103
- if (n === "Object" && o.constructor) n = o.constructor.name;
104
- if (n === "Map" || n === "Set") return Array.from(n);
105
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
103
+ function _unsupported_iterable_to_array(o, minLen) {
104
+ if (!o)
105
+ return;
106
+ if (typeof o === "string")
107
+ return _array_like_to_array(o, minLen);
108
+ var n = Object.prototype.toString.call(o).slice(8, -1);
109
+ if (n === "Object" && o.constructor)
110
+ n = o.constructor.name;
111
+ if (n === "Map" || n === "Set")
112
+ return Array.from(n);
113
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
114
+ return _array_like_to_array(o, minLen);
106
115
  }
107
- var __generator = this && this.__generator || function(thisArg, body) {
108
- var f, y, t, g, _ = {
109
- label: 0,
110
- sent: function() {
111
- if (t[0] & 1) throw t[1];
112
- return t[1];
113
- },
114
- trys: [],
115
- ops: []
116
+ var __generator = function(thisArg, body) {
117
+ var f, y, t, g, _ = {
118
+ label: 0,
119
+ sent: function() {
120
+ if (t[0] & 1)
121
+ throw t[1];
122
+ return t[1];
123
+ },
124
+ trys: [],
125
+ ops: []
126
+ };
127
+ return g = {
128
+ next: verb(0),
129
+ "throw": verb(1),
130
+ "return": verb(2)
131
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
132
+ return this;
133
+ }), g;
134
+ function verb(n) {
135
+ return function(v) {
136
+ return step([
137
+ n,
138
+ v
139
+ ]);
116
140
  };
117
- return g = {
118
- next: verb(0),
119
- "throw": verb(1),
120
- "return": verb(2)
121
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
122
- return this;
123
- }), g;
124
- function verb(n) {
125
- return function(v) {
126
- return step([
127
- n,
128
- v
129
- ]);
130
- };
131
- }
132
- function step(op) {
133
- if (f) throw new TypeError("Generator is already executing.");
134
- while(_)try {
135
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
136
- if (y = 0, t) op = [
137
- op[0] & 2,
138
- t.value
139
- ];
140
- switch(op[0]){
141
- case 0:
142
- case 1:
143
- t = op;
144
- break;
145
- case 4:
146
- _.label++;
147
- return {
148
- value: op[1],
149
- done: false
150
- };
151
- case 5:
152
- _.label++;
153
- y = op[1];
154
- op = [
155
- 0
156
- ];
157
- continue;
158
- case 7:
159
- op = _.ops.pop();
160
- _.trys.pop();
161
- continue;
162
- default:
163
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
164
- _ = 0;
165
- continue;
166
- }
167
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
168
- _.label = op[1];
169
- break;
170
- }
171
- if (op[0] === 6 && _.label < t[1]) {
172
- _.label = t[1];
173
- t = op;
174
- break;
175
- }
176
- if (t && _.label < t[2]) {
177
- _.label = t[2];
178
- _.ops.push(op);
179
- break;
180
- }
181
- if (t[2]) _.ops.pop();
182
- _.trys.pop();
183
- continue;
184
- }
185
- op = body.call(thisArg, _);
186
- } catch (e) {
141
+ }
142
+ function step(op) {
143
+ if (f)
144
+ throw new TypeError("Generator is already executing.");
145
+ while (_)
146
+ try {
147
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
148
+ return t;
149
+ if (y = 0, t)
150
+ op = [
151
+ op[0] & 2,
152
+ t.value
153
+ ];
154
+ switch (op[0]) {
155
+ case 0:
156
+ case 1:
157
+ t = op;
158
+ break;
159
+ case 4:
160
+ _.label++;
161
+ return {
162
+ value: op[1],
163
+ done: false
164
+ };
165
+ case 5:
166
+ _.label++;
167
+ y = op[1];
187
168
  op = [
188
- 6,
189
- e
169
+ 0
190
170
  ];
191
- y = 0;
192
- } finally{
193
- f = t = 0;
171
+ continue;
172
+ case 7:
173
+ op = _.ops.pop();
174
+ _.trys.pop();
175
+ continue;
176
+ default:
177
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
178
+ _ = 0;
179
+ continue;
180
+ }
181
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
182
+ _.label = op[1];
183
+ break;
184
+ }
185
+ if (op[0] === 6 && _.label < t[1]) {
186
+ _.label = t[1];
187
+ t = op;
188
+ break;
189
+ }
190
+ if (t && _.label < t[2]) {
191
+ _.label = t[2];
192
+ _.ops.push(op);
193
+ break;
194
+ }
195
+ if (t[2])
196
+ _.ops.pop();
197
+ _.trys.pop();
198
+ continue;
194
199
  }
195
- if (op[0] & 5) throw op[1];
196
- return {
197
- value: op[0] ? op[1] : void 0,
198
- done: true
199
- };
200
- }
200
+ op = body.call(thisArg, _);
201
+ } catch (e) {
202
+ op = [
203
+ 6,
204
+ e
205
+ ];
206
+ y = 0;
207
+ } finally {
208
+ f = t = 0;
209
+ }
210
+ if (op[0] & 5)
211
+ throw op[1];
212
+ return {
213
+ value: op[0] ? op[1] : void 0,
214
+ done: true
215
+ };
216
+ }
201
217
  };
202
218
  import path from "path";
203
219
  import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from "@modern-js/utils";
@@ -206,167 +222,168 @@ import { ApiRouter } from "@modern-js/bff-core";
206
222
  import { registerModernRuntimePath } from "./helper";
207
223
  var DEFAULT_API_PREFIX = "/api";
208
224
  var TS_CONFIG_FILENAME = "tsconfig.json";
209
- var cli_default = function() {
210
- return {
211
- name: "@modern-js/plugin-bff",
212
- setup: function(api) {
213
- var unRegisterResolveRuntimePath = null;
225
+ export default function() {
226
+ return {
227
+ name: "@modern-js/plugin-bff",
228
+ setup: function(api) {
229
+ var unRegisterResolveRuntimePath = null;
230
+ return {
231
+ validateSchema: function validateSchema() {
232
+ return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
233
+ },
234
+ config: function config() {
235
+ return {
236
+ tools: {
237
+ bundlerChain: function(chain, param) {
238
+ var CHAIN_ID = param.CHAIN_ID, isServer = param.isServer;
239
+ var _api_useAppContext = api.useAppContext(), port = _api_useAppContext.port, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory;
240
+ var modernConfig = api.useResolvedConfigContext();
241
+ var bff = (modernConfig || {}).bff;
242
+ var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
243
+ var httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
244
+ chain.resolve.alias.set("@api", apiDirectory);
245
+ var apiRouter = new ApiRouter({
246
+ apiDir: apiDirectory,
247
+ lambdaDir: lambdaDirectory,
248
+ prefix,
249
+ httpMethodDecider
250
+ });
251
+ var lambdaDir = apiRouter.getLambdaDir();
252
+ var existLambda = apiRouter.isExistLambda();
253
+ var apiRegexp = new RegExp(normalizeOutputPath("".concat(apiDirectory).concat(path.sep, ".*(.[tj]s)$")));
254
+ var name = isServer ? "server" : "client";
255
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
256
+ chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
257
+ prefix,
258
+ apiDir: apiDirectory,
259
+ lambdaDir,
260
+ existLambda,
261
+ port,
262
+ target: name,
263
+ httpMethodDecider
264
+ });
265
+ }
266
+ },
267
+ source: {
268
+ moduleScopes: [
269
+ "./".concat(API_DIR),
270
+ /create-request/
271
+ ]
272
+ }
273
+ };
274
+ },
275
+ modifyServerRoutes: function modifyServerRoutes(param) {
276
+ var routes = param.routes;
277
+ var modernConfig = api.useResolvedConfigContext();
278
+ var bff = (modernConfig || {}).bff;
279
+ var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
280
+ var prefixList = [];
281
+ if (Array.isArray(prefix)) {
282
+ var _prefixList;
283
+ (_prefixList = prefixList).push.apply(_prefixList, _to_consumable_array(prefix));
284
+ } else {
285
+ prefixList.push(prefix);
286
+ }
287
+ var apiServerRoutes = prefixList.map(function(pre) {
214
288
  return {
215
- validateSchema: function validateSchema() {
216
- return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
217
- },
218
- config: function config() {
219
- return {
220
- tools: {
221
- bundlerChain: function(chain, param) {
222
- var CHAIN_ID = param.CHAIN_ID, isServer = param.isServer;
223
- var _api_useAppContext = api.useAppContext(), port = _api_useAppContext.port, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory;
224
- var modernConfig = api.useResolvedConfigContext();
225
- var bff = (modernConfig || {}).bff;
226
- var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
227
- var httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
228
- chain.resolve.alias.set("@api", apiDirectory);
229
- var apiRouter = new ApiRouter({
230
- apiDir: apiDirectory,
231
- lambdaDir: lambdaDirectory,
232
- prefix: prefix,
233
- httpMethodDecider: httpMethodDecider
234
- });
235
- var lambdaDir = apiRouter.getLambdaDir();
236
- var existLambda = apiRouter.isExistLambda();
237
- var apiRegexp = new RegExp(normalizeOutputPath("".concat(apiDirectory).concat(path.sep, ".*(.[tj]s)$")));
238
- var name = isServer ? "server" : "client";
239
- chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
240
- chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
241
- prefix: prefix,
242
- apiDir: apiDirectory,
243
- lambdaDir: lambdaDir,
244
- existLambda: existLambda,
245
- port: port,
246
- target: name,
247
- httpMethodDecider: httpMethodDecider
248
- });
249
- }
250
- },
251
- source: {
252
- moduleScopes: [
253
- "./".concat(API_DIR),
254
- /create-request/
255
- ]
256
- }
257
- };
258
- },
259
- modifyServerRoutes: function modifyServerRoutes(param) {
260
- var routes = param.routes;
261
- var modernConfig = api.useResolvedConfigContext();
262
- var bff = (modernConfig || {}).bff;
263
- var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
264
- var prefixList = [];
265
- if (Array.isArray(prefix)) {
266
- var _prefixList;
267
- (_prefixList = prefixList).push.apply(_prefixList, _toConsumableArray(prefix));
268
- } else {
269
- prefixList.push(prefix);
270
- }
271
- var apiServerRoutes = prefixList.map(function(pre) {
272
- return {
273
- urlPath: pre,
274
- isApi: true,
275
- entryPath: "",
276
- isSPA: false,
277
- isSSR: false
278
- };
279
- });
280
- if (bff === null || bff === void 0 ? void 0 : bff.enableHandleWeb) {
281
- return {
282
- routes: routes.map(function(route) {
283
- return _objectSpreadProps(_objectSpread({}, route), {
284
- isApi: true
285
- });
286
- }).concat(apiServerRoutes)
287
- };
288
- }
289
- return {
290
- routes: routes.concat(apiServerRoutes)
291
- };
292
- },
293
- collectServerPlugins: function collectServerPlugins(param) {
294
- var plugins = param.plugins;
295
- plugins.push({
296
- "@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
297
- });
298
- return {
299
- plugins: plugins
300
- };
301
- },
302
- beforeBuild: function beforeBuild() {
303
- return _asyncToGenerator(function() {
304
- var internalDirectory;
305
- return __generator(this, function(_state) {
306
- if (isProd()) {
307
- internalDirectory = api.useAppContext().internalDirectory;
308
- unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
309
- }
310
- return [
311
- 2
312
- ];
313
- });
314
- })();
315
- },
316
- afterBuild: function afterBuild() {
317
- return _asyncToGenerator(function() {
318
- var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
319
- return __generator(this, function(_state) {
320
- switch(_state.label){
321
- case 0:
322
- if (unRegisterResolveRuntimePath) {
323
- unRegisterResolveRuntimePath();
324
- }
325
- _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory;
326
- modernConfig = api.useResolvedConfigContext();
327
- distDir = path.resolve(distDirectory);
328
- apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
329
- sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
330
- tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
331
- sourceDirs = [];
332
- if (fs.existsSync(apiDir)) {
333
- sourceDirs.push(apiDir);
334
- }
335
- if (fs.existsSync(sharedDir)) {
336
- sourceDirs.push(sharedDir);
337
- }
338
- server = modernConfig.server;
339
- alias = modernConfig.source.alias;
340
- babel = modernConfig.tools.babel;
341
- if (!(sourceDirs.length > 0)) return [
342
- 3,
343
- 2
344
- ];
345
- return [
346
- 4,
347
- compile(appDirectory, {
348
- server: server,
349
- alias: alias,
350
- babelConfig: babel
351
- }, {
352
- sourceDirs: sourceDirs,
353
- distDir: distDir,
354
- tsconfigPath: tsconfigPath
355
- })
356
- ];
357
- case 1:
358
- _state.sent();
359
- _state.label = 2;
360
- case 2:
361
- return [
362
- 2
363
- ];
364
- }
365
- });
366
- })();
367
- }
289
+ urlPath: pre,
290
+ isApi: true,
291
+ entryPath: "",
292
+ isSPA: false,
293
+ isSSR: false
368
294
  };
295
+ });
296
+ if (bff === null || bff === void 0 ? void 0 : bff.enableHandleWeb) {
297
+ return {
298
+ routes: routes.map(function(route) {
299
+ return _object_spread_props(_object_spread({}, route), {
300
+ isApi: true
301
+ });
302
+ }).concat(apiServerRoutes)
303
+ };
304
+ }
305
+ return {
306
+ routes: routes.concat(apiServerRoutes)
307
+ };
308
+ },
309
+ collectServerPlugins: function collectServerPlugins(param) {
310
+ var plugins = param.plugins;
311
+ plugins.push({
312
+ "@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
313
+ });
314
+ return {
315
+ plugins
316
+ };
317
+ },
318
+ beforeBuild: function beforeBuild() {
319
+ return _async_to_generator(function() {
320
+ var internalDirectory;
321
+ return __generator(this, function(_state) {
322
+ if (isProd()) {
323
+ internalDirectory = api.useAppContext().internalDirectory;
324
+ unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
325
+ }
326
+ return [
327
+ 2
328
+ ];
329
+ });
330
+ })();
331
+ },
332
+ afterBuild: function afterBuild() {
333
+ return _async_to_generator(function() {
334
+ var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
335
+ return __generator(this, function(_state) {
336
+ switch (_state.label) {
337
+ case 0:
338
+ if (unRegisterResolveRuntimePath) {
339
+ unRegisterResolveRuntimePath();
340
+ }
341
+ _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory;
342
+ modernConfig = api.useResolvedConfigContext();
343
+ distDir = path.resolve(distDirectory);
344
+ apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
345
+ sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
346
+ tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
347
+ sourceDirs = [];
348
+ if (fs.existsSync(apiDir)) {
349
+ sourceDirs.push(apiDir);
350
+ }
351
+ if (fs.existsSync(sharedDir)) {
352
+ sourceDirs.push(sharedDir);
353
+ }
354
+ server = modernConfig.server;
355
+ alias = modernConfig.source.alias;
356
+ babel = modernConfig.tools.babel;
357
+ if (!(sourceDirs.length > 0))
358
+ return [
359
+ 3,
360
+ 2
361
+ ];
362
+ return [
363
+ 4,
364
+ compile(appDirectory, {
365
+ server,
366
+ alias,
367
+ babelConfig: babel
368
+ }, {
369
+ sourceDirs,
370
+ distDir,
371
+ tsconfigPath
372
+ })
373
+ ];
374
+ case 1:
375
+ _state.sent();
376
+ _state.label = 2;
377
+ case 2:
378
+ return [
379
+ 2
380
+ ];
381
+ }
382
+ });
383
+ })();
369
384
  }
370
- };
371
- };
372
- export { cli_default as default };
385
+ };
386
+ }
387
+ };
388
+ }
389
+ ;