@modern-js/plugin-bff 2.48.6 → 2.49.1

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.
@@ -54,9 +54,11 @@ var server_default = () => ({
54
54
  const storage = new Storage();
55
55
  const transformAPI = createTransformAPI(storage);
56
56
  let apiAppPath = "";
57
+ let apiRouter;
57
58
  return {
58
59
  prepare() {
59
- const { appDirectory, distDirectory } = api.useAppContext();
60
+ const appContext = api.useAppContext();
61
+ const { appDirectory, distDirectory } = appContext;
60
62
  const root = (0, import_utils.isProd)() ? distDirectory : appDirectory;
61
63
  const apiPath = import_path.default.resolve(root || process.cwd(), import_utils.API_DIR);
62
64
  apiAppPath = import_path.default.resolve(apiPath, import_constants.API_APP_NAME);
@@ -64,25 +66,40 @@ var server_default = () => ({
64
66
  if (apiMod && typeof apiMod === "function") {
65
67
  apiMod(transformAPI);
66
68
  }
69
+ const { middlewares } = storage;
70
+ api.setAppContext({
71
+ ...appContext,
72
+ apiMiddlewares: middlewares
73
+ });
67
74
  },
68
75
  reset() {
69
76
  storage.reset();
77
+ const appContext = api.useAppContext();
70
78
  const newApiModule = (0, import_utils.requireExistModule)(apiAppPath);
71
79
  if (newApiModule && typeof newApiModule === "function") {
72
80
  newApiModule(transformAPI);
73
81
  }
82
+ const { middlewares } = storage;
83
+ api.setAppContext({
84
+ ...appContext,
85
+ apiMiddlewares: middlewares
86
+ });
74
87
  },
75
- gather({ addAPIMiddleware }) {
76
- storage.middlewares.forEach((mid) => {
77
- addAPIMiddleware(mid);
88
+ onApiChange(changes) {
89
+ const apiHandlerInfos = apiRouter.getApiHandlers();
90
+ const appContext = api.useAppContext();
91
+ api.setAppContext({
92
+ ...appContext,
93
+ apiHandlerInfos
78
94
  });
95
+ return changes;
79
96
  },
80
97
  prepareApiServer(props, next) {
81
98
  const { pwd, prefix, httpMethodDecider } = props;
82
99
  const apiDir = import_path.default.resolve(pwd, import_utils.API_DIR);
83
100
  const appContext = api.useAppContext();
84
101
  const { apiDirectory, lambdaDirectory } = appContext;
85
- const apiRouter = new import_bff_core.ApiRouter({
102
+ apiRouter = new import_bff_core.ApiRouter({
86
103
  appDir: pwd,
87
104
  apiDir: apiDirectory || apiDir,
88
105
  lambdaDir: lambdaDirectory,
@@ -31,9 +31,11 @@ function server_default() {
31
31
  var storage = new Storage();
32
32
  var transformAPI = createTransformAPI(storage);
33
33
  var apiAppPath = "";
34
+ var apiRouter;
34
35
  return {
35
36
  prepare: function prepare() {
36
- var _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
37
+ var appContext = api.useAppContext();
38
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
37
39
  var root = isProd() ? distDirectory : appDirectory;
38
40
  var apiPath = path.resolve(root || process.cwd(), API_DIR);
39
41
  apiAppPath = path.resolve(apiPath, API_APP_NAME);
@@ -41,26 +43,37 @@ function server_default() {
41
43
  if (apiMod && typeof apiMod === "function") {
42
44
  apiMod(transformAPI);
43
45
  }
46
+ var middlewares = storage.middlewares;
47
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
48
+ apiMiddlewares: middlewares
49
+ }));
44
50
  },
45
51
  reset: function reset() {
46
52
  storage.reset();
53
+ var appContext = api.useAppContext();
47
54
  var newApiModule = requireExistModule(apiAppPath);
48
55
  if (newApiModule && typeof newApiModule === "function") {
49
56
  newApiModule(transformAPI);
50
57
  }
58
+ var middlewares = storage.middlewares;
59
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
60
+ apiMiddlewares: middlewares
61
+ }));
51
62
  },
52
- gather: function gather(param) {
53
- var addAPIMiddleware = param.addAPIMiddleware;
54
- storage.middlewares.forEach(function(mid) {
55
- addAPIMiddleware(mid);
56
- });
63
+ onApiChange: function onApiChange(changes) {
64
+ var apiHandlerInfos = apiRouter.getApiHandlers();
65
+ var appContext = api.useAppContext();
66
+ api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
67
+ apiHandlerInfos
68
+ }));
69
+ return changes;
57
70
  },
58
71
  prepareApiServer: function prepareApiServer(props, next) {
59
72
  var pwd = props.pwd, prefix = props.prefix, httpMethodDecider = props.httpMethodDecider;
60
73
  var apiDir = path.resolve(pwd, API_DIR);
61
74
  var appContext = api.useAppContext();
62
75
  var apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory;
63
- var apiRouter = new ApiRouter({
76
+ apiRouter = new ApiRouter({
64
77
  appDir: pwd,
65
78
  apiDir: apiDirectory || apiDir,
66
79
  lambdaDir: lambdaDirectory,
@@ -21,9 +21,11 @@ var server_default = () => ({
21
21
  const storage = new Storage();
22
22
  const transformAPI = createTransformAPI(storage);
23
23
  let apiAppPath = "";
24
+ let apiRouter;
24
25
  return {
25
26
  prepare() {
26
- const { appDirectory, distDirectory } = api.useAppContext();
27
+ const appContext = api.useAppContext();
28
+ const { appDirectory, distDirectory } = appContext;
27
29
  const root = isProd() ? distDirectory : appDirectory;
28
30
  const apiPath = path.resolve(root || process.cwd(), API_DIR);
29
31
  apiAppPath = path.resolve(apiPath, API_APP_NAME);
@@ -31,25 +33,40 @@ var server_default = () => ({
31
33
  if (apiMod && typeof apiMod === "function") {
32
34
  apiMod(transformAPI);
33
35
  }
36
+ const { middlewares } = storage;
37
+ api.setAppContext({
38
+ ...appContext,
39
+ apiMiddlewares: middlewares
40
+ });
34
41
  },
35
42
  reset() {
36
43
  storage.reset();
44
+ const appContext = api.useAppContext();
37
45
  const newApiModule = requireExistModule(apiAppPath);
38
46
  if (newApiModule && typeof newApiModule === "function") {
39
47
  newApiModule(transformAPI);
40
48
  }
49
+ const { middlewares } = storage;
50
+ api.setAppContext({
51
+ ...appContext,
52
+ apiMiddlewares: middlewares
53
+ });
41
54
  },
42
- gather({ addAPIMiddleware }) {
43
- storage.middlewares.forEach((mid) => {
44
- addAPIMiddleware(mid);
55
+ onApiChange(changes) {
56
+ const apiHandlerInfos = apiRouter.getApiHandlers();
57
+ const appContext = api.useAppContext();
58
+ api.setAppContext({
59
+ ...appContext,
60
+ apiHandlerInfos
45
61
  });
62
+ return changes;
46
63
  },
47
64
  prepareApiServer(props, next) {
48
65
  const { pwd, prefix, httpMethodDecider } = props;
49
66
  const apiDir = path.resolve(pwd, API_DIR);
50
67
  const appContext = api.useAppContext();
51
68
  const { apiDirectory, lambdaDirectory } = appContext;
52
- const apiRouter = new ApiRouter({
69
+ apiRouter = new ApiRouter({
53
70
  appDir: pwd,
54
71
  apiDir: apiDirectory || apiDir,
55
72
  lambdaDir: lambdaDirectory,
@@ -1,3 +1,3 @@
1
- import type { ServerPlugin } from '@modern-js/server-core';
1
+ import { type ServerPlugin } from '@modern-js/server-core';
2
2
  declare const _default: () => ServerPlugin;
3
3
  export default _default;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.48.6",
18
+ "version": "2.49.1",
19
19
  "jsnext:source": "./src/cli.ts",
20
20
  "types": "./dist/types/cli.d.ts",
21
21
  "main": "./dist/cjs/cli.js",
@@ -57,13 +57,13 @@
57
57
  "dependencies": {
58
58
  "@babel/core": "^7.23.2",
59
59
  "@swc/helpers": "0.5.3",
60
- "@modern-js/bff-core": "2.48.6",
61
- "@modern-js/create-request": "2.48.6",
62
- "@modern-js/server-utils": "2.48.6",
63
- "@modern-js/utils": "2.48.6"
60
+ "@modern-js/bff-core": "2.49.1",
61
+ "@modern-js/create-request": "2.49.1",
62
+ "@modern-js/server-utils": "2.49.1",
63
+ "@modern-js/utils": "2.49.1"
64
64
  },
65
65
  "devDependencies": {
66
- "@rsbuild/shared": "0.6.1",
66
+ "@rsbuild/shared": "0.6.6",
67
67
  "@types/babel__core": "^7.20.1",
68
68
  "@types/jest": "^29",
69
69
  "@types/node": "^14",
@@ -72,14 +72,14 @@
72
72
  "ts-jest": "^29.1.0",
73
73
  "typescript": "^5",
74
74
  "webpack": "^5.91.0",
75
- "@modern-js/runtime": "2.48.6",
76
- "@modern-js/core": "2.48.6",
77
- "@modern-js/bff-runtime": "2.48.6",
78
- "@modern-js/server-core": "2.48.6",
79
- "@modern-js/types": "2.48.6",
80
- "@modern-js/app-tools": "2.48.6",
81
- "@scripts/build": "2.48.6",
82
- "@scripts/jest-config": "2.48.6"
75
+ "@modern-js/runtime": "2.49.1",
76
+ "@modern-js/core": "2.49.1",
77
+ "@modern-js/bff-runtime": "2.49.1",
78
+ "@modern-js/types": "2.49.1",
79
+ "@modern-js/app-tools": "2.49.1",
80
+ "@modern-js/server-core": "2.49.1",
81
+ "@scripts/build": "2.49.1",
82
+ "@scripts/jest-config": "2.49.1"
83
83
  },
84
84
  "sideEffects": false,
85
85
  "publishConfig": {