* Adds inferred typings from manifest/module pairs (think package.json + node_modules) * * @param projectRootPath is the path to the directory where to look for package.json, bower.json and other typing information * @param manifestName is the name of the manif
(projectRootPath, manifestName, modulesDirName, filesToWatch)
| 125808 | * @param filesToWatch are the files to watch for changes. We will push things into this array. |
| 125809 | */ |
| 125810 | function getTypingNames(projectRootPath, manifestName, modulesDirName, filesToWatch) { |
| 125811 | // First, we check the manifests themselves. They're not |
| 125812 | // _required_, but they allow us to do some filtering when dealing |
| 125813 | // with big flat dep directories. |
| 125814 | var manifestPath = ts.combinePaths(projectRootPath, manifestName); |
| 125815 | var manifest; |
| 125816 | var manifestTypingNames; |
| 125817 | if (host.fileExists(manifestPath)) { |
| 125818 | filesToWatch.push(manifestPath); |
| 125819 | manifest = ts.readConfigFile(manifestPath, function (path) { return host.readFile(path); }).config; |
| 125820 | manifestTypingNames = ts.flatMap([manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies], ts.getOwnKeys); |
| 125821 | addInferredTypings(manifestTypingNames, "Typing names in '".concat(manifestPath, "' dependencies")); |
| 125822 | } |
| 125823 | // Now we scan the directories for typing information in |
| 125824 | // already-installed dependencies (if present). Note that this |
| 125825 | // step happens regardless of whether a manifest was present, |
| 125826 | // which is certainly a valid configuration, if an unusual one. |
| 125827 | var packagesFolderPath = ts.combinePaths(projectRootPath, modulesDirName); |
| 125828 | filesToWatch.push(packagesFolderPath); |
| 125829 | if (!host.directoryExists(packagesFolderPath)) { |
| 125830 | return; |
| 125831 | } |
| 125832 | // There's two cases we have to take into account here: |
| 125833 | // 1. If manifest is undefined, then we're not using a manifest. |
| 125834 | // That means that we should scan _all_ dependencies at the top |
| 125835 | // level of the modulesDir. |
| 125836 | // 2. If manifest is defined, then we can do some special |
| 125837 | // filtering to reduce the amount of scanning we need to do. |
| 125838 | // |
| 125839 | // Previous versions of this algorithm checked for a `_requiredBy` |
| 125840 | // field in the package.json, but that field is only present in |
| 125841 | // `npm@>=3 <7`. |
| 125842 | // Package names that do **not** provide their own typings, so |
| 125843 | // we'll look them up. |
| 125844 | var packageNames = []; |
| 125845 | var dependencyManifestNames = manifestTypingNames |
| 125846 | // This is #1 described above. |
| 125847 | ? manifestTypingNames.map(function (typingName) { return ts.combinePaths(packagesFolderPath, typingName, manifestName); }) |
| 125848 | // And #2. Depth = 3 because scoped packages look like `node_modules/@foo/bar/package.json` |
| 125849 | : host.readDirectory(packagesFolderPath, [".json" /* Extension.Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 3) |
| 125850 | .filter(function (manifestPath) { |
| 125851 | if (ts.getBaseFileName(manifestPath) !== manifestName) { |
| 125852 | return false; |
| 125853 | } |
| 125854 | // It's ok to treat |
| 125855 | // `node_modules/@foo/bar/package.json` as a manifest, |
| 125856 | // but not `node_modules/jquery/nested/package.json`. |
| 125857 | // We only assume depth 3 is ok for formally scoped |
| 125858 | // packages. So that needs this dance here. |
| 125859 | var pathComponents = ts.getPathComponents(ts.normalizePath(manifestPath)); |
| 125860 | var isScoped = pathComponents[pathComponents.length - 3][0] === "@"; |
| 125861 | return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar` |
| 125862 | !isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo` |
| 125863 | }); |
| 125864 | if (log) |
| 125865 | log("Searching for typing names in ".concat(packagesFolderPath, "; all files: ").concat(JSON.stringify(dependencyManifestNames))); |
| 125866 | // Once we have the names of things to look up, we iterate over |
| 125867 | // and either collect their included typings, or add them to the |
no test coverage detected
searching dependent graphs…