@modern-js/plugin-bff 0.0.0-next-20230226140607 → 0.0.0-next-20230227084544

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,6 +1,11 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
- ## 0.0.0-next-20230226140607
3
+ ## 0.0.0-next-20230227084544
4
+
5
+ ### Minor Changes
6
+
7
+ - 84bfb439b: feat: support custom apiDir, lambdaDir and style of writing for bff
8
+ feat: 支持定制 api 目录,lambda 目录,bff 的写法
4
9
 
5
10
  ### Patch Changes
6
11
 
@@ -11,10 +16,11 @@
11
16
  - Updated dependencies [dcad88702]
12
17
  - Updated dependencies [7fff9020e]
13
18
  - Updated dependencies [1eea234fd]
14
- - @modern-js/utils@0.0.0-next-20230226140607
15
- - @modern-js/bff-core@0.0.0-next-20230226140607
16
- - @modern-js/server-utils@0.0.0-next-20230226140607
17
- - @modern-js/create-request@0.0.0-next-20230226140607
19
+ - Updated dependencies [84bfb439b]
20
+ - @modern-js/utils@0.0.0-next-20230227084544
21
+ - @modern-js/bff-core@0.0.0-next-20230227084544
22
+ - @modern-js/server-utils@0.0.0-next-20230227084544
23
+ - @modern-js/create-request@0.0.0-next-20230227084544
18
24
 
19
25
  ## 2.6.0
20
26
 
package/dist/cjs/cli.js CHANGED
@@ -49,29 +49,32 @@ var cli_default = () => ({
49
49
  return {
50
50
  tools: {
51
51
  webpackChain: (chain, { name, CHAIN_ID }) => {
52
- const { appDirectory, port } = api.useAppContext();
52
+ const { port, apiDirectory, lambdaDirectory } = api.useAppContext();
53
53
  const modernConfig = api.useResolvedConfigContext();
54
54
  const { bff } = modernConfig || {};
55
55
  const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
56
- const rootDir = import_path.default.resolve(appDirectory, import_utils.API_DIR);
57
- chain.resolve.alias.set("@api", rootDir);
56
+ const httpMethodDecider = bff == null ? void 0 : bff.httpMethodDecider;
57
+ chain.resolve.alias.set("@api", apiDirectory);
58
58
  const apiRouter = new import_bff_core.ApiRouter({
59
- apiDir: rootDir,
60
- prefix
59
+ apiDir: apiDirectory,
60
+ lambdaDir: lambdaDirectory,
61
+ prefix,
62
+ httpMethodDecider
61
63
  });
62
64
  const lambdaDir = apiRouter.getLambdaDir();
63
65
  const existLambda = apiRouter.isExistLambda();
64
66
  const apiRegexp = new RegExp(
65
- (0, import_utils.normalizeOutputPath)(`${rootDir}${import_path.default.sep}.*(.[tj]s)$`)
67
+ (0, import_utils.normalizeOutputPath)(`${apiDirectory}${import_path.default.sep}.*(.[tj]s)$`)
66
68
  );
67
69
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
68
70
  chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
69
71
  prefix,
70
- apiDir: rootDir,
72
+ apiDir: apiDirectory,
71
73
  lambdaDir,
72
74
  existLambda,
73
75
  port,
74
- target: name
76
+ target: name,
77
+ httpMethodDecider
75
78
  });
76
79
  }
77
80
  },
@@ -96,7 +99,6 @@ var cli_default = () => ({
96
99
  entryPath: "",
97
100
  isSPA: false,
98
101
  isSSR: false
99
- // FIXME: })) as IAppContext[`serverRoutes`];
100
102
  }));
101
103
  if (bff == null ? void 0 : bff.enableHandleWeb) {
102
104
  return {
@@ -126,11 +128,11 @@ var cli_default = () => ({
126
128
  if (unRegisterResolveRuntimePath) {
127
129
  unRegisterResolveRuntimePath();
128
130
  }
129
- const { appDirectory, distDirectory } = api.useAppContext();
131
+ const { appDirectory, distDirectory, apiDirectory, sharedDirectory } = api.useAppContext();
130
132
  const modernConfig = api.useResolvedConfigContext();
131
133
  const distDir = import_path.default.resolve(distDirectory);
132
- const apiDir = import_path.default.resolve(appDirectory, import_utils.API_DIR);
133
- const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
134
+ const apiDir = apiDirectory || import_path.default.resolve(appDirectory, import_utils.API_DIR);
135
+ const sharedDir = sharedDirectory || import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
134
136
  const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
135
137
  const sourceDirs = [];
136
138
  if (import_utils.fs.existsSync(apiDir)) {
@@ -36,10 +36,12 @@ async function loader(source) {
36
36
  const options = {
37
37
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
38
38
  apiDir: draftOptions.apiDir,
39
+ lambdaDir: draftOptions.lambdaDir,
39
40
  target: draftOptions.target,
40
41
  port: Number(draftOptions.port),
41
42
  source,
42
- resourcePath
43
+ resourcePath,
44
+ httpMethodDecider: draftOptions.httpMethodDecider
43
45
  };
44
46
  const { lambdaDir } = draftOptions;
45
47
  if (!resourcePath.startsWith(lambdaDir)) {
@@ -77,12 +77,15 @@ var server_default = () => ({
77
77
  });
78
78
  },
79
79
  prepareApiServer(props, next) {
80
- const { pwd, prefix } = props;
80
+ const { pwd, prefix, httpMethodDecider } = props;
81
81
  const apiDir = import_path.default.resolve(pwd, import_utils.API_DIR);
82
82
  const appContext = api.useAppContext();
83
+ const { apiDirectory, lambdaDirectory } = appContext;
83
84
  const apiRouter = new import_bff_core.ApiRouter({
84
- apiDir,
85
- prefix
85
+ apiDir: apiDirectory || apiDir,
86
+ lambdaDir: lambdaDirectory,
87
+ prefix,
88
+ httpMethodDecider
86
89
  });
87
90
  const apiMode = apiRouter.getApiMode();
88
91
  const apiHandlerInfos = apiRouter.getApiHandlers();
package/dist/esm/cli.js CHANGED
@@ -220,27 +220,30 @@ var cli_default = function() {
220
220
  tools: {
221
221
  webpackChain: function(chain, param) {
222
222
  var name = param.name, CHAIN_ID = param.CHAIN_ID;
223
- var _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, port = _api_useAppContext.port;
223
+ var _api_useAppContext = api.useAppContext(), port = _api_useAppContext.port, apiDirectory = _api_useAppContext.apiDirectory, lambdaDirectory = _api_useAppContext.lambdaDirectory;
224
224
  var modernConfig = api.useResolvedConfigContext();
225
225
  var bff = (modernConfig || {}).bff;
226
226
  var prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
227
- var rootDir = path.resolve(appDirectory, API_DIR);
228
- chain.resolve.alias.set("@api", rootDir);
227
+ var httpMethodDecider = bff === null || bff === void 0 ? void 0 : bff.httpMethodDecider;
228
+ chain.resolve.alias.set("@api", apiDirectory);
229
229
  var apiRouter = new ApiRouter({
230
- apiDir: rootDir,
231
- prefix: prefix
230
+ apiDir: apiDirectory,
231
+ lambdaDir: lambdaDirectory,
232
+ prefix: prefix,
233
+ httpMethodDecider: httpMethodDecider
232
234
  });
233
235
  var lambdaDir = apiRouter.getLambdaDir();
234
236
  var existLambda = apiRouter.isExistLambda();
235
- var apiRegexp = new RegExp(normalizeOutputPath("".concat(rootDir).concat(path.sep, ".*(.[tj]s)$")));
237
+ var apiRegexp = new RegExp(normalizeOutputPath("".concat(apiDirectory).concat(path.sep, ".*(.[tj]s)$")));
236
238
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
237
239
  chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
238
240
  prefix: prefix,
239
- apiDir: rootDir,
241
+ apiDir: apiDirectory,
240
242
  lambdaDir: lambdaDir,
241
243
  existLambda: existLambda,
242
244
  port: port,
243
- target: name
245
+ target: name,
246
+ httpMethodDecider: httpMethodDecider
244
247
  });
245
248
  }
246
249
  },
@@ -311,18 +314,18 @@ var cli_default = function() {
311
314
  },
312
315
  afterBuild: function afterBuild() {
313
316
  return _asyncToGenerator(function() {
314
- var _api_useAppContext, appDirectory, distDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig_source, alias, define, globalVars, babel;
317
+ var _api_useAppContext, appDirectory, distDirectory, apiDirectory, sharedDirectory, modernConfig, distDir, apiDir, sharedDir, tsconfigPath, sourceDirs, server, _modernConfig_source, alias, define, globalVars, babel;
315
318
  return __generator(this, function(_state) {
316
319
  switch(_state.label){
317
320
  case 0:
318
321
  if (unRegisterResolveRuntimePath) {
319
322
  unRegisterResolveRuntimePath();
320
323
  }
321
- _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
324
+ _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory;
322
325
  modernConfig = api.useResolvedConfigContext();
323
326
  distDir = path.resolve(distDirectory);
324
- apiDir = path.resolve(appDirectory, API_DIR);
325
- sharedDir = path.resolve(appDirectory, SHARED_DIR);
327
+ apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
328
+ sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
326
329
  tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
327
330
  sourceDirs = [];
328
331
  if (fs.existsSync(apiDir)) {
@@ -148,10 +148,12 @@ function _loader() {
148
148
  options = {
149
149
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
150
150
  apiDir: draftOptions.apiDir,
151
+ lambdaDir: draftOptions.lambdaDir,
151
152
  target: draftOptions.target,
152
153
  port: Number(draftOptions.port),
153
154
  source: source,
154
- resourcePath: resourcePath
155
+ resourcePath: resourcePath,
156
+ httpMethodDecider: draftOptions.httpMethodDecider
155
157
  };
156
158
  lambdaDir = draftOptions.lambdaDir;
157
159
  if (!resourcePath.startsWith(lambdaDir)) {
@@ -128,12 +128,15 @@ var server_default = function() {
128
128
  });
129
129
  },
130
130
  prepareApiServer: function prepareApiServer(props, next) {
131
- var pwd = props.pwd, prefix = props.prefix;
131
+ var pwd = props.pwd, prefix = props.prefix, httpMethodDecider = props.httpMethodDecider;
132
132
  var apiDir = path.resolve(pwd, API_DIR);
133
133
  var appContext = api.useAppContext();
134
+ var apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory;
134
135
  var apiRouter = new ApiRouter({
135
- apiDir: apiDir,
136
- prefix: prefix
136
+ apiDir: apiDirectory || apiDir,
137
+ lambdaDir: lambdaDirectory,
138
+ prefix: prefix,
139
+ httpMethodDecider: httpMethodDecider
137
140
  });
138
141
  var apiMode = apiRouter.getApiMode();
139
142
  var apiHandlerInfos = apiRouter.getApiHandlers();
@@ -24,29 +24,32 @@ var cli_default = () => ({
24
24
  return {
25
25
  tools: {
26
26
  webpackChain: (chain, { name, CHAIN_ID }) => {
27
- const { appDirectory, port } = api.useAppContext();
27
+ const { port, apiDirectory, lambdaDirectory } = api.useAppContext();
28
28
  const modernConfig = api.useResolvedConfigContext();
29
29
  const { bff } = modernConfig || {};
30
30
  const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
31
- const rootDir = path.resolve(appDirectory, API_DIR);
32
- chain.resolve.alias.set("@api", rootDir);
31
+ const httpMethodDecider = bff == null ? void 0 : bff.httpMethodDecider;
32
+ chain.resolve.alias.set("@api", apiDirectory);
33
33
  const apiRouter = new ApiRouter({
34
- apiDir: rootDir,
35
- prefix
34
+ apiDir: apiDirectory,
35
+ lambdaDir: lambdaDirectory,
36
+ prefix,
37
+ httpMethodDecider
36
38
  });
37
39
  const lambdaDir = apiRouter.getLambdaDir();
38
40
  const existLambda = apiRouter.isExistLambda();
39
41
  const apiRegexp = new RegExp(
40
- normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`)
42
+ normalizeOutputPath(`${apiDirectory}${path.sep}.*(.[tj]s)$`)
41
43
  );
42
44
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
43
45
  chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
44
46
  prefix,
45
- apiDir: rootDir,
47
+ apiDir: apiDirectory,
46
48
  lambdaDir,
47
49
  existLambda,
48
50
  port,
49
- target: name
51
+ target: name,
52
+ httpMethodDecider
50
53
  });
51
54
  }
52
55
  },
@@ -71,7 +74,6 @@ var cli_default = () => ({
71
74
  entryPath: "",
72
75
  isSPA: false,
73
76
  isSSR: false
74
- // FIXME: })) as IAppContext[`serverRoutes`];
75
77
  }));
76
78
  if (bff == null ? void 0 : bff.enableHandleWeb) {
77
79
  return {
@@ -101,11 +103,11 @@ var cli_default = () => ({
101
103
  if (unRegisterResolveRuntimePath) {
102
104
  unRegisterResolveRuntimePath();
103
105
  }
104
- const { appDirectory, distDirectory } = api.useAppContext();
106
+ const { appDirectory, distDirectory, apiDirectory, sharedDirectory } = api.useAppContext();
105
107
  const modernConfig = api.useResolvedConfigContext();
106
108
  const distDir = path.resolve(distDirectory);
107
- const apiDir = path.resolve(appDirectory, API_DIR);
108
- const sharedDir = path.resolve(appDirectory, SHARED_DIR);
109
+ const apiDir = apiDirectory || path.resolve(appDirectory, API_DIR);
110
+ const sharedDir = sharedDirectory || path.resolve(appDirectory, SHARED_DIR);
109
111
  const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
110
112
  const sourceDirs = [];
111
113
  if (fs.existsSync(apiDir)) {
@@ -14,10 +14,12 @@ async function loader(source) {
14
14
  const options = {
15
15
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
16
16
  apiDir: draftOptions.apiDir,
17
+ lambdaDir: draftOptions.lambdaDir,
17
18
  target: draftOptions.target,
18
19
  port: Number(draftOptions.port),
19
20
  source,
20
- resourcePath
21
+ resourcePath,
22
+ httpMethodDecider: draftOptions.httpMethodDecider
21
23
  };
22
24
  const { lambdaDir } = draftOptions;
23
25
  if (!resourcePath.startsWith(lambdaDir)) {
@@ -45,12 +45,15 @@ var server_default = () => ({
45
45
  });
46
46
  },
47
47
  prepareApiServer(props, next) {
48
- const { pwd, prefix } = props;
48
+ const { pwd, prefix, httpMethodDecider } = props;
49
49
  const apiDir = path.resolve(pwd, API_DIR);
50
50
  const appContext = api.useAppContext();
51
+ const { apiDirectory, lambdaDirectory } = appContext;
51
52
  const apiRouter = new ApiRouter({
52
- apiDir,
53
- prefix
53
+ apiDir: apiDirectory || apiDir,
54
+ lambdaDir: lambdaDirectory,
55
+ prefix,
56
+ httpMethodDecider
54
57
  });
55
58
  const apiMode = apiRouter.getApiMode();
56
59
  const apiHandlerInfos = apiRouter.getApiHandlers();
@@ -1,3 +1,4 @@
1
+ import type { HttpMethodDecider } from '@modern-js/types';
1
2
  import type { LoaderContext } from 'webpack';
2
3
  export type APILoaderOptions = {
3
4
  prefix: string;
@@ -8,6 +9,7 @@ export type APILoaderOptions = {
8
9
  fetcher?: string;
9
10
  requestCreator?: string;
10
11
  target: string;
12
+ httpMethodDecider?: HttpMethodDecider;
11
13
  };
12
14
  declare function loader(this: LoaderContext<APILoaderOptions>, source: string): Promise<void>;
13
15
  export default loader;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "0.0.0-next-20230226140607",
14
+ "version": "0.0.0-next-20230227084544",
15
15
  "jsnext:source": "./src/cli.ts",
16
16
  "types": "./dist/types/cli.d.ts",
17
17
  "main": "./dist/cjs/cli.js",
@@ -50,10 +50,10 @@
50
50
  "dependencies": {
51
51
  "@babel/core": "^7.18.0",
52
52
  "@babel/runtime": "^7.18.0",
53
- "@modern-js/bff-core": "0.0.0-next-20230226140607",
54
- "@modern-js/create-request": "0.0.0-next-20230226140607",
55
- "@modern-js/server-utils": "0.0.0-next-20230226140607",
56
- "@modern-js/utils": "0.0.0-next-20230226140607"
53
+ "@modern-js/bff-core": "0.0.0-next-20230227084544",
54
+ "@modern-js/create-request": "0.0.0-next-20230227084544",
55
+ "@modern-js/server-utils": "0.0.0-next-20230227084544",
56
+ "@modern-js/utils": "0.0.0-next-20230227084544"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/babel__core": "^7.1.15",
@@ -65,14 +65,14 @@
65
65
  "typescript": "^4",
66
66
  "webpack": "^5.75.0",
67
67
  "webpack-chain": "^6.5.1",
68
- "@modern-js/runtime": "0.0.0-next-20230226140607",
69
- "@modern-js/bff-runtime": "0.0.0-next-20230226140607",
70
- "@modern-js/core": "0.0.0-next-20230226140607",
71
- "@modern-js/server-core": "0.0.0-next-20230226140607",
72
- "@modern-js/types": "0.0.0-next-20230226140607",
73
- "@modern-js/app-tools": "0.0.0-next-20230226140607",
74
- "@scripts/build": "0.0.0-next-20230226140607",
75
- "@scripts/jest-config": "0.0.0-next-20230226140607"
68
+ "@modern-js/runtime": "0.0.0-next-20230227084544",
69
+ "@modern-js/core": "0.0.0-next-20230227084544",
70
+ "@modern-js/bff-runtime": "0.0.0-next-20230227084544",
71
+ "@modern-js/server-core": "0.0.0-next-20230227084544",
72
+ "@modern-js/types": "0.0.0-next-20230227084544",
73
+ "@modern-js/app-tools": "0.0.0-next-20230227084544",
74
+ "@scripts/build": "0.0.0-next-20230227084544",
75
+ "@scripts/jest-config": "0.0.0-next-20230227084544"
76
76
  },
77
77
  "sideEffects": false,
78
78
  "publishConfig": {