Skip to content

Commit

Permalink
fix(vue-tsc): updated createVueLanguagePlugin syntax, version pin (#398)
Browse files Browse the repository at this point in the history
* fix(vue-tsc): compatibility with new createVueLanguagePlugin syntax, version pin

* fix: TS issues

* fix: TS issues

* chore: pin language core

* chore: upgrade to vue-tsc 2.1.6

---------

Co-authored-by: drodichkin <drodichkin@azbukavkusa.ru>
  • Loading branch information
daniluk4000 and drodichkin committed Sep 5, 2024
1 parent b2c3236 commit 5f5b92a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"@vitejs/plugin-vue": "^5.0.5",
"vite": "^5.3.2",
"vue": "^3.3.4",
"vue-tsc": "^2.0.14"
"vue-tsc": "~2.1.6"
}
}
6 changes: 3 additions & 3 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@biomejs/biome": "^1.8.3",
"@types/eslint": "^7.2.14",
"@types/fs-extra": "^11.0.1",
"@vue/language-core": "^2.0.14",
"@vue/language-core": "~2.1.6",
"esbuild": "^0.14.27",
"meow": "^9.0.0",
"npm-run-all2": "^5.0.0",
Expand All @@ -64,7 +64,7 @@
"typescript": "^5.5.3",
"vls": "^0.8.5",
"vti": "^0.1.11",
"vue-tsc": "^2.0.14"
"vue-tsc": "~2.1.6"
},
"peerDependencies": {
"@biomejs/biome": ">=1.7",
Expand All @@ -76,7 +76,7 @@
"vite": ">=2.0.0",
"vls": "*",
"vti": "*",
"vue-tsc": ">=2.0.0"
"vue-tsc": "~2.1.6"
},
"peerDependenciesMeta": {
"@biomejs/biome": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
const path = require('node: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

const removeEmitGlobalTypesRegexp = /^[^\n]*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd[^\n]*\n?$/mg;

/**
* @param dts {string}
* @returns {string}
*/
function removeEmitGlobalTypes(dts) {
return dts.replace(removeEmitGlobalTypesRegexp, '');
}

// #region copied from https://github.com/vuejs/language-tools/blob/0781998a29f176ad52c30d3139d5c78a5688bd5d/packages/tsc/index.ts
/**
* @param {typeof import('typescript')} ts
Expand All @@ -29,21 +38,9 @@ exports.getLanguagePlugins = (ts, options) => {
}
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,
(id) => id,
)
return [vueLanguagePlugin]
}
Expand Down
6 changes: 3 additions & 3 deletions playground/vue-tsc-vue3/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"private": true,
"name": "@playground/vue-tsc-vue3",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"dev": "vite",
"serve": "vite preview"
},
"dependencies": {
Expand All @@ -16,6 +16,6 @@
"typescript": "^5.5.3",
"vite": "^5.3.2",
"vite-plugin-checker": "workspace:*",
"vue-tsc": "^2.0.14"
"vue-tsc": "~2.1.6"
}
}
91 changes: 51 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f5b92a

Please sign in to comment.