Skip to content

Commit

Permalink
fix(vue-tsc): runtime error UI
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Mar 24, 2022
1 parent ad0803a commit 6c561e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
52 changes: 18 additions & 34 deletions packages/vite-plugin-checker/src/checkers/vueTsc/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
diagnosticToRuntimeError,
diagnosticToTerminalLog,
ensureCall,
normalizeTsDiagnostic,
normalizeVueTscDiagnostic,
toViteCustomPayload,
wrapCheckerSummary,
} from '../../logger'
Expand All @@ -28,10 +28,9 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
terminal = enableTerminal
},
configureServer({ root }) {
invariant(pluginConfig.vueTsc, 'config.typescript should be `false`')
invariant(pluginConfig.vueTsc, 'config.vueTsc should be `false`')

const { tsDirTo } = prepareVueTsc()
// const tsDirTo = path.resolve(__dirname, 'typescript-vue-tsc')

const vueTs = require(path.resolve(tsDirTo, 'lib/tsc.js'))

Expand Down Expand Up @@ -61,13 +60,13 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {

// https://github.com/microsoft/TypeScript/blob/a545ab1ac2cb24ff3b1aaf0bfbfb62c499742ac2/src/compiler/watch.ts#L12-L28
const reportDiagnostic = (diagnostic: ts.Diagnostic) => {
const normalizedDiagnostic = normalizeTsDiagnostic(diagnostic)
const normalizedDiagnostic = normalizeVueTscDiagnostic(diagnostic)
if (normalizedDiagnostic === null) {
return
}

currDiagnostics.push(diagnosticToRuntimeError(normalizedDiagnostic))
logChunk += os.EOL + diagnosticToTerminalLog(normalizedDiagnostic, 'TypeScript')
logChunk += os.EOL + diagnosticToTerminalLog(normalizedDiagnostic, 'vue-tsc')
}

const reportWatchStatusChanged: ts.WatchStatusReporter = (
Expand All @@ -93,7 +92,7 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
if (overlay) {
parentPort?.postMessage({
type: ACTION_TYPES.overlayError,
payload: toViteCustomPayload('typescript', currDiagnostics),
payload: toViteCustomPayload('vue-tsc', currDiagnostics),
})
}
}
Expand All @@ -105,9 +104,7 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {

if (terminal) {
consoleLog(
logChunk +
os.EOL +
wrapCheckerSummary('TypeScript', diagnostic.messageText.toString())
logChunk + os.EOL + wrapCheckerSummary('vue-tsc', diagnostic.messageText.toString())
)
}
})
Expand All @@ -117,27 +114,16 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
// https://github.com/microsoft/TypeScript/pull/33082/files
const createProgram = vueTs.createSemanticDiagnosticsBuilderProgram

if (typeof pluginConfig.vueTsc === 'object' && pluginConfig.vueTsc.buildMode) {
// const host = ts.createSolutionBuilderWithWatchHost(
// ts.sys,
// createProgram,
// reportDiagnostic,
// undefined,
// reportWatchStatusChanged
// )
// ts.createSolutionBuilderWithWatch(host, [configFile], {}).build()
} else {
const host = vueTs.createWatchCompilerHost(
configFile,
{ noEmit: true },
vueTs.sys,
createProgram,
reportDiagnostic,
reportWatchStatusChanged
)
const host = vueTs.createWatchCompilerHost(
configFile,
{ noEmit: true },
vueTs.sys,
createProgram,
reportDiagnostic,
reportWatchStatusChanged
)

vueTs.createWatchProgram(host)
}
vueTs.createWatchProgram(host)
},
}
}
Expand All @@ -149,12 +135,10 @@ export class VueTscChecker extends Checker<'vueTsc'> {
absFilePath: __filename,
build: {
buildBin: (config) => {
if (typeof config.typescript === 'object') {
const { root, tsconfigPath, buildMode } = config.typescript

// Compiler option '--noEmit' may not be used with '--build'
let args = [buildMode ? '-b' : '--noEmit']
if (typeof config.vueTsc === 'object') {
const { root, tsconfigPath } = config.vueTsc

let args = ['--noEmit']
// Custom config path
if (tsconfigPath) {
const fullConfigPath = root ? path.join(root, tsconfigPath) : tsconfigPath
Expand Down
6 changes: 6 additions & 0 deletions packages/vite-plugin-checker/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ export function lspRange2Location(range: Range): SourceLocation {

/* --------------------------------- vue-tsc -------------------------------- */

export function normalizeVueTscDiagnostic(d: TsDiagnostic): NormalizedDiagnostic {
const diagnostic = normalizeTsDiagnostic(d)
diagnostic.checker = 'vue-tsc'
return diagnostic
}

/* --------------------------------- ESLint --------------------------------- */

const isNormalizedDiagnostic = (
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type VueTscConfig =
* - set to `true` to enable type checking with default configuration
* - set to `false` to disable type checking, you can also remove `config.vueTsc` directly
*/
boolean | Partial<Omit<TsConfigOptions, 'build'>>
boolean | Partial<Omit<TsConfigOptions, 'buildMode'>>

/** vls checker configuration */
export type VlsConfig = boolean | DeepPartial<VlsOptions>
Expand Down
1 change: 0 additions & 1 deletion playground/vue3-vue-tsc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"noEmit": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
Expand Down

0 comments on commit 6c561e8

Please sign in to comment.