@shuvi/platform-web 1.0.0-rc.2 → 1.0.0-rc.20
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 +12 -6
- package/esm/shared/configTypes.d.ts +1 -3
- package/esm/shared/constants.d.ts +8 -0
- package/esm/shared/constants.js +8 -0
- package/esm/shared/htmlRenderer.d.ts +33 -0
- package/esm/shared/{serverTypes.js → htmlRenderer.js} +0 -0
- package/esm/shared/index.d.ts +2 -1
- package/esm/shared/index.js +2 -1
- package/esm/shared/renderTypes.d.ts +8 -7
- package/esm/shared/routeTypes.d.ts +4 -9
- package/esm/shuvi-app/app/client.d.ts +2 -1
- package/esm/shuvi-app/app/client.js +13 -17
- package/esm/shuvi-app/app/server.js +13 -9
- package/esm/shuvi-app/dev/eventsource.d.ts +1 -0
- package/esm/shuvi-app/dev/eventsource.js +60 -0
- package/esm/shuvi-app/dev/hotDevClient.d.ts +32 -0
- package/esm/shuvi-app/dev/hotDevClient.js +327 -0
- package/esm/shuvi-app/dev/index.d.ts +3 -0
- package/esm/shuvi-app/dev/index.js +27 -0
- package/esm/shuvi-app/dev/websocket.d.ts +16 -0
- package/esm/shuvi-app/dev/websocket.js +61 -0
- package/esm/shuvi-app/entry/client/app.d.ts +2 -1
- package/esm/shuvi-app/entry/client/app.js +13 -6
- package/esm/shuvi-app/entry/client/index.js +1 -1
- package/esm/shuvi-app/entry/client/run.dev.js +15 -16
- package/esm/shuvi-app/entry/server/index.d.ts +5 -4
- package/esm/shuvi-app/entry/server/index.js +5 -4
- 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 +4 -5
- package/esm/shuvi-app/react/AppContainer.jsx +4 -5
- package/esm/shuvi-app/react/ApplicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/{applicationContext.jsx → ApplicationContext.jsx} +0 -0
- package/esm/shuvi-app/react/Error.jsx +4 -1
- package/esm/shuvi-app/react/Link.d.ts +2 -1
- package/esm/shuvi-app/react/Link.jsx +1 -1
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -2
- package/esm/shuvi-app/react/getRoutes.js +9 -8
- 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 +8 -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 +34 -23
- package/esm/shuvi-app/react/view/ReactView.server.jsx +29 -14
- package/esm/shuvi-app/react/view/render.d.ts +8 -0
- package/esm/shuvi-app/react/view/{render-action.js → render.js} +6 -6
- 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/custom-server/server.js +20 -11
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +7 -7
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +5 -5
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/api/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/hooks.d.ts +2 -1
- package/lib/node/features/filesystem-routes/hooks.js +2 -1
- package/lib/node/features/filesystem-routes/index.d.ts +1 -13
- package/lib/node/features/filesystem-routes/index.js +55 -84
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/middleware/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/page/routes.d.ts +3 -3
- package/lib/node/features/filesystem-routes/page/routes.js +25 -12
- package/lib/node/features/html-render/index.d.ts +4 -18
- package/lib/node/features/html-render/index.js +129 -16
- package/lib/node/features/{main → html-render/lib}/buildHtml.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/buildHtml.js +2 -1
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -3
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +3 -3
- package/lib/node/features/{main → html-render/lib}/generateResource.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/generateResource.js +12 -8
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -2
- package/lib/node/features/html-render/lib/getPageMiddleware.js +18 -13
- package/lib/node/features/html-render/lib/index.d.ts +0 -2
- package/lib/node/features/html-render/lib/index.js +1 -4
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderToHTML.js +9 -49
- package/lib/node/features/html-render/lib/renderer/base.d.ts +7 -8
- package/lib/node/features/html-render/lib/renderer/base.js +19 -11
- package/lib/node/features/html-render/lib/renderer/index.d.ts +5 -4
- package/lib/node/features/html-render/lib/renderer/index.js +77 -8
- 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 +9 -11
- package/lib/node/features/html-render/lib/renderer/types.d.ts +10 -8
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.d.ts +27 -0
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.js +223 -0
- package/lib/node/features/html-render/server.d.ts +1 -1
- package/lib/node/features/html-render/serverHooks.d.ts +6 -1
- package/lib/node/features/html-render/serverHooks.js +1 -2
- package/lib/node/features/index.d.ts +3 -31
- package/lib/node/features/index.js +6 -7
- package/lib/node/features/middlewares.d.ts +1 -1
- package/lib/node/features/middlewares.js +12 -3
- package/lib/node/features/model/index.d.ts +1 -13
- package/lib/node/features/model/runtime.d.ts +3 -8
- package/lib/node/features/model/runtime.js +13 -18
- package/lib/node/features/model/server.js +2 -3
- package/lib/node/features/model/shuvi-app.d.ts +2 -2
- package/lib/node/features/on-demand-compile-page/index.d.ts +3 -13
- package/lib/node/features/on-demand-compile-page/index.js +4 -1
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +3 -3
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +4 -6
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +17 -5
- package/lib/node/paths.js +0 -2
- package/lib/node/shuvi-runtime-server.d.ts +26 -0
- package/lib/{shared/serverTypes.js → node/shuvi-runtime-server.js} +0 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +20 -23
- package/lib/node/targets/react/bundler/index.d.ts +1 -13
- package/lib/node/targets/react/bundler/index.js +19 -13
- package/lib/node/targets/react/index.d.ts +2 -27
- package/lib/node/targets/react/index.js +3 -7
- 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/node/version.d.ts +1 -0
- package/lib/node/version.js +13 -0
- package/lib/shared/appTypes.d.ts +12 -6
- package/lib/shared/configTypes.d.ts +1 -3
- package/lib/shared/constants.d.ts +8 -0
- package/lib/shared/constants.js +15 -0
- package/lib/shared/htmlRenderer.d.ts +33 -0
- package/lib/shared/htmlRenderer.js +2 -0
- package/lib/shared/index.d.ts +2 -1
- package/lib/shared/index.js +2 -1
- package/lib/shared/renderTypes.d.ts +8 -7
- package/lib/shared/routeTypes.d.ts +4 -9
- package/package.json +40 -26
- package/polyfills/polyfills.js +1 -0
- package/shuvi-env.d.ts +10 -0
- package/shuvi-image.d.ts +54 -0
- package/shuvi-type-extensions-node.js +1 -0
- package/shuvi-type-extensions-runtime.d.ts +2 -2
- package/esm/shared/serverTypes.d.ts +0 -6
- package/esm/shuvi-app/dev/webpackHotDevClient.d.ts +0 -5
- package/esm/shuvi-app/dev/webpackHotDevClient.js +0 -34
- package/esm/shuvi-app/react/applicationContext.d.ts +0 -7
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +0 -2
- package/esm/shuvi-app/react/view/render-action.d.ts +0 -10
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +0 -4
- package/esm/shuvi-app/shuvi-runtime-index.js +0 -2
- 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/html-render/lib/pageLoader.d.ts +0 -1
- package/lib/node/features/html-render/lib/pageLoader.js +0 -42
- package/lib/node/features/main/index.d.ts +0 -3
- package/lib/node/features/main/index.js +0 -82
- package/lib/node/targets/react/redox-react/index.d.ts +0 -18
- package/lib/shared/serverTypes.d.ts +0 -6
package/esm/shared/appTypes.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IPageRouteRecord, IAppData, IAppState, Application as _Application } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { ApplicationImpl as _ApplicationImpl } from '@shuvi/platform-shared/shuvi-app/application';
|
|
3
|
+
import type { ShuviRequest } from '@shuvi/service';
|
|
4
|
+
export interface AppConfig {
|
|
5
|
+
ssr: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare type InternalApplication = _ApplicationImpl<AppConfig>;
|
|
8
|
+
export declare type Application = _Application<AppConfig>;
|
|
3
9
|
export interface CreateAppServer {
|
|
4
10
|
(options: {
|
|
5
|
-
req:
|
|
11
|
+
req: ShuviRequest;
|
|
6
12
|
ssr: boolean;
|
|
7
|
-
}):
|
|
13
|
+
}): InternalApplication;
|
|
8
14
|
}
|
|
9
15
|
export interface CreateAppClient {
|
|
10
16
|
(options: {
|
|
11
|
-
routes:
|
|
17
|
+
routes: IPageRouteRecord[];
|
|
12
18
|
appComponent: any;
|
|
13
19
|
appData: IAppData<any, IAppState>;
|
|
14
|
-
}):
|
|
20
|
+
}): InternalApplication;
|
|
15
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRouterHistoryMode, IPageRouteConfig
|
|
1
|
+
import { IRouterHistoryMode, IPageRouteConfig } from '@shuvi/platform-shared/shared';
|
|
2
2
|
export interface IRouterConfig {
|
|
3
3
|
history: IRouterHistoryMode | 'auto';
|
|
4
4
|
}
|
|
@@ -6,8 +6,6 @@ export interface PlatformWebCustomConfig {
|
|
|
6
6
|
ssr: boolean;
|
|
7
7
|
router: IRouterConfig;
|
|
8
8
|
routes?: IPageRouteConfig[];
|
|
9
|
-
middlewareRoutes?: IMiddlewareRouteConfig[];
|
|
10
|
-
apiRoutes?: IApiRouteConfig[];
|
|
11
9
|
conventionRoutes: {
|
|
12
10
|
exclude?: string[];
|
|
13
11
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BUNDLER_TARGET_CLIENT, BUNDLER_TARGET_SERVER, CLIENT_OUTPUT_DIR, SERVER_OUTPUT_DIR } from '@shuvi/shared/lib/constants';
|
|
2
|
+
export declare const CLIENT_BUILD_MANIFEST_PATH = "../build-manifest.client.json";
|
|
3
|
+
export declare const SERVER_BUILD_MANIFEST_PATH = "../build-manifest.server.json";
|
|
4
|
+
export declare const BUILD_CLIENT_RUNTIME_POLYFILLS = "static/polyfills";
|
|
5
|
+
export declare const BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL: unique symbol;
|
|
6
|
+
export declare const BUILD_CLIENT_RUNTIME_WEBPACK = "static/webpack-runtime";
|
|
7
|
+
export declare const BUILD_CLIENT_RUNTIME_MAIN = "static/main";
|
|
8
|
+
export declare const BUILD_SERVER_FILE_SERVER = "server";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BUNDLER_TARGET_CLIENT, BUNDLER_TARGET_SERVER, CLIENT_OUTPUT_DIR, SERVER_OUTPUT_DIR } from '@shuvi/shared/lib/constants';
|
|
2
|
+
export const CLIENT_BUILD_MANIFEST_PATH = '../build-manifest.client.json';
|
|
3
|
+
export const SERVER_BUILD_MANIFEST_PATH = '../build-manifest.server.json';
|
|
4
|
+
export const BUILD_CLIENT_RUNTIME_POLYFILLS = `static/polyfills`;
|
|
5
|
+
export const BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL = Symbol(`polyfills`);
|
|
6
|
+
export const BUILD_CLIENT_RUNTIME_WEBPACK = `static/webpack-runtime`;
|
|
7
|
+
export const BUILD_CLIENT_RUNTIME_MAIN = `static/main`;
|
|
8
|
+
export const BUILD_SERVER_FILE_SERVER = `server`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface IModuleItem {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface IModule {
|
|
6
|
+
files: string[];
|
|
7
|
+
children: IModuleItem[];
|
|
8
|
+
}
|
|
9
|
+
export declare type IAssetMap = {
|
|
10
|
+
js: string[];
|
|
11
|
+
css?: string[];
|
|
12
|
+
} & {
|
|
13
|
+
[ext: string]: string[];
|
|
14
|
+
};
|
|
15
|
+
export interface IChunk {
|
|
16
|
+
file: string;
|
|
17
|
+
request: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IManifest {
|
|
20
|
+
polyfillFiles?: string[];
|
|
21
|
+
entries: {
|
|
22
|
+
[s: string]: IAssetMap;
|
|
23
|
+
};
|
|
24
|
+
bundles: {
|
|
25
|
+
[name: string]: string;
|
|
26
|
+
};
|
|
27
|
+
chunkRequest: {
|
|
28
|
+
[file: string]: string;
|
|
29
|
+
};
|
|
30
|
+
loadble: {
|
|
31
|
+
[s: string]: IModule;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
File without changes
|
package/esm/shared/index.d.ts
CHANGED
package/esm/shared/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Response,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { ShuviRequest } from '@shuvi/service';
|
|
2
|
+
import { Response, IAppData } from '@shuvi/platform-shared/shared';
|
|
3
|
+
import { IManifest } from '../shared';
|
|
4
|
+
import { Application } from './appTypes';
|
|
5
|
+
export declare type IRenderViewOptions = {
|
|
6
|
+
app: Application;
|
|
6
7
|
};
|
|
7
|
-
export interface IRenderOptions extends
|
|
8
|
+
export interface IRenderOptions extends IRenderViewOptions {
|
|
8
9
|
}
|
|
9
10
|
export interface IView<RenderOption extends IRenderOptions = any, RenderResult = void> {
|
|
10
11
|
renderApp(options: RenderOption): RenderResult;
|
|
@@ -35,8 +36,8 @@ export interface IClientRendererOptions<ExtraAppData = {}> extends IRenderOption
|
|
|
35
36
|
appData: IAppData<ExtraAppData>;
|
|
36
37
|
}
|
|
37
38
|
export interface IServerRendererOptions extends IRenderOptions {
|
|
39
|
+
req: ShuviRequest;
|
|
38
40
|
manifest: IManifest;
|
|
39
|
-
getAssetPublicUrl(path: string): string;
|
|
40
41
|
}
|
|
41
42
|
export interface IViewClient<ExtraAppData = {}> extends IView<IClientRendererOptions<ExtraAppData>> {
|
|
42
43
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IRequestHandlerWithNext } from '@shuvi/service';
|
|
3
|
-
import { IResponse, IRequest } from '@shuvi/service';
|
|
1
|
+
import { ShuviRequest, ShuviResponse, ShuviRequestHandler } from '@shuvi/service';
|
|
4
2
|
export interface IApiReq {
|
|
5
|
-
pathname: string;
|
|
6
|
-
query: IURLQuery;
|
|
7
|
-
params: IURLParams;
|
|
8
3
|
cookies: {
|
|
9
4
|
[key: string]: string;
|
|
10
5
|
};
|
|
@@ -12,7 +7,7 @@ export interface IApiReq {
|
|
|
12
7
|
[key: string]: any;
|
|
13
8
|
};
|
|
14
9
|
}
|
|
15
|
-
export declare type IApiRequest =
|
|
10
|
+
export declare type IApiRequest = ShuviRequest & IApiReq;
|
|
16
11
|
export declare type Send<T> = (body: T) => void;
|
|
17
12
|
export declare type IApiRes<T = any> = {
|
|
18
13
|
send: Send<T>;
|
|
@@ -21,7 +16,7 @@ export declare type IApiRes<T = any> = {
|
|
|
21
16
|
redirect(url: string): IApiRes<T>;
|
|
22
17
|
redirect(status: number, url: string): IApiRes<T>;
|
|
23
18
|
};
|
|
24
|
-
export declare type IApiResponse<T = any> =
|
|
19
|
+
export declare type IApiResponse<T = any> = ShuviResponse & IApiRes<T>;
|
|
25
20
|
export declare type IApiRequestHandler<T = any> = (req: IApiRequest, res: IApiResponse<T>) => void | Promise<void>;
|
|
26
21
|
export interface IApiConfig {
|
|
27
22
|
api?: {
|
|
@@ -35,7 +30,7 @@ export interface IApiHandler {
|
|
|
35
30
|
config?: IApiConfig;
|
|
36
31
|
}
|
|
37
32
|
export interface IMiddlewareConfig {
|
|
38
|
-
default:
|
|
33
|
+
default: ShuviRequestHandler;
|
|
39
34
|
}
|
|
40
35
|
export declare type IApiRoutes = {
|
|
41
36
|
path: string;
|
|
@@ -8,19 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { getRoutes } from '@shuvi/app/core/platform';
|
|
11
|
-
import { runPreload, runLoaders, getRouteMatchesWithInvalidLoader,
|
|
11
|
+
import { runPreload, runLoaders, getRouteMatchesWithInvalidLoader, isRedirect, isResponse } from '@shuvi/platform-shared/shared';
|
|
12
12
|
import application from '@shuvi/platform-shared/shuvi-app/application';
|
|
13
13
|
import { createRouter, createBrowserHistory, createHashHistory } from '@shuvi/router';
|
|
14
14
|
import pageLoaders from '@shuvi/app/files/page-loaders';
|
|
15
15
|
import { historyMode } from '@shuvi/app/files/routerConfig';
|
|
16
16
|
import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
|
|
17
|
+
import { serializeServerError } from '../helper/serializeServerError';
|
|
17
18
|
let app;
|
|
18
19
|
export const createApp = ({ routes, appData, appComponent }) => {
|
|
19
20
|
// app is a singleton in client side
|
|
20
21
|
if (app) {
|
|
21
22
|
return app;
|
|
22
23
|
}
|
|
23
|
-
const {
|
|
24
|
+
const { appState, ssr } = appData;
|
|
24
25
|
let history;
|
|
25
26
|
if (historyMode === 'hash') {
|
|
26
27
|
history = createHashHistory();
|
|
@@ -35,16 +36,17 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
35
36
|
app = application({
|
|
36
37
|
initialState: appState,
|
|
37
38
|
AppComponent: appComponent,
|
|
38
|
-
router
|
|
39
|
+
router,
|
|
40
|
+
config: { ssr }
|
|
39
41
|
});
|
|
42
|
+
const loadersData = app.getLoadersData();
|
|
40
43
|
const hasHydrateData = Object.keys(loadersData).length > 0;
|
|
41
|
-
const loaderManager = getLoaderManager();
|
|
42
44
|
let shouldHydrate = ssr && hasHydrateData;
|
|
43
|
-
let hasServerError = app.error
|
|
45
|
+
let hasServerError = !!app.error;
|
|
44
46
|
router.beforeResolve((to, from, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
47
|
if (shouldHydrate) {
|
|
46
48
|
shouldHydrate = false;
|
|
47
|
-
|
|
49
|
+
app.setLoadersData(loadersData);
|
|
48
50
|
return next();
|
|
49
51
|
}
|
|
50
52
|
if (hasServerError) {
|
|
@@ -52,12 +54,11 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
52
54
|
return next();
|
|
53
55
|
}
|
|
54
56
|
if (!to.matches.length) {
|
|
55
|
-
app.
|
|
57
|
+
app.setError(SHUVI_ERROR.PAGE_NOT_FOUND);
|
|
56
58
|
next();
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
const matches = getRouteMatchesWithInvalidLoader(to, from, pageLoaders);
|
|
60
|
-
let isPreloadError = false;
|
|
61
62
|
try {
|
|
62
63
|
const loaderDatas = yield new Promise((resolve, reject) => {
|
|
63
64
|
let value;
|
|
@@ -78,11 +79,9 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
78
79
|
runPreload(to)
|
|
79
80
|
.then(tryResolve)
|
|
80
81
|
.catch(err => {
|
|
81
|
-
isPreloadError = true;
|
|
82
82
|
reject(err);
|
|
83
83
|
});
|
|
84
84
|
runLoaders(matches, pageLoaders, {
|
|
85
|
-
isServer: false,
|
|
86
85
|
query: to.query,
|
|
87
86
|
getAppContext: () => app.context
|
|
88
87
|
})
|
|
@@ -95,7 +94,7 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
95
94
|
tryResolve();
|
|
96
95
|
});
|
|
97
96
|
});
|
|
98
|
-
|
|
97
|
+
app.setLoadersData(loaderDatas);
|
|
99
98
|
}
|
|
100
99
|
catch (error) {
|
|
101
100
|
if (isRedirect(error)) {
|
|
@@ -103,22 +102,19 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
105
104
|
if (isResponse(error) && error.status >= 400 && error.status < 600) {
|
|
106
|
-
app.
|
|
105
|
+
app.setError({
|
|
107
106
|
code: error.status,
|
|
108
107
|
message: error.data
|
|
109
108
|
});
|
|
110
109
|
next();
|
|
111
110
|
return;
|
|
112
111
|
}
|
|
113
|
-
app.error
|
|
114
|
-
code: SHUVI_ERROR.APP_ERROR.code,
|
|
115
|
-
message: error.message || isPreloadError ? 'Preload Error' : 'Loader Error'
|
|
116
|
-
});
|
|
112
|
+
app.setError(serializeServerError(error));
|
|
117
113
|
next();
|
|
118
114
|
return;
|
|
119
115
|
}
|
|
120
116
|
next(() => {
|
|
121
|
-
app.
|
|
117
|
+
app.clearError();
|
|
122
118
|
});
|
|
123
119
|
}));
|
|
124
120
|
return app;
|
|
@@ -9,10 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import routes from '@shuvi/app/files/routes';
|
|
11
11
|
import { getRoutes, app as AppComponent } from '@shuvi/app/core/platform';
|
|
12
|
-
import { runLoaders, getRouteMatchesWithInvalidLoader, isResponse, isRedirect
|
|
12
|
+
import { runLoaders, getRouteMatchesWithInvalidLoader, isResponse, isRedirect } from '@shuvi/platform-shared/shared';
|
|
13
13
|
import pageLoaders from '@shuvi/app/files/page-loaders';
|
|
14
14
|
import application from '@shuvi/platform-shared/shuvi-app/application';
|
|
15
15
|
import { createRouter, createMemoryHistory } from '@shuvi/router';
|
|
16
|
+
import logger from '@shuvi/utils/lib/logger';
|
|
17
|
+
import { serializeServerError } from '../helper/serializeServerError';
|
|
16
18
|
export const createApp = options => {
|
|
17
19
|
const { req, ssr } = options;
|
|
18
20
|
const history = createMemoryHistory({
|
|
@@ -24,18 +26,16 @@ export const createApp = options => {
|
|
|
24
26
|
routes: getRoutes(routes)
|
|
25
27
|
});
|
|
26
28
|
let app;
|
|
27
|
-
const loaderManager = getLoaderManager();
|
|
28
29
|
if (ssr) {
|
|
29
30
|
router.beforeResolve((to, from, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
31
|
const matches = getRouteMatchesWithInvalidLoader(to, from, pageLoaders);
|
|
31
32
|
try {
|
|
32
33
|
const loaderResult = yield runLoaders(matches, pageLoaders, {
|
|
33
|
-
isServer: true,
|
|
34
34
|
req,
|
|
35
35
|
query: to.query,
|
|
36
36
|
getAppContext: () => app.context
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
app.setLoadersData(loaderResult);
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
41
41
|
if (isRedirect(error)) {
|
|
@@ -43,16 +43,17 @@ export const createApp = options => {
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
if (isResponse(error) && error.status >= 400 && error.status < 600) {
|
|
46
|
-
app.
|
|
46
|
+
app.setError({
|
|
47
47
|
code: error.status,
|
|
48
48
|
message: error.data
|
|
49
49
|
});
|
|
50
50
|
next();
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
53
|
+
if (process.env.NODE_ENV === 'development') {
|
|
54
|
+
logger.error(error.stack);
|
|
55
|
+
}
|
|
56
|
+
app.setError(serializeServerError(error));
|
|
56
57
|
next();
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
@@ -61,7 +62,10 @@ export const createApp = options => {
|
|
|
61
62
|
}
|
|
62
63
|
app = application({
|
|
63
64
|
AppComponent,
|
|
64
|
-
router
|
|
65
|
+
router,
|
|
66
|
+
config: {
|
|
67
|
+
ssr
|
|
68
|
+
}
|
|
65
69
|
});
|
|
66
70
|
return app;
|
|
67
71
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getEventSourceWrapper(options: any): any;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const eventCallbacks = [];
|
|
2
|
+
function EventSourceWrapper(options) {
|
|
3
|
+
var source;
|
|
4
|
+
var lastActivity = new Date();
|
|
5
|
+
var listeners = [];
|
|
6
|
+
if (!options.timeout) {
|
|
7
|
+
options.timeout = 20 * 1000;
|
|
8
|
+
}
|
|
9
|
+
init();
|
|
10
|
+
var timer = setInterval(function () {
|
|
11
|
+
if (new Date() - lastActivity > options.timeout) {
|
|
12
|
+
handleDisconnect();
|
|
13
|
+
}
|
|
14
|
+
}, options.timeout / 2);
|
|
15
|
+
function init() {
|
|
16
|
+
source = new window.EventSource(options.path);
|
|
17
|
+
source.onopen = handleOnline;
|
|
18
|
+
source.onerror = handleDisconnect;
|
|
19
|
+
source.onmessage = handleMessage;
|
|
20
|
+
}
|
|
21
|
+
function handleOnline() {
|
|
22
|
+
if (options.log)
|
|
23
|
+
console.log('[HMR] connected');
|
|
24
|
+
lastActivity = new Date();
|
|
25
|
+
}
|
|
26
|
+
function handleMessage(event) {
|
|
27
|
+
lastActivity = new Date();
|
|
28
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
29
|
+
listeners[i](event);
|
|
30
|
+
}
|
|
31
|
+
if (event.data.indexOf('action') !== -1) {
|
|
32
|
+
eventCallbacks.forEach(cb => cb(event));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function handleDisconnect() {
|
|
36
|
+
clearInterval(timer);
|
|
37
|
+
source.close();
|
|
38
|
+
setTimeout(init, options.timeout);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
onclose: () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
source.close();
|
|
44
|
+
},
|
|
45
|
+
addMessageListener: function (fn) {
|
|
46
|
+
listeners.push(fn);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function getEventSourceWrapper(options) {
|
|
51
|
+
if (!window.__whmEventSourceWrapper) {
|
|
52
|
+
window.__whmEventSourceWrapper = {};
|
|
53
|
+
}
|
|
54
|
+
if (!window.__whmEventSourceWrapper[options.path]) {
|
|
55
|
+
// cache the wrapper for other entries loaded on
|
|
56
|
+
// the same page with the same options.path
|
|
57
|
+
window.__whmEventSourceWrapper[options.path] = EventSourceWrapper(options);
|
|
58
|
+
}
|
|
59
|
+
return window.__whmEventSourceWrapper[options.path];
|
|
60
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2013-present, Facebook, Inc.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
export declare type HotDevClient = {
|
|
25
|
+
sendMessage: (data: any) => void;
|
|
26
|
+
subscribeToHmrEvent: (handler: any) => void;
|
|
27
|
+
};
|
|
28
|
+
export default function connect(options: {
|
|
29
|
+
launchEditorEndpoint: string;
|
|
30
|
+
path: string;
|
|
31
|
+
location: Location;
|
|
32
|
+
}): HotDevClient;
|