-
-
Notifications
You must be signed in to change notification settings - Fork 408
/
index.ts
48 lines (43 loc) · 1.21 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
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
import * as vue from '@vue/language-core';
const windowsPathReg = /\\/g;
export function run(tscPath = require.resolve('typescript/lib/tsc')) {
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;
}
}
}