Skip to content

Commit 19dcb45

Browse files
committed
Maintain support for deprecated API typingOptions.enableAutoDiscovery
1 parent ada48e5 commit 19dcb45

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

src/compiler/commandLineParser.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ namespace ts {
463463

464464
/* @internal */
465465
export let typeAcquisitionDeclarations: CommandLineOption[] = [
466+
{
467+
/* @deprecated typingOptions.enableAutoDiscovery
468+
* Use typeAcquisition.enable instead.
469+
*/
470+
name: "enableAutoDiscovery",
471+
type: "boolean",
472+
},
466473
{
467474
name: "enable",
468475
type: "boolean",
@@ -501,6 +508,15 @@ namespace ts {
501508

502509
let optionNameMapCache: OptionNameMap;
503510

511+
/* @internal */
512+
export function replaceEnableAutoDiscoveryWithEnable(typeAcquisition: TypeAcquisition): void {
513+
// Replace deprecated typingOptions.enableAutoDiscovery with typeAcquisition.enable
514+
if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) {
515+
typeAcquisition.enable = typeAcquisition.enableAutoDiscovery;
516+
delete typeAcquisition.enableAutoDiscovery;
517+
}
518+
}
519+
504520
/* @internal */
505521
export function getOptionNameMap(): OptionNameMap {
506522
if (optionNameMapCache) {
@@ -843,7 +859,9 @@ namespace ts {
843859
}
844860

845861
let options: CompilerOptions = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName);
846-
const typeAcquisition: TypeAcquisition = convertTypeAcquisitionFromJsonWorker(json["typeAcquisition"], basePath, errors, configFileName);
862+
// typingOptions has been deprecated. Use typeAcquisition instead.
863+
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
864+
const typeAcquisition: TypeAcquisition = convertTypeAcquisitionFromJsonWorker(jsonOptions, basePath, errors, configFileName);
847865

848866
if (json["extends"]) {
849867
let [include, exclude, files, baseOptions]: [string[], string[], string[], CompilerOptions] = [undefined, undefined, undefined, {}];
@@ -1016,7 +1034,9 @@ namespace ts {
10161034
basePath: string, errors: Diagnostic[], configFileName?: string): TypeAcquisition {
10171035

10181036
const options: TypeAcquisition = { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
1037+
replaceEnableAutoDiscoveryWithEnable(jsonOptions);
10191038
convertOptionsFromJson(typeAcquisitionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_type_acquisition_option_0, errors);
1039+
10201040
return options;
10211041
}
10221042

src/compiler/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,10 @@ namespace ts {
32063206
}
32073207

32083208
export interface TypeAcquisition {
3209+
/* @deprecated typingOptions.enableAutoDiscovery
3210+
* Use typeAcquisition.enable instead.
3211+
*/
3212+
enableAutoDiscovery?: boolean;
32093213
enable?: boolean;
32103214
include?: string[];
32113215
exclude?: string[];

src/harness/unittests/convertTypeAcquisitionFromJson.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
namespace ts {
55
describe("convertTypeAcquisitionFromJson", () => {
66
function assertTypeAcquisition(json: any, configFileName: string, expectedResult: { typeAcquisition: TypeAcquisition, errors: Diagnostic[] }) {
7-
const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(json["typeAcquisition"], "/apath/", configFileName);
7+
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
8+
const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(jsonOptions, "/apath/", configFileName);
89
const parsedTypeAcquisition = JSON.stringify(actualTypeAcquisition);
910
const expectedTypeAcquisition = JSON.stringify(expectedResult.typeAcquisition);
1011
assert.equal(parsedTypeAcquisition, expectedTypeAcquisition);
@@ -20,7 +21,29 @@ namespace ts {
2021
}
2122

2223
// tsconfig.json
23-
it("Convert correctly format tsconfig.json to typing-options ", () => {
24+
it("Convert deprecated typingOptions.enableAutoDiscovery format tsconfig.json to typeAcquisition ", () => {
25+
assertTypeAcquisition(
26+
{
27+
"typingOptions":
28+
{
29+
"enableAutoDiscovery": true,
30+
"include": ["0.d.ts", "1.d.ts"],
31+
"exclude": ["0.js", "1.js"]
32+
}
33+
},
34+
"tsconfig.json",
35+
{
36+
typeAcquisition:
37+
{
38+
enable: true,
39+
include: ["0.d.ts", "1.d.ts"],
40+
exclude: ["0.js", "1.js"]
41+
},
42+
errors: <Diagnostic[]>[]
43+
});
44+
});
45+
46+
it("Convert correctly format tsconfig.json to typeAcquisition ", () => {
2447
assertTypeAcquisition(
2548
{
2649
"typeAcquisition":
@@ -42,7 +65,7 @@ namespace ts {
4265
});
4366
});
4467

45-
it("Convert incorrect format tsconfig.json to typing-options ", () => {
68+
it("Convert incorrect format tsconfig.json to typeAcquisition ", () => {
4669
assertTypeAcquisition(
4770
{
4871
"typeAcquisition":
@@ -70,7 +93,7 @@ namespace ts {
7093
});
7194
});
7295

73-
it("Convert default tsconfig.json to typing-options ", () => {
96+
it("Convert default tsconfig.json to typeAcquisition ", () => {
7497
assertTypeAcquisition({}, "tsconfig.json",
7598
{
7699
typeAcquisition:
@@ -83,7 +106,7 @@ namespace ts {
83106
});
84107
});
85108

86-
it("Convert tsconfig.json with only enable property to typing-options ", () => {
109+
it("Convert tsconfig.json with only enable property to typeAcquisition ", () => {
87110
assertTypeAcquisition(
88111
{
89112
"typeAcquisition":
@@ -103,7 +126,7 @@ namespace ts {
103126
});
104127

105128
// jsconfig.json
106-
it("Convert jsconfig.json to typing-options ", () => {
129+
it("Convert jsconfig.json to typeAcquisition ", () => {
107130
assertTypeAcquisition(
108131
{
109132
"typeAcquisition":
@@ -124,7 +147,7 @@ namespace ts {
124147
});
125148
});
126149

127-
it("Convert default jsconfig.json to typing-options ", () => {
150+
it("Convert default jsconfig.json to typeAcquisition ", () => {
128151
assertTypeAcquisition({ }, "jsconfig.json",
129152
{
130153
typeAcquisition:
@@ -137,7 +160,7 @@ namespace ts {
137160
});
138161
});
139162

140-
it("Convert incorrect format jsconfig.json to typing-options ", () => {
163+
it("Convert incorrect format jsconfig.json to typeAcquisition ", () => {
141164
assertTypeAcquisition(
142165
{
143166
"typeAcquisition":
@@ -165,7 +188,7 @@ namespace ts {
165188
});
166189
});
167190

168-
it("Convert jsconfig.json with only enable property to typing-options ", () => {
191+
it("Convert jsconfig.json with only enable property to typeAcquisition ", () => {
169192
assertTypeAcquisition(
170193
{
171194
"typeAcquisition":

src/server/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ namespace ts.server.protocol {
860860
* Compiler options for the project
861861
*/
862862
options: ExternalProjectCompilerOptions;
863+
/**
864+
* @deprecated typingOptions. Use typeAcquisition instead
865+
*/
866+
typingOptions?: TypeAcquisition;
863867
/**
864868
* Explicitly specified type acquisition for the project
865869
*/

src/server/session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,12 @@ namespace ts.server {
13651365

13661366
private handlers = createMap<(request: protocol.Request) => { response?: any, responseRequired?: boolean }>({
13671367
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
1368+
// Replace deprecated typingOptions with typeAcquisition
1369+
if (request.arguments.typingOptions && !request.arguments.typeAcquisition) {
1370+
replaceEnableAutoDiscoveryWithEnable(request.arguments.typingOptions);
1371+
request.arguments.typeAcquisition = request.arguments.typingOptions;
1372+
delete request.arguments.typingOptions;
1373+
}
13681374
this.projectService.openExternalProject(request.arguments);
13691375
// TODO: report errors
13701376
return this.requiredResponse(true);

0 commit comments

Comments
 (0)