@modern-js/plugin-bff 1.3.6 → 1.3.8

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