Skip to content

Commit

Permalink
Maintain support for deprecated API typingOptions.enableAutoDiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jramsay committed Nov 22, 2016
1 parent 5a9451a commit 8a52f05
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
22 changes: 21 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -501,6 +508,15 @@ namespace ts {

let optionNameMapCache: OptionNameMap;

/* @internal */
export function replaceEnableAutoDiscoveryWithEnable(typeAcquisition: TypeAcquisition): void {
// Convert deprecated typingOptions.enableAutoDiscovery to typeAcquisition.enable
if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) {
typeAcquisition.enable = typeAcquisition.enableAutoDiscovery;
delete typeAcquisition.enableAutoDiscovery;
}
}

/* @internal */
export function getOptionNameMap(): OptionNameMap {
if (optionNameMapCache) {
Expand Down Expand Up @@ -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, {}];
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3199,6 +3199,10 @@ namespace ts {
}

export interface TypeAcquisition {
/* @deprecated typingOptions.enableAutoDiscovery
* Use typeAcquisition.enable instead.
*/
enableAutoDiscovery?: boolean;
enable?: boolean;
include?: string[];
exclude?: string[];
Expand Down
41 changes: 32 additions & 9 deletions src/harness/unittests/convertTypeAcquisitionFromJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand All @@ -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":
Expand All @@ -103,7 +126,7 @@ namespace ts {
});

// jsconfig.json
it("Convert jsconfig.json to typing-options ", () => {
it("Convert jsconfig.json to typeAcquisition ", () => {
assertTypeAcquisition(
{
"typeAcquisition":
Expand All @@ -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:
Expand All @@ -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":
Expand Down Expand Up @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,12 @@ namespace ts.server {

private handlers = createMap<(request: protocol.Request) => { response?: any, responseRequired?: boolean }>({
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
// Convert deprecated typingOptions to 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);
Expand Down

0 comments on commit 8a52f05

Please sign in to comment.