* @param host is the object providing I/O related operations. * @param fileNames are the file names that belong to the same project * @param projectRootPath is the path to the project root directory * @param safeListPath is the path used to retrieve the safe list
(host, log, fileNames, projectRootPath, safeList, packageNameToTypingLocation, typeAcquisition, unresolvedImports, typesRegistry)
| 125730 | * @param compilerOptions are used as a source for typing inference |
| 125731 | */ |
| 125732 | function discoverTypings(host, log, fileNames, projectRootPath, safeList, packageNameToTypingLocation, typeAcquisition, unresolvedImports, typesRegistry) { |
| 125733 | if (!typeAcquisition || !typeAcquisition.enable) { |
| 125734 | return { cachedTypingPaths: [], newTypingNames: [], filesToWatch: [] }; |
| 125735 | } |
| 125736 | // A typing name to typing file path mapping |
| 125737 | var inferredTypings = new ts.Map(); |
| 125738 | // Only infer typings for .js and .jsx files |
| 125739 | fileNames = ts.mapDefined(fileNames, function (fileName) { |
| 125740 | var path = ts.normalizePath(fileName); |
| 125741 | if (ts.hasJSFileExtension(path)) { |
| 125742 | return path; |
| 125743 | } |
| 125744 | }); |
| 125745 | var filesToWatch = []; |
| 125746 | if (typeAcquisition.include) |
| 125747 | addInferredTypings(typeAcquisition.include, "Explicitly included types"); |
| 125748 | var exclude = typeAcquisition.exclude || []; |
| 125749 | // Directories to search for package.json, bower.json and other typing information |
| 125750 | var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath)); |
| 125751 | possibleSearchDirs.add(projectRootPath); |
| 125752 | possibleSearchDirs.forEach(function (searchDir) { |
| 125753 | getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch); |
| 125754 | getTypingNames(searchDir, "package.json", "node_modules", filesToWatch); |
| 125755 | }); |
| 125756 | if (!typeAcquisition.disableFilenameBasedTypeAcquisition) { |
| 125757 | getTypingNamesFromSourceFileNames(fileNames); |
| 125758 | } |
| 125759 | // add typings for unresolved imports |
| 125760 | if (unresolvedImports) { |
| 125761 | var module_1 = ts.deduplicate(unresolvedImports.map(nonRelativeModuleNameForTypingCache), ts.equateStringsCaseSensitive, ts.compareStringsCaseSensitive); |
| 125762 | addInferredTypings(module_1, "Inferred typings from unresolved imports"); |
| 125763 | } |
| 125764 | // Add the cached typing locations for inferred typings that are already installed |
| 125765 | packageNameToTypingLocation.forEach(function (typing, name) { |
| 125766 | var registryEntry = typesRegistry.get(name); |
| 125767 | if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) { |
| 125768 | inferredTypings.set(name, typing.typingLocation); |
| 125769 | } |
| 125770 | }); |
| 125771 | // Remove typings that the user has added to the exclude list |
| 125772 | for (var _i = 0, exclude_1 = exclude; _i < exclude_1.length; _i++) { |
| 125773 | var excludeTypingName = exclude_1[_i]; |
| 125774 | var didDelete = inferredTypings.delete(excludeTypingName); |
| 125775 | if (didDelete && log) |
| 125776 | log("Typing for ".concat(excludeTypingName, " is in exclude list, will be ignored.")); |
| 125777 | } |
| 125778 | var newTypingNames = []; |
| 125779 | var cachedTypingPaths = []; |
| 125780 | inferredTypings.forEach(function (inferred, typing) { |
| 125781 | if (inferred !== undefined) { |
| 125782 | cachedTypingPaths.push(inferred); |
| 125783 | } |
| 125784 | else { |
| 125785 | newTypingNames.push(typing); |
| 125786 | } |
| 125787 | }); |
| 125788 | var result = { cachedTypingPaths: cachedTypingPaths, newTypingNames: newTypingNames, filesToWatch: filesToWatch }; |
| 125789 | if (log) |
nothing calls this directly
no test coverage detected