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

Support adding additional compiler options #311

Open
wants to merge 9 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/cold-jokes-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-checker': patch
---

Support merging compiler options with tsconfig in checker ts
2 changes: 2 additions & 0 deletions docs/checkers/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ Advanced object configuration table of `options.typescript`.
| root | `string` | [Vite config](https://vitejs.dev/config/#root) `root` | Root path to find tsconfig file |
| tsconfigPath | `string` | `"tsconfig.json"` | Relative tsconfig path to `root` |
| buildMode | `boolean` | `false` | Add [`--build`](https://www.typescriptlang.org/docs/handbook/project-references.html) to `tsc` flag, note that `noEmit` does NOT work if `buildMode` is `true` ([#36917](https://github.com/microsoft/TypeScript/issues/36917)) |
| extraTSOptions | `ts.CompilerOptions \| undefined` | `undefined` | These are extra options that merge with tsconfig, by default when `build: false` this includes `noEmit: true` |

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"version": "0.0.0",
"engines": {
"pnpm": "^7.0.0",
"pnpm": "7.0.0",
"yarn": "forbidden, use pnpm",
"npm": "forbidden, use pnpm"
},
Expand All @@ -25,7 +25,7 @@
}
}
},
"packageManager": "pnpm@7.5.0",
"packageManager": "pnpm@7.0.0",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "pnpm -r --filter=./packages/** --parallel run dev",
Expand Down
24 changes: 22 additions & 2 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,31 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
// https://github.com/microsoft/TypeScript/issues/32385
// https://github.com/microsoft/TypeScript/pull/33082/files
const createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram
const addtionalTypescriptOptions =
typeof pluginConfig.typescript === 'object' ? pluginConfig.typescript.extraTSOptions : {}

if (typeof pluginConfig.typescript === 'object' && pluginConfig.typescript.buildMode) {
const host = ts.createSolutionBuilderWithWatchHost(
ts.sys,
createProgram,
/* eslint-disable */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why disable eslint @EliLichtblau?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres a lint rule that makes it impossible to make a function that takes I think more than 3 arguments iirc - this needs to take 6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using Rest parameters instead. Disabling eslint should be the last resort i guess.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe philosophical difference but I disable eslint when making eslint happy makes the code harder to understand. Imo rest parameters make this code that is currently clear less clear. If the maintainer asks me I'll happily make the change but until then I think disabling eslint is probably the right call

(
rootNames: readonly string[] | undefined,
options: ts.CompilerOptions | undefined,
host?: ts.CompilerHost,
oldProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram,
configFileParsingDiagnostics?: readonly ts.Diagnostic[],
projectReferences?: readonly ts.ProjectReference[] | undefined
) => {
return createProgram(
rootNames,
{ ...options, ...addtionalTypescriptOptions },
host,
oldProgram,
configFileParsingDiagnostics,
projectReferences
)
},
/* eslint-enable */
reportDiagnostic,
undefined,
reportWatchStatusChanged
Expand All @@ -123,7 +143,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
} else {
const host = ts.createWatchCompilerHost(
configFile,
{ noEmit: true },
{ noEmit: true, ...addtionalTypescriptOptions },
ts.sys,
createProgram,
reportDiagnostic,
Expand Down
6 changes: 6 additions & 0 deletions packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Worker } from 'worker_threads'
import type { ESLint } from 'eslint'
import type * as Stylelint from 'stylelint'
import type { VlsOptions } from './checkers/vls/initParams.js'
import type * as ts from 'typescript'

/* ----------------------------- userland plugin options ----------------------------- */

Expand All @@ -19,6 +20,11 @@ interface TsConfigOptions {
* root path of cwd
*/
buildMode: boolean

/**
* Additional Compiler options to merge with tsconfig
*/
extraTSOptions?: ts.CompilerOptions
}

/**
Expand Down