@modern-js/plugin-bff 2.56.2 → 2.57.1-alpha.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/cjs/cli.js +5 -15
- package/dist/cjs/server.js +9 -14
- package/dist/esm/cli.js +21 -29
- package/dist/esm/server.js +95 -72
- package/dist/esm-node/cli.js +6 -16
- package/dist/esm-node/server.js +9 -14
- package/package.json +14 -13
package/dist/cjs/cli.js
CHANGED
|
@@ -36,13 +36,11 @@ var import_path = __toESM(require("path"));
|
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_server_utils = require("@modern-js/server-utils");
|
|
38
38
|
var import_bff_core = require("@modern-js/bff-core");
|
|
39
|
-
var import_helper = require("./helper");
|
|
40
39
|
const DEFAULT_API_PREFIX = "/api";
|
|
41
40
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
42
41
|
const bffPlugin = () => ({
|
|
43
42
|
name: "@modern-js/plugin-bff",
|
|
44
43
|
setup: (api) => {
|
|
45
|
-
let unRegisterResolveRuntimePath = null;
|
|
46
44
|
return {
|
|
47
45
|
config() {
|
|
48
46
|
return {
|
|
@@ -129,27 +127,18 @@ const bffPlugin = () => ({
|
|
|
129
127
|
plugins
|
|
130
128
|
};
|
|
131
129
|
},
|
|
132
|
-
async beforeBuild() {
|
|
133
|
-
if ((0, import_utils.isProd)()) {
|
|
134
|
-
const { internalDirectory } = api.useAppContext();
|
|
135
|
-
unRegisterResolveRuntimePath = (0, import_helper.registerModernRuntimePath)(internalDirectory);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
130
|
async afterBuild() {
|
|
139
|
-
|
|
140
|
-
unRegisterResolveRuntimePath();
|
|
141
|
-
}
|
|
142
|
-
const { appDirectory, distDirectory, apiDirectory, sharedDirectory } = api.useAppContext();
|
|
131
|
+
const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.useAppContext();
|
|
143
132
|
const modernConfig = api.useResolvedConfigContext();
|
|
144
133
|
const distDir = import_path.default.resolve(distDirectory);
|
|
145
134
|
const apiDir = apiDirectory || import_path.default.resolve(appDirectory, import_utils.API_DIR);
|
|
146
135
|
const sharedDir = sharedDirectory || import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
|
147
136
|
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
148
137
|
const sourceDirs = [];
|
|
149
|
-
if (import_utils.fs.
|
|
138
|
+
if (await import_utils.fs.pathExists(apiDir)) {
|
|
150
139
|
sourceDirs.push(apiDir);
|
|
151
140
|
}
|
|
152
|
-
if (import_utils.fs.
|
|
141
|
+
if (await import_utils.fs.pathExists(sharedDir)) {
|
|
153
142
|
sourceDirs.push(sharedDir);
|
|
154
143
|
}
|
|
155
144
|
const { server } = modernConfig;
|
|
@@ -163,7 +152,8 @@ const bffPlugin = () => ({
|
|
|
163
152
|
}, {
|
|
164
153
|
sourceDirs,
|
|
165
154
|
distDir,
|
|
166
|
-
tsconfigPath
|
|
155
|
+
tsconfigPath,
|
|
156
|
+
moduleType
|
|
167
157
|
});
|
|
168
158
|
}
|
|
169
159
|
}
|
package/dist/cjs/server.js
CHANGED
|
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(server_exports);
|
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_bff_core = require("@modern-js/bff-core");
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
|
-
var import_server_core = require("@modern-js/server-core");
|
|
38
37
|
var import_constants = require("./constants");
|
|
39
38
|
class Storage {
|
|
40
39
|
reset() {
|
|
@@ -60,11 +59,11 @@ var server_default = () => ({
|
|
|
60
59
|
async prepare() {
|
|
61
60
|
var _config_bff, _config_bff1, _config_bff2;
|
|
62
61
|
const appContext = api.useAppContext();
|
|
63
|
-
const { appDirectory, distDirectory } = appContext;
|
|
62
|
+
const { appDirectory, distDirectory, render } = appContext;
|
|
64
63
|
const root = (0, import_utils.isProd)() ? distDirectory : appDirectory;
|
|
65
64
|
const apiPath = import_path.default.resolve(root || process.cwd(), import_utils.API_DIR);
|
|
66
65
|
apiAppPath = import_path.default.resolve(apiPath, import_constants.API_APP_NAME);
|
|
67
|
-
const apiMod = (0, import_utils.requireExistModule)(apiAppPath);
|
|
66
|
+
const apiMod = await (0, import_utils.requireExistModule)(apiAppPath);
|
|
68
67
|
if (apiMod && typeof apiMod === "function") {
|
|
69
68
|
apiMod(transformAPI);
|
|
70
69
|
}
|
|
@@ -77,7 +76,7 @@ var server_default = () => ({
|
|
|
77
76
|
const prefix = (config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
|
|
78
77
|
const enableHandleWeb = config === null || config === void 0 ? void 0 : (_config_bff1 = config.bff) === null || _config_bff1 === void 0 ? void 0 : _config_bff1.enableHandleWeb;
|
|
79
78
|
const httpMethodDecider = config === null || config === void 0 ? void 0 : (_config_bff2 = config.bff) === null || _config_bff2 === void 0 ? void 0 : _config_bff2.httpMethodDecider;
|
|
80
|
-
const { distDirectory: pwd,
|
|
79
|
+
const { distDirectory: pwd, middlewares: globalMiddlewares } = api.useAppContext();
|
|
81
80
|
const webOnly = await (0, import_utils.isWebOnly)();
|
|
82
81
|
let handler;
|
|
83
82
|
if (webOnly) {
|
|
@@ -87,11 +86,7 @@ var server_default = () => ({
|
|
|
87
86
|
};
|
|
88
87
|
} else {
|
|
89
88
|
const runner = api.useHookRunners();
|
|
90
|
-
const renderHandler = enableHandleWeb ?
|
|
91
|
-
pwd,
|
|
92
|
-
routes: routes || [],
|
|
93
|
-
config
|
|
94
|
-
}) : null;
|
|
89
|
+
const renderHandler = enableHandleWeb ? render : null;
|
|
95
90
|
handler = await runner.prepareApiServer({
|
|
96
91
|
pwd,
|
|
97
92
|
prefix,
|
|
@@ -120,10 +115,10 @@ var server_default = () => ({
|
|
|
120
115
|
});
|
|
121
116
|
}
|
|
122
117
|
},
|
|
123
|
-
reset({ event }) {
|
|
118
|
+
async reset({ event }) {
|
|
124
119
|
storage.reset();
|
|
125
120
|
const appContext = api.useAppContext();
|
|
126
|
-
const newApiModule = (0, import_utils.requireExistModule)(apiAppPath);
|
|
121
|
+
const newApiModule = await (0, import_utils.requireExistModule)(apiAppPath);
|
|
127
122
|
if (newApiModule && typeof newApiModule === "function") {
|
|
128
123
|
newApiModule(transformAPI);
|
|
129
124
|
}
|
|
@@ -133,7 +128,7 @@ var server_default = () => ({
|
|
|
133
128
|
apiMiddlewares: middlewares
|
|
134
129
|
});
|
|
135
130
|
if (event.type === "file-change") {
|
|
136
|
-
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
131
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
137
132
|
const appContext2 = api.useAppContext();
|
|
138
133
|
api.setAppContext({
|
|
139
134
|
...appContext2,
|
|
@@ -141,7 +136,7 @@ var server_default = () => ({
|
|
|
141
136
|
});
|
|
142
137
|
}
|
|
143
138
|
},
|
|
144
|
-
prepareApiServer(props, next) {
|
|
139
|
+
async prepareApiServer(props, next) {
|
|
145
140
|
const { pwd, prefix, httpMethodDecider } = props;
|
|
146
141
|
const apiDir = import_path.default.resolve(pwd, import_utils.API_DIR);
|
|
147
142
|
const appContext = api.useAppContext();
|
|
@@ -154,7 +149,7 @@ var server_default = () => ({
|
|
|
154
149
|
httpMethodDecider
|
|
155
150
|
});
|
|
156
151
|
const apiMode = apiRouter.getApiMode();
|
|
157
|
-
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
152
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
158
153
|
api.setAppContext({
|
|
159
154
|
...appContext,
|
|
160
155
|
apiRouter,
|
package/dist/esm/cli.js
CHANGED
|
@@ -4,17 +4,15 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import { fs, API_DIR, normalizeOutputPath, SHARED_DIR
|
|
7
|
+
import { fs, API_DIR, normalizeOutputPath, SHARED_DIR } from "@modern-js/utils";
|
|
8
8
|
import { compile } from "@modern-js/server-utils";
|
|
9
9
|
import { ApiRouter } from "@modern-js/bff-core";
|
|
10
|
-
import { registerModernRuntimePath } from "./helper";
|
|
11
10
|
var DEFAULT_API_PREFIX = "/api";
|
|
12
11
|
var TS_CONFIG_FILENAME = "tsconfig.json";
|
|
13
12
|
var bffPlugin = function() {
|
|
14
13
|
return {
|
|
15
14
|
name: "@modern-js/plugin-bff",
|
|
16
15
|
setup: function(api) {
|
|
17
|
-
var unRegisterResolveRuntimePath = null;
|
|
18
16
|
return {
|
|
19
17
|
config: function config() {
|
|
20
18
|
return {
|
|
@@ -106,40 +104,33 @@ var bffPlugin = function() {
|
|
|
106
104
|
plugins
|
|
107
105
|
};
|
|
108
106
|
},
|
|
109
|
-
beforeBuild: function beforeBuild() {
|
|
110
|
-
return _async_to_generator(function() {
|
|
111
|
-
var internalDirectory;
|
|
112
|
-
return _ts_generator(this, function(_state) {
|
|
113
|
-
if (isProd()) {
|
|
114
|
-
internalDirectory = api.useAppContext().internalDirectory;
|
|
115
|
-
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
116
|
-
}
|
|
117
|
-
return [
|
|
118
|
-
2
|
|
119
|
-
];
|
|
120
|
-
});
|
|
121
|
-
})();
|
|
122
|
-
},
|
|
123
107
|
afterBuild: function afterBuild() {
|
|
124
108
|
return _async_to_generator(function() {
|
|
125
|
-
var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
|
109
|
+
var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
|
126
110
|
return _ts_generator(this, function(_state) {
|
|
127
111
|
switch (_state.label) {
|
|
128
112
|
case 0:
|
|
129
|
-
|
|
130
|
-
unRegisterResolveRuntimePath();
|
|
131
|
-
}
|
|
132
|
-
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory;
|
|
113
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory, moduleType = _api_useAppContext.moduleType;
|
|
133
114
|
modernConfig = api.useResolvedConfigContext();
|
|
134
115
|
distDir = path.resolve(distDirectory);
|
|
135
116
|
apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
|
|
136
117
|
sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
|
|
137
118
|
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
138
119
|
sourceDirs = [];
|
|
139
|
-
|
|
120
|
+
return [
|
|
121
|
+
4,
|
|
122
|
+
fs.pathExists(apiDir)
|
|
123
|
+
];
|
|
124
|
+
case 1:
|
|
125
|
+
if (_state.sent()) {
|
|
140
126
|
sourceDirs.push(apiDir);
|
|
141
127
|
}
|
|
142
|
-
|
|
128
|
+
return [
|
|
129
|
+
4,
|
|
130
|
+
fs.pathExists(sharedDir)
|
|
131
|
+
];
|
|
132
|
+
case 2:
|
|
133
|
+
if (_state.sent()) {
|
|
143
134
|
sourceDirs.push(sharedDir);
|
|
144
135
|
}
|
|
145
136
|
server = modernConfig.server;
|
|
@@ -148,7 +139,7 @@ var bffPlugin = function() {
|
|
|
148
139
|
if (!(sourceDirs.length > 0))
|
|
149
140
|
return [
|
|
150
141
|
3,
|
|
151
|
-
|
|
142
|
+
4
|
|
152
143
|
];
|
|
153
144
|
return [
|
|
154
145
|
4,
|
|
@@ -159,13 +150,14 @@ var bffPlugin = function() {
|
|
|
159
150
|
}, {
|
|
160
151
|
sourceDirs,
|
|
161
152
|
distDir,
|
|
162
|
-
tsconfigPath
|
|
153
|
+
tsconfigPath,
|
|
154
|
+
moduleType
|
|
163
155
|
})
|
|
164
156
|
];
|
|
165
|
-
case
|
|
157
|
+
case 3:
|
|
166
158
|
_state.sent();
|
|
167
|
-
_state.label =
|
|
168
|
-
case
|
|
159
|
+
_state.label = 4;
|
|
160
|
+
case 4:
|
|
169
161
|
return [
|
|
170
162
|
2
|
|
171
163
|
];
|
package/dist/esm/server.js
CHANGED
|
@@ -6,7 +6,6 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { ApiRouter } from "@modern-js/bff-core";
|
|
8
8
|
import { API_DIR, isProd, isWebOnly, requireExistModule } from "@modern-js/utils";
|
|
9
|
-
import { getRenderHandler } from "@modern-js/server-core";
|
|
10
9
|
import { API_APP_NAME } from "./constants";
|
|
11
10
|
var Storage = /* @__PURE__ */ function() {
|
|
12
11
|
"use strict";
|
|
@@ -38,16 +37,21 @@ function server_default() {
|
|
|
38
37
|
return {
|
|
39
38
|
prepare: function prepare() {
|
|
40
39
|
return _async_to_generator(function() {
|
|
41
|
-
var _config_bff, _config_bff1, _config_bff2, appContext, appDirectory, distDirectory, root, apiPath, apiMod, middlewares, config, prefix, enableHandleWeb, httpMethodDecider, _api_useAppContext, pwd,
|
|
40
|
+
var _config_bff, _config_bff1, _config_bff2, appContext, appDirectory, distDirectory, render, root, apiPath, apiMod, middlewares, config, prefix, enableHandleWeb, httpMethodDecider, _api_useAppContext, pwd, globalMiddlewares, webOnly, handler, runner, renderHandler;
|
|
42
41
|
return _ts_generator(this, function(_state) {
|
|
43
42
|
switch (_state.label) {
|
|
44
43
|
case 0:
|
|
45
44
|
appContext = api.useAppContext();
|
|
46
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
|
|
45
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, render = appContext.render;
|
|
47
46
|
root = isProd() ? distDirectory : appDirectory;
|
|
48
47
|
apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
49
48
|
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
50
|
-
|
|
49
|
+
return [
|
|
50
|
+
4,
|
|
51
|
+
requireExistModule(apiAppPath)
|
|
52
|
+
];
|
|
53
|
+
case 1:
|
|
54
|
+
apiMod = _state.sent();
|
|
51
55
|
if (apiMod && typeof apiMod === "function") {
|
|
52
56
|
apiMod(transformAPI);
|
|
53
57
|
}
|
|
@@ -59,17 +63,17 @@ function server_default() {
|
|
|
59
63
|
prefix = (config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
|
|
60
64
|
enableHandleWeb = config === null || config === void 0 ? void 0 : (_config_bff1 = config.bff) === null || _config_bff1 === void 0 ? void 0 : _config_bff1.enableHandleWeb;
|
|
61
65
|
httpMethodDecider = config === null || config === void 0 ? void 0 : (_config_bff2 = config.bff) === null || _config_bff2 === void 0 ? void 0 : _config_bff2.httpMethodDecider;
|
|
62
|
-
_api_useAppContext = api.useAppContext(), pwd = _api_useAppContext.distDirectory,
|
|
66
|
+
_api_useAppContext = api.useAppContext(), pwd = _api_useAppContext.distDirectory, globalMiddlewares = _api_useAppContext.middlewares;
|
|
63
67
|
return [
|
|
64
68
|
4,
|
|
65
69
|
isWebOnly()
|
|
66
70
|
];
|
|
67
|
-
case
|
|
71
|
+
case 2:
|
|
68
72
|
webOnly = _state.sent();
|
|
69
73
|
if (!webOnly)
|
|
70
74
|
return [
|
|
71
75
|
3,
|
|
72
|
-
|
|
76
|
+
3
|
|
73
77
|
];
|
|
74
78
|
handler = function() {
|
|
75
79
|
var _ref = _async_to_generator(function(c, next) {
|
|
@@ -93,36 +97,13 @@ function server_default() {
|
|
|
93
97
|
return _ref.apply(this, arguments);
|
|
94
98
|
};
|
|
95
99
|
}();
|
|
96
|
-
return [
|
|
97
|
-
3,
|
|
98
|
-
7
|
|
99
|
-
];
|
|
100
|
-
case 2:
|
|
101
|
-
runner = api.useHookRunners();
|
|
102
|
-
if (!enableHandleWeb)
|
|
103
|
-
return [
|
|
104
|
-
3,
|
|
105
|
-
4
|
|
106
|
-
];
|
|
107
|
-
return [
|
|
108
|
-
4,
|
|
109
|
-
getRenderHandler({
|
|
110
|
-
pwd,
|
|
111
|
-
routes: routes || [],
|
|
112
|
-
config
|
|
113
|
-
})
|
|
114
|
-
];
|
|
115
|
-
case 3:
|
|
116
|
-
_tmp = _state.sent();
|
|
117
100
|
return [
|
|
118
101
|
3,
|
|
119
102
|
5
|
|
120
103
|
];
|
|
121
|
-
case
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case 5:
|
|
125
|
-
renderHandler = _tmp;
|
|
104
|
+
case 3:
|
|
105
|
+
runner = api.useHookRunners();
|
|
106
|
+
renderHandler = enableHandleWeb ? render : null;
|
|
126
107
|
return [
|
|
127
108
|
4,
|
|
128
109
|
runner.prepareApiServer({
|
|
@@ -136,10 +117,10 @@ function server_default() {
|
|
|
136
117
|
}
|
|
137
118
|
})
|
|
138
119
|
];
|
|
139
|
-
case
|
|
120
|
+
case 4:
|
|
140
121
|
handler = _state.sent();
|
|
141
|
-
_state.label =
|
|
142
|
-
case
|
|
122
|
+
_state.label = 5;
|
|
123
|
+
case 5:
|
|
143
124
|
if (handler) {
|
|
144
125
|
globalMiddlewares.push({
|
|
145
126
|
name: "bind-bff",
|
|
@@ -167,44 +148,86 @@ function server_default() {
|
|
|
167
148
|
},
|
|
168
149
|
reset: function reset(param) {
|
|
169
150
|
var event = param.event;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
151
|
+
return _async_to_generator(function() {
|
|
152
|
+
var appContext, newApiModule, middlewares, apiHandlerInfos, appContext1;
|
|
153
|
+
return _ts_generator(this, function(_state) {
|
|
154
|
+
switch (_state.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
storage.reset();
|
|
157
|
+
appContext = api.useAppContext();
|
|
158
|
+
return [
|
|
159
|
+
4,
|
|
160
|
+
requireExistModule(apiAppPath)
|
|
161
|
+
];
|
|
162
|
+
case 1:
|
|
163
|
+
newApiModule = _state.sent();
|
|
164
|
+
if (newApiModule && typeof newApiModule === "function") {
|
|
165
|
+
newApiModule(transformAPI);
|
|
166
|
+
}
|
|
167
|
+
middlewares = storage.middlewares;
|
|
168
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
|
169
|
+
apiMiddlewares: middlewares
|
|
170
|
+
}));
|
|
171
|
+
if (!(event.type === "file-change"))
|
|
172
|
+
return [
|
|
173
|
+
3,
|
|
174
|
+
3
|
|
175
|
+
];
|
|
176
|
+
return [
|
|
177
|
+
4,
|
|
178
|
+
apiRouter.getApiHandlers()
|
|
179
|
+
];
|
|
180
|
+
case 2:
|
|
181
|
+
apiHandlerInfos = _state.sent();
|
|
182
|
+
appContext1 = api.useAppContext();
|
|
183
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext1), {
|
|
184
|
+
apiHandlerInfos
|
|
185
|
+
}));
|
|
186
|
+
_state.label = 3;
|
|
187
|
+
case 3:
|
|
188
|
+
return [
|
|
189
|
+
2
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})();
|
|
187
194
|
},
|
|
188
195
|
prepareApiServer: function prepareApiServer(props, next) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
return _async_to_generator(function() {
|
|
197
|
+
var pwd, prefix, httpMethodDecider, apiDir, appContext, apiDirectory, lambdaDirectory, apiMode, apiHandlerInfos;
|
|
198
|
+
return _ts_generator(this, function(_state) {
|
|
199
|
+
switch (_state.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
pwd = props.pwd, prefix = props.prefix, httpMethodDecider = props.httpMethodDecider;
|
|
202
|
+
apiDir = path.resolve(pwd, API_DIR);
|
|
203
|
+
appContext = api.useAppContext();
|
|
204
|
+
apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory;
|
|
205
|
+
apiRouter = new ApiRouter({
|
|
206
|
+
appDir: pwd,
|
|
207
|
+
apiDir: apiDirectory || apiDir,
|
|
208
|
+
lambdaDir: lambdaDirectory,
|
|
209
|
+
prefix,
|
|
210
|
+
httpMethodDecider
|
|
211
|
+
});
|
|
212
|
+
apiMode = apiRouter.getApiMode();
|
|
213
|
+
return [
|
|
214
|
+
4,
|
|
215
|
+
apiRouter.getApiHandlers()
|
|
216
|
+
];
|
|
217
|
+
case 1:
|
|
218
|
+
apiHandlerInfos = _state.sent();
|
|
219
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
|
220
|
+
apiRouter,
|
|
221
|
+
apiHandlerInfos,
|
|
222
|
+
apiMode
|
|
223
|
+
}));
|
|
224
|
+
return [
|
|
225
|
+
2,
|
|
226
|
+
next(props)
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
})();
|
|
208
231
|
}
|
|
209
232
|
};
|
|
210
233
|
}
|
package/dist/esm-node/cli.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, API_DIR, normalizeOutputPath, SHARED_DIR
|
|
2
|
+
import { fs, API_DIR, normalizeOutputPath, SHARED_DIR } from "@modern-js/utils";
|
|
3
3
|
import { compile } from "@modern-js/server-utils";
|
|
4
4
|
import { ApiRouter } from "@modern-js/bff-core";
|
|
5
|
-
import { registerModernRuntimePath } from "./helper";
|
|
6
5
|
const DEFAULT_API_PREFIX = "/api";
|
|
7
6
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
8
7
|
const bffPlugin = () => ({
|
|
9
8
|
name: "@modern-js/plugin-bff",
|
|
10
9
|
setup: (api) => {
|
|
11
|
-
let unRegisterResolveRuntimePath = null;
|
|
12
10
|
return {
|
|
13
11
|
config() {
|
|
14
12
|
return {
|
|
@@ -95,27 +93,18 @@ const bffPlugin = () => ({
|
|
|
95
93
|
plugins
|
|
96
94
|
};
|
|
97
95
|
},
|
|
98
|
-
async beforeBuild() {
|
|
99
|
-
if (isProd()) {
|
|
100
|
-
const { internalDirectory } = api.useAppContext();
|
|
101
|
-
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
96
|
async afterBuild() {
|
|
105
|
-
|
|
106
|
-
unRegisterResolveRuntimePath();
|
|
107
|
-
}
|
|
108
|
-
const { appDirectory, distDirectory, apiDirectory, sharedDirectory } = api.useAppContext();
|
|
97
|
+
const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.useAppContext();
|
|
109
98
|
const modernConfig = api.useResolvedConfigContext();
|
|
110
99
|
const distDir = path.resolve(distDirectory);
|
|
111
100
|
const apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
|
|
112
101
|
const sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
|
|
113
102
|
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
114
103
|
const sourceDirs = [];
|
|
115
|
-
if (fs.
|
|
104
|
+
if (await fs.pathExists(apiDir)) {
|
|
116
105
|
sourceDirs.push(apiDir);
|
|
117
106
|
}
|
|
118
|
-
if (fs.
|
|
107
|
+
if (await fs.pathExists(sharedDir)) {
|
|
119
108
|
sourceDirs.push(sharedDir);
|
|
120
109
|
}
|
|
121
110
|
const { server } = modernConfig;
|
|
@@ -129,7 +118,8 @@ const bffPlugin = () => ({
|
|
|
129
118
|
}, {
|
|
130
119
|
sourceDirs,
|
|
131
120
|
distDir,
|
|
132
|
-
tsconfigPath
|
|
121
|
+
tsconfigPath,
|
|
122
|
+
moduleType
|
|
133
123
|
});
|
|
134
124
|
}
|
|
135
125
|
}
|
package/dist/esm-node/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { ApiRouter } from "@modern-js/bff-core";
|
|
3
3
|
import { API_DIR, isProd, isWebOnly, requireExistModule } from "@modern-js/utils";
|
|
4
|
-
import { getRenderHandler } from "@modern-js/server-core";
|
|
5
4
|
import { API_APP_NAME } from "./constants";
|
|
6
5
|
class Storage {
|
|
7
6
|
reset() {
|
|
@@ -27,11 +26,11 @@ var server_default = () => ({
|
|
|
27
26
|
async prepare() {
|
|
28
27
|
var _config_bff, _config_bff1, _config_bff2;
|
|
29
28
|
const appContext = api.useAppContext();
|
|
30
|
-
const { appDirectory, distDirectory } = appContext;
|
|
29
|
+
const { appDirectory, distDirectory, render } = appContext;
|
|
31
30
|
const root = isProd() ? distDirectory : appDirectory;
|
|
32
31
|
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
33
32
|
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
34
|
-
const apiMod = requireExistModule(apiAppPath);
|
|
33
|
+
const apiMod = await requireExistModule(apiAppPath);
|
|
35
34
|
if (apiMod && typeof apiMod === "function") {
|
|
36
35
|
apiMod(transformAPI);
|
|
37
36
|
}
|
|
@@ -44,7 +43,7 @@ var server_default = () => ({
|
|
|
44
43
|
const prefix = (config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
|
|
45
44
|
const enableHandleWeb = config === null || config === void 0 ? void 0 : (_config_bff1 = config.bff) === null || _config_bff1 === void 0 ? void 0 : _config_bff1.enableHandleWeb;
|
|
46
45
|
const httpMethodDecider = config === null || config === void 0 ? void 0 : (_config_bff2 = config.bff) === null || _config_bff2 === void 0 ? void 0 : _config_bff2.httpMethodDecider;
|
|
47
|
-
const { distDirectory: pwd,
|
|
46
|
+
const { distDirectory: pwd, middlewares: globalMiddlewares } = api.useAppContext();
|
|
48
47
|
const webOnly = await isWebOnly();
|
|
49
48
|
let handler;
|
|
50
49
|
if (webOnly) {
|
|
@@ -54,11 +53,7 @@ var server_default = () => ({
|
|
|
54
53
|
};
|
|
55
54
|
} else {
|
|
56
55
|
const runner = api.useHookRunners();
|
|
57
|
-
const renderHandler = enableHandleWeb ?
|
|
58
|
-
pwd,
|
|
59
|
-
routes: routes || [],
|
|
60
|
-
config
|
|
61
|
-
}) : null;
|
|
56
|
+
const renderHandler = enableHandleWeb ? render : null;
|
|
62
57
|
handler = await runner.prepareApiServer({
|
|
63
58
|
pwd,
|
|
64
59
|
prefix,
|
|
@@ -87,10 +82,10 @@ var server_default = () => ({
|
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
84
|
},
|
|
90
|
-
reset({ event }) {
|
|
85
|
+
async reset({ event }) {
|
|
91
86
|
storage.reset();
|
|
92
87
|
const appContext = api.useAppContext();
|
|
93
|
-
const newApiModule = requireExistModule(apiAppPath);
|
|
88
|
+
const newApiModule = await requireExistModule(apiAppPath);
|
|
94
89
|
if (newApiModule && typeof newApiModule === "function") {
|
|
95
90
|
newApiModule(transformAPI);
|
|
96
91
|
}
|
|
@@ -100,7 +95,7 @@ var server_default = () => ({
|
|
|
100
95
|
apiMiddlewares: middlewares
|
|
101
96
|
});
|
|
102
97
|
if (event.type === "file-change") {
|
|
103
|
-
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
98
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
104
99
|
const appContext2 = api.useAppContext();
|
|
105
100
|
api.setAppContext({
|
|
106
101
|
...appContext2,
|
|
@@ -108,7 +103,7 @@ var server_default = () => ({
|
|
|
108
103
|
});
|
|
109
104
|
}
|
|
110
105
|
},
|
|
111
|
-
prepareApiServer(props, next) {
|
|
106
|
+
async prepareApiServer(props, next) {
|
|
112
107
|
const { pwd, prefix, httpMethodDecider } = props;
|
|
113
108
|
const apiDir = path.resolve(pwd, API_DIR);
|
|
114
109
|
const appContext = api.useAppContext();
|
|
@@ -121,7 +116,7 @@ var server_default = () => ({
|
|
|
121
116
|
httpMethodDecider
|
|
122
117
|
});
|
|
123
118
|
const apiMode = apiRouter.getApiMode();
|
|
124
|
-
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
119
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
125
120
|
api.setAppContext({
|
|
126
121
|
...appContext,
|
|
127
122
|
apiRouter,
|
package/package.json
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.57.1-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/cli.ts",
|
|
20
20
|
"types": "./dist/types/cli.d.ts",
|
|
21
21
|
"main": "./dist/cjs/cli.js",
|
|
22
22
|
"module": "./dist/esm/cli.js",
|
|
23
23
|
"exports": {
|
|
24
|
+
"./types": "./types.d.ts",
|
|
24
25
|
".": {
|
|
25
26
|
"types": "./dist/types/cli.d.ts",
|
|
26
27
|
"jsnext:source": "./src/cli.ts",
|
|
@@ -58,11 +59,11 @@
|
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"@babel/core": "^7.24.7",
|
|
60
61
|
"@swc/helpers": "0.5.3",
|
|
61
|
-
"@modern-js/bff-core": "2.
|
|
62
|
-
"@modern-js/server-
|
|
63
|
-
"@modern-js/
|
|
64
|
-
"@modern-js/server-
|
|
65
|
-
"@modern-js/
|
|
62
|
+
"@modern-js/bff-core": "2.57.0",
|
|
63
|
+
"@modern-js/server-utils": "2.57.0",
|
|
64
|
+
"@modern-js/utils": "2.57.0",
|
|
65
|
+
"@modern-js/server-core": "2.57.0",
|
|
66
|
+
"@modern-js/create-request": "2.57.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@types/babel__core": "^7.20.5",
|
|
@@ -73,13 +74,13 @@
|
|
|
73
74
|
"ts-jest": "^29.1.0",
|
|
74
75
|
"typescript": "^5",
|
|
75
76
|
"webpack": "^5.93.0",
|
|
76
|
-
"@modern-js/runtime": "2.
|
|
77
|
-
"@modern-js/
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@scripts/jest-config": "2.
|
|
77
|
+
"@modern-js/bff-runtime": "2.57.0",
|
|
78
|
+
"@modern-js/types": "2.57.0",
|
|
79
|
+
"@modern-js/core": "2.57.0",
|
|
80
|
+
"@modern-js/app-tools": "2.57.1-alpha.3",
|
|
81
|
+
"@scripts/build": "2.57.0",
|
|
82
|
+
"@modern-js/runtime": "2.57.0",
|
|
83
|
+
"@scripts/jest-config": "2.57.0"
|
|
83
84
|
},
|
|
84
85
|
"sideEffects": false,
|
|
85
86
|
"publishConfig": {
|