Maintain support for deprecated API typingOptions.enableAutoDiscovery
This commit is contained in:
parent
5a9451ae23
commit
70e130b08c
|
@ -463,6 +463,13 @@ namespace ts {
|
|||
|
||||
/* @internal */
|
||||
export let typeAcquisitionDeclarations: CommandLineOption[] = [
|
||||
{
|
||||
/* @deprecated typingOptions.enableAutoDiscovery
|
||||
* Use typeAcquisition.enable instead.
|
||||
*/
|
||||
name: "enableAutoDiscovery",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
name: "enable",
|
||||
type: "boolean",
|
||||
|
@ -501,6 +508,15 @@ namespace ts {
|
|||
|
||||
let optionNameMapCache: OptionNameMap;
|
||||
|
||||
/* @internal */
|
||||
export function replaceEnableAutoDiscoveryWithEnable(typeAcquisition: TypeAcquisition): void {
|
||||
// Replace deprecated typingOptions.enableAutoDiscovery with typeAcquisition.enable
|
||||
if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) {
|
||||
typeAcquisition.enable = typeAcquisition.enableAutoDiscovery;
|
||||
delete typeAcquisition.enableAutoDiscovery;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function getOptionNameMap(): OptionNameMap {
|
||||
if (optionNameMapCache) {
|
||||
|
@ -843,7 +859,9 @@ namespace ts {
|
|||
}
|
||||
|
||||
let options: CompilerOptions = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName);
|
||||
const typeAcquisition: TypeAcquisition = convertTypeAcquisitionFromJsonWorker(json["typeAcquisition"], basePath, errors, configFileName);
|
||||
// typingOptions has been deprecated. Use typeAcquisition instead.
|
||||
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
|
||||
const typeAcquisition: TypeAcquisition = convertTypeAcquisitionFromJsonWorker(jsonOptions, basePath, errors, configFileName);
|
||||
|
||||
if (json["extends"]) {
|
||||
let [include, exclude, files, baseOptions]: [string[], string[], string[], CompilerOptions] = [undefined, undefined, undefined, {}];
|
||||
|
@ -1016,7 +1034,9 @@ namespace ts {
|
|||
basePath: string, errors: Diagnostic[], configFileName?: string): TypeAcquisition {
|
||||
|
||||
const options: TypeAcquisition = { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
|
||||
replaceEnableAutoDiscoveryWithEnable(jsonOptions);
|
||||
convertOptionsFromJson(typeAcquisitionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_type_acquisition_option_0, errors);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
|
|
@ -3199,6 +3199,10 @@ namespace ts {
|
|||
}
|
||||
|
||||
export interface TypeAcquisition {
|
||||
/* @deprecated typingOptions.enableAutoDiscovery
|
||||
* Use typeAcquisition.enable instead.
|
||||
*/
|
||||
enableAutoDiscovery?: boolean;
|
||||
enable?: boolean;
|
||||
include?: string[];
|
||||
exclude?: string[];
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
namespace ts {
|
||||
describe("convertTypeAcquisitionFromJson", () => {
|
||||
function assertTypeAcquisition(json: any, configFileName: string, expectedResult: { typeAcquisition: TypeAcquisition, errors: Diagnostic[] }) {
|
||||
const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(json["typeAcquisition"], "/apath/", configFileName);
|
||||
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
|
||||
const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(jsonOptions, "/apath/", configFileName);
|
||||
const parsedTypeAcquisition = JSON.stringify(actualTypeAcquisition);
|
||||
const expectedTypeAcquisition = JSON.stringify(expectedResult.typeAcquisition);
|
||||
assert.equal(parsedTypeAcquisition, expectedTypeAcquisition);
|
||||
|
@ -20,7 +21,29 @@ namespace ts {
|
|||
}
|
||||
|
||||
// tsconfig.json
|
||||
it("Convert correctly format tsconfig.json to typing-options ", () => {
|
||||
it("Convert deprecated typingOptions.enableAutoDiscovery format tsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typingOptions":
|
||||
{
|
||||
"enableAutoDiscovery": true,
|
||||
"include": ["0.d.ts", "1.d.ts"],
|
||||
"exclude": ["0.js", "1.js"]
|
||||
}
|
||||
},
|
||||
"tsconfig.json",
|
||||
{
|
||||
typeAcquisition:
|
||||
{
|
||||
enable: true,
|
||||
include: ["0.d.ts", "1.d.ts"],
|
||||
exclude: ["0.js", "1.js"]
|
||||
},
|
||||
errors: <Diagnostic[]>[]
|
||||
});
|
||||
});
|
||||
|
||||
it("Convert correctly format tsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
@ -42,7 +65,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert incorrect format tsconfig.json to typing-options ", () => {
|
||||
it("Convert incorrect format tsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
@ -70,7 +93,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert default tsconfig.json to typing-options ", () => {
|
||||
it("Convert default tsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition({}, "tsconfig.json",
|
||||
{
|
||||
typeAcquisition:
|
||||
|
@ -83,7 +106,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert tsconfig.json with only enable property to typing-options ", () => {
|
||||
it("Convert tsconfig.json with only enable property to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
@ -103,7 +126,7 @@ namespace ts {
|
|||
});
|
||||
|
||||
// jsconfig.json
|
||||
it("Convert jsconfig.json to typing-options ", () => {
|
||||
it("Convert jsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
@ -124,7 +147,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert default jsconfig.json to typing-options ", () => {
|
||||
it("Convert default jsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition({ }, "jsconfig.json",
|
||||
{
|
||||
typeAcquisition:
|
||||
|
@ -137,7 +160,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert incorrect format jsconfig.json to typing-options ", () => {
|
||||
it("Convert incorrect format jsconfig.json to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
@ -165,7 +188,7 @@ namespace ts {
|
|||
});
|
||||
});
|
||||
|
||||
it("Convert jsconfig.json with only enable property to typing-options ", () => {
|
||||
it("Convert jsconfig.json with only enable property to typeAcquisition ", () => {
|
||||
assertTypeAcquisition(
|
||||
{
|
||||
"typeAcquisition":
|
||||
|
|
|
@ -860,6 +860,10 @@ namespace ts.server.protocol {
|
|||
* Compiler options for the project
|
||||
*/
|
||||
options: ExternalProjectCompilerOptions;
|
||||
/**
|
||||
* @deprecated typingOptions. Use typeAcquisition instead
|
||||
*/
|
||||
typingOptions?: TypeAcquisition;
|
||||
/**
|
||||
* Explicitly specified type acquisition for the project
|
||||
*/
|
||||
|
|
|
@ -1365,6 +1365,12 @@ namespace ts.server {
|
|||
|
||||
private handlers = createMap<(request: protocol.Request) => { response?: any, responseRequired?: boolean }>({
|
||||
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
|
||||
// Replace deprecated typingOptions with typeAcquisition
|
||||
if (request.arguments.typingOptions && !request.arguments.typeAcquisition) {
|
||||
replaceEnableAutoDiscoveryWithEnable(request.arguments.typingOptions);
|
||||
request.arguments.typeAcquisition = request.arguments.typingOptions;
|
||||
delete request.arguments.typingOptions;
|
||||
}
|
||||
this.projectService.openExternalProject(request.arguments);
|
||||
// TODO: report errors
|
||||
return this.requiredResponse(true);
|
||||
|
|
Loading…
Reference in a new issue