@modern-js/types 1.1.3 → 1.2.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 +25 -0
- package/cli/index.d.ts +1 -14
- package/jest.config.js +8 -0
- package/package.json +16 -7
- package/server/context.d.ts +19 -2
- package/server/hook.d.ts +35 -0
- package/server/index.d.ts +3 -1
- package/server/route.d.ts +19 -0
- package/server/{util.d.ts → utils.d.ts} +1 -1
- package/tsconfig.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @modern-js/types
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- e2464fe5: add more server types
|
|
12
|
+
- Updated dependencies [cfe11628]
|
|
13
|
+
- @modern-js/plugin@1.2.0
|
|
14
|
+
|
|
15
|
+
## 1.1.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- e51b1db3: feat: support custom sdk, interceptor, headers for bff request
|
|
20
|
+
|
|
21
|
+
## 1.1.4
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- e04914ce: add route types, fix metrics types
|
|
26
|
+
- e04914ce: add route types, fix metrics types
|
|
27
|
+
|
|
3
28
|
## 1.1.3
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/cli/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncWaterfall, AsyncWorkflow } from '@modern-js/plugin';
|
|
2
2
|
import { Compiler, MultiCompiler, Configuration } from 'webpack';
|
|
3
|
+
import { ServerRoute } from '../server';
|
|
3
4
|
|
|
4
5
|
export type { Compiler, MultiCompiler, Configuration };
|
|
5
6
|
|
|
@@ -17,20 +18,6 @@ export interface Entrypoint {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
/**
|
|
21
|
-
* server route
|
|
22
|
-
*/
|
|
23
|
-
export interface ServerRoute {
|
|
24
|
-
urlPath: string;
|
|
25
|
-
entryName?: string;
|
|
26
|
-
entryPath: string;
|
|
27
|
-
isSPA: boolean;
|
|
28
|
-
isSSR: boolean;
|
|
29
|
-
isApi?: boolean;
|
|
30
|
-
bundle?: string;
|
|
31
|
-
enableModernMode?: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
21
|
/**
|
|
35
22
|
* file system routes.
|
|
36
23
|
*/
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -11,29 +11,38 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
15
|
-
"main": "",
|
|
14
|
+
"version": "1.2.0",
|
|
16
15
|
"types": "./index.d.ts",
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"@modern-js/plugin": "^1.
|
|
17
|
+
"@modern-js/plugin": "^1.2.0",
|
|
19
18
|
"webpack": "^5.54.0"
|
|
20
19
|
},
|
|
21
20
|
"exports": {
|
|
22
21
|
".": "./index.d.ts",
|
|
23
|
-
"./server":
|
|
22
|
+
"./server": {
|
|
23
|
+
"jsnext:source": "./server/index.d.ts",
|
|
24
|
+
"default": "./server/index.d.ts"
|
|
25
|
+
}
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/jest": "^26",
|
|
27
29
|
"@types/node": "^14",
|
|
28
30
|
"@types/react": "^17",
|
|
29
31
|
"@types/react-dom": "^17",
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
+
"@scripts/build": "0.0.0",
|
|
33
|
+
"jest": "^27",
|
|
34
|
+
"@scripts/jest-config": "0.0.0"
|
|
32
35
|
},
|
|
33
36
|
"sideEffects": false,
|
|
34
37
|
"publishConfig": {
|
|
35
38
|
"registry": "https://registry.npmjs.org/",
|
|
36
|
-
"access": "public"
|
|
39
|
+
"access": "public",
|
|
40
|
+
"main": "",
|
|
41
|
+
"types": "./index.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "jest --passWithNoTests"
|
|
37
45
|
},
|
|
46
|
+
"main": "",
|
|
38
47
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
39
48
|
}
|
package/server/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
|
|
2
2
|
import { URL } from 'url';
|
|
3
3
|
import qs from 'querystring';
|
|
4
|
-
import {
|
|
4
|
+
import { Metrics, Logger } from './utils';
|
|
5
5
|
|
|
6
6
|
export interface ModernServerContext {
|
|
7
7
|
req: IncomingMessage;
|
|
@@ -12,7 +12,7 @@ export interface ModernServerContext {
|
|
|
12
12
|
|
|
13
13
|
logger: Logger;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
metrics?: Metrics;
|
|
16
16
|
|
|
17
17
|
setParams: (params: Record<string, string>) => void;
|
|
18
18
|
|
|
@@ -44,3 +44,20 @@ export interface ModernServerContext {
|
|
|
44
44
|
|
|
45
45
|
resHasHandled: () => boolean;
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
export type BaseSSRServerContext = {
|
|
49
|
+
request: {
|
|
50
|
+
params: Record<string, string>;
|
|
51
|
+
pathname: string;
|
|
52
|
+
query: Record<string, string>;
|
|
53
|
+
headers: IncomingHttpHeaders;
|
|
54
|
+
cookie?: string;
|
|
55
|
+
};
|
|
56
|
+
redirection: { url?: string; status?: number };
|
|
57
|
+
distDir: string;
|
|
58
|
+
template: string;
|
|
59
|
+
entryName: string;
|
|
60
|
+
logger: Logger;
|
|
61
|
+
metrics?: Metrics;
|
|
62
|
+
loadableManifest?: string;
|
|
63
|
+
};
|
package/server/hook.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import { ServerRoute as Route } from './route';
|
|
3
|
+
import { NextFunction } from './utils';
|
|
4
|
+
import { ModernServerContext } from './context';
|
|
5
|
+
|
|
6
|
+
type Middleware = (
|
|
7
|
+
req: IncomingMessage,
|
|
8
|
+
res: ServerResponse,
|
|
9
|
+
next: NextFunction,
|
|
10
|
+
) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export type TemplateAPI = {
|
|
13
|
+
get: () => Promise<string>;
|
|
14
|
+
set: (html: string) => void;
|
|
15
|
+
prependBody: (frag: string) => TemplateAPI;
|
|
16
|
+
prependHead: (frag: string) => TemplateAPI;
|
|
17
|
+
appendBody: (frag: string) => TemplateAPI;
|
|
18
|
+
appendHead: (frag: string) => TemplateAPI;
|
|
19
|
+
replace: (tag: string, frag: string) => TemplateAPI;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type RouteAPI = {
|
|
23
|
+
cur: () => Route;
|
|
24
|
+
get: (entryName: string) => Route | undefined;
|
|
25
|
+
use: (entryName: string) => boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type HookHandler<Context> = (ctx: Context, next: NextFunction) => Promise<void>;
|
|
29
|
+
type Hook<Context> = (fn: HookHandler<Context>) => void;
|
|
30
|
+
export type ModernServerHook = {
|
|
31
|
+
beforeMatch: Hook<ModernServerContext>;
|
|
32
|
+
afterMatch: Hook<ModernServerContext & { router: RouteAPI }>;
|
|
33
|
+
beforeRender: Hook<ModernServerContext>;
|
|
34
|
+
afterRender: Hook<ModernServerContext & { template: TemplateAPI }>;
|
|
35
|
+
};
|
package/server/index.d.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ServerRoute {
|
|
2
|
+
// modern js web entry name
|
|
3
|
+
entryName?: string;
|
|
4
|
+
// the url path for request match
|
|
5
|
+
urlPath: string;
|
|
6
|
+
// the default resource file to response to route
|
|
7
|
+
entryPath: string;
|
|
8
|
+
// if route is spa page
|
|
9
|
+
isSPA?: boolean;
|
|
10
|
+
// if route is ssr page
|
|
11
|
+
isSSR?: boolean;
|
|
12
|
+
// if route is api service
|
|
13
|
+
isApi?: boolean;
|
|
14
|
+
// ssr js bundle for ssr page
|
|
15
|
+
bundle?: string;
|
|
16
|
+
// if route has modern product
|
|
17
|
+
enableModernMode?: boolean;
|
|
18
|
+
// specialHeader?: SpecialHeader[];
|
|
19
|
+
}
|