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 // Ignore default javascript files when calling `getConfig()` 23 '**/node_modules/@babel/**/*', 24 '**/node_modules/@expo/**/*', 25 '**/node_modules/@jridgewell/**/*', 26 '**/node_modules/expo/config.js', 27 '**/node_modules/expo/config-plugins.js', 28 `**/node_modules/{${[ 29 'debug', 30 'escape-string-regexp', 31 'getenv', 32 'graceful-fs', 33 'has-flag', 34 'imurmurhash', 35 'js-tokens', 36 'json5', 37 'lines-and-columns', 38 'require-from-string', 39 'resolve-from', 40 'signal-exit', 41 'sucrase', 42 'supports-color', 43 'ts-interface-checker', 44 'write-file-atomic', 45 ].join(',')}}/**/*`, 46]; 47 48export async function normalizeOptionsAsync( 49 projectRoot: string, 50 options?: Options 51): Promise<NormalizedOptions> { 52 return { 53 ...options, 54 platforms: options?.platforms ?? ['android', 'ios'], 55 concurrentIoLimit: options?.concurrentIoLimit ?? os.cpus().length, 56 hashAlgorithm: options?.hashAlgorithm ?? 'sha1', 57 ignorePaths: await collectIgnorePathsAsync(projectRoot, options), 58 }; 59} 60 61async function collectIgnorePathsAsync(projectRoot: string, options?: Options): Promise<string[]> { 62 const ignorePaths = [ 63 ...DEFAULT_IGNORE_PATHS, 64 ...(options?.ignorePaths ?? []), 65 ...(options?.dirExcludes?.map((dirExclude) => `${dirExclude}/**/*`) ?? []), 66 ]; 67 68 const fingerprintIgnorePath = path.join(projectRoot, FINGERPRINT_IGNORE_FILENAME); 69 try { 70 const fingerprintIgnore = await fs.readFile(fingerprintIgnorePath, 'utf8'); 71 const fingerprintIgnoreLines = fingerprintIgnore.split('\n'); 72 for (const line of fingerprintIgnoreLines) { 73 const trimmedLine = line.trim(); 74 if (trimmedLine) { 75 ignorePaths.push(trimmedLine); 76 } 77 } 78 } catch {} 79 80 return ignorePaths; 81} 82