gulp-dependents
Version:
Gulp plugin that tracks dependencies between files and adds any files that depend on the files currently in the stream, thus enabling incremental build of pcss, less, scss, sass, with extensibility points to support other file types.
74 lines (73 loc) • 4.27 kB
TypeScript
import File from "vinyl";
import { IDependencyTracker } from "../dependency-tracker";
import { IDependencyParser } from "../../dependency-parser/dependency-parser";
/**
* Represents a dependency tracker, which tracks the files that pass through and the dependencies between them.
* It assumes that it will be used in such a way, that after the instance has been created, the first sequence of
* files passed to the tracker represent all the files between which dependencies may exist. This is nessesary to
* set up the initial dependency map, such that when a dependency is changed, we knows which files depend on it.
*
* A typical Gulp setup satisfying the above requirement involves two tasks:
* - A 'build' task, which pipes all files through first the 'gulp-cached' plugin, and then through this plugin.
* - A 'watch' task, which watches the files, and invokes the 'build' task whenever a file changes.
* This works because the 'gulp-cached' plugin will pass through, and cache, only the files that are not already
* in the cache or which have changed compared to the cached version. Alternatively, you may use the 'gulp-watch'
* plugin, which creates an infinite stream that initially pass through all files, and after that, only changes.
*/
export declare class DependencyTracker implements IDependencyTracker {
/**
* The parser used to extract dependency file paths from files.
*/
private dependencyParser;
/**
* Object representing a map, where a truthy value indicate the existence of the dependency defined by the keys.
* Example: dependencyMap[dependencyFilePath][filePath] == true ~ filePath depends on dependencyFilePath.
*/
private dependencyMap;
/**
* Object representing a set, where a truthy value indicate that the file defined by the key is being tracked.
* Example: trackedFilePaths[filePath] == true ~ filePath is being tracked.
*/
private trackedFilePaths;
/**
* Creates a new instance of the type.
* @param dependencyParser The parser used to extract dependency file paths from files.
*/
constructor(dependencyParser: IDependencyParser);
/**
* Updates the dependency map, returning the set of files that depend on the specified file.
* @param file The file that should be tracked and analyzed.
* @param encoding The name of the encoding used in the file.
* @return The files dependend files, or null, if no dependents should be added to the stream.
*/
updateAndGetDependents(file: File, encoding: string): File[];
/**
* Logs the state of the dependency map to the console.
* Note that this lists only dependencies and their dependents; files without dependencies
* are not listed, except as dependents, even though they are in fact tracked.
* @param basePath The absolute base path, or null to log absolute file paths.
*/
logDependencyMap(basePath?: string): void;
/**
* Logs the specified dependency and its dependents to the console.
* @param filePath The file path for which dependents should be logged.
* @param recursive True to perform a recursive search; otherwise false.
* @param basePath The absolute base path, or null to log absolute file paths.
*/
logDependents(filePath: string, recursive: boolean, basePath?: string): void;
/**
* Formats the specified path as a path relative to a base path, or returns it unmodified if it is outside the base path.
* @param absolutePath The absolute path to format.
* @param basePath The absolute base path, or null to return the absolute path.
* @return The relative path from the base path to the specified path, or an absolute path it is if outside the base path.
*/
private formatPathForDisplay;
/**
* Searches the dependency map to find the set of files that depend on the specified file path.
* @param filePath The file path for which dependent files should be found.
* @param recursive True to perform a recursive search; otherwise false.
* @param checkFilesExist True to remove file paths that do not exist in the file system from the map.
* @return The set of dependent file paths.
*/
private getDependentFilePaths;
}