@shuvi/platform-shared 1.0.55 → 1.0.56
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 +1 -1
- package/esm/shared/application.js +2 -2
- package/esm/shared/applicationTypes.d.ts +5 -5
- package/esm/shared/helper/getAppData.d.ts +2 -3
- package/esm/shared/helper/getFilesOfRoute.d.ts +2 -2
- package/esm/shared/loader/types.d.ts +4 -4
- package/esm/shared/models/error.d.ts +1 -1
- package/esm/shared/models/loader.d.ts +1 -1
- package/esm/shared/response.d.ts +3 -3
- package/esm/shared/routerTypes.d.ts +4 -4
- package/esm/shared/runtimPlugin.d.ts +13 -13
- package/esm/shared/runtimeConfigTypes.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-app.d.ts +5 -5
- package/lib/node/platform/index.d.ts +1 -1
- package/lib/node/platform/plugins/main/index.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/entry.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/error.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/platform.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/runtimeConfig.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/setRuntimeConfig.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/app.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/error.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/server.js.d.ts +1 -1
- package/lib/node/project/file-presets/index.d.ts +1 -1
- package/lib/node/project/file-presets/index.js +2 -2
- package/lib/node/route/helpers.d.ts +4 -4
- package/lib/node/route/helpers.js +5 -5
- package/lib/node/route/matchSpec.d.ts +1 -1
- package/lib/node/route/matchSpec.js +5 -6
- package/lib/node/route/route.d.ts +14 -14
- package/lib/node/route/route.js +4 -4
- package/lib/shared/application.d.ts +1 -1
- package/lib/shared/application.js +2 -2
- package/lib/shared/applicationTypes.d.ts +5 -5
- package/lib/shared/helper/getAppData.d.ts +2 -3
- package/lib/shared/helper/getAppData.js +1 -2
- package/lib/shared/helper/getFilesOfRoute.d.ts +2 -2
- package/lib/shared/helper/getFilesOfRoute.js +1 -2
- package/lib/shared/helper/getPageData.js +1 -2
- package/lib/shared/helper/getPublicPath.js +1 -2
- package/lib/shared/helper/router.js +2 -3
- package/lib/shared/loader/loader.js +3 -4
- package/lib/shared/loader/types.d.ts +4 -4
- package/lib/shared/models/error.d.ts +1 -1
- package/lib/shared/models/loader.d.ts +1 -1
- package/lib/shared/response.d.ts +3 -3
- package/lib/shared/response.js +5 -5
- package/lib/shared/routerTypes.d.ts +4 -4
- package/lib/shared/runtimPlugin.d.ts +13 -13
- package/lib/shared/runtimeConfigTypes.d.ts +1 -1
- package/lib/shared/shuvi-singleton-runtimeConfig.js +5 -6
- package/package.json +8 -8
|
@@ -20,7 +20,7 @@ export declare class ApplicationImpl<Config extends {} = {}> {
|
|
|
20
20
|
get error(): IError | null;
|
|
21
21
|
setError(err: IError): void;
|
|
22
22
|
clearError(): void;
|
|
23
|
-
getLoaders(): Promise<Record<string, import("./
|
|
23
|
+
getLoaders(): Promise<Record<string, import("./loader").Loader>>;
|
|
24
24
|
getLoadersData(): Record<string, any>;
|
|
25
25
|
setLoadersData(datas: Record<string, any>): void;
|
|
26
26
|
init(): Promise<void>;
|
|
@@ -70,8 +70,8 @@ export class ApplicationImpl {
|
|
|
70
70
|
get store() {
|
|
71
71
|
return this._store;
|
|
72
72
|
}
|
|
73
|
-
updateComponents(
|
|
74
|
-
return __awaiter(this,
|
|
73
|
+
updateComponents() {
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* ({ AppComponent } = {}) {
|
|
75
75
|
if (AppComponent && AppComponent !== this._appComponent) {
|
|
76
76
|
this._appComponent = AppComponent;
|
|
77
77
|
}
|
|
@@ -4,15 +4,15 @@ import type { ShuviRequest } from '@shuvi/service';
|
|
|
4
4
|
import { IRouter } from './routerTypes';
|
|
5
5
|
import { IPluginList } from './runtimPlugin';
|
|
6
6
|
import { Loader } from './loader';
|
|
7
|
-
export
|
|
7
|
+
export type Loaders = Record<string, Loader>;
|
|
8
8
|
export interface IAppContext extends CustomAppContext {
|
|
9
9
|
[x: string]: unknown;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type IRerenderConfig = {
|
|
12
12
|
AppComponent?: any;
|
|
13
13
|
};
|
|
14
14
|
export type { Doura };
|
|
15
|
-
export
|
|
15
|
+
export type ErrorSource = 'server';
|
|
16
16
|
export interface IError {
|
|
17
17
|
code?: number;
|
|
18
18
|
message?: string;
|
|
@@ -23,7 +23,7 @@ export interface IError {
|
|
|
23
23
|
export interface IErrorState {
|
|
24
24
|
error: IError | null;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type IAppState = {
|
|
27
27
|
error: IErrorState;
|
|
28
28
|
};
|
|
29
29
|
export interface Application<Config extends {} = {}> {
|
|
@@ -50,4 +50,4 @@ export interface ApplicationInternalOptions<C extends {}> {
|
|
|
50
50
|
plugins?: IPluginList;
|
|
51
51
|
request?: ShuviRequest;
|
|
52
52
|
}
|
|
53
|
-
export
|
|
53
|
+
export type ApplicationlOptions<C extends {}> = Omit<ApplicationInternalOptions<C>, 'getLoaders' | 'plugins'>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type IData = {
|
|
1
|
+
export type IData = {
|
|
3
2
|
[k: string]: string | number | boolean | undefined | null;
|
|
4
3
|
};
|
|
5
|
-
export
|
|
4
|
+
export type IAppData<Data = {}, appState = any> = {
|
|
6
5
|
ssr: boolean;
|
|
7
6
|
basename?: string;
|
|
8
7
|
runtimeConfig?: Record<string, string>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IRouter, PathRecord } from '../routerTypes';
|
|
2
|
-
export
|
|
2
|
+
export type RouteFile = {
|
|
3
3
|
id: string;
|
|
4
4
|
url: string;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type RouteFiles = {
|
|
7
7
|
js: RouteFile[];
|
|
8
8
|
css: RouteFile[];
|
|
9
9
|
};
|
|
@@ -9,7 +9,7 @@ export interface LoaderContextOptions {
|
|
|
9
9
|
params: IRouteLoaderContext['params'];
|
|
10
10
|
getAppContext: () => IAppContext;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type RedirectFunction = (to: string, status?: number) => any;
|
|
13
13
|
export interface ErrorFunction {
|
|
14
14
|
(): any;
|
|
15
15
|
(msg: string): any;
|
|
@@ -68,6 +68,6 @@ export interface IRouteLoaderContext {
|
|
|
68
68
|
*/
|
|
69
69
|
appContext: IAppContext;
|
|
70
70
|
}
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
export
|
|
71
|
+
export type Loader<T = any> = (loaderContext: IRouteLoaderContext) => Promise<T> | T;
|
|
72
|
+
export type NormalizedLoader = (loaderContext: IRouteLoaderContext) => Promise<Response | undefined>;
|
|
73
|
+
export type LoaderDataRecord = Record<string, any>;
|
package/esm/shared/response.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type HeaderRecord = Record<string, string>;
|
|
2
|
+
type HeaderArray = [string, string][];
|
|
3
3
|
export interface ResponseOptions {
|
|
4
4
|
status?: number;
|
|
5
5
|
statusText?: string;
|
|
@@ -33,7 +33,7 @@ declare class Headers {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export
|
|
36
|
+
export type ResponseType = 'text' | 'json' | 'redirect' | 'raw';
|
|
37
37
|
export interface Response {
|
|
38
38
|
readonly data: any;
|
|
39
39
|
readonly status: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ParsedQuery, IParams, IRouteRecord } from '@shuvi/router';
|
|
2
2
|
import { IRouter as IRouter_, IRoute, IRouteMatch, PathRecord } from '@shuvi/router';
|
|
3
3
|
export { IRoute, IRouteMatch, PathRecord };
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type IURLQuery = ParsedQuery;
|
|
5
|
+
export type IURLParams = IParams;
|
|
6
|
+
export type IRouter = IRouter_<IPageRouteRecord>;
|
|
7
7
|
export interface IPageRouteRecord extends IRouteRecord {
|
|
8
8
|
id: string;
|
|
9
9
|
path: string;
|
|
@@ -21,7 +21,7 @@ export interface IPlatformConfig {
|
|
|
21
21
|
target?: string;
|
|
22
22
|
[index: string]: any;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type IRouterHistoryMode = 'browser' | 'hash' | 'memory';
|
|
25
25
|
export interface IPageRouteConfig {
|
|
26
26
|
children?: IPageRouteConfig[];
|
|
27
27
|
name?: string;
|
|
@@ -3,8 +3,8 @@ import type { ShuviRequest } from '@shuvi/service';
|
|
|
3
3
|
import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
4
4
|
import { IAppContext } from './applicationTypes';
|
|
5
5
|
import { IRouter } from './routerTypes';
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export type AppComponent = unknown;
|
|
7
|
+
export type AppContextCtx = {
|
|
8
8
|
router: IRouter;
|
|
9
9
|
req?: ShuviRequest;
|
|
10
10
|
};
|
|
@@ -23,28 +23,28 @@ export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRun
|
|
|
23
23
|
export declare const getManager: () => import("@shuvi/hook").HookManager<RuntimePluginHooks, void>;
|
|
24
24
|
export declare const createRuntimePluginBefore: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePlugin: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePluginAfter: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>;
|
|
25
25
|
export type { IPluginInstance, CustomRuntimePluginHooks };
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
26
|
+
export type PluginManager = ReturnType<typeof getManager>;
|
|
27
|
+
export type RuntimePluginInstance = IPluginInstance<RuntimePluginHooks, void>;
|
|
28
|
+
export type IRuntimePluginConstructor = IPluginHandlers<RuntimePluginHooks, void>;
|
|
29
|
+
export type IAppModule = {
|
|
30
30
|
init?: IRuntimePluginConstructor['init'];
|
|
31
31
|
appContext?: IRuntimePluginConstructor['appContext'];
|
|
32
32
|
appComponent?: IRuntimePluginConstructor['appComponent'];
|
|
33
33
|
dispose?: IRuntimePluginConstructor['dispose'];
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
35
|
+
type SerializedPluginOptions = string;
|
|
36
|
+
export type IRuntimePluginOptions = Record<string, unknown>;
|
|
37
|
+
export type IRuntimePluginWithOptions = (...params: any[]) => RuntimePluginInstance;
|
|
38
|
+
export type IRuntimePlugin = RuntimePluginInstance | IRuntimePluginWithOptions;
|
|
39
|
+
export type IPluginModule = {
|
|
40
40
|
plugin: IRuntimePlugin;
|
|
41
41
|
pluginOptions: IRuntimePluginOptions;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export type IPluginRecord = {
|
|
44
44
|
[name: string]: {
|
|
45
45
|
plugin: IRuntimePlugin;
|
|
46
46
|
options: SerializedPluginOptions;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
export
|
|
49
|
+
export type IPluginList = [IRuntimePlugin, SerializedPluginOptions?][];
|
|
50
50
|
export declare const initPlugins: (pluginManager: PluginManager, plugins: IPluginList) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type IRuntimeConfig = Record<string, any>;
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { IAppModule as _IAppModule } from '../shared/runtimPlugin';
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
9
|
+
type AppModule = Required<_IAppModule>;
|
|
10
|
+
export type InitFunction = AppModule['init'];
|
|
11
|
+
export type AppComponentFunction = AppModule['appComponent'];
|
|
12
|
+
export type AppContextFunction = AppModule['appContext'];
|
|
13
|
+
export type DisposeFunction = AppModule['dispose'];
|
|
14
14
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './runtimeFiles';
|
|
2
2
|
export declare const SharedPlugins: {
|
|
3
|
-
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core
|
|
3
|
+
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core").PluginHooks, import("@shuvi/service").IPluginContext>;
|
|
4
4
|
}[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core
|
|
2
|
+
core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core").PluginHooks, import("@shuvi/service").IPluginContext>;
|
|
3
3
|
};
|
|
4
4
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => Omit<import("@shuvi/service/lib/project
|
|
1
|
+
declare const _default: () => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => Omit<import("@shuvi/service/lib/project
|
|
1
|
+
declare const _default: () => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOption, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FileOptionWithId, FileOption } from '@shuvi/service/lib/project';
|
|
2
2
|
import { ProjectContext } from '../projectContext';
|
|
3
3
|
export declare function getFilePresets(context: ProjectContext): FileOptionWithId<any>[];
|
|
4
|
-
export declare const defineFile: (options: Omit<FileOption,
|
|
4
|
+
export declare const defineFile: (options: Omit<FileOption, "name">) => Omit<FileOption, "name">;
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.defineFile =
|
|
26
|
+
exports.defineFile = void 0;
|
|
27
|
+
exports.getFilePresets = getFilePresets;
|
|
27
28
|
const fs = __importStar(require("fs"));
|
|
28
29
|
const path = __importStar(require("path"));
|
|
29
30
|
const project_1 = require("@shuvi/service/lib/project");
|
|
@@ -53,6 +54,5 @@ const getAllFiles = (context, dirPath, parent = '', fileList = []) => {
|
|
|
53
54
|
function getFilePresets(context) {
|
|
54
55
|
return getAllFiles(context, path.join(__dirname, 'files'));
|
|
55
56
|
}
|
|
56
|
-
exports.getFilePresets = getFilePresets;
|
|
57
57
|
const defineFile = (options) => options;
|
|
58
58
|
exports.defineFile = defineFile;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare const supportFileTypes: readonly ["page", "layout", "middleware", "api"];
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type GetArrayElementType<T extends readonly any[]> = T extends readonly any[] ? T[number] : never;
|
|
3
|
+
export type SupportFileType = GetArrayElementType<typeof supportFileTypes>;
|
|
4
|
+
type CapName = Capitalize<SupportFileType>;
|
|
5
|
+
type FileTypeChecker = Record<`is${CapName}`, (filename: string) => boolean>;
|
|
6
6
|
export declare function parseDynamicPath(normalizedRoute: string): string;
|
|
7
7
|
export declare function normalizeRoutePath(rawPath: string): string;
|
|
8
8
|
export declare function combineComponents(fisrt: string, sec: string): string;
|
|
@@ -12,7 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.fileTypeChecker = exports.hasRouteChildren = exports.readDir = exports.getAllowFilesAndDirs = exports.isRouteFile = void 0;
|
|
16
|
+
exports.parseDynamicPath = parseDynamicPath;
|
|
17
|
+
exports.normalizeRoutePath = normalizeRoutePath;
|
|
18
|
+
exports.combineComponents = combineComponents;
|
|
19
|
+
exports.sortRoutes = sortRoutes;
|
|
16
20
|
const fs_1 = __importDefault(require("fs"));
|
|
17
21
|
const path_1 = require("path");
|
|
18
22
|
const file_1 = require("@shuvi/utils/file");
|
|
@@ -28,7 +32,6 @@ function parseDynamicPath(normalizedRoute) {
|
|
|
28
32
|
.replace(dynamicMatchAllRegex, '*')
|
|
29
33
|
.replace(dynamicMatchPartRegex, ':');
|
|
30
34
|
}
|
|
31
|
-
exports.parseDynamicPath = parseDynamicPath;
|
|
32
35
|
function checkSpecialRegexChars(string) {
|
|
33
36
|
return /[|\\{}()^:+*?]/g.test(string);
|
|
34
37
|
}
|
|
@@ -48,7 +51,6 @@ function normalizeRoutePath(rawPath) {
|
|
|
48
51
|
routePath = parseDynamicPath(routePath);
|
|
49
52
|
return routePath;
|
|
50
53
|
}
|
|
51
|
-
exports.normalizeRoutePath = normalizeRoutePath;
|
|
52
54
|
function combineComponents(fisrt, sec) {
|
|
53
55
|
if (fisrt === '' || sec === '') {
|
|
54
56
|
return `${fisrt}${sec}`;
|
|
@@ -68,7 +70,6 @@ function combineComponents(fisrt, sec) {
|
|
|
68
70
|
return `${fisrt}/${sec}`;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
exports.combineComponents = combineComponents;
|
|
72
73
|
const isRouteFile = (file) => {
|
|
73
74
|
return Object.keys(fileTypeChecker).some(key => {
|
|
74
75
|
return fileTypeChecker[key](file);
|
|
@@ -179,4 +180,3 @@ function sortRoutes(routes) {
|
|
|
179
180
|
return rankRoute[1];
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
|
-
exports.sortRoutes = sortRoutes;
|
|
@@ -2,7 +2,7 @@ export interface FileMatcherPatterns {
|
|
|
2
2
|
includePattern: string | undefined;
|
|
3
3
|
excludePattern: string | undefined;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export type Usage = 'include' | 'exclude';
|
|
6
6
|
export declare function getRegularExpressionsForWildcards(specs: readonly string[] | undefined, basePath: string, usage: Usage): readonly string[] | undefined;
|
|
7
7
|
export declare function getRegularExpressionForWildcard(specs: readonly string[] | undefined, basePath: string, usage: Usage): string | undefined;
|
|
8
8
|
export declare function getRegexFromPattern(pattern: string, caseSensitive: boolean): RegExp;
|
|
@@ -23,7 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.getRegularExpressionsForWildcards = getRegularExpressionsForWildcards;
|
|
27
|
+
exports.getRegularExpressionForWildcard = getRegularExpressionForWildcard;
|
|
28
|
+
exports.getRegexFromPattern = getRegexFromPattern;
|
|
29
|
+
exports.getFileMatcherPatterns = getFileMatcherPatterns;
|
|
30
|
+
exports.matchesSpecs = matchesSpecs;
|
|
27
31
|
// port from typescript
|
|
28
32
|
const nodePath = __importStar(require("path"));
|
|
29
33
|
const CharacterCodes = {
|
|
@@ -151,7 +155,6 @@ function getRegularExpressionsForWildcards(specs, basePath, usage) {
|
|
|
151
155
|
}
|
|
152
156
|
return result;
|
|
153
157
|
}
|
|
154
|
-
exports.getRegularExpressionsForWildcards = getRegularExpressionsForWildcards;
|
|
155
158
|
function getRegularExpressionForWildcard(specs, basePath, usage) {
|
|
156
159
|
const patterns = getRegularExpressionsForWildcards(specs, basePath, usage);
|
|
157
160
|
if (!patterns || !patterns.length) {
|
|
@@ -162,11 +165,9 @@ function getRegularExpressionForWildcard(specs, basePath, usage) {
|
|
|
162
165
|
const terminator = usage === 'exclude' ? '($|/)' : '$';
|
|
163
166
|
return `^(${pattern})${terminator}`;
|
|
164
167
|
}
|
|
165
|
-
exports.getRegularExpressionForWildcard = getRegularExpressionForWildcard;
|
|
166
168
|
function getRegexFromPattern(pattern, caseSensitive) {
|
|
167
169
|
return new RegExp(pattern, caseSensitive ? '' : 'i');
|
|
168
170
|
}
|
|
169
|
-
exports.getRegexFromPattern = getRegexFromPattern;
|
|
170
171
|
function getFileMatcherPatterns(basePath, includes, excludes) {
|
|
171
172
|
const absolutePath = normalizePath(basePath);
|
|
172
173
|
return {
|
|
@@ -174,7 +175,6 @@ function getFileMatcherPatterns(basePath, includes, excludes) {
|
|
|
174
175
|
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, 'exclude')
|
|
175
176
|
};
|
|
176
177
|
}
|
|
177
|
-
exports.getFileMatcherPatterns = getFileMatcherPatterns;
|
|
178
178
|
function matchesSpecs(basePath, { includes, excludes, caseSensitive }) {
|
|
179
179
|
const patterns = getFileMatcherPatterns(basePath, includes, excludes);
|
|
180
180
|
const includeRegex = patterns.includePattern &&
|
|
@@ -192,4 +192,3 @@ function matchesSpecs(basePath, { includes, excludes, caseSensitive }) {
|
|
|
192
192
|
}
|
|
193
193
|
return () => true;
|
|
194
194
|
}
|
|
195
|
-
exports.matchesSpecs = matchesSpecs;
|
|
@@ -13,7 +13,7 @@ export interface RawDirRoute {
|
|
|
13
13
|
segment: string;
|
|
14
14
|
children: (RawFileRoute | RawDirRoute)[];
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type RawRoute = RawFileRoute | RawDirRoute;
|
|
17
17
|
export interface RouteException {
|
|
18
18
|
type: SupportFileType | 'dir';
|
|
19
19
|
msg: string;
|
|
@@ -23,24 +23,24 @@ export interface RouteResult<T> {
|
|
|
23
23
|
errors: RouteException[];
|
|
24
24
|
routes: T[];
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
26
|
+
export type RawRoutes = RouteResult<RawRoute>;
|
|
27
|
+
export type PageRoutes = RouteResult<IPageRouteConfig>;
|
|
28
|
+
export type ApiRoutes = RouteResult<IApiRouteConfig>;
|
|
29
|
+
export type MiddlewareRoutes = RouteResult<IMiddlewareRouteConfig>;
|
|
30
|
+
export type RouteConfigType = IPageRouteConfig | IApiRouteConfig | IMiddlewareRouteConfig;
|
|
31
31
|
export declare const getRawRoutesFromDir: (dirname: string, { includes, excludes }: {
|
|
32
|
-
includes?: string[]
|
|
33
|
-
excludes?: string[]
|
|
32
|
+
includes?: string[];
|
|
33
|
+
excludes?: string[];
|
|
34
34
|
}) => Promise<RawRoutes>;
|
|
35
35
|
export declare const getPageRoutes: (dir: string | RawRoutes, { includes, excludes }?: {
|
|
36
|
-
includes?: string[]
|
|
37
|
-
excludes?: string[]
|
|
36
|
+
includes?: string[];
|
|
37
|
+
excludes?: string[];
|
|
38
38
|
}) => Promise<PageRoutes>;
|
|
39
39
|
export declare const getApiRoutes: (dir: string | RawRoutes, { includes, excludes }?: {
|
|
40
|
-
includes?: string[]
|
|
41
|
-
excludes?: string[]
|
|
40
|
+
includes?: string[];
|
|
41
|
+
excludes?: string[];
|
|
42
42
|
}) => Promise<ApiRoutes>;
|
|
43
43
|
export declare const getMiddlewareRoutes: (dir: string | RawRoutes, { includes, excludes }?: {
|
|
44
|
-
includes?: string[]
|
|
45
|
-
excludes?: string[]
|
|
44
|
+
includes?: string[];
|
|
45
|
+
excludes?: string[];
|
|
46
46
|
}) => Promise<MiddlewareRoutes>;
|
package/lib/node/route/route.js
CHANGED
|
@@ -14,7 +14,7 @@ const path_1 = require("path");
|
|
|
14
14
|
const file_1 = require("@shuvi/utils/file");
|
|
15
15
|
const helpers_1 = require("./helpers");
|
|
16
16
|
const matchSpec_1 = require("./matchSpec");
|
|
17
|
-
const getRawRoutesFromDir = (
|
|
17
|
+
const getRawRoutesFromDir = (dirname_1, _a) => __awaiter(void 0, [dirname_1, _a], void 0, function* (dirname, { includes, excludes }) {
|
|
18
18
|
const rootDirname = dirname;
|
|
19
19
|
if (!(yield (0, file_1.isDirectory)(rootDirname))) {
|
|
20
20
|
return {
|
|
@@ -81,7 +81,7 @@ const getRawRoutesFromDir = (dirname, { includes, excludes }) => __awaiter(void
|
|
|
81
81
|
};
|
|
82
82
|
});
|
|
83
83
|
exports.getRawRoutesFromDir = getRawRoutesFromDir;
|
|
84
|
-
const getPageRoutes = (
|
|
84
|
+
const getPageRoutes = (dir_1, ...args_1) => __awaiter(void 0, [dir_1, ...args_1], void 0, function* (dir, { includes, excludes } = {}) {
|
|
85
85
|
let raw;
|
|
86
86
|
if (typeof dir === 'string') {
|
|
87
87
|
raw = yield (0, exports.getRawRoutesFromDir)(dir, { includes, excludes });
|
|
@@ -128,7 +128,7 @@ const getPageRoutes = (dir, { includes, excludes } = {}) => __awaiter(void 0, vo
|
|
|
128
128
|
};
|
|
129
129
|
});
|
|
130
130
|
exports.getPageRoutes = getPageRoutes;
|
|
131
|
-
const getApiRoutes = (
|
|
131
|
+
const getApiRoutes = (dir_1, ...args_1) => __awaiter(void 0, [dir_1, ...args_1], void 0, function* (dir, { includes, excludes } = {}) {
|
|
132
132
|
let raw;
|
|
133
133
|
if (typeof dir === 'string') {
|
|
134
134
|
raw = yield (0, exports.getRawRoutesFromDir)(dir, { includes, excludes });
|
|
@@ -181,7 +181,7 @@ const getApiRoutes = (dir, { includes, excludes } = {}) => __awaiter(void 0, voi
|
|
|
181
181
|
};
|
|
182
182
|
});
|
|
183
183
|
exports.getApiRoutes = getApiRoutes;
|
|
184
|
-
const getMiddlewareRoutes = (
|
|
184
|
+
const getMiddlewareRoutes = (dir_1, ...args_1) => __awaiter(void 0, [dir_1, ...args_1], void 0, function* (dir, { includes, excludes } = {}) {
|
|
185
185
|
let raw;
|
|
186
186
|
if (typeof dir === 'string') {
|
|
187
187
|
raw = yield (0, exports.getRawRoutesFromDir)(dir, { includes, excludes });
|
|
@@ -20,7 +20,7 @@ export declare class ApplicationImpl<Config extends {} = {}> {
|
|
|
20
20
|
get error(): IError | null;
|
|
21
21
|
setError(err: IError): void;
|
|
22
22
|
clearError(): void;
|
|
23
|
-
getLoaders(): Promise<Record<string, import("./
|
|
23
|
+
getLoaders(): Promise<Record<string, import("./loader").Loader>>;
|
|
24
24
|
getLoadersData(): Record<string, any>;
|
|
25
25
|
setLoadersData(datas: Record<string, any>): void;
|
|
26
26
|
init(): Promise<void>;
|
|
@@ -73,8 +73,8 @@ class ApplicationImpl {
|
|
|
73
73
|
get store() {
|
|
74
74
|
return this._store;
|
|
75
75
|
}
|
|
76
|
-
updateComponents(
|
|
77
|
-
return __awaiter(this,
|
|
76
|
+
updateComponents() {
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* ({ AppComponent } = {}) {
|
|
78
78
|
if (AppComponent && AppComponent !== this._appComponent) {
|
|
79
79
|
this._appComponent = AppComponent;
|
|
80
80
|
}
|
|
@@ -4,15 +4,15 @@ import type { ShuviRequest } from '@shuvi/service';
|
|
|
4
4
|
import { IRouter } from './routerTypes';
|
|
5
5
|
import { IPluginList } from './runtimPlugin';
|
|
6
6
|
import { Loader } from './loader';
|
|
7
|
-
export
|
|
7
|
+
export type Loaders = Record<string, Loader>;
|
|
8
8
|
export interface IAppContext extends CustomAppContext {
|
|
9
9
|
[x: string]: unknown;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type IRerenderConfig = {
|
|
12
12
|
AppComponent?: any;
|
|
13
13
|
};
|
|
14
14
|
export type { Doura };
|
|
15
|
-
export
|
|
15
|
+
export type ErrorSource = 'server';
|
|
16
16
|
export interface IError {
|
|
17
17
|
code?: number;
|
|
18
18
|
message?: string;
|
|
@@ -23,7 +23,7 @@ export interface IError {
|
|
|
23
23
|
export interface IErrorState {
|
|
24
24
|
error: IError | null;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type IAppState = {
|
|
27
27
|
error: IErrorState;
|
|
28
28
|
};
|
|
29
29
|
export interface Application<Config extends {} = {}> {
|
|
@@ -50,4 +50,4 @@ export interface ApplicationInternalOptions<C extends {}> {
|
|
|
50
50
|
plugins?: IPluginList;
|
|
51
51
|
request?: ShuviRequest;
|
|
52
52
|
}
|
|
53
|
-
export
|
|
53
|
+
export type ApplicationlOptions<C extends {}> = Omit<ApplicationInternalOptions<C>, 'getLoaders' | 'plugins'>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type IData = {
|
|
1
|
+
export type IData = {
|
|
3
2
|
[k: string]: string | number | boolean | undefined | null;
|
|
4
3
|
};
|
|
5
|
-
export
|
|
4
|
+
export type IAppData<Data = {}, appState = any> = {
|
|
6
5
|
ssr: boolean;
|
|
7
6
|
basename?: string;
|
|
8
7
|
runtimeConfig?: Record<string, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAppData =
|
|
3
|
+
exports.getAppData = getAppData;
|
|
4
4
|
/// <reference lib="dom" />
|
|
5
5
|
const constants_1 = require("@shuvi/shared/constants");
|
|
6
6
|
let appData = null;
|
|
@@ -27,4 +27,3 @@ function getAppData() {
|
|
|
27
27
|
}
|
|
28
28
|
return JSON.parse(el.textContent);
|
|
29
29
|
}
|
|
30
|
-
exports.getAppData = getAppData;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IRouter, PathRecord } from '../routerTypes';
|
|
2
|
-
export
|
|
2
|
+
export type RouteFile = {
|
|
3
3
|
id: string;
|
|
4
4
|
url: string;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type RouteFiles = {
|
|
7
7
|
js: RouteFile[];
|
|
8
8
|
css: RouteFile[];
|
|
9
9
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFilesOfRoute =
|
|
3
|
+
exports.getFilesOfRoute = getFilesOfRoute;
|
|
4
4
|
const getAppData_1 = require("./getAppData");
|
|
5
5
|
const getPublicPath_1 = require("./getPublicPath");
|
|
6
6
|
function getFilesOfRoute(router, to) {
|
|
@@ -31,4 +31,3 @@ function getFilesOfRoute(router, to) {
|
|
|
31
31
|
css
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
exports.getFilesOfRoute = getFilesOfRoute;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPageData =
|
|
3
|
+
exports.getPageData = getPageData;
|
|
4
4
|
const getAppData_1 = require("./getAppData");
|
|
5
5
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6
6
|
function getPageData(key, defaultValue) {
|
|
@@ -14,4 +14,3 @@ function getPageData(key, defaultValue) {
|
|
|
14
14
|
}
|
|
15
15
|
return pageData[key];
|
|
16
16
|
}
|
|
17
|
-
exports.getPageData = getPageData;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPublicPath =
|
|
3
|
+
exports.getPublicPath = getPublicPath;
|
|
4
4
|
const getAppData_1 = require("./getAppData");
|
|
5
5
|
function getPublicPath() {
|
|
6
6
|
const { publicPath } = (0, getAppData_1.getAppData)();
|
|
7
7
|
return publicPath;
|
|
8
8
|
}
|
|
9
|
-
exports.getPublicPath = getPublicPath;
|
|
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.runPreload = runPreload;
|
|
16
|
+
exports.getRouteMatchesWithInvalidLoader = getRouteMatchesWithInvalidLoader;
|
|
16
17
|
const isEqual_1 = __importDefault(require("@shuvi/utils/isEqual"));
|
|
17
18
|
function runPreload(to) {
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -28,7 +29,6 @@ function runPreload(to) {
|
|
|
28
29
|
yield Promise.all(preloadList);
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
exports.runPreload = runPreload;
|
|
32
32
|
function getRouteMatchesWithInvalidLoader(to, from, loaders) {
|
|
33
33
|
const toMatches = to.matches;
|
|
34
34
|
const fromMatches = from.matches;
|
|
@@ -65,4 +65,3 @@ function getRouteMatchesWithInvalidLoader(to, from, loaders) {
|
|
|
65
65
|
});
|
|
66
66
|
return targets;
|
|
67
67
|
}
|
|
68
|
-
exports.getRouteMatchesWithInvalidLoader = getRouteMatchesWithInvalidLoader;
|
|
@@ -12,7 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.runInParallerAndBail = runInParallerAndBail;
|
|
16
|
+
exports.createLoaderContext = createLoaderContext;
|
|
17
|
+
exports.runLoaders = runLoaders;
|
|
16
18
|
const invariant_1 = __importDefault(require("@shuvi/utils/invariant"));
|
|
17
19
|
const response_1 = require("../response");
|
|
18
20
|
// todo: add unit tests
|
|
@@ -67,7 +69,6 @@ function runInParallerAndBail(fns) {
|
|
|
67
69
|
});
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
|
-
exports.runInParallerAndBail = runInParallerAndBail;
|
|
71
72
|
function redirectHelper(to, status = 302) {
|
|
72
73
|
if (process.env.NODE_ENV === 'development') {
|
|
73
74
|
(0, invariant_1.default)(typeof to === 'string', `redirect's frist argument should be string, now is ${typeof to}`);
|
|
@@ -83,7 +84,6 @@ function createLoaderContext({ pathname, query, params, req, getAppContext }) {
|
|
|
83
84
|
params,
|
|
84
85
|
query, redirect: redirectHelper, error: errorHelper, appContext: getAppContext() }, (req ? { req } : {}));
|
|
85
86
|
}
|
|
86
|
-
exports.createLoaderContext = createLoaderContext;
|
|
87
87
|
function runLoaders(matches, loadersByRouteId, loaderContext) {
|
|
88
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
89
|
const loaderDatas = {};
|
|
@@ -132,4 +132,3 @@ function runLoaders(matches, loadersByRouteId, loaderContext) {
|
|
|
132
132
|
return loaderDatas;
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
exports.runLoaders = runLoaders;
|
|
@@ -9,7 +9,7 @@ export interface LoaderContextOptions {
|
|
|
9
9
|
params: IRouteLoaderContext['params'];
|
|
10
10
|
getAppContext: () => IAppContext;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type RedirectFunction = (to: string, status?: number) => any;
|
|
13
13
|
export interface ErrorFunction {
|
|
14
14
|
(): any;
|
|
15
15
|
(msg: string): any;
|
|
@@ -68,6 +68,6 @@ export interface IRouteLoaderContext {
|
|
|
68
68
|
*/
|
|
69
69
|
appContext: IAppContext;
|
|
70
70
|
}
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
export
|
|
71
|
+
export type Loader<T = any> = (loaderContext: IRouteLoaderContext) => Promise<T> | T;
|
|
72
|
+
export type NormalizedLoader = (loaderContext: IRouteLoaderContext) => Promise<Response | undefined>;
|
|
73
|
+
export type LoaderDataRecord = Record<string, any>;
|
package/lib/shared/response.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type HeaderRecord = Record<string, string>;
|
|
2
|
+
type HeaderArray = [string, string][];
|
|
3
3
|
export interface ResponseOptions {
|
|
4
4
|
status?: number;
|
|
5
5
|
statusText?: string;
|
|
@@ -33,7 +33,7 @@ declare class Headers {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export
|
|
36
|
+
export type ResponseType = 'text' | 'json' | 'redirect' | 'raw';
|
|
37
37
|
export interface Response {
|
|
38
38
|
readonly data: any;
|
|
39
39
|
readonly status: number;
|
package/lib/shared/response.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isRedirect = exports.isText = exports.isJson = exports.isResponse = void 0;
|
|
4
|
+
exports.response = response;
|
|
5
|
+
exports.json = json;
|
|
6
|
+
exports.text = text;
|
|
7
|
+
exports.redirect = redirect;
|
|
4
8
|
const supportIterator = 'Symbol' in global && 'iterator' in Symbol;
|
|
5
9
|
function normalizeName(name) {
|
|
6
10
|
if (typeof name !== 'string') {
|
|
@@ -114,15 +118,12 @@ exports.isRedirect = createTypeCreator('redirect');
|
|
|
114
118
|
function response(data, options) {
|
|
115
119
|
return new ResponseImpl(data, 'raw', options);
|
|
116
120
|
}
|
|
117
|
-
exports.response = response;
|
|
118
121
|
function json(data) {
|
|
119
122
|
return new ResponseImpl(data, 'json');
|
|
120
123
|
}
|
|
121
|
-
exports.json = json;
|
|
122
124
|
function text(data, options) {
|
|
123
125
|
return new ResponseImpl(data, 'text', options);
|
|
124
126
|
}
|
|
125
|
-
exports.text = text;
|
|
126
127
|
function redirect(to, status = 302) {
|
|
127
128
|
return new ResponseImpl('', 'redirect', {
|
|
128
129
|
status,
|
|
@@ -131,4 +132,3 @@ function redirect(to, status = 302) {
|
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
exports.redirect = redirect;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ParsedQuery, IParams, IRouteRecord } from '@shuvi/router';
|
|
2
2
|
import { IRouter as IRouter_, IRoute, IRouteMatch, PathRecord } from '@shuvi/router';
|
|
3
3
|
export { IRoute, IRouteMatch, PathRecord };
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type IURLQuery = ParsedQuery;
|
|
5
|
+
export type IURLParams = IParams;
|
|
6
|
+
export type IRouter = IRouter_<IPageRouteRecord>;
|
|
7
7
|
export interface IPageRouteRecord extends IRouteRecord {
|
|
8
8
|
id: string;
|
|
9
9
|
path: string;
|
|
@@ -21,7 +21,7 @@ export interface IPlatformConfig {
|
|
|
21
21
|
target?: string;
|
|
22
22
|
[index: string]: any;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type IRouterHistoryMode = 'browser' | 'hash' | 'memory';
|
|
25
25
|
export interface IPageRouteConfig {
|
|
26
26
|
children?: IPageRouteConfig[];
|
|
27
27
|
name?: string;
|
|
@@ -3,8 +3,8 @@ import type { ShuviRequest } from '@shuvi/service';
|
|
|
3
3
|
import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
4
4
|
import { IAppContext } from './applicationTypes';
|
|
5
5
|
import { IRouter } from './routerTypes';
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export type AppComponent = unknown;
|
|
7
|
+
export type AppContextCtx = {
|
|
8
8
|
router: IRouter;
|
|
9
9
|
req?: ShuviRequest;
|
|
10
10
|
};
|
|
@@ -23,28 +23,28 @@ export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRun
|
|
|
23
23
|
export declare const getManager: () => import("@shuvi/hook").HookManager<RuntimePluginHooks, void>;
|
|
24
24
|
export declare const createRuntimePluginBefore: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePlugin: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>, createRuntimePluginAfter: import("@shuvi/shared/plugins").PluginFunc<RuntimePluginHooks, void>;
|
|
25
25
|
export type { IPluginInstance, CustomRuntimePluginHooks };
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
26
|
+
export type PluginManager = ReturnType<typeof getManager>;
|
|
27
|
+
export type RuntimePluginInstance = IPluginInstance<RuntimePluginHooks, void>;
|
|
28
|
+
export type IRuntimePluginConstructor = IPluginHandlers<RuntimePluginHooks, void>;
|
|
29
|
+
export type IAppModule = {
|
|
30
30
|
init?: IRuntimePluginConstructor['init'];
|
|
31
31
|
appContext?: IRuntimePluginConstructor['appContext'];
|
|
32
32
|
appComponent?: IRuntimePluginConstructor['appComponent'];
|
|
33
33
|
dispose?: IRuntimePluginConstructor['dispose'];
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
35
|
+
type SerializedPluginOptions = string;
|
|
36
|
+
export type IRuntimePluginOptions = Record<string, unknown>;
|
|
37
|
+
export type IRuntimePluginWithOptions = (...params: any[]) => RuntimePluginInstance;
|
|
38
|
+
export type IRuntimePlugin = RuntimePluginInstance | IRuntimePluginWithOptions;
|
|
39
|
+
export type IPluginModule = {
|
|
40
40
|
plugin: IRuntimePlugin;
|
|
41
41
|
pluginOptions: IRuntimePluginOptions;
|
|
42
42
|
};
|
|
43
|
-
export
|
|
43
|
+
export type IPluginRecord = {
|
|
44
44
|
[name: string]: {
|
|
45
45
|
plugin: IRuntimePlugin;
|
|
46
46
|
options: SerializedPluginOptions;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
export
|
|
49
|
+
export type IPluginList = [IRuntimePlugin, SerializedPluginOptions?][];
|
|
50
50
|
export declare const initPlugins: (pluginManager: PluginManager, plugins: IPluginList) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type IRuntimeConfig = Record<string, any>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getRuntimeConfig = getRuntimeConfig;
|
|
4
|
+
exports.getPublicRuntimeConfig = getPublicRuntimeConfig;
|
|
5
|
+
exports.setPublicRuntimeConfig = setPublicRuntimeConfig;
|
|
6
|
+
exports.getServerRuntimeConfig = getServerRuntimeConfig;
|
|
7
|
+
exports.setServerRuntimeConfig = setServerRuntimeConfig;
|
|
4
8
|
const isServer = typeof window === 'undefined';
|
|
5
9
|
/**
|
|
6
10
|
* use global this to store runtime config, so we can safely bundle this module
|
|
@@ -18,7 +22,6 @@ let serverRuntimeConfig;
|
|
|
18
22
|
function getRuntimeConfig() {
|
|
19
23
|
return Object.assign(Object.assign({}, (getServerRuntimeConfig() || {})), (getPublicRuntimeConfig() || {}));
|
|
20
24
|
}
|
|
21
|
-
exports.getRuntimeConfig = getRuntimeConfig;
|
|
22
25
|
function getPublicRuntimeConfig() {
|
|
23
26
|
if (isServer) {
|
|
24
27
|
return globalThis[KEY_PUBLIC_RUNTIME_CONFIG];
|
|
@@ -27,7 +30,6 @@ function getPublicRuntimeConfig() {
|
|
|
27
30
|
return publicRuntimeConfig;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
|
-
exports.getPublicRuntimeConfig = getPublicRuntimeConfig;
|
|
31
33
|
function setPublicRuntimeConfig(config) {
|
|
32
34
|
if (isServer) {
|
|
33
35
|
globalThis[KEY_PUBLIC_RUNTIME_CONFIG] = config;
|
|
@@ -36,7 +38,6 @@ function setPublicRuntimeConfig(config) {
|
|
|
36
38
|
publicRuntimeConfig = config;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
exports.setPublicRuntimeConfig = setPublicRuntimeConfig;
|
|
40
41
|
function getServerRuntimeConfig() {
|
|
41
42
|
if (isServer) {
|
|
42
43
|
return globalThis[KEY_SERVER_RUNTIME_CONFIG];
|
|
@@ -45,7 +46,6 @@ function getServerRuntimeConfig() {
|
|
|
45
46
|
return serverRuntimeConfig;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
exports.getServerRuntimeConfig = getServerRuntimeConfig;
|
|
49
49
|
function setServerRuntimeConfig(config) {
|
|
50
50
|
if (isServer) {
|
|
51
51
|
globalThis[KEY_SERVER_RUNTIME_CONFIG] = config;
|
|
@@ -54,4 +54,3 @@ function setServerRuntimeConfig(config) {
|
|
|
54
54
|
serverRuntimeConfig = config;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
exports.setServerRuntimeConfig = setServerRuntimeConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"node": ">= 16.0.0"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@shuvi/hook": "1.0.
|
|
86
|
+
"@shuvi/hook": "1.0.56",
|
|
87
87
|
"doura": "0.0.13",
|
|
88
|
-
"@shuvi/router": "1.0.
|
|
89
|
-
"@shuvi/runtime": "1.0.
|
|
90
|
-
"@shuvi/shared": "1.0.
|
|
91
|
-
"@shuvi/toolpack": "1.0.
|
|
92
|
-
"@shuvi/utils": "1.0.
|
|
88
|
+
"@shuvi/router": "1.0.56",
|
|
89
|
+
"@shuvi/runtime": "1.0.56",
|
|
90
|
+
"@shuvi/shared": "1.0.56",
|
|
91
|
+
"@shuvi/toolpack": "1.0.56",
|
|
92
|
+
"@shuvi/utils": "1.0.56"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"@shuvi/service": "1.0.
|
|
95
|
+
"@shuvi/service": "1.0.56"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@shuvi/service": "workspace:*",
|