Package com.google.javascript.jscomp
Class JSModuleGraph
- java.lang.Object
-
- com.google.javascript.jscomp.JSModuleGraph
-
public class JSModuleGraph extends java.lang.Object
AJSModule
dependency graph that assigns a depth to each module and can answer depth-related queries about them. For the purposes of this class, a module's depth is defined as the number of hops in the longest path from the module to a module with no dependencies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSModuleGraph.MissingModuleException
protected static class
JSModuleGraph.ModuleDependenceException
-
Constructor Summary
Constructors Constructor Description JSModuleGraph(JSModule[] modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.JSModuleGraph(java.util.List<JSModule> modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
coalesceDuplicateFiles()
Replaces any files that are found multiple times with a single instance in the closest parent module that is common to all modules where it appears.boolean
dependsOn(JSModule src, JSModule m)
Determines whether this module depends on a given module.JSModule
getDeepestCommonDependencyInclusive(JSModule m1, JSModule m2)
Finds the deepest common dependency of two modules, including the modules themselves.JSModule
getDeepestCommonDependencyInclusive(java.util.Collection<JSModule> modules)
Returns the deepest common dependency of the given modules.java.util.List<CompilerInput>
manageDependencies(DependencyOptions depOptions, java.util.List<CompilerInput> inputs)
Apply the dependency options to the list of sources, returning a new source list re-ordering and dropping files as necessary.java.util.List<CompilerInput>
manageDependencies(java.util.List<java.lang.String> entryPoints, java.util.List<CompilerInput> inputs)
Applies a DependencyOptions in "dependency sorting" and "dependency pruning" mode to the given list of inputs.
-
-
-
Method Detail
-
dependsOn
public boolean dependsOn(JSModule src, JSModule m)
Determines whether this module depends on a given module. Note that a module never depends on itself, as that dependency would be cyclic.
-
getDeepestCommonDependencyInclusive
public JSModule getDeepestCommonDependencyInclusive(JSModule m1, JSModule m2)
Finds the deepest common dependency of two modules, including the modules themselves.- Parameters:
m1
- A module in this graphm2
- A module in this graph- Returns:
- The deepest common dep of
m1
andm2
, or null if they have no common dependencies
-
getDeepestCommonDependencyInclusive
public JSModule getDeepestCommonDependencyInclusive(java.util.Collection<JSModule> modules)
Returns the deepest common dependency of the given modules.
-
coalesceDuplicateFiles
public void coalesceDuplicateFiles()
Replaces any files that are found multiple times with a single instance in the closest parent module that is common to all modules where it appears. JSCompiler normally errors if you attempt to compile modules containing the same file. This method can be used to remove duplicates before compiling to avoid such an error.
-
manageDependencies
public java.util.List<CompilerInput> manageDependencies(java.util.List<java.lang.String> entryPoints, java.util.List<CompilerInput> inputs) throws SortedDependencies.CircularDependencyException, JSModuleGraph.MissingModuleException, SortedDependencies.MissingProvideException
Applies a DependencyOptions in "dependency sorting" and "dependency pruning" mode to the given list of inputs. Returns a new list with the files sorted and removed. This module graph will be updated to reflect the new list. If you need more fine-grained dependency management, you should create your own DependencyOptions and callmanageDependencies(DependencyOptions, List<CompilerInput>)
.- Parameters:
entryPoints
- The entry points into the program. Expressed as JS symbols.inputs
- The original list of sources. Used to ensure that the sort is stable.- Throws:
SortedDependencies.CircularDependencyException
- if there is a circular dependency between the provides and requires.SortedDependencies.MissingProvideException
- if an entry point was not provided by any of the inputs.JSModuleGraph.MissingModuleException
- See Also:
for more info on how this works.
-
manageDependencies
public java.util.List<CompilerInput> manageDependencies(DependencyOptions depOptions, java.util.List<CompilerInput> inputs) throws SortedDependencies.CircularDependencyException, SortedDependencies.MissingProvideException, JSModuleGraph.MissingModuleException
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.- Parameters:
inputs
- The original list of sources. Used to ensure that the sort is stable.- Throws:
SortedDependencies.CircularDependencyException
- if there is a circular dependency between the provides and requires.SortedDependencies.MissingProvideException
- if an entry point was not provided by any of the inputs.JSModuleGraph.MissingModuleException
- See Also:
for more info on how this works.
-
-