@@ -26,6 +26,14 @@ const DEFAULT_IOS_RUNNER_APP_BUNDLE_ID = 'com.callstack.agentdevice.runner';
2626const RUNNER_DERIVED_ROOT = path . join ( os . homedir ( ) , '.agent-device' , 'apple-runner' ) ;
2727export const RUNNER_CACHE_METADATA_FILE = '.agent-device-runner-cache.json' ;
2828const RUNNER_CACHE_SCHEMA_VERSION = 2 ;
29+ const RUNNER_SOURCE_IGNORED_DIR_NAMES = new Set ( [ '.build' , '.swiftpm' , 'xcuserdata' ] ) ;
30+ const SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES = new Set ( [
31+ '.build' ,
32+ '.swiftpm' ,
33+ 'SnapshotPresentationConformance' ,
34+ 'Tests' ,
35+ 'xcuserdata' ,
36+ ] ) ;
2937const RUNNER_SANDBOX_BUILD_ARGS = [
3038 '-IDEPackageSupportDisableManifestSandbox=1' ,
3139 '-IDEPackageSupportDisablePluginExecutionSandbox=1' ,
@@ -247,12 +255,18 @@ const runnerSourceFingerprintCache = new Map<string, RunnerSourceFingerprintCach
247255
248256function computeRunnerSourceFingerprint ( projectRoot : string ) : string {
249257 const sourceRoots = [
250- resolveAppleRunnerSourceRoot ( projectRoot ) ,
251- resolveAppleSnapshotPresentationSourceRoot ( projectRoot ) ,
258+ {
259+ path : resolveAppleRunnerSourceRoot ( projectRoot ) ,
260+ ignoredDirectoryNames : RUNNER_SOURCE_IGNORED_DIR_NAMES ,
261+ } ,
262+ {
263+ path : resolveAppleSnapshotPresentationSourceRoot ( projectRoot ) ,
264+ ignoredDirectoryNames : SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES ,
265+ } ,
252266 ] ;
253267 const files = collectRunnerSourceFiles ( sourceRoots ) ;
254268 const fileStatsFingerprint = computeRunnerSourceFileStatsFingerprint ( projectRoot , files ) ;
255- const cacheKey = JSON . stringify ( sourceRoots ) ;
269+ const cacheKey = JSON . stringify ( sourceRoots . map ( ( { path : sourcePath } ) => sourcePath ) ) ;
256270 const cached = runnerSourceFingerprintCache . get ( cacheKey ) ;
257271 if ( cached ?. fileStatsFingerprint === fileStatsFingerprint ) {
258272 return cached . sourceFingerprint ;
@@ -288,23 +302,40 @@ function computeRunnerSourceFileStatsFingerprint(
288302 return hash . digest ( 'hex' ) ;
289303}
290304
291- function collectRunnerSourceFiles ( roots : readonly string [ ] ) : string [ ] {
292- return [ ...new Set ( roots . flatMap ( collectRunnerSourceFilesUnderRoot ) ) ] . sort ( ( a , b ) =>
293- a . localeCompare ( b ) ,
294- ) ;
305+ type RunnerSourceRoot = Readonly < {
306+ path : string ;
307+ ignoredDirectoryNames : ReadonlySet < string > ;
308+ } > ;
309+
310+ function collectRunnerSourceFiles ( roots : readonly RunnerSourceRoot [ ] ) : string [ ] {
311+ return [
312+ ...new Set (
313+ roots . flatMap ( ( { path : sourcePath , ignoredDirectoryNames } ) =>
314+ collectRunnerSourceFilesUnderRoot ( sourcePath , ignoredDirectoryNames ) ,
315+ ) ,
316+ ) ,
317+ ] . sort ( ( a , b ) => a . localeCompare ( b ) ) ;
295318}
296319
297- function collectRunnerSourceFilesUnderRoot ( root : string ) : string [ ] {
298- return fs . existsSync ( root ) ? collectRunnerSourceFilesInDirectory ( root ) : [ ] ;
320+ function collectRunnerSourceFilesUnderRoot (
321+ root : string ,
322+ ignoredDirectoryNames : ReadonlySet < string > ,
323+ ) : string [ ] {
324+ return fs . existsSync ( root )
325+ ? collectRunnerSourceFilesInDirectory ( root , ignoredDirectoryNames )
326+ : [ ] ;
299327}
300328
301- function collectRunnerSourceFilesInDirectory ( directory : string ) : string [ ] {
329+ function collectRunnerSourceFilesInDirectory (
330+ directory : string ,
331+ ignoredDirectoryNames : ReadonlySet < string > ,
332+ ) : string [ ] {
302333 const files : string [ ] = [ ] ;
303334 for ( const entry of fs . readdirSync ( directory , { withFileTypes : true } ) ) {
304335 const fullPath = path . join ( directory , entry . name ) ;
305336 if ( entry . isDirectory ( ) ) {
306- if ( entry . name !== 'xcuserdata' ) {
307- files . push ( ...collectRunnerSourceFilesInDirectory ( fullPath ) ) ;
337+ if ( ! ignoredDirectoryNames . has ( entry . name ) ) {
338+ files . push ( ...collectRunnerSourceFilesInDirectory ( fullPath , ignoredDirectoryNames ) ) ;
308339 }
309340 } else if ( entry . isFile ( ) && isRunnerSourceFile ( entry . name , fullPath ) ) {
310341 files . push ( fullPath ) ;
0 commit comments