-
-
Notifications
You must be signed in to change notification settings - Fork 413
/
index.ts
60 lines (53 loc) · 1.46 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
import * as vue from '@vue/language-core';
import * as semver from 'semver';
const windowsPathReg = /\\/g;
export function run(tscPath = getTscPath()) {
let runExtensions = ['.vue'];
const extensionsChangedException = new Error('extensions changed');
const main = () => runTsc(
tscPath,
runExtensions,
(ts, options) => {
const { configFilePath } = options.options;
const vueOptions = typeof configFilePath === 'string'
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
: vue.resolveVueCompilerOptions({});
const allExtensions = vue.getAllExtensions(vueOptions);
if (
runExtensions.length === allExtensions.length
&& runExtensions.every(ext => allExtensions.includes(ext))
) {
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
ts,
options.options,
vueOptions,
id => id
);
return { languagePlugins: [vueLanguagePlugin] };
}
else {
runExtensions = allExtensions;
throw extensionsChangedException;
}
}
);
try {
main();
} catch (err) {
if (err === extensionsChangedException) {
main();
} else {
throw err;
}
}
}
function getTscPath() {
const version = require('typescript/package.json').version as string;
if (semver.gte(version, '5.7.0')) {
return require.resolve('typescript/lib/_tsc');
}
else {
return require.resolve('typescript/lib/tsc');
}
}