66// used to tell new code from pre-existing code
77
88import { execFileSync } from "node:child_process" ;
9- import { existsSync } from "node:fs" ;
9+ import { existsSync , statSync } from "node:fs" ;
1010import { join } from "node:path" ;
1111import { repoRoot , sections } from "../validate-examples.mjs" ;
1212
@@ -31,14 +31,20 @@ export function changedDirs(base, head) {
3131
3232 const seen = new Map ( ) ;
3333 for ( const file of names ) {
34- const [ section , name ] = file . split ( "/" ) ;
34+ const parts = file . split ( "/" ) ;
35+ // Only files inside an entry folder count: examples/<name>/... . A file
36+ // sitting directly under examples/ (its README) is not an entry.
37+ if ( parts . length < 3 ) continue ;
38+ const [ section , name ] = parts ;
3539 if ( ! section || ! name || ! sectionDirs . includes ( section ) ) continue ;
3640 if ( name . startsWith ( "_" ) || name . startsWith ( "." ) ) continue ;
3741 const path = `${ section } /${ name } ` ;
3842 if ( seen . has ( path ) ) continue ;
3943 // Skip folders deleted in this range. Check the working tree first (CI
4044 // checks out the PR head) and fall back to the head commit for local runs.
41- if ( ! existsSync ( join ( repoRoot , path ) ) && ! existsAt ( head || "HEAD" , path ) ) continue ;
45+ const abs = join ( repoRoot , path ) ;
46+ const inTree = existsSync ( abs ) && statSync ( abs ) . isDirectory ( ) ;
47+ if ( ! inTree && ! existsAt ( head || "HEAD" , path ) ) continue ;
4248 seen . set ( path , { path, section, name, status : existedAt ( base || "origin/main" , head || "HEAD" , path ) ? "modified" : "added" } ) ;
4349 }
4450 return [ ...seen . values ( ) ] ;
0 commit comments