Ejemplo n.º 1
0
        private IEnumerable <LibraryReference> GetReferencesFromFile(string fileName)
        {
            var folderName = Path.GetFileName(Path.GetDirectoryName(fileName));

            if (new IgnoreFilter(Configuration.IgnorePackages.ByFolderName).Filter(folderName))
            {
                yield break;
            }

            var nodeModulesDirectoryName = Path.Combine(Path.GetDirectoryName(fileName), PackageJsonParser.NodeModules);

            if (!Directory.Exists(nodeModulesDirectoryName))
            {
                throw new DirectoryNotFoundException("Directory {0} not found.".FormatWith(nodeModulesDirectoryName));
            }

            var parser       = PackageJsonParser.FromFile(fileName);
            var ignoreByName = new IgnoreFilter(Configuration.IgnorePackages.ByName);

            foreach (var dependency in parser.GetDependencies())
            {
                if (!ignoreByName.Filter(dependency.Name))
                {
                    yield return(ReadFromNodeModules(dependency, nodeModulesDirectoryName, false));
                }
            }

            foreach (var dependency in parser.GetDevDependencies())
            {
                if (!ignoreByName.Filter(dependency.Name))
                {
                    yield return(ReadFromNodeModules(dependency, nodeModulesDirectoryName, true));
                }
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <(NuGetPackageId Package, IList <LibraryId> Dependencies)> GetFilteredReferences(ProjectAssetsParser parser, string[] targetFrameworks)
        {
            if (new IgnoreFilter(Configuration.IgnorePackages.ByProjectName).Filter(parser.GetProjectName()))
            {
                yield break;
            }

            var ignoreFilterByName = new IgnoreFilter(Configuration.IgnorePackages.ByName);

            foreach (var targetFramework in targetFrameworks)
            {
                foreach (var entry in parser.GetReferences(targetFramework))
                {
                    if (ignoreFilterByName.Filter(entry.Package.Name))
                    {
                        continue;
                    }

                    var dependencies = new List <LibraryId>(entry.Dependencies.Count);
                    foreach (var d in entry.Dependencies)
                    {
                        if (!ignoreFilterByName.Filter(d.Name))
                        {
                            dependencies.Add(new LibraryId(PackageSources.NuGet, d.Name, d.Version));
                        }
                    }

                    yield return(entry.Package, dependencies);
                }
            }
        }
Ejemplo n.º 3
0
        public void Ignore_certain_dotSync_files_in_reporoot(string relativeFilename)
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[]{});

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }
Ejemplo n.º 4
0
        public void Filter_case_insenstive(string relativeFilename)
        {
            var sut = new IgnoreFilter(null, new[]{"hello"});

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }
Ejemplo n.º 5
0
        public void Dont_ignore_dotSync_files_in_subfolders(string relativeFilename)
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[] { });

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNotNull(result);
        }
Ejemplo n.º 6
0
        public void Dont_ignore_files_with_dotSync_extension(string relativeFilename)
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[]{});

            var rf = new RepoFile {RelativeFileName = relativeFilename};
            RepoFile result = null;
            sut.Filter(rf, _ => result = _);

            Equalidator.AreEqual(result, rf);
        }
Ejemplo n.º 7
0
        public void Ignore_empty_patterns(string relativeFilename, string expected)
        {
            var sut = new IgnoreFilter(null, new[] { "A", "", "B" });

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            if (relativeFilename == "C")
                Assert.AreEqual("C", result.RelativeFileName);
            else
                Assert.IsNull(result);
        }
Ejemplo n.º 8
0
        private IEnumerable <LibraryReference> GetReferencesFromFile(string fileName)
        {
            var parser = ProjectAssetsParser.FromFile(fileName);

            var targetFrameworks = parser.GetTargetFrameworks();

            var internalFilterByName = new IgnoreFilter(Configuration.InternalPackages.ByName);
            var isInternalByProject  = new IgnoreFilter(Configuration.InternalPackages.ByProjectName).Filter(parser.GetProjectName());

            foreach (var entry in GetFilteredReferences(parser, targetFrameworks))
            {
                var isInternal = isInternalByProject || internalFilterByName.Filter(entry.Package.Name);
                yield return(new LibraryReference(
                                 new LibraryId(PackageSources.NuGet, entry.Package.Name, entry.Package.Version),
                                 targetFrameworks,
                                 entry.Dependencies,
                                 isInternal));
            }
        }
Ejemplo n.º 9
0
        public void Ignore_on_multiple_patterns(string relativeFilename, string ignorePatterns)
        {
            var sut = new IgnoreFilter(REPO_PATH, ignorePatterns.Split(','));

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }
Ejemplo n.º 10
0
        public void No_file_to_ignore()
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[]{});

            RepoFile result = null;
            var rf = new RepoFile {RelativeFileName = "hello.txt"};
            sut.Filter(rf, _ => result = _);

            Equalidator.AreEqual(result, rf);
        }
Ejemplo n.º 11
0
        public void Load_ignore_patterns_from_ignorefile(string relativeFilename)
        {
            File.WriteAllText(".syncignore", "/bin/");
            var sut = new IgnoreFilter(".");

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }
Ejemplo n.º 12
0
        public void Ignore_on_single_pattern(string relativeFilename, string ignorePattern)
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[] { ignorePattern });

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }
Ejemplo n.º 13
0
        public void Ignore_on_normalized_path_delimiter(string relativeFilename)
        {
            var sut = new IgnoreFilter(REPO_PATH, new string[] { "/abc" });

            RepoFile result = null;
            sut.Filter(new RepoFile { RelativeFileName = relativeFilename }, _ => result = _);

            Assert.IsNull(result);
        }