@modern-js/plugin-express 2.8.0 → 2.10.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,34 @@
1
1
  # @modern-js/plugin-express
2
2
 
3
+ ## 2.10.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 3e0bd50: feat: when enable bff handle render, support use `useContext` to get framework plugin context in data loader.
8
+ feat: 当开启 BFF 托管渲染时,支持在 data loader 中使用 `useContext` 获取框架插件提供的上下文。
9
+ - 0da32d0: chore: upgrade jest and puppeteer
10
+ chore: 升级 jest 和 puppeteer 到 latest
11
+ - Updated dependencies [3e0bd50]
12
+ - Updated dependencies [92d247f]
13
+ - Updated dependencies [0da32d0]
14
+ - Updated dependencies [0d9962b]
15
+ - Updated dependencies [fbefa7e]
16
+ - Updated dependencies [4d54233]
17
+ - Updated dependencies [6db4864]
18
+ - @modern-js/types@2.10.0
19
+ - @modern-js/bff-runtime@2.10.0
20
+ - @modern-js/bff-core@2.10.0
21
+ - @modern-js/utils@2.10.0
22
+
23
+ ## 2.9.0
24
+
25
+ ### Patch Changes
26
+
27
+ - @modern-js/bff-core@2.9.0
28
+ - @modern-js/bff-runtime@2.9.0
29
+ - @modern-js/types@2.9.0
30
+ - @modern-js/utils@2.9.0
31
+
3
32
  ## 2.8.0
4
33
 
5
34
  ### Patch Changes
@@ -87,13 +87,15 @@ var plugin_default = () => ({
87
87
  "@modern-js/plugin-server"
88
88
  ],
89
89
  setup: (api) => ({
90
- async prepareApiServer({ pwd, config }) {
90
+ async prepareApiServer({ pwd, config, render }) {
91
+ var _a;
91
92
  let app;
92
93
  const appContext = api.useAppContext();
93
94
  const apiHandlerInfos = appContext.apiHandlerInfos;
94
95
  const apiDirectory = appContext.apiDirectory;
95
96
  const apiDir = apiDirectory || path.join(pwd, "./api");
96
97
  const mode = appContext.apiMode;
98
+ const userConfig = api.useConfigContext();
97
99
  if (mode === "framework") {
98
100
  const appModule = await findAppModule(apiDir);
99
101
  app = appModule[0];
@@ -126,6 +128,15 @@ var plugin_default = () => ({
126
128
  } else {
127
129
  throw new Error(`mode must be function or framework`);
128
130
  }
131
+ if (((_a = userConfig.bff) == null ? void 0 : _a.enableHandleWeb) && render) {
132
+ app.use(async (req, res, next) => {
133
+ const html = await render(req, res);
134
+ if (html) {
135
+ res.end(html);
136
+ }
137
+ next();
138
+ });
139
+ }
129
140
  return (req, res) => new Promise((resolve, reject) => {
130
141
  const handler = (err) => {
131
142
  if (err) {
@@ -255,9 +255,9 @@ var plugin_default = function() {
255
255
  setup: function(api) {
256
256
  return {
257
257
  prepareApiServer: function prepareApiServer(param) {
258
- var pwd = param.pwd, config = param.config;
258
+ var pwd = param.pwd, config = param.config, render = param.render;
259
259
  return _asyncToGenerator(function() {
260
- var app, appContext, apiHandlerInfos, apiDirectory, apiDir, mode, appModule, hooks, middleware, afterLambdaRegisted, middleware1;
260
+ var _userConfig_bff, app, appContext, apiHandlerInfos, apiDirectory, apiDir, mode, userConfig, appModule, hooks, middleware, afterLambdaRegisted, middleware1;
261
261
  return __generator(this, function(_state) {
262
262
  switch(_state.label){
263
263
  case 0:
@@ -266,6 +266,7 @@ var plugin_default = function() {
266
266
  apiDirectory = appContext.apiDirectory;
267
267
  apiDir = apiDirectory || path.join(pwd, "./api");
268
268
  mode = appContext.apiMode;
269
+ userConfig = api.useConfigContext();
269
270
  if (!(mode === "framework")) return [
270
271
  3,
271
272
  2
@@ -313,6 +314,34 @@ var plugin_default = function() {
313
314
  }
314
315
  _state.label = 3;
315
316
  case 3:
317
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
318
+ app.use(function() {
319
+ var _ref = _asyncToGenerator(function(req, res, next) {
320
+ var html;
321
+ return __generator(this, function(_state) {
322
+ switch(_state.label){
323
+ case 0:
324
+ return [
325
+ 4,
326
+ render(req, res)
327
+ ];
328
+ case 1:
329
+ html = _state.sent();
330
+ if (html) {
331
+ res.end(html);
332
+ }
333
+ next();
334
+ return [
335
+ 2
336
+ ];
337
+ }
338
+ });
339
+ });
340
+ return function(req, res, next) {
341
+ return _ref.apply(this, arguments);
342
+ };
343
+ }());
344
+ }
316
345
  return [
317
346
  2,
318
347
  function(req, res) {
@@ -55,13 +55,15 @@ var plugin_default = () => ({
55
55
  "@modern-js/plugin-server"
56
56
  ],
57
57
  setup: (api) => ({
58
- async prepareApiServer({ pwd, config }) {
58
+ async prepareApiServer({ pwd, config, render }) {
59
+ var _a;
59
60
  let app;
60
61
  const appContext = api.useAppContext();
61
62
  const apiHandlerInfos = appContext.apiHandlerInfos;
62
63
  const apiDirectory = appContext.apiDirectory;
63
64
  const apiDir = apiDirectory || path.join(pwd, "./api");
64
65
  const mode = appContext.apiMode;
66
+ const userConfig = api.useConfigContext();
65
67
  if (mode === "framework") {
66
68
  const appModule = await findAppModule(apiDir);
67
69
  app = appModule[0];
@@ -94,6 +96,15 @@ var plugin_default = () => ({
94
96
  } else {
95
97
  throw new Error(`mode must be function or framework`);
96
98
  }
99
+ if (((_a = userConfig.bff) == null ? void 0 : _a.enableHandleWeb) && render) {
100
+ app.use(async (req, res, next) => {
101
+ const html = await render(req, res);
102
+ if (html) {
103
+ res.end(html);
104
+ }
105
+ next();
106
+ });
107
+ }
97
108
  return (req, res) => new Promise((resolve, reject) => {
98
109
  const handler = (err) => {
99
110
  if (err) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.8.0",
14
+ "version": "2.10.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/cli/index.d.ts",
17
17
  "main": "./dist/cjs/cli/index.js",
@@ -42,30 +42,30 @@
42
42
  "formidable": "^1.2.2",
43
43
  "reflect-metadata": "^0.1.13",
44
44
  "type-is": "^1.6.18",
45
- "@modern-js/bff-core": "2.8.0",
46
- "@modern-js/bff-runtime": "2.8.0",
47
- "@modern-js/types": "2.8.0",
48
- "@modern-js/utils": "2.8.0"
45
+ "@modern-js/bff-core": "2.10.0",
46
+ "@modern-js/bff-runtime": "2.10.0",
47
+ "@modern-js/types": "2.10.0",
48
+ "@modern-js/utils": "2.10.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/cookie-parser": "^1.4.2",
52
52
  "@types/express": "^4.17.13",
53
53
  "@types/finalhandler": "^1.1.1",
54
54
  "@types/formidable": "^1.2.3",
55
- "@types/jest": "^27",
55
+ "@types/jest": "^29",
56
56
  "@types/node": "^14",
57
57
  "@types/supertest": "^2.0.11",
58
58
  "@types/type-is": "^1.6.3",
59
59
  "express": "^4.17.1",
60
- "jest": "^27",
60
+ "jest": "^29",
61
61
  "supertest": "^6.1.6",
62
62
  "typescript": "^4",
63
63
  "zod": "^3.17.3",
64
- "@modern-js/core": "2.8.0",
65
- "@modern-js/app-tools": "2.8.0",
66
- "@modern-js/server-core": "2.8.0",
67
- "@scripts/build": "2.8.0",
68
- "@scripts/jest-config": "2.8.0"
64
+ "@modern-js/core": "2.10.0",
65
+ "@modern-js/app-tools": "2.10.0",
66
+ "@modern-js/server-core": "2.10.0",
67
+ "@scripts/jest-config": "2.10.0",
68
+ "@scripts/build": "2.10.0"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "express": "^4.17.1"