@modern-js/plugin-koa 1.21.2 → 2.0.0-beta.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 +31 -0
- package/dist/js/modern/cli/index.js +4 -2
- package/dist/js/modern/plugin.js +22 -7
- package/dist/js/node/cli/index.js +4 -2
- package/dist/js/node/plugin.js +22 -7
- package/package.json +12 -33
- package/types.d.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @modern-js/plugin-koa
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 8d24bed25: fix: compat Hook API in /server namespace
|
|
12
|
+
fix: 在 @modern-js/runtime/server 命名空间下兼容 Hook API
|
|
13
|
+
- 3bbea92b2: feat: support Hook、Middleware new API
|
|
14
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
15
|
+
- Updated dependencies [a2509bf]
|
|
16
|
+
- Updated dependencies [edd1cfb1a]
|
|
17
|
+
- Updated dependencies [cc971eabf]
|
|
18
|
+
- Updated dependencies [5b9049f]
|
|
19
|
+
- Updated dependencies [6bda14ed7]
|
|
20
|
+
- Updated dependencies [b8bbe036c]
|
|
21
|
+
- Updated dependencies [d5a31df78]
|
|
22
|
+
- Updated dependencies [dda38c9]
|
|
23
|
+
- Updated dependencies [102d32e4b]
|
|
24
|
+
- Updated dependencies [8b8e1bb57]
|
|
25
|
+
- Updated dependencies [3bbea92b2]
|
|
26
|
+
- Updated dependencies [abf3421]
|
|
27
|
+
- Updated dependencies [543be95]
|
|
28
|
+
- Updated dependencies [14b712d]
|
|
29
|
+
- @modern-js/bff-core@2.0.0-beta.0
|
|
30
|
+
- @modern-js/utils@2.0.0-beta.0
|
|
31
|
+
- @modern-js/types@2.0.0-beta.0
|
|
32
|
+
- @modern-js/bff-runtime@2.0.0-beta.0
|
|
33
|
+
|
|
3
34
|
## 1.21.2
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -23,7 +23,8 @@ export default (() => ({
|
|
|
23
23
|
return {
|
|
24
24
|
source: {
|
|
25
25
|
alias: {
|
|
26
|
-
'@modern-js/runtime/server': relativeRuntimePath
|
|
26
|
+
'@modern-js/runtime/server': relativeRuntimePath,
|
|
27
|
+
'@modern-js/runtime/koa': relativeRuntimePath
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
};
|
|
@@ -31,7 +32,8 @@ export default (() => ({
|
|
|
31
32
|
return {
|
|
32
33
|
source: {
|
|
33
34
|
alias: {
|
|
34
|
-
'@modern-js/runtime/server': serverRuntimePath
|
|
35
|
+
'@modern-js/runtime/server': serverRuntimePath,
|
|
36
|
+
'@modern-js/runtime/koa': serverRuntimePath
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
};
|
package/dist/js/modern/plugin.js
CHANGED
|
@@ -31,6 +31,7 @@ const initMiddlewares = (middleware, app) => {
|
|
|
31
31
|
export default (() => ({
|
|
32
32
|
name: '@modern-js/plugin-koa',
|
|
33
33
|
pre: ['@modern-js/plugin-bff'],
|
|
34
|
+
post: ['@modern-js/plugin-server'],
|
|
34
35
|
setup: api => ({
|
|
35
36
|
async prepareApiServer({
|
|
36
37
|
pwd,
|
|
@@ -89,7 +90,15 @@ export default (() => ({
|
|
|
89
90
|
|
|
90
91
|
prepareWebServer({
|
|
91
92
|
config
|
|
92
|
-
}) {
|
|
93
|
+
}, next) {
|
|
94
|
+
var _userConfig$server;
|
|
95
|
+
|
|
96
|
+
const userConfig = api.useConfigContext();
|
|
97
|
+
|
|
98
|
+
if (userConfig !== null && userConfig !== void 0 && (_userConfig$server = userConfig.server) !== null && _userConfig$server !== void 0 && _userConfig$server.disableFrameworkExt) {
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
|
|
93
102
|
const app = new Koa();
|
|
94
103
|
app.use(async (ctx, next) => {
|
|
95
104
|
await next();
|
|
@@ -112,12 +121,18 @@ export default (() => ({
|
|
|
112
121
|
initMiddlewares(middleware, app);
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
return ctx => {
|
|
125
|
+
const {
|
|
126
|
+
source: {
|
|
127
|
+
req,
|
|
128
|
+
res
|
|
129
|
+
}
|
|
130
|
+
} = ctx;
|
|
131
|
+
app.on('error', err => {
|
|
132
|
+
if (err) {
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
121
136
|
return Promise.resolve(app.callback()(req, res));
|
|
122
137
|
};
|
|
123
138
|
}
|
|
@@ -37,7 +37,8 @@ var _default = () => ({
|
|
|
37
37
|
return {
|
|
38
38
|
source: {
|
|
39
39
|
alias: {
|
|
40
|
-
'@modern-js/runtime/server': relativeRuntimePath
|
|
40
|
+
'@modern-js/runtime/server': relativeRuntimePath,
|
|
41
|
+
'@modern-js/runtime/koa': relativeRuntimePath
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
};
|
|
@@ -45,7 +46,8 @@ var _default = () => ({
|
|
|
45
46
|
return {
|
|
46
47
|
source: {
|
|
47
48
|
alias: {
|
|
48
|
-
'@modern-js/runtime/server': serverRuntimePath
|
|
49
|
+
'@modern-js/runtime/server': serverRuntimePath,
|
|
50
|
+
'@modern-js/runtime/koa': serverRuntimePath
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
};
|
package/dist/js/node/plugin.js
CHANGED
|
@@ -50,6 +50,7 @@ const initMiddlewares = (middleware, app) => {
|
|
|
50
50
|
var _default = () => ({
|
|
51
51
|
name: '@modern-js/plugin-koa',
|
|
52
52
|
pre: ['@modern-js/plugin-bff'],
|
|
53
|
+
post: ['@modern-js/plugin-server'],
|
|
53
54
|
setup: api => ({
|
|
54
55
|
async prepareApiServer({
|
|
55
56
|
pwd,
|
|
@@ -108,7 +109,15 @@ var _default = () => ({
|
|
|
108
109
|
|
|
109
110
|
prepareWebServer({
|
|
110
111
|
config
|
|
111
|
-
}) {
|
|
112
|
+
}, next) {
|
|
113
|
+
var _userConfig$server;
|
|
114
|
+
|
|
115
|
+
const userConfig = api.useConfigContext();
|
|
116
|
+
|
|
117
|
+
if (userConfig !== null && userConfig !== void 0 && (_userConfig$server = userConfig.server) !== null && _userConfig$server !== void 0 && _userConfig$server.disableFrameworkExt) {
|
|
118
|
+
return next();
|
|
119
|
+
}
|
|
120
|
+
|
|
112
121
|
const app = new _koa.default();
|
|
113
122
|
app.use(async (ctx, next) => {
|
|
114
123
|
await next();
|
|
@@ -131,12 +140,18 @@ var _default = () => ({
|
|
|
131
140
|
initMiddlewares(middleware, app);
|
|
132
141
|
}
|
|
133
142
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
return ctx => {
|
|
144
|
+
const {
|
|
145
|
+
source: {
|
|
146
|
+
req,
|
|
147
|
+
res
|
|
148
|
+
}
|
|
149
|
+
} = ctx;
|
|
150
|
+
app.on('error', err => {
|
|
151
|
+
if (err) {
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
140
155
|
return Promise.resolve(app.callback()(req, res));
|
|
141
156
|
};
|
|
142
157
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "2.0.0-beta.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -34,18 +34,19 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.18.0",
|
|
37
|
-
"@modern-js/bff-core": "
|
|
38
|
-
"@modern-js/bff-runtime": "
|
|
39
|
-
"@modern-js/utils": "
|
|
37
|
+
"@modern-js/bff-core": "2.0.0-beta.0",
|
|
38
|
+
"@modern-js/bff-runtime": "2.0.0-beta.0",
|
|
39
|
+
"@modern-js/utils": "2.0.0-beta.0",
|
|
40
|
+
"@modern-js/types": "2.0.0-beta.0",
|
|
40
41
|
"koa-body": "^4.2.0",
|
|
41
42
|
"koa-router": "^10.0.0",
|
|
42
43
|
"type-is": "^1.6.18"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@modern-js/core": "
|
|
46
|
-
"@modern-js/server-core": "
|
|
47
|
-
"@scripts/build": "
|
|
48
|
-
"@scripts/jest-config": "
|
|
46
|
+
"@modern-js/core": "2.0.0-beta.0",
|
|
47
|
+
"@modern-js/server-core": "2.0.0-beta.0",
|
|
48
|
+
"@scripts/build": "2.0.0-beta.0",
|
|
49
|
+
"@scripts/jest-config": "2.0.0-beta.0",
|
|
49
50
|
"@types/jest": "^27",
|
|
50
51
|
"@types/koa": "^2.13.4",
|
|
51
52
|
"@types/koa-router": "^7.4.4",
|
|
@@ -70,32 +71,10 @@
|
|
|
70
71
|
"registry": "https://registry.npmjs.org/",
|
|
71
72
|
"access": "public"
|
|
72
73
|
},
|
|
73
|
-
"wireit": {
|
|
74
|
-
"build": {
|
|
75
|
-
"command": "modern build",
|
|
76
|
-
"files": [
|
|
77
|
-
"src/**/*",
|
|
78
|
-
"tsconfig.json",
|
|
79
|
-
"package.json"
|
|
80
|
-
],
|
|
81
|
-
"output": [
|
|
82
|
-
"dist/**/*"
|
|
83
|
-
]
|
|
84
|
-
},
|
|
85
|
-
"test": {
|
|
86
|
-
"command": "jest --passWithNoTests",
|
|
87
|
-
"files": [
|
|
88
|
-
"src/**/*",
|
|
89
|
-
"tsconfig.json",
|
|
90
|
-
"package.json",
|
|
91
|
-
"tests/**/*"
|
|
92
|
-
],
|
|
93
|
-
"output": []
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
74
|
"scripts": {
|
|
97
75
|
"new": "modern new",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
76
|
+
"dev": "modern build --watch",
|
|
77
|
+
"build": "modern build",
|
|
78
|
+
"test": "jest --passWithNoTests"
|
|
100
79
|
}
|
|
101
80
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
/// <reference path="./dist/types/index.d.ts" />
|
|
2
|
+
declare module '@modern-js/runtime/koa' {
|
|
3
|
+
|
|
4
|
+
import { Context, Middleware } from 'koa';
|
|
5
|
+
|
|
6
|
+
export type { Middleware as RequestHandler };
|
|
7
|
+
|
|
8
|
+
export function useContext(): Context;
|
|
9
|
+
|
|
10
|
+
export * from '@modern-js/bff-core';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Todo: remove on next version
|
|
2
14
|
declare module '@modern-js/runtime/server' {
|
|
3
15
|
|
|
4
16
|
import { Context, Middleware } from 'koa';
|
|
17
|
+
import type { AfterMatchContext, AfterRenderContext, NextFunction } from '@modern-js/types';
|
|
18
|
+
|
|
19
|
+
export type AfterRenderHook = (
|
|
20
|
+
context: AfterRenderContext,
|
|
21
|
+
next: NextFunction,
|
|
22
|
+
) => void;
|
|
23
|
+
|
|
24
|
+
export type AfterMatchHook = (
|
|
25
|
+
context: AfterMatchContext,
|
|
26
|
+
next: NextFunction,
|
|
27
|
+
) => void;
|
|
28
|
+
|
|
5
29
|
|
|
6
30
|
type KoaOptions = {
|
|
7
31
|
addMiddleware: (...input: Middleware[]) => void;
|
|
32
|
+
afterRender: (hook: AfterRenderHook) => void;
|
|
33
|
+
afterMatch: (hook: AfterMatchHook) => void;
|
|
8
34
|
};
|
|
9
35
|
|
|
10
36
|
type KoaAttacher = (options: KoaOptions) => void;
|
|
11
37
|
|
|
38
|
+
export type { Middleware as RequestHandler };
|
|
39
|
+
|
|
12
40
|
export function useContext(): Context;
|
|
13
41
|
|
|
14
42
|
export function hook(attacher: KoaAttacher): KoaAttacher;
|