@modern-js/plugin-bff 1.15.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/js/modern/cli.js +10 -1
- package/dist/js/modern/loader.js +24 -3
- package/dist/js/node/cli.js +11 -1
- package/dist/js/node/loader.js +27 -3
- package/dist/js/treeshaking/cli.js +10 -1
- package/dist/js/treeshaking/loader.js +32 -7
- package/dist/types/loader.d.ts +2 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 020b9bd52: feat: support frame mode without lambda directories
|
|
8
|
+
feat: 支持无 lambda 目录的框架模式
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [641592f52]
|
|
13
|
+
- Updated dependencies [3904b30a5]
|
|
14
|
+
- Updated dependencies [1100dd58c]
|
|
15
|
+
- Updated dependencies [e04e6e76a]
|
|
16
|
+
- Updated dependencies [81c66e4a4]
|
|
17
|
+
- Updated dependencies [2c305b6f5]
|
|
18
|
+
- Updated dependencies [020b9bd52]
|
|
19
|
+
- @modern-js/utils@1.16.0
|
|
20
|
+
- @modern-js/create-request@1.16.0
|
|
21
|
+
- @modern-js/server-utils@1.16.0
|
|
22
|
+
- @modern-js/bff-core@1.16.0
|
|
23
|
+
- @modern-js/babel-compiler@1.16.0
|
|
24
|
+
|
|
3
25
|
## 1.15.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import { compiler } from '@modern-js/babel-compiler';
|
|
3
3
|
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
|
|
4
4
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
5
|
+
import { ApiRouter } from '@modern-js/bff-core';
|
|
5
6
|
import { registerModernRuntimePath } from "./helper";
|
|
6
7
|
const DEFAULT_API_PREFIX = '/api';
|
|
7
8
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
@@ -75,10 +76,18 @@ export default (() => ({
|
|
|
75
76
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
76
77
|
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
77
78
|
chain.resolve.alias.set('@api', rootDir);
|
|
78
|
-
const
|
|
79
|
+
const apiRouter = new ApiRouter({
|
|
80
|
+
apiDir: rootDir,
|
|
81
|
+
prefix
|
|
82
|
+
});
|
|
83
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
84
|
+
const existLambda = apiRouter.isExistLambda();
|
|
85
|
+
const apiRegexp = new RegExp(normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`));
|
|
79
86
|
chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
80
87
|
prefix,
|
|
81
88
|
apiDir: rootDir,
|
|
89
|
+
lambdaDir,
|
|
90
|
+
existLambda,
|
|
82
91
|
port,
|
|
83
92
|
fetcher,
|
|
84
93
|
target: name,
|
package/dist/js/modern/loader.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { generateClient } from '@modern-js/bff-core';
|
|
2
|
+
import { logger } from '@modern-js/utils';
|
|
2
3
|
|
|
3
4
|
async function loader(source) {
|
|
4
5
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
@@ -6,16 +7,36 @@ async function loader(source) {
|
|
|
6
7
|
|
|
7
8
|
const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
|
|
8
9
|
|
|
9
|
-
const draftOptions = this.getOptions();
|
|
10
|
+
const draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
resourcePath
|
|
14
|
+
} = this;
|
|
15
|
+
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
16
|
+
|
|
17
|
+
if (!draftOptions.existLambda) {
|
|
18
|
+
logger.warn(warning);
|
|
19
|
+
callback(null, `throw new Error('${warning}')`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
const options = {
|
|
11
24
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
12
25
|
apiDir: draftOptions.apiDir,
|
|
13
26
|
target: draftOptions.target,
|
|
14
27
|
port: Number(draftOptions.port),
|
|
15
28
|
source,
|
|
16
|
-
|
|
17
|
-
resourcePath: this.resourcePath
|
|
29
|
+
resourcePath
|
|
18
30
|
};
|
|
31
|
+
const {
|
|
32
|
+
lambdaDir
|
|
33
|
+
} = draftOptions;
|
|
34
|
+
|
|
35
|
+
if (!resourcePath.startsWith(lambdaDir)) {
|
|
36
|
+
logger.warn(warning);
|
|
37
|
+
callback(null, `throw new Error('${warning}')`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
19
40
|
|
|
20
41
|
if (draftOptions.fetcher) {
|
|
21
42
|
options.fetcher = draftOptions.fetcher;
|
package/dist/js/node/cli.js
CHANGED
|
@@ -13,6 +13,8 @@ var _utils = require("@modern-js/utils");
|
|
|
13
13
|
|
|
14
14
|
var _serverUtils = require("@modern-js/server-utils");
|
|
15
15
|
|
|
16
|
+
var _bffCore = require("@modern-js/bff-core");
|
|
17
|
+
|
|
16
18
|
var _helper = require("./helper");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -93,10 +95,18 @@ var _default = () => ({
|
|
|
93
95
|
const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
94
96
|
|
|
95
97
|
chain.resolve.alias.set('@api', rootDir);
|
|
96
|
-
const
|
|
98
|
+
const apiRouter = new _bffCore.ApiRouter({
|
|
99
|
+
apiDir: rootDir,
|
|
100
|
+
prefix
|
|
101
|
+
});
|
|
102
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
103
|
+
const existLambda = apiRouter.isExistLambda();
|
|
104
|
+
const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${rootDir}${_path.default.sep}.*(.[tj]s)$`));
|
|
97
105
|
chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
98
106
|
prefix,
|
|
99
107
|
apiDir: rootDir,
|
|
108
|
+
lambdaDir,
|
|
109
|
+
existLambda,
|
|
100
110
|
port,
|
|
101
111
|
fetcher,
|
|
102
112
|
target: name,
|
package/dist/js/node/loader.js
CHANGED
|
@@ -7,22 +7,46 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _bffCore = require("@modern-js/bff-core");
|
|
9
9
|
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
10
12
|
async function loader(source) {
|
|
11
13
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
12
14
|
this.cacheable(); // eslint-disable-next-line @babel/no-invalid-this
|
|
13
15
|
|
|
14
16
|
const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
|
|
15
17
|
|
|
16
|
-
const draftOptions = this.getOptions();
|
|
18
|
+
const draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
resourcePath
|
|
22
|
+
} = this;
|
|
23
|
+
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
24
|
+
|
|
25
|
+
if (!draftOptions.existLambda) {
|
|
26
|
+
_utils.logger.warn(warning);
|
|
27
|
+
|
|
28
|
+
callback(null, `throw new Error('${warning}')`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
const options = {
|
|
18
33
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
19
34
|
apiDir: draftOptions.apiDir,
|
|
20
35
|
target: draftOptions.target,
|
|
21
36
|
port: Number(draftOptions.port),
|
|
22
37
|
source,
|
|
23
|
-
|
|
24
|
-
resourcePath: this.resourcePath
|
|
38
|
+
resourcePath
|
|
25
39
|
};
|
|
40
|
+
const {
|
|
41
|
+
lambdaDir
|
|
42
|
+
} = draftOptions;
|
|
43
|
+
|
|
44
|
+
if (!resourcePath.startsWith(lambdaDir)) {
|
|
45
|
+
_utils.logger.warn(warning);
|
|
46
|
+
|
|
47
|
+
callback(null, `throw new Error('${warning}')`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
26
50
|
|
|
27
51
|
if (draftOptions.fetcher) {
|
|
28
52
|
options.fetcher = draftOptions.fetcher;
|
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import { compiler } from '@modern-js/babel-compiler';
|
|
6
6
|
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
|
|
7
7
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
8
|
+
import { ApiRouter } from '@modern-js/bff-core';
|
|
8
9
|
import { registerModernRuntimePath } from "./helper";
|
|
9
10
|
var DEFAULT_API_PREFIX = '/api';
|
|
10
11
|
var TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
@@ -123,10 +124,18 @@ export default (function () {
|
|
|
123
124
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
124
125
|
var rootDir = path.resolve(appDirectory, API_DIR);
|
|
125
126
|
chain.resolve.alias.set('@api', rootDir);
|
|
126
|
-
var
|
|
127
|
+
var apiRouter = new ApiRouter({
|
|
128
|
+
apiDir: rootDir,
|
|
129
|
+
prefix: prefix
|
|
130
|
+
});
|
|
131
|
+
var lambdaDir = apiRouter.getLambdaDir();
|
|
132
|
+
var existLambda = apiRouter.isExistLambda();
|
|
133
|
+
var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
|
|
127
134
|
chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
128
135
|
prefix: prefix,
|
|
129
136
|
apiDir: rootDir,
|
|
137
|
+
lambdaDir: lambdaDir,
|
|
138
|
+
existLambda: existLambda,
|
|
130
139
|
port: port,
|
|
131
140
|
fetcher: fetcher,
|
|
132
141
|
target: name,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import { generateClient } from '@modern-js/bff-core';
|
|
4
|
+
import { logger } from '@modern-js/utils';
|
|
4
5
|
|
|
5
6
|
function loader(_x) {
|
|
6
7
|
return _loader.apply(this, arguments);
|
|
@@ -8,7 +9,7 @@ function loader(_x) {
|
|
|
8
9
|
|
|
9
10
|
function _loader() {
|
|
10
11
|
_loader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
|
|
11
|
-
var callback, draftOptions, options, result;
|
|
12
|
+
var callback, draftOptions, resourcePath, warning, options, lambdaDir, result;
|
|
12
13
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
13
14
|
while (1) {
|
|
14
15
|
switch (_context.prev = _context.next) {
|
|
@@ -18,17 +19,41 @@ function _loader() {
|
|
|
18
19
|
|
|
19
20
|
callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
|
|
20
21
|
|
|
21
|
-
draftOptions = this.getOptions();
|
|
22
|
+
draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
|
|
23
|
+
|
|
24
|
+
resourcePath = this.resourcePath;
|
|
25
|
+
warning = "The file ".concat(resourcePath, " is not allowd to be imported in src directory, only API definition files are allowed.");
|
|
26
|
+
|
|
27
|
+
if (draftOptions.existLambda) {
|
|
28
|
+
_context.next = 9;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
logger.warn(warning);
|
|
33
|
+
callback(null, "throw new Error('".concat(warning, "')"));
|
|
34
|
+
return _context.abrupt("return");
|
|
35
|
+
|
|
36
|
+
case 9:
|
|
22
37
|
options = {
|
|
23
38
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
24
39
|
apiDir: draftOptions.apiDir,
|
|
25
40
|
target: draftOptions.target,
|
|
26
41
|
port: Number(draftOptions.port),
|
|
27
42
|
source: source,
|
|
28
|
-
|
|
29
|
-
resourcePath: this.resourcePath
|
|
43
|
+
resourcePath: resourcePath
|
|
30
44
|
};
|
|
45
|
+
lambdaDir = draftOptions.lambdaDir;
|
|
46
|
+
|
|
47
|
+
if (resourcePath.startsWith(lambdaDir)) {
|
|
48
|
+
_context.next = 15;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
31
51
|
|
|
52
|
+
logger.warn(warning);
|
|
53
|
+
callback(null, "throw new Error('".concat(warning, "')"));
|
|
54
|
+
return _context.abrupt("return");
|
|
55
|
+
|
|
56
|
+
case 15:
|
|
32
57
|
if (draftOptions.fetcher) {
|
|
33
58
|
options.fetcher = draftOptions.fetcher;
|
|
34
59
|
}
|
|
@@ -38,10 +63,10 @@ function _loader() {
|
|
|
38
63
|
}
|
|
39
64
|
|
|
40
65
|
options.requireResolve = require.resolve;
|
|
41
|
-
_context.next =
|
|
66
|
+
_context.next = 20;
|
|
42
67
|
return generateClient(options);
|
|
43
68
|
|
|
44
|
-
case
|
|
69
|
+
case 20:
|
|
45
70
|
result = _context.sent;
|
|
46
71
|
|
|
47
72
|
if (result.isOk) {
|
|
@@ -50,7 +75,7 @@ function _loader() {
|
|
|
50
75
|
callback(undefined, "throw new Error('".concat(result.value, "')"));
|
|
51
76
|
}
|
|
52
77
|
|
|
53
|
-
case
|
|
78
|
+
case 22:
|
|
54
79
|
case "end":
|
|
55
80
|
return _context.stop();
|
|
56
81
|
}
|
package/dist/types/loader.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.16.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/core": "^7.18.0",
|
|
57
57
|
"@babel/runtime": "^7.18.0",
|
|
58
|
-
"@modern-js/babel-compiler": "1.
|
|
59
|
-
"@modern-js/bff-core": "1.
|
|
60
|
-
"@modern-js/create-request": "1.
|
|
61
|
-
"@modern-js/server-utils": "1.
|
|
62
|
-
"@modern-js/utils": "1.
|
|
58
|
+
"@modern-js/babel-compiler": "1.16.0",
|
|
59
|
+
"@modern-js/bff-core": "1.16.0",
|
|
60
|
+
"@modern-js/create-request": "1.16.0",
|
|
61
|
+
"@modern-js/server-utils": "1.16.0",
|
|
62
|
+
"@modern-js/utils": "1.16.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@modern-js/core": "1.
|
|
66
|
-
"@modern-js/bff-runtime": "1.
|
|
67
|
-
"@modern-js/runtime": "1.
|
|
68
|
-
"@modern-js/server-core": "1.
|
|
69
|
-
"@modern-js/types": "1.
|
|
65
|
+
"@modern-js/core": "1.16.0",
|
|
66
|
+
"@modern-js/bff-runtime": "1.16.0",
|
|
67
|
+
"@modern-js/runtime": "1.16.0",
|
|
68
|
+
"@modern-js/server-core": "1.16.0",
|
|
69
|
+
"@modern-js/types": "1.16.0",
|
|
70
70
|
"@scripts/build": "1.15.0",
|
|
71
71
|
"@scripts/jest-config": "1.15.0",
|
|
72
72
|
"@types/babel__core": "^7.1.15",
|