diff --git a/Jakefile.js b/Jakefile.js index 087bbb675117c..dcdebdf8ea586 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -256,7 +256,7 @@ var harnessSources = harnessCoreSources.concat([ "commandLineParsing.ts", "configurationExtension.ts", "convertCompilerOptionsFromJson.ts", - "convertTypingOptionsFromJson.ts", + "convertTypeAcquisitionFromJson.ts", "tsserverProjectSystem.ts", "compileOnSave.ts", "typingsInstaller.ts", diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 26877de43c4da..414e1f117f52e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -462,11 +462,18 @@ namespace ts { ]; /* @internal */ - export let typingOptionDeclarations: CommandLineOption[] = [ + export let typeAcquisitionDeclarations: CommandLineOption[] = [ { + /* @deprecated typingOptions.enableAutoDiscovery + * Use typeAcquisition.enable instead. + */ name: "enableAutoDiscovery", type: "boolean", }, + { + name: "enable", + type: "boolean", + }, { name: "include", type: "list", @@ -501,6 +508,20 @@ namespace ts { let optionNameMapCache: OptionNameMap; + /* @internal */ + export function convertEnableAutoDiscoveryToEnable(typeAcquisition: TypeAcquisition): TypeAcquisition { + // Convert deprecated typingOptions.enableAutoDiscovery to typeAcquisition.enable + if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) { + const result: TypeAcquisition = { + enable: typeAcquisition.enableAutoDiscovery, + include: typeAcquisition.include || [], + exclude: typeAcquisition.exclude || [] + }; + return result; + } + return typeAcquisition; + } + /* @internal */ export function getOptionNameMap(): OptionNameMap { if (optionNameMapCache) { @@ -835,7 +856,7 @@ namespace ts { return { options: {}, fileNames: [], - typingOptions: {}, + typeAcquisition: {}, raw: json, errors: [createCompilerDiagnostic(Diagnostics.Circularity_detected_while_resolving_configuration_Colon_0, [...resolutionStack, resolvedPath].join(" -> "))], wildcardDirectories: {} @@ -843,7 +864,10 @@ namespace ts { } let options: CompilerOptions = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName); - const typingOptions: TypingOptions = convertTypingOptionsFromJsonWorker(json["typingOptions"], basePath, errors, configFileName); + // typingOptions has been deprecated and is only supported for backward compatibility purposes. + // It should be removed in future releases - 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, {}]; @@ -874,7 +898,7 @@ namespace ts { return { options, fileNames, - typingOptions, + typeAcquisition, raw: json, errors, wildcardDirectories, @@ -996,9 +1020,9 @@ namespace ts { return { options, errors }; } - export function convertTypingOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: TypingOptions, errors: Diagnostic[] } { + export function convertTypeAcquisitionFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: TypeAcquisition, errors: Diagnostic[] } { const errors: Diagnostic[] = []; - const options = convertTypingOptionsFromJsonWorker(jsonOptions, basePath, errors, configFileName); + const options = convertTypeAcquisitionFromJsonWorker(jsonOptions, basePath, errors, configFileName); return { options, errors }; } @@ -1012,16 +1036,18 @@ namespace ts { return options; } - function convertTypingOptionsFromJsonWorker(jsonOptions: any, - basePath: string, errors: Diagnostic[], configFileName?: string): TypingOptions { + function convertTypeAcquisitionFromJsonWorker(jsonOptions: any, + basePath: string, errors: Diagnostic[], configFileName?: string): TypeAcquisition { + + const options: TypeAcquisition = { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] }; + const typeAcquisition = convertEnableAutoDiscoveryToEnable(jsonOptions); + convertOptionsFromJson(typeAcquisitionDeclarations, typeAcquisition, basePath, options, Diagnostics.Unknown_type_acquisition_option_0, errors); - const options: TypingOptions = { enableAutoDiscovery: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] }; - convertOptionsFromJson(typingOptionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_typing_option_0, errors); return options; } function convertOptionsFromJson(optionDeclarations: CommandLineOption[], jsonOptions: any, basePath: string, - defaultOptions: CompilerOptions | TypingOptions, diagnosticMessage: DiagnosticMessage, errors: Diagnostic[]) { + defaultOptions: CompilerOptions | TypeAcquisition, diagnosticMessage: DiagnosticMessage, errors: Diagnostic[]) { if (!jsonOptions) { return; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7f12558cee519..b823b1ed6b36b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3137,7 +3137,7 @@ "category": "Error", "code": 17009 }, - "Unknown typing option '{0}'.": { + "Unknown type acquisition option '{0}'.": { "category": "Error", "code": 17010 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2b8b6fe294e55..9c45dd111078f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3198,8 +3198,12 @@ namespace ts { [option: string]: CompilerOptionsValue | undefined; } - export interface TypingOptions { + export interface TypeAcquisition { + /* @deprecated typingOptions.enableAutoDiscovery + * Use typeAcquisition.enable instead. + */ enableAutoDiscovery?: boolean; + enable?: boolean; include?: string[]; exclude?: string[]; [option: string]: string[] | boolean | undefined; @@ -3210,7 +3214,7 @@ namespace ts { projectRootPath: string; // The path to the project root directory safeListPath: string; // The path used to retrieve the safe list packageNameToTypingLocation: Map; // The map of package names to their cached typing locations - typingOptions: TypingOptions; // Used to customize the typing inference process + typeAcquisition: TypeAcquisition; // Used to customize the type acquisition process compilerOptions: CompilerOptions; // Used as a source for typing inference unresolvedImports: ReadonlyArray; // List of unresolved module ids from imports } @@ -3275,7 +3279,7 @@ namespace ts { /** Either a parsed command line or a parsed tsconfig.json */ export interface ParsedCommandLine { options: CompilerOptions; - typingOptions?: TypingOptions; + typeAcquisition?: TypeAcquisition; fileNames: string[]; raw?: any; errors: Diagnostic[]; diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index d3a814f26caf0..f4057057e4efd 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -108,7 +108,7 @@ "./unittests/commandLineParsing.ts", "./unittests/configurationExtension.ts", "./unittests/convertCompilerOptionsFromJson.ts", - "./unittests/convertTypingOptionsFromJson.ts", + "./unittests/convertTypeAcquisitionFromJson.ts", "./unittests/tsserverProjectSystem.ts", "./unittests/matchFiles.ts", "./unittests/initializeTSConfig.ts", diff --git a/src/harness/unittests/convertTypingOptionsFromJson.ts b/src/harness/unittests/convertTypeAcquisitionFromJson.ts similarity index 53% rename from src/harness/unittests/convertTypingOptionsFromJson.ts rename to src/harness/unittests/convertTypeAcquisitionFromJson.ts index 439409b24b707..4c21b7ca2b99d 100644 --- a/src/harness/unittests/convertTypingOptionsFromJson.ts +++ b/src/harness/unittests/convertTypeAcquisitionFromJson.ts @@ -2,12 +2,13 @@ /// namespace ts { - describe("convertTypingOptionsFromJson", () => { - function assertTypingOptions(json: any, configFileName: string, expectedResult: { typingOptions: TypingOptions, errors: Diagnostic[] }) { - const { options: actualTypingOptions, errors: actualErrors } = convertTypingOptionsFromJson(json["typingOptions"], "/apath/", configFileName); - const parsedTypingOptions = JSON.stringify(actualTypingOptions); - const expectedTypingOptions = JSON.stringify(expectedResult.typingOptions); - assert.equal(parsedTypingOptions, expectedTypingOptions); + describe("convertTypeAcquisitionFromJson", () => { + function assertTypeAcquisition(json: any, configFileName: string, expectedResult: { typeAcquisition: TypeAcquisition, errors: Diagnostic[] }) { + 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); const expectedErrors = expectedResult.errors; assert.isTrue(expectedResult.errors.length === actualErrors.length, `Expected error: ${JSON.stringify(expectedResult.errors)}. Actual error: ${JSON.stringify(actualErrors)}.`); @@ -20,8 +21,8 @@ namespace ts { } // tsconfig.json - it("Convert correctly format tsconfig.json to typing-options ", () => { - assertTypingOptions( + it("Convert deprecated typingOptions.enableAutoDiscovery format tsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition( { "typingOptions": { @@ -32,9 +33,9 @@ namespace ts { }, "tsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: true, + enable: true, include: ["0.d.ts", "1.d.ts"], exclude: ["0.js", "1.js"] }, @@ -42,25 +43,47 @@ namespace ts { }); }); - it("Convert incorrect format tsconfig.json to typing-options ", () => { - assertTypingOptions( + it("Convert correctly format tsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition( { - "typingOptions": + "typeAcquisition": + { + "enable": 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: [] + }); + }); + + it("Convert incorrect format tsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition( + { + "typeAcquisition": { "enableAutoDiscovy": true, } }, "tsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: false, + enable: false, include: [], exclude: [] }, errors: [ { - category: Diagnostics.Unknown_typing_option_0.category, - code: Diagnostics.Unknown_typing_option_0.code, + category: Diagnostics.Unknown_type_acquisition_option_0.category, + code: Diagnostics.Unknown_type_acquisition_option_0.code, file: undefined, start: 0, length: 0, @@ -70,12 +93,12 @@ namespace ts { }); }); - it("Convert default tsconfig.json to typing-options ", () => { - assertTypingOptions({}, "tsconfig.json", + it("Convert default tsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition({}, "tsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: false, + enable: false, include: [], exclude: [] }, @@ -83,18 +106,18 @@ namespace ts { }); }); - it("Convert tsconfig.json with only enableAutoDiscovery property to typing-options ", () => { - assertTypingOptions( + it("Convert tsconfig.json with only enable property to typeAcquisition ", () => { + assertTypeAcquisition( { - "typingOptions": + "typeAcquisition": { - "enableAutoDiscovery": true + "enable": true } }, "tsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: true, + enable: true, include: [], exclude: [] }, @@ -103,20 +126,20 @@ namespace ts { }); // jsconfig.json - it("Convert jsconfig.json to typing-options ", () => { - assertTypingOptions( + it("Convert jsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition( { - "typingOptions": + "typeAcquisition": { - "enableAutoDiscovery": false, + "enable": false, "include": ["0.d.ts"], "exclude": ["0.js"] } }, "jsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: false, + enable: false, include: ["0.d.ts"], exclude: ["0.js"] }, @@ -124,12 +147,12 @@ namespace ts { }); }); - it("Convert default jsconfig.json to typing-options ", () => { - assertTypingOptions({ }, "jsconfig.json", + it("Convert default jsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition({ }, "jsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: true, + enable: true, include: [], exclude: [] }, @@ -137,25 +160,25 @@ namespace ts { }); }); - it("Convert incorrect format jsconfig.json to typing-options ", () => { - assertTypingOptions( + it("Convert incorrect format jsconfig.json to typeAcquisition ", () => { + assertTypeAcquisition( { - "typingOptions": + "typeAcquisition": { "enableAutoDiscovy": true, } }, "jsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: true, + enable: true, include: [], exclude: [] }, errors: [ { category: Diagnostics.Unknown_compiler_option_0.category, - code: Diagnostics.Unknown_typing_option_0.code, + code: Diagnostics.Unknown_type_acquisition_option_0.code, file: undefined, start: 0, length: 0, @@ -165,18 +188,18 @@ namespace ts { }); }); - it("Convert jsconfig.json with only enableAutoDiscovery property to typing-options ", () => { - assertTypingOptions( + it("Convert jsconfig.json with only enable property to typeAcquisition ", () => { + assertTypeAcquisition( { - "typingOptions": + "typeAcquisition": { - "enableAutoDiscovery": false + "enable": false } }, "jsconfig.json", { - typingOptions: + typeAcquisition: { - enableAutoDiscovery: false, + enable: false, include: [], exclude: [] }, diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e9b6ccb788401..7aed5f81908e9 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -90,8 +90,8 @@ namespace ts.projectSystem { this.projectService.updateTypingsForProject(response); } - enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions, unresolvedImports: server.SortedReadonlyArray) { - const request = server.createInstallTypingsRequest(project, typingOptions, unresolvedImports, this.globalTypingsCacheLocation); + enqueueInstallTypingsRequest(project: server.Project, typeAcquisition: TypeAcquisition, unresolvedImports: server.SortedReadonlyArray) { + const request = server.createInstallTypingsRequest(project, typeAcquisition, unresolvedImports, this.globalTypingsCacheLocation); this.install(request); } @@ -1726,8 +1726,8 @@ namespace ts.projectSystem { options: {} }); projectService.checkNumberOfProjects({ externalProjects: 1 }); - const typingOptions = projectService.externalProjects[0].getTypingOptions(); - assert.isTrue(typingOptions.enableAutoDiscovery, "Typing autodiscovery should be enabled"); + const typeAcquisition = projectService.externalProjects[0].getTypeAcquisition(); + assert.isTrue(typeAcquisition.enable, "Typine acquisition should be enabled"); }); }); diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 2dda506ad58f8..aea9f4eb9ed1c 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -57,8 +57,8 @@ namespace ts.projectSystem { compilerOptions: { allowJs: true }, - typingOptions: { - enableAutoDiscovery: true + typeAcquisition: { + enable: true } }) }; @@ -145,7 +145,7 @@ namespace ts.projectSystem { checkProjectActualFiles(p, [file1.path, jquery.path]); }); - it("external project - no typing options, no .d.ts/js files", () => { + it("external project - no type acquisition, no .d.ts/js files", () => { const file1 = { path: "/a/b/app.ts", content: "" @@ -173,7 +173,7 @@ namespace ts.projectSystem { projectService.checkNumberOfProjects({ externalProjects: 1 }); }); - it("external project - no autoDiscovery in typing options, no .d.ts/js files", () => { + it("external project - no auto in typing acquisition, no .d.ts/js files", () => { const file1 = { path: "/a/b/app.ts", content: "" @@ -194,11 +194,11 @@ namespace ts.projectSystem { projectFileName, options: {}, rootFiles: [toExternalFile(file1.path)], - typingOptions: { include: ["jquery"] } + typeAcquisition: { include: ["jquery"] } }); installer.checkPendingCommands(/*expectedCount*/ 0); // by default auto discovery will kick in if project contain only .js/.d.ts files - // in this case project contain only ts files - no auto discovery even if typing options is set + // in this case project contain only ts files - no auto discovery even if type acquisition is set projectService.checkNumberOfProjects({ externalProjects: 1 }); }); @@ -217,9 +217,9 @@ namespace ts.projectSystem { constructor() { super(host, { typesRegistry: createTypesRegistry("jquery") }); } - enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions, unresolvedImports: server.SortedReadonlyArray) { + enqueueInstallTypingsRequest(project: server.Project, typeAcquisition: TypeAcquisition, unresolvedImports: server.SortedReadonlyArray) { enqueueIsCalled = true; - super.enqueueInstallTypingsRequest(project, typingOptions, unresolvedImports); + super.enqueueInstallTypingsRequest(project, typeAcquisition, unresolvedImports); } installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings = ["@types/node"]; @@ -234,17 +234,17 @@ namespace ts.projectSystem { projectFileName, options: {}, rootFiles: [toExternalFile(file1.path)], - typingOptions: { enableAutoDiscovery: true, include: ["jquery"] } + typeAcquisition: { enable: true, include: ["jquery"] } }); assert.isTrue(enqueueIsCalled, "expected enqueueIsCalled to be true"); installer.installAll(/*expectedCount*/ 1); - // autoDiscovery is set in typing options - use it even if project contains only .ts files + // auto is set in type acquisition - use it even if project contains only .ts files projectService.checkNumberOfProjects({ externalProjects: 1 }); }); - it("external project - no typing options, with only js, jsx, d.ts files", () => { + it("external project - no type acquisition, with only js, jsx, d.ts files", () => { // Tests: // 1. react typings are installed for .jsx // 2. loose files names are matched against safe list for typings if @@ -288,7 +288,7 @@ namespace ts.projectSystem { projectFileName, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(file1.path), toExternalFile(file2.path), toExternalFile(file3.path)], - typingOptions: {} + typeAcquisition: {} }); const p = projectService.externalProjects[0]; @@ -301,7 +301,7 @@ namespace ts.projectSystem { checkProjectActualFiles(p, [file1.path, file2.path, file3.path, lodash.path, react.path]); }); - it("external project - no typing options, with js & ts files", () => { + it("external project - no type acquisition, with js & ts files", () => { // Tests: // 1. No typings are included for JS projects when the project contains ts files const file1 = { @@ -319,9 +319,9 @@ namespace ts.projectSystem { constructor() { super(host, { typesRegistry: createTypesRegistry("jquery") }); } - enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions, unresolvedImports: server.SortedReadonlyArray) { + enqueueInstallTypingsRequest(project: server.Project, typeAcquisition: TypeAcquisition, unresolvedImports: server.SortedReadonlyArray) { enqueueIsCalled = true; - super.enqueueInstallTypingsRequest(project, typingOptions, unresolvedImports); + super.enqueueInstallTypingsRequest(project, typeAcquisition, unresolvedImports); } installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings: string[] = []; @@ -336,7 +336,7 @@ namespace ts.projectSystem { projectFileName, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(file1.path), toExternalFile(file2.path)], - typingOptions: {} + typeAcquisition: {} }); const p = projectService.externalProjects[0]; @@ -349,11 +349,11 @@ namespace ts.projectSystem { checkProjectActualFiles(p, [file1.path, file2.path]); }); - it("external project - with typing options, with only js, d.ts files", () => { + it("external project - with type acquisition, with only js, d.ts files", () => { // Tests: - // 1. Safelist matching, typing options includes/excludes and package.json typings are all acquired - // 2. Types for safelist matches are not included when they also appear in the typing option exclude list - // 3. Multiple includes and excludes are respected in typing options + // 1. Safelist matching, type acquisition includes/excludes and package.json typings are all acquired + // 2. Types for safelist matches are not included when they also appear in the type acquisition exclude list + // 3. Multiple includes and excludes are respected in type acquisition const file1 = { path: "/a/b/lodash.js", content: "" @@ -411,7 +411,7 @@ namespace ts.projectSystem { projectFileName, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(file1.path), toExternalFile(file2.path), toExternalFile(file3.path)], - typingOptions: { include: ["jquery", "moment"], exclude: ["lodash"] } + typeAcquisition: { include: ["jquery", "moment"], exclude: ["lodash"] } }); const p = projectService.externalProjects[0]; @@ -486,7 +486,7 @@ namespace ts.projectSystem { projectFileName, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(lodashJs.path), toExternalFile(commanderJs.path), toExternalFile(file3.path)], - typingOptions: { include: ["jquery", "moment"] } + typeAcquisition: { include: ["jquery", "moment"] } }); const p = projectService.externalProjects[0]; @@ -572,7 +572,7 @@ namespace ts.projectSystem { projectFileName: projectFileName1, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(lodashJs.path), toExternalFile(commanderJs.path), toExternalFile(file3.path)], - typingOptions: { include: ["jquery", "cordova"] } + typeAcquisition: { include: ["jquery", "cordova"] } }); installer.checkPendingCommands(/*expectedCount*/ 1); @@ -584,7 +584,7 @@ namespace ts.projectSystem { projectFileName: projectFileName2, options: { allowJS: true, moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: [toExternalFile(file3.path)], - typingOptions: { include: ["grunt", "gulp"] } + typeAcquisition: { include: ["grunt", "gulp"] } }); assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request"); @@ -930,7 +930,7 @@ namespace ts.projectSystem { const host = createServerHost([f]); const cache = createMap(); for (const name of JsTyping.nodeCoreModuleList) { - const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(f.path), /*safeListPath*/ undefined, cache, { enableAutoDiscovery: true }, [name, "somename"]); + const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(f.path), /*safeListPath*/ undefined, cache, { enable: true }, [name, "somename"]); assert.deepEqual(result.newTypingNames.sort(), ["node", "somename"]); } }); @@ -946,7 +946,7 @@ namespace ts.projectSystem { }; const host = createServerHost([f, node]); const cache = createMap({ "node": node.path }); - const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(f.path), /*safeListPath*/ undefined, cache, { enableAutoDiscovery: true }, ["fs", "bar"]); + const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(f.path), /*safeListPath*/ undefined, cache, { enable: true }, ["fs", "bar"]); assert.deepEqual(result.cachedTypingPaths, [node.path]); assert.deepEqual(result.newTypingNames, ["bar"]); }); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 6a7cb049296c7..5f65140c6dcf8 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -317,7 +317,7 @@ namespace ts.server { } switch (response.kind) { case ActionSet: - this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.unresolvedImports, response.typings); + this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typeAcquisition, response.unresolvedImports, response.typings); break; case ActionInvalidate: this.typingsCache.deleteTypingsForProject(response.projectName); @@ -821,7 +821,7 @@ namespace ts.server { compilerOptions: parsedCommandLine.options, configHasFilesProperty: config["files"] !== undefined, wildcardDirectories: createMap(parsedCommandLine.wildcardDirectories), - typingOptions: parsedCommandLine.typingOptions, + typeAcquisition: parsedCommandLine.typeAcquisition, compileOnSave: parsedCommandLine.compileOnSave }; return { success: true, projectOptions, configFileErrors: errors }; @@ -845,7 +845,7 @@ namespace ts.server { return false; } - private createAndAddExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typingOptions: TypingOptions) { + private createAndAddExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition) { const compilerOptions = convertCompilerOptions(options); const project = new ExternalProject( projectFileName, @@ -855,7 +855,7 @@ namespace ts.server { /*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(compilerOptions, files, externalFilePropertyReader), options.compileOnSave === undefined ? true : options.compileOnSave); - this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined, typingOptions, /*configFileErrors*/ undefined); + this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined, typeAcquisition, /*configFileErrors*/ undefined); this.externalProjects.push(project); return project; } @@ -883,7 +883,7 @@ namespace ts.server { /*languageServiceEnabled*/ !sizeLimitExceeded, projectOptions.compileOnSave === undefined ? false : projectOptions.compileOnSave); - this.addFilesToProjectAndUpdateGraph(project, projectOptions.files, fileNamePropertyReader, clientFileName, projectOptions.typingOptions, configFileErrors); + this.addFilesToProjectAndUpdateGraph(project, projectOptions.files, fileNamePropertyReader, clientFileName, projectOptions.typeAcquisition, configFileErrors); project.watchConfigFile(project => this.onConfigChangedForConfiguredProject(project)); if (!sizeLimitExceeded) { @@ -902,7 +902,7 @@ namespace ts.server { } } - private addFilesToProjectAndUpdateGraph(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader, clientFileName: string, typingOptions: TypingOptions, configFileErrors: Diagnostic[]): void { + private addFilesToProjectAndUpdateGraph(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader, clientFileName: string, typeAcquisition: TypeAcquisition, configFileErrors: Diagnostic[]): void { let errors: Diagnostic[]; for (const f of files) { const rootFilename = propertyReader.getFileName(f); @@ -917,7 +917,7 @@ namespace ts.server { } } project.setProjectErrors(concatenate(configFileErrors, errors)); - project.setTypingOptions(typingOptions); + project.setTypeAcquisition(typeAcquisition); project.updateGraph(); } @@ -934,7 +934,7 @@ namespace ts.server { }; } - private updateNonInferredProject(project: ExternalProject | ConfiguredProject, newUncheckedFiles: T[], propertyReader: FilePropertyReader, newOptions: CompilerOptions, newTypingOptions: TypingOptions, compileOnSave: boolean, configFileErrors: Diagnostic[]) { + private updateNonInferredProject(project: ExternalProject | ConfiguredProject, newUncheckedFiles: T[], propertyReader: FilePropertyReader, newOptions: CompilerOptions, newTypeAcquisition: TypeAcquisition, compileOnSave: boolean, configFileErrors: Diagnostic[]) { const oldRootScriptInfos = project.getRootScriptInfos(); const newRootScriptInfos: ScriptInfo[] = []; const newRootScriptInfoMap: NormalizedPathMap = createNormalizedPathMap(); @@ -996,7 +996,7 @@ namespace ts.server { } project.setCompilerOptions(newOptions); - (project).setTypingOptions(newTypingOptions); + (project).setTypeAcquisition(newTypeAcquisition); // VS only set the CompileOnSaveEnabled option in the request if the option was changed recently // therefore if it is undefined, it should not be updated. @@ -1036,7 +1036,7 @@ namespace ts.server { project.enableLanguageService(); } this.watchConfigDirectoryForProject(project, projectOptions); - this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions, projectOptions.compileOnSave, configFileErrors); + this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typeAcquisition, projectOptions.compileOnSave, configFileErrors); } } @@ -1316,6 +1316,12 @@ namespace ts.server { } openExternalProject(proj: protocol.ExternalProject): void { + // typingOptions has been deprecated and is only supported for backward compatibility + // purposes. It should be removed in future releases - use typeAcquisition instead. + if (proj.typingOptions && !proj.typeAcquisition) { + const typeAcquisition = convertEnableAutoDiscoveryToEnable(proj.typingOptions); + proj.typeAcquisition = typeAcquisition; + } let tsConfigFiles: NormalizedPath[]; const rootFiles: protocol.ExternalFile[] = []; for (const file of proj.rootFiles) { @@ -1340,7 +1346,7 @@ namespace ts.server { if (externalProject) { if (!tsConfigFiles) { // external project already exists and not config files were added - update the project and return; - this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, convertCompilerOptions(proj.options), proj.typingOptions, proj.options.compileOnSave, /*configFileErrors*/ undefined); + this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, convertCompilerOptions(proj.options), proj.typeAcquisition, proj.options.compileOnSave, /*configFileErrors*/ undefined); return; } // some config files were added to external project (that previously were not there) @@ -1400,7 +1406,7 @@ namespace ts.server { else { // no config files - remove the item from the collection delete this.externalProjectToConfiguredProjectMap[proj.projectFileName]; - this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typingOptions); + this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typeAcquisition); } this.refreshInferredProjects(); } diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index 8f57cbf40746b..aa37008ff6679 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -23,7 +23,7 @@ namespace ts.server { } this.resolveModuleName = (moduleName, containingFile, compilerOptions, host) => { - const globalCache = this.project.getTypingOptions().enableAutoDiscovery + const globalCache = this.project.getTypeAcquisition().enable ? this.project.projectService.typingsInstaller.globalTypingsCacheLocation : undefined; const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host); diff --git a/src/server/project.ts b/src/server/project.ts index 82ecc6f3644a3..c37dd6e135a1d 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -312,7 +312,7 @@ namespace ts.server { return this.projectName; } abstract getProjectRootPath(): string | undefined; - abstract getTypingOptions(): TypingOptions; + abstract getTypeAcquisition(): TypeAcquisition; getSourceFile(path: Path) { if (!this.program) { @@ -802,9 +802,9 @@ namespace ts.server { } } - getTypingOptions(): TypingOptions { + getTypeAcquisition(): TypeAcquisition { return { - enableAutoDiscovery: allRootFilesAreJsOrDts(this), + enable: allRootFilesAreJsOrDts(this), include: [], exclude: [] }; @@ -812,7 +812,7 @@ namespace ts.server { } export class ConfiguredProject extends Project { - private typingOptions: TypingOptions; + private typeAcquisition: TypeAcquisition; private projectFileWatcher: FileWatcher; private directoryWatcher: FileWatcher; private directoriesWatchedForWildcards: Map; @@ -844,12 +844,12 @@ namespace ts.server { this.projectErrors = projectErrors; } - setTypingOptions(newTypingOptions: TypingOptions): void { - this.typingOptions = newTypingOptions; + setTypeAcquisition(newTypeAcquisition: TypeAcquisition): void { + this.typeAcquisition = newTypeAcquisition; } - getTypingOptions() { - return this.typingOptions; + getTypeAcquisition() { + return this.typeAcquisition; } watchConfigFile(callback: (project: ConfiguredProject) => void) { @@ -939,7 +939,7 @@ namespace ts.server { } export class ExternalProject extends Project { - private typingOptions: TypingOptions; + private typeAcquisition: TypeAcquisition; constructor(externalProjectName: string, projectService: ProjectService, documentRegistry: ts.DocumentRegistry, @@ -960,36 +960,36 @@ namespace ts.server { return getDirectoryPath(normalizeSlashes(this.getProjectName())); } - getTypingOptions() { - return this.typingOptions; + getTypeAcquisition() { + return this.typeAcquisition; } setProjectErrors(projectErrors: Diagnostic[]) { this.projectErrors = projectErrors; } - setTypingOptions(newTypingOptions: TypingOptions): void { - if (!newTypingOptions) { + setTypeAcquisition(newTypeAcquisition: TypeAcquisition): void { + if (!newTypeAcquisition) { // set default typings options - newTypingOptions = { - enableAutoDiscovery: allRootFilesAreJsOrDts(this), + newTypeAcquisition = { + enable: allRootFilesAreJsOrDts(this), include: [], exclude: [] }; } else { - if (newTypingOptions.enableAutoDiscovery === undefined) { + if (newTypeAcquisition.enable === undefined) { // if autoDiscovery was not specified by the caller - set it based on the content of the project - newTypingOptions.enableAutoDiscovery = allRootFilesAreJsOrDts(this); + newTypeAcquisition.enable = allRootFilesAreJsOrDts(this); } - if (!newTypingOptions.include) { - newTypingOptions.include = []; + if (!newTypeAcquisition.include) { + newTypeAcquisition.include = []; } - if (!newTypingOptions.exclude) { - newTypingOptions.exclude = []; + if (!newTypeAcquisition.exclude) { + newTypeAcquisition.exclude = []; } } - this.typingOptions = newTypingOptions; + this.typeAcquisition = newTypeAcquisition; } } } \ No newline at end of file diff --git a/src/server/protocol.ts b/src/server/protocol.ts index dad66f3cc7175..e1735f768e42b 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -861,9 +861,13 @@ namespace ts.server.protocol { */ options: ExternalProjectCompilerOptions; /** - * Explicitly specified typing options for the project + * @deprecated typingOptions. Use typeAcquisition instead */ - typingOptions?: TypingOptions; + typingOptions?: TypeAcquisition; + /** + * Explicitly specified type acquisition for the project + */ + typeAcquisition?: TypeAcquisition; } export interface CompileOnSaveMixin { diff --git a/src/server/server.ts b/src/server/server.ts index 220b0d90c65e6..da928c57485bc 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -275,8 +275,8 @@ namespace ts.server { this.installer.send({ projectName: p.getProjectName(), kind: "closeProject" }); } - enqueueInstallTypingsRequest(project: Project, typingOptions: TypingOptions, unresolvedImports: SortedReadonlyArray): void { - const request = createInstallTypingsRequest(project, typingOptions, unresolvedImports); + enqueueInstallTypingsRequest(project: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray): void { + const request = createInstallTypingsRequest(project, typeAcquisition, unresolvedImports); if (this.logger.hasLevel(LogLevel.verbose)) { if (this.logger.hasLevel(LogLevel.verbose)) { this.logger.info(`Scheduling throttled operation: ${JSON.stringify(request)}`); diff --git a/src/server/types.d.ts b/src/server/types.d.ts index a4032bf062e8c..77e9e762b5996 100644 --- a/src/server/types.d.ts +++ b/src/server/types.d.ts @@ -31,7 +31,7 @@ declare namespace ts.server { readonly fileNames: string[]; readonly projectRootPath: ts.Path; readonly compilerOptions: ts.CompilerOptions; - readonly typingOptions: ts.TypingOptions; + readonly typeAcquisition: ts.TypeAcquisition; readonly unresolvedImports: SortedReadonlyArray; readonly cachePath?: string; readonly kind: "discover"; @@ -54,7 +54,7 @@ declare namespace ts.server { } export interface SetTypings extends ProjectResponse { - readonly typingOptions: ts.TypingOptions; + readonly typeAcquisition: ts.TypeAcquisition; readonly compilerOptions: ts.CompilerOptions; readonly typings: string[]; readonly unresolvedImports: SortedReadonlyArray; diff --git a/src/server/typingsCache.ts b/src/server/typingsCache.ts index 9013622e24ada..8b03d59003c6d 100644 --- a/src/server/typingsCache.ts +++ b/src/server/typingsCache.ts @@ -2,7 +2,7 @@ namespace ts.server { export interface ITypingsInstaller { - enqueueInstallTypingsRequest(p: Project, typingOptions: TypingOptions, unresolvedImports: SortedReadonlyArray): void; + enqueueInstallTypingsRequest(p: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray): void; attach(projectService: ProjectService): void; onProjectClosed(p: Project): void; readonly globalTypingsCacheLocation: string; @@ -16,7 +16,7 @@ namespace ts.server { }; class TypingsCacheEntry { - readonly typingOptions: TypingOptions; + readonly typeAcquisition: TypeAcquisition; readonly compilerOptions: CompilerOptions; readonly typings: SortedReadonlyArray; readonly unresolvedImports: SortedReadonlyArray; @@ -52,8 +52,8 @@ namespace ts.server { return unique === 0; } - function typingOptionsChanged(opt1: TypingOptions, opt2: TypingOptions): boolean { - return opt1.enableAutoDiscovery !== opt2.enableAutoDiscovery || + function typeAcquisitionChanged(opt1: TypeAcquisition, opt2: TypeAcquisition): boolean { + return opt1.enable !== opt2.enable || !setIsEqualTo(opt1.include, opt2.include) || !setIsEqualTo(opt1.exclude, opt2.exclude); } @@ -77,9 +77,9 @@ namespace ts.server { } getTypingsForProject(project: Project, unresolvedImports: SortedReadonlyArray, forceRefresh: boolean): SortedReadonlyArray { - const typingOptions = project.getTypingOptions(); + const typeAcquisition = project.getTypeAcquisition(); - if (!typingOptions || !typingOptions.enableAutoDiscovery) { + if (!typeAcquisition || !typeAcquisition.enable) { return emptyArray; } @@ -87,28 +87,28 @@ namespace ts.server { const result: SortedReadonlyArray = entry ? entry.typings : emptyArray; if (forceRefresh || !entry || - typingOptionsChanged(typingOptions, entry.typingOptions) || + typeAcquisitionChanged(typeAcquisition, entry.typeAcquisition) || compilerOptionsChanged(project.getCompilerOptions(), entry.compilerOptions) || unresolvedImportsChanged(unresolvedImports, entry.unresolvedImports)) { // Note: entry is now poisoned since it does not really contain typings for a given combination of compiler options\typings options. // instead it acts as a placeholder to prevent issuing multiple requests this.perProjectCache[project.getProjectName()] = { compilerOptions: project.getCompilerOptions(), - typingOptions, + typeAcquisition, typings: result, unresolvedImports, poisoned: true }; // something has been changed, issue a request to update typings - this.installer.enqueueInstallTypingsRequest(project, typingOptions, unresolvedImports); + this.installer.enqueueInstallTypingsRequest(project, typeAcquisition, unresolvedImports); } return result; } - updateTypingsForProject(projectName: string, compilerOptions: CompilerOptions, typingOptions: TypingOptions, unresolvedImports: SortedReadonlyArray, newTypings: string[]) { + updateTypingsForProject(projectName: string, compilerOptions: CompilerOptions, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray, newTypings: string[]) { this.perProjectCache[projectName] = { compilerOptions, - typingOptions, + typeAcquisition, typings: toSortedReadonlyArray(newTypings), unresolvedImports, poisoned: false diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index 677e2c7bba098..25d53e14e755d 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -150,7 +150,7 @@ namespace ts.server.typingsInstaller { req.projectRootPath, this.safeListPath, this.packageNameToTypingLocation, - req.typingOptions, + req.typeAcquisition, req.unresolvedImports); if (this.log.isEnabled()) { @@ -391,7 +391,7 @@ namespace ts.server.typingsInstaller { private createSetTypings(request: DiscoverTypings, typings: string[]): SetTypings { return { projectName: request.projectName, - typingOptions: request.typingOptions, + typeAcquisition: request.typeAcquisition, compilerOptions: request.compilerOptions, typings, unresolvedImports: request.unresolvedImports, diff --git a/src/server/utilities.ts b/src/server/utilities.ts index a52e5848de900..fd370da7fa15f 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -46,12 +46,12 @@ namespace ts.server { } } - export function createInstallTypingsRequest(project: Project, typingOptions: TypingOptions, unresolvedImports: SortedReadonlyArray, cachePath?: string): DiscoverTypings { + export function createInstallTypingsRequest(project: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray, cachePath?: string): DiscoverTypings { return { projectName: project.getProjectName(), fileNames: project.getFileNames(/*excludeFilesFromExternalLibraries*/ true), compilerOptions: project.getCompilerOptions(), - typingOptions, + typeAcquisition, unresolvedImports, projectRootPath: getProjectRootPath(project), cachePath, @@ -171,7 +171,7 @@ namespace ts.server { files?: string[]; wildcardDirectories?: Map; compilerOptions?: CompilerOptions; - typingOptions?: TypingOptions; + typeAcquisition?: TypeAcquisition; compileOnSave?: boolean; } diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index 316dcd355c232..04ac60c4e7438 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -48,7 +48,7 @@ namespace ts.JsTyping { * @param projectRootPath is the path to the project root directory * @param safeListPath is the path used to retrieve the safe list * @param packageNameToTypingLocation is the map of package names to their cached typing locations - * @param typingOptions are used to customize the typing inference process + * @param typeAcquisition is used to customize the typing acquisition process * @param compilerOptions are used as a source for typing inference */ export function discoverTypings( @@ -57,14 +57,14 @@ namespace ts.JsTyping { projectRootPath: Path, safeListPath: Path, packageNameToTypingLocation: Map, - typingOptions: TypingOptions, + typeAcquisition: TypeAcquisition, unresolvedImports: ReadonlyArray): { cachedTypingPaths: string[], newTypingNames: string[], filesToWatch: string[] } { // A typing name to typing file path mapping const inferredTypings = createMap(); - if (!typingOptions || !typingOptions.enableAutoDiscovery) { + if (!typeAcquisition || !typeAcquisition.enable) { return { cachedTypingPaths: [], newTypingNames: [], filesToWatch: [] }; } @@ -84,8 +84,8 @@ namespace ts.JsTyping { let searchDirs: string[] = []; let exclude: string[] = []; - mergeTypings(typingOptions.include); - exclude = typingOptions.exclude || []; + mergeTypings(typeAcquisition.include); + exclude = typeAcquisition.exclude || []; const possibleSearchDirs = map(fileNames, getDirectoryPath); if (projectRootPath) { diff --git a/src/services/shims.ts b/src/services/shims.ts index 1c8132793a349..6184f1e2ff373 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -1138,7 +1138,7 @@ namespace ts { if (result.error) { return { options: {}, - typingOptions: {}, + typeAcquisition: {}, files: [], raw: {}, errors: [realizeDiagnostic(result.error, "\r\n")] @@ -1150,7 +1150,7 @@ namespace ts { return { options: configFile.options, - typingOptions: configFile.typingOptions, + typeAcquisition: configFile.typeAcquisition, files: configFile.fileNames, raw: configFile.raw, errors: realizeDiagnostics(configFile.errors, "\r\n") @@ -1175,7 +1175,7 @@ namespace ts { toPath(info.projectRootPath, info.projectRootPath, getCanonicalFileName), toPath(info.safeListPath, info.safeListPath, getCanonicalFileName), info.packageNameToTypingLocation, - info.typingOptions, + info.typeAcquisition, info.unresolvedImports); }); }