chore: improve the console project infrastructure (#4105)

#### What type of PR is this?

/area console
/kind improvement
/milestone 2.7.x

#### What this PR does / why we need it:

维护 Console 端的开发基础设施。

- 升级 TypeScript 以及 Vue 对于 TS 支持的相关包。
- 优化 packages 下所有包的配置,解决构建时生成 d.ts 文件的异常。
- 解决 TS 异常。

#### Special notes for your reviewer:

尝试执行:

1. pnpm build:packages
2. pnpm typecheck

观察是否正常即可。

#### Does this PR introduce a user-facing change?

```release-note
维护 Console 端的开发基础设施。
```
pull/4112/head^2
Ryan Wang 2023-06-26 11:54:17 +08:00 committed by GitHub
parent d28f6075c1
commit 96225e4040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 737 additions and 841 deletions

View File

@ -23,4 +23,7 @@ module.exports = {
extends: ["plugin:cypress/recommended"], extends: ["plugin:cypress/recommended"],
}, },
], ],
parserOptions: {
ecmaVersion: "latest",
},
}; };

1
console/env.d.ts vendored
View File

@ -1,4 +1,5 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
/// <reference types="unplugin-icons/types/vue" />
export {}; export {};

View File

@ -94,7 +94,7 @@
"vue": "^3.2.45", "vue": "^3.2.45",
"vue-demi": "^0.13.11", "vue-demi": "^0.13.11",
"vue-grid-layout": "3.0.0-beta1", "vue-grid-layout": "3.0.0-beta1",
"vue-i18n": "^9.2.2", "vue-i18n": "9.3.0-beta.19",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",
"vuedraggable": "^4.1.0" "vuedraggable": "^4.1.0"
}, },
@ -103,9 +103,10 @@
"@iconify-json/mdi": "^1.1.50", "@iconify-json/mdi": "^1.1.50",
"@iconify-json/vscode-icons": "^1.1.22", "@iconify-json/vscode-icons": "^1.1.22",
"@intlify/unplugin-vue-i18n": "^0.9.3", "@intlify/unplugin-vue-i18n": "^0.9.3",
"@rushstack/eslint-patch": "^1.2.0", "@rushstack/eslint-patch": "^1.3.2",
"@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/container-queries": "^0.1.0", "@tailwindcss/container-queries": "^0.1.0",
"@tsconfig/node18": "^2.0.1",
"@types/jsdom": "^20.0.1", "@types/jsdom": "^20.0.1",
"@types/lodash.clonedeep": "4.5.7", "@types/lodash.clonedeep": "4.5.7",
"@types/lodash.debounce": "^4.0.7", "@types/lodash.debounce": "^4.0.7",
@ -115,19 +116,19 @@
"@types/qs": "^6.9.7", "@types/qs": "^6.9.7",
"@types/randomstring": "^1.1.8", "@types/randomstring": "^1.1.8",
"@vitejs/plugin-vue": "^4.0.0", "@vitejs/plugin-vue": "^4.0.0",
"@vitejs/plugin-vue-jsx": "^3.0.0", "@vitejs/plugin-vue-jsx": "^3.0.1",
"@vitest/ui": "^0.25.3", "@vitest/ui": "^0.25.3",
"@vue/compiler-sfc": "^3.2.45", "@vue/compiler-sfc": "^3.2.45",
"@vue/eslint-config-prettier": "^7.1.0", "@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.3", "@vue/eslint-config-typescript": "^11.0.3",
"@vue/test-utils": "^2.2.4", "@vue/test-utils": "^2.3.2",
"@vue/tsconfig": "^0.1.3", "@vue/tsconfig": "^0.4.0",
"autoprefixer": "^10.4.14", "autoprefixer": "^10.4.14",
"c8": "^7.12.0", "c8": "^7.12.0",
"cypress": "^10.11.0", "cypress": "^10.11.0",
"eslint": "^8.41.0", "eslint": "^8.43.0",
"eslint-plugin-cypress": "^2.13.3", "eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-vue": "^9.13.0", "eslint-plugin-vue": "^9.15.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"jsdom": "^20.0.3", "jsdom": "^20.0.3",
"lint-staged": "^13.2.2", "lint-staged": "^13.2.2",
@ -141,7 +142,7 @@
"tailwindcss": "^3.2.7", "tailwindcss": "^3.2.7",
"tailwindcss-safe-area": "^0.2.2", "tailwindcss-safe-area": "^0.2.2",
"tailwindcss-themer": "^2.0.3", "tailwindcss-themer": "^2.0.3",
"typescript": "~4.7.4", "typescript": "~5.0.4",
"unplugin-icons": "^0.14.15", "unplugin-icons": "^0.14.15",
"vite": "^4.0.4", "vite": "^4.0.4",
"vite-compression-plugin": "^0.0.4", "vite-compression-plugin": "^0.0.4",
@ -150,6 +151,6 @@
"vite-plugin-pwa": "^0.13.3", "vite-plugin-pwa": "^0.13.3",
"vite-plugin-static-copy": "^0.11.1", "vite-plugin-static-copy": "^0.11.1",
"vitest": "^0.25.3", "vitest": "^0.25.3",
"vue-tsc": "^1.0.24" "vue-tsc": "^1.8.1"
} }
} }

View File

@ -1,5 +1,6 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
/// <reference types="histoire" /> /// <reference types="histoire" />
/// <reference types="unplugin-icons/types/vue" />
declare module "*.vue" { declare module "*.vue" {
import type { DefineComponent } from "vue"; import type { DefineComponent } from "vue";

View File

@ -48,7 +48,7 @@
"@iconify-json/ri": "^1.1.4", "@iconify-json/ri": "^1.1.4",
"histoire": "^0.11.7", "histoire": "^0.11.7",
"unplugin-icons": "^0.14.14", "unplugin-icons": "^0.14.14",
"vite-plugin-dts": "^1.7.3" "vite-plugin-dts": "^2.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"vue": "^3.2.37", "vue": "^3.2.37",

View File

@ -1,6 +1,6 @@
export type Type = "success" | "info" | "warning" | "error"; export type Type = "success" | "info" | "warning" | "error";
export const DialogProviderProvideKey = "DIALOG_PROVIDER_PROVIDE_KEY"; export const DialogProviderProvideKey = "DIALOG_PROVIDER_PROVIDE_KEY";
import type { Type as ButtonType } from "@/components/button/interface"; import type { Type as ButtonType } from "../button/interface";
export interface useDialogOptions { export interface useDialogOptions {
type?: Type; type?: Type;

View File

@ -1,5 +1,5 @@
{ {
"extends": "@vue/tsconfig/tsconfig.web.json", "extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"], "exclude": ["src/**/__tests__/*"],
"compilerOptions": { "compilerOptions": {

View File

@ -2,7 +2,7 @@
"files": [], "files": [],
"references": [ "references": [
{ {
"path": "./tsconfig.vite-config.json" "path": "./tsconfig.node.json"
}, },
{ {
"path": "./tsconfig.app.json" "path": "./tsconfig.app.json"

View File

@ -0,0 +1,9 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*"],
"compilerOptions": {
"composite": true,
"module": "ESNext",
"types": ["node"]
}
}

View File

@ -1,8 +0,0 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["vite.config.*"],
"compilerOptions": {
"composite": true,
"types": ["node", "vitest"]
}
}

View File

@ -1,6 +1,6 @@
import { fileURLToPath, URL } from "url"; import { fileURLToPath, URL } from "url";
import { defineConfig } from "vite"; import { defineConfig, type Plugin } from "vite";
import Vue from "@vitejs/plugin-vue"; import Vue from "@vitejs/plugin-vue";
import VueJsx from "@vitejs/plugin-vue-jsx"; import VueJsx from "@vitejs/plugin-vue-jsx";
import Icons from "unplugin-icons/vite"; import Icons from "unplugin-icons/vite";
@ -13,10 +13,11 @@ export default defineConfig({
VueJsx(), VueJsx(),
Icons({ compiler: "vue3" }), Icons({ compiler: "vue3" }),
Dts({ Dts({
tsConfigFilePath: "./tsconfig.app.json",
entryRoot: "./src", entryRoot: "./src",
outputDir: "./dist", outputDir: "./dist",
insertTypesEntry: true, insertTypesEntry: true,
}), }) as Plugin,
], ],
define: { define: {
"process.env": process.env, "process.env": process.env,

View File

@ -2,9 +2,9 @@
export {}; export {};
import type { Component } from "vue";
import type { CoreMenuGroupId } from "./src/types/menus"; import type { CoreMenuGroupId } from "./src/types/menus";
declare module "*.vue" { declare module "*.vue" {
import type { DefineComponent } from "vue"; import type { DefineComponent } from "vue";
// eslint-disable-next-line // eslint-disable-next-line

View File

@ -38,10 +38,13 @@
"homepage": "https://github.com/halo-dev/console/tree/main/packages/shared#readme", "homepage": "https://github.com/halo-dev/console/tree/main/packages/shared#readme",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"vite-plugin-dts": "^1.7.3" "vite-plugin-dts": "^2.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"vue": "^3.2.37", "vue": "^3.2.37",
"vue-router": "^4.0.16" "vue-router": "^4.0.16"
},
"dependencies": {
"@halo-dev/api-client": "workspace:*"
} }
} }

View File

@ -1,5 +1,5 @@
{ {
"extends": "@vue/tsconfig/tsconfig.web.json", "extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"], "exclude": ["src/**/__tests__/*"],
"compilerOptions": { "compilerOptions": {

View File

@ -2,7 +2,7 @@
"files": [], "files": [],
"references": [ "references": [
{ {
"path": "./tsconfig.vite-config.json" "path": "./tsconfig.node.json"
}, },
{ {
"path": "./tsconfig.app.json" "path": "./tsconfig.app.json"

View File

@ -0,0 +1,9 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*"],
"compilerOptions": {
"composite": true,
"module": "ESNext",
"types": ["node"]
}
}

View File

@ -1,8 +0,0 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["vite.config.*"],
"compilerOptions": {
"composite": true,
"types": ["node", "vitest"]
}
}

View File

@ -11,6 +11,7 @@ export default defineConfig({
Vue(), Vue(),
VueJsx(), VueJsx(),
Dts({ Dts({
tsConfigFilePath: "./tsconfig.app.json",
entryRoot: "./src", entryRoot: "./src",
outputDir: "./dist", outputDir: "./dist",
insertTypesEntry: true, insertTypesEntry: true,

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,7 @@ const RoutesMenu = defineComponent({
} }
return () => ( return () => (
// @ts-ignore
<VMenu openIds={openIds.value}> <VMenu openIds={openIds.value}>
{props.menus?.map((menu: MenuGroupType) => { {props.menus?.map((menu: MenuGroupType) => {
return ( return (

View File

@ -117,7 +117,12 @@ const confirmCountMessage = computed(() => {
> >
<VTabbar <VTabbar
v-model:active-id="activeId" v-model:active-id="activeId"
:items="attachmentSelectProviders" :items="
attachmentSelectProviders.map((provider) => ({
id: provider.id,
label: provider.label,
}))
"
class="w-full" class="w-full"
type="outline" type="outline"
></VTabbar> ></VTabbar>

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { VCard, IconBookRead } from "@halo-dev/components"; import { VCard, IconBookRead } from "@halo-dev/components";
import { inject, type Ref } from "vue"; import { inject, type Ref } from "vue";
import type { DashboardStats } from "@halo-dev/api-client/index"; import type { DashboardStats } from "@halo-dev/api-client";
const dashboardStats = inject<Ref<DashboardStats>>("dashboardStats"); const dashboardStats = inject<Ref<DashboardStats>>("dashboardStats");
</script> </script>

View File

@ -123,7 +123,7 @@ import { onMounted, provide, ref, type Ref } from "vue";
import { useStorage } from "@vueuse/core"; import { useStorage } from "@vueuse/core";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import type { DashboardStats } from "@halo-dev/api-client/index"; import type { DashboardStats } from "@halo-dev/api-client";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
const { t } = useI18n(); const { t } = useI18n();

View File

@ -301,9 +301,6 @@ exports[`sortMenuItemsTree > will match snapshot 1`] = `
"version": 12, "version": 12,
}, },
"spec": { "spec": {
"categoryRef": {
"name": "",
},
"children": [ "children": [
{ {
"apiVersion": "v1alpha1", "apiVersion": "v1alpha1",
@ -314,22 +311,10 @@ exports[`sortMenuItemsTree > will match snapshot 1`] = `
"version": 0, "version": 0,
}, },
"spec": { "spec": {
"categoryRef": {
"name": "",
},
"children": [], "children": [],
"displayName": "Java", "displayName": "Java",
"href": "https://ryanc.cc/categories/java", "href": "https://ryanc.cc/categories/java",
"pageRef": {
"name": "",
},
"postRef": {
"name": "",
},
"priority": 0, "priority": 0,
"tagRef": {
"name": "",
},
}, },
}, },
{ {
@ -341,37 +326,16 @@ exports[`sortMenuItemsTree > will match snapshot 1`] = `
"version": 4, "version": 4,
}, },
"spec": { "spec": {
"categoryRef": {
"name": "",
},
"children": [], "children": [],
"displayName": "Halo", "displayName": "Halo",
"href": "https://ryanc.cc/categories/halo", "href": "https://ryanc.cc/categories/halo",
"pageRef": {
"name": "",
},
"postRef": {
"name": "",
},
"priority": 1, "priority": 1,
"tagRef": {
"name": "",
},
}, },
}, },
], ],
"displayName": "文章分类", "displayName": "文章分类",
"href": "https://ryanc.cc/categories", "href": "https://ryanc.cc/categories",
"pageRef": {
"name": "",
},
"postRef": {
"name": "",
},
"priority": 0, "priority": 0,
"tagRef": {
"name": "",
},
}, },
}, },
] ]

View File

@ -137,9 +137,6 @@ describe("sortMenuItemsTree", () => {
version: 12, version: 12,
}, },
spec: { spec: {
categoryRef: {
name: "",
},
children: [ children: [
{ {
apiVersion: "v1alpha1", apiVersion: "v1alpha1",
@ -150,22 +147,10 @@ describe("sortMenuItemsTree", () => {
version: 4, version: 4,
}, },
spec: { spec: {
categoryRef: {
name: "",
},
children: [], children: [],
priority: 1, priority: 1,
displayName: "Halo", displayName: "Halo",
href: "https://ryanc.cc/categories/halo", href: "https://ryanc.cc/categories/halo",
pageRef: {
name: "",
},
postRef: {
name: "",
},
tagRef: {
name: "",
},
}, },
}, },
{ {
@ -177,37 +162,16 @@ describe("sortMenuItemsTree", () => {
version: 0, version: 0,
}, },
spec: { spec: {
categoryRef: {
name: "",
},
children: [], children: [],
priority: 0, priority: 0,
displayName: "Java", displayName: "Java",
href: "https://ryanc.cc/categories/java", href: "https://ryanc.cc/categories/java",
pageRef: {
name: "",
},
postRef: {
name: "",
},
tagRef: {
name: "",
},
}, },
}, },
], ],
priority: 0, priority: 0,
displayName: "文章分类", displayName: "文章分类",
href: "https://ryanc.cc/categories", href: "https://ryanc.cc/categories",
pageRef: {
name: "",
},
postRef: {
name: "",
},
tagRef: {
name: "",
},
}, },
}, },
]; ];

View File

@ -16,8 +16,7 @@ import { useThemeStore } from "@/stores/theme";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import { useRouteQuery } from "@vueuse/router"; import { useRouteQuery } from "@vueuse/router";
import { submitForm } from "@formkit/core"; import { submitForm } from "@formkit/core";
import type { ErrorResponse } from "@uppy/core"; import type { ErrorResponse, UppyFile } from "@uppy/core";
import type { UppyFile } from "@uppy/utils";
const { t } = useI18n(); const { t } = useI18n();
const queryClient = useQueryClient(); const queryClient = useQueryClient();

View File

@ -248,9 +248,10 @@ const iframeClasses = computed(() => {
@update:visible="onVisibleChange" @update:visible="onVisibleChange"
> >
<template #center> <template #center>
<!-- TODO: Reactor VTabbar component to support icon prop -->
<VTabbar <VTabbar
v-model:active-id="deviceActiveId" v-model:active-id="deviceActiveId"
:items="mockDevices" :items="mockDevices as any"
type="outline" type="outline"
></VTabbar> ></VTabbar>
</template> </template>

View File

@ -245,7 +245,7 @@ onMounted(() => {
<template #header> <template #header>
<VTabbar <VTabbar
v-model:active-id="activeTab" v-model:active-id="activeTab"
:items="tabs" :items="tabs.map((item) => ({ id: item.id, label: item.label }))"
class="w-full !rounded-none" class="w-full !rounded-none"
type="outline" type="outline"
@change="handleTabChange" @change="handleTabChange"

View File

@ -11,8 +11,7 @@ import UppyUpload from "@/components/upload/UppyUpload.vue";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import type { Plugin } from "@halo-dev/api-client"; import type { Plugin } from "@halo-dev/api-client";
import { computed, ref, watch, nextTick } from "vue"; import { computed, ref, watch, nextTick } from "vue";
import type { SuccessResponse, ErrorResponse } from "@uppy/core"; import type { SuccessResponse, ErrorResponse, UppyFile } from "@uppy/core";
import type { UppyFile } from "@uppy/utils";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useQueryClient } from "@tanstack/vue-query"; import { useQueryClient } from "@tanstack/vue-query";
import { useRouteQuery } from "@vueuse/router"; import { useRouteQuery } from "@vueuse/router";

View File

@ -160,7 +160,7 @@ watch([() => route.name, () => route.params], () => {
<template #header> <template #header>
<VTabbar <VTabbar
v-model:active-id="activeTab" v-model:active-id="activeTab"
:items="tabs" :items="tabs.map((item) => ({ id: item.id, label: item.label }))"
class="w-full !rounded-none" class="w-full !rounded-none"
type="outline" type="outline"
@change="handleTabChange" @change="handleTabChange"

View File

@ -116,7 +116,7 @@ watch([() => route.name, () => route.params], async () => {
<template #header> <template #header>
<VTabbar <VTabbar
v-model:active-id="activeTab" v-model:active-id="activeTab"
:items="tabs" :items="tabs.map((item) => ({ id: item.id, label: item.label }))"
class="w-full !rounded-none" class="w-full !rounded-none"
type="outline" type="outline"
@change="handleTabChange" @change="handleTabChange"

View File

@ -1,5 +1,5 @@
{ {
"extends": "@vue/tsconfig/tsconfig.web.json", "extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*", "packages/**/*"], "exclude": ["src/**/__tests__/*", "packages/**/*"],
"compilerOptions": { "compilerOptions": {
@ -10,6 +10,7 @@
"@/*": ["./src/*"] "@/*": ["./src/*"]
}, },
"noStrictGenericChecks": true, "noStrictGenericChecks": true,
"ignoreDeprecations": "5.0",
"types": ["unplugin-icons/types/vue"] "types": ["unplugin-icons/types/vue"]
} }
} }

View File

@ -2,7 +2,7 @@
"files": [], "files": [],
"references": [ "references": [
{ {
"path": "./tsconfig.vite-config.json" "path": "./tsconfig.node.json"
}, },
{ {
"path": "./tsconfig.app.json" "path": "./tsconfig.app.json"

View File

@ -0,0 +1,14 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"./src/build/library-external.ts"
],
"compilerOptions": {
"composite": true,
"module": "ESNext",
"types": ["node"]
}
}

View File

@ -1,8 +0,0 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["vite.config.*","./src/build/*.ts"],
"compilerOptions": {
"composite": true,
"types": ["node", "vitest"]
}
}