Skip to content

Commit

Permalink
fix: compatible with mac’s duplication watch report
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 29, 2023
1 parent 30510a6 commit 5dd90c9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
"typescript": "^5.0.4",
"vls": "^0.7.6",
"vti": "^0.1.7",
"vue-tsc": "^1.4.3"
"vue-tsc": "^1.6.1"
}
}
13 changes: 9 additions & 4 deletions packages/vite-plugin-checker/src/checkers/vueTsc/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
invariant(pluginConfig.vueTsc, 'config.vueTsc should be `false`')

const { targetTsDir } = await prepareVueTsc()

const vueTs = _require(path.resolve(targetTsDir, 'lib/typescript.js'))

const finalConfig =
pluginConfig.vueTsc === true
? { root, tsconfigPath: 'tsconfig.json' }
Expand All @@ -64,6 +62,7 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
}

let logChunk = ''
let prevLogChunk = ''

// https://github.com/microsoft/TypeScript/blob/a545ab1ac2cb24ff3b1aaf0bfbfb62c499742ac2/src/compiler/watch.ts#L12-L28
const reportDiagnostic = (diagnostic: ts.Diagnostic) => {
Expand Down Expand Up @@ -110,9 +109,15 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
}

if (terminal) {
consoleLog(
logChunk =
logChunk + os.EOL + wrapCheckerSummary('vue-tsc', diagnostic.messageText.toString())
)
if (logChunk === prevLogChunk) {
return
}

// TODO: only macOS will report multiple times for same result
prevLogChunk = logChunk
consoleLog(logChunk)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function prepareVueTsc() {
// 1. copy typescript to folder
const targetTsDir = path.resolve(_dirname, 'typescript-vue-tsc')
const vueTscFlagFile = path.resolve(targetTsDir, 'vue-tsc-resolve-path')
// let currTsVersion: string = ''
const currTsVersion = _require('typescript/package.json').version

let shouldBuildFixture = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,5 @@ exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 4`] =
5 |
6 | <script lang=\\"ts\\">
[vue-tsc] Found 1 error. Watching for file changes.
ERROR(vue-tsc) Argument of type '{ msg2: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'.
Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue:3:4
1 | <template>
2 | <img alt=\\"Vue logo\\" src=\\"./assets/logo.png\\" />
> 3 | <HelloWorld msg2=\\"Diana\\" />
| ^^^^^^^^^^
4 | </template>
5 |
6 | <script lang=\\"ts\\">
[vue-tsc] Found 1 error. Watching for file changes."
`;
2 changes: 0 additions & 2 deletions playground/vue-tsc-vue3-ts4/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ describe('vue-tsc-vue3-ts4', () => {
it('get initial error and subsequent error', async () => {
await sleepForServerReady(2)
expect(stringify(diagnostics)).toMatchSnapshot()
console.log('🙇 diagnostics', stringify(diagnostics))
console.log('🙇 stripedLog', stripedLog)
expect(stripedLog).toMatchSnapshot()

console.log('-- edit file --')
Expand Down
4 changes: 2 additions & 2 deletions playground/vue-tsc-vue3-ts4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.25"
"vue": "^3.2.47"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.1",
"typescript": "^4",
"vite": "^4.3.0",
"vite-plugin-checker": "workspace:*",
"vue-tsc": "^1.4.3"
"vue-tsc": "^1.6.1"
}
}
13 changes: 0 additions & 13 deletions playground/vue-tsc-vue3/__tests__/__snapshots__/test.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,5 @@ exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 4`] = `
5 |
6 | <script lang=\\"ts\\">
[vue-tsc] Found 1 error. Watching for file changes.
ERROR(vue-tsc) Argument of type '{ msg2: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'.
Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue:3:4
1 | <template>
2 | <img alt=\\"Vue logo\\" src=\\"./assets/logo.png\\" />
> 3 | <HelloWorld msg2=\\"Diana\\" />
| ^^^^^^^^^^
4 | </template>
5 |
6 | <script lang=\\"ts\\">
[vue-tsc] Found 1 error. Watching for file changes."
`;
4 changes: 2 additions & 2 deletions playground/vue-tsc-vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.25"
"vue": "^3.2.47"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.1",
"typescript": "^5.0.4",
"vite": "^4.3.0",
"vite-plugin-checker": "workspace:*",
"vue-tsc": "^1.4.3"
"vue-tsc": "^1.6.1"
}
}
67 changes: 30 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5dd90c9

Please sign in to comment.