Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/tsconfigUtils.ts
4770 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { dirname } from 'path';
6
import ts from 'typescript';
7
8
/**
9
* Get the target (e.g. 'ES2024') from a tsconfig.json file.
10
*/
11
export function getTargetStringFromTsConfig(configFilePath: string): string {
12
const parsed = ts.readConfigFile(configFilePath, ts.sys.readFile);
13
if (parsed.error) {
14
throw new Error(`Cannot determine target from ${configFilePath}. TS error: ${parsed.error.messageText}`);
15
}
16
17
const cmdLine = ts.parseJsonConfigFileContent(parsed.config, ts.sys, dirname(configFilePath), {});
18
const resolved = typeof cmdLine.options.target !== 'undefined' ? ts.ScriptTarget[cmdLine.options.target] : undefined;
19
if (!resolved) {
20
throw new Error(`Could not resolve target in ${configFilePath}`);
21
}
22
return resolved;
23
}
24
25
26