/// import { ClosureModuleFactory } from './ClosureModuleFactory'; import { PluginError } from '../errors/PluginError'; import { MatchState, Sources } from '../source/Sources'; import { ClosureModule, DependencyParam } from './ClosureModule'; import type { Environment } from '../Environment'; /** Namespace object that used mange and present namespace structure. */ export interface NamespaceObject { /** This namespace full name last part. */ name: string; /** This namespace name. */ fullname: string; /** Sub parts fullname and namespace object. */ subs: Map; } /** Store all root namespace objects, e.g. goog */ export declare const RootsObject: NamespaceObject; export declare class ClosureTree { readonly factory: ClosureModuleFactory; readonly env: Environment; readonly libpath: string; readonly googpath: string; readonly basefile: string; readonly depsfile: string; readonly namespaceToRequest: Map; readonly requestToModule: Map; readonly roots: NamespaceObject; readonly sources: Sources; /** Errors when parsing Closure module. */ readonly errors: PluginError[]; /** Warnings when parsing Closure module. */ readonly warnings: PluginError[]; /** * @param options.base - Path to Closure library base.js file, must be absolute or relative from the environment context. * @param options.sources - List of absolute patterns, or relative from the environment context. */ constructor(options: { base?: string; sources: string | string[]; env: Environment; }); private _collectErrors; addModule(module: ClosureModule): void; /** * @param namespace - Full namespace, dot-separated sequence of a-z, A-Z, 0-9, _ and $. */ addProvide(namespace: string, module: ClosureModule): void; /** * Check Closure tree. * This will auto perform after {@link ClosureTree.scan}. * @see https://github.com/google/closure-library/blob/c3b90b/closure-deps/lib/depgraph.js#L336 * @throws {@link CircularReferenceError} Throw CircularReferenceError if has circular reference. * @throws {@link BadRequire} Throw BadRequire if GOOG module not has exposed namespace but connect PROVIDE module. * @throws {@link PluginError} Throw PluginError if the required namespace missing or load failed. */ check(): void; clear(): void; /** * Unload and destory the module from tree, also remove its provides. * @param arg - Request or namespace. */ deleteModule(arg: string): void; /** * @param arg - Request or namespace. */ private _get; /** * Find the specific module, return null if not found. * If the module in tree but not load, load it. * @param arg - Request or namespace. */ getModule(arg: string): ClosureModule | null; /** * Get the specific Namespace object. * @param namespace - Full namespace, dot-separated sequence of a-z, A-Z, 0-9, _ and $. * Defautls return the {@link RootsObject}. */ getNamespaceObject(namespace?: string, constructMissing?: boolean): NamespaceObject | null; /** * Get namespace all sub parts. * @param namespace - Full namespace, dot-separated sequence of a-z, A-Z, 0-9, _ and $. * Defaults return all root namespaces(subs in the {@link RootsObject}). * @returns Return null if the namespace not found. */ getSubNamespace(namespace?: string): string[] | null; /** * If the specific module in tree, return true. * @param arg - Request or namespace. */ hasModule(arg: string): boolean; /** * If the request is a library module, return true. * @throws {@link PluginError} Throw PluginError if Closure library base.js file not found. */ isLibraryModule(arg: string | ClosureModule): boolean; /** * If the namespace is a library namespace, return true. * @param namespace - Full namespace, dot-separated sequence of a-z, A-Z, 0-9, _ and $. * @throws {@link PluginError} Throw PluginError if Closure library base.js file not found. */ isLibraryNamespace(namespace: string): boolean; /** * Load and parse the request module from dependency param or source. * If the module in tree but not loaded, load and return it; * If the request not in tree and not excluded, add to source and try load it; * If the module not in tree and not in filesystem, return null; * If the request excluded, return null; * @param arg - Request or goog.addDependency params. */ loadModule(arg: string | DependencyParam, source?: string | Buffer): ClosureModule | null; /** * Create list of goog.addDependency params. * @param filter - Test each Closure module, defaults filter out all Closure library modules. * @param base - Defautls base.js file. * @throws {@link PluginError} Throw PluginError if Closure library base.js file not found. */ makeDependencies(filter?: (module: ClosureModule) => boolean, base?: string): DependencyParam[]; /** * Create dependency param from the request module. * @param arg - Request or namespace. * @param base - Defautls base.js file. * @throws {@link PluginError} Throw PluginError if Closure library base.js file not found. */ makeDependencyParam(arg: string, base?: string): DependencyParam | null; /** * Get the relative path from base.js to the js file. * @param arg - Request or namespace. * @param base - Defautls base.js file. * @throws {@link PluginError} Throw PluginError if Closure library base.js file not found. */ makeRelPath(arg: string, base?: string): string | null; /** * Get the request match state. * If the request is a library module, always return MatchState.INCLUDE; * If the request is included in this.sources, return MatchState.INCLUDE; * If the request is excluded in this.sources, return MatchState.EXCLUDE; * If the request not included and not excluded, return MatchState.UNKNOW; * @param request - A file, directory or glob pattern that absolute or relative from the environment context. */ matchRequest(request: string): MatchState; /** Reload a module that already in this tree. */ reloadModule(request: string, source?: string | Buffer): ClosureModule | null; /** * Scan and load all files found. * @param patterns - List of patterns, defaults scan all. */ scan(patterns?: string | string[]): void; }