1import fs from 'fs/promises'; 2import os from 'os'; 3import path from 'path'; 4 5import type { NormalizedOptions, Options } from './Fingerprint.types'; 6 7export const FINGERPRINT_IGNORE_FILENAME = '.fingerprintignore'; 8 9export const DEFAULT_IGNORE_PATHS = [ 10 FINGERPRINT_IGNORE_FILENAME, 11 '**/android/build/**/*', 12 '**/android/app/build/**/*', 13 '**/android/app/.cxx/**/*', 14 '**/ios/Pods/**/*', 15 16 // Ignore all expo configs because we will read expo config in a HashSourceContents already 17 'app.config.ts', 18 'app.config.js', 19 'app.config.json', 20 'app.json', 21]; 22 23export async function normalizeOptionsAsync( 24 projectRoot: string, 25 options?: Options 26): Promise<NormalizedOptions> { 27 return { 28 ...options, 29 platforms: options?.platforms ?? ['android', 'ios'], 30 concurrentIoLimit: options?.concurrentIoLimit ?? os.cpus().length, 31 hashAlgorithm: options?.hashAlgorithm ?? 'sha1', 32 ignorePaths: await collectIgnorePathsAsync(projectRoot, options), 33 }; 34} 35 36async function collectIgnorePathsAsync(projectRoot: string, options?: Options): Promise<string[]> { 37 const ignorePaths = [ 38 ...DEFAULT_IGNORE_PATHS, 39 ...(options?.ignorePaths ?? []), 40 ...(options?.dirExcludes?.map((dirExclude) => `${dirExclude}/**/*`) ?? []), 41 ]; 42 43 const fingerprintIgnorePath = path.join(projectRoot, FINGERPRINT_IGNORE_FILENAME); 44 try { 45 const fingerprintIgnore = await fs.readFile(fingerprintIgnorePath, 'utf8'); 46 const fingerprintIgnoreLines = fingerprintIgnore.split('\n'); 47 for (const line of fingerprintIgnoreLines) { 48 const trimmedLine = line.trim(); 49 if (trimmedLine) { 50 ignorePaths.push(trimmedLine); 51 } 52 } 53 } catch {} 54 55 return ignorePaths; 56} 57