@shuvi/platform-shared 1.0.0-rc.5 → 1.0.0-rc.8
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/application.d.ts +3 -3
- package/esm/shared/application.js +4 -4
- package/esm/shared/applicationTypes.d.ts +8 -9
- package/esm/shared/index.d.ts +1 -1
- package/esm/shared/index.js +1 -3
- package/esm/shared/loader/loader.d.ts +1 -1
- package/esm/shared/loader/loader.js +2 -2
- package/esm/shared/loader/types.d.ts +4 -8
- package/esm/shared/models/error.d.ts +2 -2
- package/esm/shared/models/loader.d.ts +3 -3
- package/esm/shared/routerTypes.d.ts +2 -0
- package/esm/shared/{lifecycle.d.ts → runtimPlugin.d.ts} +2 -4
- package/esm/shared/{lifecycle.js → runtimPlugin.js} +2 -1
- package/esm/shuvi-app/shuvi-runtime-app.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-index.js +1 -1
- package/lib/node/platform/index.d.ts +1 -13
- package/lib/node/platform/plugins/main/index.d.ts +1 -13
- package/lib/node/route/helpers.js +6 -27
- package/lib/shared/application.d.ts +3 -3
- package/lib/shared/application.js +6 -6
- package/lib/shared/applicationTypes.d.ts +8 -9
- package/lib/shared/index.d.ts +1 -1
- package/lib/shared/index.js +5 -4
- package/lib/shared/loader/loader.d.ts +1 -1
- package/lib/shared/loader/loader.js +2 -2
- package/lib/shared/loader/types.d.ts +4 -8
- package/lib/shared/models/error.d.ts +2 -2
- package/lib/shared/models/loader.d.ts +3 -3
- package/lib/shared/routerTypes.d.ts +2 -0
- package/lib/shared/{lifecycle.d.ts → runtimPlugin.d.ts} +2 -4
- package/lib/shared/{lifecycle.js → runtimPlugin.js} +4 -2
- package/package.json +10 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { RedoxStore, IApplication, IAppContext, IApplicationOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class Application {
|
|
4
4
|
private _router;
|
|
5
5
|
private _appComponent;
|
|
@@ -11,7 +11,7 @@ export declare class Application {
|
|
|
11
11
|
constructor(options: IApplicationOptions);
|
|
12
12
|
get router(): IRouter<IPageRouteRecord>;
|
|
13
13
|
get context(): IAppContext;
|
|
14
|
-
get pluginManager(): import("@shuvi/hook").HookManager<import("./
|
|
14
|
+
get pluginManager(): import("@shuvi/hook").HookManager<import("./runtimPlugin").RuntimePluginHooks, void>;
|
|
15
15
|
get appComponent(): any;
|
|
16
16
|
get error(): IError | undefined;
|
|
17
17
|
setError(err: IError): void;
|
|
@@ -19,7 +19,7 @@ export declare class Application {
|
|
|
19
19
|
getLoadersData(): Record<string, any>;
|
|
20
20
|
setLoadersData(datas: Record<string, any>): void;
|
|
21
21
|
init(): Promise<void>;
|
|
22
|
-
get store():
|
|
22
|
+
get store(): RedoxStore;
|
|
23
23
|
updateComponents({ AppComponent }?: IRerenderConfig): Promise<void>;
|
|
24
24
|
dispose(): Promise<void>;
|
|
25
25
|
private _initPlugin;
|
|
@@ -7,8 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { getManager } from './
|
|
11
|
-
import { initPlugins } from './
|
|
10
|
+
import { getManager } from './runtimPlugin';
|
|
11
|
+
import { initPlugins } from './runtimPlugin';
|
|
12
12
|
import { redox } from '@shuvi/redox';
|
|
13
13
|
import { errorModel } from './models/error';
|
|
14
14
|
import { loaderModel } from './models/loader';
|
|
@@ -17,8 +17,8 @@ export class Application {
|
|
|
17
17
|
this._router = options.router;
|
|
18
18
|
this._context = {};
|
|
19
19
|
this._store = redox({ initialState: options.initialState });
|
|
20
|
-
this._error = this._store.
|
|
21
|
-
this._loader = this._store.
|
|
20
|
+
this._error = this._store.getModel(errorModel);
|
|
21
|
+
this._loader = this._store.getModel(loaderModel);
|
|
22
22
|
this._appComponent = options.AppComponent;
|
|
23
23
|
this._pluginManager = getManager();
|
|
24
24
|
initPlugins(this._pluginManager, options.plugins || []);
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IncomingMessage } from 'http';
|
|
3
|
-
import { IStoreManager } from '@shuvi/redox';
|
|
1
|
+
import { RedoxStore } from '@shuvi/redox';
|
|
4
2
|
import { CustomAppContext } from '@shuvi/runtime';
|
|
5
3
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
6
|
-
import { IPluginList } from './
|
|
7
|
-
export declare type IRequest = IncomingMessage & {
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
};
|
|
4
|
+
import { IPluginList } from './runtimPlugin';
|
|
10
5
|
export interface IAppContext extends CustomAppContext {
|
|
11
6
|
[x: string]: unknown;
|
|
12
7
|
}
|
|
13
8
|
export declare type IRerenderConfig = {
|
|
14
9
|
AppComponent?: any;
|
|
15
10
|
};
|
|
16
|
-
export type {
|
|
11
|
+
export type { RedoxStore };
|
|
12
|
+
export declare type ErrorSource = 'server';
|
|
17
13
|
export interface IError {
|
|
18
14
|
code?: number;
|
|
19
15
|
message?: string;
|
|
16
|
+
stack?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
source?: ErrorSource;
|
|
20
19
|
}
|
|
21
20
|
export interface IErrorState {
|
|
22
21
|
error?: IError;
|
|
@@ -28,7 +27,7 @@ export interface IApplication {
|
|
|
28
27
|
readonly context: IAppContext;
|
|
29
28
|
readonly router: IRouter<IPageRouteRecord>;
|
|
30
29
|
readonly appComponent: any;
|
|
31
|
-
readonly store:
|
|
30
|
+
readonly store: RedoxStore;
|
|
32
31
|
readonly error: IError | undefined;
|
|
33
32
|
setError(err: IError): void;
|
|
34
33
|
clearError(): void;
|
package/esm/shared/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export { loaderModel } from './models/loader';
|
|
|
8
8
|
export * from './applicationTypes';
|
|
9
9
|
export type { Application } from './application';
|
|
10
10
|
export type { IRuntimeConfig } from './runtimeConfigTypes';
|
|
11
|
-
export { IAppModule, IPluginInstance, BuiltInRuntimePluginHooks, CustomRuntimePluginHooks, RuntimePluginHooks, createRuntimePlugin, RuntimePluginInstance } from './
|
|
11
|
+
export { IAppModule, IPluginInstance, BuiltInRuntimePluginHooks, CustomRuntimePluginHooks, RuntimePluginHooks, createRuntimePlugin, createRuntimePluginBefore, createRuntimePluginAfter, RuntimePluginInstance } from './runtimPlugin';
|
package/esm/shared/index.js
CHANGED
|
@@ -6,6 +6,4 @@ export * from './loader';
|
|
|
6
6
|
export { errorModel } from './models/error';
|
|
7
7
|
export { loaderModel } from './models/loader';
|
|
8
8
|
export * from './applicationTypes';
|
|
9
|
-
export {
|
|
10
|
-
// fix createRuntimePlugin is not portable end
|
|
11
|
-
createRuntimePlugin } from './lifecycle';
|
|
9
|
+
export { createRuntimePlugin, createRuntimePluginBefore, createRuntimePluginAfter } from './runtimPlugin';
|
|
@@ -5,5 +5,5 @@ interface Result<T> {
|
|
|
5
5
|
result?: T;
|
|
6
6
|
}
|
|
7
7
|
export declare function runInParallerAndBail<T>(fns: Array<() => Promise<T> | T>): Promise<Result<T>[]>;
|
|
8
|
-
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, {
|
|
8
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { query, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
9
9
|
export {};
|
|
@@ -68,7 +68,7 @@ function errorHelper(msg, statusCode = 500) {
|
|
|
68
68
|
invariant(statusCode >= 400 && statusCode < 600, 'status code should be 4xx and 5xx');
|
|
69
69
|
throw response(msg, { status: statusCode });
|
|
70
70
|
}
|
|
71
|
-
export function runLoaders(matches, loadersByRouteId, {
|
|
71
|
+
export function runLoaders(matches, loadersByRouteId, { query, req, getAppContext }) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
73
|
if (!matches.length) {
|
|
74
74
|
return [];
|
|
@@ -78,7 +78,7 @@ export function runLoaders(matches, loadersByRouteId, { isServer, query, req, ge
|
|
|
78
78
|
const loaderFn = loadersByRouteId[match.route.id];
|
|
79
79
|
let res;
|
|
80
80
|
try {
|
|
81
|
-
const value = yield loaderFn(Object.assign({
|
|
81
|
+
const value = yield loaderFn(Object.assign({ pathname: match.pathname, params: match.params, query: query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
82
82
|
if (value) {
|
|
83
83
|
res = createJson(value);
|
|
84
84
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ShuviRequest } from '@shuvi/service';
|
|
1
2
|
import { IURLQuery, IURLParams } from '../routerTypes';
|
|
2
|
-
import { IAppContext
|
|
3
|
+
import { IAppContext } from '../applicationTypes';
|
|
3
4
|
import { Response } from '../response';
|
|
4
5
|
export interface LoaderContextOptions {
|
|
5
|
-
|
|
6
|
-
req?: IRequest;
|
|
6
|
+
req?: ShuviRequest;
|
|
7
7
|
query: IURLQuery;
|
|
8
8
|
getAppContext: () => IAppContext;
|
|
9
9
|
}
|
|
@@ -17,10 +17,6 @@ export interface ErrorFunction {
|
|
|
17
17
|
* route component getInitialProps params `context`
|
|
18
18
|
*/
|
|
19
19
|
export interface IRouteLoaderContext {
|
|
20
|
-
/**
|
|
21
|
-
* is running on server, if server is true, client will be false
|
|
22
|
-
*/
|
|
23
|
-
isServer: boolean;
|
|
24
20
|
/**
|
|
25
21
|
* current url path
|
|
26
22
|
*/
|
|
@@ -62,7 +58,7 @@ export interface IRouteLoaderContext {
|
|
|
62
58
|
/**
|
|
63
59
|
* server only
|
|
64
60
|
*/
|
|
65
|
-
req?:
|
|
61
|
+
req?: ShuviRequest;
|
|
66
62
|
/**
|
|
67
63
|
* Application context object, which is accessiable during the entire lifecycle of application
|
|
68
64
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IErrorState, IError } from '../applicationTypes';
|
|
2
|
-
export declare const errorModel: import("@shuvi/redox").
|
|
2
|
+
export declare const errorModel: import("@shuvi/redox/esm/core/defineModel").DefineModel<"error", IErrorState, {
|
|
3
3
|
setError(_state: IErrorState, error?: IError): {
|
|
4
4
|
error: IError | undefined;
|
|
5
5
|
};
|
|
@@ -9,5 +9,5 @@ export declare const errorModel: import("@shuvi/redox").Model<"error", IErrorSta
|
|
|
9
9
|
}, {
|
|
10
10
|
errorObject(): IError | undefined;
|
|
11
11
|
hasError(): boolean;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}>;
|
|
13
13
|
export declare type ErrorModel = typeof errorModel;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface LoaderState {
|
|
2
2
|
dataByRouteId: Record<string, any>;
|
|
3
3
|
}
|
|
4
|
-
export declare const loaderModel: import("@shuvi/redox").
|
|
4
|
+
export declare const loaderModel: import("@shuvi/redox/esm/core/defineModel").DefineModel<"loader", LoaderState, {
|
|
5
5
|
setDatas(state: LoaderState, newData: Record<string, any>): {
|
|
6
6
|
dataByRouteId: {
|
|
7
7
|
[x: string]: any;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
}, import("@shuvi/redox").
|
|
10
|
+
}, import("@shuvi/redox/esm/core/defineModel").ActionOptions, {
|
|
11
11
|
getAllData(): Record<string, any>;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}>;
|
|
13
13
|
export declare type LoaderModel = typeof loaderModel;
|
|
@@ -7,6 +7,8 @@ export interface IPageRouteRecord extends IRouteRecord {
|
|
|
7
7
|
path: string;
|
|
8
8
|
component?: any;
|
|
9
9
|
children?: IPageRouteRecord[];
|
|
10
|
+
__import__?: () => Promise<any>;
|
|
11
|
+
__resolveWeak__?: () => string[];
|
|
10
12
|
__componentSource__?: string;
|
|
11
13
|
__componentRawRequest__?: string;
|
|
12
14
|
[x: string]: any;
|
|
@@ -14,10 +14,8 @@ export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
|
14
14
|
}
|
|
15
15
|
export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRuntimePluginHooks {
|
|
16
16
|
}
|
|
17
|
-
export declare const getManager: () => import("@shuvi/hook").HookManager<
|
|
18
|
-
export declare const
|
|
19
|
-
setup?: import("@shuvi/hook").Setup<CustomRuntimePluginHooks> | undefined;
|
|
20
|
-
}, options?: import("@shuvi/hook").PluginOptions | undefined) => IPluginInstance<BuiltInRuntimePluginHooks & CustomRuntimePluginHooks, void>;
|
|
17
|
+
export declare const getManager: () => import("@shuvi/hook").HookManager<RuntimePluginHooks, void>;
|
|
18
|
+
export declare const createRuntimePluginBefore: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePlugin: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePluginAfter: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>;
|
|
21
19
|
export type { IPluginInstance, CustomRuntimePluginHooks };
|
|
22
20
|
export declare type PluginManager = ReturnType<typeof getManager>;
|
|
23
21
|
export declare type RuntimePluginInstance = IPluginInstance<RuntimePluginHooks, void>;
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { createAsyncParallelHook, createAsyncSeriesWaterfallHook, createHookManager, isPluginInstance } from '@shuvi/hook';
|
|
11
|
+
import { createPluginCreator } from '@shuvi/shared/lib/plugins';
|
|
11
12
|
const init = createAsyncParallelHook();
|
|
12
13
|
const appContext = createAsyncSeriesWaterfallHook();
|
|
13
14
|
const appComponent = createAsyncSeriesWaterfallHook();
|
|
@@ -19,7 +20,7 @@ const builtinRuntimePluginHooks = {
|
|
|
19
20
|
dispose
|
|
20
21
|
};
|
|
21
22
|
export const getManager = () => createHookManager(builtinRuntimePluginHooks, false);
|
|
22
|
-
export const { createPlugin: createRuntimePlugin } = getManager();
|
|
23
|
+
export const { createPluginBefore: createRuntimePluginBefore, createPlugin: createRuntimePlugin, createPluginAfter: createRuntimePluginAfter } = createPluginCreator(getManager());
|
|
23
24
|
export const initPlugins = (pluginManager, plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
25
|
// clear plugin at development mode every time
|
|
25
26
|
if (process.env.NODE_ENV === 'development') {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* import {} from '@shuvi/runtime/app'
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { IAppModule as _IAppModule } from '../shared/
|
|
8
|
+
import { IAppModule as _IAppModule } from '../shared/runtimPlugin';
|
|
9
9
|
declare type AppModule = Required<_IAppModule>;
|
|
10
10
|
export declare type InitFunction = AppModule['init'];
|
|
11
11
|
export declare type AppComponentFunction = AppModule['appComponent'];
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* import {} from '@shuvi/runtime'
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export { createRuntimePlugin } from '../shared/
|
|
8
|
+
export { createRuntimePlugin } from '../shared/runtimPlugin';
|
|
9
9
|
export { getPageData } from '../shared/helper/getPageData';
|
|
10
10
|
export type { Loader } from '../shared/loader';
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
export * from './runtimeFiles';
|
|
2
2
|
export declare const SharedPlugins: {
|
|
3
|
-
core: import("@shuvi/hook").IPluginInstance<
|
|
4
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
5
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
8
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
9
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
10
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
11
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
12
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
13
|
-
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>[]>;
|
|
14
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
15
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
3
|
+
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
|
|
16
4
|
}[];
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
core: import("@shuvi/hook").IPluginInstance<
|
|
3
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
4
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
5
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
8
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
9
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
11
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
12
|
-
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>[]>;
|
|
13
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
2
|
+
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
|
|
15
3
|
};
|
|
16
4
|
export default _default;
|
|
@@ -20,38 +20,17 @@ const invariant_1 = __importDefault(require("@shuvi/utils/lib/invariant"));
|
|
|
20
20
|
const router_1 = require("../../shared/router");
|
|
21
21
|
const supportFileTypes = ['page', 'layout', 'middleware', 'api'];
|
|
22
22
|
const allowReadFilExtList = ['ts', 'js', 'tsx', 'jsx'];
|
|
23
|
-
const dynamicMatchAllRegex =
|
|
24
|
-
const dynamicMatchPartRegex =
|
|
23
|
+
const dynamicMatchAllRegex = /\$$/;
|
|
24
|
+
const dynamicMatchPartRegex = /\$/g;
|
|
25
25
|
function parseDynamicPath(normalizedRoute) {
|
|
26
|
-
(0, invariant_1.default)(!checkSpecialRegexChars(normalizedRoute), 'filePath should not be special regex chars: |\\{}()
|
|
26
|
+
(0, invariant_1.default)(!checkSpecialRegexChars(normalizedRoute), 'filePath should not be special regex chars: |\\{}()^:+*?');
|
|
27
27
|
return normalizedRoute
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
let result = '';
|
|
31
|
-
result = segment.replace(dynamicMatchAllRegex, function (matchString, ...matchArr) {
|
|
32
|
-
return parseMatchRepeat(matchArr[0], true);
|
|
33
|
-
});
|
|
34
|
-
result = result.replace(dynamicMatchPartRegex, function (matchString, ...matchArr) {
|
|
35
|
-
return parseMatchRepeat(matchArr[0], false);
|
|
36
|
-
});
|
|
37
|
-
return `${result}`;
|
|
38
|
-
})
|
|
39
|
-
.join('/');
|
|
28
|
+
.replace(dynamicMatchAllRegex, '*')
|
|
29
|
+
.replace(dynamicMatchPartRegex, ':');
|
|
40
30
|
}
|
|
41
31
|
exports.parseDynamicPath = parseDynamicPath;
|
|
42
|
-
function parseMatchRepeat(param, optional) {
|
|
43
|
-
const repeat = param.startsWith('...');
|
|
44
|
-
if (repeat) {
|
|
45
|
-
param = param.slice(3);
|
|
46
|
-
}
|
|
47
|
-
return repeat
|
|
48
|
-
? optional
|
|
49
|
-
? `:${param}*`
|
|
50
|
-
: `:${param}+`
|
|
51
|
-
: `:${param}${optional ? '?' : ''}`;
|
|
52
|
-
}
|
|
53
32
|
function checkSpecialRegexChars(string) {
|
|
54
|
-
return /[|\\{}()
|
|
33
|
+
return /[|\\{}()^:+*?]/g.test(string);
|
|
55
34
|
}
|
|
56
35
|
function normalizeRoutePath(rawPath) {
|
|
57
36
|
let routePath = rawPath
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { RedoxStore, IApplication, IAppContext, IApplicationOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class Application {
|
|
4
4
|
private _router;
|
|
5
5
|
private _appComponent;
|
|
@@ -11,7 +11,7 @@ export declare class Application {
|
|
|
11
11
|
constructor(options: IApplicationOptions);
|
|
12
12
|
get router(): IRouter<IPageRouteRecord>;
|
|
13
13
|
get context(): IAppContext;
|
|
14
|
-
get pluginManager(): import("@shuvi/hook").HookManager<import("./
|
|
14
|
+
get pluginManager(): import("@shuvi/hook").HookManager<import("./runtimPlugin").RuntimePluginHooks, void>;
|
|
15
15
|
get appComponent(): any;
|
|
16
16
|
get error(): IError | undefined;
|
|
17
17
|
setError(err: IError): void;
|
|
@@ -19,7 +19,7 @@ export declare class Application {
|
|
|
19
19
|
getLoadersData(): Record<string, any>;
|
|
20
20
|
setLoadersData(datas: Record<string, any>): void;
|
|
21
21
|
init(): Promise<void>;
|
|
22
|
-
get store():
|
|
22
|
+
get store(): RedoxStore;
|
|
23
23
|
updateComponents({ AppComponent }?: IRerenderConfig): Promise<void>;
|
|
24
24
|
dispose(): Promise<void>;
|
|
25
25
|
private _initPlugin;
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Application = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const runtimPlugin_1 = require("./runtimPlugin");
|
|
14
|
+
const runtimPlugin_2 = require("./runtimPlugin");
|
|
15
15
|
const redox_1 = require("@shuvi/redox");
|
|
16
16
|
const error_1 = require("./models/error");
|
|
17
17
|
const loader_1 = require("./models/loader");
|
|
@@ -20,11 +20,11 @@ class Application {
|
|
|
20
20
|
this._router = options.router;
|
|
21
21
|
this._context = {};
|
|
22
22
|
this._store = (0, redox_1.redox)({ initialState: options.initialState });
|
|
23
|
-
this._error = this._store.
|
|
24
|
-
this._loader = this._store.
|
|
23
|
+
this._error = this._store.getModel(error_1.errorModel);
|
|
24
|
+
this._loader = this._store.getModel(loader_1.loaderModel);
|
|
25
25
|
this._appComponent = options.AppComponent;
|
|
26
|
-
this._pluginManager = (0,
|
|
27
|
-
(0,
|
|
26
|
+
this._pluginManager = (0, runtimPlugin_1.getManager)();
|
|
27
|
+
(0, runtimPlugin_2.initPlugins)(this._pluginManager, options.plugins || []);
|
|
28
28
|
}
|
|
29
29
|
get router() {
|
|
30
30
|
return this._router;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IncomingMessage } from 'http';
|
|
3
|
-
import { IStoreManager } from '@shuvi/redox';
|
|
1
|
+
import { RedoxStore } from '@shuvi/redox';
|
|
4
2
|
import { CustomAppContext } from '@shuvi/runtime';
|
|
5
3
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
6
|
-
import { IPluginList } from './
|
|
7
|
-
export declare type IRequest = IncomingMessage & {
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
};
|
|
4
|
+
import { IPluginList } from './runtimPlugin';
|
|
10
5
|
export interface IAppContext extends CustomAppContext {
|
|
11
6
|
[x: string]: unknown;
|
|
12
7
|
}
|
|
13
8
|
export declare type IRerenderConfig = {
|
|
14
9
|
AppComponent?: any;
|
|
15
10
|
};
|
|
16
|
-
export type {
|
|
11
|
+
export type { RedoxStore };
|
|
12
|
+
export declare type ErrorSource = 'server';
|
|
17
13
|
export interface IError {
|
|
18
14
|
code?: number;
|
|
19
15
|
message?: string;
|
|
16
|
+
stack?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
source?: ErrorSource;
|
|
20
19
|
}
|
|
21
20
|
export interface IErrorState {
|
|
22
21
|
error?: IError;
|
|
@@ -28,7 +27,7 @@ export interface IApplication {
|
|
|
28
27
|
readonly context: IAppContext;
|
|
29
28
|
readonly router: IRouter<IPageRouteRecord>;
|
|
30
29
|
readonly appComponent: any;
|
|
31
|
-
readonly store:
|
|
30
|
+
readonly store: RedoxStore;
|
|
32
31
|
readonly error: IError | undefined;
|
|
33
32
|
setError(err: IError): void;
|
|
34
33
|
clearError(): void;
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export { loaderModel } from './models/loader';
|
|
|
8
8
|
export * from './applicationTypes';
|
|
9
9
|
export type { Application } from './application';
|
|
10
10
|
export type { IRuntimeConfig } from './runtimeConfigTypes';
|
|
11
|
-
export { IAppModule, IPluginInstance, BuiltInRuntimePluginHooks, CustomRuntimePluginHooks, RuntimePluginHooks, createRuntimePlugin, RuntimePluginInstance } from './
|
|
11
|
+
export { IAppModule, IPluginInstance, BuiltInRuntimePluginHooks, CustomRuntimePluginHooks, RuntimePluginHooks, createRuntimePlugin, createRuntimePluginBefore, createRuntimePluginAfter, RuntimePluginInstance } from './runtimPlugin';
|
package/lib/shared/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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.createRuntimePlugin = exports.loaderModel = exports.errorModel = void 0;
|
|
17
|
+
exports.createRuntimePluginAfter = exports.createRuntimePluginBefore = exports.createRuntimePlugin = exports.loaderModel = exports.errorModel = void 0;
|
|
18
18
|
__exportStar(require("./helper"), exports);
|
|
19
19
|
__exportStar(require("./routerTypes"), exports);
|
|
20
20
|
__exportStar(require("./router"), exports);
|
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "errorModel", { enumerable: true, get: function (
|
|
|
25
25
|
var loader_1 = require("./models/loader");
|
|
26
26
|
Object.defineProperty(exports, "loaderModel", { enumerable: true, get: function () { return loader_1.loaderModel; } });
|
|
27
27
|
__exportStar(require("./applicationTypes"), exports);
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "
|
|
28
|
+
var runtimPlugin_1 = require("./runtimPlugin");
|
|
29
|
+
Object.defineProperty(exports, "createRuntimePlugin", { enumerable: true, get: function () { return runtimPlugin_1.createRuntimePlugin; } });
|
|
30
|
+
Object.defineProperty(exports, "createRuntimePluginBefore", { enumerable: true, get: function () { return runtimPlugin_1.createRuntimePluginBefore; } });
|
|
31
|
+
Object.defineProperty(exports, "createRuntimePluginAfter", { enumerable: true, get: function () { return runtimPlugin_1.createRuntimePluginAfter; } });
|
|
@@ -5,5 +5,5 @@ interface Result<T> {
|
|
|
5
5
|
result?: T;
|
|
6
6
|
}
|
|
7
7
|
export declare function runInParallerAndBail<T>(fns: Array<() => Promise<T> | T>): Promise<Result<T>[]>;
|
|
8
|
-
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, {
|
|
8
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { query, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
9
9
|
export {};
|
|
@@ -75,7 +75,7 @@ function errorHelper(msg, statusCode = 500) {
|
|
|
75
75
|
(0, invariant_1.default)(statusCode >= 400 && statusCode < 600, 'status code should be 4xx and 5xx');
|
|
76
76
|
throw (0, response_1.response)(msg, { status: statusCode });
|
|
77
77
|
}
|
|
78
|
-
function runLoaders(matches, loadersByRouteId, {
|
|
78
|
+
function runLoaders(matches, loadersByRouteId, { query, req, getAppContext }) {
|
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
80
|
if (!matches.length) {
|
|
81
81
|
return [];
|
|
@@ -85,7 +85,7 @@ function runLoaders(matches, loadersByRouteId, { isServer, query, req, getAppCon
|
|
|
85
85
|
const loaderFn = loadersByRouteId[match.route.id];
|
|
86
86
|
let res;
|
|
87
87
|
try {
|
|
88
|
-
const value = yield loaderFn(Object.assign({
|
|
88
|
+
const value = yield loaderFn(Object.assign({ pathname: match.pathname, params: match.params, query: query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
89
89
|
if (value) {
|
|
90
90
|
res = (0, response_1.json)(value);
|
|
91
91
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ShuviRequest } from '@shuvi/service';
|
|
1
2
|
import { IURLQuery, IURLParams } from '../routerTypes';
|
|
2
|
-
import { IAppContext
|
|
3
|
+
import { IAppContext } from '../applicationTypes';
|
|
3
4
|
import { Response } from '../response';
|
|
4
5
|
export interface LoaderContextOptions {
|
|
5
|
-
|
|
6
|
-
req?: IRequest;
|
|
6
|
+
req?: ShuviRequest;
|
|
7
7
|
query: IURLQuery;
|
|
8
8
|
getAppContext: () => IAppContext;
|
|
9
9
|
}
|
|
@@ -17,10 +17,6 @@ export interface ErrorFunction {
|
|
|
17
17
|
* route component getInitialProps params `context`
|
|
18
18
|
*/
|
|
19
19
|
export interface IRouteLoaderContext {
|
|
20
|
-
/**
|
|
21
|
-
* is running on server, if server is true, client will be false
|
|
22
|
-
*/
|
|
23
|
-
isServer: boolean;
|
|
24
20
|
/**
|
|
25
21
|
* current url path
|
|
26
22
|
*/
|
|
@@ -62,7 +58,7 @@ export interface IRouteLoaderContext {
|
|
|
62
58
|
/**
|
|
63
59
|
* server only
|
|
64
60
|
*/
|
|
65
|
-
req?:
|
|
61
|
+
req?: ShuviRequest;
|
|
66
62
|
/**
|
|
67
63
|
* Application context object, which is accessiable during the entire lifecycle of application
|
|
68
64
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IErrorState, IError } from '../applicationTypes';
|
|
2
|
-
export declare const errorModel: import("@shuvi/redox").
|
|
2
|
+
export declare const errorModel: import("@shuvi/redox/esm/core/defineModel").DefineModel<"error", IErrorState, {
|
|
3
3
|
setError(_state: IErrorState, error?: IError): {
|
|
4
4
|
error: IError | undefined;
|
|
5
5
|
};
|
|
@@ -9,5 +9,5 @@ export declare const errorModel: import("@shuvi/redox").Model<"error", IErrorSta
|
|
|
9
9
|
}, {
|
|
10
10
|
errorObject(): IError | undefined;
|
|
11
11
|
hasError(): boolean;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}>;
|
|
13
13
|
export declare type ErrorModel = typeof errorModel;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface LoaderState {
|
|
2
2
|
dataByRouteId: Record<string, any>;
|
|
3
3
|
}
|
|
4
|
-
export declare const loaderModel: import("@shuvi/redox").
|
|
4
|
+
export declare const loaderModel: import("@shuvi/redox/esm/core/defineModel").DefineModel<"loader", LoaderState, {
|
|
5
5
|
setDatas(state: LoaderState, newData: Record<string, any>): {
|
|
6
6
|
dataByRouteId: {
|
|
7
7
|
[x: string]: any;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
}, import("@shuvi/redox").
|
|
10
|
+
}, import("@shuvi/redox/esm/core/defineModel").ActionOptions, {
|
|
11
11
|
getAllData(): Record<string, any>;
|
|
12
|
-
}>;
|
|
12
|
+
}, {}>;
|
|
13
13
|
export declare type LoaderModel = typeof loaderModel;
|
|
@@ -7,6 +7,8 @@ export interface IPageRouteRecord extends IRouteRecord {
|
|
|
7
7
|
path: string;
|
|
8
8
|
component?: any;
|
|
9
9
|
children?: IPageRouteRecord[];
|
|
10
|
+
__import__?: () => Promise<any>;
|
|
11
|
+
__resolveWeak__?: () => string[];
|
|
10
12
|
__componentSource__?: string;
|
|
11
13
|
__componentRawRequest__?: string;
|
|
12
14
|
[x: string]: any;
|
|
@@ -14,10 +14,8 @@ export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
|
14
14
|
}
|
|
15
15
|
export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRuntimePluginHooks {
|
|
16
16
|
}
|
|
17
|
-
export declare const getManager: () => import("@shuvi/hook").HookManager<
|
|
18
|
-
export declare const
|
|
19
|
-
setup?: import("@shuvi/hook").Setup<CustomRuntimePluginHooks> | undefined;
|
|
20
|
-
}, options?: import("@shuvi/hook").PluginOptions | undefined) => IPluginInstance<BuiltInRuntimePluginHooks & CustomRuntimePluginHooks, void>;
|
|
17
|
+
export declare const getManager: () => import("@shuvi/hook").HookManager<RuntimePluginHooks, void>;
|
|
18
|
+
export declare const createRuntimePluginBefore: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePlugin: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePluginAfter: import("@shuvi/shared/lib/plugins").PluginFunc<RuntimePluginHooks, void>;
|
|
21
19
|
export type { IPluginInstance, CustomRuntimePluginHooks };
|
|
22
20
|
export declare type PluginManager = ReturnType<typeof getManager>;
|
|
23
21
|
export declare type RuntimePluginInstance = IPluginInstance<RuntimePluginHooks, void>;
|
|
@@ -8,9 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var _a;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.initPlugins = exports.createRuntimePlugin = exports.getManager = void 0;
|
|
13
|
+
exports.initPlugins = exports.createRuntimePluginAfter = exports.createRuntimePlugin = exports.createRuntimePluginBefore = exports.getManager = void 0;
|
|
13
14
|
const hook_1 = require("@shuvi/hook");
|
|
15
|
+
const plugins_1 = require("@shuvi/shared/lib/plugins");
|
|
14
16
|
const init = (0, hook_1.createAsyncParallelHook)();
|
|
15
17
|
const appContext = (0, hook_1.createAsyncSeriesWaterfallHook)();
|
|
16
18
|
const appComponent = (0, hook_1.createAsyncSeriesWaterfallHook)();
|
|
@@ -23,7 +25,7 @@ const builtinRuntimePluginHooks = {
|
|
|
23
25
|
};
|
|
24
26
|
const getManager = () => (0, hook_1.createHookManager)(builtinRuntimePluginHooks, false);
|
|
25
27
|
exports.getManager = getManager;
|
|
26
|
-
|
|
28
|
+
_a = (0, plugins_1.createPluginCreator)((0, exports.getManager)()), exports.createRuntimePluginBefore = _a.createPluginBefore, exports.createRuntimePlugin = _a.createPlugin, exports.createRuntimePluginAfter = _a.createPluginAfter;
|
|
27
29
|
const initPlugins = (pluginManager, plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
30
|
// clear plugin at development mode every time
|
|
29
31
|
if (process.env.NODE_ENV === 'development') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -82,18 +82,18 @@
|
|
|
82
82
|
"node": ">= 12.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@shuvi/hook": "1.0.0-rc.
|
|
86
|
-
"@shuvi/redox": "0.0.
|
|
87
|
-
"@shuvi/router": "1.0.0-rc.
|
|
88
|
-
"@shuvi/runtime": "1.0.0-rc.
|
|
89
|
-
"@shuvi/service": "1.0.0-rc.
|
|
90
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
91
|
-
"@shuvi/toolpack": "1.0.0-rc.
|
|
92
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
85
|
+
"@shuvi/hook": "1.0.0-rc.8",
|
|
86
|
+
"@shuvi/redox": "0.0.6",
|
|
87
|
+
"@shuvi/router": "1.0.0-rc.8",
|
|
88
|
+
"@shuvi/runtime": "1.0.0-rc.8",
|
|
89
|
+
"@shuvi/service": "1.0.0-rc.8",
|
|
90
|
+
"@shuvi/shared": "1.0.0-rc.8",
|
|
91
|
+
"@shuvi/toolpack": "1.0.0-rc.8",
|
|
92
|
+
"@shuvi/utils": "1.0.0-rc.8",
|
|
93
93
|
"redux": "4.1.2"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@shuvi/service": "1.0.0-rc.
|
|
96
|
+
"@shuvi/service": "1.0.0-rc.8"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@types/minimatch": "3.0.5"
|