@modern-js/plugin-bff 1.3.7 → 1.3.9
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 +19 -0
- package/dist/js/modern/cli.js +98 -104
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/server.js +43 -43
- package/dist/js/node/cli.js +108 -116
- package/dist/js/node/index.js +0 -2
- package/dist/js/node/server.js +46 -47
- package/dist/types/cli.d.ts +5 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/loader.d.ts +11 -0
- package/dist/types/server.d.ts +5 -0
- package/jest.config.js +0 -1
- package/modern.config.js +5 -1
- package/package.json +15 -21
- package/tests/compiler.ts +0 -1
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/types.js +0 -3
- package/types.d.ts +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 1.3.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
8
|
+
- 132f7b53: feat: move config declarations to @modern-js/core
|
|
9
|
+
- Updated dependencies [bebb39b6]
|
|
10
|
+
- Updated dependencies [132f7b53]
|
|
11
|
+
- @modern-js/server-utils@1.2.2
|
|
12
|
+
- @modern-js/utils@1.3.7
|
|
13
|
+
|
|
14
|
+
## 1.3.8
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- c1b8fa0a: feat: convert to new server plugin
|
|
19
|
+
- Updated dependencies [c2046f37]
|
|
20
|
+
- @modern-js/utils@1.3.6
|
|
21
|
+
|
|
3
22
|
## 1.3.6
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -1,123 +1,117 @@
|
|
|
1
|
-
import "./types";
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import fs from 'fs-extra';
|
|
4
|
-
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
5
3
|
import { compiler } from '@modern-js/babel-compiler';
|
|
6
4
|
import { PLUGIN_SCHEMAS, normalizeOutputPath, API_DIR } from '@modern-js/utils';
|
|
7
5
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
8
6
|
const DEFAULT_API_PREFIX = '/api';
|
|
9
7
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
10
8
|
const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
|
11
|
-
export default
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export default (() => ({
|
|
10
|
+
name: '@modern-js/plugin-bff',
|
|
11
|
+
setup: api => ({
|
|
12
|
+
validateSchema() {
|
|
13
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
|
|
14
|
+
},
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
16
|
+
config() {
|
|
17
|
+
return {
|
|
18
|
+
tools: {
|
|
19
|
+
webpack: (_config, {
|
|
20
|
+
chain
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
appDirectory,
|
|
24
|
+
port
|
|
25
|
+
} = api.useAppContext();
|
|
26
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
27
|
+
const {
|
|
28
|
+
bff
|
|
29
|
+
} = modernConfig || {};
|
|
30
|
+
const {
|
|
31
|
+
fetcher
|
|
32
|
+
} = bff || {};
|
|
33
|
+
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
34
|
+
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
35
|
+
chain.resolve.alias.set('@api', rootDir);
|
|
36
|
+
const apiRegexp = new RegExp(normalizeOutputPath(`${appDirectory}${path.sep}api${path.sep}.*(.[tj]s)$`));
|
|
37
|
+
chain.module.rule('loaders').oneOf('bff-client').before('fallback').test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
38
|
+
prefix,
|
|
39
|
+
apiDir: rootDir,
|
|
40
|
+
port,
|
|
41
|
+
fetcher,
|
|
42
|
+
target: _config.name,
|
|
43
|
+
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
source: {
|
|
48
|
+
moduleScopes: [`./${API_DIR}`, /create-request/]
|
|
47
49
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
moduleScopes: [`./${API_DIR}`, /create-request/]
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
modifyServerRoutes({
|
|
56
|
-
routes
|
|
57
|
-
}) {
|
|
58
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
59
|
-
const modernConfig = useResolvedConfigContext();
|
|
60
|
-
const {
|
|
61
|
-
bff
|
|
62
|
-
} = modernConfig || {};
|
|
63
|
-
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
64
|
-
const prefixList = [];
|
|
65
|
-
|
|
66
|
-
if (Array.isArray(prefix)) {
|
|
67
|
-
prefixList.push(...prefix);
|
|
68
|
-
} else {
|
|
69
|
-
prefixList.push(prefix);
|
|
70
|
-
}
|
|
50
|
+
};
|
|
51
|
+
},
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
53
|
+
modifyServerRoutes({
|
|
54
|
+
routes
|
|
55
|
+
}) {
|
|
56
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
57
|
+
const {
|
|
58
|
+
bff
|
|
59
|
+
} = modernConfig || {};
|
|
60
|
+
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
61
|
+
const prefixList = [];
|
|
78
62
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
63
|
+
if (Array.isArray(prefix)) {
|
|
64
|
+
prefixList.push(...prefix);
|
|
65
|
+
} else {
|
|
66
|
+
prefixList.push(prefix);
|
|
67
|
+
}
|
|
84
68
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
const apiServerRoutes = prefixList.map(pre => ({
|
|
70
|
+
urlPath: pre,
|
|
71
|
+
isApi: true,
|
|
72
|
+
entryPath: '',
|
|
73
|
+
isSPA: false,
|
|
74
|
+
isSSR: false // FIXME: })) as IAppContext[`serverRoutes`];
|
|
91
75
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
|
|
98
|
-
tsconfigPath,
|
|
99
|
-
syntax: 'es6+',
|
|
100
|
-
type: 'commonjs'
|
|
101
|
-
});
|
|
102
|
-
const result = await compiler({
|
|
103
|
-
rootDir,
|
|
104
|
-
distDir,
|
|
105
|
-
sourceDir: sourceAbsDir,
|
|
106
|
-
extensions: FILE_EXTENSIONS,
|
|
107
|
-
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
108
|
-
}, babelConfig);
|
|
76
|
+
}));
|
|
77
|
+
return {
|
|
78
|
+
routes: routes.concat(apiServerRoutes)
|
|
79
|
+
};
|
|
80
|
+
},
|
|
109
81
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
async afterBuild() {
|
|
83
|
+
const {
|
|
84
|
+
appDirectory,
|
|
85
|
+
distDirectory
|
|
86
|
+
} = api.useAppContext();
|
|
87
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
88
|
+
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
89
|
+
const distDir = path.resolve(distDirectory, API_DIR);
|
|
90
|
+
const sourceAbsDir = path.resolve(appDirectory, API_DIR);
|
|
91
|
+
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
92
|
+
const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
|
|
93
|
+
tsconfigPath,
|
|
94
|
+
syntax: 'es6+',
|
|
95
|
+
type: 'commonjs'
|
|
113
96
|
});
|
|
114
|
-
|
|
97
|
+
const result = await compiler({
|
|
98
|
+
rootDir,
|
|
99
|
+
distDir,
|
|
100
|
+
sourceDir: sourceAbsDir,
|
|
101
|
+
extensions: FILE_EXTENSIONS,
|
|
102
|
+
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
103
|
+
}, babelConfig);
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
if (await fs.pathExists(rootDir)) {
|
|
106
|
+
await fs.copy(rootDir, distDir, {
|
|
107
|
+
filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (result.code === 1) {
|
|
112
|
+
throw new Error(result.message);
|
|
113
|
+
}
|
|
118
114
|
}
|
|
119
|
-
}
|
|
120
115
|
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
});
|
|
116
|
+
})
|
|
117
|
+
}));
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/modern/server.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { createPlugin, useAppContext } from '@modern-js/server-core';
|
|
3
2
|
import { injectAPIHandlerInfos } from '@modern-js/bff-utils';
|
|
4
3
|
import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
|
|
5
4
|
import { API_APP_NAME } from "./constants";
|
|
@@ -22,51 +21,52 @@ const createTransformAPI = storage => ({
|
|
|
22
21
|
|
|
23
22
|
});
|
|
24
23
|
|
|
25
|
-
export default
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
export default (() => ({
|
|
25
|
+
name: '@modern-js/plugin-bff',
|
|
26
|
+
setup: api => {
|
|
27
|
+
const {
|
|
28
|
+
appDirectory,
|
|
29
|
+
distDirectory
|
|
30
|
+
} = api.useAppContext();
|
|
31
|
+
const root = isProd() ? distDirectory : appDirectory;
|
|
32
|
+
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
33
|
+
const apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
34
|
+
const storage = new Storage();
|
|
35
|
+
const transformAPI = createTransformAPI(storage);
|
|
36
|
+
const apiMod = requireExistModule(apiAppPath);
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (apiMod && typeof apiMod === 'function') {
|
|
39
|
+
apiMod(transformAPI);
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
return {
|
|
43
|
+
reset() {
|
|
44
|
+
storage.reset();
|
|
45
|
+
const newApiModule = requireExistModule(apiAppPath);
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if (newApiModule && typeof newApiModule === 'function') {
|
|
48
|
+
newApiModule(transformAPI);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
gather({
|
|
53
|
+
addAPIMiddleware
|
|
54
|
+
}) {
|
|
55
|
+
storage.middlewares.forEach(mid => {
|
|
56
|
+
addAPIMiddleware(mid);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
prepareApiServer(props, next) {
|
|
61
|
+
const {
|
|
62
|
+
pwd,
|
|
63
|
+
prefix
|
|
64
|
+
} = props;
|
|
65
|
+
const apiDir = path.resolve(pwd, API_DIR);
|
|
66
|
+
injectAPIHandlerInfos(apiDir, prefix);
|
|
67
|
+
return next(props);
|
|
68
|
+
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
});
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}));
|
package/dist/js/node/cli.js
CHANGED
|
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
require("./types");
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
9
|
|
|
12
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
11
|
|
|
14
|
-
var _core = require("@modern-js/core");
|
|
15
|
-
|
|
16
12
|
var _babelCompiler = require("@modern-js/babel-compiler");
|
|
17
13
|
|
|
18
14
|
var _utils = require("@modern-js/utils");
|
|
@@ -25,125 +21,121 @@ const DEFAULT_API_PREFIX = '/api';
|
|
|
25
21
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
26
22
|
const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
|
27
23
|
|
|
28
|
-
var _default = (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
24
|
+
var _default = () => ({
|
|
25
|
+
name: '@modern-js/plugin-bff',
|
|
26
|
+
setup: api => ({
|
|
27
|
+
validateSchema() {
|
|
28
|
+
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
config() {
|
|
32
|
+
return {
|
|
33
|
+
tools: {
|
|
34
|
+
webpack: (_config, {
|
|
35
|
+
chain
|
|
36
|
+
}) => {
|
|
37
|
+
const {
|
|
38
|
+
appDirectory,
|
|
39
|
+
port
|
|
40
|
+
} = api.useAppContext();
|
|
41
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
42
|
+
const {
|
|
43
|
+
bff
|
|
44
|
+
} = modernConfig || {};
|
|
45
|
+
const {
|
|
46
|
+
fetcher
|
|
47
|
+
} = bff || {};
|
|
48
|
+
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
49
|
+
|
|
50
|
+
const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
51
|
+
|
|
52
|
+
chain.resolve.alias.set('@api', rootDir);
|
|
53
|
+
const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${appDirectory}${_path.default.sep}api${_path.default.sep}.*(.[tj]s)$`));
|
|
54
|
+
chain.module.rule('loaders').oneOf('bff-client').before('fallback').test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
55
|
+
prefix,
|
|
56
|
+
apiDir: rootDir,
|
|
57
|
+
port,
|
|
58
|
+
fetcher,
|
|
59
|
+
target: _config.name,
|
|
60
|
+
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
source: {
|
|
65
|
+
moduleScopes: [`./${_utils.API_DIR}`, /create-request/]
|
|
66
66
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
modifyServerRoutes({
|
|
71
|
+
routes
|
|
72
|
+
}) {
|
|
73
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
74
|
+
const {
|
|
75
|
+
bff
|
|
76
|
+
} = modernConfig || {};
|
|
77
|
+
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
78
|
+
const prefixList = [];
|
|
79
|
+
|
|
80
|
+
if (Array.isArray(prefix)) {
|
|
81
|
+
prefixList.push(...prefix);
|
|
82
|
+
} else {
|
|
83
|
+
prefixList.push(prefix);
|
|
70
84
|
}
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
modifyServerRoutes({
|
|
75
|
-
routes
|
|
76
|
-
}) {
|
|
77
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
78
|
-
const modernConfig = (0, _core.useResolvedConfigContext)();
|
|
79
|
-
const {
|
|
80
|
-
bff
|
|
81
|
-
} = modernConfig || {};
|
|
82
|
-
const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
|
|
83
|
-
const prefixList = [];
|
|
84
|
-
|
|
85
|
-
if (Array.isArray(prefix)) {
|
|
86
|
-
prefixList.push(...prefix);
|
|
87
|
-
} else {
|
|
88
|
-
prefixList.push(prefix);
|
|
89
|
-
}
|
|
90
85
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
syntax: 'es6+',
|
|
124
|
-
type: 'commonjs'
|
|
125
|
-
});
|
|
126
|
-
const result = await (0, _babelCompiler.compiler)({
|
|
127
|
-
rootDir,
|
|
128
|
-
distDir,
|
|
129
|
-
sourceDir: sourceAbsDir,
|
|
130
|
-
extensions: FILE_EXTENSIONS,
|
|
131
|
-
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
132
|
-
}, babelConfig);
|
|
133
|
-
|
|
134
|
-
if (await _fsExtra.default.pathExists(rootDir)) {
|
|
135
|
-
await _fsExtra.default.copy(rootDir, distDir, {
|
|
136
|
-
filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
86
|
+
const apiServerRoutes = prefixList.map(pre => ({
|
|
87
|
+
urlPath: pre,
|
|
88
|
+
isApi: true,
|
|
89
|
+
entryPath: '',
|
|
90
|
+
isSPA: false,
|
|
91
|
+
isSSR: false // FIXME: })) as IAppContext[`serverRoutes`];
|
|
92
|
+
|
|
93
|
+
}));
|
|
94
|
+
return {
|
|
95
|
+
routes: routes.concat(apiServerRoutes)
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
async afterBuild() {
|
|
100
|
+
const {
|
|
101
|
+
appDirectory,
|
|
102
|
+
distDirectory
|
|
103
|
+
} = api.useAppContext();
|
|
104
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
105
|
+
|
|
106
|
+
const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
107
|
+
|
|
108
|
+
const distDir = _path.default.resolve(distDirectory, _utils.API_DIR);
|
|
109
|
+
|
|
110
|
+
const sourceAbsDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
111
|
+
|
|
112
|
+
const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
113
|
+
|
|
114
|
+
const babelConfig = (0, _serverUtils.resolveBabelConfig)(appDirectory, modernConfig, {
|
|
115
|
+
tsconfigPath,
|
|
116
|
+
syntax: 'es6+',
|
|
117
|
+
type: 'commonjs'
|
|
137
118
|
});
|
|
138
|
-
|
|
119
|
+
const result = await (0, _babelCompiler.compiler)({
|
|
120
|
+
rootDir,
|
|
121
|
+
distDir,
|
|
122
|
+
sourceDir: sourceAbsDir,
|
|
123
|
+
extensions: FILE_EXTENSIONS,
|
|
124
|
+
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
125
|
+
}, babelConfig);
|
|
126
|
+
|
|
127
|
+
if (await _fsExtra.default.pathExists(rootDir)) {
|
|
128
|
+
await _fsExtra.default.copy(rootDir, distDir, {
|
|
129
|
+
filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
130
|
+
});
|
|
131
|
+
}
|
|
139
132
|
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
if (result.code === 1) {
|
|
134
|
+
throw new Error(result.message);
|
|
135
|
+
}
|
|
142
136
|
}
|
|
143
|
-
}
|
|
144
137
|
|
|
145
|
-
})
|
|
146
|
-
name: '@modern-js/plugin-bff'
|
|
138
|
+
})
|
|
147
139
|
});
|
|
148
140
|
|
|
149
141
|
exports.default = _default;
|
package/dist/js/node/index.js
CHANGED
package/dist/js/node/server.js
CHANGED
|
@@ -7,8 +7,6 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
10
|
-
var _serverCore = require("@modern-js/server-core");
|
|
11
|
-
|
|
12
10
|
var _bffUtils = require("@modern-js/bff-utils");
|
|
13
11
|
|
|
14
12
|
var _utils = require("@modern-js/utils");
|
|
@@ -35,58 +33,59 @@ const createTransformAPI = storage => ({
|
|
|
35
33
|
|
|
36
34
|
});
|
|
37
35
|
|
|
38
|
-
var _default = (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
var _default = () => ({
|
|
37
|
+
name: '@modern-js/plugin-bff',
|
|
38
|
+
setup: api => {
|
|
39
|
+
const {
|
|
40
|
+
appDirectory,
|
|
41
|
+
distDirectory
|
|
42
|
+
} = api.useAppContext();
|
|
43
|
+
const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
const transformAPI = createTransformAPI(storage);
|
|
51
|
-
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
47
|
+
const apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const storage = new Storage();
|
|
50
|
+
const transformAPI = createTransformAPI(storage);
|
|
51
|
+
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
|
|
53
|
+
if (apiMod && typeof apiMod === 'function') {
|
|
54
|
+
apiMod(transformAPI);
|
|
55
|
+
}
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
return {
|
|
58
|
+
reset() {
|
|
59
|
+
storage.reset();
|
|
60
|
+
const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
|
|
61
|
+
|
|
62
|
+
if (newApiModule && typeof newApiModule === 'function') {
|
|
63
|
+
newApiModule(transformAPI);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
gather({
|
|
68
|
+
addAPIMiddleware
|
|
69
|
+
}) {
|
|
70
|
+
storage.middlewares.forEach(mid => {
|
|
71
|
+
addAPIMiddleware(mid);
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
prepareApiServer(props, next) {
|
|
76
|
+
const {
|
|
77
|
+
pwd,
|
|
78
|
+
prefix
|
|
79
|
+
} = props;
|
|
80
|
+
|
|
81
|
+
const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
|
|
82
|
+
|
|
83
|
+
(0, _bffUtils.injectAPIHandlerInfos)(apiDir, prefix);
|
|
84
|
+
return next(props);
|
|
64
85
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
gather({
|
|
68
|
-
addAPIMiddleware
|
|
69
|
-
}) {
|
|
70
|
-
storage.middlewares.forEach(mid => {
|
|
71
|
-
addAPIMiddleware(mid);
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
prepareApiServer(props, next) {
|
|
76
|
-
const {
|
|
77
|
-
pwd,
|
|
78
|
-
prefix
|
|
79
|
-
} = props;
|
|
80
|
-
|
|
81
|
-
const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
|
|
82
|
-
|
|
83
|
-
(0, _bffUtils.injectAPIHandlerInfos)(apiDir, prefix);
|
|
84
|
-
return next(props);
|
|
85
|
-
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
name: '@modern-js/plugin-bff'
|
|
87
|
+
};
|
|
88
|
+
}
|
|
90
89
|
});
|
|
91
90
|
|
|
92
91
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constants';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
export declare type APILoaderOptions = {
|
|
3
|
+
prefix: string;
|
|
4
|
+
apiDir: string;
|
|
5
|
+
port: number;
|
|
6
|
+
fetcher?: string;
|
|
7
|
+
requestCreator?: string;
|
|
8
|
+
target: string;
|
|
9
|
+
};
|
|
10
|
+
declare function loader(this: LoaderContext<APILoaderOptions>, source: string): Promise<void>;
|
|
11
|
+
export default loader;
|
package/jest.config.js
CHANGED
package/modern.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.3.
|
|
14
|
+
"version": "1.3.9",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -56,43 +56,37 @@
|
|
|
56
56
|
"@babel/core": "7.16.7",
|
|
57
57
|
"@babel/runtime": "^7",
|
|
58
58
|
"@modern-js/babel-compiler": "^1.2.2",
|
|
59
|
+
"@modern-js/bff-utils": "^1.2.2",
|
|
59
60
|
"@modern-js/create-request": "^1.2.2",
|
|
60
|
-
"@modern-js/server-utils": "^1.2.
|
|
61
|
-
"@modern-js/utils": "^1.3.
|
|
61
|
+
"@modern-js/server-utils": "^1.2.2",
|
|
62
|
+
"@modern-js/utils": "^1.3.7",
|
|
62
63
|
"fs-extra": "^10.0.0",
|
|
63
|
-
"loader-utils": "^2.0.0"
|
|
64
|
-
"@modern-js/bff-utils": "^1.2.2",
|
|
65
|
-
"@modern-js/server-core": "^1.2.2",
|
|
66
|
-
"@modern-js/core": "^1.4.6"
|
|
64
|
+
"loader-utils": "^2.0.0"
|
|
67
65
|
},
|
|
68
66
|
"devDependencies": {
|
|
67
|
+
"@modern-js/core": "1.6.1",
|
|
68
|
+
"@modern-js/plugin-analyze": "^1.3.5",
|
|
69
|
+
"@modern-js/runtime": "^1.2.5",
|
|
70
|
+
"@modern-js/server-core": "1.2.5",
|
|
71
|
+
"@modern-js/types": "^1.3.6",
|
|
69
72
|
"@scripts/build": "0.0.0",
|
|
70
|
-
"@
|
|
71
|
-
"@modern-js/runtime": "^1.2.2",
|
|
72
|
-
"@modern-js/types": "^1.3.4",
|
|
73
|
+
"@scripts/jest-config": "0.0.0",
|
|
73
74
|
"@types/babel__core": "^7.1.15",
|
|
74
75
|
"@types/fs-extra": "^9.0.13",
|
|
75
76
|
"@types/jest": "^26",
|
|
76
77
|
"@types/loader-utils": "^2.0.3",
|
|
77
78
|
"@types/node": "^14",
|
|
79
|
+
"jest": "^27",
|
|
78
80
|
"memfs": "^3.3.0",
|
|
79
81
|
"ts-jest": "^27.0.5",
|
|
80
82
|
"typescript": "^4",
|
|
81
|
-
"webpack": "^5.
|
|
82
|
-
"webpack-chain": "^6.5.1"
|
|
83
|
-
"jest": "^27",
|
|
84
|
-
"@scripts/jest-config": "0.0.0"
|
|
85
|
-
},
|
|
86
|
-
"modernConfig": {
|
|
87
|
-
"output": {
|
|
88
|
-
"packageMode": "node-js"
|
|
89
|
-
}
|
|
83
|
+
"webpack": "^5.71.0",
|
|
84
|
+
"webpack-chain": "^6.5.1"
|
|
90
85
|
},
|
|
91
86
|
"sideEffects": false,
|
|
92
87
|
"publishConfig": {
|
|
93
88
|
"registry": "https://registry.npmjs.org/",
|
|
94
|
-
"access": "public"
|
|
95
|
-
"types": "./dist/types/index.d.ts"
|
|
89
|
+
"access": "public"
|
|
96
90
|
},
|
|
97
91
|
"scripts": {
|
|
98
92
|
"new": "modern new",
|
package/tests/compiler.ts
CHANGED
|
@@ -12,7 +12,6 @@ global.setImmediate = setTimeout;
|
|
|
12
12
|
global.clearImmediate = clearTimeout;
|
|
13
13
|
|
|
14
14
|
export const compiler = (fixture: string, options: APILoaderOptions) => {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
16
15
|
const compiler = webpack({
|
|
17
16
|
context: __dirname,
|
|
18
17
|
entry: fixture,
|
package/dist/js/modern/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@modern-js/core';
|
package/dist/js/node/types.js
DELETED