@shuvi/platform-web 1.0.0-rc.4 → 1.0.0-rc.7
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/esm/shared/appTypes.d.ts +4 -2
- package/esm/shared/renderTypes.d.ts +6 -5
- package/esm/shared/routeTypes.d.ts +4 -9
- package/esm/shuvi-app/app/client.js +11 -16
- package/esm/shuvi-app/app/server.js +10 -9
- package/esm/shuvi-app/dev/hotDevClient.d.ts +0 -1
- package/esm/shuvi-app/dev/hotDevClient.js +30 -51
- package/esm/shuvi-app/dev/websocket.d.ts +0 -1
- package/esm/shuvi-app/helper/serializeServerError.d.ts +2 -0
- package/esm/shuvi-app/helper/serializeServerError.js +21 -0
- package/esm/shuvi-app/react/AppContainer.d.ts +2 -3
- package/esm/shuvi-app/react/AppContainer.jsx +3 -4
- package/esm/shuvi-app/react/getRoutes.js +5 -3
- package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.d.ts +3 -3
- package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.jsx +3 -3
- package/esm/shuvi-app/react/model/runtime.d.ts +8 -0
- package/esm/shuvi-app/react/{redox-react → model}/runtime.js +6 -3
- package/esm/shuvi-app/react/store.d.ts +5 -0
- package/esm/shuvi-app/react/store.js +3 -0
- package/esm/shuvi-app/react/types.d.ts +0 -7
- package/esm/shuvi-app/react/useLoaderData.js +9 -20
- package/esm/shuvi-app/react/view/ReactView.client.jsx +25 -4
- package/esm/shuvi-app/react/view/ReactView.server.jsx +17 -14
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +3 -3
- package/lib/node/features/custom-server/index.d.ts +1 -1
- package/lib/node/features/custom-server/server.d.ts +1 -1
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +7 -7
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +0 -4
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/index.d.ts +1 -13
- package/lib/node/features/filesystem-routes/index.js +3 -41
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/page/routes.js +1 -1
- package/lib/node/features/html-render/index.js +1 -1
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -2
- package/lib/node/features/html-render/lib/index.d.ts +0 -1
- package/lib/node/features/html-render/lib/index.js +1 -3
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderToHTML.js +7 -48
- package/lib/node/features/html-render/lib/renderer/base.d.ts +6 -6
- package/lib/node/features/html-render/lib/renderer/base.js +5 -5
- package/lib/node/features/html-render/lib/renderer/index.d.ts +5 -4
- package/lib/node/features/html-render/lib/renderer/index.js +69 -6
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/spa.js +4 -6
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/ssr.js +5 -6
- package/lib/node/features/html-render/lib/renderer/types.d.ts +8 -5
- package/lib/node/features/html-render/server.d.ts +1 -1
- package/lib/node/features/index.js +1 -3
- package/lib/node/features/model/index.d.ts +1 -13
- package/lib/node/features/model/runtime.d.ts +3 -3
- package/lib/node/features/model/runtime.js +2 -0
- package/lib/node/features/model/shuvi-app.d.ts +2 -2
- package/lib/node/features/on-demand-compile-page/index.d.ts +1 -13
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +3 -3
- package/lib/node/paths.js +0 -2
- package/lib/node/shuvi-runtime-server.d.ts +18 -0
- package/lib/node/shuvi-runtime-server.js +2 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +0 -6
- package/lib/node/targets/react/bundler/index.d.ts +1 -13
- package/lib/node/targets/react/index.d.ts +2 -26
- package/lib/node/targets/react/index.js +2 -2
- package/lib/node/targets/react/model/index.d.ts +6 -0
- package/lib/node/targets/react/{redox-react → model}/index.js +7 -6
- package/lib/shared/appTypes.d.ts +4 -2
- package/lib/shared/renderTypes.d.ts +6 -5
- package/lib/shared/routeTypes.d.ts +4 -9
- package/package.json +14 -14
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +0 -8
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +0 -6
- package/esm/shuvi-app/shuvi-runtime-server.js +0 -1
- package/lib/node/features/webpack-watch-wait-for-file-builder/index.d.ts +0 -16
- package/lib/node/features/webpack-watch-wait-for-file-builder/index.js +0 -25
- package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.d.ts +0 -12
- package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.js +0 -32
- package/lib/node/targets/react/redox-react/index.d.ts +0 -18
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import * as React from 'react';
|
|
11
11
|
import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
|
|
12
12
|
import { Router } from '@shuvi/router-react';
|
|
13
|
+
import { getServerError } from '@shuvi/error-overlay';
|
|
13
14
|
import AppContainer from '../AppContainer';
|
|
14
15
|
import { HeadManager, HeadManagerContext } from '../head';
|
|
15
16
|
import Loadable from '../loadable';
|
|
@@ -20,8 +21,8 @@ export class ReactClientView {
|
|
|
20
21
|
this._isInitialRender = true;
|
|
21
22
|
this.renderApp = ({ appContainer, app, appData }) => __awaiter(this, void 0, void 0, function* () {
|
|
22
23
|
const { _isInitialRender: isInitialRender } = this;
|
|
23
|
-
const { router, appComponent: AppComponent, error } = app;
|
|
24
|
-
let { ssr,
|
|
24
|
+
const { router, appComponent: AppComponent, setError: setAppError, error: appError } = app;
|
|
25
|
+
let { ssr, dynamicIds } = appData;
|
|
25
26
|
// For e2e test
|
|
26
27
|
if (window.__SHUVI) {
|
|
27
28
|
window.__SHUVI.router = router;
|
|
@@ -29,6 +30,26 @@ export class ReactClientView {
|
|
|
29
30
|
else {
|
|
30
31
|
window.__SHUVI = { router };
|
|
31
32
|
}
|
|
33
|
+
if (process.env.NODE_ENV === 'development') {
|
|
34
|
+
if (appError && appError.source === 'server') {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
let error;
|
|
38
|
+
try {
|
|
39
|
+
// Generate a new error object. We `throw` it because some browsers
|
|
40
|
+
// will set the `stack` when thrown, and we want to ensure ours is
|
|
41
|
+
// not overridden when we re-throw it below.
|
|
42
|
+
throw new Error(appError.message);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
error = e;
|
|
46
|
+
}
|
|
47
|
+
error.name = (_a = appError.name) !== null && _a !== void 0 ? _a : '';
|
|
48
|
+
error.stack = appError.stack;
|
|
49
|
+
throw getServerError(error);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
32
53
|
const TypedAppComponent = AppComponent;
|
|
33
54
|
if (ssr) {
|
|
34
55
|
yield Loadable.preloadReady(dynamicIds);
|
|
@@ -39,13 +60,13 @@ export class ReactClientView {
|
|
|
39
60
|
const { matches } = router.current;
|
|
40
61
|
if (!matches.length) {
|
|
41
62
|
// no handler no matches
|
|
42
|
-
|
|
63
|
+
setAppError(SHUVI_ERROR.PAGE_NOT_FOUND);
|
|
43
64
|
}
|
|
44
65
|
}
|
|
45
66
|
const root = (<Router router={router}>
|
|
46
67
|
<AppContainer app={app}>
|
|
47
68
|
<HeadManagerContext.Provider value={headManager.updateHead}>
|
|
48
|
-
<TypedAppComponent
|
|
69
|
+
<TypedAppComponent />
|
|
49
70
|
</HeadManagerContext.Provider>
|
|
50
71
|
</AppContainer>
|
|
51
72
|
</Router>);
|
|
@@ -9,32 +9,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import * as React from 'react';
|
|
11
11
|
import { renderToString } from 'react-dom/server';
|
|
12
|
-
import {
|
|
12
|
+
import { redirect } from '@shuvi/platform-shared/shared';
|
|
13
13
|
import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
|
|
14
14
|
import { Router } from '@shuvi/router-react';
|
|
15
|
+
import chalk from '@shuvi/utils/lib/chalk';
|
|
15
16
|
import Loadable, { LoadableContext } from '../loadable';
|
|
16
17
|
import AppContainer from '../AppContainer';
|
|
17
18
|
import { Head } from '../head';
|
|
19
|
+
import { serializeServerError } from '../../helper/serializeServerError';
|
|
18
20
|
export class ReactServerView {
|
|
19
21
|
constructor() {
|
|
20
|
-
this.renderApp = ({ app, manifest,
|
|
22
|
+
this.renderApp = ({ req, app, manifest, isDev }) => __awaiter(this, void 0, void 0, function* () {
|
|
21
23
|
yield Loadable.preloadAll();
|
|
22
|
-
const {
|
|
24
|
+
const { router, appComponent: AppComponent, setError: setAppError } = app;
|
|
23
25
|
yield router.ready;
|
|
24
26
|
// todo: move these into renderer
|
|
25
27
|
let { pathname, matches, redirected } = router.current;
|
|
26
28
|
// handler no matches
|
|
27
29
|
if (!matches.length) {
|
|
28
|
-
|
|
30
|
+
setAppError(SHUVI_ERROR.PAGE_NOT_FOUND);
|
|
29
31
|
}
|
|
30
32
|
if (redirected) {
|
|
31
33
|
return redirect(pathname);
|
|
32
34
|
}
|
|
33
|
-
// todo: move loader into app, avoid using global module
|
|
34
|
-
const loaderManager = getLoaderManager();
|
|
35
|
-
const loadersData = yield loaderManager.getAllData();
|
|
36
35
|
const loadableModules = [];
|
|
37
|
-
let htmlContent;
|
|
36
|
+
let htmlContent = undefined;
|
|
38
37
|
let head;
|
|
39
38
|
const RootApp = (<Router static router={router}>
|
|
40
39
|
<AppContainer app={app}>
|
|
@@ -46,8 +45,14 @@ export class ReactServerView {
|
|
|
46
45
|
try {
|
|
47
46
|
htmlContent = renderToString(RootApp);
|
|
48
47
|
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (isDev) {
|
|
50
|
+
console.error(chalk.red('error') + ' - ' + error.stack);
|
|
51
|
+
}
|
|
52
|
+
setAppError(serializeServerError(error, isDev));
|
|
53
|
+
htmlContent = renderToString(RootApp); // Consistency on both server and client side
|
|
54
|
+
}
|
|
49
55
|
finally {
|
|
50
|
-
loaderManager.clearAllData();
|
|
51
56
|
head = Head.rewind() || [];
|
|
52
57
|
}
|
|
53
58
|
const { loadble } = manifest;
|
|
@@ -72,7 +77,7 @@ export class ReactServerView {
|
|
|
72
77
|
tagName: 'link',
|
|
73
78
|
attrs: {
|
|
74
79
|
rel: 'preload',
|
|
75
|
-
href:
|
|
80
|
+
href: req.getAssetUrl(file),
|
|
76
81
|
as: 'script'
|
|
77
82
|
}
|
|
78
83
|
});
|
|
@@ -82,19 +87,17 @@ export class ReactServerView {
|
|
|
82
87
|
tagName: 'link',
|
|
83
88
|
attrs: {
|
|
84
89
|
rel: 'stylesheet',
|
|
85
|
-
href:
|
|
90
|
+
href: req.getAssetUrl(file)
|
|
86
91
|
}
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
const appData = {
|
|
91
|
-
dynamicIds: [...dynamicImportIdSet]
|
|
92
|
-
loadersData
|
|
96
|
+
dynamicIds: [...dynamicImportIdSet]
|
|
93
97
|
};
|
|
94
98
|
if (dynamicImportIdSet.size) {
|
|
95
99
|
appData.dynamicIds = Array.from(dynamicImportIdSet);
|
|
96
100
|
}
|
|
97
|
-
appData.appState = storeManager.getState();
|
|
98
101
|
return {
|
|
99
102
|
appData,
|
|
100
103
|
content: htmlContent,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ShuviRequestHandler } from '@shuvi/service';
|
|
2
2
|
import { IApiRequestHandler } from '../shared';
|
|
3
|
-
export declare type
|
|
4
|
-
export declare type
|
|
3
|
+
export declare type ShuviMiddlewareHandler = ShuviRequestHandler;
|
|
4
|
+
export declare type ShuviApiHandler = IApiRequestHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").
|
|
2
|
+
server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").ServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
3
3
|
};
|
|
4
4
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").
|
|
1
|
+
declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").ServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
2
2
|
export default _default;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
|
-
import {
|
|
3
|
+
import { ShuviRequest, ShuviResponse } from '@shuvi/service';
|
|
4
4
|
import { IApiRequestHandler, IApiResponse } from '../../../../shared';
|
|
5
5
|
export { IApiRequestHandler };
|
|
6
|
-
export declare function apiRouteHandler(req:
|
|
6
|
+
export declare function apiRouteHandler(req: ShuviRequest, res: ShuviResponse, resolver: IApiRequestHandler, apiRoutesConfig: any): Promise<void>;
|
|
7
7
|
/**
|
|
8
8
|
* Parse incoming message like `json` or `urlencoded`
|
|
9
9
|
* @param req request object
|
|
10
10
|
*/
|
|
11
|
-
export declare function parseBody(req:
|
|
11
|
+
export declare function parseBody(req: ShuviRequest, limit: string | number): Promise<any>;
|
|
12
12
|
/**
|
|
13
13
|
* Parse cookies from `req` header
|
|
14
14
|
* @param req request object
|
|
@@ -21,27 +21,27 @@ export declare function getCookieParser(req: IncomingMessage): {
|
|
|
21
21
|
* @param res ServerResponse object
|
|
22
22
|
* @param statusCode `HTTP` status code of response
|
|
23
23
|
*/
|
|
24
|
-
export declare function sendStatusCode<IRes extends IApiResponse>(res:
|
|
24
|
+
export declare function sendStatusCode<IRes extends IApiResponse>(res: ShuviResponse, statusCode: number): IRes;
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
27
|
* @param res response object
|
|
28
28
|
* @param [statusOrUrl] `HTTP` status code of redirect
|
|
29
29
|
* @param url URL of redirect
|
|
30
30
|
*/
|
|
31
|
-
export declare function redirect<IRes extends IApiResponse>(res:
|
|
31
|
+
export declare function redirect<IRes extends IApiResponse>(res: ShuviResponse, statusOrUrl: string | number, url?: string): IRes;
|
|
32
32
|
/**
|
|
33
33
|
* Send `any` body to response
|
|
34
34
|
* @param req request object
|
|
35
35
|
* @param res response object
|
|
36
36
|
* @param body of response
|
|
37
37
|
*/
|
|
38
|
-
export declare function sendData(req:
|
|
38
|
+
export declare function sendData(req: ShuviRequest, res: ShuviResponse, body: any): void;
|
|
39
39
|
/**
|
|
40
40
|
* Send `JSON` object
|
|
41
41
|
* @param res response object
|
|
42
42
|
* @param jsonBody of data
|
|
43
43
|
*/
|
|
44
|
-
export declare function sendJson(req:
|
|
44
|
+
export declare function sendJson(req: ShuviRequest, res: ShuviResponse, jsonBody: any): void;
|
|
45
45
|
/**
|
|
46
46
|
* Custom error class
|
|
47
47
|
*/
|
|
@@ -42,11 +42,7 @@ function apiRouteHandler(req, res, resolver, apiRoutesConfig) {
|
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
43
|
try {
|
|
44
44
|
const { bodyParser } = apiRoutesConfig || {};
|
|
45
|
-
const { pathname, query, params } = req;
|
|
46
45
|
const apiReq = {
|
|
47
|
-
pathname,
|
|
48
|
-
query,
|
|
49
|
-
params,
|
|
50
46
|
// Parsing of cookies
|
|
51
47
|
cookies: getCookieParser(req)
|
|
52
48
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IServerPluginContext,
|
|
2
|
-
export declare function middleware(_ctx: IServerPluginContext):
|
|
1
|
+
import { IServerPluginContext, ShuviRequestHandler } from '@shuvi/service';
|
|
2
|
+
export declare function middleware(_ctx: IServerPluginContext): ShuviRequestHandler;
|
|
@@ -3,18 +3,6 @@ import { middleware as getMiddlewareMiddleware } from './middleware';
|
|
|
3
3
|
import { IApiRequestHandler, middleware as getApiMiddleware } from './api';
|
|
4
4
|
export { IApiRequestHandler, getRoutes, getMiddlewareMiddleware, getApiMiddleware };
|
|
5
5
|
declare const _default: {
|
|
6
|
-
core: import("@shuvi/platform-shared/shared").IPluginInstance<
|
|
7
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
8
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
10
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
11
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
12
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
13
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
14
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
15
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
16
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
|
|
17
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
18
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
6
|
+
core: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
|
|
19
7
|
};
|
|
20
8
|
export default _default;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -33,9 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
12
|
exports.getApiMiddleware = exports.getMiddlewareMiddleware = exports.getRoutes = void 0;
|
|
36
|
-
const fs = __importStar(require("fs"));
|
|
37
|
-
const path = __importStar(require("path"));
|
|
38
|
-
const build_loaders_1 = require("@shuvi/toolpack/lib/utils/build-loaders");
|
|
39
13
|
const service_1 = require("@shuvi/service");
|
|
40
14
|
const node_1 = require("@shuvi/platform-shared/node");
|
|
41
15
|
const lib_1 = require("../html-render/lib");
|
|
@@ -133,8 +107,8 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
133
107
|
}),
|
|
134
108
|
dependencies: [rawRoutes]
|
|
135
109
|
});
|
|
136
|
-
const
|
|
137
|
-
name: 'loaders.js',
|
|
110
|
+
const pageLoadersFile = defineFile({
|
|
111
|
+
name: 'page-loaders.js',
|
|
138
112
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
113
|
const routes = (0, page_1.getRoutes)();
|
|
140
114
|
const loaders = {};
|
|
@@ -157,30 +131,18 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
157
131
|
let exports = '';
|
|
158
132
|
Object.entries(loaders).forEach((loader, index) => {
|
|
159
133
|
const [id, component] = loader;
|
|
160
|
-
imports += `import { loader as loader_${index} } from '${component}'\n`;
|
|
134
|
+
imports += `import { loader as loader_${index} } from '${component}?keep=loader'\n`;
|
|
161
135
|
exports += `'${id}': loader_${index},\n`;
|
|
162
136
|
});
|
|
163
137
|
return `${imports} export default {\n ${exports}\n}`;
|
|
164
138
|
}),
|
|
165
139
|
dependencies: [pageRoutesFile]
|
|
166
140
|
});
|
|
167
|
-
const loadersFileName = path.join(context.paths.appDir, 'files', 'loaders.js');
|
|
168
|
-
const pageLoadersFile = defineFile({
|
|
169
|
-
name: 'page-loaders.js',
|
|
170
|
-
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
171
|
-
if (fs.existsSync(loadersFileName)) {
|
|
172
|
-
return yield (0, build_loaders_1.buildToString)(loadersFileName);
|
|
173
|
-
}
|
|
174
|
-
return '';
|
|
175
|
-
}),
|
|
176
|
-
dependencies: [loadersFile]
|
|
177
|
-
});
|
|
178
141
|
return [
|
|
179
142
|
rawRoutes,
|
|
180
143
|
pageRoutesFile,
|
|
181
144
|
apiRoutesFile,
|
|
182
145
|
middlewareRoutesFile,
|
|
183
|
-
loadersFile,
|
|
184
146
|
pageLoadersFile
|
|
185
147
|
];
|
|
186
148
|
})
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IServerPluginContext,
|
|
2
|
-
export declare function middleware(_api: IServerPluginContext):
|
|
1
|
+
import { IServerPluginContext, ShuviRequestHandler } from '@shuvi/service';
|
|
2
|
+
export declare function middleware(_api: IServerPluginContext): ShuviRequestHandler;
|
|
@@ -74,7 +74,7 @@ const getPlugin = (platformContext) => {
|
|
|
74
74
|
exported: '*'
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
source: (0, paths_1.resolvePkgFile)('
|
|
77
|
+
source: (0, paths_1.resolvePkgFile)('lib/node/shuvi-runtime-server'),
|
|
78
78
|
filepath: 'server.ts',
|
|
79
79
|
exported: '*'
|
|
80
80
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getPageMiddleware(api: IServerPluginContext):
|
|
1
|
+
import { ShuviRequestHandler, IServerPluginContext } from '@shuvi/service';
|
|
2
|
+
export declare function getPageMiddleware(api: IServerPluginContext): ShuviRequestHandler;
|
|
@@ -14,10 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.getPageMiddleware = void 0;
|
|
18
18
|
var getPageMiddleware_1 = require("./getPageMiddleware");
|
|
19
19
|
Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return getPageMiddleware_1.getPageMiddleware; } });
|
|
20
|
-
var renderToHTML_1 = require("./renderToHTML");
|
|
21
|
-
Object.defineProperty(exports, "renderToHTML", { enumerable: true, get: function () { return renderToHTML_1.renderToHTML; } });
|
|
22
20
|
__exportStar(require("./renderer"), exports);
|
|
23
21
|
__exportStar(require("./pageLoader"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
|
|
2
2
|
import { Response } from '@shuvi/platform-shared/shared';
|
|
3
3
|
export declare function renderToHTML({ req, serverPluginContext }: {
|
|
4
|
-
req:
|
|
4
|
+
req: ShuviRequest;
|
|
5
5
|
serverPluginContext: IServerPluginContext;
|
|
6
6
|
}): Promise<Response>;
|
|
@@ -11,38 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.renderToHTML = void 0;
|
|
13
13
|
const resources_1 = require("@shuvi/service/lib/resources");
|
|
14
|
-
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
15
14
|
const renderer_1 = require("./renderer");
|
|
16
|
-
const htmlTag_1 = require("./renderer/htmlTag");
|
|
17
|
-
function addEssentialTagsIfMissing(document) {
|
|
18
|
-
let hasMetaCharset = false;
|
|
19
|
-
let hasMetaViewport = false;
|
|
20
|
-
for (const { tagName, attrs } of document.headTags) {
|
|
21
|
-
if (hasMetaCharset && hasMetaViewport) {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (tagName === 'meta') {
|
|
25
|
-
if (attrs.charset) {
|
|
26
|
-
hasMetaCharset = true;
|
|
27
|
-
}
|
|
28
|
-
else if (attrs.name === 'viewport') {
|
|
29
|
-
hasMetaViewport = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (!hasMetaCharset) {
|
|
34
|
-
document.headTags.unshift((0, htmlTag_1.tag)('meta', {
|
|
35
|
-
charset: 'utf-8'
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
if (!hasMetaViewport) {
|
|
39
|
-
document.headTags.unshift((0, htmlTag_1.tag)('meta', {
|
|
40
|
-
name: 'viewport',
|
|
41
|
-
content: 'width=device-width,minimum-scale=1,initial-scale=1'
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
return document;
|
|
45
|
-
}
|
|
46
15
|
function renderToHTML({ req, serverPluginContext }) {
|
|
47
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
17
|
let result;
|
|
@@ -50,27 +19,17 @@ function renderToHTML({ req, serverPluginContext }) {
|
|
|
50
19
|
const { application } = resources_1.server;
|
|
51
20
|
const app = application.createApp({
|
|
52
21
|
req,
|
|
53
|
-
ssr: serverPluginContext.config.ssr
|
|
22
|
+
ssr: serverPluginContext.config.ssr,
|
|
23
|
+
isDev: serverPluginContext.mode === 'development'
|
|
54
24
|
});
|
|
55
25
|
try {
|
|
56
26
|
yield app.init();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
app:
|
|
60
|
-
|
|
27
|
+
result = yield renderer.renderView({
|
|
28
|
+
req,
|
|
29
|
+
app: app.getPublicAPI(),
|
|
30
|
+
ssr: serverPluginContext.config.ssr,
|
|
31
|
+
isDev: serverPluginContext.mode === 'development'
|
|
61
32
|
});
|
|
62
|
-
if ((0, shared_1.isResponse)(doc)) {
|
|
63
|
-
result = doc;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
addEssentialTagsIfMissing(doc);
|
|
67
|
-
yield serverPluginContext.serverPluginRunner.modifyHtml(doc, app.context);
|
|
68
|
-
const htmlStr = renderer.renderDocumentToString(doc);
|
|
69
|
-
const appError = app.error.getError;
|
|
70
|
-
result = (0, shared_1.text)(htmlStr, {
|
|
71
|
-
status: appError && typeof appError.code !== 'undefined' ? appError.code : 200
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
33
|
}
|
|
75
34
|
finally {
|
|
76
35
|
yield app.dispose();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { IAppData
|
|
2
|
-
import { IServerPluginContext } from '@shuvi/service';
|
|
3
|
-
import {
|
|
4
|
-
import { IRendererConstructorOptions,
|
|
1
|
+
import { IAppData } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
|
|
3
|
+
import { IHtmlTag, IApplication } from './types';
|
|
4
|
+
import { IRendererConstructorOptions, IRenderViewOptions, IRenderDocumentResult } from './types';
|
|
5
5
|
export declare type AppData = Omit<IAppData, 'filesByRoutId' | 'publicPath'>;
|
|
6
6
|
export declare abstract class BaseRenderer {
|
|
7
7
|
protected _serverPluginContext: IServerPluginContext;
|
|
8
8
|
protected _app?: IApplication;
|
|
9
9
|
constructor({ serverPluginContext }: IRendererConstructorOptions);
|
|
10
|
-
abstract renderDocument({ app, req }:
|
|
11
|
-
protected _getMainAssetTags(): {
|
|
10
|
+
abstract renderDocument({ app, req }: IRenderViewOptions): IRenderDocumentResult;
|
|
11
|
+
protected _getMainAssetTags(req: ShuviRequest): {
|
|
12
12
|
styles: IHtmlTag<any>[];
|
|
13
13
|
scripts: IHtmlTag<any>[];
|
|
14
14
|
};
|
|
@@ -14,24 +14,24 @@ class BaseRenderer {
|
|
|
14
14
|
constructor({ serverPluginContext }) {
|
|
15
15
|
this._serverPluginContext = serverPluginContext;
|
|
16
16
|
}
|
|
17
|
-
_getMainAssetTags() {
|
|
17
|
+
_getMainAssetTags(req) {
|
|
18
18
|
const styles = [];
|
|
19
19
|
const scripts = [];
|
|
20
20
|
const entrypoints = resources_1.clientManifest.entries[service_1.BUILD_CLIENT_RUNTIME_MAIN];
|
|
21
21
|
const polyfill = resources_1.clientManifest.bundles[service_1.BUILD_CLIENT_RUNTIME_POLYFILL];
|
|
22
22
|
scripts.push((0, htmlTag_1.tag)('script', {
|
|
23
|
-
src:
|
|
23
|
+
src: req.getAssetUrl(polyfill)
|
|
24
24
|
}));
|
|
25
25
|
entrypoints.js.forEach((asset) => {
|
|
26
26
|
scripts.push((0, htmlTag_1.tag)('script', {
|
|
27
|
-
src:
|
|
27
|
+
src: req.getAssetUrl(asset)
|
|
28
28
|
}));
|
|
29
29
|
});
|
|
30
30
|
if (entrypoints.css) {
|
|
31
31
|
entrypoints.css.forEach((asset) => {
|
|
32
32
|
styles.push((0, htmlTag_1.tag)('link', {
|
|
33
33
|
rel: 'stylesheet',
|
|
34
|
-
href:
|
|
34
|
+
href: req.getAssetUrl(asset)
|
|
35
35
|
}));
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -60,7 +60,7 @@ class BaseRenderer {
|
|
|
60
60
|
}
|
|
61
61
|
_getInlineAppData(app, appData) {
|
|
62
62
|
const routes = app.router.routes || [];
|
|
63
|
-
const data = JSON.stringify(Object.assign(Object.assign({}, appData), { filesByRoutId: (0, generateFilesByRoutId_1.default)(resources_1.clientManifest, routes), publicPath: this._serverPluginContext.
|
|
63
|
+
const data = JSON.stringify(Object.assign(Object.assign({}, appData), { filesByRoutId: (0, generateFilesByRoutId_1.default)(resources_1.clientManifest, routes), publicPath: this._serverPluginContext.assetPublicPath }));
|
|
64
64
|
return (0, htmlTag_1.tag)('script', {
|
|
65
65
|
id: constants_1.CLIENT_APPDATA_ID,
|
|
66
66
|
type: 'application/json'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Response } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { IRendererConstructorOptions, IRenderViewOptions } from './types';
|
|
3
3
|
export * from './types';
|
|
4
4
|
export interface ITemplateData {
|
|
5
5
|
[x: string]: any;
|
|
@@ -10,6 +10,7 @@ export declare class Renderer {
|
|
|
10
10
|
private _ssrRenderer;
|
|
11
11
|
private _spaRenderer;
|
|
12
12
|
constructor(options: IRendererConstructorOptions);
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
renderView(options: IRenderViewOptions): Promise<Response>;
|
|
14
|
+
private _renderDocument;
|
|
15
|
+
private _renderDocumentToString;
|
|
15
16
|
}
|