import type { Minimatch } from 'minimatch'; import type { SourceSkips } from './sourcer/SourceSkips'; export type FingerprintSource = HashSource & { /** * Hash value of the `source`. * If the source is excluded the value will be null. */ hash: string | null; /** * Debug info from the hashing process. Differs based on source type. Designed to be consumed by humans * as opposed to programmatically. */ debugInfo?: DebugInfo; }; export interface Fingerprint { /** * Sources and their hash values from which the project fingerprint was generated. */ sources: FingerprintSource[]; /** * The final hash value of the whole project fingerprint. */ hash: string; } export type FingerprintDiffItem = { /** * The operation type of the diff item. */ op: 'added'; /** * The added source. */ addedSource: FingerprintSource; } | { /** * The operation type of the diff item. */ op: 'removed'; /** * The removed source. */ removedSource: FingerprintSource; } | { /** * The operation type of the diff item. */ op: 'changed'; /** * The source before. */ beforeSource: FingerprintSource; /** * The source after. */ afterSource: FingerprintSource; }; export type Platform = 'android' | 'ios'; export type ProjectWorkflow = 'generic' | 'managed' | 'unknown'; /** * A named preset of fingerprint settings, from strict (react to any potential native change) to * relaxed (ignore changes that usually don't affect the native build). * - `strict`: highest fidelity - even a version bump changes the fingerprint. * The historical default. * - `balanced`: the default, tuned for a good first-time experience. * - `relaxed`: for building multiple variants from one native project. * On top of `balanced`, it also ignores app identity like app icons and the Android `package` / * iOS `bundleIdentifier`. */ export type FingerprintPreset = 'strict' | 'balanced' | 'relaxed'; /** * How an autolinked native module is hashed. * - `files`: hash the module's native directory. * - `package`: hash its `package.json` `name@version`, so patch-level or cross-machine churn inside * the module is ignored. */ export type NativeModuleSourceType = 'files' | 'package'; /** * How config-plugin modules loaded while evaluating the Expo config are hashed. * - `files`: hash every loaded module from its files (in-repo and node_modules). * - `package`: collapse node_modules modules to their package `name@version` while still hashing * in-repo modules from their files, trading exact node_modules plugin fidelity for far fewer false * positives. */ export type ConfigPluginSourceType = 'files' | 'package'; export interface Options { /** * The preset to derive default settings from. * A preset sets `sourceSkips` and related defaults; * any explicitly provided option (e.g. `sourceSkips`) takes precedence over the preset. * @default 'balanced' */ preset?: FingerprintPreset; /** * Limit native files to those for specified platforms. * @default ['android', 'ios'] */ platforms?: Platform[]; /** * I/O concurrency limit. * @default The number of CPU cores. */ concurrentIoLimit?: number; /** * The algorithm to use for `crypto.createHash()`. * @default 'sha1' */ hashAlgorithm?: string; /** * Exclude specified directories from hashing. The supported pattern is the same as `glob()`. * Default is `['android/build', 'android/app/build', 'android/app/.cxx', 'ios/Pods']`. * @deprecated Use `ignorePaths` instead. */ dirExcludes?: string[]; /** * Ignore files and directories from hashing. The supported pattern is the same as `glob()`. * * The pattern matching is slightly different from gitignore. Partial matching is unsupported. For example, `build` does not match `android/build`; instead, use `'**' + '/build'`. * @see [minimatch implementations](https://github.com/isaacs/minimatch#comparisons-to-other-fnmatchglob-implementations) for further reference. * * Fingerprint comes with implicit default ignorePaths defined in `Options.DEFAULT_IGNORE_PATHS`. * If you want to override the default ignorePaths, use `!` prefix in `ignorePaths`. */ ignorePaths?: string[]; /** * Additional sources for hashing. */ extraSources?: HashSource[]; /** * Skips some sources from fingerprint. Value is the result of bitwise-OR'ing desired values of SourceSkips. * @default DEFAULT_SOURCE_SKIPS */ sourceSkips?: SourceSkips; /** * How autolinked native modules are hashed. * Defaults to the value from the resolved `preset`; set this to override it. */ nativeModuleSourceType?: NativeModuleSourceType; /** * How config-plugin modules loaded while evaluating the Expo config are hashed. * Defaults to the value from the resolved `preset`; set this to override it. */ configPluginSourceType?: ConfigPluginSourceType; /** * Enable ReactImportsPatcher to transform imports from React of the form `#import "RCTBridge.h"` to `#import `. * This is useful when you want to have a stable fingerprint for Expo projects, * since expo-modules-autolinking will change the import style on iOS. * @default true for Expo SDK 51 and lower. */ enableReactImportsPatcher?: boolean; /** * Use the react-native core autolinking sources from `expo-modules-autolinking` rather than `@react-native-community/cli`. * @default true for Expo SDK 52 and higher. */ useRNCoreAutolinkingFromExpo?: boolean; /** * Whether running the functions should mute all console output. This is useful when fingerprinting is being done as * part of a CLI that outputs a fingerprint and outputting anything else pollutes the results. */ silent?: boolean; /** * Whether to include verbose debug info in source output. Useful for debugging. */ debug?: boolean; /** * A custom hook function to transform file content sources before hashing. */ fileHookTransform?: FileHookTransformFunction; } type SourceSkipsKeys = keyof typeof SourceSkips; /** * Supported options for use in fingerprint.config.js */ export type Config = Pick & { sourceSkips?: SourceSkips | SourceSkipsKeys[]; }; /** * Hook function to transform file content sources before hashing. */ export type FileHookTransformFunction = ( /** * Source from HashSourceFile or HashSourceContents. */ source: FileHookTransformSource, /** * The chunk of file content. * When the stream reaches the end, the chunk will be null. */ chunk: Buffer | string | null, /** * Indicates the end of the file. */ isEndOfFile: boolean, /** * The encoding of the chunk. */ encoding: BufferEncoding) => Buffer | string | null; /** * The `source` parameter for `FileHookTransformFunction`. */ export type FileHookTransformSource = { type: 'file'; filePath: string; } | { type: 'contents'; id: string; }; export interface HashSourceFile { type: 'file'; filePath: string; /** * Reasons of this source coming from. */ reasons: string[]; /** * Override key for hashing. * Without this key, the `filePath` is used as the hash key. */ overrideHashKey?: string; } export interface HashSourceDir { type: 'dir'; filePath: string; /** * Reasons of this source coming from. */ reasons: string[]; /** * Override key for hashing. * Without this key, the `filePath` is used as the hash key. */ overrideHashKey?: string; } export interface HashSourceContents { type: 'contents'; id: string; contents: string | Buffer; /** * Reasons of this source coming from. */ reasons: string[]; } export interface HashSourcePackage { type: 'package'; /** * Package name from its `package.json`. * Together with `version`, this is the only thing hashed, so unrelated churn inside the package * (or across machines) is ignored. */ name: string; /** * Package version from its `package.json`. */ version: string; /** * Path to the package's `package.json`. * Kept for ignore-path matching and debugging only — it is deliberately not part of the hash, so * the fingerprint doesn't depend on where the package resolves on disk (e.g. hoisted vs. isolated * installs). */ filePath: string; /** * Reasons of this source coming from. */ reasons: string[]; /** * Override key for hashing. * Without this key, the package `name@version` is used as the hash key. */ overrideHashKey?: string; } export type HashSource = HashSourceFile | HashSourceDir | HashSourceContents | HashSourcePackage; export interface DebugInfoFile { path: string; hash: string; /** Indicates whether the source is transformed by `fileHookTransform`. */ isTransformed?: boolean; } export interface DebugInfoDir { path: string; hash: string; children: (DebugInfoFile | DebugInfoDir | undefined)[]; } export interface DebugInfoContents { hash: string; /** Indicates whether the source is transformed by `fileHookTransform`. */ isTransformed?: boolean; } export interface DebugInfoPackage { path: string; name: string; version: string; hash: string; } export type DebugInfo = DebugInfoFile | DebugInfoDir | DebugInfoContents | DebugInfoPackage; export interface HashResultFile { type: 'file'; id: string; hex: string; debugInfo?: DebugInfoFile; } export interface HashResultDir { type: 'dir'; id: string; hex: string; debugInfo?: DebugInfoDir; } export interface HashResultContents { type: 'contents'; id: string; hex: string; debugInfo?: DebugInfoContents; } export interface HashResultPackage { type: 'package'; id: string; hex: string; debugInfo?: DebugInfoPackage; } export type HashResult = HashResultFile | HashResultDir | HashResultContents | HashResultPackage; /** * @hidden */ export type NormalizedOptions = Omit & { platforms: NonNullable; concurrentIoLimit: NonNullable; hashAlgorithm: NonNullable; sourceSkips: NonNullable; enableReactImportsPatcher: NonNullable; ignorePathMatchObjects: Minimatch[]; /** * An ignore pattern list specific for dir matching. It is built by `ignorePathMatchObjects` in runtime. */ ignoreDirMatchObjects: Minimatch[]; /** * Indicate whether the project is using CNG for each platform. */ useCNGForPlatforms: Record; /** * How autolinked native modules are hashed. From the resolved preset unless explicitly overridden. */ nativeModuleSourceType: NativeModuleSourceType; /** * How config-plugin modules loaded during config evaluation are hashed. From the resolved preset * unless explicitly overridden. */ configPluginSourceType: ConfigPluginSourceType; }; export {};