src/com/google/javascript/jscomp/JSModuleGraph.java
/**
   * Apply the dependency options to the list of sources, returning a new source list re-ordering
   * and dropping files as necessary. This module graph will be updated to reflect the new list.
   *
   * @throws MissingProvideException if an entry point was not provided by any of the inputs.
   * @see DependencyOptions for more info on how this works.
   */
Apply the dependency options to the list of sources, returning a new source list re-ordering
and dropping files as necessary. This module graph will be updated to reflect the new list.

@throws MissingProvideException if an entry point was not provided by any of the inputs.
@see DependencyOptions for more info on how this works.
Apply the dependency options to the list of sources returning a new source list re - ordering and dropping files as necessary . This module graph will be updated to reflect the new list . @throws MissingProvideException if an entry point was not provided by any of the inputs . @see DependencyOptions for more info on how this works .
public ImmutableList<CompilerInput> manageDependencies(DependencyOptions depOptions)
      throws MissingProvideException, MissingModuleException {
    List<CompilerInput> originalInputs = ImmutableList.copyOf(getAllInputs());
    SortedDependencies<CompilerInput> sorter = new Es6SortedDependencies<>(originalInputs);
    Set<CompilerInput> entryPointInputs =
        createEntryPointInputs(depOptions, getAllInputs(), sorter);
    HashMap<String, CompilerInput> inputsByProvide = new HashMap<>();
    for (CompilerInput input : originalInputs) {
      for (String provide : input.getKnownProvides()) {
        inputsByProvide.put(provide, input);
      }
      String moduleName = input.getPath().toModuleName();
      inputsByProvide.putIfAbsent(moduleName, input);
    }
    for (CompilerInput input : originalInputs) {
      for (String require : input.getDynamicRequires()) {
        if (inputsByProvide.containsKey(require)) {
          entryPointInputs.add(inputsByProvide.get(require));
        }
      }
    }
    List<CompilerInput> absoluteOrder =
        sorter.getDependenciesOf(originalInputs, depOptions.shouldSortDependencies());
    ListMultimap<JSModule, CompilerInput> entryPointInputsPerModule =
        LinkedListMultimap.create();
    for (CompilerInput input : entryPointInputs) {
      JSModule module = input.getModule();
      checkNotNull(module);
      entryPointInputsPerModule.put(module, input);
    }
    for (JSModule module : getAllModules()) {
      module.removeAll();
    }
    List<CompilerInput> orderedInputs = new ArrayList<>();
    Set<CompilerInput> reachedInputs = new HashSet<>();
    for (JSModule module : entryPointInputsPerModule.keySet()) {
      List<CompilerInput> transitiveClosure;
      if (depOptions.shouldSortDependencies() && depOptions.shouldPruneDependencies()) {
        transitiveClosure = new ArrayList<>();
        Set<CompilerInput> inputsNotYetReached = new HashSet<>(originalInputs);
        for (CompilerInput entryPoint : entryPointInputsPerModule.get(module)) {
          transitiveClosure.addAll(
              getDepthFirstDependenciesOf(entryPoint, inputsNotYetReached, inputsByProvide));
        }
        for (CompilerInput orderedInput : transitiveClosure) {
          if (reachedInputs.add(orderedInput)) {
            orderedInputs.add(orderedInput);
          }
        }
      } else {
        transitiveClosure =
            sorter.getDependenciesOf(
                entryPointInputsPerModule.get(module), depOptions.shouldSortDependencies());
      }
      for (CompilerInput input : transitiveClosure) {
        JSModule oldModule = input.getModule();
        if (oldModule == null) {
          input.setModule(module);
        } else {
          input.setModule(null);
          input.setModule(
              getDeepestCommonDependencyInclusive(oldModule, module));
        }
      }
    }
    if (!(depOptions.shouldSortDependencies() && depOptions.shouldPruneDependencies())
        || entryPointInputsPerModule.isEmpty()) {
      orderedInputs = absoluteOrder;
    }
    for (CompilerInput input : orderedInputs) {
      JSModule module = input.getModule();
      if (module != null) {
        module.add(input);
      }
    }
    ImmutableList.Builder<CompilerInput> result = ImmutableList.builder();
    for (JSModule module : getAllModules()) {
      result.addAll(module.getInputs());
    }
    return result.build();
  }
public ImmutableList < CompilerInput > manageDependencies ( DependencyOptions depOptions ) throws MissingProvideException , MissingModuleException { List < CompilerInput > originalInputs = ImmutableList . copyOf ( getAllInputs ( ) ) ; SortedDependencies < CompilerInput > sorter = new Es6SortedDependencies < > ( originalInputs ) ; Set < CompilerInput > entryPointInputs = createEntryPointInputs ( depOptions , getAllInputs ( ) , sorter ) ; HashMap < String , CompilerInput > inputsByProvide = new HashMap < > ( ) ; for ( CompilerInput input : originalInputs ) { for ( String provide : input . getKnownProvides ( ) ) { inputsByProvide . put ( provide , input ) ; } String moduleName = input . getPath ( ) . toModuleName ( ) ; inputsByProvide . putIfAbsent ( moduleName , input ) ; } for ( CompilerInput input : originalInputs ) { for ( String require : input . getDynamicRequires ( ) ) { if ( inputsByProvide . containsKey ( require ) ) { entryPointInputs . add ( inputsByProvide . get ( require ) ) ; } } } List < CompilerInput > absoluteOrder = sorter . getDependenciesOf ( originalInputs , depOptions . shouldSortDependencies ( ) ) ; ListMultimap < JSModule , CompilerInput > entryPointInputsPerModule = LinkedListMultimap . create ( ) ; for ( CompilerInput input : entryPointInputs ) { JSModule module = input . getModule ( ) ; checkNotNull ( module ) ; entryPointInputsPerModule . put ( module , input ) ; } for ( JSModule module : getAllModules ( ) ) { module . removeAll ( ) ; } List < CompilerInput > orderedInputs = new ArrayList < > ( ) ; Set < CompilerInput > reachedInputs = new HashSet < > ( ) ; for ( JSModule module : entryPointInputsPerModule . keySet ( ) ) { List < CompilerInput > transitiveClosure ; if ( depOptions . shouldSortDependencies ( ) && depOptions . shouldPruneDependencies ( ) ) { transitiveClosure = new ArrayList < > ( ) ; Set < CompilerInput > inputsNotYetReached = new HashSet < > ( originalInputs ) ; for ( CompilerInput entryPoint : entryPointInputsPerModule . get ( module ) ) { transitiveClosure . addAll ( getDepthFirstDependenciesOf ( entryPoint , inputsNotYetReached , inputsByProvide ) ) ; } for ( CompilerInput orderedInput : transitiveClosure ) { if ( reachedInputs . add ( orderedInput ) ) { orderedInputs . add ( orderedInput ) ; } } } else { transitiveClosure = sorter . getDependenciesOf ( entryPointInputsPerModule . get ( module ) , depOptions . shouldSortDependencies ( ) ) ; } for ( CompilerInput input : transitiveClosure ) { JSModule oldModule = input . getModule ( ) ; if ( oldModule == null ) { input . setModule ( module ) ; } else { input . setModule ( null ) ; input . setModule ( getDeepestCommonDependencyInclusive ( oldModule , module ) ) ; } } } if ( ! ( depOptions . shouldSortDependencies ( ) && depOptions . shouldPruneDependencies ( ) ) || entryPointInputsPerModule . isEmpty ( ) ) { orderedInputs = absoluteOrder ; } for ( CompilerInput input : orderedInputs ) { JSModule module = input . getModule ( ) ; if ( module != null ) { module . add ( input ) ; } } ImmutableList . Builder < CompilerInput > result = ImmutableList . builder ( ) ; for ( JSModule module : getAllModules ( ) ) { result . addAll ( module . getInputs ( ) ) ; } return result . build ( ) ; }
Apply the dependency options to the list of sources, returning a new source list re-ordering
 and dropping files as necessary.
Apply the dependency options to the list of sources returning a new source list re - ordering and dropping files as necessary .
// Make a copy since we're going to mutate the graph below. // Dynamically imported files must be added to the module graph, but // they should not be ordered ahead of the files that import them. // We add them as entry points to ensure they get included. // The order of inputs, sorted independently of modules. // Figure out which sources *must* be in each module. // Clear the modules of their inputs. This also nulls out // the input's reference to its module. // Figure out which sources *must* be in each module, or in one // of that module's dependencies. // Prefer a depth first ordering of dependencies from entry points. // Always orders in a deterministic fashion regardless of the order of provided inputs // given the same entry points in the same order. // We need the ful set of dependencies for each module, so start with the full input set // For any input we have not yet reached, add them to the ordered list // Simply order inputs so that any required namespace comes before it's usage. // Ordered result varies based on the original order of inputs. // All the inputs are pointing to the modules that own them. Yeah! // Update the modules to reflect this. // Now, generate the sorted result.