/** * 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<<919ac912df195d04796dd62cb68839d2>> * * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js * Original file: packages/metro-file-map/src/flow-types.js * To regenerate, run: * js1 build metro-ts-defs (internal) OR * yarn run build-ts-defs (OSS) */ import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config'; export type {PerfLoggerFactory, PerfLogger}; export type BuildParameters = Readonly<{ computeSha1: boolean; enableSymlinks: boolean; extensions: ReadonlyArray; forceNodeFilesystemAPI: boolean; ignorePattern: RegExp; plugins: ReadonlyArray; retainAllFiles: boolean; rootDir: string; roots: ReadonlyArray; cacheBreaker: string; }>; export type BuildResult = {fileSystem: FileSystem}; export type CacheData = Readonly<{ clocks: WatchmanClocks; fileSystemData: unknown; plugins: ReadonlyMap; }>; export interface CacheManager { /** * Called during startup to load initial state, if available. Provided to * a crawler, which will return the delta between the initial state and the * current file system state. */ read(): Promise; /** * Called when metro-file-map `build()` has applied changes returned by the * crawler - i.e. internal state reflects the current file system state. * * getSnapshot may be retained and called at any time before end(), such as * in response to eventSource 'change' events. */ write( getSnapshot: () => CacheData, opts: CacheManagerWriteOptions, ): Promise; /** * The last call that will be made to this CacheManager. Any handles should * be closed by the time this settles. */ end(): Promise; } export interface CacheManagerEventSource { onChange(listener: () => void): () => void; } export type CacheManagerFactory = ( options: CacheManagerFactoryOptions, ) => CacheManager; export type CacheManagerFactoryOptions = Readonly<{ buildParameters: BuildParameters; }>; export type CacheManagerWriteOptions = Readonly<{ changedSinceCacheRead: boolean; eventSource: CacheManagerEventSource; onWriteError: (error: Error) => void; }>; export type CanonicalPath = string; export type ChangeEvent = { logger: null | undefined | RootPerfLogger; eventsQueue: EventsQueue; }; export type ChangeEventMetadata = { modifiedTime: null | undefined | number; size: null | undefined | number; type: 'f' | 'd' | 'l'; }; export type Console = typeof global.console; export type CrawlerOptions = { abortSignal: null | undefined | AbortSignal; computeSha1: boolean; console: Console; extensions: ReadonlyArray; forceNodeFilesystemAPI: boolean; ignore: IgnoreMatcher; includeSymlinks: boolean; perfLogger?: null | undefined | PerfLogger; previousState: Readonly<{ clocks: ReadonlyMap; fileSystem: FileSystem; }>; rootDir: string; roots: ReadonlyArray; onStatus: (status: WatcherStatus) => void; }; export type DependencyExtractor = { extract: ( content: string, absoluteFilePath: string, defaultExtractor?: DependencyExtractor['extract'], ) => Set; getCacheKey: () => string; }; export type WatcherStatus = | { type: 'watchman_slow_command'; timeElapsed: number; command: 'watch-project' | 'query'; } | { type: 'watchman_slow_command_complete'; timeElapsed: number; command: 'watch-project' | 'query'; } | { type: 'watchman_warning'; warning: unknown; command: 'watch-project' | 'query'; }; export type DuplicatesSet = Map; export type DuplicatesIndex = Map>; export type EventsQueue = Array<{ filePath: Path; metadata: ChangeEventMetadata; type: string; }>; export type FileMapDelta = Readonly<{ removed: Iterable<[CanonicalPath, T]>; addedOrModified: Iterable<[CanonicalPath, T]>; }>; export type FileMapPluginInitOptions< SerializableState, PerFileData = void, > = Readonly<{ files: Readonly<{ fileIterator( opts: Readonly<{includeNodeModules: boolean; includeSymlinks: boolean}>, ): Iterable<{ baseName: string; canonicalPath: string; pluginData: null | undefined | PerFileData; }>; lookup( mixedPath: string, ): | {exists: false} | {exists: true; type: 'f'; pluginData: PerFileData} | {exists: true; type: 'd'}; }>; pluginState: null | undefined | SerializableState; }>; export type FileMapPluginWorker = Readonly<{ worker: Readonly<{modulePath: string; setupArgs: JsonData}>; filter: ($$PARAM_0$$: { normalPath: string; isNodeModules: boolean; }) => boolean; }>; export type V8Serializable = | string | number | boolean | null | ReadonlyArray | ReadonlySet | ReadonlyMap | Readonly<{[key: string]: V8Serializable}>; export interface FileMapPlugin< SerializableState extends void | V8Serializable = void | V8Serializable, PerFileData extends void | V8Serializable = void | V8Serializable, > { readonly name: string; initialize( initOptions: FileMapPluginInitOptions, ): Promise; assertValid(): void; bulkUpdate(delta: FileMapDelta): void; getSerializableSnapshot(): SerializableState; onRemovedFile( relativeFilePath: string, pluginData: null | undefined | PerFileData, ): void; onNewOrModifiedFile( relativeFilePath: string, pluginData: null | undefined | PerFileData, ): void; getCacheKey(): string; getWorker(): null | undefined | FileMapPluginWorker; } export interface MetadataWorker { processFile( $$PARAM_0$$: WorkerMessage, $$PARAM_1$$: Readonly<{getContent: () => Buffer}>, ): V8Serializable; } export type HType = { MTIME: 0; SIZE: 1; VISITED: 2; SHA1: 3; SYMLINK: 4; PLUGINDATA: number; PATH: 0; TYPE: 1; MODULE: 0; PACKAGE: 1; GENERIC_PLATFORM: 'g'; NATIVE_PLATFORM: 'native'; }; export type HTypeValue = HType[keyof HType]; export type IgnoreMatcher = (item: string) => boolean; export type FileData = Map; export type FileMetadata = [ null | undefined | number, number, 0 | 1, null | undefined | string, 0 | 1 | string, ...unknown[], ]; export type FileStats = Readonly<{ fileType: 'f' | 'l'; modifiedTime: null | undefined | number; size: null | undefined | number; }>; export interface FileSystem { exists(file: Path): boolean; getAllFiles(): Array; getDifference(files: FileData): { changedFiles: FileData; removedFiles: Set; }; getSerializableSnapshot(): CacheData['fileSystemData']; getSha1(file: Path): null | undefined | string; getOrComputeSha1( file: Path, ): Promise; /** * Given a start path (which need not exist), a subpath and type, and * optionally a 'breakOnSegment', performs the following: * * X = mixedStartPath * do * if basename(X) === opts.breakOnSegment * return null * if X + subpath exists and has type opts.subpathType * return { * absolutePath: realpath(X + subpath) * containerRelativePath: relative(mixedStartPath, X) * } * X = dirname(X) * while X !== dirname(X) * * If opts.invalidatedBy is given, collects all absolute, real paths that if * added or removed may invalidate this result. * * Useful for finding the closest package scope (subpath: package.json, * type f, breakOnSegment: node_modules) or closest potential package root * (subpath: node_modules/pkg, type: d) in Node.js resolution. */ hierarchicalLookup( mixedStartPath: string, subpath: string, opts: { breakOnSegment: null | undefined | string; invalidatedBy: null | undefined | Set; subpathType: 'f' | 'd'; }, ): null | undefined | {absolutePath: string; containerRelativePath: string}; /** * Analogous to posix lstat. If the file at `file` is a symlink, return * information about the symlink without following it. */ linkStats(file: Path): null | undefined | FileStats; /** * Return information about the given path, whether a directory or file. * Always follow symlinks, and return a real path if it exists. */ lookup(mixedPath: Path): LookupResult; matchFiles(opts: { filter?: RegExp | null; filterCompareAbsolute?: boolean; filterComparePosix?: boolean; follow?: boolean; recursive?: boolean; rootDir?: Path | null; }): Iterable; } export type Glob = string; export type JsonData = | string | number | boolean | null | Array | {[key: string]: JsonData}; export type LookupResult = | {exists: false; links: ReadonlySet; missing: string} | {exists: true; links: ReadonlySet; realPath: string; type: 'd'} | { exists: true; links: ReadonlySet; realPath: string; type: 'f'; metadata: FileMetadata; }; export interface MockMap { getMockModule(name: string): null | undefined | Path; } export type HasteConflict = { id: string; platform: string | null; absolutePaths: Array; type: 'duplicate' | 'shadowing'; }; export interface HasteMap { getModule( name: string, platform?: null | undefined | string, supportsNativePlatform?: null | undefined | boolean, type?: null | undefined | HTypeValue, ): null | undefined | Path; getModuleNameByPath(file: Path): null | undefined | string; getPackage( name: string, platform: null | undefined | string, _supportsNativePlatform: null | undefined | boolean, ): null | undefined | Path; computeConflicts(): Array; } export type HasteMapData = Map; export type HasteMapItem = { [platform: string]: HasteMapItemMetadata; }; export type HasteMapItemMetadata = [string, number]; export interface MutableFileSystem extends FileSystem { remove(filePath: Path): null | undefined | FileMetadata; addOrModify(filePath: Path, fileMetadata: FileMetadata): void; bulkAddOrModify(addedOrModifiedFiles: FileData): void; } export type Path = string; export type ProcessFileFunction = ( normalPath: string, metadata: FileMetadata, request: Readonly<{computeSha1: boolean}>, ) => null | undefined | Buffer; export type RawMockMap = Readonly<{ duplicates: Map>; mocks: Map; version: number; }>; export type ReadOnlyRawMockMap = Readonly<{ duplicates: ReadonlyMap>; mocks: ReadonlyMap; version: number; }>; export interface WatcherBackend { getPauseReason(): null | undefined | string; onError(listener: (error: Error) => void): () => void; onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void; startWatching(): Promise; stopWatching(): Promise; } export type ChangeEventClock = [string, string]; export type WatcherBackendChangeEvent = | Readonly<{ event: 'touch'; clock?: ChangeEventClock; relativePath: string; root: string; metadata: ChangeEventMetadata; }> | Readonly<{ event: 'delete'; clock?: ChangeEventClock; relativePath: string; root: string; metadata?: void; }>; export type WatcherBackendOptions = Readonly<{ ignored: null | undefined | RegExp; globs: ReadonlyArray; dot: boolean; }>; export type WatchmanClockSpec = | string | Readonly<{scm: Readonly<{'mergebase-with': string}>}>; export type WatchmanClocks = Map; export type WorkerMessage = Readonly<{ computeSha1: boolean; filePath: string; maybeReturnContent: boolean; pluginsToRun: ReadonlyArray; }>; export type WorkerMetadata = Readonly<{ sha1?: null | undefined | string; content?: null | undefined | Buffer; pluginData?: ReadonlyArray; }>; export type WorkerSetupArgs = Readonly<{ plugins?: ReadonlyArray; }>;