Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
89 lines (78 loc) · 3.06 KB

File metadata and controls

89 lines (78 loc) · 3.06 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as path from "path";
import * as ts from "typescript";
import { CompilerOptions } from "../CompilerOptions";
import { normalizeSlashes } from "../utils";
import * as cliDiagnostics from "./diagnostics";
import { ParsedCommandLine, updateParsedConfigFile } from "./parse";
export function locateConfigFile(commandLine: ParsedCommandLine): ts.Diagnostic | string | undefined {
const { project } = commandLine.options;
if (!project) {
if (commandLine.fileNames.length > 0) {
return undefined;
}
const searchPath = normalizeSlashes(process.cwd());
return ts.findConfigFile(searchPath, ts.sys.fileExists);
}
if (commandLine.fileNames.length !== 0) {
return cliDiagnostics.optionProjectCannotBeMixedWithSourceFilesOnACommandLine();
}
// TODO: Unlike tsc, this resolves `.` to absolute path
const fileOrDirectory = normalizeSlashes(path.resolve(process.cwd(), project));
if (ts.sys.directoryExists(fileOrDirectory)) {
const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json");
if (ts.sys.fileExists(configFileName)) {
return configFileName;
} else {
return cliDiagnostics.cannotFindATsconfigJsonAtTheSpecifiedDirectory(project);
}
} else if (ts.sys.fileExists(fileOrDirectory)) {
return fileOrDirectory;
} else {
return cliDiagnostics.theSpecifiedPathDoesNotExist(project);
}
}
export function parseConfigFileWithSystem(
configFileName: string,
commandLineOptions?: CompilerOptions,
system = ts.sys
): ParsedCommandLine {
if (!system.fileExists(configFileName)) {
return {
options: {},
fileNames: [configFileName],
errors: [cliDiagnostics.theSpecifiedPathDoesNotExist(configFileName)],
};
}
const parsedConfigFile = ts.parseJsonSourceFileConfigFileContent(
ts.readJsonConfigFile(configFileName, system.readFile),
system,
path.dirname(configFileName),
commandLineOptions,
configFileName
);
return updateParsedConfigFile(parsedConfigFile);
}
export function createConfigFileUpdater(
optionsToExtend: CompilerOptions
): (options: ts.CompilerOptions) => ts.Diagnostic[] {
const configFileMap = new WeakMap<ts.TsConfigSourceFile, ts.ParsedCommandLine>();
return options => {
const { configFile, configFilePath } = options;
if (!configFile || !configFilePath) return [];
if (!configFileMap.has(configFile)) {
const parsedConfigFile = updateParsedConfigFile(
ts.parseJsonSourceFileConfigFileContent(
configFile,
ts.sys,
path.dirname(configFilePath),
optionsToExtend,
configFilePath
)
);
configFileMap.set(configFile, parsedConfigFile);
}
const parsedConfigFile = configFileMap.get(configFile)!;
Object.assign(options, parsedConfigFile.options);
return parsedConfigFile.errors;
};
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.