@modern-js/plugin-bff 1.15.1-beta.0 → 1.17.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
+ ## 1.17.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [1b9176f]
8
+ - Updated dependencies [77d3a38]
9
+ - Updated dependencies [151329d]
10
+ - Updated dependencies [5af9472]
11
+ - Updated dependencies [6b6a534]
12
+ - Updated dependencies [6b43a2b]
13
+ - Updated dependencies [a7be124]
14
+ - Updated dependencies [31547b4]
15
+ - @modern-js/utils@1.17.0
16
+ - @modern-js/bff-core@1.17.0
17
+ - @modern-js/create-request@1.17.0
18
+ - @modern-js/server-utils@1.17.0
19
+ - @modern-js/babel-compiler@1.17.0
20
+
21
+ ## 1.16.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 020b9bd52: feat: support frame mode without lambda directories
26
+ feat: 支持无 lambda 目录的框架模式
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [641592f52]
31
+ - Updated dependencies [3904b30a5]
32
+ - Updated dependencies [1100dd58c]
33
+ - Updated dependencies [e04e6e76a]
34
+ - Updated dependencies [81c66e4a4]
35
+ - Updated dependencies [2c305b6f5]
36
+ - Updated dependencies [020b9bd52]
37
+ - @modern-js/utils@1.16.0
38
+ - @modern-js/create-request@1.16.0
39
+ - @modern-js/server-utils@1.16.0
40
+ - @modern-js/bff-core@1.16.0
41
+ - @modern-js/babel-compiler@1.16.0
42
+
3
43
  ## 1.15.0
4
44
 
5
45
  ### Patch Changes
@@ -1,48 +1,50 @@
1
1
  import path from 'path';
2
+ import { compiler } from '@modern-js/babel-compiler';
2
3
  import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
3
- import { compile } from '@modern-js/server-utils';
4
+ import { resolveBabelConfig } from '@modern-js/server-utils';
5
+ import { ApiRouter } from '@modern-js/bff-core';
4
6
  import { registerModernRuntimePath } from "./helper";
5
7
  const DEFAULT_API_PREFIX = '/api';
6
8
  const TS_CONFIG_FILENAME = 'tsconfig.json';
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
- // };
9
+ const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
10
+
11
+ const compile = async (appDirectory, modernConfig, compileOptions) => {
12
+ const {
13
+ patterns
14
+ } = compileOptions;
15
+ const results = await Promise.all(patterns.map(async pattern => {
16
+ const {
17
+ from,
18
+ to,
19
+ tsconfigPath
20
+ } = pattern;
21
+ const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
22
+ tsconfigPath: tsconfigPath ? tsconfigPath : '',
23
+ syntax: 'es6+',
24
+ type: 'commonjs'
25
+ });
26
+
27
+ if (await fs.pathExists(from)) {
28
+ const basename = path.basename(from);
29
+ const targetDir = path.join(to, basename);
30
+ await fs.copy(from, targetDir, {
31
+ filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
32
+ });
33
+ }
34
+
35
+ return compiler({
36
+ rootDir: appDirectory,
37
+ distDir: to,
38
+ sourceDir: from,
39
+ extensions: FILE_EXTENSIONS
40
+ }, babelConfig);
41
+ }));
42
+ results.forEach(result => {
43
+ if (result.code === 1) {
44
+ throw new Error(result.message);
45
+ }
46
+ });
47
+ };
46
48
 
47
49
  export default (() => ({
48
50
  name: '@modern-js/plugin-bff',
@@ -74,10 +76,18 @@ export default (() => ({
74
76
  const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
75
77
  const rootDir = path.resolve(appDirectory, API_DIR);
76
78
  chain.resolve.alias.set('@api', rootDir);
77
- const apiRegexp = new RegExp(normalizeOutputPath(`${appDirectory}${path.sep}api${path.sep}.*(.[tj]s)$`));
79
+ const apiRouter = new ApiRouter({
80
+ apiDir: rootDir,
81
+ prefix
82
+ });
83
+ const lambdaDir = apiRouter.getLambdaDir();
84
+ const existLambda = apiRouter.isExistLambda();
85
+ const apiRegexp = new RegExp(normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`));
78
86
  chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
79
87
  prefix,
80
88
  apiDir: rootDir,
89
+ lambdaDir,
90
+ existLambda,
81
91
  port,
82
92
  fetcher,
83
93
  target: name,
@@ -1,4 +1,5 @@
1
1
  import { generateClient } from '@modern-js/bff-core';
2
+ import { logger } from '@modern-js/utils';
2
3
 
3
4
  async function loader(source) {
4
5
  // eslint-disable-next-line @babel/no-invalid-this
@@ -6,16 +7,36 @@ async function loader(source) {
6
7
 
7
8
  const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
8
9
 
9
- const draftOptions = this.getOptions();
10
+ const draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
11
+
12
+ const {
13
+ resourcePath
14
+ } = this;
15
+ const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
16
+
17
+ if (!draftOptions.existLambda) {
18
+ logger.warn(warning);
19
+ callback(null, `throw new Error('${warning}')`);
20
+ return;
21
+ }
22
+
10
23
  const options = {
11
24
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
12
25
  apiDir: draftOptions.apiDir,
13
26
  target: draftOptions.target,
14
27
  port: Number(draftOptions.port),
15
28
  source,
16
- // eslint-disable-next-line @babel/no-invalid-this
17
- resourcePath: this.resourcePath
29
+ resourcePath
18
30
  };
31
+ const {
32
+ lambdaDir
33
+ } = draftOptions;
34
+
35
+ if (!resourcePath.startsWith(lambdaDir)) {
36
+ logger.warn(warning);
37
+ callback(null, `throw new Error('${warning}')`);
38
+ return;
39
+ }
19
40
 
20
41
  if (draftOptions.fetcher) {
21
42
  options.fetcher = draftOptions.fetcher;
@@ -7,55 +7,61 @@ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
+ var _babelCompiler = require("@modern-js/babel-compiler");
11
+
10
12
  var _utils = require("@modern-js/utils");
11
13
 
12
14
  var _serverUtils = require("@modern-js/server-utils");
13
15
 
16
+ var _bffCore = require("@modern-js/bff-core");
17
+
14
18
  var _helper = require("./helper");
15
19
 
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  const DEFAULT_API_PREFIX = '/api';
19
23
  const TS_CONFIG_FILENAME = 'tsconfig.json';
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
- // };
24
+ const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
25
+
26
+ const compile = async (appDirectory, modernConfig, compileOptions) => {
27
+ const {
28
+ patterns
29
+ } = compileOptions;
30
+ const results = await Promise.all(patterns.map(async pattern => {
31
+ const {
32
+ from,
33
+ to,
34
+ tsconfigPath
35
+ } = pattern;
36
+ const babelConfig = (0, _serverUtils.resolveBabelConfig)(appDirectory, modernConfig, {
37
+ tsconfigPath: tsconfigPath ? tsconfigPath : '',
38
+ syntax: 'es6+',
39
+ type: 'commonjs'
40
+ });
41
+
42
+ if (await _utils.fs.pathExists(from)) {
43
+ const basename = _path.default.basename(from);
44
+
45
+ const targetDir = _path.default.join(to, basename);
46
+
47
+ await _utils.fs.copy(from, targetDir, {
48
+ filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
49
+ });
50
+ }
51
+
52
+ return (0, _babelCompiler.compiler)({
53
+ rootDir: appDirectory,
54
+ distDir: to,
55
+ sourceDir: from,
56
+ extensions: FILE_EXTENSIONS
57
+ }, babelConfig);
58
+ }));
59
+ results.forEach(result => {
60
+ if (result.code === 1) {
61
+ throw new Error(result.message);
62
+ }
63
+ });
64
+ };
59
65
 
60
66
  var _default = () => ({
61
67
  name: '@modern-js/plugin-bff',
@@ -89,10 +95,18 @@ var _default = () => ({
89
95
  const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
90
96
 
91
97
  chain.resolve.alias.set('@api', rootDir);
92
- const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${appDirectory}${_path.default.sep}api${_path.default.sep}.*(.[tj]s)$`));
98
+ const apiRouter = new _bffCore.ApiRouter({
99
+ apiDir: rootDir,
100
+ prefix
101
+ });
102
+ const lambdaDir = apiRouter.getLambdaDir();
103
+ const existLambda = apiRouter.isExistLambda();
104
+ const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${rootDir}${_path.default.sep}.*(.[tj]s)$`));
93
105
  chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
94
106
  prefix,
95
107
  apiDir: rootDir,
108
+ lambdaDir,
109
+ existLambda,
96
110
  port,
97
111
  fetcher,
98
112
  target: name,
@@ -183,7 +197,7 @@ var _default = () => ({
183
197
  }
184
198
 
185
199
  if (patterns.length > 0) {
186
- await (0, _serverUtils.compile)(appDirectory, modernConfig, {
200
+ await compile(appDirectory, modernConfig, {
187
201
  patterns
188
202
  });
189
203
  }
@@ -7,22 +7,46 @@ exports.default = void 0;
7
7
 
8
8
  var _bffCore = require("@modern-js/bff-core");
9
9
 
10
+ var _utils = require("@modern-js/utils");
11
+
10
12
  async function loader(source) {
11
13
  // eslint-disable-next-line @babel/no-invalid-this
12
14
  this.cacheable(); // eslint-disable-next-line @babel/no-invalid-this
13
15
 
14
16
  const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
15
17
 
16
- const draftOptions = this.getOptions();
18
+ const draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
19
+
20
+ const {
21
+ resourcePath
22
+ } = this;
23
+ const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
24
+
25
+ if (!draftOptions.existLambda) {
26
+ _utils.logger.warn(warning);
27
+
28
+ callback(null, `throw new Error('${warning}')`);
29
+ return;
30
+ }
31
+
17
32
  const options = {
18
33
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
19
34
  apiDir: draftOptions.apiDir,
20
35
  target: draftOptions.target,
21
36
  port: Number(draftOptions.port),
22
37
  source,
23
- // eslint-disable-next-line @babel/no-invalid-this
24
- resourcePath: this.resourcePath
38
+ resourcePath
25
39
  };
40
+ const {
41
+ lambdaDir
42
+ } = draftOptions;
43
+
44
+ if (!resourcePath.startsWith(lambdaDir)) {
45
+ _utils.logger.warn(warning);
46
+
47
+ callback(null, `throw new Error('${warning}')`);
48
+ return;
49
+ }
26
50
 
27
51
  if (draftOptions.fetcher) {
28
52
  options.fetcher = draftOptions.fetcher;
@@ -1,51 +1,97 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
3
  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';
5
6
  import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR, isProd } from '@modern-js/utils';
6
- import { compile } from '@modern-js/server-utils';
7
+ import { resolveBabelConfig } from '@modern-js/server-utils';
8
+ import { ApiRouter } from '@modern-js/bff-core';
7
9
  import { registerModernRuntimePath } from "./helper";
8
10
  var DEFAULT_API_PREFIX = '/api';
9
11
  var TS_CONFIG_FILENAME = 'tsconfig.json';
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
- // };
12
+ var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs']; // TODO: 封装服务端编译函数
13
+
14
+ var compile = /*#__PURE__*/function () {
15
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, modernConfig, compileOptions) {
16
+ var patterns, results;
17
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
18
+ while (1) {
19
+ switch (_context2.prev = _context2.next) {
20
+ case 0:
21
+ patterns = compileOptions.patterns;
22
+ _context2.next = 3;
23
+ return Promise.all(patterns.map( /*#__PURE__*/function () {
24
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pattern) {
25
+ var from, to, tsconfigPath, babelConfig, basename, targetDir;
26
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
27
+ while (1) {
28
+ switch (_context.prev = _context.next) {
29
+ case 0:
30
+ from = pattern.from, to = pattern.to, tsconfigPath = pattern.tsconfigPath;
31
+ babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
32
+ tsconfigPath: tsconfigPath ? tsconfigPath : '',
33
+ syntax: 'es6+',
34
+ type: 'commonjs'
35
+ });
36
+ _context.next = 4;
37
+ return fs.pathExists(from);
38
+
39
+ case 4:
40
+ if (!_context.sent) {
41
+ _context.next = 9;
42
+ break;
43
+ }
44
+
45
+ basename = path.basename(from);
46
+ targetDir = path.join(to, basename);
47
+ _context.next = 9;
48
+ return fs.copy(from, targetDir, {
49
+ filter: function filter(src) {
50
+ return !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath;
51
+ }
52
+ });
53
+
54
+ case 9:
55
+ return _context.abrupt("return", compiler({
56
+ rootDir: appDirectory,
57
+ distDir: to,
58
+ sourceDir: from,
59
+ extensions: FILE_EXTENSIONS
60
+ }, babelConfig));
61
+
62
+ case 10:
63
+ case "end":
64
+ return _context.stop();
65
+ }
66
+ }
67
+ }, _callee);
68
+ }));
69
+
70
+ return function (_x4) {
71
+ return _ref2.apply(this, arguments);
72
+ };
73
+ }()));
74
+
75
+ case 3:
76
+ results = _context2.sent;
77
+ results.forEach(function (result) {
78
+ if (result.code === 1) {
79
+ throw new Error(result.message);
80
+ }
81
+ });
82
+
83
+ case 5:
84
+ case "end":
85
+ return _context2.stop();
86
+ }
87
+ }
88
+ }, _callee2);
89
+ }));
90
+
91
+ return function compile(_x, _x2, _x3) {
92
+ return _ref.apply(this, arguments);
93
+ };
94
+ }();
49
95
 
50
96
  export default (function () {
51
97
  return {
@@ -59,9 +105,9 @@ export default (function () {
59
105
  config: function config() {
60
106
  return {
61
107
  tools: {
62
- webpackChain: function webpackChain(chain, _ref) {
63
- var name = _ref.name,
64
- CHAIN_ID = _ref.CHAIN_ID;
108
+ webpackChain: function webpackChain(chain, _ref3) {
109
+ var name = _ref3.name,
110
+ CHAIN_ID = _ref3.CHAIN_ID;
65
111
 
66
112
  var _api$useAppContext = api.useAppContext(),
67
113
  appDirectory = _api$useAppContext.appDirectory,
@@ -69,19 +115,27 @@ export default (function () {
69
115
 
70
116
  var modernConfig = api.useResolvedConfigContext();
71
117
 
72
- var _ref2 = modernConfig || {},
73
- bff = _ref2.bff;
118
+ var _ref4 = modernConfig || {},
119
+ bff = _ref4.bff;
74
120
 
75
- var _ref3 = bff || {},
76
- fetcher = _ref3.fetcher;
121
+ var _ref5 = bff || {},
122
+ fetcher = _ref5.fetcher;
77
123
 
78
124
  var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
79
125
  var rootDir = path.resolve(appDirectory, API_DIR);
80
126
  chain.resolve.alias.set('@api', rootDir);
81
- var apiRegexp = new RegExp(normalizeOutputPath("".concat(appDirectory).concat(path.sep, "api").concat(path.sep, ".*(.[tj]s)$")));
127
+ var apiRouter = new ApiRouter({
128
+ apiDir: rootDir,
129
+ prefix: prefix
130
+ });
131
+ var lambdaDir = apiRouter.getLambdaDir();
132
+ var existLambda = apiRouter.isExistLambda();
133
+ var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
82
134
  chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
83
135
  prefix: prefix,
84
136
  apiDir: rootDir,
137
+ lambdaDir: lambdaDir,
138
+ existLambda: existLambda,
85
139
  port: port,
86
140
  fetcher: fetcher,
87
141
  target: name,
@@ -94,12 +148,12 @@ export default (function () {
94
148
  }
95
149
  };
96
150
  },
97
- modifyServerRoutes: function modifyServerRoutes(_ref4) {
98
- var routes = _ref4.routes;
151
+ modifyServerRoutes: function modifyServerRoutes(_ref6) {
152
+ var routes = _ref6.routes;
99
153
  var modernConfig = api.useResolvedConfigContext();
100
154
 
101
- var _ref5 = modernConfig || {},
102
- bff = _ref5.bff;
155
+ var _ref7 = modernConfig || {},
156
+ bff = _ref7.bff;
103
157
 
104
158
  var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
105
159
  var prefixList = [];
@@ -125,12 +179,12 @@ export default (function () {
125
179
  };
126
180
  },
127
181
  beforeBuild: function beforeBuild() {
128
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
182
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
129
183
  var _api$useAppContext2, internalDirectory;
130
184
 
131
- return _regeneratorRuntime().wrap(function _callee$(_context) {
185
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
132
186
  while (1) {
133
- switch (_context.prev = _context.next) {
187
+ switch (_context3.prev = _context3.next) {
134
188
  case 0:
135
189
  // help esbuild-register resolve @modern-js/server/runtime
136
190
  if (isProd()) {
@@ -140,19 +194,19 @@ export default (function () {
140
194
 
141
195
  case 1:
142
196
  case "end":
143
- return _context.stop();
197
+ return _context3.stop();
144
198
  }
145
199
  }
146
- }, _callee);
200
+ }, _callee3);
147
201
  }))();
148
202
  },
149
203
  afterBuild: function afterBuild() {
150
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
204
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
151
205
  var _api$useAppContext3, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, patterns;
152
206
 
153
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
207
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
154
208
  while (1) {
155
- switch (_context2.prev = _context2.next) {
209
+ switch (_context4.prev = _context4.next) {
156
210
  case 0:
157
211
  if (unRegisterResolveRuntimePath) {
158
212
  unRegisterResolveRuntimePath();
@@ -183,21 +237,21 @@ export default (function () {
183
237
  }
184
238
 
185
239
  if (!(patterns.length > 0)) {
186
- _context2.next = 13;
240
+ _context4.next = 13;
187
241
  break;
188
242
  }
189
243
 
190
- _context2.next = 13;
244
+ _context4.next = 13;
191
245
  return compile(appDirectory, modernConfig, {
192
246
  patterns: patterns
193
247
  });
194
248
 
195
249
  case 13:
196
250
  case "end":
197
- return _context2.stop();
251
+ return _context4.stop();
198
252
  }
199
253
  }
200
- }, _callee2);
254
+ }, _callee4);
201
255
  }))();
202
256
  }
203
257
  };
@@ -1,6 +1,7 @@
1
1
  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
+ import { logger } from '@modern-js/utils';
4
5
 
5
6
  function loader(_x) {
6
7
  return _loader.apply(this, arguments);
@@ -8,7 +9,7 @@ function loader(_x) {
8
9
 
9
10
  function _loader() {
10
11
  _loader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
11
- var callback, draftOptions, options, result;
12
+ var callback, draftOptions, resourcePath, warning, options, lambdaDir, result;
12
13
  return _regeneratorRuntime().wrap(function _callee$(_context) {
13
14
  while (1) {
14
15
  switch (_context.prev = _context.next) {
@@ -18,17 +19,41 @@ function _loader() {
18
19
 
19
20
  callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
20
21
 
21
- draftOptions = this.getOptions();
22
+ draftOptions = this.getOptions(); // eslint-disable-next-line @babel/no-invalid-this
23
+
24
+ resourcePath = this.resourcePath;
25
+ warning = "The file ".concat(resourcePath, " is not allowd to be imported in src directory, only API definition files are allowed.");
26
+
27
+ if (draftOptions.existLambda) {
28
+ _context.next = 9;
29
+ break;
30
+ }
31
+
32
+ logger.warn(warning);
33
+ callback(null, "throw new Error('".concat(warning, "')"));
34
+ return _context.abrupt("return");
35
+
36
+ case 9:
22
37
  options = {
23
38
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
24
39
  apiDir: draftOptions.apiDir,
25
40
  target: draftOptions.target,
26
41
  port: Number(draftOptions.port),
27
42
  source: source,
28
- // eslint-disable-next-line @babel/no-invalid-this
29
- resourcePath: this.resourcePath
43
+ resourcePath: resourcePath
30
44
  };
45
+ lambdaDir = draftOptions.lambdaDir;
46
+
47
+ if (resourcePath.startsWith(lambdaDir)) {
48
+ _context.next = 15;
49
+ break;
50
+ }
31
51
 
52
+ logger.warn(warning);
53
+ callback(null, "throw new Error('".concat(warning, "')"));
54
+ return _context.abrupt("return");
55
+
56
+ case 15:
32
57
  if (draftOptions.fetcher) {
33
58
  options.fetcher = draftOptions.fetcher;
34
59
  }
@@ -38,10 +63,10 @@ function _loader() {
38
63
  }
39
64
 
40
65
  options.requireResolve = require.resolve;
41
- _context.next = 9;
66
+ _context.next = 20;
42
67
  return generateClient(options);
43
68
 
44
- case 9:
69
+ case 20:
45
70
  result = _context.sent;
46
71
 
47
72
  if (result.isOk) {
@@ -50,7 +75,7 @@ function _loader() {
50
75
  callback(undefined, "throw new Error('".concat(result.value, "')"));
51
76
  }
52
77
 
53
- case 11:
78
+ case 22:
54
79
  case "end":
55
80
  return _context.stop();
56
81
  }
@@ -2,6 +2,8 @@ import type { LoaderContext } from 'webpack';
2
2
  export declare type APILoaderOptions = {
3
3
  prefix: string;
4
4
  apiDir: string;
5
+ lambdaDir: string;
6
+ existLambda: boolean;
5
7
  port: number;
6
8
  fetcher?: string;
7
9
  requestCreator?: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.15.1-beta.0",
14
+ "version": "1.17.0",
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,20 @@
55
55
  "dependencies": {
56
56
  "@babel/core": "^7.18.0",
57
57
  "@babel/runtime": "^7.18.0",
58
- "@modern-js/babel-compiler": "1.15.0",
59
- "@modern-js/bff-core": "1.15.0",
60
- "@modern-js/create-request": "1.15.0",
61
- "@modern-js/server-utils": "1.15.1-beta.0",
62
- "@modern-js/utils": "1.15.0"
58
+ "@modern-js/babel-compiler": "1.17.0",
59
+ "@modern-js/bff-core": "1.17.0",
60
+ "@modern-js/create-request": "1.17.0",
61
+ "@modern-js/server-utils": "1.17.0",
62
+ "@modern-js/utils": "1.17.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@modern-js/core": "1.15.0",
66
- "@modern-js/bff-runtime": "1.15.0",
67
- "@modern-js/runtime": "1.15.0",
68
- "@modern-js/server-core": "1.15.0",
69
- "@modern-js/types": "1.15.0",
70
- "@scripts/build": "1.15.0",
71
- "@scripts/jest-config": "1.15.0",
65
+ "@modern-js/core": "1.17.0",
66
+ "@modern-js/bff-runtime": "1.17.0",
67
+ "@modern-js/runtime": "1.17.0",
68
+ "@modern-js/server-core": "1.17.0",
69
+ "@modern-js/types": "1.17.0",
70
+ "@scripts/build": "1.17.0",
71
+ "@scripts/jest-config": "1.17.0",
72
72
  "@types/babel__core": "^7.1.15",
73
73
  "@types/jest": "^27",
74
74
  "@types/node": "^14",
@@ -82,8 +82,7 @@
82
82
  "sideEffects": false,
83
83
  "publishConfig": {
84
84
  "registry": "https://registry.npmjs.org/",
85
- "access": "public",
86
- "types": "./dist/types/index.d.ts"
85
+ "access": "public"
87
86
  },
88
87
  "wireit": {
89
88
  "build": {