Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support typescript path #296

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-lizards-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-checker': minor
---

add support custom typescript path
13 changes: 7 additions & 6 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from 'os'
import path from 'path'
import invariant from 'tiny-invariant'
import ts from 'typescript'
import type * as typescript from 'typescript'
import { fileURLToPath } from 'url'
import { parentPort } from 'worker_threads'

Expand Down Expand Up @@ -30,18 +30,19 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
overlay = enableOverlay
terminal = enableTerminal
},
configureServer({ root }) {
async configureServer({ root }) {
invariant(pluginConfig.typescript, 'config.typescript should be `false`')
const finalConfig =
pluginConfig.typescript === true
? { root, tsconfigPath: 'tsconfig.json' }
? { root, tsconfigPath: 'tsconfig.json', typescriptPath: 'typescript' }
: {
root: pluginConfig.typescript.root ?? root,
tsconfigPath: pluginConfig.typescript.tsconfigPath ?? 'tsconfig.json',
typescriptPath: pluginConfig.typescript.typescriptPath ?? 'typescript',
}

let configFile: string | undefined

const ts: typeof typescript = await import(finalConfig.typescriptPath)
configFile = ts.findConfigFile(finalConfig.root, ts.sys.fileExists, finalConfig.tsconfigPath)

if (configFile === undefined) {
Expand All @@ -53,7 +54,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
let logChunk = ''

// https://github.com/microsoft/TypeScript/blob/a545ab1ac2cb24ff3b1aaf0bfbfb62c499742ac2/src/compiler/watch.ts#L12-L28
const reportDiagnostic = (diagnostic: ts.Diagnostic) => {
const reportDiagnostic = (diagnostic: typescript.Diagnostic) => {
const normalizedDiagnostic = normalizeTsDiagnostic(diagnostic)
if (normalizedDiagnostic === null) {
return
Expand All @@ -63,7 +64,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
logChunk += os.EOL + diagnosticToTerminalLog(normalizedDiagnostic, 'TypeScript')
}

const reportWatchStatusChanged: ts.WatchStatusReporter = (
const reportWatchStatusChanged: typescript.WatchStatusReporter = (
diagnostic,
newLine,
options,
Expand Down
4 changes: 4 additions & 0 deletions packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ interface TsConfigOptions {
* path to tsconfig.json file
*/
tsconfigPath: string
/**
* path to typescript package
*/
typescriptPath: string
/**
* root path of cwd
*/
Expand Down