@modern-js/plugin-bff 2.69.7 → 3.0.0-alpha.1

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.
Files changed (76) hide show
  1. package/dist/cjs/cli.js +256 -272
  2. package/dist/cjs/constants.js +43 -34
  3. package/dist/cjs/index.js +55 -19
  4. package/dist/cjs/loader.js +69 -65
  5. package/dist/cjs/runtime/create-request/index.js +39 -29
  6. package/dist/cjs/runtime/hono/adapter.js +128 -126
  7. package/dist/cjs/runtime/hono/index.js +78 -30
  8. package/dist/cjs/runtime/hono/operators.js +64 -67
  9. package/dist/cjs/server.js +159 -165
  10. package/dist/cjs/utils/clientGenerator.js +204 -206
  11. package/dist/cjs/utils/createHonoRoutes.js +128 -144
  12. package/dist/cjs/utils/crossProjectApiPlugin.js +91 -81
  13. package/dist/cjs/utils/pluginGenerator.js +66 -54
  14. package/dist/cjs/utils/runtimeGenerator.js +67 -45
  15. package/dist/esm/cli.mjs +214 -0
  16. package/dist/esm/constants.mjs +11 -0
  17. package/dist/esm/loader.mjs +39 -0
  18. package/dist/esm/runtime/create-request/{index.js → index.mjs} +1 -5
  19. package/dist/esm/runtime/hono/adapter.mjs +95 -0
  20. package/dist/{esm-node/runtime/hono/index.js → esm/runtime/hono/index.mjs} +2 -4
  21. package/dist/esm/runtime/hono/operators.mjs +31 -0
  22. package/dist/esm/server.mjs +122 -0
  23. package/dist/esm/utils/clientGenerator.mjs +175 -0
  24. package/dist/esm/utils/createHonoRoutes.mjs +91 -0
  25. package/dist/esm/utils/crossProjectApiPlugin.mjs +34 -0
  26. package/dist/esm/utils/pluginGenerator.mjs +29 -0
  27. package/dist/esm/utils/runtimeGenerator.mjs +43 -0
  28. package/dist/esm-node/cli.mjs +214 -0
  29. package/dist/esm-node/constants.mjs +11 -0
  30. package/dist/esm-node/index.mjs +1 -0
  31. package/dist/esm-node/loader.mjs +39 -0
  32. package/dist/esm-node/runtime/create-request/{index.js → index.mjs} +1 -5
  33. package/dist/esm-node/runtime/hono/adapter.mjs +95 -0
  34. package/dist/{esm/runtime/hono/index.js → esm-node/runtime/hono/index.mjs} +3 -5
  35. package/dist/esm-node/runtime/hono/operators.mjs +31 -0
  36. package/dist/esm-node/server.mjs +122 -0
  37. package/dist/esm-node/utils/clientGenerator.mjs +175 -0
  38. package/dist/esm-node/utils/createHonoRoutes.mjs +91 -0
  39. package/dist/esm-node/utils/crossProjectApiPlugin.mjs +34 -0
  40. package/dist/esm-node/utils/pluginGenerator.mjs +29 -0
  41. package/dist/esm-node/utils/runtimeGenerator.mjs +43 -0
  42. package/dist/types/loader.d.ts +2 -2
  43. package/dist/types/runtime/hono/adapter.d.ts +3 -3
  44. package/dist/types/server.d.ts +2 -2
  45. package/dist/types/utils/runtimeGenerator.d.ts +2 -1
  46. package/package.json +55 -33
  47. package/rslib.config.mts +4 -0
  48. package/dist/cjs/helper.js +0 -48
  49. package/dist/esm/cli.js +0 -425
  50. package/dist/esm/constants.js +0 -14
  51. package/dist/esm/helper.js +0 -13
  52. package/dist/esm/index.js +0 -1
  53. package/dist/esm/loader.js +0 -75
  54. package/dist/esm/runtime/hono/adapter.js +0 -243
  55. package/dist/esm/runtime/hono/operators.js +0 -79
  56. package/dist/esm/server.js +0 -258
  57. package/dist/esm/utils/clientGenerator.js +0 -517
  58. package/dist/esm/utils/createHonoRoutes.js +0 -319
  59. package/dist/esm/utils/crossProjectApiPlugin.js +0 -49
  60. package/dist/esm/utils/pluginGenerator.js +0 -94
  61. package/dist/esm/utils/runtimeGenerator.js +0 -55
  62. package/dist/esm-node/cli.js +0 -246
  63. package/dist/esm-node/constants.js +0 -14
  64. package/dist/esm-node/helper.js +0 -14
  65. package/dist/esm-node/loader.js +0 -49
  66. package/dist/esm-node/runtime/hono/adapter.js +0 -103
  67. package/dist/esm-node/runtime/hono/operators.js +0 -46
  68. package/dist/esm-node/server.js +0 -142
  69. package/dist/esm-node/utils/clientGenerator.js +0 -192
  70. package/dist/esm-node/utils/createHonoRoutes.js +0 -120
  71. package/dist/esm-node/utils/crossProjectApiPlugin.js +0 -47
  72. package/dist/esm-node/utils/pluginGenerator.js +0 -31
  73. package/dist/esm-node/utils/runtimeGenerator.js +0 -35
  74. package/dist/types/helper.d.ts +0 -2
  75. package/types.d.ts +0 -3
  76. /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
package/dist/cjs/cli.js CHANGED
@@ -1,280 +1,264 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
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 cli_exports = {};
30
- __export(cli_exports, {
31
- bffPlugin: () => bffPlugin,
32
- default: () => cli_default
33
- });
34
- module.exports = __toCommonJS(cli_exports);
35
- var import_path = __toESM(require("path"));
36
- var import_bff_core = require("@modern-js/bff-core");
37
- var import_server_utils = require("@modern-js/server-utils");
38
- var import_utils = require("@modern-js/utils");
39
- var import_clientGenerator = __toESM(require("./utils/clientGenerator"));
40
- var import_pluginGenerator = __toESM(require("./utils/pluginGenerator"));
41
- var import_runtimeGenerator = __toESM(require("./utils/runtimeGenerator"));
42
- const TS_CONFIG_FILENAME = "tsconfig.json";
43
- const RUNTIME_CREATE_REQUEST = "@modern-js/plugin-bff/runtime/create-request";
44
- const RUNTIME_HONO = "@modern-js/plugin-bff/hono";
45
- const bffPlugin = () => ({
46
- name: "@modern-js/plugin-bff",
47
- setup: (api) => {
48
- const compileApi = async () => {
49
- const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.useAppContext();
50
- const modernConfig = api.useResolvedConfigContext();
51
- const distDir = import_path.default.resolve(distDirectory);
52
- const apiDir = apiDirectory || import_path.default.resolve(appDirectory, import_utils.API_DIR);
53
- const sharedDir = sharedDirectory || import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
54
- const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
55
- const sourceDirs = [];
56
- if (await import_utils.fs.pathExists(apiDir)) {
57
- sourceDirs.push(apiDir);
58
- }
59
- if (await import_utils.fs.pathExists(sharedDir)) {
60
- sourceDirs.push(sharedDir);
61
- }
62
- const { server } = modernConfig;
63
- const { alias } = modernConfig.source;
64
- const { alias: resolveAlias } = modernConfig.resolve;
65
- const { babel } = modernConfig.tools;
66
- if (sourceDirs.length > 0) {
67
- const combinedAlias = [].concat(alias !== null && alias !== void 0 ? alias : []).concat(resolveAlias !== null && resolveAlias !== void 0 ? resolveAlias : []);
68
- await (0, import_server_utils.compile)(appDirectory, {
69
- server,
70
- alias: combinedAlias,
71
- babelConfig: babel
72
- }, {
73
- sourceDirs,
74
- distDir,
75
- tsconfigPath,
76
- moduleType,
77
- throwErrorInsteadOfExit: true
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
78
8
  });
79
- }
80
- };
81
- const generator = async () => {
82
- var _modernConfig_output_distPath, _modernConfig_output;
83
- const { appDirectory, apiDirectory, lambdaDirectory, port } = api.useAppContext();
84
- const modernConfig = api.useResolvedConfigContext();
85
- const relativeDistPath = (modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_output = modernConfig.output) === null || _modernConfig_output === void 0 ? void 0 : (_modernConfig_output_distPath = _modernConfig_output.distPath) === null || _modernConfig_output_distPath === void 0 ? void 0 : _modernConfig_output_distPath.root) || "dist";
86
- const { bff } = modernConfig || {};
87
- const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || import_utils.DEFAULT_API_PREFIX;
88
- const httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
89
- const apiRouter = new import_bff_core.ApiRouter({
90
- apiDir: apiDirectory,
91
- appDir: appDirectory,
92
- lambdaDir: lambdaDirectory,
93
- prefix,
94
- httpMethodDecider,
95
- isBuild: true
96
- });
97
- const lambdaDir = apiRouter.getLambdaDir();
98
- const existLambda = apiRouter.isExistLambda();
99
- const runtime = (bff === null || bff === void 0 ? void 0 : bff.runtimeCreateRequest) || RUNTIME_CREATE_REQUEST;
100
- const relativeApiPath = import_path.default.relative(appDirectory, apiDirectory);
101
- const relativeLambdaPath = import_path.default.relative(appDirectory, lambdaDir);
102
- await (0, import_pluginGenerator.default)({
103
- prefix,
104
- appDirectory,
105
- relativeDistPath,
106
- relativeApiPath,
107
- relativeLambdaPath
108
- });
109
- await (0, import_clientGenerator.default)({
110
- prefix,
111
- appDir: appDirectory,
112
- apiDir: apiDirectory,
113
- lambdaDir,
114
- existLambda,
115
- port,
116
- requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator,
117
- httpMethodDecider,
118
- relativeDistPath,
119
- relativeApiPath
120
- });
121
- await (0, import_runtimeGenerator.default)({
122
- runtime,
123
- appDirectory,
124
- relativeDistPath
125
- });
9
+ return getter;
126
10
  };
127
- const handleCrossProjectInvocation = async (isBuild = false) => {
128
- const { bff } = api.useResolvedConfigContext();
129
- if (bff === null || bff === void 0 ? void 0 : bff.crossProject) {
130
- if (!isBuild) {
131
- await compileApi();
132
- }
133
- await generator();
134
- }
135
- };
136
- const isHono = () => {
137
- const { bffRuntimeFramework } = api.useAppContext();
138
- return bffRuntimeFramework === "hono";
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
+ });
139
18
  };
140
- return {
141
- config() {
142
- var _api_useConfigContext_tools, _api_useConfigContext, _api_useConfigContext_bff, _api_useConfigContext1;
143
- const honoRuntimePath = isHono() ? {
144
- [RUNTIME_HONO]: RUNTIME_HONO
145
- } : void 0;
146
- const devServer = (_api_useConfigContext = api.useConfigContext()) === null || _api_useConfigContext === void 0 ? void 0 : (_api_useConfigContext_tools = _api_useConfigContext.tools) === null || _api_useConfigContext_tools === void 0 ? void 0 : _api_useConfigContext_tools.devServer;
147
- const prefix = ((_api_useConfigContext1 = api.useConfigContext()) === null || _api_useConfigContext1 === void 0 ? void 0 : (_api_useConfigContext_bff = _api_useConfigContext1.bff) === null || _api_useConfigContext_bff === void 0 ? void 0 : _api_useConfigContext_bff.prefix) || import_utils.DEFAULT_API_PREFIX;
148
- if (typeof devServer === "object" && devServer !== null && !Array.isArray(devServer)) {
149
- const compress = devServer.compress;
150
- if (typeof compress === "undefined" || compress === true) {
151
- devServer.compress = {
152
- filter: (req) => {
153
- var _req_url;
154
- return !((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(prefix));
155
- }
156
- };
157
- }
158
- }
159
- return {
160
- tools: {
161
- bundlerChain: (chain, { CHAIN_ID, isServer }) => {
162
- const { port, appDirectory, apiDirectory, lambdaDirectory } = api.useAppContext();
163
- const modernConfig = api.useResolvedConfigContext();
164
- const { bff } = modernConfig || {};
165
- const prefix2 = (bff === null || bff === void 0 ? void 0 : bff.prefix) || import_utils.DEFAULT_API_PREFIX;
166
- const httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
167
- const apiRouter = new import_bff_core.ApiRouter({
168
- apiDir: apiDirectory,
169
- appDir: appDirectory,
170
- lambdaDir: lambdaDirectory,
171
- prefix: prefix2,
172
- httpMethodDecider,
173
- isBuild: true
174
- });
175
- const lambdaDir = apiRouter.getLambdaDir();
176
- const existLambda = apiRouter.isExistLambda();
177
- const apiRegexp = new RegExp((0, import_utils.normalizeOutputPath)(`${apiDirectory}${import_path.default.sep}.*(.[tj]s)$`));
178
- const name = isServer ? "server" : "client";
179
- chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
180
- chain.module.rule("js-bff-api").test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
181
- prefix: prefix2,
182
- appDir: appDirectory,
183
- apiDir: apiDirectory,
184
- lambdaDir,
185
- existLambda,
186
- port,
187
- target: name,
188
- // Internal field
189
- requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator,
190
- httpMethodDecider
191
- });
192
- chain.resolve.alias.set("@api", apiDirectory);
193
- chain.resolve.alias.set("@modern-js/runtime/bff", RUNTIME_CREATE_REQUEST);
194
- }
195
- },
196
- source: {
197
- moduleScopes: [
198
- `./${import_utils.API_DIR}`,
199
- /create-request/
200
- ]
201
- },
202
- output: {
203
- externals: honoRuntimePath
204
- }
205
- };
206
- },
207
- modifyServerRoutes({ routes }) {
208
- const modernConfig = api.useResolvedConfigContext();
209
- const { bff } = modernConfig || {};
210
- const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
211
- const prefixList = [];
212
- if (Array.isArray(prefix)) {
213
- prefixList.push(...prefix);
214
- } else {
215
- prefixList.push(prefix);
216
- }
217
- const apiServerRoutes = prefixList.map((pre) => ({
218
- urlPath: pre,
219
- isApi: true,
220
- entryPath: "",
221
- isSPA: false,
222
- isSSR: false
223
- }));
224
- if (!isHono() && (bff === null || bff === void 0 ? void 0 : bff.enableHandleWeb)) {
225
- return {
226
- routes: routes.map((route) => {
227
- return {
228
- ...route,
229
- isApi: true
230
- };
231
- }).concat(apiServerRoutes)
232
- };
233
- }
234
- return {
235
- routes: routes.concat(apiServerRoutes)
236
- };
237
- },
238
- _internalServerPlugins({ plugins }) {
239
- plugins.push({
240
- name: "@modern-js/plugin-bff/server"
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
241
30
  });
242
- return {
243
- plugins
244
- };
245
- },
246
- async beforeDev() {
247
- await handleCrossProjectInvocation();
248
- },
249
- async afterBuild() {
250
- await compileApi();
251
- await handleCrossProjectInvocation(true);
252
- },
253
- async watchFiles() {
254
- var _config_bff;
255
- const appContext = api.useAppContext();
256
- const config = api.useResolvedConfigContext();
257
- if (config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.crossProject) {
258
- return [
259
- appContext.apiDirectory
260
- ];
261
- } else {
262
- return [];
263
- }
264
- },
265
- async fileChange(e) {
266
- const { filename, eventType, isPrivate } = e;
267
- const { appDirectory, apiDirectory } = api.useAppContext();
268
- const relativeApiPath = import_path.default.relative(appDirectory, apiDirectory);
269
- if (!isPrivate && (eventType === "change" || eventType === "unlink") && filename.startsWith(`${relativeApiPath}/`) && (filename.endsWith(".ts") || filename.endsWith(".js"))) {
270
- await handleCrossProjectInvocation();
271
- }
272
- }
273
31
  };
274
- }
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ default: ()=>cli,
37
+ bffPlugin: ()=>bffPlugin
275
38
  });
276
- var cli_default = bffPlugin;
277
- // Annotate the CommonJS export names for ESM import in node:
278
- 0 && (module.exports = {
279
- bffPlugin
39
+ const external_path_namespaceObject = require("path");
40
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
41
+ const bff_core_namespaceObject = require("@modern-js/bff-core");
42
+ const server_utils_namespaceObject = require("@modern-js/server-utils");
43
+ const utils_namespaceObject = require("@modern-js/utils");
44
+ const clientGenerator_js_namespaceObject = require("./utils/clientGenerator.js");
45
+ var clientGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(clientGenerator_js_namespaceObject);
46
+ const pluginGenerator_js_namespaceObject = require("./utils/pluginGenerator.js");
47
+ var pluginGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(pluginGenerator_js_namespaceObject);
48
+ const runtimeGenerator_js_namespaceObject = require("./utils/runtimeGenerator.js");
49
+ var runtimeGenerator_js_default = /*#__PURE__*/ __webpack_require__.n(runtimeGenerator_js_namespaceObject);
50
+ const TS_CONFIG_FILENAME = 'tsconfig.json';
51
+ const RUNTIME_CREATE_REQUEST = '@modern-js/plugin-bff/client';
52
+ const RUNTIME_HONO = '@modern-js/plugin-bff/server';
53
+ const bffPlugin = ()=>({
54
+ name: '@modern-js/plugin-bff',
55
+ setup: (api)=>{
56
+ const compileApi = async ()=>{
57
+ const { appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType } = api.getAppContext();
58
+ const modernConfig = api.getNormalizedConfig();
59
+ const distDir = external_path_default().resolve(distDirectory);
60
+ const apiDir = apiDirectory || external_path_default().resolve(appDirectory, utils_namespaceObject.API_DIR);
61
+ const sharedDir = sharedDirectory || external_path_default().resolve(appDirectory, utils_namespaceObject.SHARED_DIR);
62
+ const tsconfigPath = external_path_default().resolve(appDirectory, TS_CONFIG_FILENAME);
63
+ const sourceDirs = [];
64
+ if (await utils_namespaceObject.fs.pathExists(apiDir)) sourceDirs.push(apiDir);
65
+ if (await utils_namespaceObject.fs.pathExists(sharedDir)) sourceDirs.push(sharedDir);
66
+ const { server } = modernConfig;
67
+ const { alias } = modernConfig.source;
68
+ const { alias: resolveAlias } = modernConfig.resolve;
69
+ const { babel } = modernConfig.tools;
70
+ if (sourceDirs.length > 0) {
71
+ const combinedAlias = [].concat(alias ?? []).concat(resolveAlias ?? []);
72
+ await (0, server_utils_namespaceObject.compile)(appDirectory, {
73
+ server,
74
+ alias: combinedAlias,
75
+ babelConfig: babel
76
+ }, {
77
+ sourceDirs,
78
+ distDir,
79
+ tsconfigPath,
80
+ moduleType,
81
+ throwErrorInsteadOfExit: true
82
+ });
83
+ }
84
+ };
85
+ const generator = async ()=>{
86
+ const { appDirectory, apiDirectory, lambdaDirectory, port } = api.getAppContext();
87
+ const modernConfig = api.getNormalizedConfig();
88
+ const relativeDistPath = modernConfig?.output?.distPath?.root || 'dist';
89
+ const { bff } = modernConfig || {};
90
+ const prefix = bff?.prefix || utils_namespaceObject.DEFAULT_API_PREFIX;
91
+ const httpMethodDecider = bff?.httpMethodDecider;
92
+ const apiRouter = new bff_core_namespaceObject.ApiRouter({
93
+ apiDir: apiDirectory,
94
+ appDir: appDirectory,
95
+ lambdaDir: lambdaDirectory,
96
+ prefix,
97
+ httpMethodDecider,
98
+ isBuild: true
99
+ });
100
+ const lambdaDir = apiRouter.getLambdaDir();
101
+ const existLambda = apiRouter.isExistLambda();
102
+ const runtime = bff?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
103
+ const relativeApiPath = external_path_default().relative(appDirectory, apiDirectory);
104
+ const relativeLambdaPath = external_path_default().relative(appDirectory, lambdaDir);
105
+ await pluginGenerator_js_default()({
106
+ prefix,
107
+ appDirectory,
108
+ relativeDistPath,
109
+ relativeApiPath,
110
+ relativeLambdaPath
111
+ });
112
+ await clientGenerator_js_default()({
113
+ prefix,
114
+ appDir: appDirectory,
115
+ apiDir: apiDirectory,
116
+ lambdaDir,
117
+ existLambda,
118
+ port,
119
+ requestCreator: bff?.requestCreator,
120
+ httpMethodDecider,
121
+ relativeDistPath,
122
+ relativeApiPath
123
+ });
124
+ await runtimeGenerator_js_default()({
125
+ runtime,
126
+ appDirectory,
127
+ relativeDistPath
128
+ });
129
+ };
130
+ const handleCrossProjectInvocation = async (isBuild = false)=>{
131
+ const { bff } = api.getNormalizedConfig();
132
+ if (bff?.crossProject) {
133
+ if (!isBuild) await compileApi();
134
+ await generator();
135
+ }
136
+ };
137
+ const isHono = ()=>{
138
+ const { bffRuntimeFramework } = api.getAppContext();
139
+ return 'hono' === bffRuntimeFramework;
140
+ };
141
+ const createCompressConfig = (devServer, prefix)=>{
142
+ if (!devServer || 'object' != typeof devServer || Array.isArray(devServer)) return;
143
+ const { compress } = devServer;
144
+ if (void 0 === compress || true === compress) return {
145
+ filter: (req)=>!req.url?.includes(prefix)
146
+ };
147
+ if (false === compress) return false;
148
+ return compress;
149
+ };
150
+ api.config(async ()=>{
151
+ const honoRuntimePath = isHono() ? {
152
+ [RUNTIME_HONO]: RUNTIME_HONO
153
+ } : void 0;
154
+ const devServer = api.getConfig()?.tools?.devServer;
155
+ const prefix = api.getConfig()?.bff?.prefix || utils_namespaceObject.DEFAULT_API_PREFIX;
156
+ const compress = createCompressConfig(devServer, prefix);
157
+ return {
158
+ tools: {
159
+ devServer: {
160
+ compress
161
+ },
162
+ bundlerChain: (chain, { CHAIN_ID, isServer })=>{
163
+ const { port, appDirectory, apiDirectory, lambdaDirectory } = api.getAppContext();
164
+ const modernConfig = api.getNormalizedConfig();
165
+ const { bff } = modernConfig || {};
166
+ const prefix = bff?.prefix || utils_namespaceObject.DEFAULT_API_PREFIX;
167
+ const httpMethodDecider = bff?.httpMethodDecider;
168
+ const apiRouter = new bff_core_namespaceObject.ApiRouter({
169
+ apiDir: apiDirectory,
170
+ appDir: appDirectory,
171
+ lambdaDir: lambdaDirectory,
172
+ prefix,
173
+ httpMethodDecider,
174
+ isBuild: true
175
+ });
176
+ const lambdaDir = apiRouter.getLambdaDir();
177
+ const existLambda = apiRouter.isExistLambda();
178
+ const apiRegexp = new RegExp((0, utils_namespaceObject.normalizeOutputPath)(`${apiDirectory}${external_path_default().sep}.*(.[tj]s)$`));
179
+ const name = isServer ? 'server' : 'client';
180
+ const loaderPath = require.resolve('./loader');
181
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
182
+ chain.module.rule('js-bff-api').test(apiRegexp).use('custom-loader').loader(loaderPath.replace(/\\/g, '/')).options({
183
+ prefix,
184
+ appDir: appDirectory,
185
+ apiDir: apiDirectory,
186
+ lambdaDir,
187
+ existLambda,
188
+ port,
189
+ target: name,
190
+ requestCreator: bff?.requestCreator,
191
+ httpMethodDecider
192
+ });
193
+ }
194
+ },
195
+ output: {
196
+ externals: honoRuntimePath
197
+ }
198
+ };
199
+ });
200
+ api.modifyServerRoutes(({ routes })=>{
201
+ const modernConfig = api.getNormalizedConfig();
202
+ const { bff } = modernConfig || {};
203
+ const prefix = bff?.prefix || '/api';
204
+ const prefixList = [];
205
+ if (Array.isArray(prefix)) prefixList.push(...prefix);
206
+ else prefixList.push(prefix);
207
+ const apiServerRoutes = prefixList.map((pre)=>({
208
+ urlPath: pre,
209
+ isApi: true,
210
+ entryPath: '',
211
+ isSPA: false,
212
+ isSSR: false
213
+ }));
214
+ if (!isHono() && bff?.enableHandleWeb) return {
215
+ routes: routes.map((route)=>({
216
+ ...route,
217
+ isApi: true
218
+ })).concat(apiServerRoutes)
219
+ };
220
+ return {
221
+ routes: routes.concat(apiServerRoutes)
222
+ };
223
+ });
224
+ api._internalServerPlugins(({ plugins })=>{
225
+ plugins.push({
226
+ name: '@modern-js/plugin-bff/server-plugin'
227
+ });
228
+ return {
229
+ plugins
230
+ };
231
+ });
232
+ api.onBeforeDev(async ()=>{
233
+ await handleCrossProjectInvocation();
234
+ });
235
+ api.onAfterBuild(async ()=>{
236
+ await compileApi();
237
+ await handleCrossProjectInvocation(true);
238
+ });
239
+ api.addWatchFiles(async ()=>{
240
+ const appContext = api.getAppContext();
241
+ const config = api.getNormalizedConfig();
242
+ if (config?.bff?.crossProject) return [
243
+ appContext.apiDirectory
244
+ ];
245
+ return [];
246
+ });
247
+ api.onFileChanged(async (e)=>{
248
+ const { filename, eventType, isPrivate } = e;
249
+ const { appDirectory, apiDirectory } = api.getAppContext();
250
+ const relativeApiPath = external_path_default().relative(appDirectory, apiDirectory);
251
+ if (!isPrivate && ('change' === eventType || 'unlink' === eventType) && filename.startsWith(`${relativeApiPath}/`) && (filename.endsWith('.ts') || filename.endsWith('.js'))) await handleCrossProjectInvocation();
252
+ });
253
+ }
254
+ });
255
+ const cli = bffPlugin;
256
+ exports.bffPlugin = __webpack_exports__.bffPlugin;
257
+ exports["default"] = __webpack_exports__["default"];
258
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
259
+ "bffPlugin",
260
+ "default"
261
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
262
+ Object.defineProperty(exports, '__esModule', {
263
+ value: true
280
264
  });
@@ -1,39 +1,48 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var constants_exports = {};
20
- __export(constants_exports, {
21
- API_APP_NAME: () => API_APP_NAME,
22
- BUILD_FILES: () => BUILD_FILES
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ API_APP_NAME: ()=>API_APP_NAME,
28
+ BUILD_FILES: ()=>BUILD_FILES
23
29
  });
24
- module.exports = __toCommonJS(constants_exports);
25
- const API_APP_NAME = "_app";
30
+ const API_APP_NAME = '_app';
26
31
  const BUILD_FILES = [
27
- "**/*.[tj]sx?",
28
- "!**/*.test.jsx?",
29
- "!**/*.test.tsx?",
30
- "!**/*.spec.jsx?",
31
- "!**/*.spec.tsx?",
32
- "!__tests__/*.tsx?",
33
- "!__tests__/*.jsx?"
32
+ '**/*.[tj]sx?',
33
+ '!**/*.test.jsx?',
34
+ '!**/*.test.tsx?',
35
+ '!**/*.spec.jsx?',
36
+ '!**/*.spec.tsx?',
37
+ '!__tests__/*.tsx?',
38
+ '!__tests__/*.jsx?'
34
39
  ];
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- API_APP_NAME,
38
- BUILD_FILES
40
+ exports.API_APP_NAME = __webpack_exports__.API_APP_NAME;
41
+ exports.BUILD_FILES = __webpack_exports__.BUILD_FILES;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "API_APP_NAME",
44
+ "BUILD_FILES"
45
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
46
+ Object.defineProperty(exports, '__esModule', {
47
+ value: true
39
48
  });