Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Contributor

Choose a reason for hiding this comment

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

createProgram takes an object anyways, so this can change to

(options: CreateProgramOptions) => {
  return createProgram({
    ...options,
    options: {
      ...options.options,
      ...additionalTypescriptOptions
    }
  })
}

But aside from that, disabling the linter wholesale with no comment isn't the way to go. It provides absolutely no indication to anyone reading why it's happening. Disabling the specific rule with a comment clarifying why (we con't care about the args / we are not in control of the args) goes a long way.

(
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
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Are docs changed needed here @EliLichtblau?

Copy link
Author

Choose a reason for hiding this comment

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

I can change the docs if wanted - I thought the comment would be clear in intellisense - I think the mistake here is I didn't make "extraTSOptions" optional which was an oversight

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be added to the docs here I think.

Copy link
Author

Choose a reason for hiding this comment

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

thanks! will do now

Copy link
Contributor

Choose a reason for hiding this comment

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

Added in ee392c7

}

/**
Expand Down