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 LibraryReference ReadFromNodeModules(
            NpmPackageId dependency,
            string nodeModulesDirectoryName,
            bool isInternal)
        {
            var fileName = Path.Combine(nodeModulesDirectoryName, dependency.Name, PackageJsonParser.FileName);

            if (!File.Exists(fileName))
            {
                fileName = Path.Combine(GetNpmRoot(), dependency.Name, PackageJsonParser.FileName);
                if (!File.Exists(fileName))
                {
                    // throw new FileNotFoundException("File {0} not found.".FormatWith(fileName));
                    Logger.Error("Npm package {0}/{1} not found.".FormatWith(dependency.Name, dependency.Version));
                    return(null);
                }
            }

            var parser = PackageJsonParser.FromFile(fileName);

            return(new LibraryReference(
                       new LibraryId(PackageSources.Npm, parser.GetName(), parser.GetVersion()),
                       Array.Empty <string>(),
                       Array.Empty <LibraryId>(),
                       isInternal));
        }