@modern-js/plugin-bff 1.21.5 → 2.0.0-beta.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.
- package/CHANGELOG.md +52 -22
- package/dist/js/modern/cli.js +5 -15
- package/dist/js/modern/helper.js +0 -2
- package/dist/js/modern/loader.js +6 -14
- package/dist/js/modern/server.js +0 -15
- package/dist/js/node/cli.js +5 -31
- package/dist/js/node/helper.js +0 -7
- package/dist/js/node/index.js +0 -2
- package/dist/js/node/loader.js +6 -18
- package/dist/js/node/server.js +0 -25
- package/dist/js/treeshaking/cli.js +11 -28
- package/dist/js/treeshaking/helper.js +0 -3
- package/dist/js/treeshaking/loader.js +2 -18
- package/dist/js/treeshaking/server.js +3 -12
- package/dist/types/cli.d.ts +0 -2
- package/dist/types/server.d.ts +0 -2
- package/package.json +15 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,35 +1,65 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [4876aa7]
|
|
8
|
-
- @modern-js/bff-core@1.21.5
|
|
9
|
-
- @modern-js/create-request@1.21.5
|
|
10
|
-
- @modern-js/server-utils@1.21.5
|
|
11
|
-
- @modern-js/babel-compiler@1.21.5
|
|
12
|
-
- @modern-js/utils@1.21.5
|
|
5
|
+
### Major Changes
|
|
13
6
|
|
|
14
|
-
|
|
7
|
+
- dda38c9: chore: v2
|
|
15
8
|
|
|
16
9
|
### Patch Changes
|
|
17
10
|
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
- 8ff2cf4c71: fix: bff api loader should run before babel loader
|
|
12
|
+
fix: bff 一体化调用的 loader 应该在 babel loader 前执行
|
|
13
|
+
- Updated dependencies [9b915e0c10]
|
|
14
|
+
- Updated dependencies [2344eb2]
|
|
15
|
+
- Updated dependencies [a2509bfbdb]
|
|
16
|
+
- Updated dependencies [92f0ead]
|
|
17
|
+
- Updated dependencies [edd1cfb1af]
|
|
18
|
+
- Updated dependencies [cc971eabfc]
|
|
19
|
+
- Updated dependencies [5b9049f]
|
|
20
|
+
- Updated dependencies [a8642da]
|
|
21
|
+
- Updated dependencies [92004d1]
|
|
22
|
+
- Updated dependencies [b8bbe036c7]
|
|
23
|
+
- Updated dependencies [d5a31df781]
|
|
24
|
+
- Updated dependencies [dda38c9]
|
|
25
|
+
- Updated dependencies [3bbea92b2a]
|
|
26
|
+
- Updated dependencies [abf3421]
|
|
27
|
+
- Updated dependencies [543be9558e]
|
|
28
|
+
- Updated dependencies [14b712d]
|
|
29
|
+
- @modern-js/server-utils@2.0.0-beta.1
|
|
30
|
+
- @modern-js/bff-core@2.0.0-beta.1
|
|
31
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
32
|
+
- @modern-js/create-request@2.0.0-beta.1
|
|
33
|
+
- @modern-js/babel-compiler@2.0.0-beta.1
|
|
34
|
+
|
|
35
|
+
## 2.0.0-beta.0
|
|
36
|
+
|
|
37
|
+
### Major Changes
|
|
38
|
+
|
|
39
|
+
- dda38c9: chore: v2
|
|
25
40
|
|
|
26
41
|
### Patch Changes
|
|
27
42
|
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
43
|
+
- 8ff2cf4: fix: bff api loader should run before babel loader
|
|
44
|
+
fix: bff 一体化调用的 loader 应该在 babel loader 前执行
|
|
45
|
+
- Updated dependencies [9b915e0c1]
|
|
46
|
+
- Updated dependencies [a2509bf]
|
|
47
|
+
- Updated dependencies [edd1cfb1a]
|
|
48
|
+
- Updated dependencies [cc971eabf]
|
|
49
|
+
- Updated dependencies [5b9049f]
|
|
50
|
+
- Updated dependencies [a8642da]
|
|
51
|
+
- Updated dependencies [b8bbe036c]
|
|
52
|
+
- Updated dependencies [d5a31df78]
|
|
53
|
+
- Updated dependencies [dda38c9]
|
|
54
|
+
- Updated dependencies [3bbea92b2]
|
|
55
|
+
- Updated dependencies [abf3421]
|
|
56
|
+
- Updated dependencies [543be95]
|
|
57
|
+
- Updated dependencies [14b712d]
|
|
58
|
+
- @modern-js/server-utils@2.0.0-beta.0
|
|
59
|
+
- @modern-js/bff-core@2.0.0-beta.0
|
|
60
|
+
- @modern-js/utils@2.0.0-beta.0
|
|
61
|
+
- @modern-js/create-request@2.0.0-beta.0
|
|
62
|
+
- @modern-js/babel-compiler@2.0.0-beta.0
|
|
33
63
|
|
|
34
64
|
## 1.21.2
|
|
35
65
|
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -13,7 +13,6 @@ export default (() => ({
|
|
|
13
13
|
validateSchema() {
|
|
14
14
|
return PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
|
|
15
15
|
},
|
|
16
|
-
|
|
17
16
|
config() {
|
|
18
17
|
return {
|
|
19
18
|
tools: {
|
|
@@ -42,7 +41,8 @@ export default (() => ({
|
|
|
42
41
|
const lambdaDir = apiRouter.getLambdaDir();
|
|
43
42
|
const existLambda = apiRouter.isExistLambda();
|
|
44
43
|
const apiRegexp = new RegExp(normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`));
|
|
45
|
-
chain.module.rule(CHAIN_ID.RULE.
|
|
44
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
45
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
46
46
|
prefix,
|
|
47
47
|
apiDir: rootDir,
|
|
48
48
|
lambdaDir,
|
|
@@ -59,7 +59,6 @@ export default (() => ({
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
},
|
|
62
|
-
|
|
63
62
|
modifyServerRoutes({
|
|
64
63
|
routes
|
|
65
64
|
}) {
|
|
@@ -69,26 +68,24 @@ export default (() => ({
|
|
|
69
68
|
} = modernConfig || {};
|
|
70
69
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
71
70
|
const prefixList = [];
|
|
72
|
-
|
|
73
71
|
if (Array.isArray(prefix)) {
|
|
74
72
|
prefixList.push(...prefix);
|
|
75
73
|
} else {
|
|
76
74
|
prefixList.push(prefix);
|
|
77
75
|
}
|
|
78
|
-
|
|
79
76
|
const apiServerRoutes = prefixList.map(pre => ({
|
|
80
77
|
urlPath: pre,
|
|
81
78
|
isApi: true,
|
|
82
79
|
entryPath: '',
|
|
83
80
|
isSPA: false,
|
|
84
|
-
isSSR: false
|
|
85
|
-
|
|
81
|
+
isSSR: false
|
|
82
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
86
83
|
}));
|
|
84
|
+
|
|
87
85
|
return {
|
|
88
86
|
routes: routes.concat(apiServerRoutes)
|
|
89
87
|
};
|
|
90
88
|
},
|
|
91
|
-
|
|
92
89
|
async beforeBuild() {
|
|
93
90
|
// help esbuild-register resolve @modern-js/server/runtime
|
|
94
91
|
if (isProd()) {
|
|
@@ -98,12 +95,10 @@ export default (() => ({
|
|
|
98
95
|
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
99
96
|
}
|
|
100
97
|
},
|
|
101
|
-
|
|
102
98
|
async afterBuild() {
|
|
103
99
|
if (unRegisterResolveRuntimePath) {
|
|
104
100
|
unRegisterResolveRuntimePath();
|
|
105
101
|
}
|
|
106
|
-
|
|
107
102
|
const {
|
|
108
103
|
appDirectory,
|
|
109
104
|
distDirectory
|
|
@@ -114,15 +109,12 @@ export default (() => ({
|
|
|
114
109
|
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
115
110
|
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
116
111
|
const sourceDirs = [];
|
|
117
|
-
|
|
118
112
|
if (fs.existsSync(apiDir)) {
|
|
119
113
|
sourceDirs.push(apiDir);
|
|
120
114
|
}
|
|
121
|
-
|
|
122
115
|
if (fs.existsSync(sharedDir)) {
|
|
123
116
|
sourceDirs.push(sharedDir);
|
|
124
117
|
}
|
|
125
|
-
|
|
126
118
|
const {
|
|
127
119
|
server
|
|
128
120
|
} = modernConfig;
|
|
@@ -134,7 +126,6 @@ export default (() => ({
|
|
|
134
126
|
const {
|
|
135
127
|
babel
|
|
136
128
|
} = modernConfig.tools;
|
|
137
|
-
|
|
138
129
|
if (sourceDirs.length > 0) {
|
|
139
130
|
await compile(appDirectory, {
|
|
140
131
|
server,
|
|
@@ -149,7 +140,6 @@ export default (() => ({
|
|
|
149
140
|
});
|
|
150
141
|
}
|
|
151
142
|
}
|
|
152
|
-
|
|
153
143
|
};
|
|
154
144
|
}
|
|
155
145
|
}));
|
package/dist/js/modern/helper.js
CHANGED
|
@@ -2,7 +2,6 @@ import * as path from 'path';
|
|
|
2
2
|
import { registerPaths } from '@modern-js/bff-core';
|
|
3
3
|
const serverRuntimeAlias = '@modern-js/runtime/server';
|
|
4
4
|
const serverRuntimePath = '.runtime-exports/server';
|
|
5
|
-
|
|
6
5
|
const registerModernRuntimePath = internalDirectory => {
|
|
7
6
|
const paths = {
|
|
8
7
|
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
@@ -10,5 +9,4 @@ const registerModernRuntimePath = internalDirectory => {
|
|
|
10
9
|
const unRegister = registerPaths(paths);
|
|
11
10
|
return unRegister;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
export { registerModernRuntimePath };
|
package/dist/js/modern/loader.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import { generateClient } from '@modern-js/bff-core';
|
|
2
2
|
import { logger } from '@modern-js/utils';
|
|
3
|
-
|
|
4
3
|
async function loader(source) {
|
|
5
4
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
6
|
-
this.cacheable();
|
|
7
|
-
|
|
8
|
-
const callback = this.async();
|
|
9
|
-
|
|
10
|
-
const draftOptions = this.getOptions();
|
|
5
|
+
this.cacheable();
|
|
6
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
7
|
+
const callback = this.async();
|
|
8
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
9
|
+
const draftOptions = this.getOptions();
|
|
11
10
|
|
|
11
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
12
12
|
const {
|
|
13
13
|
resourcePath
|
|
14
14
|
} = this;
|
|
15
15
|
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
16
|
-
|
|
17
16
|
if (!draftOptions.existLambda) {
|
|
18
17
|
logger.warn(warning);
|
|
19
18
|
callback(null, `throw new Error('${warning}')`);
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
const options = {
|
|
24
22
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
25
23
|
apiDir: draftOptions.apiDir,
|
|
@@ -31,29 +29,23 @@ async function loader(source) {
|
|
|
31
29
|
const {
|
|
32
30
|
lambdaDir
|
|
33
31
|
} = draftOptions;
|
|
34
|
-
|
|
35
32
|
if (!resourcePath.startsWith(lambdaDir)) {
|
|
36
33
|
logger.warn(warning);
|
|
37
34
|
callback(null, `throw new Error('${warning}')`);
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
if (draftOptions.fetcher) {
|
|
42
38
|
options.fetcher = draftOptions.fetcher;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
if (draftOptions.requestCreator) {
|
|
46
41
|
options.requestCreator = draftOptions.requestCreator;
|
|
47
42
|
}
|
|
48
|
-
|
|
49
43
|
options.requireResolve = require.resolve;
|
|
50
44
|
const result = await generateClient(options);
|
|
51
|
-
|
|
52
45
|
if (result.isOk) {
|
|
53
46
|
callback(undefined, result.value);
|
|
54
47
|
} else {
|
|
55
48
|
callback(undefined, `throw new Error('${result.value}')`);
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
export default loader;
|
package/dist/js/modern/server.js
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { ApiRouter } from '@modern-js/bff-core';
|
|
9
6
|
import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
|
|
10
7
|
import { API_APP_NAME } from "./constants";
|
|
11
|
-
|
|
12
8
|
class Storage {
|
|
13
9
|
constructor() {
|
|
14
10
|
_defineProperty(this, "middlewares", []);
|
|
15
11
|
}
|
|
16
|
-
|
|
17
12
|
reset() {
|
|
18
13
|
this.middlewares = [];
|
|
19
14
|
}
|
|
20
|
-
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
const createTransformAPI = storage => ({
|
|
24
17
|
addMiddleware(fn) {
|
|
25
18
|
storage.middlewares.push(fn);
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
});
|
|
29
|
-
|
|
30
21
|
export default (() => ({
|
|
31
22
|
name: '@modern-js/plugin-bff',
|
|
32
23
|
setup: api => {
|
|
@@ -43,21 +34,17 @@ export default (() => ({
|
|
|
43
34
|
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
44
35
|
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
45
36
|
const apiMod = requireExistModule(apiAppPath);
|
|
46
|
-
|
|
47
37
|
if (apiMod && typeof apiMod === 'function') {
|
|
48
38
|
apiMod(transformAPI);
|
|
49
39
|
}
|
|
50
40
|
},
|
|
51
|
-
|
|
52
41
|
reset() {
|
|
53
42
|
storage.reset();
|
|
54
43
|
const newApiModule = requireExistModule(apiAppPath);
|
|
55
|
-
|
|
56
44
|
if (newApiModule && typeof newApiModule === 'function') {
|
|
57
45
|
newApiModule(transformAPI);
|
|
58
46
|
}
|
|
59
47
|
},
|
|
60
|
-
|
|
61
48
|
gather({
|
|
62
49
|
addAPIMiddleware
|
|
63
50
|
}) {
|
|
@@ -65,7 +52,6 @@ export default (() => ({
|
|
|
65
52
|
addAPIMiddleware(mid);
|
|
66
53
|
});
|
|
67
54
|
},
|
|
68
|
-
|
|
69
55
|
prepareApiServer(props, next) {
|
|
70
56
|
const {
|
|
71
57
|
pwd,
|
|
@@ -86,7 +72,6 @@ export default (() => ({
|
|
|
86
72
|
}));
|
|
87
73
|
return next(props);
|
|
88
74
|
}
|
|
89
|
-
|
|
90
75
|
};
|
|
91
76
|
}
|
|
92
77
|
}));
|
package/dist/js/node/cli.js
CHANGED
|
@@ -4,22 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _serverUtils = require("@modern-js/server-utils");
|
|
13
|
-
|
|
14
10
|
var _bffCore = require("@modern-js/bff-core");
|
|
15
|
-
|
|
16
11
|
var _helper = require("./helper");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const DEFAULT_API_PREFIX = '/api';
|
|
21
14
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
22
|
-
|
|
23
15
|
var _default = () => ({
|
|
24
16
|
name: '@modern-js/plugin-bff',
|
|
25
17
|
setup: api => {
|
|
@@ -28,7 +20,6 @@ var _default = () => ({
|
|
|
28
20
|
validateSchema() {
|
|
29
21
|
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
|
|
30
22
|
},
|
|
31
|
-
|
|
32
23
|
config() {
|
|
33
24
|
return {
|
|
34
25
|
tools: {
|
|
@@ -48,9 +39,7 @@ var _default = () => ({
|
|
|
48
39
|
fetcher
|
|
49
40
|
} = bff || {};
|
|
50
41
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
51
|
-
|
|
52
42
|
const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
53
|
-
|
|
54
43
|
chain.resolve.alias.set('@api', rootDir);
|
|
55
44
|
const apiRouter = new _bffCore.ApiRouter({
|
|
56
45
|
apiDir: rootDir,
|
|
@@ -59,7 +48,8 @@ var _default = () => ({
|
|
|
59
48
|
const lambdaDir = apiRouter.getLambdaDir();
|
|
60
49
|
const existLambda = apiRouter.isExistLambda();
|
|
61
50
|
const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${rootDir}${_path.default.sep}.*(.[tj]s)$`));
|
|
62
|
-
chain.module.rule(CHAIN_ID.RULE.
|
|
51
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
52
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
63
53
|
prefix,
|
|
64
54
|
apiDir: rootDir,
|
|
65
55
|
lambdaDir,
|
|
@@ -76,7 +66,6 @@ var _default = () => ({
|
|
|
76
66
|
}
|
|
77
67
|
};
|
|
78
68
|
},
|
|
79
|
-
|
|
80
69
|
modifyServerRoutes({
|
|
81
70
|
routes
|
|
82
71
|
}) {
|
|
@@ -86,26 +75,24 @@ var _default = () => ({
|
|
|
86
75
|
} = modernConfig || {};
|
|
87
76
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
88
77
|
const prefixList = [];
|
|
89
|
-
|
|
90
78
|
if (Array.isArray(prefix)) {
|
|
91
79
|
prefixList.push(...prefix);
|
|
92
80
|
} else {
|
|
93
81
|
prefixList.push(prefix);
|
|
94
82
|
}
|
|
95
|
-
|
|
96
83
|
const apiServerRoutes = prefixList.map(pre => ({
|
|
97
84
|
urlPath: pre,
|
|
98
85
|
isApi: true,
|
|
99
86
|
entryPath: '',
|
|
100
87
|
isSPA: false,
|
|
101
|
-
isSSR: false
|
|
102
|
-
|
|
88
|
+
isSSR: false
|
|
89
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
103
90
|
}));
|
|
91
|
+
|
|
104
92
|
return {
|
|
105
93
|
routes: routes.concat(apiServerRoutes)
|
|
106
94
|
};
|
|
107
95
|
},
|
|
108
|
-
|
|
109
96
|
async beforeBuild() {
|
|
110
97
|
// help esbuild-register resolve @modern-js/server/runtime
|
|
111
98
|
if ((0, _utils.isProd)()) {
|
|
@@ -115,36 +102,26 @@ var _default = () => ({
|
|
|
115
102
|
unRegisterResolveRuntimePath = (0, _helper.registerModernRuntimePath)(internalDirectory);
|
|
116
103
|
}
|
|
117
104
|
},
|
|
118
|
-
|
|
119
105
|
async afterBuild() {
|
|
120
106
|
if (unRegisterResolveRuntimePath) {
|
|
121
107
|
unRegisterResolveRuntimePath();
|
|
122
108
|
}
|
|
123
|
-
|
|
124
109
|
const {
|
|
125
110
|
appDirectory,
|
|
126
111
|
distDirectory
|
|
127
112
|
} = api.useAppContext();
|
|
128
113
|
const modernConfig = api.useResolvedConfigContext();
|
|
129
|
-
|
|
130
114
|
const distDir = _path.default.resolve(distDirectory);
|
|
131
|
-
|
|
132
115
|
const apiDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
133
|
-
|
|
134
116
|
const sharedDir = _path.default.resolve(appDirectory, _utils.SHARED_DIR);
|
|
135
|
-
|
|
136
117
|
const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
137
|
-
|
|
138
118
|
const sourceDirs = [];
|
|
139
|
-
|
|
140
119
|
if (_utils.fs.existsSync(apiDir)) {
|
|
141
120
|
sourceDirs.push(apiDir);
|
|
142
121
|
}
|
|
143
|
-
|
|
144
122
|
if (_utils.fs.existsSync(sharedDir)) {
|
|
145
123
|
sourceDirs.push(sharedDir);
|
|
146
124
|
}
|
|
147
|
-
|
|
148
125
|
const {
|
|
149
126
|
server
|
|
150
127
|
} = modernConfig;
|
|
@@ -156,7 +133,6 @@ var _default = () => ({
|
|
|
156
133
|
const {
|
|
157
134
|
babel
|
|
158
135
|
} = modernConfig.tools;
|
|
159
|
-
|
|
160
136
|
if (sourceDirs.length > 0) {
|
|
161
137
|
await (0, _serverUtils.compile)(appDirectory, {
|
|
162
138
|
server,
|
|
@@ -171,9 +147,7 @@ var _default = () => ({
|
|
|
171
147
|
});
|
|
172
148
|
}
|
|
173
149
|
}
|
|
174
|
-
|
|
175
150
|
};
|
|
176
151
|
}
|
|
177
152
|
});
|
|
178
|
-
|
|
179
153
|
exports.default = _default;
|
package/dist/js/node/helper.js
CHANGED
|
@@ -4,18 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.registerModernRuntimePath = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _bffCore = require("@modern-js/bff-core");
|
|
11
|
-
|
|
12
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
11
|
const serverRuntimeAlias = '@modern-js/runtime/server';
|
|
17
12
|
const serverRuntimePath = '.runtime-exports/server';
|
|
18
|
-
|
|
19
13
|
const registerModernRuntimePath = internalDirectory => {
|
|
20
14
|
const paths = {
|
|
21
15
|
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
@@ -23,5 +17,4 @@ const registerModernRuntimePath = internalDirectory => {
|
|
|
23
17
|
const unRegister = (0, _bffCore.registerPaths)(paths);
|
|
24
18
|
return unRegister;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
exports.registerModernRuntimePath = registerModernRuntimePath;
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _constants = require("./constants");
|
|
8
|
-
|
|
9
7
|
Object.keys(_constants).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _constants[key]) return;
|
package/dist/js/node/loader.js
CHANGED
|
@@ -4,31 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _bffCore = require("@modern-js/bff-core");
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
async function loader(source) {
|
|
13
10
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
14
|
-
this.cacheable();
|
|
15
|
-
|
|
16
|
-
const callback = this.async();
|
|
17
|
-
|
|
18
|
-
const draftOptions = this.getOptions();
|
|
11
|
+
this.cacheable();
|
|
12
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
13
|
+
const callback = this.async();
|
|
14
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
15
|
+
const draftOptions = this.getOptions();
|
|
19
16
|
|
|
17
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
20
18
|
const {
|
|
21
19
|
resourcePath
|
|
22
20
|
} = this;
|
|
23
21
|
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
24
|
-
|
|
25
22
|
if (!draftOptions.existLambda) {
|
|
26
23
|
_utils.logger.warn(warning);
|
|
27
|
-
|
|
28
24
|
callback(null, `throw new Error('${warning}')`);
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
const options = {
|
|
33
28
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
34
29
|
apiDir: draftOptions.apiDir,
|
|
@@ -40,31 +35,24 @@ async function loader(source) {
|
|
|
40
35
|
const {
|
|
41
36
|
lambdaDir
|
|
42
37
|
} = draftOptions;
|
|
43
|
-
|
|
44
38
|
if (!resourcePath.startsWith(lambdaDir)) {
|
|
45
39
|
_utils.logger.warn(warning);
|
|
46
|
-
|
|
47
40
|
callback(null, `throw new Error('${warning}')`);
|
|
48
41
|
return;
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
if (draftOptions.fetcher) {
|
|
52
44
|
options.fetcher = draftOptions.fetcher;
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
if (draftOptions.requestCreator) {
|
|
56
47
|
options.requestCreator = draftOptions.requestCreator;
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
options.requireResolve = require.resolve;
|
|
60
50
|
const result = await (0, _bffCore.generateClient)(options);
|
|
61
|
-
|
|
62
51
|
if (result.isOk) {
|
|
63
52
|
callback(undefined, result.value);
|
|
64
53
|
} else {
|
|
65
54
|
callback(undefined, `throw new Error('${result.value}')`);
|
|
66
55
|
}
|
|
67
56
|
}
|
|
68
|
-
|
|
69
57
|
var _default = loader;
|
|
70
58
|
exports.default = _default;
|
package/dist/js/node/server.js
CHANGED
|
@@ -4,41 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _bffCore = require("@modern-js/bff-core");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _constants = require("./constants");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
14
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
24
15
|
class Storage {
|
|
25
16
|
constructor() {
|
|
26
17
|
_defineProperty(this, "middlewares", []);
|
|
27
18
|
}
|
|
28
|
-
|
|
29
19
|
reset() {
|
|
30
20
|
this.middlewares = [];
|
|
31
21
|
}
|
|
32
|
-
|
|
33
22
|
}
|
|
34
|
-
|
|
35
23
|
const createTransformAPI = storage => ({
|
|
36
24
|
addMiddleware(fn) {
|
|
37
25
|
storage.middlewares.push(fn);
|
|
38
26
|
}
|
|
39
|
-
|
|
40
27
|
});
|
|
41
|
-
|
|
42
28
|
var _default = () => ({
|
|
43
29
|
name: '@modern-js/plugin-bff',
|
|
44
30
|
setup: api => {
|
|
@@ -52,26 +38,20 @@ var _default = () => ({
|
|
|
52
38
|
distDirectory
|
|
53
39
|
} = api.useAppContext();
|
|
54
40
|
const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
|
|
55
|
-
|
|
56
41
|
const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
|
|
57
|
-
|
|
58
42
|
apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
59
43
|
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
60
|
-
|
|
61
44
|
if (apiMod && typeof apiMod === 'function') {
|
|
62
45
|
apiMod(transformAPI);
|
|
63
46
|
}
|
|
64
47
|
},
|
|
65
|
-
|
|
66
48
|
reset() {
|
|
67
49
|
storage.reset();
|
|
68
50
|
const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
|
|
69
|
-
|
|
70
51
|
if (newApiModule && typeof newApiModule === 'function') {
|
|
71
52
|
newApiModule(transformAPI);
|
|
72
53
|
}
|
|
73
54
|
},
|
|
74
|
-
|
|
75
55
|
gather({
|
|
76
56
|
addAPIMiddleware
|
|
77
57
|
}) {
|
|
@@ -79,15 +59,12 @@ var _default = () => ({
|
|
|
79
59
|
addAPIMiddleware(mid);
|
|
80
60
|
});
|
|
81
61
|
},
|
|
82
|
-
|
|
83
62
|
prepareApiServer(props, next) {
|
|
84
63
|
const {
|
|
85
64
|
pwd,
|
|
86
65
|
prefix
|
|
87
66
|
} = props;
|
|
88
|
-
|
|
89
67
|
const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
|
|
90
|
-
|
|
91
68
|
const appContext = api.useAppContext();
|
|
92
69
|
const apiRouter = new _bffCore.ApiRouter({
|
|
93
70
|
apiDir,
|
|
@@ -102,9 +79,7 @@ var _default = () => ({
|
|
|
102
79
|
}));
|
|
103
80
|
return next(props);
|
|
104
81
|
}
|
|
105
|
-
|
|
106
82
|
};
|
|
107
83
|
}
|
|
108
84
|
});
|
|
109
|
-
|
|
110
85
|
exports.default = _default;
|
|
@@ -22,20 +22,15 @@ export default (function () {
|
|
|
22
22
|
tools: {
|
|
23
23
|
webpackChain: function webpackChain(chain, _ref) {
|
|
24
24
|
var name = _ref.name,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
CHAIN_ID = _ref.CHAIN_ID;
|
|
27
26
|
var _api$useAppContext = api.useAppContext(),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
appDirectory = _api$useAppContext.appDirectory,
|
|
28
|
+
port = _api$useAppContext.port;
|
|
31
29
|
var modernConfig = api.useResolvedConfigContext();
|
|
32
|
-
|
|
33
30
|
var _ref2 = modernConfig || {},
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
bff = _ref2.bff;
|
|
36
32
|
var _ref3 = bff || {},
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
fetcher = _ref3.fetcher;
|
|
39
34
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
40
35
|
var rootDir = path.resolve(appDirectory, API_DIR);
|
|
41
36
|
chain.resolve.alias.set('@api', rootDir);
|
|
@@ -46,7 +41,8 @@ export default (function () {
|
|
|
46
41
|
var lambdaDir = apiRouter.getLambdaDir();
|
|
47
42
|
var existLambda = apiRouter.isExistLambda();
|
|
48
43
|
var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
|
|
49
|
-
chain.module.rule(CHAIN_ID.RULE.
|
|
44
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
45
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
50
46
|
prefix: prefix,
|
|
51
47
|
apiDir: rootDir,
|
|
52
48
|
lambdaDir: lambdaDir,
|
|
@@ -66,29 +62,26 @@ export default (function () {
|
|
|
66
62
|
modifyServerRoutes: function modifyServerRoutes(_ref4) {
|
|
67
63
|
var routes = _ref4.routes;
|
|
68
64
|
var modernConfig = api.useResolvedConfigContext();
|
|
69
|
-
|
|
70
65
|
var _ref5 = modernConfig || {},
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
bff = _ref5.bff;
|
|
73
67
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
74
68
|
var prefixList = [];
|
|
75
|
-
|
|
76
69
|
if (Array.isArray(prefix)) {
|
|
77
70
|
prefixList.push.apply(prefixList, _toConsumableArray(prefix));
|
|
78
71
|
} else {
|
|
79
72
|
prefixList.push(prefix);
|
|
80
73
|
}
|
|
81
|
-
|
|
82
74
|
var apiServerRoutes = prefixList.map(function (pre) {
|
|
83
75
|
return {
|
|
84
76
|
urlPath: pre,
|
|
85
77
|
isApi: true,
|
|
86
78
|
entryPath: '',
|
|
87
79
|
isSPA: false,
|
|
88
|
-
isSSR: false
|
|
89
|
-
|
|
80
|
+
isSSR: false
|
|
81
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
90
82
|
};
|
|
91
83
|
});
|
|
84
|
+
|
|
92
85
|
return {
|
|
93
86
|
routes: routes.concat(apiServerRoutes)
|
|
94
87
|
};
|
|
@@ -96,7 +89,6 @@ export default (function () {
|
|
|
96
89
|
beforeBuild: function beforeBuild() {
|
|
97
90
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
98
91
|
var _api$useAppContext2, internalDirectory;
|
|
99
|
-
|
|
100
92
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
101
93
|
while (1) {
|
|
102
94
|
switch (_context.prev = _context.next) {
|
|
@@ -106,7 +98,6 @@ export default (function () {
|
|
|
106
98
|
_api$useAppContext2 = api.useAppContext(), internalDirectory = _api$useAppContext2.internalDirectory;
|
|
107
99
|
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
108
100
|
}
|
|
109
|
-
|
|
110
101
|
case 1:
|
|
111
102
|
case "end":
|
|
112
103
|
return _context.stop();
|
|
@@ -118,7 +109,6 @@ export default (function () {
|
|
|
118
109
|
afterBuild: function afterBuild() {
|
|
119
110
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
120
111
|
var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig$source, alias, envVars, globalVars, babel;
|
|
121
|
-
|
|
122
112
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
123
113
|
while (1) {
|
|
124
114
|
switch (_context2.prev = _context2.next) {
|
|
@@ -126,7 +116,6 @@ export default (function () {
|
|
|
126
116
|
if (unRegisterResolveRuntimePath) {
|
|
127
117
|
unRegisterResolveRuntimePath();
|
|
128
118
|
}
|
|
129
|
-
|
|
130
119
|
_api$useAppContext3 = api.useAppContext(), appDirectory = _api$useAppContext3.appDirectory, distDirectory = _api$useAppContext3.distDirectory;
|
|
131
120
|
modernConfig = api.useResolvedConfigContext();
|
|
132
121
|
distDir = path.resolve(distDirectory);
|
|
@@ -134,24 +123,19 @@ export default (function () {
|
|
|
134
123
|
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
135
124
|
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
136
125
|
sourceDirs = [];
|
|
137
|
-
|
|
138
126
|
if (fs.existsSync(apiDir)) {
|
|
139
127
|
sourceDirs.push(apiDir);
|
|
140
128
|
}
|
|
141
|
-
|
|
142
129
|
if (fs.existsSync(sharedDir)) {
|
|
143
130
|
sourceDirs.push(sharedDir);
|
|
144
131
|
}
|
|
145
|
-
|
|
146
132
|
server = modernConfig.server;
|
|
147
133
|
_modernConfig$source = modernConfig.source, alias = _modernConfig$source.alias, envVars = _modernConfig$source.envVars, globalVars = _modernConfig$source.globalVars;
|
|
148
134
|
babel = modernConfig.tools.babel;
|
|
149
|
-
|
|
150
135
|
if (!(sourceDirs.length > 0)) {
|
|
151
136
|
_context2.next = 16;
|
|
152
137
|
break;
|
|
153
138
|
}
|
|
154
|
-
|
|
155
139
|
_context2.next = 16;
|
|
156
140
|
return compile(appDirectory, {
|
|
157
141
|
server: server,
|
|
@@ -164,7 +148,6 @@ export default (function () {
|
|
|
164
148
|
distDir: distDir,
|
|
165
149
|
tsconfigPath: tsconfigPath
|
|
166
150
|
});
|
|
167
|
-
|
|
168
151
|
case 16:
|
|
169
152
|
case "end":
|
|
170
153
|
return _context2.stop();
|
|
@@ -3,12 +3,9 @@ import * as path from 'path';
|
|
|
3
3
|
import { registerPaths } from '@modern-js/bff-core';
|
|
4
4
|
var serverRuntimeAlias = '@modern-js/runtime/server';
|
|
5
5
|
var serverRuntimePath = '.runtime-exports/server';
|
|
6
|
-
|
|
7
6
|
var registerModernRuntimePath = function registerModernRuntimePath(internalDirectory) {
|
|
8
7
|
var paths = _defineProperty({}, serverRuntimeAlias, path.join(internalDirectory, serverRuntimePath));
|
|
9
|
-
|
|
10
8
|
var unRegister = registerPaths(paths);
|
|
11
9
|
return unRegister;
|
|
12
10
|
};
|
|
13
|
-
|
|
14
11
|
export { registerModernRuntimePath };
|
|
@@ -2,11 +2,9 @@ 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
4
|
import { logger } from '@modern-js/utils';
|
|
5
|
-
|
|
6
5
|
function loader(_x) {
|
|
7
6
|
return _loader.apply(this, arguments);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
function _loader() {
|
|
11
9
|
_loader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
|
|
12
10
|
var callback, draftOptions, resourcePath, warning, options, lambdaDir, result;
|
|
@@ -15,24 +13,19 @@ function _loader() {
|
|
|
15
13
|
switch (_context.prev = _context.next) {
|
|
16
14
|
case 0:
|
|
17
15
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
18
|
-
this.cacheable();
|
|
19
|
-
|
|
16
|
+
this.cacheable();
|
|
17
|
+
// eslint-disable-next-line @babel/no-invalid-this
|
|
20
18
|
callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
|
|
21
|
-
|
|
22
19
|
draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
|
|
23
|
-
|
|
24
20
|
resourcePath = this.resourcePath;
|
|
25
21
|
warning = "The file ".concat(resourcePath, " is not allowd to be imported in src directory, only API definition files are allowed.");
|
|
26
|
-
|
|
27
22
|
if (draftOptions.existLambda) {
|
|
28
23
|
_context.next = 9;
|
|
29
24
|
break;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
logger.warn(warning);
|
|
33
27
|
callback(null, "throw new Error('".concat(warning, "')"));
|
|
34
28
|
return _context.abrupt("return");
|
|
35
|
-
|
|
36
29
|
case 9:
|
|
37
30
|
options = {
|
|
38
31
|
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
@@ -43,38 +36,30 @@ function _loader() {
|
|
|
43
36
|
resourcePath: resourcePath
|
|
44
37
|
};
|
|
45
38
|
lambdaDir = draftOptions.lambdaDir;
|
|
46
|
-
|
|
47
39
|
if (resourcePath.startsWith(lambdaDir)) {
|
|
48
40
|
_context.next = 15;
|
|
49
41
|
break;
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
logger.warn(warning);
|
|
53
44
|
callback(null, "throw new Error('".concat(warning, "')"));
|
|
54
45
|
return _context.abrupt("return");
|
|
55
|
-
|
|
56
46
|
case 15:
|
|
57
47
|
if (draftOptions.fetcher) {
|
|
58
48
|
options.fetcher = draftOptions.fetcher;
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
if (draftOptions.requestCreator) {
|
|
62
51
|
options.requestCreator = draftOptions.requestCreator;
|
|
63
52
|
}
|
|
64
|
-
|
|
65
53
|
options.requireResolve = require.resolve;
|
|
66
54
|
_context.next = 20;
|
|
67
55
|
return generateClient(options);
|
|
68
|
-
|
|
69
56
|
case 20:
|
|
70
57
|
result = _context.sent;
|
|
71
|
-
|
|
72
58
|
if (result.isOk) {
|
|
73
59
|
callback(undefined, result.value);
|
|
74
60
|
} else {
|
|
75
61
|
callback(undefined, "throw new Error('".concat(result.value, "')"));
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
case 22:
|
|
79
64
|
case "end":
|
|
80
65
|
return _context.stop();
|
|
@@ -84,5 +69,4 @@ function _loader() {
|
|
|
84
69
|
}));
|
|
85
70
|
return _loader.apply(this, arguments);
|
|
86
71
|
}
|
|
87
|
-
|
|
88
72
|
export default loader;
|
|
@@ -6,24 +6,19 @@ import path from 'path';
|
|
|
6
6
|
import { ApiRouter } from '@modern-js/bff-core';
|
|
7
7
|
import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
|
|
8
8
|
import { API_APP_NAME } from "./constants";
|
|
9
|
-
|
|
10
9
|
var Storage = /*#__PURE__*/function () {
|
|
11
10
|
function Storage() {
|
|
12
11
|
_classCallCheck(this, Storage);
|
|
13
|
-
|
|
14
12
|
_defineProperty(this, "middlewares", []);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
_createClass(Storage, [{
|
|
18
15
|
key: "reset",
|
|
19
16
|
value: function reset() {
|
|
20
17
|
this.middlewares = [];
|
|
21
18
|
}
|
|
22
19
|
}]);
|
|
23
|
-
|
|
24
20
|
return Storage;
|
|
25
21
|
}();
|
|
26
|
-
|
|
27
22
|
var createTransformAPI = function createTransformAPI(storage) {
|
|
28
23
|
return {
|
|
29
24
|
addMiddleware: function addMiddleware(fn) {
|
|
@@ -31,7 +26,6 @@ var createTransformAPI = function createTransformAPI(storage) {
|
|
|
31
26
|
}
|
|
32
27
|
};
|
|
33
28
|
};
|
|
34
|
-
|
|
35
29
|
export default (function () {
|
|
36
30
|
return {
|
|
37
31
|
name: '@modern-js/plugin-bff',
|
|
@@ -42,14 +36,12 @@ export default (function () {
|
|
|
42
36
|
return {
|
|
43
37
|
prepare: function prepare() {
|
|
44
38
|
var _api$useAppContext = api.useAppContext(),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
appDirectory = _api$useAppContext.appDirectory,
|
|
40
|
+
distDirectory = _api$useAppContext.distDirectory;
|
|
48
41
|
var root = isProd() ? distDirectory : appDirectory;
|
|
49
42
|
var apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
50
43
|
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
51
44
|
var apiMod = requireExistModule(apiAppPath);
|
|
52
|
-
|
|
53
45
|
if (apiMod && typeof apiMod === 'function') {
|
|
54
46
|
apiMod(transformAPI);
|
|
55
47
|
}
|
|
@@ -57,7 +49,6 @@ export default (function () {
|
|
|
57
49
|
reset: function reset() {
|
|
58
50
|
storage.reset();
|
|
59
51
|
var newApiModule = requireExistModule(apiAppPath);
|
|
60
|
-
|
|
61
52
|
if (newApiModule && typeof newApiModule === 'function') {
|
|
62
53
|
newApiModule(transformAPI);
|
|
63
54
|
}
|
|
@@ -70,7 +61,7 @@ export default (function () {
|
|
|
70
61
|
},
|
|
71
62
|
prepareApiServer: function prepareApiServer(props, next) {
|
|
72
63
|
var pwd = props.pwd,
|
|
73
|
-
|
|
64
|
+
prefix = props.prefix;
|
|
74
65
|
var apiDir = path.resolve(pwd, API_DIR);
|
|
75
66
|
var appContext = api.useAppContext();
|
|
76
67
|
var apiRouter = new ApiRouter({
|
package/dist/types/cli.d.ts
CHANGED
package/dist/types/server.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "2.0.0-beta.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/core": "^7.18.0",
|
|
57
57
|
"@babel/runtime": "^7.18.0",
|
|
58
|
-
"@modern-js/babel-compiler": "
|
|
59
|
-
"@modern-js/bff-core": "
|
|
60
|
-
"@modern-js/create-request": "
|
|
61
|
-
"@modern-js/server-utils": "
|
|
62
|
-
"@modern-js/utils": "
|
|
58
|
+
"@modern-js/babel-compiler": "2.0.0-beta.1",
|
|
59
|
+
"@modern-js/bff-core": "2.0.0-beta.1",
|
|
60
|
+
"@modern-js/create-request": "2.0.0-beta.1",
|
|
61
|
+
"@modern-js/server-utils": "2.0.0-beta.1",
|
|
62
|
+
"@modern-js/utils": "2.0.0-beta.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/babel__core": "^7.1.15",
|
|
@@ -71,46 +71,23 @@
|
|
|
71
71
|
"typescript": "^4",
|
|
72
72
|
"webpack": "^5.74.0",
|
|
73
73
|
"webpack-chain": "^6.5.1",
|
|
74
|
-
"@modern-js/core": "
|
|
75
|
-
"@modern-js/bff-runtime": "
|
|
76
|
-
"@modern-js/runtime": "
|
|
77
|
-
"@modern-js/server-core": "
|
|
78
|
-
"@modern-js/types": "
|
|
79
|
-
"@scripts/build": "
|
|
80
|
-
"@scripts/jest-config": "
|
|
74
|
+
"@modern-js/core": "2.0.0-beta.1",
|
|
75
|
+
"@modern-js/bff-runtime": "2.0.0-beta.1",
|
|
76
|
+
"@modern-js/runtime": "2.0.0-beta.1",
|
|
77
|
+
"@modern-js/server-core": "2.0.0-beta.1",
|
|
78
|
+
"@modern-js/types": "2.0.0-beta.1",
|
|
79
|
+
"@scripts/build": "2.0.0-beta.1",
|
|
80
|
+
"@scripts/jest-config": "2.0.0-beta.1"
|
|
81
81
|
},
|
|
82
82
|
"sideEffects": false,
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"registry": "https://registry.npmjs.org/",
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"wireit": {
|
|
88
|
-
"build": {
|
|
89
|
-
"command": "modern build",
|
|
90
|
-
"files": [
|
|
91
|
-
"src/**/*",
|
|
92
|
-
"tsconfig.json",
|
|
93
|
-
"package.json"
|
|
94
|
-
],
|
|
95
|
-
"output": [
|
|
96
|
-
"dist/**/*"
|
|
97
|
-
]
|
|
98
|
-
},
|
|
99
|
-
"test": {
|
|
100
|
-
"command": "jest --passWithNoTests",
|
|
101
|
-
"files": [
|
|
102
|
-
"src/**/*",
|
|
103
|
-
"tsconfig.json",
|
|
104
|
-
"package.json",
|
|
105
|
-
"tests/**/*"
|
|
106
|
-
],
|
|
107
|
-
"output": []
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
87
|
"scripts": {
|
|
111
88
|
"new": "modern new",
|
|
112
|
-
"build": "
|
|
89
|
+
"build": "modern build",
|
|
113
90
|
"dev": "modern build --watch",
|
|
114
|
-
"test": "
|
|
91
|
+
"test": "jest --passWithNoTests"
|
|
115
92
|
}
|
|
116
93
|
}
|