From 7b7afc8f49a34efefe93dc9667762b0b7f4fa6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 15 Feb 2022 14:45:50 +0800 Subject: [PATCH] refactor: improve tsconfig (#5993) * refactor: improve tsconfig * chore: add cypress tsconfig --- build/gulpfile.ts | 2 +- build/tsconfig.json | 12 +++++---- cypress/tsconfig.json | 10 +++++++ typings/global.d.ts => global.d.ts | 0 package.json | 2 ++ play/tsconfig.json | 10 +++---- pnpm-lock.yaml | 30 +++++++++++++++++++++ tsconfig.jest.json | 10 +++++++ tsconfig.json | 22 ++++++++------- play/global.d.ts => typings/components.d.ts | 2 ++ 10 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 cypress/tsconfig.json rename typings/global.d.ts => global.d.ts (100%) create mode 100644 tsconfig.jest.json rename play/global.d.ts => typings/components.d.ts (99%) diff --git a/build/gulpfile.ts b/build/gulpfile.ts index 1df445136a562..9cfbaad534f31 100644 --- a/build/gulpfile.ts +++ b/build/gulpfile.ts @@ -17,7 +17,7 @@ export const copyFiles = () => path.resolve(epOutput, 'README.md') ), copyFile( - path.resolve(projRoot, 'typings/global.d.ts'), + path.resolve(projRoot, 'global.d.ts'), path.resolve(epOutput, 'global.d.ts') ), ]) diff --git a/build/tsconfig.json b/build/tsconfig.json index 4710dcd6daf2d..7366cbe4a640c 100644 --- a/build/tsconfig.json +++ b/build/tsconfig.json @@ -1,9 +1,11 @@ { - "extends": "../tsconfig.json", + "extends": "@vue/tsconfig/tsconfig.node.json", "compilerOptions": { - "module": "CommonJS", - "target": "ESNext", - "lib": ["ESNext"] + "target": "ES2021", + "lib": ["ES2021"], + "types": ["node"], + "moduleResolution": "Node", + "allowSyntheticDefaultImports": true }, - "include": ["**/*.ts"] + "include": ["**/*"] } diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 0000000000000..a2dbf9e3f93fc --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "@vue/tsconfig/tsconfig.web.json", + "include": ["./integration/**/*", "./support/**/*"], + "compilerOptions": { + "isolatedModules": false, + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress"] + } +} diff --git a/typings/global.d.ts b/global.d.ts similarity index 100% rename from typings/global.d.ts rename to global.d.ts diff --git a/package.json b/package.json index 8d2f0fc294ade..56ba1617b4e6b 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@types/lodash": "4.14.178", "@types/lodash-es": "4.17.6", "@types/node": "17.0.16", + "@types/rollup-plugin-css-only": "^3.1.0", "@types/sass": "1.43.1", "@typescript-eslint/eslint-plugin": "5.12.0", "@typescript-eslint/parser": "5.12.0", @@ -97,6 +98,7 @@ "@vitejs/plugin-vue-jsx": "1.3.7", "@vue/babel-plugin-jsx": "1.1.1", "@vue/test-utils": "2.0.0-rc.16", + "@vue/tsconfig": "^0.1.3", "babel-jest": "26.6.3", "chalk": "4.1.2", "components-helper": "2.0.0", diff --git a/play/tsconfig.json b/play/tsconfig.json index 8bd0c6bf0b64b..b7621046bb7f9 100644 --- a/play/tsconfig.json +++ b/play/tsconfig.json @@ -1,14 +1,10 @@ { + "extends": "@vue/tsconfig/tsconfig.web.json", "compilerOptions": { - "strict": true, "allowJs": true, - "module": "ESNext", "lib": ["ESNext", "DOM"], - "types": ["vite/client", "./global"], - "resolveJsonModule": true, - "moduleResolution": "Node", - "allowSyntheticDefaultImports": true, - "baseUrl": "." + "types": ["node", "vite/client", "../typings/components"], + "allowSyntheticDefaultImports": true }, "include": ["**/*"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8b08cbd00b09..7c0184e62e96b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,7 @@ importers: '@types/lodash': 4.14.178 '@types/lodash-es': 4.17.6 '@types/node': 17.0.16 + '@types/rollup-plugin-css-only': ^3.1.0 '@types/sass': 1.43.1 '@typescript-eslint/eslint-plugin': 5.12.0 '@typescript-eslint/parser': 5.12.0 @@ -39,6 +40,7 @@ importers: '@vitejs/plugin-vue-jsx': 1.3.7 '@vue/babel-plugin-jsx': 1.1.1 '@vue/test-utils': 2.0.0-rc.16 + '@vue/tsconfig': ^0.1.3 '@vueuse/core': ^7.6.0 async-validator: ^4.0.7 babel-jest: 26.6.3 @@ -124,6 +126,7 @@ importers: '@types/lodash': 4.14.178 '@types/lodash-es': 4.17.6 '@types/node': 17.0.16 + '@types/rollup-plugin-css-only': 3.1.0 '@types/sass': 1.43.1 '@typescript-eslint/eslint-plugin': 5.12.0_c467cf9bb49b295941e83ce479a578b7 '@typescript-eslint/parser': 5.12.0_eslint@8.9.0+typescript@4.5.5 @@ -131,6 +134,7 @@ importers: '@vitejs/plugin-vue-jsx': 1.3.7 '@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.17.2 '@vue/test-utils': 2.0.0-rc.16_vue@3.2.30 + '@vue/tsconfig': 0.1.3_@types+node@17.0.16 babel-jest: 26.6.3_@babel+core@7.17.2 chalk: 4.1.2 components-helper: 2.0.0 @@ -2938,6 +2942,13 @@ packages: '@types/node': 17.0.16 dev: true + /@types/rollup-plugin-css-only/3.1.0: + resolution: {integrity: sha512-2/CYJ3xDTVtS9DBDXhj0jjxF3idO1yUjJWjFzqA3JlK8NqSlUHeMKv3FH/VILLrnvdZRY+901TlDPnKa4WhFYA==} + dependencies: + '@types/node': 17.0.16 + rollup: 0.63.5 + dev: true + /@types/sass/1.43.1: resolution: {integrity: sha512-BPdoIt1lfJ6B7rw35ncdwBZrAssjcwzI5LByIrYs+tpXlj/CAkuVdRsgZDdP4lq5EjyWzwxZCqAoFyHKFwp32g==} dependencies: @@ -3446,6 +3457,17 @@ packages: vue: 3.2.30 dev: true + /@vue/tsconfig/0.1.3_@types+node@17.0.16: + resolution: {integrity: sha512-kQVsh8yyWPvHpb8gIc9l/HIDiiVUy1amynLNpCy8p+FoCiZXCo6fQos5/097MmnNZc9AtseDsCrfkhqCrJ8Olg==} + peerDependencies: + '@types/node': '*' + peerDependenciesMeta: + '@types/node': + optional: true + dependencies: + '@types/node': 17.0.16 + dev: true + /@vueuse/core/7.6.0_vue@3.2.30: resolution: {integrity: sha512-gTkTYbOO19AnhmbH39mMlfoOOcxSSOtXeI69Ixm7gE/C0eT8Vnpb7VE9KGrobCr4sUqE5fmwAdPIYkdB/NJIzQ==} peerDependencies: @@ -10539,6 +10561,14 @@ packages: - supports-color dev: true + /rollup/0.63.5: + resolution: {integrity: sha512-dFf8LpUNzIj3oE0vCvobX6rqOzHzLBoblyFp+3znPbjiSmSvOoK2kMKx+Fv9jYduG1rvcCfCveSgEaQHjWRF6g==} + hasBin: true + dependencies: + '@types/estree': 0.0.39 + '@types/node': 17.0.16 + dev: true + /rollup/2.67.2: resolution: {integrity: sha512-hoEiBWwZtf1QdK3jZIq59L0FJj4Fiv4RplCO4pvCRC86qsoFurWB4hKQIjoRf3WvJmk5UZ9b0y5ton+62fC7Tw==} engines: {node: '>=10.0.0'} diff --git a/tsconfig.jest.json b/tsconfig.jest.json new file mode 100644 index 0000000000000..3dbbaf54e8cb1 --- /dev/null +++ b/tsconfig.jest.json @@ -0,0 +1,10 @@ +{ + "extends": "@vue/tsconfig/tsconfig.node.json", + "include": ["packages/**/*.test.*", "packages/**/*.spec.*"], + "compilerOptions": { + "composite": true, + "lib": ["DOM"], + "types": ["node", "jest"], + "jsx": "preserve" + } +} diff --git a/tsconfig.json b/tsconfig.json index 82d7dcd98fd93..39669f74e5947 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,23 @@ { + "extends": "@vue/tsconfig/tsconfig.web.json", "compilerOptions": { "allowJs": true, - "strict": true, "module": "ES6", "target": "ES2018", "noImplicitAny": false, "declaration": true, - "moduleResolution": "Node", - "esModuleInterop": true, - "jsx": "preserve", "sourceMap": true, - "lib": ["ES2018", "DOM"], + "lib": ["ES2018", "DOM", "DOM.Iterable"], "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "types": ["unplugin-vue-define-options", "jest", "./typings/jsx-shim"] + "types": ["unplugin-vue-define-options"] }, - "include": ["packages"], - "exclude": ["node_modules", "**/dist"] + "references": [{ "path": "./tsconfig.jest.json" }], + "include": ["packages", "typings"], + "exclude": [ + "node_modules", + "**/dist", + "**/__tests__", + "**/*.test.*", + "**/*.spec.*" + ] } diff --git a/play/global.d.ts b/typings/components.d.ts similarity index 99% rename from play/global.d.ts rename to typings/components.d.ts index 4a25733c72ed9..cc7e295c99f03 100644 --- a/play/global.d.ts +++ b/typings/components.d.ts @@ -1,3 +1,5 @@ +// For this project development + // GlobalComponents for Volar declare module 'vue' { export interface GlobalComponents {