@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 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
@@ -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 createPlugin(() => ({
12
- validateSchema() {
13
- return PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
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
- 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
- });
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
- 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
- }
50
+ };
51
+ },
71
52
 
72
- const apiServerRoutes = prefixList.map(pre => ({
73
- urlPath: pre,
74
- isApi: true,
75
- entryPath: '',
76
- isSPA: false,
77
- isSSR: false // FIXME: })) as IAppContext[`serverRoutes`];
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
- return {
81
- routes: routes.concat(apiServerRoutes)
82
- };
83
- },
63
+ if (Array.isArray(prefix)) {
64
+ prefixList.push(...prefix);
65
+ } else {
66
+ prefixList.push(prefix);
67
+ }
84
68
 
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
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
- 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);
76
+ }));
77
+ return {
78
+ routes: routes.concat(apiServerRoutes)
79
+ };
80
+ },
109
81
 
110
- if (await fs.pathExists(rootDir)) {
111
- await fs.copy(rootDir, distDir, {
112
- filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
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
- if (result.code === 1) {
117
- throw new Error(result.message);
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
- name: '@modern-js/plugin-bff'
123
- });
116
+ })
117
+ }));
@@ -1,2 +1 @@
1
- import "./types";
2
1
  export * from "./constants";
@@ -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
+ }));
@@ -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 = (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
- });
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
- source: {
69
- moduleScopes: [`./${_utils.API_DIR}`, /create-request/]
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
- 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
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
- if (result.code === 1) {
141
- throw new Error(result.message);
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;
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- require("./types");
8
-
9
7
  var _constants = require("./constants");
10
8
 
11
9
  Object.keys(_constants).forEach(function (key) {
@@ -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;
@@ -0,0 +1,5 @@
1
+ import type { CliPlugin } from '@modern-js/core';
2
+
3
+ declare const _default: () => CliPlugin;
4
+
5
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export declare const API_APP_NAME = "_app";
2
+ export declare const BUILD_FILES: string[];
@@ -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;
@@ -0,0 +1,5 @@
1
+ import type { ServerPlugin } from '@modern-js/server-core';
2
+
3
+ declare const _default: () => ServerPlugin;
4
+
5
+ export default _default;
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
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.7",
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.1",
61
- "@modern-js/utils": "^1.3.4",
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
- "@modern-js/plugin-analyze": "^1.3.3",
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.54.0",
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,
@@ -1 +0,0 @@
1
- import '@modern-js/core';
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- require("@modern-js/core");
package/types.d.ts DELETED
@@ -1,10 +0,0 @@
1
- declare module '@modern-js/core' {
2
- interface UserConfig {
3
- bff?: Partial<{
4
- prefix: string;
5
- requestCreator: string;
6
- fetcher: string;
7
- proxy: Record<string, any>;
8
- }>;
9
- }
10
- }