@modern-js/plugin-bff 1.15.0 → 1.15.1-beta.0

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.
@@ -1,49 +1,48 @@
1
1
  import path from 'path';
2
- import { compiler } from '@modern-js/babel-compiler';
3
2
  import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
4
- import { resolveBabelConfig } from '@modern-js/server-utils';
3
+ import { compile } from '@modern-js/server-utils';
5
4
  import { registerModernRuntimePath } from "./helper";
6
5
  const DEFAULT_API_PREFIX = '/api';
7
6
  const TS_CONFIG_FILENAME = 'tsconfig.json';
8
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
9
-
10
- const compile = async (appDirectory, modernConfig, compileOptions) => {
11
- const {
12
- patterns
13
- } = compileOptions;
14
- const results = await Promise.all(patterns.map(async pattern => {
15
- const {
16
- from,
17
- to,
18
- tsconfigPath
19
- } = pattern;
20
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
21
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
22
- syntax: 'es6+',
23
- type: 'commonjs'
24
- });
25
-
26
- if (await fs.pathExists(from)) {
27
- const basename = path.basename(from);
28
- const targetDir = path.join(to, basename);
29
- await fs.copy(from, targetDir, {
30
- filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
31
- });
32
- }
33
-
34
- return compiler({
35
- rootDir: appDirectory,
36
- distDir: to,
37
- sourceDir: from,
38
- extensions: FILE_EXTENSIONS
39
- }, babelConfig);
40
- }));
41
- results.forEach(result => {
42
- if (result.code === 1) {
43
- throw new Error(result.message);
44
- }
45
- });
46
- };
7
+ const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // const compile = async (
8
+ // appDirectory: string,
9
+ // modernConfig: NormalizedConfig,
10
+ // compileOptions: CompileOptions,
11
+ // ) => {
12
+ // const { patterns } = compileOptions;
13
+ // const results = await Promise.all(
14
+ // patterns.map(async pattern => {
15
+ // const { from, to, tsconfigPath } = pattern;
16
+ // const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
17
+ // tsconfigPath: tsconfigPath ? tsconfigPath : '',
18
+ // syntax: 'es6+',
19
+ // type: 'commonjs',
20
+ // });
21
+ // if (await fs.pathExists(from)) {
22
+ // const basename = path.basename(from);
23
+ // const targetDir = path.join(to, basename);
24
+ // await fs.copy(from, targetDir, {
25
+ // filter: src =>
26
+ // !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath,
27
+ // });
28
+ // }
29
+ // return compiler(
30
+ // {
31
+ // rootDir: appDirectory,
32
+ // distDir: to,
33
+ // sourceDir: from,
34
+ // extensions: FILE_EXTENSIONS,
35
+ // },
36
+ // babelConfig,
37
+ // );
38
+ // }),
39
+ // );
40
+ // results.forEach(result => {
41
+ // if (result.code === 1) {
42
+ // throw new Error(result.message);
43
+ // }
44
+ // });
45
+ // };
47
46
 
48
47
  export default (() => ({
49
48
  name: '@modern-js/plugin-bff',
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
- var _babelCompiler = require("@modern-js/babel-compiler");
11
-
12
10
  var _utils = require("@modern-js/utils");
13
11
 
14
12
  var _serverUtils = require("@modern-js/server-utils");
@@ -19,47 +17,45 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
17
 
20
18
  const DEFAULT_API_PREFIX = '/api';
21
19
  const TS_CONFIG_FILENAME = 'tsconfig.json';
22
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
23
-
24
- const compile = async (appDirectory, modernConfig, compileOptions) => {
25
- const {
26
- patterns
27
- } = compileOptions;
28
- const results = await Promise.all(patterns.map(async pattern => {
29
- const {
30
- from,
31
- to,
32
- tsconfigPath
33
- } = pattern;
34
- const babelConfig = (0, _serverUtils.resolveBabelConfig)(appDirectory, modernConfig, {
35
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
36
- syntax: 'es6+',
37
- type: 'commonjs'
38
- });
39
-
40
- if (await _utils.fs.pathExists(from)) {
41
- const basename = _path.default.basename(from);
42
-
43
- const targetDir = _path.default.join(to, basename);
44
-
45
- await _utils.fs.copy(from, targetDir, {
46
- filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
47
- });
48
- }
49
-
50
- return (0, _babelCompiler.compiler)({
51
- rootDir: appDirectory,
52
- distDir: to,
53
- sourceDir: from,
54
- extensions: FILE_EXTENSIONS
55
- }, babelConfig);
56
- }));
57
- results.forEach(result => {
58
- if (result.code === 1) {
59
- throw new Error(result.message);
60
- }
61
- });
62
- };
20
+ const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // const compile = async (
21
+ // appDirectory: string,
22
+ // modernConfig: NormalizedConfig,
23
+ // compileOptions: CompileOptions,
24
+ // ) => {
25
+ // const { patterns } = compileOptions;
26
+ // const results = await Promise.all(
27
+ // patterns.map(async pattern => {
28
+ // const { from, to, tsconfigPath } = pattern;
29
+ // const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
30
+ // tsconfigPath: tsconfigPath ? tsconfigPath : '',
31
+ // syntax: 'es6+',
32
+ // type: 'commonjs',
33
+ // });
34
+ // if (await fs.pathExists(from)) {
35
+ // const basename = path.basename(from);
36
+ // const targetDir = path.join(to, basename);
37
+ // await fs.copy(from, targetDir, {
38
+ // filter: src =>
39
+ // !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath,
40
+ // });
41
+ // }
42
+ // return compiler(
43
+ // {
44
+ // rootDir: appDirectory,
45
+ // distDir: to,
46
+ // sourceDir: from,
47
+ // extensions: FILE_EXTENSIONS,
48
+ // },
49
+ // babelConfig,
50
+ // );
51
+ // }),
52
+ // );
53
+ // results.forEach(result => {
54
+ // if (result.code === 1) {
55
+ // throw new Error(result.message);
56
+ // }
57
+ // });
58
+ // };
63
59
 
64
60
  var _default = () => ({
65
61
  name: '@modern-js/plugin-bff',
@@ -187,7 +183,7 @@ var _default = () => ({
187
183
  }
188
184
 
189
185
  if (patterns.length > 0) {
190
- await compile(appDirectory, modernConfig, {
186
+ await (0, _serverUtils.compile)(appDirectory, modernConfig, {
191
187
  patterns
192
188
  });
193
189
  }
@@ -1,96 +1,51 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import path from 'path';
5
- import { compiler } from '@modern-js/babel-compiler';
6
5
  import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
7
- import { resolveBabelConfig } from '@modern-js/server-utils';
6
+ import { compile } from '@modern-js/server-utils';
8
7
  import { registerModernRuntimePath } from "./helper";
9
8
  var DEFAULT_API_PREFIX = '/api';
10
9
  var TS_CONFIG_FILENAME = 'tsconfig.json';
11
- var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
12
-
13
- var compile = /*#__PURE__*/function () {
14
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, modernConfig, compileOptions) {
15
- var patterns, results;
16
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
17
- while (1) {
18
- switch (_context2.prev = _context2.next) {
19
- case 0:
20
- patterns = compileOptions.patterns;
21
- _context2.next = 3;
22
- return Promise.all(patterns.map( /*#__PURE__*/function () {
23
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pattern) {
24
- var from, to, tsconfigPath, babelConfig, basename, targetDir;
25
- return _regeneratorRuntime().wrap(function _callee$(_context) {
26
- while (1) {
27
- switch (_context.prev = _context.next) {
28
- case 0:
29
- from = pattern.from, to = pattern.to, tsconfigPath = pattern.tsconfigPath;
30
- babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
31
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
32
- syntax: 'es6+',
33
- type: 'commonjs'
34
- });
35
- _context.next = 4;
36
- return fs.pathExists(from);
37
-
38
- case 4:
39
- if (!_context.sent) {
40
- _context.next = 9;
41
- break;
42
- }
43
-
44
- basename = path.basename(from);
45
- targetDir = path.join(to, basename);
46
- _context.next = 9;
47
- return fs.copy(from, targetDir, {
48
- filter: function filter(src) {
49
- return !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath;
50
- }
51
- });
52
-
53
- case 9:
54
- return _context.abrupt("return", compiler({
55
- rootDir: appDirectory,
56
- distDir: to,
57
- sourceDir: from,
58
- extensions: FILE_EXTENSIONS
59
- }, babelConfig));
60
-
61
- case 10:
62
- case "end":
63
- return _context.stop();
64
- }
65
- }
66
- }, _callee);
67
- }));
68
-
69
- return function (_x4) {
70
- return _ref2.apply(this, arguments);
71
- };
72
- }()));
73
-
74
- case 3:
75
- results = _context2.sent;
76
- results.forEach(function (result) {
77
- if (result.code === 1) {
78
- throw new Error(result.message);
79
- }
80
- });
81
-
82
- case 5:
83
- case "end":
84
- return _context2.stop();
85
- }
86
- }
87
- }, _callee2);
88
- }));
89
-
90
- return function compile(_x, _x2, _x3) {
91
- return _ref.apply(this, arguments);
92
- };
93
- }();
10
+ var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // const compile = async (
11
+ // appDirectory: string,
12
+ // modernConfig: NormalizedConfig,
13
+ // compileOptions: CompileOptions,
14
+ // ) => {
15
+ // const { patterns } = compileOptions;
16
+ // const results = await Promise.all(
17
+ // patterns.map(async pattern => {
18
+ // const { from, to, tsconfigPath } = pattern;
19
+ // const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
20
+ // tsconfigPath: tsconfigPath ? tsconfigPath : '',
21
+ // syntax: 'es6+',
22
+ // type: 'commonjs',
23
+ // });
24
+ // if (await fs.pathExists(from)) {
25
+ // const basename = path.basename(from);
26
+ // const targetDir = path.join(to, basename);
27
+ // await fs.copy(from, targetDir, {
28
+ // filter: src =>
29
+ // !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath,
30
+ // });
31
+ // }
32
+ // return compiler(
33
+ // {
34
+ // rootDir: appDirectory,
35
+ // distDir: to,
36
+ // sourceDir: from,
37
+ // extensions: FILE_EXTENSIONS,
38
+ // },
39
+ // babelConfig,
40
+ // );
41
+ // }),
42
+ // );
43
+ // results.forEach(result => {
44
+ // if (result.code === 1) {
45
+ // throw new Error(result.message);
46
+ // }
47
+ // });
48
+ // };
94
49
 
95
50
  export default (function () {
96
51
  return {
@@ -104,9 +59,9 @@ export default (function () {
104
59
  config: function config() {
105
60
  return {
106
61
  tools: {
107
- webpackChain: function webpackChain(chain, _ref3) {
108
- var name = _ref3.name,
109
- CHAIN_ID = _ref3.CHAIN_ID;
62
+ webpackChain: function webpackChain(chain, _ref) {
63
+ var name = _ref.name,
64
+ CHAIN_ID = _ref.CHAIN_ID;
110
65
 
111
66
  var _api$useAppContext = api.useAppContext(),
112
67
  appDirectory = _api$useAppContext.appDirectory,
@@ -114,11 +69,11 @@ export default (function () {
114
69
 
115
70
  var modernConfig = api.useResolvedConfigContext();
116
71
 
117
- var _ref4 = modernConfig || {},
118
- bff = _ref4.bff;
72
+ var _ref2 = modernConfig || {},
73
+ bff = _ref2.bff;
119
74
 
120
- var _ref5 = bff || {},
121
- fetcher = _ref5.fetcher;
75
+ var _ref3 = bff || {},
76
+ fetcher = _ref3.fetcher;
122
77
 
123
78
  var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
124
79
  var rootDir = path.resolve(appDirectory, API_DIR);
@@ -139,12 +94,12 @@ export default (function () {
139
94
  }
140
95
  };
141
96
  },
142
- modifyServerRoutes: function modifyServerRoutes(_ref6) {
143
- var routes = _ref6.routes;
97
+ modifyServerRoutes: function modifyServerRoutes(_ref4) {
98
+ var routes = _ref4.routes;
144
99
  var modernConfig = api.useResolvedConfigContext();
145
100
 
146
- var _ref7 = modernConfig || {},
147
- bff = _ref7.bff;
101
+ var _ref5 = modernConfig || {},
102
+ bff = _ref5.bff;
148
103
 
149
104
  var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
150
105
  var prefixList = [];
@@ -170,12 +125,12 @@ export default (function () {
170
125
  };
171
126
  },
172
127
  beforeBuild: function beforeBuild() {
173
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
128
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
174
129
  var _api$useAppContext2, internalDirectory;
175
130
 
176
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
131
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
177
132
  while (1) {
178
- switch (_context3.prev = _context3.next) {
133
+ switch (_context.prev = _context.next) {
179
134
  case 0:
180
135
  // help esbuild-register resolve @modern-js/server/runtime
181
136
  if (isProd()) {
@@ -185,19 +140,19 @@ export default (function () {
185
140
 
186
141
  case 1:
187
142
  case "end":
188
- return _context3.stop();
143
+ return _context.stop();
189
144
  }
190
145
  }
191
- }, _callee3);
146
+ }, _callee);
192
147
  }))();
193
148
  },
194
149
  afterBuild: function afterBuild() {
195
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
150
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
196
151
  var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, patterns;
197
152
 
198
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
153
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
199
154
  while (1) {
200
- switch (_context4.prev = _context4.next) {
155
+ switch (_context2.prev = _context2.next) {
201
156
  case 0:
202
157
  if (unRegisterResolveRuntimePath) {
203
158
  unRegisterResolveRuntimePath();
@@ -228,21 +183,21 @@ export default (function () {
228
183
  }
229
184
 
230
185
  if (!(patterns.length > 0)) {
231
- _context4.next = 13;
186
+ _context2.next = 13;
232
187
  break;
233
188
  }
234
189
 
235
- _context4.next = 13;
190
+ _context2.next = 13;
236
191
  return compile(appDirectory, modernConfig, {
237
192
  patterns: patterns
238
193
  });
239
194
 
240
195
  case 13:
241
196
  case "end":
242
- return _context4.stop();
197
+ return _context2.stop();
243
198
  }
244
199
  }
245
- }, _callee4);
200
+ }, _callee2);
246
201
  }))();
247
202
  }
248
203
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.15.0",
14
+ "version": "1.15.1-beta.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -58,7 +58,7 @@
58
58
  "@modern-js/babel-compiler": "1.15.0",
59
59
  "@modern-js/bff-core": "1.15.0",
60
60
  "@modern-js/create-request": "1.15.0",
61
- "@modern-js/server-utils": "1.15.0",
61
+ "@modern-js/server-utils": "1.15.1-beta.0",
62
62
  "@modern-js/utils": "1.15.0"
63
63
  },
64
64
  "devDependencies": {
@@ -82,7 +82,8 @@
82
82
  "sideEffects": false,
83
83
  "publishConfig": {
84
84
  "registry": "https://registry.npmjs.org/",
85
- "access": "public"
85
+ "access": "public",
86
+ "types": "./dist/types/index.d.ts"
86
87
  },
87
88
  "wireit": {
88
89
  "build": {