Esempio n. 1
0
        public NodeModules(IRootPackage parent, bool showMissingDevOptionalSubPackages) {
            var modulesBase = Path.Combine(parent.Path, "node_modules");
            if (Directory.Exists(modulesBase)) {
                var bin = string.Format("{0}.bin", Path.DirectorySeparatorChar);
                foreach (var moduleDir in Directory.EnumerateDirectories(modulesBase)) {
                    if (!moduleDir.EndsWith(bin)) {
                        AddModule(new Package(parent, moduleDir, showMissingDevOptionalSubPackages));
                    }
                }
            }

            var parentPackageJson = parent.PackageJson;
            if (null != parentPackageJson) {
                foreach (var dependency in parentPackageJson.AllDependencies) {
                    Package module = null;
                    if (!Contains(dependency.Name)) {
                        module = new Package(
                            parent,
                            Path.Combine(modulesBase, dependency.Name),
                            showMissingDevOptionalSubPackages);
                        if (parent as IPackage == null || !module.IsMissing || showMissingDevOptionalSubPackages) {
                            AddModule(module);
                        }
                    } else {
                        module = this[dependency.Name] as Package;
                    }

                    if (null != module) {
                        module.RequestedVersionRange = dependency.VersionRangeText;
                    }
                }
            }

            _packagesSorted.Sort(new PackageComparer());
        }
Esempio n. 2
0
        private bool AddModuleIfNotExists(IRootPackage parent, string moduleDir, bool showMissingDevOptionalSubPackages, int depth, int maxDepth, IDependency dependency = null) {
            depth++;

            ModuleInfo moduleInfo;
            _allModules.TryGetValue(moduleDir, out moduleInfo);

            if (moduleInfo != null) {
                // Update module information if the module already exists.
                if (moduleInfo.Depth > depth) {
                    moduleInfo.Depth = depth;
                }

                if (dependency != null) {
                    var existingPackage = this[dependency.Name] as Package;
                    if (existingPackage != null) {
                        existingPackage.RequestedVersionRange = dependency.VersionRangeText;
                    }
                }
            } else if (Directory.Exists(moduleDir) || depth == 1) {
                // Top-level modules are always added so we can include missing modules.
                moduleInfo = new ModuleInfo(depth);
                _allModules.Add(moduleDir, moduleInfo);
            } else {
                // The module directory wasn't found.
                return false;
            }

            IPackage package = moduleInfo.Package;
                        
            if (package == null || depth == 1 || !moduleInfo.RequiredBy.Contains(parent.Path)) {
                // Create a dummy value for the current package to prevent infinite loops
                moduleInfo.Package = new PackageProxy();

                moduleInfo.RequiredBy.Add(parent.Path);

                var pkg = new Package(parent, moduleDir, showMissingDevOptionalSubPackages, _allModules, depth, maxDepth);
                if (dependency != null) {
                    pkg.RequestedVersionRange = dependency.VersionRangeText;
                }

                package = moduleInfo.Package = pkg;
            }

            if (parent as IPackage == null || !package.IsMissing || showMissingDevOptionalSubPackages) {
                AddModule(package);
            }

            return true;
        }
Esempio n. 3
0
        private bool AddModuleIfNotExists(IRootPackage parent, string moduleDir, bool showMissingDevOptionalSubPackages, int depth, IDependency dependency = null) {
            depth++;

            ModuleInfo moduleInfo;
            _allModules.TryGetValue(moduleDir, out moduleInfo);

            if (moduleInfo != null) {
                // Update module information if the module already exists.
                if (moduleInfo.Depth > depth) {
                    moduleInfo.Depth = depth;
                }

                if (dependency != null) {
                    var existingPackage = this[dependency.Name] as Package;
                    if (existingPackage != null) {
                        existingPackage.RequestedVersionRange = dependency.VersionRangeText;
                    }
                }
            } else if (Directory.Exists(moduleDir) || depth == 1) {
                // Top-level modules are always added so we can include missing modules.
                moduleInfo = new ModuleInfo(depth);
                _allModules.Add(moduleDir, moduleInfo);
            } else {
                // The module directory wasn't found.
                return false;
            }

            if (moduleInfo.RequiredBy.Contains(parent.Name)) {
                return true;
            }

            moduleInfo.RequiredBy.Add(parent.Name);
            var package = new Package(parent, moduleDir, showMissingDevOptionalSubPackages, _allModules, depth);
            if (dependency != null) {
                package.RequestedVersionRange = dependency.VersionRangeText;
            }
            AddModule(package);

            return true;
        }