-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compatibility with vue-tsc 2.x (#327)
* fix: compatibility with vue-tsc 2.x * Create funny-maps-give.md * Update funny-maps-give.md * fix: correctly load typescript plugin * Update tsup.config.ts * fix: vscode-uri import * ci: bump nodejs version * fix: bypass typescript regex validation * chore: fix build * refactor: move languageplugins to ts * Update tsconfig.json * Update languagePlugins.cts * Update languagePlugins.cts * Update tsup.config.ts * Update tsup.config.ts * Update tsup.config.ts * Update tsup.config.ts * Update packages/vite-plugin-checker/src/checkers/vueTsc/languagePlugins.cts Co-authored-by: Johnson Chu <[email protected]> * chore: organize code * refactor: use path.dirname * test: update test * test: update unit test snapshot * chore: add `@vue/language-core` to devDeps * refactor: use js again * fix: add allowJs * fix: types * should use cjs * docs: fix build * fix: build and update snapshot * ci: Windows serializer * chore: bump vitest * chore: should be minor change * try remove * replace all --------- Co-authored-by: Johnson Chu <[email protected]> Co-authored-by: fi3ework <[email protected]>
- Loading branch information
1 parent
0a2a2e0
commit 0747729
Showing
50 changed files
with
8,518 additions
and
6,648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vite-plugin-checker": minor | ||
--- | ||
|
||
fix: compatibility with vue-tsc 2.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,6 @@ | |
"@vitejs/plugin-vue": "^2.0.1", | ||
"vite": "^4.3.0", | ||
"vue": "^3.3.4", | ||
"vue-tsc": "^1.6.1" | ||
"vue-tsc": "^2.0.14" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/vite-plugin-checker/src/checkers/vueTsc/languagePlugins.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('path') | ||
const { removeEmitGlobalTypes } = require('vue-tsc') | ||
|
||
const vueTscDir = path.dirname(require.resolve('vue-tsc/package.json')) | ||
const vue = /** @type {typeof import('@vue/language-core')} */ ( | ||
require(require.resolve('@vue/language-core', { paths: [vueTscDir] })) | ||
) | ||
const windowsPathReg = /\\/g | ||
|
||
// #region copied from https://github.com/vuejs/language-tools/blob/0781998a29f176ad52c30d3139d5c78a5688bd5d/packages/tsc/index.ts | ||
/** | ||
* @param {typeof import('typescript')} ts | ||
* @param {import('typescript').CreateProgramOptions} options | ||
*/ | ||
exports.getLanguagePlugins = (ts, options) => { | ||
const { configFilePath } = options.options | ||
const vueOptions = | ||
typeof configFilePath === 'string' | ||
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')) | ||
.vueOptions | ||
: vue.resolveVueCompilerOptions({}) | ||
const host = /** @type {import('typescript').CompilerHost} */ (options.host) | ||
const writeFile = host.writeFile.bind(host) | ||
host.writeFile = (fileName, contents, ...args) => { | ||
return writeFile(fileName, removeEmitGlobalTypes(contents), ...args) | ||
} | ||
const vueLanguagePlugin = vue.createVueLanguagePlugin( | ||
ts, | ||
(id) => id, | ||
() => '', | ||
(fileName) => { | ||
const fileMap = new vue.FileMap(host?.useCaseSensitiveFileNames?.() ?? false) | ||
for (const vueFileName of options.rootNames.map((rootName) => | ||
rootName.replace(windowsPathReg, '/') | ||
)) { | ||
fileMap.set(vueFileName, undefined) | ||
} | ||
return fileMap.has(fileName) | ||
}, | ||
options.options, | ||
vueOptions | ||
) | ||
return [vueLanguagePlugin] | ||
} | ||
// #endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.