@modern-js/plugin-bff 2.69.5 → 3.0.0-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 +256 -272
- package/dist/cjs/constants.js +43 -34
- package/dist/cjs/index.js +55 -19
- package/dist/cjs/loader.js +69 -65
- package/dist/cjs/runtime/create-request/index.js +39 -29
- package/dist/cjs/runtime/hono/adapter.js +128 -126
- package/dist/cjs/runtime/hono/index.js +78 -30
- package/dist/cjs/runtime/hono/operators.js +64 -67
- package/dist/cjs/server.js +159 -165
- package/dist/cjs/utils/clientGenerator.js +204 -206
- package/dist/cjs/utils/createHonoRoutes.js +128 -144
- package/dist/cjs/utils/crossProjectApiPlugin.js +91 -81
- package/dist/cjs/utils/pluginGenerator.js +66 -54
- package/dist/cjs/utils/runtimeGenerator.js +67 -45
- package/dist/esm/cli.mjs +214 -0
- package/dist/esm/constants.mjs +11 -0
- package/dist/esm/loader.mjs +39 -0
- package/dist/esm/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm-node/runtime/hono/index.js → esm/runtime/hono/index.mjs} +2 -4
- package/dist/esm/runtime/hono/operators.mjs +31 -0
- package/dist/esm/server.mjs +122 -0
- package/dist/esm/utils/clientGenerator.mjs +175 -0
- package/dist/esm/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm/utils/pluginGenerator.mjs +29 -0
- package/dist/esm/utils/runtimeGenerator.mjs +43 -0
- package/dist/esm-node/cli.mjs +214 -0
- package/dist/esm-node/constants.mjs +11 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/loader.mjs +39 -0
- package/dist/esm-node/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm-node/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm/runtime/hono/index.js → esm-node/runtime/hono/index.mjs} +3 -5
- package/dist/esm-node/runtime/hono/operators.mjs +31 -0
- package/dist/esm-node/server.mjs +122 -0
- package/dist/esm-node/utils/clientGenerator.mjs +175 -0
- package/dist/esm-node/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm-node/utils/pluginGenerator.mjs +29 -0
- package/dist/esm-node/utils/runtimeGenerator.mjs +43 -0
- package/dist/types/loader.d.ts +2 -2
- package/dist/types/runtime/hono/adapter.d.ts +3 -3
- package/dist/types/server.d.ts +2 -2
- package/dist/types/utils/runtimeGenerator.d.ts +2 -1
- package/package.json +53 -31
- package/rslib.config.mts +4 -0
- package/dist/cjs/helper.js +0 -48
- package/dist/esm/cli.js +0 -425
- package/dist/esm/constants.js +0 -14
- package/dist/esm/helper.js +0 -13
- package/dist/esm/index.js +0 -1
- package/dist/esm/loader.js +0 -75
- package/dist/esm/runtime/hono/adapter.js +0 -243
- package/dist/esm/runtime/hono/operators.js +0 -79
- package/dist/esm/server.js +0 -258
- package/dist/esm/utils/clientGenerator.js +0 -517
- package/dist/esm/utils/createHonoRoutes.js +0 -319
- package/dist/esm/utils/crossProjectApiPlugin.js +0 -49
- package/dist/esm/utils/pluginGenerator.js +0 -94
- package/dist/esm/utils/runtimeGenerator.js +0 -55
- package/dist/esm-node/cli.js +0 -246
- package/dist/esm-node/constants.js +0 -14
- package/dist/esm-node/helper.js +0 -14
- package/dist/esm-node/loader.js +0 -49
- package/dist/esm-node/runtime/hono/adapter.js +0 -103
- package/dist/esm-node/runtime/hono/operators.js +0 -46
- package/dist/esm-node/server.js +0 -142
- package/dist/esm-node/utils/clientGenerator.js +0 -192
- package/dist/esm-node/utils/createHonoRoutes.js +0 -120
- package/dist/esm-node/utils/crossProjectApiPlugin.js +0 -47
- package/dist/esm-node/utils/pluginGenerator.js +0 -31
- package/dist/esm-node/utils/runtimeGenerator.js +0 -35
- package/dist/types/helper.d.ts +0 -2
- package/types.d.ts +0 -3
- /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
|
@@ -1,154 +1,138 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var createHonoRoutes_exports = {};
|
|
30
|
-
__export(createHonoRoutes_exports, {
|
|
31
|
-
createHonoHandler: () => createHonoHandler,
|
|
32
|
-
default: () => createHonoRoutes_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(createHonoRoutes_exports);
|
|
35
|
-
var import_bff_core = require("@modern-js/bff-core");
|
|
36
|
-
var import_qs = require("@modern-js/create-request/qs");
|
|
37
|
-
var import_type_is = __toESM(require("type-is"));
|
|
38
|
-
const createHonoRoutes = (handlerInfos = []) => {
|
|
39
|
-
return handlerInfos.map(({ routePath, handler, httpMethod }) => {
|
|
40
|
-
const routeMiddlwares = Reflect.getMetadata("middleware", handler) || [];
|
|
41
|
-
const honoHandler = createHonoHandler(handler);
|
|
42
|
-
return {
|
|
43
|
-
method: httpMethod.toLowerCase(),
|
|
44
|
-
path: routePath,
|
|
45
|
-
handler: routeMiddlwares.length > 0 ? [
|
|
46
|
-
...routeMiddlwares,
|
|
47
|
-
honoHandler
|
|
48
|
-
] : honoHandler
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
49
10
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
default: ()=>utils_createHonoRoutes,
|
|
37
|
+
createHonoHandler: ()=>createHonoHandler
|
|
38
|
+
});
|
|
39
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
40
|
+
const qs_namespaceObject = require("@modern-js/create-request/qs");
|
|
41
|
+
const external_type_is_namespaceObject = require("type-is");
|
|
42
|
+
var external_type_is_default = /*#__PURE__*/ __webpack_require__.n(external_type_is_namespaceObject);
|
|
43
|
+
const createHonoRoutes = (handlerInfos = [])=>handlerInfos.map(({ routePath, handler, httpMethod })=>{
|
|
44
|
+
const routeMiddlwares = Reflect.getMetadata('middleware', handler) || [];
|
|
45
|
+
const honoHandler = createHonoHandler(handler);
|
|
46
|
+
return {
|
|
47
|
+
method: httpMethod.toLowerCase(),
|
|
48
|
+
path: routePath,
|
|
49
|
+
handler: routeMiddlwares.length > 0 ? [
|
|
50
|
+
...routeMiddlwares,
|
|
51
|
+
honoHandler
|
|
52
|
+
] : honoHandler
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const handleResponseMeta = (c, handler)=>{
|
|
56
|
+
const responseMeta = Reflect.getMetadata(bff_core_namespaceObject.HttpMetadata.Response, handler);
|
|
57
|
+
if (Array.isArray(responseMeta)) for (const meta of responseMeta)switch(meta.type){
|
|
58
|
+
case bff_core_namespaceObject.ResponseMetaType.Headers:
|
|
59
|
+
for (const [key, value] of Object.entries(meta.value))c.header(key, value);
|
|
60
|
+
break;
|
|
61
|
+
case bff_core_namespaceObject.ResponseMetaType.Redirect:
|
|
62
|
+
return c.redirect(meta.value);
|
|
63
|
+
case bff_core_namespaceObject.ResponseMetaType.StatusCode:
|
|
64
|
+
c.status(meta.value);
|
|
65
|
+
break;
|
|
67
66
|
default:
|
|
68
|
-
|
|
69
|
-
}
|
|
67
|
+
break;
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
return null;
|
|
69
|
+
return null;
|
|
73
70
|
};
|
|
74
|
-
const createHonoHandler = (handler) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
const createHonoHandler = (handler)=>async (c)=>{
|
|
72
|
+
const input = await getHonoInput(c);
|
|
73
|
+
if ((0, bff_core_namespaceObject.isWithMetaHandler)(handler)) try {
|
|
74
|
+
const response = handleResponseMeta(c, handler);
|
|
75
|
+
if (response) return response;
|
|
76
|
+
if (c.finalized) return;
|
|
77
|
+
const result = await handler(input);
|
|
78
|
+
if (result instanceof Response) return result;
|
|
79
|
+
return result && 'object' == typeof result ? c.json(result) : c.body(result);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof bff_core_namespaceObject.ValidationError) {
|
|
82
|
+
c.status(error.status);
|
|
83
|
+
return c.json({
|
|
84
|
+
message: error.message
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
82
88
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
{
|
|
90
|
+
const routePath = c.req.routePath;
|
|
91
|
+
const paramNames = routePath.match(/:\w+/g)?.map((s)=>s.slice(1)) || [];
|
|
92
|
+
const params = Object.fromEntries(paramNames.map((name)=>[
|
|
93
|
+
name,
|
|
94
|
+
input.params[name]
|
|
95
|
+
]));
|
|
96
|
+
const args = Object.values(params).concat(input);
|
|
97
|
+
const body = await handler(...args);
|
|
98
|
+
if (c.finalized) return await Promise.resolve();
|
|
99
|
+
if (void 0 !== body) {
|
|
100
|
+
if (body instanceof Response) return body;
|
|
101
|
+
return c.json(body);
|
|
102
|
+
}
|
|
88
103
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
if (typeof body !== "undefined") {
|
|
113
|
-
if (body instanceof Response) {
|
|
114
|
-
return body;
|
|
115
|
-
}
|
|
116
|
-
return c.json(body);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
const getHonoInput = async (c) => {
|
|
122
|
-
const draft = {
|
|
123
|
-
params: c.req.param(),
|
|
124
|
-
query: (0, import_qs.parse)(c.req.query()),
|
|
125
|
-
headers: c.req.header(),
|
|
126
|
-
cookies: c.req.header("cookie")
|
|
127
|
-
};
|
|
128
|
-
try {
|
|
129
|
-
const contentType = c.req.header("content-type") || "";
|
|
130
|
-
if (import_type_is.default.is(contentType, [
|
|
131
|
-
"application/json"
|
|
132
|
-
])) {
|
|
133
|
-
draft.data = await c.req.json();
|
|
134
|
-
} else if (import_type_is.default.is(contentType, [
|
|
135
|
-
"multipart/form-data"
|
|
136
|
-
])) {
|
|
137
|
-
draft.formData = await c.req.parseBody();
|
|
138
|
-
} else if (import_type_is.default.is(contentType, [
|
|
139
|
-
"application/x-www-form-urlencoded"
|
|
140
|
-
])) {
|
|
141
|
-
draft.formUrlencoded = await c.req.parseBody();
|
|
142
|
-
} else {
|
|
143
|
-
draft.body = await c.req.json();
|
|
104
|
+
};
|
|
105
|
+
const getHonoInput = async (c)=>{
|
|
106
|
+
const draft = {
|
|
107
|
+
params: c.req.param(),
|
|
108
|
+
query: (0, qs_namespaceObject.parse)(c.req.query()),
|
|
109
|
+
headers: c.req.header(),
|
|
110
|
+
cookies: c.req.header('cookie')
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
const contentType = c.req.header('content-type') || '';
|
|
114
|
+
if (external_type_is_default().is(contentType, [
|
|
115
|
+
'application/json'
|
|
116
|
+
])) draft.data = await c.req.json();
|
|
117
|
+
else if (external_type_is_default().is(contentType, [
|
|
118
|
+
'multipart/form-data'
|
|
119
|
+
])) draft.formData = await c.req.parseBody();
|
|
120
|
+
else if (external_type_is_default().is(contentType, [
|
|
121
|
+
'application/x-www-form-urlencoded'
|
|
122
|
+
])) draft.formUrlencoded = await c.req.parseBody();
|
|
123
|
+
else draft.body = await c.req.json();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
draft.body = null;
|
|
144
126
|
}
|
|
145
|
-
|
|
146
|
-
draft.body = null;
|
|
147
|
-
}
|
|
148
|
-
return draft;
|
|
127
|
+
return draft;
|
|
149
128
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
129
|
+
const utils_createHonoRoutes = createHonoRoutes;
|
|
130
|
+
exports.createHonoHandler = __webpack_exports__.createHonoHandler;
|
|
131
|
+
exports["default"] = __webpack_exports__["default"];
|
|
132
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
133
|
+
"createHonoHandler",
|
|
134
|
+
"default"
|
|
135
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
136
|
+
Object.defineProperty(exports, '__esModule', {
|
|
137
|
+
value: true
|
|
154
138
|
});
|
|
@@ -1,86 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
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
|
-
__export(crossProjectApiPlugin_exports, {
|
|
31
|
-
API_DIR: () => API_DIR,
|
|
32
|
-
DIST_DIR: () => DIST_DIR,
|
|
33
|
-
LAMBDA_DIR: () => LAMBDA_DIR,
|
|
34
|
-
PACKAGE_NAME: () => PACKAGE_NAME,
|
|
35
|
-
PREFIX: () => PREFIX,
|
|
36
|
-
crossProjectApiPlugin: () => crossProjectApiPlugin,
|
|
37
|
-
default: () => crossProjectApiPlugin_default
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(crossProjectApiPlugin_exports);
|
|
40
|
-
var import_path = __toESM(require("path"));
|
|
41
|
-
const PACKAGE_NAME = "{packageName}";
|
|
42
|
-
const PREFIX = "{prefix}";
|
|
43
|
-
const API_DIR = "{apiDirectory}";
|
|
44
|
-
const LAMBDA_DIR = "{lambdaDirectory}";
|
|
45
|
-
const DIST_DIR = "{distDirectory}";
|
|
46
|
-
const NODE_MODULES = "node_modules";
|
|
47
|
-
const crossProjectApiPlugin = () => ({
|
|
48
|
-
name: "@modern-js/plugin-independent-bff",
|
|
49
|
-
post: [
|
|
50
|
-
"@modern-js/plugin-bff"
|
|
51
|
-
],
|
|
52
|
-
setup: (api) => {
|
|
53
|
-
return {
|
|
54
|
-
config() {
|
|
55
|
-
const { appDirectory: originAppDirectory } = api.useAppContext();
|
|
56
|
-
const sdkPath = import_path.default.join(originAppDirectory, NODE_MODULES, PACKAGE_NAME);
|
|
57
|
-
const sdkDistPath = import_path.default.join(sdkPath, DIST_DIR);
|
|
58
|
-
const apiDirectory = import_path.default.join(sdkDistPath, API_DIR);
|
|
59
|
-
const lambdaDirectory = import_path.default.resolve(sdkDistPath, LAMBDA_DIR);
|
|
60
|
-
const appContext = api.useAppContext();
|
|
61
|
-
api.setAppContext({
|
|
62
|
-
...appContext,
|
|
63
|
-
apiDirectory,
|
|
64
|
-
lambdaDirectory
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
65
30
|
});
|
|
66
|
-
const config = api.useConfigContext();
|
|
67
|
-
config.bff = {
|
|
68
|
-
...config.bff,
|
|
69
|
-
prefix: PREFIX,
|
|
70
|
-
isCrossProjectServer: true
|
|
71
|
-
};
|
|
72
|
-
return {};
|
|
73
|
-
}
|
|
74
31
|
};
|
|
75
|
-
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
crossProjectApiPlugin: ()=>crossProjectApiPlugin,
|
|
37
|
+
API_DIR: ()=>API_DIR,
|
|
38
|
+
default: ()=>utils_crossProjectApiPlugin,
|
|
39
|
+
DIST_DIR: ()=>DIST_DIR,
|
|
40
|
+
PACKAGE_NAME: ()=>PACKAGE_NAME,
|
|
41
|
+
PREFIX: ()=>PREFIX,
|
|
42
|
+
LAMBDA_DIR: ()=>LAMBDA_DIR
|
|
76
43
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
44
|
+
const external_path_namespaceObject = require("path");
|
|
45
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
46
|
+
const PACKAGE_NAME = '{packageName}';
|
|
47
|
+
const PREFIX = '{prefix}';
|
|
48
|
+
const API_DIR = '{apiDirectory}';
|
|
49
|
+
const LAMBDA_DIR = '{lambdaDirectory}';
|
|
50
|
+
const DIST_DIR = '{distDirectory}';
|
|
51
|
+
const NODE_MODULES = 'node_modules';
|
|
52
|
+
const crossProjectApiPlugin = ()=>({
|
|
53
|
+
name: '@modern-js/plugin-independent-bff',
|
|
54
|
+
post: [
|
|
55
|
+
'@modern-js/plugin-bff'
|
|
56
|
+
],
|
|
57
|
+
setup: (api)=>{
|
|
58
|
+
api.modifyResolvedConfig((resolvedConfig)=>{
|
|
59
|
+
const { appDirectory: originAppDirectory } = api.getAppContext();
|
|
60
|
+
const sdkPath = external_path_default().join(originAppDirectory, NODE_MODULES, PACKAGE_NAME);
|
|
61
|
+
const sdkDistPath = external_path_default().join(sdkPath, DIST_DIR);
|
|
62
|
+
const apiDirectory = external_path_default().join(sdkDistPath, API_DIR);
|
|
63
|
+
const lambdaDirectory = external_path_default().resolve(sdkDistPath, LAMBDA_DIR);
|
|
64
|
+
api.updateAppContext({
|
|
65
|
+
apiDirectory,
|
|
66
|
+
lambdaDirectory
|
|
67
|
+
});
|
|
68
|
+
const config = api.getConfig();
|
|
69
|
+
if (config?.bff?.prefix) console.warn(`[WARNING] Detected bff.prefix configuration: "${config.bff.prefix}".
|
|
70
|
+
When using cross-project BFF, you should not configure bff.prefix as it may cause API path conflicts or access issues. Please remove the bff.prefix configuration.`);
|
|
71
|
+
resolvedConfig.bff.prefix = PREFIX;
|
|
72
|
+
resolvedConfig.bff.isCrossProjectServer = true;
|
|
73
|
+
return resolvedConfig;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const utils_crossProjectApiPlugin = crossProjectApiPlugin;
|
|
78
|
+
exports.API_DIR = __webpack_exports__.API_DIR;
|
|
79
|
+
exports.DIST_DIR = __webpack_exports__.DIST_DIR;
|
|
80
|
+
exports.LAMBDA_DIR = __webpack_exports__.LAMBDA_DIR;
|
|
81
|
+
exports.PACKAGE_NAME = __webpack_exports__.PACKAGE_NAME;
|
|
82
|
+
exports.PREFIX = __webpack_exports__.PREFIX;
|
|
83
|
+
exports.crossProjectApiPlugin = __webpack_exports__.crossProjectApiPlugin;
|
|
84
|
+
exports["default"] = __webpack_exports__["default"];
|
|
85
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
86
|
+
"API_DIR",
|
|
87
|
+
"DIST_DIR",
|
|
88
|
+
"LAMBDA_DIR",
|
|
89
|
+
"PACKAGE_NAME",
|
|
90
|
+
"PREFIX",
|
|
91
|
+
"crossProjectApiPlugin",
|
|
92
|
+
"default"
|
|
93
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
94
|
+
Object.defineProperty(exports, '__esModule', {
|
|
95
|
+
value: true
|
|
86
96
|
});
|
|
@@ -1,61 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
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
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
default: ()=>utils_pluginGenerator
|
|
32
37
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
const external_path_namespaceObject = require("path");
|
|
39
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
40
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
41
|
+
const external_crossProjectApiPlugin_js_namespaceObject = require("./crossProjectApiPlugin.js");
|
|
37
42
|
function replaceContent(source, packageName, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath) {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
const updatedSource = source.replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PACKAGE_NAME, 'g'), packageName).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.PREFIX, 'g'), prefix).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.DIST_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeDistPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.API_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeApiPath)).replace(new RegExp(external_crossProjectApiPlugin_js_namespaceObject.LAMBDA_DIR, 'g'), (0, utils_namespaceObject.normalizeToPosixPath)(relativeLambdaPath));
|
|
44
|
+
return updatedSource;
|
|
40
45
|
}
|
|
41
46
|
async function pluginGenerator({ prefix, appDirectory, relativeDistPath, relativeApiPath, relativeLambdaPath }) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
try {
|
|
48
|
+
const packageContent = await utils_namespaceObject.fs.readFile(external_path_default().resolve(appDirectory, './package.json'), 'utf8');
|
|
49
|
+
const packageJson = JSON.parse(packageContent);
|
|
50
|
+
const pluginDir = external_path_default().resolve(appDirectory, `./${relativeDistPath}`, 'plugin');
|
|
51
|
+
const pluginPath = external_path_default().join(pluginDir, 'index.js');
|
|
52
|
+
const pluginTemplate = await utils_namespaceObject.fs.readFile(external_path_default().resolve(__dirname, 'crossProjectApiPlugin.js'), 'utf8');
|
|
53
|
+
const updatedPlugin = replaceContent(pluginTemplate, packageJson.name, prefix, relativeDistPath, relativeApiPath, relativeLambdaPath);
|
|
54
|
+
await utils_namespaceObject.fs.ensureFile(pluginPath);
|
|
55
|
+
await utils_namespaceObject.fs.writeFile(pluginPath, updatedPlugin);
|
|
56
|
+
const typeContent = `import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
52
57
|
export declare const crossProjectApiPlugin: () => CliPlugin<AppTools>`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const pluginTypePath = external_path_default().join(pluginDir, 'index.d.ts');
|
|
59
|
+
await utils_namespaceObject.fs.ensureFile(pluginTypePath);
|
|
60
|
+
await utils_namespaceObject.fs.writeFile(pluginTypePath, typeContent);
|
|
61
|
+
utils_namespaceObject.logger.info('Api plugin generate succeed');
|
|
62
|
+
} catch (error) {
|
|
63
|
+
utils_namespaceObject.logger.error('Api plugin generate failed:', error);
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
|
-
|
|
66
|
+
const utils_pluginGenerator = pluginGenerator;
|
|
67
|
+
exports["default"] = __webpack_exports__["default"];
|
|
68
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
69
|
+
"default"
|
|
70
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
71
|
+
Object.defineProperty(exports, '__esModule', {
|
|
72
|
+
value: true
|
|
73
|
+
});
|