@modern-js/plugin-bff 2.0.0-beta.2 → 2.0.0-beta.4
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 +90 -0
- package/dist/js/modern/cli.js +102 -92
- package/dist/js/modern/constants.js +14 -2
- package/dist/js/modern/helper.js +8 -6
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/loader.js +66 -50
- package/dist/js/modern/server.js +39 -28
- package/dist/js/node/cli.js +122 -102
- package/dist/js/node/constants.js +32 -9
- package/dist/js/node/helper.js +33 -14
- package/dist/js/node/index.js +17 -16
- package/dist/js/node/loader.js +84 -56
- package/dist/js/node/server.js +70 -42
- package/dist/js/treeshaking/cli.js +290 -148
- package/dist/js/treeshaking/constants.js +11 -2
- package/dist/js/treeshaking/helper.js +22 -10
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/loader.js +185 -66
- package/dist/js/treeshaking/server.js +146 -78
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/server.d.ts +2 -0
- package/package.json +15 -15
package/dist/js/node/server.js
CHANGED
|
@@ -1,78 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => server_default
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var import_constants = require("./constants");
|
|
33
|
+
var __defProp2 = Object.defineProperty;
|
|
34
|
+
var __defProps = Object.defineProperties;
|
|
35
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
36
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
37
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
38
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
39
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
40
|
+
var __spreadValues = (a, b) => {
|
|
41
|
+
for (var prop in b || (b = {}))
|
|
42
|
+
if (__hasOwnProp2.call(b, prop))
|
|
43
|
+
__defNormalProp(a, prop, b[prop]);
|
|
44
|
+
if (__getOwnPropSymbols)
|
|
45
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
46
|
+
if (__propIsEnum.call(b, prop))
|
|
47
|
+
__defNormalProp(a, prop, b[prop]);
|
|
48
|
+
}
|
|
49
|
+
return a;
|
|
50
|
+
};
|
|
51
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
15
52
|
class Storage {
|
|
16
53
|
constructor() {
|
|
17
|
-
|
|
54
|
+
this.middlewares = [];
|
|
18
55
|
}
|
|
19
56
|
reset() {
|
|
20
57
|
this.middlewares = [];
|
|
21
58
|
}
|
|
22
59
|
}
|
|
23
|
-
const createTransformAPI = storage => ({
|
|
60
|
+
const createTransformAPI = (storage) => ({
|
|
24
61
|
addMiddleware(fn) {
|
|
25
62
|
storage.middlewares.push(fn);
|
|
26
63
|
}
|
|
27
64
|
});
|
|
28
|
-
var
|
|
29
|
-
name:
|
|
30
|
-
setup: api => {
|
|
65
|
+
var server_default = () => ({
|
|
66
|
+
name: "@modern-js/plugin-bff",
|
|
67
|
+
setup: (api) => {
|
|
31
68
|
const storage = new Storage();
|
|
32
69
|
const transformAPI = createTransformAPI(storage);
|
|
33
|
-
let apiAppPath =
|
|
70
|
+
let apiAppPath = "";
|
|
34
71
|
return {
|
|
35
72
|
prepare() {
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
43
|
-
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
44
|
-
if (apiMod && typeof apiMod === 'function') {
|
|
73
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
74
|
+
const root = (0, import_utils.isProd)() ? distDirectory : appDirectory;
|
|
75
|
+
const apiPath = import_path.default.resolve(root || process.cwd(), import_utils.API_DIR);
|
|
76
|
+
apiAppPath = import_path.default.resolve(apiPath, import_constants.API_APP_NAME);
|
|
77
|
+
const apiMod = (0, import_utils.requireExistModule)(apiAppPath);
|
|
78
|
+
if (apiMod && typeof apiMod === "function") {
|
|
45
79
|
apiMod(transformAPI);
|
|
46
80
|
}
|
|
47
81
|
},
|
|
48
82
|
reset() {
|
|
49
83
|
storage.reset();
|
|
50
|
-
const newApiModule = (0,
|
|
51
|
-
if (newApiModule && typeof newApiModule ===
|
|
84
|
+
const newApiModule = (0, import_utils.requireExistModule)(apiAppPath);
|
|
85
|
+
if (newApiModule && typeof newApiModule === "function") {
|
|
52
86
|
newApiModule(transformAPI);
|
|
53
87
|
}
|
|
54
88
|
},
|
|
55
|
-
gather({
|
|
56
|
-
|
|
57
|
-
}) {
|
|
58
|
-
storage.middlewares.forEach(mid => {
|
|
89
|
+
gather({ addAPIMiddleware }) {
|
|
90
|
+
storage.middlewares.forEach((mid) => {
|
|
59
91
|
addAPIMiddleware(mid);
|
|
60
92
|
});
|
|
61
93
|
},
|
|
62
94
|
prepareApiServer(props, next) {
|
|
63
|
-
const {
|
|
64
|
-
|
|
65
|
-
prefix
|
|
66
|
-
} = props;
|
|
67
|
-
const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
|
|
95
|
+
const { pwd, prefix } = props;
|
|
96
|
+
const apiDir = import_path.default.resolve(pwd, import_utils.API_DIR);
|
|
68
97
|
const appContext = api.useAppContext();
|
|
69
|
-
const apiRouter = new
|
|
98
|
+
const apiRouter = new import_bff_core.ApiRouter({
|
|
70
99
|
apiDir,
|
|
71
100
|
prefix
|
|
72
101
|
});
|
|
73
102
|
const apiMode = apiRouter.getApiMode();
|
|
74
103
|
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
75
|
-
api.setAppContext(
|
|
104
|
+
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
76
105
|
apiRouter,
|
|
77
106
|
apiHandlerInfos,
|
|
78
107
|
apiMode
|
|
@@ -82,4 +111,3 @@ var _default = () => ({
|
|
|
82
111
|
};
|
|
83
112
|
}
|
|
84
113
|
});
|
|
85
|
-
exports.default = _default;
|
|
@@ -1,158 +1,300 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
var _ref2 = modernConfig || {},
|
|
31
|
-
bff = _ref2.bff;
|
|
32
|
-
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
33
|
-
var rootDir = path.resolve(appDirectory, API_DIR);
|
|
34
|
-
chain.resolve.alias.set('@api', rootDir);
|
|
35
|
-
var apiRouter = new ApiRouter({
|
|
36
|
-
apiDir: rootDir,
|
|
37
|
-
prefix: prefix
|
|
38
|
-
});
|
|
39
|
-
var lambdaDir = apiRouter.getLambdaDir();
|
|
40
|
-
var existLambda = apiRouter.isExistLambda();
|
|
41
|
-
var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
|
|
42
|
-
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
43
|
-
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
44
|
-
prefix: prefix,
|
|
45
|
-
apiDir: rootDir,
|
|
46
|
-
lambdaDir: lambdaDir,
|
|
47
|
-
existLambda: existLambda,
|
|
48
|
-
port: port,
|
|
49
|
-
target: name
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
source: {
|
|
54
|
-
moduleScopes: ["./".concat(API_DIR), /create-request/]
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithoutHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
55
30
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterableToArray(iter) {
|
|
39
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
40
|
+
}
|
|
41
|
+
function _nonIterableSpread() {
|
|
42
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
+
}
|
|
44
|
+
function _toConsumableArray(arr) {
|
|
45
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
46
|
+
}
|
|
47
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
48
|
+
if (!o) return;
|
|
49
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
50
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
51
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
53
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
54
|
+
}
|
|
55
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
56
|
+
var f, y, t, g, _ = {
|
|
57
|
+
label: 0,
|
|
58
|
+
sent: function() {
|
|
59
|
+
if (t[0] & 1) throw t[1];
|
|
60
|
+
return t[1];
|
|
84
61
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
62
|
+
trys: [],
|
|
63
|
+
ops: []
|
|
64
|
+
};
|
|
65
|
+
return g = {
|
|
66
|
+
next: verb(0),
|
|
67
|
+
"throw": verb(1),
|
|
68
|
+
"return": verb(2)
|
|
69
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
70
|
+
return this;
|
|
71
|
+
}), g;
|
|
72
|
+
function verb(n) {
|
|
73
|
+
return function(v) {
|
|
74
|
+
return step([
|
|
75
|
+
n,
|
|
76
|
+
v
|
|
77
|
+
]);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function step(op) {
|
|
81
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
82
|
+
while(_)try {
|
|
83
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
84
|
+
if (y = 0, t) op = [
|
|
85
|
+
op[0] & 2,
|
|
86
|
+
t.value
|
|
87
|
+
];
|
|
88
|
+
switch(op[0]){
|
|
89
|
+
case 0:
|
|
90
|
+
case 1:
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
_.label++;
|
|
95
|
+
return {
|
|
96
|
+
value: op[1],
|
|
97
|
+
done: false
|
|
98
|
+
};
|
|
99
|
+
case 5:
|
|
100
|
+
_.label++;
|
|
101
|
+
y = op[1];
|
|
102
|
+
op = [
|
|
103
|
+
0
|
|
104
|
+
];
|
|
105
|
+
continue;
|
|
106
|
+
case 7:
|
|
107
|
+
op = _.ops.pop();
|
|
108
|
+
_.trys.pop();
|
|
109
|
+
continue;
|
|
110
|
+
default:
|
|
111
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
112
|
+
_ = 0;
|
|
113
|
+
continue;
|
|
96
114
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, _callee);
|
|
103
|
-
}))();
|
|
104
|
-
},
|
|
105
|
-
afterBuild: function afterBuild() {
|
|
106
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
107
|
-
var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig$source, alias, define, globalVars, babel;
|
|
108
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
109
|
-
while (1) {
|
|
110
|
-
switch (_context2.prev = _context2.next) {
|
|
111
|
-
case 0:
|
|
112
|
-
if (unRegisterResolveRuntimePath) {
|
|
113
|
-
unRegisterResolveRuntimePath();
|
|
115
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
116
|
+
_.label = op[1];
|
|
117
|
+
break;
|
|
114
118
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
120
|
-
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
121
|
-
sourceDirs = [];
|
|
122
|
-
if (fs.existsSync(apiDir)) {
|
|
123
|
-
sourceDirs.push(apiDir);
|
|
119
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
120
|
+
_.label = t[1];
|
|
121
|
+
t = op;
|
|
122
|
+
break;
|
|
124
123
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
124
|
+
if (t && _.label < t[2]) {
|
|
125
|
+
_.label = t[2];
|
|
126
|
+
_.ops.push(op);
|
|
127
|
+
break;
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
if (t[2]) _.ops.pop();
|
|
130
|
+
_.trys.pop();
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
op = body.call(thisArg, _);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
op = [
|
|
136
|
+
6,
|
|
137
|
+
e
|
|
138
|
+
];
|
|
139
|
+
y = 0;
|
|
140
|
+
} finally{
|
|
141
|
+
f = t = 0;
|
|
142
|
+
}
|
|
143
|
+
if (op[0] & 5) throw op[1];
|
|
144
|
+
return {
|
|
145
|
+
value: op[0] ? op[1] : void 0,
|
|
146
|
+
done: true
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
import path from "path";
|
|
151
|
+
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from "@modern-js/utils";
|
|
152
|
+
import { compile } from "@modern-js/server-utils";
|
|
153
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
154
|
+
import { registerModernRuntimePath } from "./helper";
|
|
155
|
+
var DEFAULT_API_PREFIX = "/api";
|
|
156
|
+
var TS_CONFIG_FILENAME = "tsconfig.json";
|
|
157
|
+
var cli_default = function() {
|
|
158
|
+
return {
|
|
159
|
+
name: "@modern-js/plugin-bff",
|
|
160
|
+
setup: function(api) {
|
|
161
|
+
var unRegisterResolveRuntimePath = null;
|
|
162
|
+
return {
|
|
163
|
+
validateSchema: function validateSchema() {
|
|
164
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
|
|
165
|
+
},
|
|
166
|
+
config: function config() {
|
|
167
|
+
return {
|
|
168
|
+
tools: {
|
|
169
|
+
webpackChain: function(chain, param) {
|
|
170
|
+
var name = param.name, CHAIN_ID = param.CHAIN_ID;
|
|
171
|
+
var ref = api.useAppContext(), appDirectory = ref.appDirectory, port = ref.port;
|
|
172
|
+
var modernConfig = api.useResolvedConfigContext();
|
|
173
|
+
var bff = (modernConfig || {}).bff;
|
|
174
|
+
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
175
|
+
var rootDir = path.resolve(appDirectory, API_DIR);
|
|
176
|
+
chain.resolve.alias.set("@api", rootDir);
|
|
177
|
+
var apiRouter = new ApiRouter({
|
|
178
|
+
apiDir: rootDir,
|
|
179
|
+
prefix: prefix
|
|
180
|
+
});
|
|
181
|
+
var lambdaDir = apiRouter.getLambdaDir();
|
|
182
|
+
var existLambda = apiRouter.isExistLambda();
|
|
183
|
+
var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
|
|
184
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
185
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
186
|
+
prefix: prefix,
|
|
187
|
+
apiDir: rootDir,
|
|
188
|
+
lambdaDir: lambdaDir,
|
|
189
|
+
existLambda: existLambda,
|
|
190
|
+
port: port,
|
|
191
|
+
target: name
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
source: {
|
|
196
|
+
moduleScopes: [
|
|
197
|
+
"./".concat(API_DIR),
|
|
198
|
+
/create-request/
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
modifyServerRoutes: function modifyServerRoutes(param) {
|
|
204
|
+
var routes = param.routes;
|
|
205
|
+
var modernConfig = api.useResolvedConfigContext();
|
|
206
|
+
var bff = (modernConfig || {}).bff;
|
|
207
|
+
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || "/api";
|
|
208
|
+
var prefixList = [];
|
|
209
|
+
if (Array.isArray(prefix)) {
|
|
210
|
+
var _prefixList;
|
|
211
|
+
(_prefixList = prefixList).push.apply(_prefixList, _toConsumableArray(prefix));
|
|
212
|
+
} else {
|
|
213
|
+
prefixList.push(prefix);
|
|
134
214
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
sourceDirs: sourceDirs,
|
|
144
|
-
distDir: distDir,
|
|
145
|
-
tsconfigPath: tsconfigPath
|
|
215
|
+
var apiServerRoutes = prefixList.map(function(pre) {
|
|
216
|
+
return {
|
|
217
|
+
urlPath: pre,
|
|
218
|
+
isApi: true,
|
|
219
|
+
entryPath: "",
|
|
220
|
+
isSPA: false,
|
|
221
|
+
isSSR: false
|
|
222
|
+
};
|
|
146
223
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
224
|
+
return {
|
|
225
|
+
routes: routes.concat(apiServerRoutes)
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
beforeBuild: function beforeBuild() {
|
|
229
|
+
return _asyncToGenerator(function() {
|
|
230
|
+
var internalDirectory;
|
|
231
|
+
return __generator(this, function(_state) {
|
|
232
|
+
if (isProd()) {
|
|
233
|
+
internalDirectory = api.useAppContext().internalDirectory;
|
|
234
|
+
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
235
|
+
}
|
|
236
|
+
return [
|
|
237
|
+
2
|
|
238
|
+
];
|
|
239
|
+
});
|
|
240
|
+
})();
|
|
241
|
+
},
|
|
242
|
+
afterBuild: function afterBuild() {
|
|
243
|
+
return _asyncToGenerator(function() {
|
|
244
|
+
var ref, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _source, alias, define, globalVars, babel;
|
|
245
|
+
return __generator(this, function(_state) {
|
|
246
|
+
switch(_state.label){
|
|
247
|
+
case 0:
|
|
248
|
+
if (unRegisterResolveRuntimePath) {
|
|
249
|
+
unRegisterResolveRuntimePath();
|
|
250
|
+
}
|
|
251
|
+
ref = api.useAppContext(), appDirectory = ref.appDirectory, distDirectory = ref.distDirectory;
|
|
252
|
+
modernConfig = api.useResolvedConfigContext();
|
|
253
|
+
distDir = path.resolve(distDirectory);
|
|
254
|
+
apiDir = path.resolve(appDirectory, API_DIR);
|
|
255
|
+
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
256
|
+
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
257
|
+
sourceDirs = [];
|
|
258
|
+
if (fs.existsSync(apiDir)) {
|
|
259
|
+
sourceDirs.push(apiDir);
|
|
260
|
+
}
|
|
261
|
+
if (fs.existsSync(sharedDir)) {
|
|
262
|
+
sourceDirs.push(sharedDir);
|
|
263
|
+
}
|
|
264
|
+
server = modernConfig.server;
|
|
265
|
+
_source = modernConfig.source, alias = _source.alias, define = _source.define, globalVars = _source.globalVars;
|
|
266
|
+
babel = modernConfig.tools.babel;
|
|
267
|
+
if (!(sourceDirs.length > 0)) return [
|
|
268
|
+
3,
|
|
269
|
+
2
|
|
270
|
+
];
|
|
271
|
+
return [
|
|
272
|
+
4,
|
|
273
|
+
compile(appDirectory, {
|
|
274
|
+
server: server,
|
|
275
|
+
alias: alias,
|
|
276
|
+
define: define,
|
|
277
|
+
globalVars: globalVars,
|
|
278
|
+
babelConfig: babel
|
|
279
|
+
}, {
|
|
280
|
+
sourceDirs: sourceDirs,
|
|
281
|
+
distDir: distDir,
|
|
282
|
+
tsconfigPath: tsconfigPath
|
|
283
|
+
})
|
|
284
|
+
];
|
|
285
|
+
case 1:
|
|
286
|
+
_state.sent();
|
|
287
|
+
_state.label = 2;
|
|
288
|
+
case 2:
|
|
289
|
+
return [
|
|
290
|
+
2
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
})();
|
|
150
295
|
}
|
|
151
|
-
|
|
152
|
-
}, _callee2);
|
|
153
|
-
}))();
|
|
296
|
+
};
|
|
154
297
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
export { cli_default as default };
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var API_APP_NAME = "_app";
|
|
2
|
+
var BUILD_FILES = [
|
|
3
|
+
"**/*.[tj]sx?",
|
|
4
|
+
"!**/*.test.jsx?",
|
|
5
|
+
"!**/*.test.tsx?",
|
|
6
|
+
"!**/*.spec.jsx?",
|
|
7
|
+
"!**/*.spec.tsx?",
|
|
8
|
+
"!__tests__/*.tsx?",
|
|
9
|
+
"!__tests__/*.jsx?"
|
|
10
|
+
];
|
|
11
|
+
export { API_APP_NAME, BUILD_FILES };
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import * as path from "path";
|
|
15
|
+
import { registerPaths } from "@modern-js/bff-core";
|
|
16
|
+
var serverRuntimeAlias = "@modern-js/runtime/server";
|
|
17
|
+
var serverRuntimePath = ".runtime-exports/server";
|
|
18
|
+
var registerModernRuntimePath = function(internalDirectory) {
|
|
19
|
+
var paths = _defineProperty({}, serverRuntimeAlias, path.join(internalDirectory, serverRuntimePath));
|
|
20
|
+
var unRegister = registerPaths(paths);
|
|
21
|
+
return unRegister;
|
|
10
22
|
};
|
|
11
|
-
export { registerModernRuntimePath };
|
|
23
|
+
export { registerModernRuntimePath };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./constants";
|
|
1
|
+
export * from "./constants";
|