Skip to content

Commit

Permalink
fix(ts/vue-tsc): able to resolve tsconfig when only root specified (#247
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fi3ework committed Jun 18, 2023
1 parent f068bf3 commit 154ca0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-cherries-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-checker": patch
---

Able to resolve tsconfig when only root specified in build mode, as well as vue-tsc.
15 changes: 9 additions & 6 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,23 @@ export class TscChecker extends Checker<'typescript'> {
build: {
buildBin: (config) => {
if (typeof config.typescript === 'object') {
const { root, tsconfigPath, buildMode } = config.typescript
const { root = '', tsconfigPath = '', buildMode } = config.typescript

// Compiler option '--noEmit' may not be used with '--build'
let args = [buildMode ? '-b' : '--noEmit']
const args = [buildMode ? '-b' : '--noEmit']

// Custom config path
if (tsconfigPath) {
const fullConfigPath = root ? path.join(root, tsconfigPath) : tsconfigPath
let projectPath = ''
if (root || tsconfigPath) {
projectPath = root ? path.join(root, tsconfigPath) : tsconfigPath
}

if (projectPath) {
// In build mode, the tsconfig path is an argument to -b, e.g. "tsc -b [path]"
if (buildMode) {
args = args.concat([fullConfigPath])
args.push(projectPath)
} else {
args = args.concat(['-p', fullConfigPath])
args.push('-p', projectPath)
}
}

Expand Down
12 changes: 8 additions & 4 deletions packages/vite-plugin-checker/src/checkers/vueTsc/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ export class VueTscChecker extends Checker<'vueTsc'> {
build: {
buildBin: (config) => {
if (typeof config.vueTsc === 'object') {
const { root, tsconfigPath } = config.vueTsc
const { root = '', tsconfigPath = '' } = config.vueTsc

let args = ['--noEmit']
// Custom config path
if (tsconfigPath) {
const fullConfigPath = root ? path.join(root, tsconfigPath) : tsconfigPath
args = args.concat(['-p', fullConfigPath])
let projectPath = ''
if (root || tsconfigPath) {
projectPath = root ? path.join(root, tsconfigPath) : tsconfigPath
}

if (projectPath) {
args.push('-p', projectPath)
}

return ['vue-tsc', args]
Expand Down

0 comments on commit 154ca0f

Please sign in to comment.