Skip to content

Commit

Permalink
fix(vue-tsc): sync up runTsc (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Jul 5, 2024
1 parent 78fc007 commit 52423b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-keys-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-checker': patch
---

sync runTsc https://github.com/volarjs/volar.js/blob/630f31118d3986c00cc730eb83cd896709fd547e/packages/typescript/lib/quickstart/runTsc.ts
28 changes: 22 additions & 6 deletions packages/vite-plugin-checker/src/checkers/vueTsc/prepareVueTsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const vueTscDir = dirname(_require.resolve('vue-tsc/package.json'))
const proxyApiPath = _require.resolve('@volar/typescript/lib/node/proxyCreateProgram', {
paths: [vueTscDir],
})
const runExtensions = ['.vue']
const extraSupportedExtensions = ['.vue']

export async function prepareVueTsc() {
// 1. copy typescript to folder
Expand Down Expand Up @@ -61,12 +61,28 @@ export async function prepareVueTsc() {
async function overrideTscJs(tscJsPath: string) {
const languagePluginsFile = path.resolve(_dirname, 'languagePlugins.cjs')
let tsc = await readFile(tscJsPath, 'utf8')
// #region copied from https://github.com/volarjs/volar.js/blob/ae7f2e01caa08f64cbc687c80841dab2a0f7c426/packages/typescript/lib/quickstart/runTsc.ts
// #region copied from https://github.com/volarjs/volar.js/blob/630f31118d3986c00cc730eb83cd896709fd547e/packages/typescript/lib/quickstart/runTsc.ts
// add *.vue files to allow extensions
const extsText = runExtensions.map((ext) => `"${ext}"`).join(', ')
tsc = replace(tsc, /supportedTSExtensions = .*(?=;)/, (s) => `${s}.concat([[${extsText}]])`)
tsc = replace(tsc, /supportedJSExtensions = .*(?=;)/, (s) => `${s}.concat([[${extsText}]])`)
tsc = replace(tsc, /allSupportedExtensions = .*(?=;)/, (s) => `${s}.concat([[${extsText}]])`)
const extsText = extraSupportedExtensions.map((ext) => `"${ext}"`).join(', ')
// tsc = replace(tsc, /supportedTSExtensions = .*(?=;)/, (s) => `${s}.concat([[${extsText}]])`)
tsc = replace(
tsc,
/supportedTSExtensions = .*(?=;)/,
// biome-ignore lint/style/useTemplate: <explanation>
(s) => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`
)
tsc = replace(
tsc,
/supportedJSExtensions = .*(?=;)/,
// biome-ignore lint/style/useTemplate: <explanation>
(s) => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`
)
tsc = replace(
tsc,
/allSupportedExtensions = .*(?=;)/,
// biome-ignore lint/style/useTemplate: <explanation>
(s) => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`
)

// proxy createProgram
tsc = replace(
Expand Down

0 comments on commit 52423b2

Please sign in to comment.