@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,6 +1,7 @@
|
|
|
1
|
-
declare function runtimeGenerator({ runtime, appDirectory, relativeDistPath, }: {
|
|
1
|
+
declare function runtimeGenerator({ runtime, appDirectory, relativeDistPath, packageName, }: {
|
|
2
2
|
runtime: string;
|
|
3
3
|
appDirectory: string;
|
|
4
4
|
relativeDistPath: string;
|
|
5
|
+
packageName?: string;
|
|
5
6
|
}): Promise<void>;
|
|
6
7
|
export default runtimeGenerator;
|
package/package.json
CHANGED
|
@@ -15,41 +15,64 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "
|
|
18
|
+
"version": "3.0.0-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
|
-
"module": "./dist/esm/cli.
|
|
22
|
+
"module": "./dist/esm-node/cli.mjs",
|
|
23
23
|
"exports": {
|
|
24
|
-
"./types": "./types.d.ts",
|
|
25
24
|
".": {
|
|
26
25
|
"types": "./dist/types/cli.d.ts",
|
|
27
26
|
"jsnext:source": "./src/cli.ts",
|
|
27
|
+
"node": {
|
|
28
|
+
"import": "./dist/esm-node/cli.mjs",
|
|
29
|
+
"require": "./dist/cjs/cli.js"
|
|
30
|
+
},
|
|
28
31
|
"default": "./dist/cjs/cli.js"
|
|
29
32
|
},
|
|
30
33
|
"./cli": {
|
|
31
34
|
"types": "./dist/types/cli.d.ts",
|
|
32
35
|
"jsnext:source": "./src/cli.ts",
|
|
36
|
+
"node": {
|
|
37
|
+
"import": "./dist/esm-node/cli.mjs",
|
|
38
|
+
"require": "./dist/cjs/cli.js"
|
|
39
|
+
},
|
|
33
40
|
"default": "./dist/cjs/cli.js"
|
|
34
41
|
},
|
|
35
|
-
"./server": {
|
|
42
|
+
"./server-plugin": {
|
|
36
43
|
"types": "./dist/types/server.d.ts",
|
|
37
44
|
"jsnext:source": "./src/server.ts",
|
|
45
|
+
"node": {
|
|
46
|
+
"import": "./dist/esm-node/server.mjs",
|
|
47
|
+
"require": "./dist/cjs/server.js"
|
|
48
|
+
},
|
|
38
49
|
"default": "./dist/cjs/server.js"
|
|
39
50
|
},
|
|
40
51
|
"./loader": {
|
|
41
52
|
"types": "./dist/types/loader.d.ts",
|
|
42
53
|
"jsnext:source": "./src/loader.ts",
|
|
54
|
+
"node": {
|
|
55
|
+
"import": "./dist/esm-node/loader.mjs",
|
|
56
|
+
"require": "./dist/cjs/loader.js"
|
|
57
|
+
},
|
|
43
58
|
"default": "./dist/cjs/loader.js"
|
|
44
59
|
},
|
|
45
|
-
"./
|
|
60
|
+
"./server": {
|
|
46
61
|
"types": "./dist/types/runtime/hono/index.d.ts",
|
|
47
62
|
"jsnext:source": "./src/runtime/hono/index.ts",
|
|
63
|
+
"node": {
|
|
64
|
+
"import": "./dist/esm-node/runtime/hono/index.mjs",
|
|
65
|
+
"require": "./dist/cjs/runtime/hono/index.js"
|
|
66
|
+
},
|
|
48
67
|
"default": "./dist/cjs/runtime/hono/index.js"
|
|
49
68
|
},
|
|
50
|
-
"./
|
|
69
|
+
"./client": {
|
|
51
70
|
"types": "./dist/types/create-request/index.d.ts",
|
|
52
71
|
"jsnext:source": "./src/runtime/create-request/index.ts",
|
|
72
|
+
"node": {
|
|
73
|
+
"import": "./dist/esm-node/runtime/create-request/index.mjs",
|
|
74
|
+
"require": "./dist/cjs/runtime/create-request/index.js"
|
|
75
|
+
},
|
|
53
76
|
"default": "./dist/cjs/runtime/create-request/index.js"
|
|
54
77
|
}
|
|
55
78
|
},
|
|
@@ -61,46 +84,46 @@
|
|
|
61
84
|
"cli": [
|
|
62
85
|
"./dist/types/cli.d.ts"
|
|
63
86
|
],
|
|
64
|
-
"server": [
|
|
87
|
+
"server-plugin": [
|
|
65
88
|
"./dist/types/server.d.ts"
|
|
66
89
|
],
|
|
67
|
-
"
|
|
90
|
+
"server": [
|
|
68
91
|
"./dist/types/runtime/hono/index.d.ts"
|
|
69
92
|
],
|
|
70
|
-
"
|
|
93
|
+
"client": [
|
|
71
94
|
"./dist/types/runtime/create-request/index.d.ts"
|
|
72
95
|
]
|
|
73
96
|
}
|
|
74
97
|
},
|
|
75
98
|
"dependencies": {
|
|
76
|
-
"@babel/core": "^7.
|
|
99
|
+
"@babel/core": "^7.28.5",
|
|
77
100
|
"@swc/helpers": "^0.5.17",
|
|
78
101
|
"type-is": "^1.6.18",
|
|
79
|
-
"@modern-js/bff-core": "
|
|
80
|
-
"@modern-js/create-request": "
|
|
81
|
-
"@modern-js/server-core": "
|
|
82
|
-
"@modern-js/
|
|
83
|
-
"@modern-js/utils": "
|
|
102
|
+
"@modern-js/bff-core": "3.0.0-alpha.0",
|
|
103
|
+
"@modern-js/create-request": "3.0.0-alpha.0",
|
|
104
|
+
"@modern-js/server-core": "3.0.0-alpha.0",
|
|
105
|
+
"@modern-js/builder": "3.0.0-alpha.0",
|
|
106
|
+
"@modern-js/server-utils": "3.0.0-alpha.0",
|
|
107
|
+
"@modern-js/utils": "3.0.0-alpha.0"
|
|
84
108
|
},
|
|
85
109
|
"devDependencies": {
|
|
86
110
|
"@rsbuild/core": "1.6.15",
|
|
111
|
+
"@rslib/core": "0.18.5",
|
|
87
112
|
"@types/babel__core": "^7.20.5",
|
|
88
|
-
"@types/jest": "^29",
|
|
89
|
-
"@types/node": "^
|
|
90
|
-
"@types/type-is": "^1.6.
|
|
91
|
-
"jest": "^29",
|
|
113
|
+
"@types/jest": "^29.5.14",
|
|
114
|
+
"@types/node": "^20",
|
|
115
|
+
"@types/type-is": "^1.6.7",
|
|
116
|
+
"jest": "^29.7.0",
|
|
92
117
|
"memfs": "^3.5.3",
|
|
93
|
-
"ts-jest": "^29.
|
|
118
|
+
"ts-jest": "^29.4.6",
|
|
94
119
|
"typescript": "^5",
|
|
95
|
-
"webpack": "^5.103.0",
|
|
96
120
|
"zod": "^3.22.3",
|
|
97
|
-
"@modern-js/
|
|
98
|
-
"@modern-js/
|
|
99
|
-
"@modern-js/
|
|
100
|
-
"@modern-js/
|
|
101
|
-
"@modern-js/types": "
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@scripts/build": "2.66.0",
|
|
121
|
+
"@modern-js/app-tools": "3.0.0-alpha.0",
|
|
122
|
+
"@modern-js/bff-runtime": "3.0.0-alpha.0",
|
|
123
|
+
"@modern-js/plugin": "3.0.0-alpha.0",
|
|
124
|
+
"@modern-js/runtime": "3.0.0-alpha.0",
|
|
125
|
+
"@modern-js/types": "3.0.0-alpha.0",
|
|
126
|
+
"@modern-js/rslib": "2.68.10",
|
|
104
127
|
"@scripts/jest-config": "2.66.0"
|
|
105
128
|
},
|
|
106
129
|
"sideEffects": false,
|
|
@@ -109,9 +132,8 @@
|
|
|
109
132
|
"access": "public"
|
|
110
133
|
},
|
|
111
134
|
"scripts": {
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"dev": "modern-lib build --watch",
|
|
135
|
+
"build": "rslib build",
|
|
136
|
+
"dev": "rslib build --watch",
|
|
115
137
|
"test": "jest --passWithNoTests"
|
|
116
138
|
}
|
|
117
139
|
}
|
package/rslib.config.mts
ADDED
package/dist/cjs/helper.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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 helper_exports = {};
|
|
30
|
-
__export(helper_exports, {
|
|
31
|
-
registerModernRuntimePath: () => registerModernRuntimePath
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(helper_exports);
|
|
34
|
-
var path = __toESM(require("path"));
|
|
35
|
-
var import_bff_core = require("@modern-js/bff-core");
|
|
36
|
-
const serverRuntimeAlias = "@modern-js/runtime/server";
|
|
37
|
-
const serverRuntimePath = ".runtime-exports/server";
|
|
38
|
-
const registerModernRuntimePath = (internalDirectory) => {
|
|
39
|
-
const paths = {
|
|
40
|
-
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
41
|
-
};
|
|
42
|
-
const unRegister = (0, import_bff_core.registerPaths)(paths);
|
|
43
|
-
return unRegister;
|
|
44
|
-
};
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
registerModernRuntimePath
|
|
48
|
-
});
|
package/dist/esm/cli.js
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
6
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
7
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import { ApiRouter } from "@modern-js/bff-core";
|
|
10
|
-
import { compile } from "@modern-js/server-utils";
|
|
11
|
-
import { fs, API_DIR, DEFAULT_API_PREFIX, SHARED_DIR, normalizeOutputPath } from "@modern-js/utils";
|
|
12
|
-
import clientGenerator from "./utils/clientGenerator";
|
|
13
|
-
import pluginGenerator from "./utils/pluginGenerator";
|
|
14
|
-
import runtimeGenerator from "./utils/runtimeGenerator";
|
|
15
|
-
var TS_CONFIG_FILENAME = "tsconfig.json";
|
|
16
|
-
var RUNTIME_CREATE_REQUEST = "@modern-js/plugin-bff/runtime/create-request";
|
|
17
|
-
var RUNTIME_HONO = "@modern-js/plugin-bff/hono";
|
|
18
|
-
var bffPlugin = function() {
|
|
19
|
-
return {
|
|
20
|
-
name: "@modern-js/plugin-bff",
|
|
21
|
-
setup: function(api) {
|
|
22
|
-
var compileApi = function() {
|
|
23
|
-
var _ref = _async_to_generator(function() {
|
|
24
|
-
var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, moduleType, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, alias, _modernConfig_resolve, resolveAlias, babel, combinedAlias;
|
|
25
|
-
return _ts_generator(this, function(_state) {
|
|
26
|
-
switch (_state.label) {
|
|
27
|
-
case 0:
|
|
28
|
-
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory, moduleType = _api_useAppContext.moduleType;
|
|
29
|
-
modernConfig = api.useResolvedConfigContext();
|
|
30
|
-
distDir = path.resolve(distDirectory);
|
|
31
|
-
apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
|
|
32
|
-
sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
|
|
33
|
-
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
34
|
-
sourceDirs = [];
|
|
35
|
-
return [
|
|
36
|
-
4,
|
|
37
|
-
fs.pathExists(apiDir)
|
|
38
|
-
];
|
|
39
|
-
case 1:
|
|
40
|
-
if (_state.sent()) {
|
|
41
|
-
sourceDirs.push(apiDir);
|
|
42
|
-
}
|
|
43
|
-
return [
|
|
44
|
-
4,
|
|
45
|
-
fs.pathExists(sharedDir)
|
|
46
|
-
];
|
|
47
|
-
case 2:
|
|
48
|
-
if (_state.sent()) {
|
|
49
|
-
sourceDirs.push(sharedDir);
|
|
50
|
-
}
|
|
51
|
-
server = modernConfig.server;
|
|
52
|
-
alias = modernConfig.source.alias;
|
|
53
|
-
_modernConfig_resolve = modernConfig.resolve, resolveAlias = _modernConfig_resolve.alias;
|
|
54
|
-
babel = modernConfig.tools.babel;
|
|
55
|
-
if (!(sourceDirs.length > 0))
|
|
56
|
-
return [
|
|
57
|
-
3,
|
|
58
|
-
4
|
|
59
|
-
];
|
|
60
|
-
combinedAlias = [].concat(alias !== null && alias !== void 0 ? alias : []).concat(resolveAlias !== null && resolveAlias !== void 0 ? resolveAlias : []);
|
|
61
|
-
return [
|
|
62
|
-
4,
|
|
63
|
-
compile(appDirectory, {
|
|
64
|
-
server,
|
|
65
|
-
alias: combinedAlias,
|
|
66
|
-
babelConfig: babel
|
|
67
|
-
}, {
|
|
68
|
-
sourceDirs,
|
|
69
|
-
distDir,
|
|
70
|
-
tsconfigPath,
|
|
71
|
-
moduleType,
|
|
72
|
-
throwErrorInsteadOfExit: true
|
|
73
|
-
})
|
|
74
|
-
];
|
|
75
|
-
case 3:
|
|
76
|
-
_state.sent();
|
|
77
|
-
_state.label = 4;
|
|
78
|
-
case 4:
|
|
79
|
-
return [
|
|
80
|
-
2
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
return function compileApi2() {
|
|
86
|
-
return _ref.apply(this, arguments);
|
|
87
|
-
};
|
|
88
|
-
}();
|
|
89
|
-
var generator = function() {
|
|
90
|
-
var _ref = _async_to_generator(function() {
|
|
91
|
-
var _modernConfig_output_distPath, _modernConfig_output, _api_useAppContext, appDirectory, apiDirectory, lambdaDirectory, port, modernConfig, relativeDistPath, bff, prefix, httpMethodDecider, apiRouter, lambdaDir, existLambda, runtime, relativeApiPath, relativeLambdaPath;
|
|
92
|
-
return _ts_generator(this, function(_state) {
|
|
93
|
-
switch (_state.label) {
|
|
94
|
-
case 0:
|
|
95
|
-
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory, port = _api_useAppContext.port;
|
|
96
|
-
modernConfig = api.useResolvedConfigContext();
|
|
97
|
-
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";
|
|
98
|
-
bff = (modernConfig || {}).bff;
|
|
99
|
-
prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
100
|
-
httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
|
|
101
|
-
apiRouter = new ApiRouter({
|
|
102
|
-
apiDir: apiDirectory,
|
|
103
|
-
appDir: appDirectory,
|
|
104
|
-
lambdaDir: lambdaDirectory,
|
|
105
|
-
prefix,
|
|
106
|
-
httpMethodDecider,
|
|
107
|
-
isBuild: true
|
|
108
|
-
});
|
|
109
|
-
lambdaDir = apiRouter.getLambdaDir();
|
|
110
|
-
existLambda = apiRouter.isExistLambda();
|
|
111
|
-
runtime = (bff === null || bff === void 0 ? void 0 : bff.runtimeCreateRequest) || RUNTIME_CREATE_REQUEST;
|
|
112
|
-
relativeApiPath = path.relative(appDirectory, apiDirectory);
|
|
113
|
-
relativeLambdaPath = path.relative(appDirectory, lambdaDir);
|
|
114
|
-
return [
|
|
115
|
-
4,
|
|
116
|
-
pluginGenerator({
|
|
117
|
-
prefix,
|
|
118
|
-
appDirectory,
|
|
119
|
-
relativeDistPath,
|
|
120
|
-
relativeApiPath,
|
|
121
|
-
relativeLambdaPath
|
|
122
|
-
})
|
|
123
|
-
];
|
|
124
|
-
case 1:
|
|
125
|
-
_state.sent();
|
|
126
|
-
return [
|
|
127
|
-
4,
|
|
128
|
-
clientGenerator({
|
|
129
|
-
prefix,
|
|
130
|
-
appDir: appDirectory,
|
|
131
|
-
apiDir: apiDirectory,
|
|
132
|
-
lambdaDir,
|
|
133
|
-
existLambda,
|
|
134
|
-
port,
|
|
135
|
-
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator,
|
|
136
|
-
httpMethodDecider,
|
|
137
|
-
relativeDistPath,
|
|
138
|
-
relativeApiPath
|
|
139
|
-
})
|
|
140
|
-
];
|
|
141
|
-
case 2:
|
|
142
|
-
_state.sent();
|
|
143
|
-
return [
|
|
144
|
-
4,
|
|
145
|
-
runtimeGenerator({
|
|
146
|
-
runtime,
|
|
147
|
-
appDirectory,
|
|
148
|
-
relativeDistPath
|
|
149
|
-
})
|
|
150
|
-
];
|
|
151
|
-
case 3:
|
|
152
|
-
_state.sent();
|
|
153
|
-
return [
|
|
154
|
-
2
|
|
155
|
-
];
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
return function generator2() {
|
|
160
|
-
return _ref.apply(this, arguments);
|
|
161
|
-
};
|
|
162
|
-
}();
|
|
163
|
-
var handleCrossProjectInvocation = function() {
|
|
164
|
-
var _ref = _async_to_generator(function() {
|
|
165
|
-
var isBuild, bff;
|
|
166
|
-
var _arguments = arguments;
|
|
167
|
-
return _ts_generator(this, function(_state) {
|
|
168
|
-
switch (_state.label) {
|
|
169
|
-
case 0:
|
|
170
|
-
isBuild = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : false;
|
|
171
|
-
bff = api.useResolvedConfigContext().bff;
|
|
172
|
-
if (!(bff === null || bff === void 0 ? void 0 : bff.crossProject))
|
|
173
|
-
return [
|
|
174
|
-
3,
|
|
175
|
-
4
|
|
176
|
-
];
|
|
177
|
-
if (!!isBuild)
|
|
178
|
-
return [
|
|
179
|
-
3,
|
|
180
|
-
2
|
|
181
|
-
];
|
|
182
|
-
return [
|
|
183
|
-
4,
|
|
184
|
-
compileApi()
|
|
185
|
-
];
|
|
186
|
-
case 1:
|
|
187
|
-
_state.sent();
|
|
188
|
-
_state.label = 2;
|
|
189
|
-
case 2:
|
|
190
|
-
return [
|
|
191
|
-
4,
|
|
192
|
-
generator()
|
|
193
|
-
];
|
|
194
|
-
case 3:
|
|
195
|
-
_state.sent();
|
|
196
|
-
_state.label = 4;
|
|
197
|
-
case 4:
|
|
198
|
-
return [
|
|
199
|
-
2
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
return function handleCrossProjectInvocation2() {
|
|
205
|
-
return _ref.apply(this, arguments);
|
|
206
|
-
};
|
|
207
|
-
}();
|
|
208
|
-
var isHono = function() {
|
|
209
|
-
var bffRuntimeFramework = api.useAppContext().bffRuntimeFramework;
|
|
210
|
-
return bffRuntimeFramework === "hono";
|
|
211
|
-
};
|
|
212
|
-
return {
|
|
213
|
-
config: function config() {
|
|
214
|
-
var _api_useConfigContext_tools, _api_useConfigContext, _api_useConfigContext_bff, _api_useConfigContext1;
|
|
215
|
-
var honoRuntimePath = isHono() ? _define_property({}, RUNTIME_HONO, RUNTIME_HONO) : void 0;
|
|
216
|
-
var 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;
|
|
217
|
-
var 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) || DEFAULT_API_PREFIX;
|
|
218
|
-
if ((typeof devServer === "undefined" ? "undefined" : _type_of(devServer)) === "object" && devServer !== null && !Array.isArray(devServer)) {
|
|
219
|
-
var compress = devServer.compress;
|
|
220
|
-
if (typeof compress === "undefined" || compress === true) {
|
|
221
|
-
devServer.compress = {
|
|
222
|
-
filter: function(req) {
|
|
223
|
-
var _req_url;
|
|
224
|
-
return !((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(prefix));
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
tools: {
|
|
231
|
-
bundlerChain: function(chain, param) {
|
|
232
|
-
var CHAIN_ID = param.CHAIN_ID, isServer = param.isServer;
|
|
233
|
-
var _api_useAppContext = api.useAppContext(), port = _api_useAppContext.port, appDirectory = _api_useAppContext.appDirectory, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory;
|
|
234
|
-
var modernConfig = api.useResolvedConfigContext();
|
|
235
|
-
var bff = (modernConfig || {}).bff;
|
|
236
|
-
var prefix2 = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
237
|
-
var httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
|
|
238
|
-
var apiRouter = new ApiRouter({
|
|
239
|
-
apiDir: apiDirectory,
|
|
240
|
-
appDir: appDirectory,
|
|
241
|
-
lambdaDir: lambdaDirectory,
|
|
242
|
-
prefix: prefix2,
|
|
243
|
-
httpMethodDecider,
|
|
244
|
-
isBuild: true
|
|
245
|
-
});
|
|
246
|
-
var lambdaDir = apiRouter.getLambdaDir();
|
|
247
|
-
var existLambda = apiRouter.isExistLambda();
|
|
248
|
-
var apiRegexp = new RegExp(normalizeOutputPath("".concat(apiDirectory).concat(path.sep, ".*(.[tj]s)$")));
|
|
249
|
-
var name = isServer ? "server" : "client";
|
|
250
|
-
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
251
|
-
chain.module.rule("js-bff-api").test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
252
|
-
prefix: prefix2,
|
|
253
|
-
appDir: appDirectory,
|
|
254
|
-
apiDir: apiDirectory,
|
|
255
|
-
lambdaDir,
|
|
256
|
-
existLambda,
|
|
257
|
-
port,
|
|
258
|
-
target: name,
|
|
259
|
-
// Internal field
|
|
260
|
-
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator,
|
|
261
|
-
httpMethodDecider
|
|
262
|
-
});
|
|
263
|
-
chain.resolve.alias.set("@api", apiDirectory);
|
|
264
|
-
chain.resolve.alias.set("@modern-js/runtime/bff", RUNTIME_CREATE_REQUEST);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
source: {
|
|
268
|
-
moduleScopes: [
|
|
269
|
-
"./".concat(API_DIR),
|
|
270
|
-
/create-request/
|
|
271
|
-
]
|
|
272
|
-
},
|
|
273
|
-
output: {
|
|
274
|
-
externals: honoRuntimePath
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
modifyServerRoutes: function modifyServerRoutes(param) {
|
|
279
|
-
var routes = param.routes;
|
|
280
|
-
var modernConfig = api.useResolvedConfigContext();
|
|
281
|
-
var bff = (modernConfig || {}).bff;
|
|
282
|
-
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
|
|
283
|
-
var prefixList = [];
|
|
284
|
-
if (Array.isArray(prefix)) {
|
|
285
|
-
var _prefixList;
|
|
286
|
-
(_prefixList = prefixList).push.apply(_prefixList, _to_consumable_array(prefix));
|
|
287
|
-
} else {
|
|
288
|
-
prefixList.push(prefix);
|
|
289
|
-
}
|
|
290
|
-
var apiServerRoutes = prefixList.map(function(pre) {
|
|
291
|
-
return {
|
|
292
|
-
urlPath: pre,
|
|
293
|
-
isApi: true,
|
|
294
|
-
entryPath: "",
|
|
295
|
-
isSPA: false,
|
|
296
|
-
isSSR: false
|
|
297
|
-
};
|
|
298
|
-
});
|
|
299
|
-
if (!isHono() && (bff === null || bff === void 0 ? void 0 : bff.enableHandleWeb)) {
|
|
300
|
-
return {
|
|
301
|
-
routes: routes.map(function(route) {
|
|
302
|
-
return _object_spread_props(_object_spread({}, route), {
|
|
303
|
-
isApi: true
|
|
304
|
-
});
|
|
305
|
-
}).concat(apiServerRoutes)
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
routes: routes.concat(apiServerRoutes)
|
|
310
|
-
};
|
|
311
|
-
},
|
|
312
|
-
_internalServerPlugins: function _internalServerPlugins(param) {
|
|
313
|
-
var plugins = param.plugins;
|
|
314
|
-
plugins.push({
|
|
315
|
-
name: "@modern-js/plugin-bff/server"
|
|
316
|
-
});
|
|
317
|
-
return {
|
|
318
|
-
plugins
|
|
319
|
-
};
|
|
320
|
-
},
|
|
321
|
-
beforeDev: function beforeDev() {
|
|
322
|
-
return _async_to_generator(function() {
|
|
323
|
-
return _ts_generator(this, function(_state) {
|
|
324
|
-
switch (_state.label) {
|
|
325
|
-
case 0:
|
|
326
|
-
return [
|
|
327
|
-
4,
|
|
328
|
-
handleCrossProjectInvocation()
|
|
329
|
-
];
|
|
330
|
-
case 1:
|
|
331
|
-
_state.sent();
|
|
332
|
-
return [
|
|
333
|
-
2
|
|
334
|
-
];
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
})();
|
|
338
|
-
},
|
|
339
|
-
afterBuild: function afterBuild() {
|
|
340
|
-
return _async_to_generator(function() {
|
|
341
|
-
return _ts_generator(this, function(_state) {
|
|
342
|
-
switch (_state.label) {
|
|
343
|
-
case 0:
|
|
344
|
-
return [
|
|
345
|
-
4,
|
|
346
|
-
compileApi()
|
|
347
|
-
];
|
|
348
|
-
case 1:
|
|
349
|
-
_state.sent();
|
|
350
|
-
return [
|
|
351
|
-
4,
|
|
352
|
-
handleCrossProjectInvocation(true)
|
|
353
|
-
];
|
|
354
|
-
case 2:
|
|
355
|
-
_state.sent();
|
|
356
|
-
return [
|
|
357
|
-
2
|
|
358
|
-
];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
})();
|
|
362
|
-
},
|
|
363
|
-
watchFiles: function watchFiles() {
|
|
364
|
-
return _async_to_generator(function() {
|
|
365
|
-
var _config_bff, appContext, config;
|
|
366
|
-
return _ts_generator(this, function(_state) {
|
|
367
|
-
appContext = api.useAppContext();
|
|
368
|
-
config = api.useResolvedConfigContext();
|
|
369
|
-
if (config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.crossProject) {
|
|
370
|
-
return [
|
|
371
|
-
2,
|
|
372
|
-
[
|
|
373
|
-
appContext.apiDirectory
|
|
374
|
-
]
|
|
375
|
-
];
|
|
376
|
-
} else {
|
|
377
|
-
return [
|
|
378
|
-
2,
|
|
379
|
-
[]
|
|
380
|
-
];
|
|
381
|
-
}
|
|
382
|
-
return [
|
|
383
|
-
2
|
|
384
|
-
];
|
|
385
|
-
});
|
|
386
|
-
})();
|
|
387
|
-
},
|
|
388
|
-
fileChange: function fileChange(e) {
|
|
389
|
-
return _async_to_generator(function() {
|
|
390
|
-
var filename, eventType, isPrivate, _api_useAppContext, appDirectory, apiDirectory, relativeApiPath;
|
|
391
|
-
return _ts_generator(this, function(_state) {
|
|
392
|
-
switch (_state.label) {
|
|
393
|
-
case 0:
|
|
394
|
-
filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
|
|
395
|
-
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, apiDirectory = _api_useAppContext.apiDirectory;
|
|
396
|
-
relativeApiPath = path.relative(appDirectory, apiDirectory);
|
|
397
|
-
if (!(!isPrivate && (eventType === "change" || eventType === "unlink") && filename.startsWith("".concat(relativeApiPath, "/")) && (filename.endsWith(".ts") || filename.endsWith(".js"))))
|
|
398
|
-
return [
|
|
399
|
-
3,
|
|
400
|
-
2
|
|
401
|
-
];
|
|
402
|
-
return [
|
|
403
|
-
4,
|
|
404
|
-
handleCrossProjectInvocation()
|
|
405
|
-
];
|
|
406
|
-
case 1:
|
|
407
|
-
_state.sent();
|
|
408
|
-
_state.label = 2;
|
|
409
|
-
case 2:
|
|
410
|
-
return [
|
|
411
|
-
2
|
|
412
|
-
];
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
})();
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
};
|
|
421
|
-
var cli_default = bffPlugin;
|
|
422
|
-
export {
|
|
423
|
-
bffPlugin,
|
|
424
|
-
cli_default as default
|
|
425
|
-
};
|
package/dist/esm/constants.js
DELETED
package/dist/esm/helper.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { registerPaths } from "@modern-js/bff-core";
|
|
4
|
-
var serverRuntimeAlias = "@modern-js/runtime/server";
|
|
5
|
-
var serverRuntimePath = ".runtime-exports/server";
|
|
6
|
-
var registerModernRuntimePath = function(internalDirectory) {
|
|
7
|
-
var paths = _define_property({}, serverRuntimeAlias, path.join(internalDirectory, serverRuntimePath));
|
|
8
|
-
var unRegister = registerPaths(paths);
|
|
9
|
-
return unRegister;
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
registerModernRuntimePath
|
|
13
|
-
};
|
package/dist/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|