@modern-js/plugin-koa 2.27.0 → 2.28.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,16 @@
1
1
  # @modern-js/plugin-koa
2
2
 
3
+ ## 2.28.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4e3ce96]
8
+ - Updated dependencies [00b58a7]
9
+ - @modern-js/types@2.28.0
10
+ - @modern-js/utils@2.28.0
11
+ - @modern-js/bff-core@2.28.0
12
+ - @modern-js/bff-runtime@2.28.0
13
+
3
14
  ## 2.27.0
4
15
 
5
16
  ### Patch Changes
@@ -37,100 +37,96 @@ const initMiddlewares = (middleware, app) => {
37
37
  app.use(middlewareFunc);
38
38
  });
39
39
  };
40
- const _default = () => {
41
- return {
42
- name: "@modern-js/plugin-koa",
43
- pre: [
44
- "@modern-js/plugin-bff"
45
- ],
46
- post: [
47
- "@modern-js/plugin-server"
48
- ],
49
- setup: (api) => {
50
- return {
51
- async prepareApiServer({ pwd, config, render }) {
52
- var _userConfig_bff;
53
- let app;
54
- const router = new _koarouter.default();
55
- const apiDir = _path.join(pwd, "./api");
56
- const appContext = api.useAppContext();
57
- const apiHandlerInfos = appContext.apiHandlerInfos;
58
- const mode = appContext.apiMode;
59
- const userConfig = api.useConfigContext();
60
- if (mode === "framework") {
61
- app = await findAppModule(apiDir);
62
- if (!(app instanceof _koa.default)) {
63
- app = new _koa.default();
64
- app.use((0, _koabody.default)({
65
- multipart: true
66
- }));
67
- }
68
- if (config) {
69
- const { middleware } = config;
70
- initMiddlewares(middleware, app);
71
- }
72
- app.use(_context.run);
73
- (0, _registerRoutes.default)(router, apiHandlerInfos);
74
- } else if (mode === "function") {
75
- app = new _koa.default();
76
- app.use((0, _koabody.default)({
77
- multipart: true
78
- }));
79
- if (config) {
80
- const { middleware } = config;
81
- initMiddlewares(middleware, app);
82
- }
83
- app.use(_context.run);
84
- (0, _registerRoutes.default)(router, apiHandlerInfos);
85
- } else {
86
- throw new Error(`mode must be function or framework`);
87
- }
88
- app.use(router.routes());
89
- if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
90
- app.use(async (ctx, next) => {
91
- const html = await render(ctx.req, ctx.res);
92
- if (html) {
93
- ctx.body = html;
94
- }
95
- await next();
96
- });
97
- }
98
- return (req, res) => {
99
- return Promise.resolve(app.callback()(req, res));
100
- };
101
- },
102
- prepareWebServer({ config }, next) {
103
- var _userConfig_server;
104
- const userConfig = api.useConfigContext();
105
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
106
- return next();
40
+ const _default = () => ({
41
+ name: "@modern-js/plugin-koa",
42
+ pre: [
43
+ "@modern-js/plugin-bff"
44
+ ],
45
+ post: [
46
+ "@modern-js/plugin-server"
47
+ ],
48
+ setup: (api) => ({
49
+ async prepareApiServer({ pwd, config, render }) {
50
+ var _userConfig_bff;
51
+ let app;
52
+ const router = new _koarouter.default();
53
+ const apiDir = _path.join(pwd, "./api");
54
+ const appContext = api.useAppContext();
55
+ const apiHandlerInfos = appContext.apiHandlerInfos;
56
+ const mode = appContext.apiMode;
57
+ const userConfig = api.useConfigContext();
58
+ if (mode === "framework") {
59
+ app = await findAppModule(apiDir);
60
+ if (!(app instanceof _koa.default)) {
61
+ app = new _koa.default();
62
+ app.use((0, _koabody.default)({
63
+ multipart: true
64
+ }));
65
+ }
66
+ if (config) {
67
+ const { middleware } = config;
68
+ initMiddlewares(middleware, app);
69
+ }
70
+ app.use(_context.run);
71
+ (0, _registerRoutes.default)(router, apiHandlerInfos);
72
+ } else if (mode === "function") {
73
+ app = new _koa.default();
74
+ app.use((0, _koabody.default)({
75
+ multipart: true
76
+ }));
77
+ if (config) {
78
+ const { middleware } = config;
79
+ initMiddlewares(middleware, app);
80
+ }
81
+ app.use(_context.run);
82
+ (0, _registerRoutes.default)(router, apiHandlerInfos);
83
+ } else {
84
+ throw new Error(`mode must be function or framework`);
85
+ }
86
+ app.use(router.routes());
87
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
88
+ app.use(async (ctx, next) => {
89
+ const html = await render(ctx.req, ctx.res);
90
+ if (html) {
91
+ ctx.body = html;
107
92
  }
108
- const app = new _koa.default();
109
- app.use(async (ctx, next2) => {
110
- await next2();
111
- if (!ctx.body) {
112
- if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
113
- ctx.res.statusCode = 200;
114
- }
115
- ctx.respond = false;
116
- }
117
- });
118
- app.use((0, _koabody.default)());
119
- if (config) {
120
- const { middleware } = config;
121
- initMiddlewares(middleware, app);
93
+ await next();
94
+ });
95
+ }
96
+ return (req, res) => {
97
+ return Promise.resolve(app.callback()(req, res));
98
+ };
99
+ },
100
+ prepareWebServer({ config }, next) {
101
+ var _userConfig_server, _userConfig;
102
+ const userConfig = api.useConfigContext();
103
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
104
+ return next();
105
+ }
106
+ const app = new _koa.default();
107
+ app.use(async (ctx, next2) => {
108
+ await next2();
109
+ if (!ctx.body) {
110
+ if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
111
+ ctx.res.statusCode = 200;
122
112
  }
123
- return (ctx) => {
124
- const { source: { req, res } } = ctx;
125
- app.on("error", (err) => {
126
- if (err) {
127
- throw err;
128
- }
129
- });
130
- return Promise.resolve(app.callback()(req, res));
131
- };
113
+ ctx.respond = false;
132
114
  }
115
+ });
116
+ app.use((0, _koabody.default)());
117
+ if (config) {
118
+ const { middleware } = config;
119
+ initMiddlewares(middleware, app);
120
+ }
121
+ return (ctx) => {
122
+ const { source: { req, res } } = ctx;
123
+ app.on("error", (err) => {
124
+ if (err) {
125
+ throw err;
126
+ }
127
+ });
128
+ return Promise.resolve(app.callback()(req, res));
133
129
  };
134
130
  }
135
- };
136
- };
131
+ })
132
+ });
@@ -216,9 +216,9 @@ export default function() {
216
216
  },
217
217
  prepareWebServer: function prepareWebServer(param, next) {
218
218
  var config = param.config;
219
- var _userConfig_server;
219
+ var _userConfig_server, _userConfig;
220
220
  var userConfig = api.useConfigContext();
221
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
221
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
222
222
  return next();
223
223
  }
224
224
  var app = new Koa();
@@ -25,100 +25,96 @@ const initMiddlewares = (middleware, app) => {
25
25
  app.use(middlewareFunc);
26
26
  });
27
27
  };
28
- export default () => {
29
- return {
30
- name: "@modern-js/plugin-koa",
31
- pre: [
32
- "@modern-js/plugin-bff"
33
- ],
34
- post: [
35
- "@modern-js/plugin-server"
36
- ],
37
- setup: (api) => {
38
- return {
39
- async prepareApiServer({ pwd, config, render }) {
40
- var _userConfig_bff;
41
- let app;
42
- const router = new Router();
43
- const apiDir = path.join(pwd, "./api");
44
- const appContext = api.useAppContext();
45
- const apiHandlerInfos = appContext.apiHandlerInfos;
46
- const mode = appContext.apiMode;
47
- const userConfig = api.useConfigContext();
48
- if (mode === "framework") {
49
- app = await findAppModule(apiDir);
50
- if (!(app instanceof Koa)) {
51
- app = new Koa();
52
- app.use(koaBody({
53
- multipart: true
54
- }));
55
- }
56
- if (config) {
57
- const { middleware } = config;
58
- initMiddlewares(middleware, app);
59
- }
60
- app.use(run);
61
- registerRoutes(router, apiHandlerInfos);
62
- } else if (mode === "function") {
63
- app = new Koa();
64
- app.use(koaBody({
65
- multipart: true
66
- }));
67
- if (config) {
68
- const { middleware } = config;
69
- initMiddlewares(middleware, app);
70
- }
71
- app.use(run);
72
- registerRoutes(router, apiHandlerInfos);
73
- } else {
74
- throw new Error(`mode must be function or framework`);
75
- }
76
- app.use(router.routes());
77
- if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
78
- app.use(async (ctx, next) => {
79
- const html = await render(ctx.req, ctx.res);
80
- if (html) {
81
- ctx.body = html;
82
- }
83
- await next();
84
- });
85
- }
86
- return (req, res) => {
87
- return Promise.resolve(app.callback()(req, res));
88
- };
89
- },
90
- prepareWebServer({ config }, next) {
91
- var _userConfig_server;
92
- const userConfig = api.useConfigContext();
93
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
94
- return next();
28
+ export default () => ({
29
+ name: "@modern-js/plugin-koa",
30
+ pre: [
31
+ "@modern-js/plugin-bff"
32
+ ],
33
+ post: [
34
+ "@modern-js/plugin-server"
35
+ ],
36
+ setup: (api) => ({
37
+ async prepareApiServer({ pwd, config, render }) {
38
+ var _userConfig_bff;
39
+ let app;
40
+ const router = new Router();
41
+ const apiDir = path.join(pwd, "./api");
42
+ const appContext = api.useAppContext();
43
+ const apiHandlerInfos = appContext.apiHandlerInfos;
44
+ const mode = appContext.apiMode;
45
+ const userConfig = api.useConfigContext();
46
+ if (mode === "framework") {
47
+ app = await findAppModule(apiDir);
48
+ if (!(app instanceof Koa)) {
49
+ app = new Koa();
50
+ app.use(koaBody({
51
+ multipart: true
52
+ }));
53
+ }
54
+ if (config) {
55
+ const { middleware } = config;
56
+ initMiddlewares(middleware, app);
57
+ }
58
+ app.use(run);
59
+ registerRoutes(router, apiHandlerInfos);
60
+ } else if (mode === "function") {
61
+ app = new Koa();
62
+ app.use(koaBody({
63
+ multipart: true
64
+ }));
65
+ if (config) {
66
+ const { middleware } = config;
67
+ initMiddlewares(middleware, app);
68
+ }
69
+ app.use(run);
70
+ registerRoutes(router, apiHandlerInfos);
71
+ } else {
72
+ throw new Error(`mode must be function or framework`);
73
+ }
74
+ app.use(router.routes());
75
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
76
+ app.use(async (ctx, next) => {
77
+ const html = await render(ctx.req, ctx.res);
78
+ if (html) {
79
+ ctx.body = html;
95
80
  }
96
- const app = new Koa();
97
- app.use(async (ctx, next2) => {
98
- await next2();
99
- if (!ctx.body) {
100
- if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
101
- ctx.res.statusCode = 200;
102
- }
103
- ctx.respond = false;
104
- }
105
- });
106
- app.use(koaBody());
107
- if (config) {
108
- const { middleware } = config;
109
- initMiddlewares(middleware, app);
81
+ await next();
82
+ });
83
+ }
84
+ return (req, res) => {
85
+ return Promise.resolve(app.callback()(req, res));
86
+ };
87
+ },
88
+ prepareWebServer({ config }, next) {
89
+ var _userConfig_server, _userConfig;
90
+ const userConfig = api.useConfigContext();
91
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
92
+ return next();
93
+ }
94
+ const app = new Koa();
95
+ app.use(async (ctx, next2) => {
96
+ await next2();
97
+ if (!ctx.body) {
98
+ if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
99
+ ctx.res.statusCode = 200;
110
100
  }
111
- return (ctx) => {
112
- const { source: { req, res } } = ctx;
113
- app.on("error", (err) => {
114
- if (err) {
115
- throw err;
116
- }
117
- });
118
- return Promise.resolve(app.callback()(req, res));
119
- };
101
+ ctx.respond = false;
120
102
  }
103
+ });
104
+ app.use(koaBody());
105
+ if (config) {
106
+ const { middleware } = config;
107
+ initMiddlewares(middleware, app);
108
+ }
109
+ return (ctx) => {
110
+ const { source: { req, res } } = ctx;
111
+ app.on("error", (err) => {
112
+ if (err) {
113
+ throw err;
114
+ }
115
+ });
116
+ return Promise.resolve(app.callback()(req, res));
121
117
  };
122
118
  }
123
- };
124
- };
119
+ })
120
+ });
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.27.0",
18
+ "version": "2.28.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -67,10 +67,10 @@
67
67
  "koa-router": "^10.0.0",
68
68
  "type-is": "^1.6.18",
69
69
  "@swc/helpers": "0.5.1",
70
- "@modern-js/bff-core": "2.27.0",
71
- "@modern-js/bff-runtime": "2.27.0",
72
- "@modern-js/utils": "2.27.0",
73
- "@modern-js/types": "2.27.0"
70
+ "@modern-js/bff-core": "2.28.0",
71
+ "@modern-js/bff-runtime": "2.28.0",
72
+ "@modern-js/utils": "2.28.0",
73
+ "@modern-js/types": "2.28.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/jest": "^29",
@@ -84,11 +84,11 @@
84
84
  "supertest": "^6.1.6",
85
85
  "typescript": "^5",
86
86
  "zod": "^3.17.3",
87
- "@modern-js/core": "2.27.0",
88
- "@modern-js/server-core": "2.27.0",
89
- "@modern-js/app-tools": "2.27.0",
90
- "@scripts/build": "2.27.0",
91
- "@scripts/jest-config": "2.27.0"
87
+ "@modern-js/core": "2.28.0",
88
+ "@modern-js/server-core": "2.28.0",
89
+ "@modern-js/app-tools": "2.28.0",
90
+ "@scripts/jest-config": "2.28.0",
91
+ "@scripts/build": "2.28.0"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "koa": "^2.13.3"