@modern-js/bff-core 1.15.0 → 1.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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @modern-js/bff-core
|
|
2
|
+
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 020b9bd52: feat: support frame mode without lambda directories
|
|
8
|
+
feat: 支持无 lambda 目录的框架模式
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [641592f52]
|
|
13
|
+
- Updated dependencies [3904b30a5]
|
|
14
|
+
- Updated dependencies [1100dd58c]
|
|
15
|
+
- Updated dependencies [e04e6e76a]
|
|
16
|
+
- Updated dependencies [81c66e4a4]
|
|
17
|
+
- Updated dependencies [2c305b6f5]
|
|
18
|
+
- @modern-js/utils@1.16.0
|
|
19
|
+
- @modern-js/bff-runtime@1.16.0
|
|
@@ -19,6 +19,8 @@ export class ApiRouter {
|
|
|
19
19
|
|
|
20
20
|
_defineProperty(this, "lambdaDir", void 0);
|
|
21
21
|
|
|
22
|
+
_defineProperty(this, "existLambda", void 0);
|
|
23
|
+
|
|
22
24
|
_defineProperty(this, "prefix", void 0);
|
|
23
25
|
|
|
24
26
|
_defineProperty(this, "apiFiles", void 0);
|
|
@@ -35,7 +37,7 @@ export class ApiRouter {
|
|
|
35
37
|
|
|
36
38
|
_defineProperty(this, "createExistChecker", base => target => fs.pathExistsSync(path.resolve(base, target)));
|
|
37
39
|
|
|
38
|
-
_defineProperty(this, "
|
|
40
|
+
_defineProperty(this, "getExactLambdaDir", apiDir => {
|
|
39
41
|
if (this.lambdaDir) {
|
|
40
42
|
return this.lambdaDir;
|
|
41
43
|
}
|
|
@@ -57,10 +59,23 @@ export class ApiRouter {
|
|
|
57
59
|
|
|
58
60
|
this.prefix = this.initPrefix(prefix);
|
|
59
61
|
this.apiDir = _apiDir;
|
|
60
|
-
this.lambdaDir = _lambdaDir || this.
|
|
62
|
+
this.lambdaDir = _lambdaDir || this.getExactLambdaDir(this.apiDir);
|
|
63
|
+
this.existLambda = this.checkExistLambda(this.apiDir, this.lambdaDir);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
isExistLambda() {
|
|
67
|
+
return this.existLambda;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getLambdaDir() {
|
|
71
|
+
return this.lambdaDir;
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
isApiFile(filename) {
|
|
75
|
+
if (this.existLambda) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
64
79
|
if (!this.apiFiles.includes(filename)) {
|
|
65
80
|
return false;
|
|
66
81
|
}
|
|
@@ -169,12 +184,20 @@ export class ApiRouter {
|
|
|
169
184
|
}
|
|
170
185
|
|
|
171
186
|
loadApiFiles() {
|
|
172
|
-
|
|
187
|
+
if (!this.existLambda) {
|
|
188
|
+
return [];
|
|
189
|
+
} // eslint-disable-next-line no-multi-assign
|
|
190
|
+
|
|
191
|
+
|
|
173
192
|
const apiFiles = this.apiFiles = getFiles(this.lambdaDir, API_FILE_RULES);
|
|
174
193
|
return apiFiles;
|
|
175
194
|
}
|
|
176
195
|
|
|
177
196
|
getApiFiles() {
|
|
197
|
+
if (!this.existLambda) {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
|
|
178
201
|
if (this.apiFiles.length > 0) {
|
|
179
202
|
return this.apiFiles;
|
|
180
203
|
}
|
|
@@ -203,6 +226,37 @@ export class ApiRouter {
|
|
|
203
226
|
return prefix || '/api';
|
|
204
227
|
}
|
|
205
228
|
|
|
229
|
+
checkExistLambda(apiDir, lambdaDir) {
|
|
230
|
+
const isSame = apiDir === lambdaDir;
|
|
231
|
+
|
|
232
|
+
if (!isSame) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const exts = ['.ts', '.js'];
|
|
237
|
+
|
|
238
|
+
const existAppDir = apiDir => {
|
|
239
|
+
return fs.existsSync(path.join(apiDir, 'app'));
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const existAppFile = apiDir => {
|
|
243
|
+
const exists = exts.some(ext => {
|
|
244
|
+
return fs.existsSync(path.join(apiDir, `app${ext}`));
|
|
245
|
+
});
|
|
246
|
+
return exists;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
if (isSame && existAppDir(apiDir)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (isSame && existAppFile(apiDir)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
206
260
|
validateAbsolute(filename, paramsName) {
|
|
207
261
|
if (!path.isAbsolute(filename)) {
|
|
208
262
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
@@ -62,6 +62,8 @@ class ApiRouter {
|
|
|
62
62
|
|
|
63
63
|
_defineProperty(this, "lambdaDir", void 0);
|
|
64
64
|
|
|
65
|
+
_defineProperty(this, "existLambda", void 0);
|
|
66
|
+
|
|
65
67
|
_defineProperty(this, "prefix", void 0);
|
|
66
68
|
|
|
67
69
|
_defineProperty(this, "apiFiles", void 0);
|
|
@@ -78,7 +80,7 @@ class ApiRouter {
|
|
|
78
80
|
|
|
79
81
|
_defineProperty(this, "createExistChecker", base => target => _utils.fs.pathExistsSync(_path.default.resolve(base, target)));
|
|
80
82
|
|
|
81
|
-
_defineProperty(this, "
|
|
83
|
+
_defineProperty(this, "getExactLambdaDir", apiDir => {
|
|
82
84
|
if (this.lambdaDir) {
|
|
83
85
|
return this.lambdaDir;
|
|
84
86
|
}
|
|
@@ -100,10 +102,23 @@ class ApiRouter {
|
|
|
100
102
|
|
|
101
103
|
this.prefix = this.initPrefix(prefix);
|
|
102
104
|
this.apiDir = _apiDir;
|
|
103
|
-
this.lambdaDir = _lambdaDir || this.
|
|
105
|
+
this.lambdaDir = _lambdaDir || this.getExactLambdaDir(this.apiDir);
|
|
106
|
+
this.existLambda = this.checkExistLambda(this.apiDir, this.lambdaDir);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
isExistLambda() {
|
|
110
|
+
return this.existLambda;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getLambdaDir() {
|
|
114
|
+
return this.lambdaDir;
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
isApiFile(filename) {
|
|
118
|
+
if (this.existLambda) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
if (!this.apiFiles.includes(filename)) {
|
|
108
123
|
return false;
|
|
109
124
|
}
|
|
@@ -213,12 +228,20 @@ class ApiRouter {
|
|
|
213
228
|
}
|
|
214
229
|
|
|
215
230
|
loadApiFiles() {
|
|
216
|
-
|
|
231
|
+
if (!this.existLambda) {
|
|
232
|
+
return [];
|
|
233
|
+
} // eslint-disable-next-line no-multi-assign
|
|
234
|
+
|
|
235
|
+
|
|
217
236
|
const apiFiles = this.apiFiles = (0, _utils3.getFiles)(this.lambdaDir, _constants.API_FILE_RULES);
|
|
218
237
|
return apiFiles;
|
|
219
238
|
}
|
|
220
239
|
|
|
221
240
|
getApiFiles() {
|
|
241
|
+
if (!this.existLambda) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
|
|
222
245
|
if (this.apiFiles.length > 0) {
|
|
223
246
|
return this.apiFiles;
|
|
224
247
|
}
|
|
@@ -247,6 +270,37 @@ class ApiRouter {
|
|
|
247
270
|
return prefix || '/api';
|
|
248
271
|
}
|
|
249
272
|
|
|
273
|
+
checkExistLambda(apiDir, lambdaDir) {
|
|
274
|
+
const isSame = apiDir === lambdaDir;
|
|
275
|
+
|
|
276
|
+
if (!isSame) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const exts = ['.ts', '.js'];
|
|
281
|
+
|
|
282
|
+
const existAppDir = apiDir => {
|
|
283
|
+
return _utils.fs.existsSync(_path.default.join(apiDir, 'app'));
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const existAppFile = apiDir => {
|
|
287
|
+
const exists = exts.some(ext => {
|
|
288
|
+
return _utils.fs.existsSync(_path.default.join(apiDir, `app${ext}`));
|
|
289
|
+
});
|
|
290
|
+
return exists;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
if (isSame && existAppDir(apiDir)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (isSame && existAppFile(apiDir)) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
250
304
|
validateAbsolute(filename, paramsName) {
|
|
251
305
|
if (!_path.default.isAbsolute(filename)) {
|
|
252
306
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
@@ -6,6 +6,7 @@ export * from './constants';
|
|
|
6
6
|
export declare class ApiRouter {
|
|
7
7
|
private apiDir;
|
|
8
8
|
private lambdaDir;
|
|
9
|
+
private existLambda;
|
|
9
10
|
private prefix;
|
|
10
11
|
private apiFiles;
|
|
11
12
|
constructor({
|
|
@@ -17,6 +18,8 @@ export declare class ApiRouter {
|
|
|
17
18
|
lambdaDir?: string;
|
|
18
19
|
prefix?: string;
|
|
19
20
|
});
|
|
21
|
+
isExistLambda(): boolean;
|
|
22
|
+
getLambdaDir(): string;
|
|
20
23
|
isApiFile(filename: string): boolean;
|
|
21
24
|
getSingleModuleHandlers(filename: string): APIHandlerInfo[] | null;
|
|
22
25
|
getHandlerInfo(filename: string, originFuncName: string, handler: ApiHandler): APIHandlerInfo | null;
|
|
@@ -32,10 +35,11 @@ export declare class ApiRouter {
|
|
|
32
35
|
*/
|
|
33
36
|
|
|
34
37
|
private initPrefix;
|
|
38
|
+
private checkExistLambda;
|
|
35
39
|
private validateAbsolute;
|
|
36
40
|
private getAPIMode;
|
|
37
41
|
private createExistChecker;
|
|
38
|
-
private
|
|
42
|
+
private getExactLambdaDir;
|
|
39
43
|
private getModuleInfos;
|
|
40
44
|
private getModuleInfo;
|
|
41
45
|
private getHandlerInfos;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.16.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/runtime": "^7.18.0",
|
|
28
|
-
"@modern-js/bff-runtime": "1.
|
|
29
|
-
"@modern-js/utils": "1.
|
|
28
|
+
"@modern-js/bff-runtime": "1.16.0",
|
|
29
|
+
"@modern-js/utils": "1.16.0",
|
|
30
30
|
"esbuild": "^0.14.38",
|
|
31
31
|
"esbuild-register": "^3.3.3",
|
|
32
32
|
"koa-compose": "^4.1.0",
|