@modern-js/plugin-bff 2.0.0-beta.0 → 2.0.0-beta.2
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 +65 -0
- package/dist/js/modern/cli.js +6 -22
- 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 +6 -38
- 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 +15 -37
- 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 +2 -4
- package/dist/types/server.d.ts +0 -2
- package/package.json +18 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
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 [5b9049f2e9]
|
|
20
|
+
- Updated dependencies [a8642da58f]
|
|
21
|
+
- Updated dependencies [92004d1]
|
|
22
|
+
- Updated dependencies [b8bbe036c7]
|
|
23
|
+
- Updated dependencies [c2bb0f1]
|
|
24
|
+
- Updated dependencies [d5a31df781]
|
|
25
|
+
- Updated dependencies [dda38c9c3e]
|
|
26
|
+
- Updated dependencies [3bbea92b2a]
|
|
27
|
+
- Updated dependencies [abf3421a75]
|
|
28
|
+
- Updated dependencies [543be9558e]
|
|
29
|
+
- Updated dependencies [14b712da84]
|
|
30
|
+
- @modern-js/server-utils@2.0.0-beta.2
|
|
31
|
+
- @modern-js/bff-core@2.0.0-beta.2
|
|
32
|
+
- @modern-js/utils@2.0.0-beta.2
|
|
33
|
+
- @modern-js/create-request@2.0.0-beta.2
|
|
34
|
+
- @modern-js/babel-compiler@2.0.0-beta.2
|
|
35
|
+
|
|
36
|
+
## 2.0.0-beta.1
|
|
37
|
+
|
|
38
|
+
### Major Changes
|
|
39
|
+
|
|
40
|
+
- dda38c9: chore: v2
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- 8ff2cf4c71: fix: bff api loader should run before babel loader
|
|
45
|
+
fix: bff 一体化调用的 loader 应该在 babel loader 前执行
|
|
46
|
+
- Updated dependencies [9b915e0c10]
|
|
47
|
+
- Updated dependencies [2344eb2]
|
|
48
|
+
- Updated dependencies [a2509bfbdb]
|
|
49
|
+
- Updated dependencies [92f0ead]
|
|
50
|
+
- Updated dependencies [edd1cfb1af]
|
|
51
|
+
- Updated dependencies [cc971eabfc]
|
|
52
|
+
- Updated dependencies [5b9049f]
|
|
53
|
+
- Updated dependencies [a8642da]
|
|
54
|
+
- Updated dependencies [92004d1]
|
|
55
|
+
- Updated dependencies [b8bbe036c7]
|
|
56
|
+
- Updated dependencies [d5a31df781]
|
|
57
|
+
- Updated dependencies [dda38c9]
|
|
58
|
+
- Updated dependencies [3bbea92b2a]
|
|
59
|
+
- Updated dependencies [abf3421]
|
|
60
|
+
- Updated dependencies [543be9558e]
|
|
61
|
+
- Updated dependencies [14b712d]
|
|
62
|
+
- @modern-js/server-utils@2.0.0-beta.1
|
|
63
|
+
- @modern-js/bff-core@2.0.0-beta.1
|
|
64
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
65
|
+
- @modern-js/create-request@2.0.0-beta.1
|
|
66
|
+
- @modern-js/babel-compiler@2.0.0-beta.1
|
|
67
|
+
|
|
3
68
|
## 2.0.0-beta.0
|
|
4
69
|
|
|
5
70
|
### Major Changes
|
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: {
|
|
@@ -29,9 +28,6 @@ export default (() => ({
|
|
|
29
28
|
const {
|
|
30
29
|
bff
|
|
31
30
|
} = modernConfig || {};
|
|
32
|
-
const {
|
|
33
|
-
fetcher
|
|
34
|
-
} = bff || {};
|
|
35
31
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
36
32
|
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
37
33
|
chain.resolve.alias.set('@api', rootDir);
|
|
@@ -49,9 +45,7 @@ export default (() => ({
|
|
|
49
45
|
lambdaDir,
|
|
50
46
|
existLambda,
|
|
51
47
|
port,
|
|
52
|
-
|
|
53
|
-
target: name,
|
|
54
|
-
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
48
|
+
target: name
|
|
55
49
|
});
|
|
56
50
|
}
|
|
57
51
|
},
|
|
@@ -60,7 +54,6 @@ export default (() => ({
|
|
|
60
54
|
}
|
|
61
55
|
};
|
|
62
56
|
},
|
|
63
|
-
|
|
64
57
|
modifyServerRoutes({
|
|
65
58
|
routes
|
|
66
59
|
}) {
|
|
@@ -70,26 +63,24 @@ export default (() => ({
|
|
|
70
63
|
} = modernConfig || {};
|
|
71
64
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
72
65
|
const prefixList = [];
|
|
73
|
-
|
|
74
66
|
if (Array.isArray(prefix)) {
|
|
75
67
|
prefixList.push(...prefix);
|
|
76
68
|
} else {
|
|
77
69
|
prefixList.push(prefix);
|
|
78
70
|
}
|
|
79
|
-
|
|
80
71
|
const apiServerRoutes = prefixList.map(pre => ({
|
|
81
72
|
urlPath: pre,
|
|
82
73
|
isApi: true,
|
|
83
74
|
entryPath: '',
|
|
84
75
|
isSPA: false,
|
|
85
|
-
isSSR: false
|
|
86
|
-
|
|
76
|
+
isSSR: false
|
|
77
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
87
78
|
}));
|
|
79
|
+
|
|
88
80
|
return {
|
|
89
81
|
routes: routes.concat(apiServerRoutes)
|
|
90
82
|
};
|
|
91
83
|
},
|
|
92
|
-
|
|
93
84
|
async beforeBuild() {
|
|
94
85
|
// help esbuild-register resolve @modern-js/server/runtime
|
|
95
86
|
if (isProd()) {
|
|
@@ -99,12 +90,10 @@ export default (() => ({
|
|
|
99
90
|
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
100
91
|
}
|
|
101
92
|
},
|
|
102
|
-
|
|
103
93
|
async afterBuild() {
|
|
104
94
|
if (unRegisterResolveRuntimePath) {
|
|
105
95
|
unRegisterResolveRuntimePath();
|
|
106
96
|
}
|
|
107
|
-
|
|
108
97
|
const {
|
|
109
98
|
appDirectory,
|
|
110
99
|
distDirectory
|
|
@@ -115,32 +104,28 @@ export default (() => ({
|
|
|
115
104
|
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
116
105
|
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
117
106
|
const sourceDirs = [];
|
|
118
|
-
|
|
119
107
|
if (fs.existsSync(apiDir)) {
|
|
120
108
|
sourceDirs.push(apiDir);
|
|
121
109
|
}
|
|
122
|
-
|
|
123
110
|
if (fs.existsSync(sharedDir)) {
|
|
124
111
|
sourceDirs.push(sharedDir);
|
|
125
112
|
}
|
|
126
|
-
|
|
127
113
|
const {
|
|
128
114
|
server
|
|
129
115
|
} = modernConfig;
|
|
130
116
|
const {
|
|
131
117
|
alias,
|
|
132
|
-
|
|
118
|
+
define,
|
|
133
119
|
globalVars
|
|
134
120
|
} = modernConfig.source;
|
|
135
121
|
const {
|
|
136
122
|
babel
|
|
137
123
|
} = modernConfig.tools;
|
|
138
|
-
|
|
139
124
|
if (sourceDirs.length > 0) {
|
|
140
125
|
await compile(appDirectory, {
|
|
141
126
|
server,
|
|
142
127
|
alias,
|
|
143
|
-
|
|
128
|
+
define,
|
|
144
129
|
globalVars,
|
|
145
130
|
babelConfig: babel
|
|
146
131
|
}, {
|
|
@@ -150,7 +135,6 @@ export default (() => ({
|
|
|
150
135
|
});
|
|
151
136
|
}
|
|
152
137
|
}
|
|
153
|
-
|
|
154
138
|
};
|
|
155
139
|
}
|
|
156
140
|
}));
|
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: {
|
|
@@ -44,13 +35,8 @@ var _default = () => ({
|
|
|
44
35
|
const {
|
|
45
36
|
bff
|
|
46
37
|
} = modernConfig || {};
|
|
47
|
-
const {
|
|
48
|
-
fetcher
|
|
49
|
-
} = bff || {};
|
|
50
38
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
51
|
-
|
|
52
39
|
const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
53
|
-
|
|
54
40
|
chain.resolve.alias.set('@api', rootDir);
|
|
55
41
|
const apiRouter = new _bffCore.ApiRouter({
|
|
56
42
|
apiDir: rootDir,
|
|
@@ -66,9 +52,7 @@ var _default = () => ({
|
|
|
66
52
|
lambdaDir,
|
|
67
53
|
existLambda,
|
|
68
54
|
port,
|
|
69
|
-
|
|
70
|
-
target: name,
|
|
71
|
-
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
55
|
+
target: name
|
|
72
56
|
});
|
|
73
57
|
}
|
|
74
58
|
},
|
|
@@ -77,7 +61,6 @@ var _default = () => ({
|
|
|
77
61
|
}
|
|
78
62
|
};
|
|
79
63
|
},
|
|
80
|
-
|
|
81
64
|
modifyServerRoutes({
|
|
82
65
|
routes
|
|
83
66
|
}) {
|
|
@@ -87,26 +70,24 @@ var _default = () => ({
|
|
|
87
70
|
} = modernConfig || {};
|
|
88
71
|
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
89
72
|
const prefixList = [];
|
|
90
|
-
|
|
91
73
|
if (Array.isArray(prefix)) {
|
|
92
74
|
prefixList.push(...prefix);
|
|
93
75
|
} else {
|
|
94
76
|
prefixList.push(prefix);
|
|
95
77
|
}
|
|
96
|
-
|
|
97
78
|
const apiServerRoutes = prefixList.map(pre => ({
|
|
98
79
|
urlPath: pre,
|
|
99
80
|
isApi: true,
|
|
100
81
|
entryPath: '',
|
|
101
82
|
isSPA: false,
|
|
102
|
-
isSSR: false
|
|
103
|
-
|
|
83
|
+
isSSR: false
|
|
84
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
104
85
|
}));
|
|
86
|
+
|
|
105
87
|
return {
|
|
106
88
|
routes: routes.concat(apiServerRoutes)
|
|
107
89
|
};
|
|
108
90
|
},
|
|
109
|
-
|
|
110
91
|
async beforeBuild() {
|
|
111
92
|
// help esbuild-register resolve @modern-js/server/runtime
|
|
112
93
|
if ((0, _utils.isProd)()) {
|
|
@@ -116,53 +97,42 @@ var _default = () => ({
|
|
|
116
97
|
unRegisterResolveRuntimePath = (0, _helper.registerModernRuntimePath)(internalDirectory);
|
|
117
98
|
}
|
|
118
99
|
},
|
|
119
|
-
|
|
120
100
|
async afterBuild() {
|
|
121
101
|
if (unRegisterResolveRuntimePath) {
|
|
122
102
|
unRegisterResolveRuntimePath();
|
|
123
103
|
}
|
|
124
|
-
|
|
125
104
|
const {
|
|
126
105
|
appDirectory,
|
|
127
106
|
distDirectory
|
|
128
107
|
} = api.useAppContext();
|
|
129
108
|
const modernConfig = api.useResolvedConfigContext();
|
|
130
|
-
|
|
131
109
|
const distDir = _path.default.resolve(distDirectory);
|
|
132
|
-
|
|
133
110
|
const apiDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
134
|
-
|
|
135
111
|
const sharedDir = _path.default.resolve(appDirectory, _utils.SHARED_DIR);
|
|
136
|
-
|
|
137
112
|
const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
138
|
-
|
|
139
113
|
const sourceDirs = [];
|
|
140
|
-
|
|
141
114
|
if (_utils.fs.existsSync(apiDir)) {
|
|
142
115
|
sourceDirs.push(apiDir);
|
|
143
116
|
}
|
|
144
|
-
|
|
145
117
|
if (_utils.fs.existsSync(sharedDir)) {
|
|
146
118
|
sourceDirs.push(sharedDir);
|
|
147
119
|
}
|
|
148
|
-
|
|
149
120
|
const {
|
|
150
121
|
server
|
|
151
122
|
} = modernConfig;
|
|
152
123
|
const {
|
|
153
124
|
alias,
|
|
154
|
-
|
|
125
|
+
define,
|
|
155
126
|
globalVars
|
|
156
127
|
} = modernConfig.source;
|
|
157
128
|
const {
|
|
158
129
|
babel
|
|
159
130
|
} = modernConfig.tools;
|
|
160
|
-
|
|
161
131
|
if (sourceDirs.length > 0) {
|
|
162
132
|
await (0, _serverUtils.compile)(appDirectory, {
|
|
163
133
|
server,
|
|
164
134
|
alias,
|
|
165
|
-
|
|
135
|
+
define,
|
|
166
136
|
globalVars,
|
|
167
137
|
babelConfig: babel
|
|
168
138
|
}, {
|
|
@@ -172,9 +142,7 @@ var _default = () => ({
|
|
|
172
142
|
});
|
|
173
143
|
}
|
|
174
144
|
}
|
|
175
|
-
|
|
176
145
|
};
|
|
177
146
|
}
|
|
178
147
|
});
|
|
179
|
-
|
|
180
148
|
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,13 @@ 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
|
-
|
|
36
|
-
var _ref3 = bff || {},
|
|
37
|
-
fetcher = _ref3.fetcher;
|
|
38
|
-
|
|
31
|
+
bff = _ref2.bff;
|
|
39
32
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
40
33
|
var rootDir = path.resolve(appDirectory, API_DIR);
|
|
41
34
|
chain.resolve.alias.set('@api', rootDir);
|
|
@@ -53,9 +46,7 @@ export default (function () {
|
|
|
53
46
|
lambdaDir: lambdaDir,
|
|
54
47
|
existLambda: existLambda,
|
|
55
48
|
port: port,
|
|
56
|
-
|
|
57
|
-
target: name,
|
|
58
|
-
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
49
|
+
target: name
|
|
59
50
|
});
|
|
60
51
|
}
|
|
61
52
|
},
|
|
@@ -64,32 +55,29 @@ export default (function () {
|
|
|
64
55
|
}
|
|
65
56
|
};
|
|
66
57
|
},
|
|
67
|
-
modifyServerRoutes: function modifyServerRoutes(
|
|
68
|
-
var routes =
|
|
58
|
+
modifyServerRoutes: function modifyServerRoutes(_ref3) {
|
|
59
|
+
var routes = _ref3.routes;
|
|
69
60
|
var modernConfig = api.useResolvedConfigContext();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
bff = _ref5.bff;
|
|
73
|
-
|
|
61
|
+
var _ref4 = modernConfig || {},
|
|
62
|
+
bff = _ref4.bff;
|
|
74
63
|
var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
75
64
|
var prefixList = [];
|
|
76
|
-
|
|
77
65
|
if (Array.isArray(prefix)) {
|
|
78
66
|
prefixList.push.apply(prefixList, _toConsumableArray(prefix));
|
|
79
67
|
} else {
|
|
80
68
|
prefixList.push(prefix);
|
|
81
69
|
}
|
|
82
|
-
|
|
83
70
|
var apiServerRoutes = prefixList.map(function (pre) {
|
|
84
71
|
return {
|
|
85
72
|
urlPath: pre,
|
|
86
73
|
isApi: true,
|
|
87
74
|
entryPath: '',
|
|
88
75
|
isSPA: false,
|
|
89
|
-
isSSR: false
|
|
90
|
-
|
|
76
|
+
isSSR: false
|
|
77
|
+
// FIXME: })) as IAppContext[`serverRoutes`];
|
|
91
78
|
};
|
|
92
79
|
});
|
|
80
|
+
|
|
93
81
|
return {
|
|
94
82
|
routes: routes.concat(apiServerRoutes)
|
|
95
83
|
};
|
|
@@ -97,7 +85,6 @@ export default (function () {
|
|
|
97
85
|
beforeBuild: function beforeBuild() {
|
|
98
86
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
99
87
|
var _api$useAppContext2, internalDirectory;
|
|
100
|
-
|
|
101
88
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
102
89
|
while (1) {
|
|
103
90
|
switch (_context.prev = _context.next) {
|
|
@@ -107,7 +94,6 @@ export default (function () {
|
|
|
107
94
|
_api$useAppContext2 = api.useAppContext(), internalDirectory = _api$useAppContext2.internalDirectory;
|
|
108
95
|
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
109
96
|
}
|
|
110
|
-
|
|
111
97
|
case 1:
|
|
112
98
|
case "end":
|
|
113
99
|
return _context.stop();
|
|
@@ -118,8 +104,7 @@ export default (function () {
|
|
|
118
104
|
},
|
|
119
105
|
afterBuild: function afterBuild() {
|
|
120
106
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
121
|
-
var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig$source, alias,
|
|
122
|
-
|
|
107
|
+
var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig$source, alias, define, globalVars, babel;
|
|
123
108
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
124
109
|
while (1) {
|
|
125
110
|
switch (_context2.prev = _context2.next) {
|
|
@@ -127,7 +112,6 @@ export default (function () {
|
|
|
127
112
|
if (unRegisterResolveRuntimePath) {
|
|
128
113
|
unRegisterResolveRuntimePath();
|
|
129
114
|
}
|
|
130
|
-
|
|
131
115
|
_api$useAppContext3 = api.useAppContext(), appDirectory = _api$useAppContext3.appDirectory, distDirectory = _api$useAppContext3.distDirectory;
|
|
132
116
|
modernConfig = api.useResolvedConfigContext();
|
|
133
117
|
distDir = path.resolve(distDirectory);
|
|
@@ -135,29 +119,24 @@ export default (function () {
|
|
|
135
119
|
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
136
120
|
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
137
121
|
sourceDirs = [];
|
|
138
|
-
|
|
139
122
|
if (fs.existsSync(apiDir)) {
|
|
140
123
|
sourceDirs.push(apiDir);
|
|
141
124
|
}
|
|
142
|
-
|
|
143
125
|
if (fs.existsSync(sharedDir)) {
|
|
144
126
|
sourceDirs.push(sharedDir);
|
|
145
127
|
}
|
|
146
|
-
|
|
147
128
|
server = modernConfig.server;
|
|
148
|
-
_modernConfig$source = modernConfig.source, alias = _modernConfig$source.alias,
|
|
129
|
+
_modernConfig$source = modernConfig.source, alias = _modernConfig$source.alias, define = _modernConfig$source.define, globalVars = _modernConfig$source.globalVars;
|
|
149
130
|
babel = modernConfig.tools.babel;
|
|
150
|
-
|
|
151
131
|
if (!(sourceDirs.length > 0)) {
|
|
152
132
|
_context2.next = 16;
|
|
153
133
|
break;
|
|
154
134
|
}
|
|
155
|
-
|
|
156
135
|
_context2.next = 16;
|
|
157
136
|
return compile(appDirectory, {
|
|
158
137
|
server: server,
|
|
159
138
|
alias: alias,
|
|
160
|
-
|
|
139
|
+
define: define,
|
|
161
140
|
globalVars: globalVars,
|
|
162
141
|
babelConfig: babel
|
|
163
142
|
}, {
|
|
@@ -165,7 +144,6 @@ export default (function () {
|
|
|
165
144
|
distDir: distDir,
|
|
166
145
|
tsconfigPath: tsconfigPath
|
|
167
146
|
});
|
|
168
|
-
|
|
169
147
|
case 16:
|
|
170
148
|
case "end":
|
|
171
149
|
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": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,20 +55,13 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/core": "^7.18.0",
|
|
57
57
|
"@babel/runtime": "^7.18.0",
|
|
58
|
-
"@modern-js/babel-compiler": "2.0.0-beta.
|
|
59
|
-
"@modern-js/bff-core": "2.0.0-beta.
|
|
60
|
-
"@modern-js/create-request": "2.0.0-beta.
|
|
61
|
-
"@modern-js/server-utils": "2.0.0-beta.
|
|
62
|
-
"@modern-js/utils": "2.0.0-beta.
|
|
58
|
+
"@modern-js/babel-compiler": "2.0.0-beta.2",
|
|
59
|
+
"@modern-js/bff-core": "2.0.0-beta.2",
|
|
60
|
+
"@modern-js/create-request": "2.0.0-beta.2",
|
|
61
|
+
"@modern-js/server-utils": "2.0.0-beta.2",
|
|
62
|
+
"@modern-js/utils": "2.0.0-beta.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@modern-js/core": "2.0.0-beta.0",
|
|
66
|
-
"@modern-js/bff-runtime": "2.0.0-beta.0",
|
|
67
|
-
"@modern-js/runtime": "2.0.0-beta.0",
|
|
68
|
-
"@modern-js/server-core": "2.0.0-beta.0",
|
|
69
|
-
"@modern-js/types": "2.0.0-beta.0",
|
|
70
|
-
"@scripts/build": "2.0.0-beta.0",
|
|
71
|
-
"@scripts/jest-config": "2.0.0-beta.0",
|
|
72
65
|
"@types/babel__core": "^7.1.15",
|
|
73
66
|
"@types/jest": "^27",
|
|
74
67
|
"@types/node": "^14",
|
|
@@ -77,7 +70,15 @@
|
|
|
77
70
|
"ts-jest": "^27.0.5",
|
|
78
71
|
"typescript": "^4",
|
|
79
72
|
"webpack": "^5.74.0",
|
|
80
|
-
"webpack-chain": "^6.5.1"
|
|
73
|
+
"webpack-chain": "^6.5.1",
|
|
74
|
+
"@modern-js/runtime": "2.0.0-beta.2",
|
|
75
|
+
"@modern-js/core": "2.0.0-beta.2",
|
|
76
|
+
"@modern-js/bff-runtime": "2.0.0-beta.2",
|
|
77
|
+
"@modern-js/server-core": "2.0.0-beta.2",
|
|
78
|
+
"@modern-js/types": "2.0.0-beta.2",
|
|
79
|
+
"@modern-js/app-tools": "2.0.0-beta.2",
|
|
80
|
+
"@scripts/build": "2.0.0-beta.2",
|
|
81
|
+
"@scripts/jest-config": "2.0.0-beta.2"
|
|
81
82
|
},
|
|
82
83
|
"sideEffects": false,
|
|
83
84
|
"publishConfig": {
|
|
@@ -85,9 +86,9 @@
|
|
|
85
86
|
"access": "public"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
|
-
"new": "modern new",
|
|
89
|
-
"build": "modern build",
|
|
90
|
-
"dev": "modern build --watch",
|
|
89
|
+
"new": "modern-lib new",
|
|
90
|
+
"build": "modern-lib build",
|
|
91
|
+
"dev": "modern-lib build --watch",
|
|
91
92
|
"test": "jest --passWithNoTests"
|
|
92
93
|
}
|
|
93
94
|
}
|