Esempio n. 1
0
        private static void TestPeerExists()
        {
            var            name                        = "@ionic/angular";
            var            folderRoot                  = Environment.CurrentDirectory;
            var            packageNodeModulesPath      = Path.GetFullPath(Path.Combine(folderRoot, @"..\..\TestOutput\AngularProject\node_modules"));
            var            packageNodeModulesDirectory = new DirectoryInfo(packageNodeModulesPath);
            var            cacheRoot                   = Environment.ExpandEnvironmentVariables(@"%APPDATA%\hydra\cache");
            var            cacheRootDirectory          = new DirectoryInfo(cacheRoot);
            NpmNodeModules npmPackageModules           = null;

            if (packageNodeModulesDirectory.Exists)
            {
                var packagePath = Path.Combine(packageNodeModulesPath, name.BackSlashes());

                npmPackageModules = new NpmNodeModules(packageNodeModulesPath);
            }

            if (cacheRootDirectory.Exists)
            {
                var npmCacheModules = new NpmNodeModules(cacheRoot);
                var cachePath       = Path.Combine(cacheRoot, name.BackSlashes());
                var cacheDirectory  = new DirectoryInfo(cachePath);

                if (cacheDirectory.Exists)
                {
                    if (NpmPackage.HasPackage(cachePath))
                    {
                        var  npmCachePackage = new NpmPackage(cachePath);
                        bool packagePeerExists;
                        bool cachePeerExists;

                        npmCachePackage.Load();

                        if (npmPackageModules != null)
                        {
                            packagePeerExists = npmCachePackage.PeerDependencies.PeerExists(npmPackageModules);
                        }

                        cachePeerExists = npmCachePackage.PeerDependencies.PeerExists(npmCacheModules);
                    }
                }
            }
        }
Esempio n. 2
0
        private static void TestPackageWorkingInstallFromCache()
        {
            var    name                    = "ionic";
            var    folderRoot              = Environment.CurrentDirectory;
            var    nodeModulesPath         = Path.GetFullPath(Path.Combine(folderRoot, @"..\..\TestOutput\AngularProject\node_modules"));
            var    cachePath               = Environment.ExpandEnvironmentVariables(@"%APPDATA%\hydra\cache\" + name);
            var    packagePath             = Path.Combine(nodeModulesPath, name.BackSlashes());
            var    packageModules          = new NpmNodeModules(nodeModulesPath);
            var    workingInstallFromCache = new PackageWorkingInstallFromCache("installs", name, cachePath, packagePath, packageModules);
            var    installsFromCacheStatus = new PackageInstallsFromCacheStatus("No activity reported");
            string printTree;
            bool   validate;

            TestPeerExists();

            workingInstallFromCache.OnUpdateCacheStatus += (sender, e) =>
            {
                switch (e.IncrementKind)
                {
                case IncrementKind.IncrementAll:

                    Debug.Assert(e.Increment == 1);
                    installsFromCacheStatus.IncrementAll();
                    break;

                case IncrementKind.IncrementTotal:

                    Debug.Assert(e.Increment == 1);
                    installsFromCacheStatus.IncrementTotal();
                    break;

                case IncrementKind.Total:

                    installsFromCacheStatus.Total += e.Increment;
                    break;

                case IncrementKind.TotalRemaining:

                    installsFromCacheStatus.TotalRemaining += e.Increment;
                    break;

                case IncrementKind.Requested:

                    installsFromCacheStatus.Requested += e.Increment;
                    break;

                case IncrementKind.RequestedRemaining:

                    installsFromCacheStatus.RequestedRemaining += e.Increment;
                    break;
                }
            };

            workingInstallFromCache.OnAddInstallStatus += (sender, e) =>
            {
                var installFromCache = e.InstallFromCache;
                var mode             = e.StatusMode;
                var status           = e.Status;
                var args             = e.Args;

                if (args.Length > 0)
                {
                    status = string.Format(status, args);
                }

                installFromCache.InstallStatusList.Add(installFromCache.CreateStatus(status, mode));
            };

            workingInstallFromCache.InstallPackage(false);

            validate  = workingInstallFromCache.ValidateTree(installsFromCacheStatus);
            printTree = workingInstallFromCache.PrintTree();

            workingInstallFromCache.ExecuteActions();

            Console.WriteLine(installsFromCacheStatus.StatusText);
            Console.WriteLine();
            Console.WriteLine(printTree);
        }
Esempio n. 3
0
        public static bool AllPeersExist(this Dictionary <string, string> peerDependencies, NpmNodeModules nodeModules)
        {
            if (peerDependencies.Count == 0)
            {
                return(false);
            }
            else
            {
                foreach (var peerDependencyPair in peerDependencies)
                {
                    var        name    = peerDependencyPair.Key;
                    NpmVersion version = peerDependencyPair.Value;

                    foreach (var package in nodeModules.LoadedPackages.Where(p => p.Name == name))
                    {
                        if (!version.Matches(package.Version))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }