From f508d2e6c0a64e5b0ab07438d55dfc5cac25d360 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 27 May 2020 21:13:21 +0800 Subject: [PATCH] feat(cli): enable type checking --- packages/vant-cli/package.json | 1 + packages/vant-cli/src/config/webpack.base.ts | 42 ++++++++++++++++---- packages/vant-cli/yarn.lock | 27 ++++++++++++- types/sku.d.ts | 1 + 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index 789152aef..5e6c2b2f3 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -73,6 +73,7 @@ "css-loader": "^3.5.3", "eslint": "^6.8.0", "fast-glob": "^3.2.2", + "fork-ts-checker-webpack-plugin": "^4.1.6", "gh-pages": "^2.2.0", "hash-sum": "^2.0.0", "html-webpack-plugin": "4.3.0", diff --git a/packages/vant-cli/src/config/webpack.base.ts b/packages/vant-cli/src/config/webpack.base.ts index a15173df4..13343a6ad 100644 --- a/packages/vant-cli/src/config/webpack.base.ts +++ b/packages/vant-cli/src/config/webpack.base.ts @@ -1,7 +1,11 @@ import sass from 'sass'; import FriendlyErrorsPlugin from '@nuxt/friendly-errors-webpack-plugin'; import { VueLoaderPlugin } from 'vue-loader'; +import { join } from 'path'; +import { existsSync } from 'fs'; +import { consola } from '../common/logger'; import { + CWD, CACHE_DIR, STYLE_EXTS, SCRIPT_EXTS, @@ -28,6 +32,36 @@ const CSS_LOADERS = [ }, ]; +const plugins = [ + new VueLoaderPlugin(), + new FriendlyErrorsPlugin({ + clearConsole: false, + logLevel: 'WARNING', + }), +]; + +const tsconfigPath = join(CWD, 'tsconfig.json'); +console.log('tsconfigPath', existsSync(tsconfigPath)); +if (existsSync(tsconfigPath)) { + const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin'); + plugins.push( + new ForkTsCheckerPlugin({ + formatter: 'codeframe', + vue: { enabled: true }, + logger: { + // skip info message + info() {}, + warn(message: string) { + consola.warn(message); + }, + error(message: string) { + consola.error(message); + }, + }, + }) + ); +} + export const baseConfig = { mode: 'development', resolve: { @@ -83,11 +117,5 @@ export const baseConfig = { }, ], }, - plugins: [ - new VueLoaderPlugin(), - new FriendlyErrorsPlugin({ - clearConsole: false, - logLevel: 'WARNING', - }), - ], + plugins, }; diff --git a/packages/vant-cli/yarn.lock b/packages/vant-cli/yarn.lock index 5a5846945..fb6be038f 100644 --- a/packages/vant-cli/yarn.lock +++ b/packages/vant-cli/yarn.lock @@ -2,7 +2,7 @@ # yarn lockfile v1 -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.8.3.tgz#33e25903d7481181534e12ec0a25f16b6fcf419e" integrity sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g== @@ -4946,6 +4946,19 @@ forever-agent@~0.6.1: resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= +fork-ts-checker-webpack-plugin@^4.1.6: + version "4.1.6" + resolved "https://registry.npm.taobao.org/fork-ts-checker-webpack-plugin/download/fork-ts-checker-webpack-plugin-4.1.6.tgz#5055c703febcf37fa06405d400c122b905167fc5" + integrity sha1-UFXHA/6883+gZAXUAMEiuQUWf8U= + dependencies: + "@babel/code-frame" "^7.5.5" + chalk "^2.4.1" + micromatch "^3.1.10" + minimatch "^3.0.4" + semver "^5.6.0" + tapable "^1.0.0" + worker-rpc "^0.1.0" + form-data@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682" @@ -7582,6 +7595,11 @@ methods@~1.1.2: resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= +microevent.ts@~0.1.1: + version "0.1.1" + resolved "https://registry.npm.taobao.org/microevent.ts/download/microevent.ts-0.1.1.tgz#70b09b83f43df5172d0205a63025bce0f7357fa0" + integrity sha1-cLCbg/Q99RctAgWmMCW84Pc1f6A= + micromatch@^3.1.10, micromatch@^3.1.4: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" @@ -11892,6 +11910,13 @@ worker-farm@^1.7.0: dependencies: errno "~0.1.7" +worker-rpc@^0.1.0: + version "0.1.1" + resolved "https://registry.npm.taobao.org/worker-rpc/download/worker-rpc-0.1.1.tgz#cb565bd6d7071a8f16660686051e969ad32f54d5" + integrity sha1-y1Zb1tcHGo8WZgaGBR6WmtMvVNU= + dependencies: + microevent.ts "~0.1.1" + wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" diff --git a/types/sku.d.ts b/types/sku.d.ts index 6e4d7c6ff..9d8215ac6 100644 --- a/types/sku.d.ts +++ b/types/sku.d.ts @@ -16,6 +16,7 @@ export type SkuTreeItemData = { k: string; v: SkuTreeItemValueData[]; k_s: string; + is_multiple: never; }; export type SkuTreeItemValueData = {