@modern-js/plugin-bff 2.0.0-beta.3 → 2.0.0-beta.6
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 +98 -0
- package/dist/js/modern/cli.js +112 -93
- package/dist/js/modern/constants.js +14 -2
- package/dist/js/modern/helper.js +8 -6
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/loader.js +66 -50
- package/dist/js/modern/server.js +39 -28
- package/dist/js/node/cli.js +133 -102
- package/dist/js/node/constants.js +37 -9
- package/dist/js/node/helper.js +37 -14
- package/dist/js/node/index.js +17 -16
- package/dist/js/node/loader.js +86 -56
- package/dist/js/node/server.js +70 -42
- package/dist/js/treeshaking/cli.js +302 -148
- package/dist/js/treeshaking/constants.js +11 -2
- package/dist/js/treeshaking/helper.js +22 -10
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/loader.js +185 -66
- package/dist/js/treeshaking/server.js +146 -78
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/server.d.ts +2 -0
- package/package.json +21 -25
- package/types.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- df7ee2d: feat: runtime user config types extends
|
|
12
|
+
feat: runtime 用户配置类型扩展
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 8ff2cf4c71: fix: bff api loader should run before babel loader
|
|
17
|
+
fix: bff 一体化调用的 loader 应该在 babel loader 前执行
|
|
18
|
+
- ea7cf06257: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
19
|
+
|
|
20
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [9b915e0c10]
|
|
23
|
+
- Updated dependencies [7879e8f711]
|
|
24
|
+
- Updated dependencies [d4e8e6fb90]
|
|
25
|
+
- Updated dependencies [6aca875011]
|
|
26
|
+
- Updated dependencies [2e6031955e]
|
|
27
|
+
- Updated dependencies [2344eb26ed]
|
|
28
|
+
- Updated dependencies [a2509bfbdb]
|
|
29
|
+
- Updated dependencies [7b7d12cf8f]
|
|
30
|
+
- Updated dependencies [7efeed4]
|
|
31
|
+
- Updated dependencies [92f0eade39]
|
|
32
|
+
- Updated dependencies [edd1cfb1af]
|
|
33
|
+
- Updated dependencies [cc971eabfc]
|
|
34
|
+
- Updated dependencies [5b9049f2e9]
|
|
35
|
+
- Updated dependencies [a8642da58f]
|
|
36
|
+
- Updated dependencies [92004d1906]
|
|
37
|
+
- Updated dependencies [b8bbe036c7]
|
|
38
|
+
- Updated dependencies [c2bb0f1745]
|
|
39
|
+
- Updated dependencies [d5a31df781]
|
|
40
|
+
- Updated dependencies [dda38c9c3e]
|
|
41
|
+
- Updated dependencies [3bbea92b2a]
|
|
42
|
+
- Updated dependencies [b710adb843]
|
|
43
|
+
- Updated dependencies [ea7cf06257]
|
|
44
|
+
- Updated dependencies [bbe4c4ab64]
|
|
45
|
+
- Updated dependencies [e4558a0bc4]
|
|
46
|
+
- Updated dependencies [abf3421a75]
|
|
47
|
+
- Updated dependencies [543be9558e]
|
|
48
|
+
- Updated dependencies [14b712da84]
|
|
49
|
+
- @modern-js/server-utils@2.0.0-beta.6
|
|
50
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
51
|
+
- @modern-js/bff-core@2.0.0-beta.6
|
|
52
|
+
- @modern-js/create-request@2.0.0-beta.6
|
|
53
|
+
- @modern-js/babel-compiler@2.0.0-beta.6
|
|
54
|
+
|
|
55
|
+
## 2.0.0-beta.4
|
|
56
|
+
|
|
57
|
+
### Major Changes
|
|
58
|
+
|
|
59
|
+
- dda38c9c3e: chore: v2
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- 8ff2cf4c71: fix: bff api loader should run before babel loader
|
|
64
|
+
fix: bff 一体化调用的 loader 应该在 babel loader 前执行
|
|
65
|
+
- ea7cf06: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
66
|
+
|
|
67
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [9b915e0c10]
|
|
70
|
+
- Updated dependencies [7879e8f]
|
|
71
|
+
- Updated dependencies [d4e8e6fb90]
|
|
72
|
+
- Updated dependencies [6aca875]
|
|
73
|
+
- Updated dependencies [2e6031955e]
|
|
74
|
+
- Updated dependencies [2344eb26ed]
|
|
75
|
+
- Updated dependencies [a2509bfbdb]
|
|
76
|
+
- Updated dependencies [7b7d12c]
|
|
77
|
+
- Updated dependencies [92f0eade39]
|
|
78
|
+
- Updated dependencies [edd1cfb1af]
|
|
79
|
+
- Updated dependencies [cc971eabfc]
|
|
80
|
+
- Updated dependencies [5b9049f2e9]
|
|
81
|
+
- Updated dependencies [a8642da58f]
|
|
82
|
+
- Updated dependencies [92004d1906]
|
|
83
|
+
- Updated dependencies [b8bbe036c7]
|
|
84
|
+
- Updated dependencies [c2bb0f1745]
|
|
85
|
+
- Updated dependencies [d5a31df781]
|
|
86
|
+
- Updated dependencies [dda38c9c3e]
|
|
87
|
+
- Updated dependencies [3bbea92b2a]
|
|
88
|
+
- Updated dependencies [b710adb843]
|
|
89
|
+
- Updated dependencies [ea7cf06]
|
|
90
|
+
- Updated dependencies [bbe4c4a]
|
|
91
|
+
- Updated dependencies [e4558a0]
|
|
92
|
+
- Updated dependencies [abf3421a75]
|
|
93
|
+
- Updated dependencies [543be9558e]
|
|
94
|
+
- Updated dependencies [14b712da84]
|
|
95
|
+
- @modern-js/server-utils@2.0.0-beta.4
|
|
96
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
97
|
+
- @modern-js/bff-core@2.0.0-beta.4
|
|
98
|
+
- @modern-js/create-request@2.0.0-beta.4
|
|
99
|
+
- @modern-js/babel-compiler@2.0.0-beta.4
|
|
100
|
+
|
|
3
101
|
## 2.0.0-beta.3
|
|
4
102
|
|
|
5
103
|
### Major Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -1,45 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import path from "path";
|
|
22
|
+
import {
|
|
23
|
+
fs,
|
|
24
|
+
API_DIR,
|
|
25
|
+
PLUGIN_SCHEMAS,
|
|
26
|
+
normalizeOutputPath,
|
|
27
|
+
SHARED_DIR,
|
|
28
|
+
isProd
|
|
29
|
+
} from "@modern-js/utils";
|
|
30
|
+
import { compile } from "@modern-js/server-utils";
|
|
31
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
5
32
|
import { registerModernRuntimePath } from "./helper";
|
|
6
|
-
const DEFAULT_API_PREFIX =
|
|
7
|
-
const TS_CONFIG_FILENAME =
|
|
8
|
-
|
|
9
|
-
name:
|
|
10
|
-
setup: api => {
|
|
33
|
+
const DEFAULT_API_PREFIX = "/api";
|
|
34
|
+
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
35
|
+
var cli_default = () => ({
|
|
36
|
+
name: "@modern-js/plugin-bff",
|
|
37
|
+
setup: (api) => {
|
|
11
38
|
let unRegisterResolveRuntimePath = null;
|
|
12
39
|
return {
|
|
13
40
|
validateSchema() {
|
|
14
|
-
return PLUGIN_SCHEMAS[
|
|
41
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
|
|
15
42
|
},
|
|
16
43
|
config() {
|
|
17
44
|
return {
|
|
18
45
|
tools: {
|
|
19
|
-
webpackChain: (chain, {
|
|
20
|
-
|
|
21
|
-
CHAIN_ID
|
|
22
|
-
}) => {
|
|
23
|
-
const {
|
|
24
|
-
appDirectory,
|
|
25
|
-
port
|
|
26
|
-
} = api.useAppContext();
|
|
46
|
+
webpackChain: (chain, { name, CHAIN_ID }) => {
|
|
47
|
+
const { appDirectory, port } = api.useAppContext();
|
|
27
48
|
const modernConfig = api.useResolvedConfigContext();
|
|
28
|
-
const {
|
|
29
|
-
|
|
30
|
-
} = modernConfig || {};
|
|
31
|
-
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
49
|
+
const { bff } = modernConfig || {};
|
|
50
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
32
51
|
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
33
|
-
chain.resolve.alias.set(
|
|
52
|
+
chain.resolve.alias.set("@api", rootDir);
|
|
34
53
|
const apiRouter = new ApiRouter({
|
|
35
54
|
apiDir: rootDir,
|
|
36
55
|
prefix
|
|
37
56
|
});
|
|
38
57
|
const lambdaDir = apiRouter.getLambdaDir();
|
|
39
58
|
const existLambda = apiRouter.isExistLambda();
|
|
40
|
-
const apiRegexp = new RegExp(
|
|
59
|
+
const apiRegexp = new RegExp(
|
|
60
|
+
normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`)
|
|
61
|
+
);
|
|
41
62
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
42
|
-
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use(
|
|
63
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
43
64
|
prefix,
|
|
44
65
|
apiDir: rootDir,
|
|
45
66
|
lambdaDir,
|
|
@@ -50,91 +71,89 @@ export default (() => ({
|
|
|
50
71
|
}
|
|
51
72
|
},
|
|
52
73
|
source: {
|
|
53
|
-
moduleScopes: [`./${API_DIR}`, /create-request/]
|
|
74
|
+
moduleScopes: [`./${API_DIR}`, /create-request/],
|
|
75
|
+
define: {
|
|
76
|
+
"process.env.PORT": JSON.stringify(process.env.PORT)
|
|
77
|
+
}
|
|
54
78
|
}
|
|
55
79
|
};
|
|
56
80
|
},
|
|
57
|
-
modifyServerRoutes({
|
|
58
|
-
routes
|
|
59
|
-
}) {
|
|
81
|
+
modifyServerRoutes({ routes }) {
|
|
60
82
|
const modernConfig = api.useResolvedConfigContext();
|
|
61
|
-
const {
|
|
62
|
-
|
|
63
|
-
} = modernConfig || {};
|
|
64
|
-
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
83
|
+
const { bff } = modernConfig || {};
|
|
84
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
|
|
65
85
|
const prefixList = [];
|
|
66
86
|
if (Array.isArray(prefix)) {
|
|
67
87
|
prefixList.push(...prefix);
|
|
68
88
|
} else {
|
|
69
89
|
prefixList.push(prefix);
|
|
70
90
|
}
|
|
71
|
-
const apiServerRoutes = prefixList.map(pre => ({
|
|
91
|
+
const apiServerRoutes = prefixList.map((pre) => ({
|
|
72
92
|
urlPath: pre,
|
|
73
93
|
isApi: true,
|
|
74
|
-
entryPath:
|
|
94
|
+
entryPath: "",
|
|
75
95
|
isSPA: false,
|
|
76
96
|
isSSR: false
|
|
77
|
-
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
78
97
|
}));
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
routes: routes.concat(apiServerRoutes)
|
|
82
|
-
};
|
|
98
|
+
return { routes: routes.concat(apiServerRoutes) };
|
|
83
99
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} = api.useAppContext();
|
|
90
|
-
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
91
|
-
}
|
|
100
|
+
collectServerPlugins({ plugins }) {
|
|
101
|
+
plugins.push({
|
|
102
|
+
"@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
|
|
103
|
+
});
|
|
104
|
+
return { plugins };
|
|
92
105
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
106
|
+
beforeBuild() {
|
|
107
|
+
return __async(this, null, function* () {
|
|
108
|
+
if (isProd()) {
|
|
109
|
+
const { internalDirectory } = api.useAppContext();
|
|
110
|
+
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
afterBuild() {
|
|
115
|
+
return __async(this, null, function* () {
|
|
116
|
+
if (unRegisterResolveRuntimePath) {
|
|
117
|
+
unRegisterResolveRuntimePath();
|
|
118
|
+
}
|
|
119
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
120
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
121
|
+
const distDir = path.resolve(distDirectory);
|
|
122
|
+
const apiDir = path.resolve(appDirectory, API_DIR);
|
|
123
|
+
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
124
|
+
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
125
|
+
const sourceDirs = [];
|
|
126
|
+
if (fs.existsSync(apiDir)) {
|
|
127
|
+
sourceDirs.push(apiDir);
|
|
128
|
+
}
|
|
129
|
+
if (fs.existsSync(sharedDir)) {
|
|
130
|
+
sourceDirs.push(sharedDir);
|
|
131
|
+
}
|
|
132
|
+
const { server } = modernConfig;
|
|
133
|
+
const { alias, define, globalVars } = modernConfig.source;
|
|
134
|
+
const { babel } = modernConfig.tools;
|
|
135
|
+
if (sourceDirs.length > 0) {
|
|
136
|
+
yield compile(
|
|
137
|
+
appDirectory,
|
|
138
|
+
{
|
|
139
|
+
server,
|
|
140
|
+
alias,
|
|
141
|
+
define,
|
|
142
|
+
globalVars,
|
|
143
|
+
babelConfig: babel
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
sourceDirs,
|
|
147
|
+
distDir,
|
|
148
|
+
tsconfigPath
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
137
153
|
}
|
|
138
154
|
};
|
|
139
155
|
}
|
|
140
|
-
})
|
|
156
|
+
});
|
|
157
|
+
export {
|
|
158
|
+
cli_default as default
|
|
159
|
+
};
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const API_APP_NAME = "_app";
|
|
2
|
+
const BUILD_FILES = [
|
|
3
|
+
"**/*.[tj]sx?",
|
|
4
|
+
"!**/*.test.jsx?",
|
|
5
|
+
"!**/*.test.tsx?",
|
|
6
|
+
"!**/*.spec.jsx?",
|
|
7
|
+
"!**/*.spec.tsx?",
|
|
8
|
+
"!__tests__/*.tsx?",
|
|
9
|
+
"!__tests__/*.jsx?"
|
|
10
|
+
];
|
|
11
|
+
export {
|
|
12
|
+
API_APP_NAME,
|
|
13
|
+
BUILD_FILES
|
|
14
|
+
};
|
package/dist/js/modern/helper.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
import { registerPaths } from
|
|
3
|
-
const serverRuntimeAlias =
|
|
4
|
-
const serverRuntimePath =
|
|
5
|
-
const registerModernRuntimePath = internalDirectory => {
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { registerPaths } from "@modern-js/bff-core";
|
|
3
|
+
const serverRuntimeAlias = "@modern-js/runtime/server";
|
|
4
|
+
const serverRuntimePath = ".runtime-exports/server";
|
|
5
|
+
const registerModernRuntimePath = (internalDirectory) => {
|
|
6
6
|
const paths = {
|
|
7
7
|
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
8
8
|
};
|
|
9
9
|
const unRegister = registerPaths(paths);
|
|
10
10
|
return unRegister;
|
|
11
11
|
};
|
|
12
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
registerModernRuntimePath
|
|
14
|
+
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./constants";
|
|
1
|
+
export * from "./constants";
|
package/dist/js/modern/loader.js
CHANGED
|
@@ -1,51 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { generateClient } from "@modern-js/bff-core";
|
|
22
|
+
import { logger } from "@modern-js/utils";
|
|
23
|
+
function loader(source) {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
this.cacheable();
|
|
26
|
+
const callback = this.async();
|
|
27
|
+
const draftOptions = this.getOptions();
|
|
28
|
+
const { resourcePath } = this;
|
|
29
|
+
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
30
|
+
if (!draftOptions.existLambda) {
|
|
31
|
+
logger.warn(warning);
|
|
32
|
+
callback(null, `throw new Error('${warning}')`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const options = {
|
|
36
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
37
|
+
apiDir: draftOptions.apiDir,
|
|
38
|
+
target: draftOptions.target,
|
|
39
|
+
port: Number(draftOptions.port),
|
|
40
|
+
source,
|
|
41
|
+
resourcePath
|
|
42
|
+
};
|
|
43
|
+
const { lambdaDir } = draftOptions;
|
|
44
|
+
if (!resourcePath.startsWith(lambdaDir)) {
|
|
45
|
+
logger.warn(warning);
|
|
46
|
+
callback(null, `throw new Error('${warning}')`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (draftOptions.fetcher) {
|
|
50
|
+
options.fetcher = draftOptions.fetcher;
|
|
51
|
+
}
|
|
52
|
+
if (draftOptions.requestCreator) {
|
|
53
|
+
options.requestCreator = draftOptions.requestCreator;
|
|
54
|
+
}
|
|
55
|
+
options.requireResolve = require.resolve;
|
|
56
|
+
const result = yield generateClient(options);
|
|
57
|
+
if (result.isOk) {
|
|
58
|
+
callback(void 0, result.value);
|
|
59
|
+
} else {
|
|
60
|
+
callback(void 0, `throw new Error('${result.value}')`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
50
63
|
}
|
|
51
|
-
|
|
64
|
+
var loader_default = loader;
|
|
65
|
+
export {
|
|
66
|
+
loader_default as default
|
|
67
|
+
};
|
package/dist/js/modern/server.js
CHANGED
|
@@ -1,62 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import path from "path";
|
|
21
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
22
|
+
import { API_DIR, isProd, requireExistModule } from "@modern-js/utils";
|
|
7
23
|
import { API_APP_NAME } from "./constants";
|
|
8
24
|
class Storage {
|
|
9
25
|
constructor() {
|
|
10
|
-
|
|
26
|
+
this.middlewares = [];
|
|
11
27
|
}
|
|
12
28
|
reset() {
|
|
13
29
|
this.middlewares = [];
|
|
14
30
|
}
|
|
15
31
|
}
|
|
16
|
-
const createTransformAPI = storage => ({
|
|
32
|
+
const createTransformAPI = (storage) => ({
|
|
17
33
|
addMiddleware(fn) {
|
|
18
34
|
storage.middlewares.push(fn);
|
|
19
35
|
}
|
|
20
36
|
});
|
|
21
|
-
|
|
22
|
-
name:
|
|
23
|
-
setup: api => {
|
|
37
|
+
var server_default = () => ({
|
|
38
|
+
name: "@modern-js/plugin-bff",
|
|
39
|
+
setup: (api) => {
|
|
24
40
|
const storage = new Storage();
|
|
25
41
|
const transformAPI = createTransformAPI(storage);
|
|
26
|
-
let apiAppPath =
|
|
42
|
+
let apiAppPath = "";
|
|
27
43
|
return {
|
|
28
44
|
prepare() {
|
|
29
|
-
const {
|
|
30
|
-
appDirectory,
|
|
31
|
-
distDirectory
|
|
32
|
-
} = api.useAppContext();
|
|
45
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
33
46
|
const root = isProd() ? distDirectory : appDirectory;
|
|
34
47
|
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
35
48
|
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
36
49
|
const apiMod = requireExistModule(apiAppPath);
|
|
37
|
-
if (apiMod && typeof apiMod ===
|
|
50
|
+
if (apiMod && typeof apiMod === "function") {
|
|
38
51
|
apiMod(transformAPI);
|
|
39
52
|
}
|
|
40
53
|
},
|
|
41
54
|
reset() {
|
|
42
55
|
storage.reset();
|
|
43
56
|
const newApiModule = requireExistModule(apiAppPath);
|
|
44
|
-
if (newApiModule && typeof newApiModule ===
|
|
57
|
+
if (newApiModule && typeof newApiModule === "function") {
|
|
45
58
|
newApiModule(transformAPI);
|
|
46
59
|
}
|
|
47
60
|
},
|
|
48
|
-
gather({
|
|
49
|
-
|
|
50
|
-
}) {
|
|
51
|
-
storage.middlewares.forEach(mid => {
|
|
61
|
+
gather({ addAPIMiddleware }) {
|
|
62
|
+
storage.middlewares.forEach((mid) => {
|
|
52
63
|
addAPIMiddleware(mid);
|
|
53
64
|
});
|
|
54
65
|
},
|
|
55
66
|
prepareApiServer(props, next) {
|
|
56
|
-
const {
|
|
57
|
-
pwd,
|
|
58
|
-
prefix
|
|
59
|
-
} = props;
|
|
67
|
+
const { pwd, prefix } = props;
|
|
60
68
|
const apiDir = path.resolve(pwd, API_DIR);
|
|
61
69
|
const appContext = api.useAppContext();
|
|
62
70
|
const apiRouter = new ApiRouter({
|
|
@@ -65,7 +73,7 @@ export default (() => ({
|
|
|
65
73
|
});
|
|
66
74
|
const apiMode = apiRouter.getApiMode();
|
|
67
75
|
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
68
|
-
api.setAppContext(
|
|
76
|
+
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
69
77
|
apiRouter,
|
|
70
78
|
apiHandlerInfos,
|
|
71
79
|
apiMode
|
|
@@ -74,4 +82,7 @@ export default (() => ({
|
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
}
|
|
77
|
-
})
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
server_default as default
|
|
88
|
+
};
|