Re-order the given dependencies of each manifest configuration.

@param array $deps List of dependencies
@param array $stack List of task names that are scheduled after this task
@todo version checks
180671
private function _addManifests( array $deps, array $stack=array( ) )
	{
		foreach ( $deps as $extName => $name )
		{
			if ( in_array( $extName, $this->_extensionsDone ) ) {
				continue;
			}

			if ( in_array( $extName, $stack ) ) {
				$msg = sprintf( 'Circular dependency for "%1$s" detected', $extName );
				throw new Exception( $msg );
			}

			$stack[] = $extName;

			/** @todo test for expression object or array when implementing version checks */
			if ( isset( $this->_dependencies[$extName] ) ) {
				$this->_addManifests( (array) $this->_dependencies[$extName], $stack );
			}

			if ( isset( $this->_extensions[$extName] ) ) {
				$this->_manifests[$this->_extensions[$extName]['location']] = $this->_extensions[$extName];
			}

			$this->_extensionsDone[] = $extName;
		}
	}
1108516
protected function _runTasks( $dbtype, array $tasknames, array $stack = array() )
	{
		foreach( $tasknames as $taskname )
		{
			if( in_array( $taskname, $this->_tasksDone ) ) { continue; }

			if( in_array( $taskname, $stack ) ) {
				$msg = 'Circular dependency for "%1$s" detected. Task stack: %2$s';
				throw new MW_Setup_Exception( sprintf( $msg, $taskname, implode( ', ', $stack ) ) );
			}

			$stack[] = $taskname;

			if( isset( $this->_dependencies[$taskname] ) ) {
				$this->_runTasks( $dbtype, (array) $this->_dependencies[$taskname], $stack );
			}

			if( isset( $this->_tasks[$taskname] ) ) {
				$this->_tasks[$taskname]->run( $dbtype );
			}

			$this->_tasksDone[] = $taskname;
		}
	}
1288465
private function formatGemfile(array $dependencies)
    {
        $lines = ["source 'https://rubygems.org'"];
        foreach ($dependencies as $package => $version) {
            if ($version != '*') {
                $lines[] = sprintf("gem '%s', '%s', :require => false", $package, $version);
            } else {
                $lines[] = sprintf("gem '%s', :require => false", $package);
            }
        }

        return implode("\n", $lines);
    }
233807
protected function get_dependency_array( $handle ) {
		foreach ( $this->dependencies as $type => $dependencies ) {
			if ( array_key_exists( $handle, $dependencies ) ) {
				return [ $type, $dependencies[ $handle ] ];
			}
		}
		// Handle not found, return an empty array.
		return [ '', null ];
	}
348759
private function sort(array $stageSteps)
    {
        if (empty($stageSteps)) {
            return [];
        }

        $dependencyGraphBuilder = new StepDependencyGraphBuilder($stageSteps);
        return $dependencyGraphBuilder->build()->sort();
    }
978221
public static DeclaredDependencies toDeclaredDependencies(Map<DependencyDescriptor, Set<DependencyDescriptor>> depMap) {
        DeclaredDependencies dependencies = new DeclaredDependencies();
        depMap.forEach((directDep, resolvedDeps) -> {
            ArtifactSpec parent = toArtifactSpec(directDep);
            dependencies.addResolved(parent);
            if (resolvedDeps != null) {
                resolvedDeps.forEach(d -> dependencies.addResolved(parent, toArtifactSpec(d)));
            }
        });
        return dependencies;
    }
63190
public static function stack(string $stack)
    {
        if (! static::hasStack($stack)) {
            static::$stacks[$stack] = new StickyContextStack;
        }

        return static::$stacks[$stack];
    }
645506
function(links) {
  this.dependencies = _buildDependencies(links);
  this.tasks = graph.tsort(this.dependencies).reverse();  
  this.index = 0;
}
490602
private function fixDeps($deps)
    {
        foreach (array_keys($deps) as $dep) {
            if (isset($deps[$dep]['optional']) && $deps[$dep]['optional']) {
                $deps[$dep]['optional'] = "yes";
            }
        }

        return $deps;
    }
394002
private function shouldRemoveStack(array $stack): bool
    {
        if (empty($stack['class'])) {
            return false;
        }

        foreach ($this->ignoreBacktraceNamespaces as $namespace) {
            if (0 === strpos($stack['class'], $namespace)) {
                return true;
            }
        }

        return false;
    }
201941
protected function enqueue_dependencies( $handles, $context = null ) {
		if ( null !== $context ) {
			$this->add_context( $context );
		}

		if ( ! $this->dependencies || count( $handles ) < 1 ) {
			return;
		}

		foreach ( $handles as $handle ) {
			$found = $this->dependencies->enqueue_handle(
				$handle,
				$this->context,
				true
			);
			if ( ! $found ) {
				$message = sprintf(
					__( 'Could not enqueue dependency "%1$s" for shortcode "%2$s".',
						'bn-shortcodes' ),
					$handle,
					$this->get_tag()
				);
				trigger_error( $message, E_USER_WARNING );
			}
		}

	}
770516
private function installGlobal(array $dependencies)
    {
        $requirements = [];
        foreach ($dependencies as $package => $version) {
            $requirements[] = $version === '*' ? $package : $package . ':' . $version;
        }
        $this->runCommand(
            'composer global require '
            . '--no-progress --prefer-dist --optimize-autoloader --no-interaction '
            . implode(' ', array_map('escapeshellarg', $requirements))
        );
    }
422511
public function setStack($stack)
    {
        if ($stack instanceof StackUri) {
            $this->stack = $stack;
        } elseif (\is_string($stack)) {
            $this->stack = new StackUri($stack);
        } else {
            if ('object' == \gettype($stack)) {
                $given = \get_class($stack);
            } else {
                $given = \gettype($stack);
            }

            throw new \RuntimeException('Stack needs to be StackUri or string. '.$given.' given.');
        }
    }
788988
private function installGlobal(array $dependencies)
    {
        foreach ($dependencies as $package => $version) {
            if (!$this->isInstalledGlobally($package)) {
                $arg = $version === '*' ? $package : $package . '@' . $version;
                $this->runCommand('npm install --global ' . escapeshellarg($arg));
            }
        }
    }
709106
private function assertRemovalsDoNotAffectDependencies(array $registrations)
    {
        $removalIds = [];
        foreach ($this->removals as $removal) {
            $removalIds[$removal->getIdToRemove()] = 0;
        }

        foreach ($registrations as $registration) {
            /** @var StepRegistrationDependency $dependency */
            foreach (array_merge($registration->getBefores(), $registration->getAfters()) as $dependency) {
                if (isset($removalIds[$dependency->getDependsOnId()])) {
                    throw new PipelineBuildingException(
                        "You cannot remove step registration with id '{$dependency->getDependsOnId()}', registration with id '{$registration->getStepId()}' depends on it."
                    );
                }
            }
        }
    }
539607
protected function resolveDependencies(array $dependencies, array $parameters = [])
    {
        $results = [];
        foreach ($dependencies as $dependency) {
            if (array_key_exists($dependency->name, $parameters)) { // Parameter value is given
                $results[] = $parameters[$dependency->name];
            } else { // Parameter value is not given
                $results[] = is_null($class = $dependency->getClass())
                    ? $dependency->getDefaultValue()
                    : $this->getInstance($dependency->getClass()->name);
            }
        }

        return $results;
    }
810909
function preprocessDependencies(dependencies) {
		if (Array.isArray(dependencies)) {
			// remove .library-preload suffix from dependencies
			return dependencies.map(function (dep) {
				return dep.replace(/\.library-preload$/, '');
			});
		}
		return dependencies;
	}