-
-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (47 loc) · 1.36 KB
/
index.ts
File metadata and controls
51 lines (47 loc) · 1.36 KB
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
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
import * as core from '@vue/language-core';
const windowsPathReg = /\\/g;
export function run(tscPath = require.resolve('typescript/lib/tsc')) {
let runExtensions = ['.vue'];
let extensionsChangedException: Error | undefined;
const main = () =>
runTsc(
tscPath,
runExtensions,
(ts, options) => {
const { configFilePath } = options.options;
const vueOptions = typeof configFilePath === 'string'
? core.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
: core.createParsedCommandLineByJson(ts, ts.sys, (options.host ?? ts.sys).getCurrentDirectory(), {})
.vueOptions;
const allExtensions = core.getAllExtensions(vueOptions);
if (
runExtensions.length === allExtensions.length
&& runExtensions.every(ext => allExtensions.includes(ext))
) {
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
ts,
options.options,
vueOptions,
id => id,
);
return { languagePlugins: [vueLanguagePlugin] };
}
else {
runExtensions = allExtensions;
throw extensionsChangedException = new Error('extensions changed');
}
},
);
try {
return main();
}
catch (err) {
if (err === extensionsChangedException) {
return main();
}
else {
throw err;
}
}
}