private static IEnumerable <KeyValuePair <string, IPackageJson> > GetTopLevelPackageDirectories(string modulesBase) { var topLevelDirectories = Enumerable.Empty <string>(); if (Directory.Exists(modulesBase)) { try { topLevelDirectories = Directory.EnumerateDirectories(modulesBase); } catch (IOException) { // We want to handle DirectoryNotFound, DriveNotFound, PathTooLong } catch (UnauthorizedAccessException) { } } // Go through every directory in node_modules, and see if it's required as a top-level dependency foreach (var moduleDir in topLevelDirectories) { if (moduleDir.Length < NativeMethods.MAX_FOLDER_PATH && !_ignoredDirectories.Any(toIgnore => moduleDir.EndsWith(toIgnore))) { IPackageJson json = null; try { json = PackageJsonFactory.Create(new DirectoryPackageJsonSource(moduleDir)); } catch (PackageJsonException) { // Fail gracefully if there was an error parsing the package.json Debug.Fail("Failed to parse package.json in {0}", moduleDir); } if (json != null) { yield return(new KeyValuePair <string, IPackageJson>(moduleDir, json)); } } } }
private static void CheckPackage(IPackageJson pkg) { Assert.IsNotNull(pkg, "Package should not be null."); Assert.AreEqual("TestPkg", pkg.Name, "Package name mismatch."); Assert.AreEqual(SemverVersion.Parse("0.1.0"), pkg.Version, "Package version mismatch."); }