Skip to content

Commit ebf8996

Browse files
committed
fix: support vue-tsc works with ts5
1 parent 20b7399 commit ebf8996

File tree

46 files changed

+973
-782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+973
-782
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dependencies": {
55
"@vueuse/core": "^8.9.4",
66
"body-scroll-lock": "4.0.0-beta.0",
7-
"vitepress": "^1.0.0-alpha.36",
7+
"vitepress": "^1.0.0-alpha.73",
88
"vue": "^3.2.37"
99
}
1010
}

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
]
4040
},
4141
"devDependencies": {
42-
"@tsconfig/node16-strictest-esm": "^1.0.3",
42+
"@tsconfig/esm": "^1.0.2",
43+
"@tsconfig/node18": "^1.0.1",
44+
"@tsconfig/strictest": "^2.0.0",
4345
"@types/babel__code-frame": "^7.0.2",
4446
"@types/debug": "^4.1.5",
4547
"@types/fs-extra": "^11.0.1",
@@ -50,8 +52,8 @@
5052
"@types/rimraf": "^3.0.0",
5153
"@types/semver": "^7.3.6",
5254
"@types/ws": "^8.5.3",
53-
"@typescript-eslint/eslint-plugin": "^5.16.0",
54-
"@typescript-eslint/parser": "^5.16.0",
55+
"@typescript-eslint/eslint-plugin": "^5.59.0",
56+
"@typescript-eslint/parser": "^5.59.0",
5557
"chalk": "^4.1.1",
5658
"conventional-changelog-cli": "^2.1.1",
5759
"cross-env": "^7.0.3",
@@ -73,14 +75,14 @@
7375
"prompts": "^2.4.1",
7476
"publint": "^0.1.9",
7577
"rimraf": "^3.0.2",
76-
"semver": "^7.3.5",
78+
"semver": "^7.5.0",
7779
"simple-git-hooks": "^2.8.0",
7880
"sort-deep-object-arrays": "^1.1.2",
7981
"strip-ansi": "^7.0.0",
8082
"svelte": "^3.46.4",
8183
"tiny-invariant": "^1.1.0",
82-
"typescript": "~4.5.5",
83-
"vite": "^4.0.4",
84+
"typescript": "^5.0.4",
85+
"vite": "^4.3.0",
8486
"vite-plugin-checker": "workspace:*",
8587
"vitest": "^0.28.5",
8688
"ws": "^8.5.0",

packages/vite-plugin-checker/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"lodash.debounce": "^4.0.8",
5252
"lodash.pick": "^4.4.0",
5353
"npm-run-path": "^4.0.1",
54+
"semver": "^7.5.0",
5455
"strip-ansi": "^6.0.0",
5556
"tiny-invariant": "^1.1.0",
5657
"vscode-languageclient": "^7.0.0",
@@ -61,13 +62,13 @@
6162
"peerDependencies": {
6263
"eslint": ">=7",
6364
"meow": "^9.0.0",
65+
"optionator": "^0.9.1",
6466
"stylelint": ">=13",
6567
"typescript": "*",
6668
"vite": ">=2.0.0",
6769
"vls": "*",
6870
"vti": "*",
69-
"vue-tsc": "*",
70-
"optionator": "^0.9.1"
71+
"vue-tsc": "*"
7172
},
7273
"peerDependenciesMeta": {
7374
"eslint": {
@@ -96,20 +97,21 @@
9697
}
9798
},
9899
"devDependencies": {
99-
"@types/fs-extra": "^11.0.1",
100100
"@types/eslint": "^7.2.14",
101+
"@types/fs-extra": "^11.0.1",
101102
"@types/lodash.debounce": "^4.0.6",
102103
"@types/lodash.pick": "^4.4.6",
104+
"@types/semver": "^7.3.13",
103105
"@volar/vue-typescript": "^0.33.0",
104106
"esbuild": "^0.14.27",
105107
"meow": "^9.0.0",
106108
"npm-run-all": "^4.1.5",
107109
"optionator": "^0.9.1",
108110
"stylelint": "^14.0.0",
109-
"tsup": "^6.2.2",
110-
"typescript": "~4.5.5",
111+
"tsup": "^6.7.0",
112+
"typescript": "^5.0.4",
111113
"vls": "^0.7.6",
112114
"vti": "^0.1.7",
113-
"vue-tsc": "^1.1.3"
115+
"vue-tsc": "^1.4.3"
114116
}
115117
}

packages/vite-plugin-checker/src/Checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import invariant from 'tiny-invariant'
22
import { isInVitestEntryThread, isMainThread } from './utils.js'
33

4-
import { createScript, Script } from './worker.js'
4+
import { createScript, type Script } from './worker.js'
55

66
import type {
77
CreateDiagnostic,

packages/vite-plugin-checker/src/checkers/typescript/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
toClientPayload,
1616
wrapCheckerSummary,
1717
} from '../../logger.js'
18-
import { ACTION_TYPES, CreateDiagnostic, DiagnosticToRuntime } from '../../types.js'
18+
import { ACTION_TYPES, type CreateDiagnostic, type DiagnosticToRuntime } from '../../types.js'
1919

2020
const __filename = fileURLToPath(import.meta.url)
2121
let createServeAndBuild

packages/vite-plugin-checker/src/checkers/vls/diagnostics.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import {
1515
DidChangeTextDocumentNotification,
1616
DidChangeWatchedFilesNotification,
1717
DidOpenTextDocumentNotification,
18-
InitializeParams,
18+
type InitializeParams,
1919
InitializeRequest,
20-
InitializeResult,
21-
Logger,
22-
ServerCapabilities,
20+
type InitializeResult,
21+
type Logger,
22+
type ServerCapabilities,
2323
StreamMessageReader,
2424
StreamMessageWriter,
2525
} from 'vscode-languageserver/node.js'
@@ -31,10 +31,10 @@ import {
3131
diagnosticToTerminalLog,
3232
normalizeLspDiagnostic,
3333
normalizePublishDiagnosticParams,
34-
NormalizedDiagnostic,
34+
type NormalizedDiagnostic,
3535
} from '../../logger.js'
3636
import type { DeepPartial } from '../../types.js'
37-
import { getInitParams, VlsOptions } from './initParams.js'
37+
import { getInitParams, type VlsOptions } from './initParams.js'
3838

3939
import { FileDiagnosticManager } from '../../FileDiagnosticManager.js'
4040

packages/vite-plugin-checker/src/checkers/vls/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
toClientPayload,
1212
} from '../../logger.js'
1313
import { ACTION_TYPES } from '../../types.js'
14-
import { DiagnosticOptions, diagnostics } from './diagnostics.js'
14+
import { type DiagnosticOptions, diagnostics } from './diagnostics.js'
1515

1616
import type { ConfigEnv } from 'vite'
1717
import type { CreateDiagnostic } from '../../types.js'

packages/vite-plugin-checker/src/checkers/vueTsc/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
toClientPayload,
1717
wrapCheckerSummary,
1818
} from '../../logger.js'
19-
import { ACTION_TYPES, CreateDiagnostic, DiagnosticToRuntime } from '../../types.js'
19+
import { ACTION_TYPES, type CreateDiagnostic, type DiagnosticToRuntime } from '../../types.js'
2020
import { prepareVueTsc } from './prepareVueTsc.js'
2121

2222
const _require = createRequire(import.meta.url)
@@ -39,7 +39,7 @@ const createDiagnostic: CreateDiagnostic<'vueTsc'> = (pluginConfig) => {
3939

4040
const { targetTsDir } = await prepareVueTsc()
4141

42-
const vueTs = _require(path.resolve(targetTsDir, 'lib/tsc.js'))
42+
const vueTs = _require(path.resolve(targetTsDir, 'lib/typescript.js'))
4343

4444
const finalConfig =
4545
pluginConfig.vueTsc === true

packages/vite-plugin-checker/src/checkers/vueTsc/prepareVueTsc.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fsExtra from 'fs-extra'
22
import { createRequire } from 'module'
33
import path, { dirname } from 'path'
44
import { fileURLToPath } from 'url'
5+
import semver from 'semver'
56
import { writeFile, access, readFile, rm } from 'fs/promises'
67

78
const { copy, mkdir } = fsExtra
@@ -29,12 +30,13 @@ export async function prepareVueTsc() {
2930
// 1. copy typescript to folder
3031
const targetTsDir = path.resolve(_dirname, 'typescript-vue-tsc')
3132
const vueTscFlagFile = path.resolve(targetTsDir, 'vue-tsc-resolve-path')
33+
// let currTsVersion: string = ''
34+
const currTsVersion = _require('typescript/package.json').version
3235

3336
let shouldBuildFixture = true
3437
try {
3538
await access(targetTsDir)
3639
const targetTsVersion = _require(path.resolve(targetTsDir, 'package.json')).version
37-
const currTsVersion = _require('typescript/package.json').version
3840
// check fixture versions before re-use
3941
await access(vueTscFlagFile)
4042
const fixtureFlagContent = await readFile(vueTscFlagFile, 'utf8')
@@ -54,39 +56,50 @@ export async function prepareVueTsc() {
5456
await writeFile(vueTscFlagFile, proxyApiPath)
5557

5658
// 2. sync modification of lib/tsc.js with vue-tsc
57-
await overrideTscJs(_require.resolve(path.resolve(targetTsDir, 'lib/tsc.js')))
59+
await overrideTscJs(
60+
_require.resolve(path.resolve(targetTsDir, 'lib/typescript.js')),
61+
currTsVersion
62+
)
5863
}
5964

6065
return { targetTsDir }
6166
}
6267

63-
async function overrideTscJs(tscJsPath: string) {
64-
let result = await readFile(tscJsPath, 'utf8')
68+
async function overrideTscJs(tscJsPath: string, version: string) {
69+
let tsc = await readFile(tscJsPath, 'utf8')
6570
// #region copied from https://github.com/johnsoncodehk/volar/blob/54f7186485d79bc0e9b7ec59ecbc01d681ee5310/vue-language-tools/vue-tsc/bin/vue-tsc.js
66-
const tryReplace = (search: RegExp | string, replace: string | ((v: string) => string)) => {
67-
const before = result
68-
// @ts-ignore
69-
result = result.replace(search, replace)
70-
if (before === result) {
71-
throw 'Search string not found: ' + JSON.stringify(search.toString())
72-
}
73-
}
74-
7571
// add *.vue files to allow extensions
76-
tryReplace(/supportedTSExtensions = .*(?=;)/, (s) => s + '.concat([[".vue"]])')
77-
tryReplace(/supportedJSExtensions = .*(?=;)/, (s) => s + '.concat([[".vue"]])')
78-
tryReplace(/allSupportedExtensions = .*(?=;)/, (s) => s + '.concat([[".vue"]])')
72+
tryReplace(/supportedTSExtensions = .*(?=;)/, (s: string) => s + '.concat([[".vue"]])')
73+
tryReplace(/supportedJSExtensions = .*(?=;)/, (s: string) => s + '.concat([[".vue"]])')
74+
tryReplace(/allSupportedExtensions = .*(?=;)/, (s: string) => s + '.concat([[".vue"]])')
7975

8076
// proxy createProgram apis
8177
tryReplace(
8278
/function createProgram\(.+\) {/,
83-
(s) =>
84-
s + ` return require(${JSON.stringify(proxyApiPath)}).${createProgramFunction}(...arguments);` // tweak for compatibility, will be removed in 0.6.0
79+
(s: string) =>
80+
s + ` return require(${JSON.stringify(proxyApiPath)}).${createProgramFunction}(...arguments);`
8581
)
86-
// #endregion
8782

88-
// change tsc command to module.exports
89-
tryReplace(`ts.executeCommandLine(ts.sys, ts.noop, ts.sys.args);`, `module.exports = ts`)
83+
// patches logic for checking root file extension in build program for incremental builds
84+
if (semver.gt(version, '5.0.0')) {
85+
tryReplace(
86+
`for (const existingRoot of buildInfoVersionMap.roots) {`,
87+
`for (const existingRoot of buildInfoVersionMap.roots
88+
.filter(file => !file.toLowerCase().includes('__vls_'))
89+
.map(file => file.replace(/\.vue\.(j|t)sx?$/i, '.vue'))
90+
) {`
91+
)
92+
}
93+
94+
function tryReplace(search: any, replace: any) {
95+
const before = tsc
96+
tsc = tsc.replace(search, replace)
97+
const after = tsc
98+
if (after === before) {
99+
throw 'Search string not found: ' + JSON.stringify(search.toString())
100+
}
101+
}
102+
// #endregion
90103

91-
await writeFile(tscJsPath, result)
104+
await writeFile(tscJsPath, tsc)
92105
}

packages/vite-plugin-checker/src/codeFrame.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os from 'os'
22
import type ts from 'typescript'
33

4-
import { codeFrameColumns, SourceLocation } from '@babel/code-frame'
4+
import { codeFrameColumns, type SourceLocation } from '@babel/code-frame'
55

66
export function createFrame({
77
source,

packages/vite-plugin-checker/src/logger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import * as _vscodeUri from 'vscode-uri'
1111
const URI = _vscodeUri?.default?.URI ?? _vscodeUri.URI
1212
import { parentPort } from 'worker_threads'
1313

14-
import { codeFrameColumns, SourceLocation } from '@babel/code-frame'
14+
import { codeFrameColumns, type SourceLocation } from '@babel/code-frame'
1515

1616
import { WS_CHECKER_ERROR_EVENT } from './client/index.js'
1717
import {
1818
ACTION_TYPES,
1919
DiagnosticLevel,
20-
DiagnosticToRuntime,
21-
ClientDiagnosticPayload,
20+
type DiagnosticToRuntime,
21+
type ClientDiagnosticPayload,
2222
} from './types.js'
2323
import { isMainThread } from './utils.js'
2424

packages/vite-plugin-checker/src/main.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import {
1313
} from './client/index.js'
1414
import {
1515
ACTION_TYPES,
16-
BuildCheckBinStr,
17-
BuildInCheckerNames,
18-
ClientDiagnosticPayload,
19-
ClientReconnectPayload,
20-
Action,
21-
PluginConfig,
22-
ServeAndBuildChecker,
23-
SharedConfig,
24-
UserPluginConfig,
16+
type BuildCheckBinStr,
17+
type BuildInCheckerNames,
18+
type ClientDiagnosticPayload,
19+
type ClientReconnectPayload,
20+
type Action,
21+
type PluginConfig,
22+
type ServeAndBuildChecker,
23+
type SharedConfig,
24+
type UserPluginConfig,
2525
} from './types.js'
2626

2727
import type { ConfigEnv, Plugin, Logger } from 'vite'

packages/vite-plugin-checker/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
2+
"extends": [
3+
"@tsconfig/strictest/tsconfig",
4+
"@tsconfig/node18/tsconfig",
5+
"@tsconfig/esm/tsconfig"
6+
],
37
"compilerOptions": {
48
"isolatedModules": true,
59
"noUnusedParameters": false,

playground/backend-integration/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"@vitejs/plugin-react": "^2.0.0",
2020
"express": "^4.18.2",
2121
"http-proxy-middleware": "^2.0.6",
22-
"typescript": "~4.5.5",
23-
"vite": "^4.0.4",
22+
"typescript": "^5.0.4",
23+
"vite": "^4.3.0",
2424
"vite-plugin-checker": "workspace:*"
2525
}
2626
}

playground/config-default/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"devDependencies": {
1717
"@types/react": "^17.0.0",
1818
"@types/react-dom": "^17.0.0",
19-
"@typescript-eslint/eslint-plugin": "^5.16.0",
20-
"@typescript-eslint/parser": "^5.30.7",
19+
"@typescript-eslint/eslint-plugin": "^5.59.0",
20+
"@typescript-eslint/parser": "^5.59.0",
2121
"eslint": "^8.11.0",
22-
"typescript": "~4.5.5",
23-
"vite": "^4.0.4",
22+
"typescript": "^5.0.4",
23+
"vite": "^4.3.0",
2424
"vite-plugin-checker": "workspace:*"
2525
}
2626
}

playground/config-enableBuild-false/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"devDependencies": {
1717
"@types/react": "^17.0.0",
1818
"@types/react-dom": "^17.0.0",
19-
"@typescript-eslint/eslint-plugin": "^5.16.0",
20-
"@typescript-eslint/parser": "^5.30.7",
19+
"@typescript-eslint/eslint-plugin": "^5.59.0",
20+
"@typescript-eslint/parser": "^5.59.0",
2121
"eslint": "^8.11.0",
22-
"typescript": "~4.5.5",
23-
"vite": "^4.0.4",
22+
"typescript": "^5.0.4",
23+
"vite": "^4.3.0",
2424
"vite-plugin-checker": "workspace:*"
2525
}
2626
}

playground/config-initialIsOpen-false/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"devDependencies": {
1717
"@types/react": "^17.0.0",
1818
"@types/react-dom": "^17.0.0",
19-
"@typescript-eslint/eslint-plugin": "^5.16.0",
20-
"@typescript-eslint/parser": "^5.30.7",
19+
"@typescript-eslint/eslint-plugin": "^5.59.0",
20+
"@typescript-eslint/parser": "^5.59.0",
2121
"eslint": "^8.11.0",
22-
"typescript": "~4.5.5",
23-
"vite": "^4.0.4",
22+
"typescript": "^5.0.4",
23+
"vite": "^4.3.0",
2424
"vite-plugin-checker": "workspace:*"
2525
}
2626
}

0 commit comments

Comments
 (0)