@modern-js/plugin-bff 2.6.1-alpha.0 → 2.7.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 +27 -0
- package/dist/cjs/cli.js +3 -3
- package/dist/esm/cli.js +3 -2
- package/dist/esm-node/cli.js +3 -3
- package/dist/types/loader.d.ts +1 -1
- package/package.json +14 -14
- package/dist/js/modern/cli.js +0 -184
- package/dist/js/modern/constants.js +0 -14
- package/dist/js/modern/helper.js +0 -14
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/loader.js +0 -67
- package/dist/js/modern/server.js +0 -88
- package/dist/js/node/cli.js +0 -202
- package/dist/js/node/constants.js +0 -38
- package/dist/js/node/helper.js +0 -43
- package/dist/js/node/index.js +0 -17
- package/dist/js/node/loader.js +0 -88
- package/dist/js/node/server.js +0 -113
- package/dist/js/treeshaking/cli.js +0 -370
- package/dist/js/treeshaking/constants.js +0 -11
- package/dist/js/treeshaking/helper.js +0 -23
- package/dist/js/treeshaking/index.js +0 -1
- package/dist/js/treeshaking/loader.js +0 -191
- package/dist/js/treeshaking/server.js +0 -151
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 2.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
|
|
8
|
+
feat: 支持定制 api 目录,lambda 目录,bff 的写法
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 7bb1554194: fix: remove process.env.PORT from the bff generate client code
|
|
13
|
+
fix: 从 bff 的 generate client code 中移除 process.env.PORT
|
|
14
|
+
- 1eea234fdd: chore: make test files naming consistent
|
|
15
|
+
|
|
16
|
+
chore: 统一测试文件命名为小驼峰格式
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [0f15fc597c]
|
|
19
|
+
- Updated dependencies [dcad887024]
|
|
20
|
+
- Updated dependencies [a4672f7c16]
|
|
21
|
+
- Updated dependencies [7bb1554194]
|
|
22
|
+
- Updated dependencies [7fff9020e1]
|
|
23
|
+
- Updated dependencies [1eea234fdd]
|
|
24
|
+
- Updated dependencies [84bfb439b8]
|
|
25
|
+
- @modern-js/utils@2.7.0
|
|
26
|
+
- @modern-js/bff-core@2.7.0
|
|
27
|
+
- @modern-js/server-utils@2.7.0
|
|
28
|
+
- @modern-js/create-request@2.7.0
|
|
29
|
+
|
|
3
30
|
## 2.6.0
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/cjs/cli.js
CHANGED
|
@@ -48,12 +48,12 @@ var cli_default = () => ({
|
|
|
48
48
|
config() {
|
|
49
49
|
return {
|
|
50
50
|
tools: {
|
|
51
|
-
webpackChain: (chain, {
|
|
51
|
+
webpackChain: (chain, { CHAIN_ID, isServer }) => {
|
|
52
52
|
const { port, apiDirectory, lambdaDirectory } = api.useAppContext();
|
|
53
53
|
const modernConfig = api.useResolvedConfigContext();
|
|
54
54
|
const { bff } = modernConfig || {};
|
|
55
55
|
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
56
|
-
const
|
|
56
|
+
const httpMethodDecider = bff == null ? void 0 : bff.httpMethodDecider;
|
|
57
57
|
chain.resolve.alias.set("@api", apiDirectory);
|
|
58
58
|
const apiRouter = new import_bff_core.ApiRouter({
|
|
59
59
|
apiDir: apiDirectory,
|
|
@@ -66,6 +66,7 @@ var cli_default = () => ({
|
|
|
66
66
|
const apiRegexp = new RegExp(
|
|
67
67
|
(0, import_utils.normalizeOutputPath)(`${apiDirectory}${import_path.default.sep}.*(.[tj]s)$`)
|
|
68
68
|
);
|
|
69
|
+
const name = isServer ? "server" : "client";
|
|
69
70
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
70
71
|
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
71
72
|
prefix,
|
|
@@ -99,7 +100,6 @@ var cli_default = () => ({
|
|
|
99
100
|
entryPath: "",
|
|
100
101
|
isSPA: false,
|
|
101
102
|
isSSR: false
|
|
102
|
-
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
103
103
|
}));
|
|
104
104
|
if (bff == null ? void 0 : bff.enableHandleWeb) {
|
|
105
105
|
return {
|
package/dist/esm/cli.js
CHANGED
|
@@ -219,12 +219,12 @@ var cli_default = function() {
|
|
|
219
219
|
return {
|
|
220
220
|
tools: {
|
|
221
221
|
webpackChain: function(chain, param) {
|
|
222
|
-
var
|
|
222
|
+
var CHAIN_ID = param.CHAIN_ID, isServer = param.isServer;
|
|
223
223
|
var _api_useAppContext = api.useAppContext(), port = _api_useAppContext.port, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory;
|
|
224
224
|
var modernConfig = api.useResolvedConfigContext();
|
|
225
225
|
var bff = (modernConfig || {}).bff;
|
|
226
226
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
227
|
-
var httpMethodDecider = bff.httpMethodDecider;
|
|
227
|
+
var httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
|
|
228
228
|
chain.resolve.alias.set("@api", apiDirectory);
|
|
229
229
|
var apiRouter = new ApiRouter({
|
|
230
230
|
apiDir: apiDirectory,
|
|
@@ -235,6 +235,7 @@ var cli_default = function() {
|
|
|
235
235
|
var lambdaDir = apiRouter.getLambdaDir();
|
|
236
236
|
var existLambda = apiRouter.isExistLambda();
|
|
237
237
|
var apiRegexp = new RegExp(normalizeOutputPath("".concat(apiDirectory).concat(path.sep, ".*(.[tj]s)$")));
|
|
238
|
+
var name = isServer ? "server" : "client";
|
|
238
239
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
239
240
|
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
240
241
|
prefix: prefix,
|
package/dist/esm-node/cli.js
CHANGED
|
@@ -23,12 +23,12 @@ var cli_default = () => ({
|
|
|
23
23
|
config() {
|
|
24
24
|
return {
|
|
25
25
|
tools: {
|
|
26
|
-
webpackChain: (chain, {
|
|
26
|
+
webpackChain: (chain, { CHAIN_ID, isServer }) => {
|
|
27
27
|
const { port, apiDirectory, lambdaDirectory } = api.useAppContext();
|
|
28
28
|
const modernConfig = api.useResolvedConfigContext();
|
|
29
29
|
const { bff } = modernConfig || {};
|
|
30
30
|
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
31
|
-
const
|
|
31
|
+
const httpMethodDecider = bff == null ? void 0 : bff.httpMethodDecider;
|
|
32
32
|
chain.resolve.alias.set("@api", apiDirectory);
|
|
33
33
|
const apiRouter = new ApiRouter({
|
|
34
34
|
apiDir: apiDirectory,
|
|
@@ -41,6 +41,7 @@ var cli_default = () => ({
|
|
|
41
41
|
const apiRegexp = new RegExp(
|
|
42
42
|
normalizeOutputPath(`${apiDirectory}${path.sep}.*(.[tj]s)$`)
|
|
43
43
|
);
|
|
44
|
+
const name = isServer ? "server" : "client";
|
|
44
45
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
45
46
|
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
46
47
|
prefix,
|
|
@@ -74,7 +75,6 @@ var cli_default = () => ({
|
|
|
74
75
|
entryPath: "",
|
|
75
76
|
isSPA: false,
|
|
76
77
|
isSSR: false
|
|
77
|
-
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
78
78
|
}));
|
|
79
79
|
if (bff == null ? void 0 : bff.enableHandleWeb) {
|
|
80
80
|
return {
|
package/dist/types/loader.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type APILoaderOptions = {
|
|
|
9
9
|
fetcher?: string;
|
|
10
10
|
requestCreator?: string;
|
|
11
11
|
target: string;
|
|
12
|
-
httpMethodDecider
|
|
12
|
+
httpMethodDecider?: HttpMethodDecider;
|
|
13
13
|
};
|
|
14
14
|
declare function loader(this: LoaderContext<APILoaderOptions>, source: string): Promise<void>;
|
|
15
15
|
export default loader;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.7.0",
|
|
15
15
|
"jsnext:source": "./src/cli.ts",
|
|
16
16
|
"types": "./dist/types/cli.d.ts",
|
|
17
17
|
"main": "./dist/cjs/cli.js",
|
|
@@ -50,20 +50,12 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@babel/core": "^7.18.0",
|
|
52
52
|
"@babel/runtime": "^7.18.0",
|
|
53
|
-
"@modern-js/bff-core": "2.
|
|
54
|
-
"@modern-js/create-request": "2.
|
|
55
|
-
"@modern-js/server-utils": "2.
|
|
56
|
-
"@modern-js/utils": "2.
|
|
53
|
+
"@modern-js/bff-core": "2.7.0",
|
|
54
|
+
"@modern-js/create-request": "2.7.0",
|
|
55
|
+
"@modern-js/server-utils": "2.7.0",
|
|
56
|
+
"@modern-js/utils": "2.7.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@modern-js/runtime": "2.6.0",
|
|
60
|
-
"@modern-js/core": "2.6.0",
|
|
61
|
-
"@modern-js/bff-runtime": "2.6.0",
|
|
62
|
-
"@modern-js/server-core": "2.6.0",
|
|
63
|
-
"@modern-js/types": "2.6.0",
|
|
64
|
-
"@modern-js/app-tools": "2.6.0",
|
|
65
|
-
"@scripts/build": "2.6.0",
|
|
66
|
-
"@scripts/jest-config": "2.6.0",
|
|
67
59
|
"@types/babel__core": "^7.1.15",
|
|
68
60
|
"@types/jest": "^27",
|
|
69
61
|
"@types/node": "^14",
|
|
@@ -72,7 +64,15 @@
|
|
|
72
64
|
"ts-jest": "^27.0.5",
|
|
73
65
|
"typescript": "^4",
|
|
74
66
|
"webpack": "^5.75.0",
|
|
75
|
-
"webpack-chain": "^6.5.1"
|
|
67
|
+
"webpack-chain": "^6.5.1",
|
|
68
|
+
"@modern-js/runtime": "2.7.0",
|
|
69
|
+
"@modern-js/core": "2.7.0",
|
|
70
|
+
"@modern-js/bff-runtime": "2.7.0",
|
|
71
|
+
"@modern-js/server-core": "2.7.0",
|
|
72
|
+
"@modern-js/types": "2.7.0",
|
|
73
|
+
"@modern-js/app-tools": "2.7.0",
|
|
74
|
+
"@scripts/build": "2.7.0",
|
|
75
|
+
"@scripts/jest-config": "2.7.0"
|
|
76
76
|
},
|
|
77
77
|
"sideEffects": false,
|
|
78
78
|
"publishConfig": {
|
package/dist/js/modern/cli.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
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
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
import path from "path";
|
|
41
|
-
import {
|
|
42
|
-
fs,
|
|
43
|
-
API_DIR,
|
|
44
|
-
PLUGIN_SCHEMAS,
|
|
45
|
-
normalizeOutputPath,
|
|
46
|
-
SHARED_DIR,
|
|
47
|
-
isProd
|
|
48
|
-
} from "@modern-js/utils";
|
|
49
|
-
import { compile } from "@modern-js/server-utils";
|
|
50
|
-
import { ApiRouter } from "@modern-js/bff-core";
|
|
51
|
-
import { registerModernRuntimePath } from "./helper";
|
|
52
|
-
const DEFAULT_API_PREFIX = "/api";
|
|
53
|
-
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
54
|
-
var cli_default = () => ({
|
|
55
|
-
name: "@modern-js/plugin-bff",
|
|
56
|
-
setup: (api) => {
|
|
57
|
-
let unRegisterResolveRuntimePath = null;
|
|
58
|
-
return {
|
|
59
|
-
validateSchema() {
|
|
60
|
-
return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
|
|
61
|
-
},
|
|
62
|
-
config() {
|
|
63
|
-
return {
|
|
64
|
-
tools: {
|
|
65
|
-
webpackChain: (chain, { name, CHAIN_ID }) => {
|
|
66
|
-
const { appDirectory, port } = api.useAppContext();
|
|
67
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
68
|
-
const { bff } = modernConfig || {};
|
|
69
|
-
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
70
|
-
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
71
|
-
chain.resolve.alias.set("@api", rootDir);
|
|
72
|
-
const apiRouter = new ApiRouter({
|
|
73
|
-
apiDir: rootDir,
|
|
74
|
-
prefix
|
|
75
|
-
});
|
|
76
|
-
const lambdaDir = apiRouter.getLambdaDir();
|
|
77
|
-
const existLambda = apiRouter.isExistLambda();
|
|
78
|
-
const apiRegexp = new RegExp(
|
|
79
|
-
normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`)
|
|
80
|
-
);
|
|
81
|
-
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
82
|
-
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
83
|
-
prefix,
|
|
84
|
-
apiDir: rootDir,
|
|
85
|
-
lambdaDir,
|
|
86
|
-
existLambda,
|
|
87
|
-
port,
|
|
88
|
-
target: name
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
source: {
|
|
93
|
-
moduleScopes: [`./${API_DIR}`, /create-request/]
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
modifyServerRoutes({ routes }) {
|
|
98
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
99
|
-
const { bff } = modernConfig || {};
|
|
100
|
-
const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
|
|
101
|
-
const prefixList = [];
|
|
102
|
-
if (Array.isArray(prefix)) {
|
|
103
|
-
prefixList.push(...prefix);
|
|
104
|
-
} else {
|
|
105
|
-
prefixList.push(prefix);
|
|
106
|
-
}
|
|
107
|
-
const apiServerRoutes = prefixList.map((pre) => ({
|
|
108
|
-
urlPath: pre,
|
|
109
|
-
isApi: true,
|
|
110
|
-
entryPath: "",
|
|
111
|
-
isSPA: false,
|
|
112
|
-
isSSR: false
|
|
113
|
-
}));
|
|
114
|
-
if (bff == null ? void 0 : bff.enableHandleWeb) {
|
|
115
|
-
return {
|
|
116
|
-
routes: routes.map((route) => {
|
|
117
|
-
return __spreadProps(__spreadValues({}, route), {
|
|
118
|
-
isApi: true
|
|
119
|
-
});
|
|
120
|
-
}).concat(apiServerRoutes)
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
return { routes: routes.concat(apiServerRoutes) };
|
|
124
|
-
},
|
|
125
|
-
collectServerPlugins({ plugins }) {
|
|
126
|
-
plugins.push({
|
|
127
|
-
"@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
|
|
128
|
-
});
|
|
129
|
-
return { plugins };
|
|
130
|
-
},
|
|
131
|
-
beforeBuild() {
|
|
132
|
-
return __async(this, null, function* () {
|
|
133
|
-
if (isProd()) {
|
|
134
|
-
const { internalDirectory } = api.useAppContext();
|
|
135
|
-
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
afterBuild() {
|
|
140
|
-
return __async(this, null, function* () {
|
|
141
|
-
if (unRegisterResolveRuntimePath) {
|
|
142
|
-
unRegisterResolveRuntimePath();
|
|
143
|
-
}
|
|
144
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
|
145
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
146
|
-
const distDir = path.resolve(distDirectory);
|
|
147
|
-
const apiDir = path.resolve(appDirectory, API_DIR);
|
|
148
|
-
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
149
|
-
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
150
|
-
const sourceDirs = [];
|
|
151
|
-
if (fs.existsSync(apiDir)) {
|
|
152
|
-
sourceDirs.push(apiDir);
|
|
153
|
-
}
|
|
154
|
-
if (fs.existsSync(sharedDir)) {
|
|
155
|
-
sourceDirs.push(sharedDir);
|
|
156
|
-
}
|
|
157
|
-
const { server } = modernConfig;
|
|
158
|
-
const { alias, define, globalVars } = modernConfig.source;
|
|
159
|
-
const { babel } = modernConfig.tools;
|
|
160
|
-
if (sourceDirs.length > 0) {
|
|
161
|
-
yield compile(
|
|
162
|
-
appDirectory,
|
|
163
|
-
{
|
|
164
|
-
server,
|
|
165
|
-
alias,
|
|
166
|
-
define,
|
|
167
|
-
globalVars,
|
|
168
|
-
babelConfig: babel
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
sourceDirs,
|
|
172
|
-
distDir,
|
|
173
|
-
tsconfigPath
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
export {
|
|
183
|
-
cli_default as default
|
|
184
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
const paths = {
|
|
7
|
-
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
8
|
-
};
|
|
9
|
-
const unRegister = registerPaths(paths);
|
|
10
|
-
return unRegister;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
registerModernRuntimePath
|
|
14
|
-
};
|
package/dist/js/modern/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
package/dist/js/modern/loader.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
});
|
|
63
|
-
}
|
|
64
|
-
var loader_default = loader;
|
|
65
|
-
export {
|
|
66
|
-
loader_default as default
|
|
67
|
-
};
|
package/dist/js/modern/server.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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";
|
|
23
|
-
import { API_APP_NAME } from "./constants";
|
|
24
|
-
class Storage {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.middlewares = [];
|
|
27
|
-
}
|
|
28
|
-
reset() {
|
|
29
|
-
this.middlewares = [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const createTransformAPI = (storage) => ({
|
|
33
|
-
addMiddleware(fn) {
|
|
34
|
-
storage.middlewares.push(fn);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
var server_default = () => ({
|
|
38
|
-
name: "@modern-js/plugin-bff",
|
|
39
|
-
setup: (api) => {
|
|
40
|
-
const storage = new Storage();
|
|
41
|
-
const transformAPI = createTransformAPI(storage);
|
|
42
|
-
let apiAppPath = "";
|
|
43
|
-
return {
|
|
44
|
-
prepare() {
|
|
45
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
|
46
|
-
const root = isProd() ? distDirectory : appDirectory;
|
|
47
|
-
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
48
|
-
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
49
|
-
const apiMod = requireExistModule(apiAppPath);
|
|
50
|
-
if (apiMod && typeof apiMod === "function") {
|
|
51
|
-
apiMod(transformAPI);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
reset() {
|
|
55
|
-
storage.reset();
|
|
56
|
-
const newApiModule = requireExistModule(apiAppPath);
|
|
57
|
-
if (newApiModule && typeof newApiModule === "function") {
|
|
58
|
-
newApiModule(transformAPI);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
gather({ addAPIMiddleware }) {
|
|
62
|
-
storage.middlewares.forEach((mid) => {
|
|
63
|
-
addAPIMiddleware(mid);
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
prepareApiServer(props, next) {
|
|
67
|
-
const { pwd, prefix } = props;
|
|
68
|
-
const apiDir = path.resolve(pwd, API_DIR);
|
|
69
|
-
const appContext = api.useAppContext();
|
|
70
|
-
const apiRouter = new ApiRouter({
|
|
71
|
-
apiDir,
|
|
72
|
-
prefix
|
|
73
|
-
});
|
|
74
|
-
const apiMode = apiRouter.getApiMode();
|
|
75
|
-
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
76
|
-
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
77
|
-
apiRouter,
|
|
78
|
-
apiHandlerInfos,
|
|
79
|
-
apiMode
|
|
80
|
-
}));
|
|
81
|
-
return next(props);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
export {
|
|
87
|
-
server_default as default
|
|
88
|
-
};
|