|
| 1 | +import * as core from '@vue/language-core'; |
| 2 | +import { posix as path } from 'path-browserify'; |
1 | 3 | import * as ts from 'typescript'; |
2 | | -import { createCheckerBase, createCheckerByJsonConfigBase } from './lib/base'; |
| 4 | +import { createCheckerBase } from './lib/checker'; |
3 | 5 | import type { MetaCheckerOptions } from './lib/types'; |
4 | 6 |
|
5 | 7 | export * from './lib/types'; |
6 | 8 |
|
7 | 9 | export function createCheckerByJson( |
8 | | - rootPath: string, |
| 10 | + rootDir: string, |
9 | 11 | json: any, |
10 | 12 | checkerOptions: MetaCheckerOptions = {}, |
11 | 13 | ) { |
12 | | - return createCheckerByJsonConfigBase( |
| 14 | + rootDir = rootDir.replace(/\\/g, '/'); |
| 15 | + return createCheckerBase( |
13 | 16 | ts, |
14 | | - rootPath, |
15 | | - json, |
| 17 | + () => { |
| 18 | + const commandLine = core.createParsedCommandLineByJson(ts, ts.sys, rootDir, json); |
| 19 | + const { fileNames } = ts.parseJsonConfigFileContent( |
| 20 | + json, |
| 21 | + ts.sys, |
| 22 | + rootDir, |
| 23 | + {}, |
| 24 | + undefined, |
| 25 | + undefined, |
| 26 | + core.getAllExtensions(commandLine.vueOptions) |
| 27 | + .map(extension => ({ |
| 28 | + extension: extension.slice(1), |
| 29 | + isMixedContent: true, |
| 30 | + scriptKind: ts.ScriptKind.Deferred, |
| 31 | + })), |
| 32 | + ); |
| 33 | + return [commandLine, fileNames]; |
| 34 | + }, |
16 | 35 | checkerOptions, |
| 36 | + rootDir, |
17 | 37 | ); |
18 | 38 | } |
19 | 39 |
|
20 | 40 | export function createChecker( |
21 | 41 | tsconfig: string, |
22 | 42 | checkerOptions: MetaCheckerOptions = {}, |
23 | 43 | ) { |
| 44 | + tsconfig = tsconfig.replace(/\\/g, '/'); |
24 | 45 | return createCheckerBase( |
25 | 46 | ts, |
26 | | - tsconfig, |
| 47 | + () => { |
| 48 | + const commandLine = core.createParsedCommandLine(ts, ts.sys, tsconfig); |
| 49 | + const { fileNames } = ts.parseJsonSourceFileConfigFileContent( |
| 50 | + ts.readJsonConfigFile(tsconfig, ts.sys.readFile), |
| 51 | + ts.sys, |
| 52 | + path.dirname(tsconfig), |
| 53 | + {}, |
| 54 | + tsconfig, |
| 55 | + undefined, |
| 56 | + core.getAllExtensions(commandLine.vueOptions) |
| 57 | + .map(extension => ({ |
| 58 | + extension: extension.slice(1), |
| 59 | + isMixedContent: true, |
| 60 | + scriptKind: ts.ScriptKind.Deferred, |
| 61 | + })), |
| 62 | + ); |
| 63 | + return [commandLine, fileNames]; |
| 64 | + }, |
27 | 65 | checkerOptions, |
| 66 | + path.dirname(tsconfig), |
28 | 67 | ); |
29 | 68 | } |
0 commit comments