@modern-js/plugin-bff 2.14.0 → 2.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 +25 -0
- package/dist/cjs/cli.js +136 -154
- package/dist/cjs/constants.js +11 -24
- package/dist/cjs/helper.js +51 -39
- package/dist/cjs/index.js +18 -17
- package/dist/cjs/loader.js +13 -29
- package/dist/cjs/server.js +40 -48
- package/dist/esm/cli.js +358 -341
- package/dist/esm/constants.js +9 -10
- package/dist/esm/helper.js +15 -15
- package/dist/esm/loader.js +185 -179
- package/dist/esm/server.js +137 -134
- package/dist/esm-node/cli.js +119 -126
- package/dist/esm-node/constants.js +2 -6
- package/dist/esm-node/helper.js +1 -3
- package/dist/esm-node/loader.js +1 -4
- package/dist/esm-node/server.js +17 -7
- package/package.json +18 -14
package/dist/cjs/server.js
CHANGED
|
@@ -1,53 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var server_exports = {};
|
|
29
|
-
__export(server_exports, {
|
|
30
|
-
default: () => server_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
8
|
+
});
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
10
|
+
const _bffcore = require("@modern-js/bff-core");
|
|
11
|
+
const _utils = require("@modern-js/utils");
|
|
12
|
+
const _constants = require("./constants");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
40
23
|
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _interop_require_default(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
class Storage {
|
|
41
32
|
reset() {
|
|
42
33
|
this.middlewares = [];
|
|
43
34
|
}
|
|
35
|
+
constructor() {
|
|
36
|
+
_define_property(this, "middlewares", []);
|
|
37
|
+
}
|
|
44
38
|
}
|
|
45
39
|
const createTransformAPI = (storage) => ({
|
|
46
40
|
addMiddleware(fn) {
|
|
47
41
|
storage.middlewares.push(fn);
|
|
48
42
|
}
|
|
49
43
|
});
|
|
50
|
-
|
|
44
|
+
const _default = () => ({
|
|
51
45
|
name: "@modern-js/plugin-bff",
|
|
52
46
|
setup: (api) => {
|
|
53
47
|
const storage = new Storage();
|
|
@@ -56,17 +50,17 @@ var server_default = () => ({
|
|
|
56
50
|
return {
|
|
57
51
|
prepare() {
|
|
58
52
|
const { appDirectory, distDirectory } = api.useAppContext();
|
|
59
|
-
const root = (0,
|
|
60
|
-
const apiPath =
|
|
61
|
-
apiAppPath =
|
|
62
|
-
const apiMod = (0,
|
|
53
|
+
const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
|
|
54
|
+
const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
|
|
55
|
+
apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
56
|
+
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
63
57
|
if (apiMod && typeof apiMod === "function") {
|
|
64
58
|
apiMod(transformAPI);
|
|
65
59
|
}
|
|
66
60
|
},
|
|
67
61
|
reset() {
|
|
68
62
|
storage.reset();
|
|
69
|
-
const newApiModule = (0,
|
|
63
|
+
const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
|
|
70
64
|
if (newApiModule && typeof newApiModule === "function") {
|
|
71
65
|
newApiModule(transformAPI);
|
|
72
66
|
}
|
|
@@ -78,10 +72,10 @@ var server_default = () => ({
|
|
|
78
72
|
},
|
|
79
73
|
prepareApiServer(props, next) {
|
|
80
74
|
const { pwd, prefix, httpMethodDecider } = props;
|
|
81
|
-
const apiDir =
|
|
75
|
+
const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
|
|
82
76
|
const appContext = api.useAppContext();
|
|
83
77
|
const { apiDirectory, lambdaDirectory } = appContext;
|
|
84
|
-
const apiRouter = new
|
|
78
|
+
const apiRouter = new _bffcore.ApiRouter({
|
|
85
79
|
apiDir: apiDirectory || apiDir,
|
|
86
80
|
lambdaDir: lambdaDirectory,
|
|
87
81
|
prefix,
|
|
@@ -100,5 +94,3 @@ var server_default = () => ({
|
|
|
100
94
|
};
|
|
101
95
|
}
|
|
102
96
|
});
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {});
|