refactor: 优化类型声明

This commit is contained in:
winixt 2022-04-15 22:54:51 +08:00
parent f20fb7a371
commit 7dca7188aa
8 changed files with 107 additions and 100 deletions

View File

@ -40,5 +40,6 @@
"peerDependencies": {
"@vue/compiler-sfc": "^3.0.5",
"core-js": "^3.21.1"
}
},
"typings": "./types.d.ts"
}

View File

@ -39,7 +39,6 @@ export function getInnerCommonConfig(api) {
...api.config.alias,
'@': api.paths.absSrcPath,
'@@': api.paths.absTmpPath,
[api.builder.innerDepPrefix]: '/',
},
},
},

View File

@ -92,7 +92,6 @@ export default class Service extends EventEmitter {
const builderPkgPath = filterBuilder(this.pkg);
this.builder = {
isVite: (builderPkgPath[0] || '').includes('build-vite'),
innerDepPrefix: '@fesInner',
};
assert(existsSync(this.cwd), `cwd ${this.cwd} does not exist.`);

View File

@ -36,5 +36,6 @@
},
"peerDependencies": {
"@vue/compiler-sfc": "^3.0.5"
}
},
"typings": "./types.d.ts"
}

View File

@ -3,6 +3,7 @@ export default function () {
plugins: [
// register methods
require.resolve('./plugins/registerMethods'),
require.resolve('./plugins/registerType'),
// generate files
require.resolve('./plugins/generateFiles/core/plugin'),

View File

@ -0,0 +1,9 @@
import { name } from '../../package.json';
export default function (api) {
api.addConfigType(() => ({
source: name,
runtime: ['InnerRuntimeConfig'],
build: ['InnerBuildConfig'],
}));
}

91
packages/fes-preset-built-in/types.d.ts vendored Normal file
View File

@ -0,0 +1,91 @@
import { Component, DefineComponent, App } from 'vue';
import { RouteRecordRaw, Router } from 'vue-router';
// @ts-ignore
import { Plugin } from '@fesjs/runtime';
interface BeforeRenderConfig {
loading: Component;
action: () => Promise<any>;
}
interface ClientRenderOption {
routes: RouteRecordRaw[];
rootElement: string;
defaultTitle: string;
plugin: Plugin;
}
type RenderFunc = () => Promise<App>
export interface InnerRuntimeConfig {
beforeRender?: (option: BeforeRenderConfig) => BeforeRenderConfig;
patchRoutes?: ({ routes }: { routes: RouteRecordRaw[] }) => void;
modifyClientRenderOpts?: (option: ClientRenderOption) => ClientRenderOption;
rootContainer?: (component: DefineComponent, option: { routes: RouteRecordRaw[], plugin: Plugin }) => DefineComponent;
onAppCreated?: ({ app, routes }: { app: App, routes: RouteRecordRaw[] }) => void;
render?: (defaultRender: RenderFunc) => RenderFunc;
onRouterCreated?: ({ router }: { router: Router }) => void;
}
export interface InnerBuildConfig {
alias?: Record<string, string>,
autoprefixer?: {
/** environment for `Browserslist` */
env?: string
/** should Autoprefixer use Visual Cascade, if CSS is uncompressed */
cascade?: boolean
/** should Autoprefixer add prefixes. */
add?: boolean
/** should Autoprefixer [remove outdated] prefixes */
remove?: boolean
/** should Autoprefixer add prefixes for @supports parameters. */
supports?: boolean
/** should Autoprefixer add prefixes for flexbox properties */
flexbox?: boolean | 'no-2009'
/** should Autoprefixer add IE 10-11 prefixes for Grid Layout properties */
grid?: boolean
/**
* list of queries for target browsers.
* Try to not use it.
* The best practice is to use `.browserslistrc` config or `browserslist` key in `package.json`
* to share target browsers with Babel, ESLint and Stylelint
*/
overrideBrowserslist?: string | string[]
/** do not raise error on unknown browser version in `Browserslist` config. */
ignoreUnknownVersions?: boolean
};
define?: Record<string, string | object>,
router?: {
base?: string;
routes?: RouteRecordRaw[];
mode?: 'hash' | 'history' | 'memory'
};
dynamicImport?: boolean;
inlineLimit?: number;
mock?: boolean | {
prefix?: string;
};
mountElementId?: string;
plugins?: string[];
proxy?: {
[apiPrefix: string]: {
target: string;
changeOrigin?: boolean;
}
};
publicPath?: string;
singular?: boolean;
targets?: object;
terserOptions?: object;
title?: string;
}

View File

@ -1,7 +1,3 @@
import { Component, DefineComponent, App } from 'vue';
import { RouteRecordRaw, Router } from 'vue-router';
// @ts-ignore
import { Plugin } from '@fesjs/runtime';
// @ts-ignore
import type { PluginRuntimeConfig, PluginBuildConfig } from '@@/configType';
@ -18,97 +14,7 @@ interface RouteMeta {
export declare function defineRouteMeta(routeMeta: RouteMeta): RouteMeta;
export function defineBuildConfig(config: PluginBuildConfig ): PluginBuildConfig;
interface BeforeRenderConfig {
loading: Component;
action: () => Promise<any>;
}
interface ClientRenderOption {
routes: RouteRecordRaw[];
rootElement: string;
defaultTitle: string;
plugin: Plugin;
}
type RenderFunc = () => Promise<App>
interface InnerRuntimeConfig {
beforeRender?: (option: BeforeRenderConfig) => BeforeRenderConfig;
patchRoutes?: ({ routes }: { routes: RouteRecordRaw[] }) => void;
modifyClientRenderOpts?: (option: ClientRenderOption) => ClientRenderOption;
rootContainer?: (component: DefineComponent, option: { routes: RouteRecordRaw[], plugin: Plugin }) => DefineComponent;
onAppCreated?: ({ app, routes }: { app: App, routes: RouteRecordRaw[] }) => void;
render?: (defaultRender: RenderFunc) => RenderFunc;
onRouterCreated?: ({ router }: { router: Router }) => void;
}
export function defineRuntimeConfig(config: InnerRuntimeConfig & PluginRuntimeConfig): InnerRuntimeConfig & PluginRuntimeConfig;
interface InnerBuildConfig {
alias?: Record<string, string>,
autoprefixer?: {
/** environment for `Browserslist` */
env?: string
/** should Autoprefixer use Visual Cascade, if CSS is uncompressed */
cascade?: boolean
/** should Autoprefixer add prefixes. */
add?: boolean
/** should Autoprefixer [remove outdated] prefixes */
remove?: boolean
/** should Autoprefixer add prefixes for @supports parameters. */
supports?: boolean
/** should Autoprefixer add prefixes for flexbox properties */
flexbox?: boolean | 'no-2009'
/** should Autoprefixer add IE 10-11 prefixes for Grid Layout properties */
grid?: boolean | GridValue
/** custom usage statistics for > 10% in my stats browsers query */
stats?: Stats
/**
* list of queries for target browsers.
* Try to not use it.
* The best practice is to use `.browserslistrc` config or `browserslist` key in `package.json`
* to share target browsers with Babel, ESLint and Stylelint
*/
overrideBrowserslist?: string | string[]
/** do not raise error on unknown browser version in `Browserslist` config. */
ignoreUnknownVersions?: boolean
};
define?: Record<string, string | object>,
router?: {
base?: string;
routes?: RouteRecordRaw[];
mode?: 'hash' | 'history' | 'memory'
};
dynamicImport?: boolean;
inlineLimit?: number;
mock?: boolean | {
prefix?: string;
};
mountElementId?: string;
plugins?: string[];
proxy?: {
[apiPrefix: string]: {
target: string;
changeOrigin?: boolean;
}
};
publicPath?: string;
singular?: boolean;
targets?: object;
terserOptions?: object;
title?: string;
}
export function defineBuildConfig(config: InnerBuildConfig & PluginBuildConfig ): InnerBuildConfig & PluginBuildConfig;
export function defineRuntimeConfig(config: PluginRuntimeConfig): PluginRuntimeConfig;