/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @noformat * @oncall react_native * @generated SignedSource<<2af7aa3b61c2afa4d8794e127666c226>> * * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js * Original file: packages/metro/src/DeltaBundler/Graph.js * To regenerate, run: * js1 build metro-ts-defs (internal) OR * yarn run build-ts-defs (OSS) */ /** * Portions of this code are based on the Synchronous Cycle Collection * algorithm described in: * * David F. Bacon and V. T. Rajan. 2001. Concurrent Cycle Collection in * Reference Counted Systems. In Proceedings of the 15th European Conference on * Object-Oriented Programming (ECOOP '01). Springer-Verlag, Berlin, * Heidelberg, 207–235. * * Notable differences from the algorithm in the paper: * 1. Our implementation uses the inverseDependencies set (which we already * have to maintain) instead of a separate refcount variable. A module's * reference count is equal to the size of its inverseDependencies set, plus * 1 if it's an entry point of the graph. * 2. We keep the "root buffer" (possibleCycleRoots) free of duplicates by * making it a Set, instead of storing a "buffered" flag on each node. * 3. On top of tracking edges between nodes, we also count references between * nodes and entries in the importBundleNodes set. */ import type {RequireContext} from '../lib/contextModule'; import type { Dependencies, Dependency, GraphInputOptions, MixedOutput, Module, ModuleData, Options, ResolvedDependency, TransformInputOptions, } from './types'; import CountingSet from '../lib/CountingSet'; export type Result = { added: Map>; modified: Map>; deleted: Set; }; type Delta = Readonly<{ added: Set; touched: Set; deleted: Set; updatedModuleData: ReadonlyMap>; baseModuleData: Map>; errors: ReadonlyMap; }>; type InternalOptions = Readonly<{ lazy: boolean; onDependencyAdd: () => unknown; onDependencyAdded: () => unknown; resolve: Options['resolve']; transform: Options['transform']; shallow: boolean; }>; export declare class Graph { readonly entryPoints: ReadonlySet; readonly transformOptions: TransformInputOptions; readonly dependencies: Dependencies; constructor(options: GraphInputOptions); /** * Dependency Traversal logic for the Delta Bundler. This method calculates * the modules that should be included in the bundle by traversing the * dependency graph. * Instead of traversing the whole graph each time, it just calculates the * difference between runs by only traversing the added/removed dependencies. * To do so, it uses the passed graph dependencies and it mutates it. * The paths parameter contains the absolute paths of the root files that the * method should traverse. Normally, these paths should be the modified files * since the last traversal. */ traverseDependencies( paths: ReadonlyArray, options: Options, ): Promise>; initialTraverseDependencies(options: Options): Promise>; _buildDelta( pathsToVisit: ReadonlySet, options: InternalOptions, moduleFilter?: (path: string) => boolean, ): Promise>; _recursivelyCommitModule( path: string, delta: Delta, options: InternalOptions, commitOptions?: Readonly<{onlyRemove: boolean}>, ): Module; _addDependency( parentModule: Module, key: string, dependency: Dependency, requireContext: null | undefined | RequireContext, delta: Delta, options: InternalOptions, ): void; _removeDependency( parentModule: Module, key: string, dependency: Dependency, delta: Delta, options: InternalOptions, ): void; /** * Collect a list of context modules which include a given file. */ markModifiedContextModules( filePath: string, modifiedPaths: Set | CountingSet, ): void; /** * Gets the list of modules affected by the deletion of a given file. The * caller is expected to mark these modules as modified in the next call to * traverseDependencies. Note that the list may contain duplicates. */ getModifiedModulesForDeletedPath(filePath: string): Iterable; /** * Re-traverse the dependency graph in DFS order to reorder the modules and * guarantee the same order between runs. This method mutates the passed graph. */ reorderGraph(options: {shallow: boolean}): void; _reorderDependencies( module: Module, orderedDependencies: Map>, options: {shallow: boolean}, ): void; /** Garbage collection functions */ _incrementImportBundleReference( dependency: ResolvedDependency, parentModule: Module, ): void; _decrementImportBundleReference( dependency: ResolvedDependency, parentModule: Module, ): void; _markModuleInUse(module: Module): void; _children( module: Module, options: InternalOptions, ): Iterator>; _moduleSnapshot(module: Module): ModuleData; _releaseModule( module: Module, delta: Delta, options: InternalOptions, ): void; _freeModule(module: Module, delta: Delta): void; _markAsPossibleCycleRoot(module: Module): void; _collectCycles(delta: Delta, options: InternalOptions): void; _markGray(module: Module, options: InternalOptions): void; _scan(module: Module, options: InternalOptions): void; _scanBlack(module: Module, options: InternalOptions): void; _collectWhite(module: Module, delta: Delta): void; /** End of garbage collection functions */ }