@modern-js/bff-core 1.2.2-beta.0 → 1.2.2-beta.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.
|
@@ -70,8 +70,10 @@ const enableRegister = requireFn => {
|
|
|
70
70
|
|
|
71
71
|
const isFunction = input => input && {}.toString.call(input) === '[object Function]';
|
|
72
72
|
|
|
73
|
-
export const requireHandlerModule =
|
|
74
|
-
|
|
73
|
+
export const requireHandlerModule = modulePath => {
|
|
74
|
+
// 测试环境不走缓存,因为缓存的 handler 文件,会被 mockAPI 函数进行 mock,升级 jest28,setupFilesAfterEnv 能做异步操作的话,可解此问题
|
|
75
|
+
const originRequire = process.env.NODE_ENV === 'test' ? jest.requireActual : require;
|
|
76
|
+
const module = originRequire(modulePath);
|
|
75
77
|
|
|
76
78
|
if (isFunction(module)) {
|
|
77
79
|
return {
|
|
@@ -80,7 +82,7 @@ export const requireHandlerModule = enableRegister(modulePath => {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
return module;
|
|
83
|
-
}
|
|
85
|
+
};
|
|
84
86
|
|
|
85
87
|
const routeValue = routePath => {
|
|
86
88
|
if (routePath.includes(':')) {
|
|
@@ -89,8 +89,10 @@ const enableRegister = requireFn => {
|
|
|
89
89
|
|
|
90
90
|
const isFunction = input => input && {}.toString.call(input) === '[object Function]';
|
|
91
91
|
|
|
92
|
-
const requireHandlerModule =
|
|
93
|
-
|
|
92
|
+
const requireHandlerModule = modulePath => {
|
|
93
|
+
// 测试环境不走缓存,因为缓存的 handler 文件,会被 mockAPI 函数进行 mock,升级 jest28,setupFilesAfterEnv 能做异步操作的话,可解此问题
|
|
94
|
+
const originRequire = process.env.NODE_ENV === 'test' ? jest.requireActual : require;
|
|
95
|
+
const module = originRequire(modulePath);
|
|
94
96
|
|
|
95
97
|
if (isFunction(module)) {
|
|
96
98
|
return {
|
|
@@ -99,7 +101,8 @@ const requireHandlerModule = enableRegister(modulePath => {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
return module;
|
|
102
|
-
}
|
|
104
|
+
};
|
|
105
|
+
|
|
103
106
|
exports.requireHandlerModule = requireHandlerModule;
|
|
104
107
|
|
|
105
108
|
const routeValue = routePath => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { APIHandlerInfo
|
|
1
|
+
import { APIHandlerInfo } from './types';
|
|
2
2
|
declare type MaybeAsync<I> = I | Promise<I>;
|
|
3
3
|
export declare type NormalHandler = (...args: any[]) => any;
|
|
4
4
|
export declare type Handler<I, O> = (input: I) => MaybeAsync<O>;
|
|
5
5
|
export declare const getFiles: (lambdaDir: string, rules: string | string[]) => string[];
|
|
6
6
|
export declare const getPathFromFilename: (baseDir: string, filename: string) => string;
|
|
7
7
|
export declare const isHandler: (input: any) => input is Handler<any, any>;
|
|
8
|
-
export declare const requireHandlerModule: (modulePath: string) =>
|
|
8
|
+
export declare const requireHandlerModule: (modulePath: string) => any;
|
|
9
9
|
export declare const sortRoutes: (apiHandlers: APIHandlerInfo[]) => APIHandlerInfo[];
|
|
10
10
|
export {};
|