@@ -5,6 +5,7 @@ import os from 'node:os';
55import path from 'node:path' ;
66import { eagerClosureGraphOf } from '../../src/__tests__/eager-import-closure.fixtures.ts' ;
77import {
8+ baseProductionPathOf ,
89 createCommittedSourceTree ,
910 headCommit ,
1011 mergeBaseWithMain ,
@@ -378,6 +379,8 @@ function mkGitFixtureRepo(prefix: string): string {
378379 fs . writeFileSync ( path . join ( pkgDir , 'src/facades/top.ts' ) , 'export const b = 2;\n' ) ;
379380 fs . writeFileSync ( path . join ( pkgDir , 'src/facades/nested/deep.ts' ) , 'export const c = 3;\n' ) ;
380381 fs . writeFileSync ( path . join ( pkgDir , 'src/facades/skip.test.ts' ) , 'export const d = 4;\n' ) ;
382+ fs . mkdirSync ( path . join ( repo , 'scripts' ) ) ;
383+ fs . writeFileSync ( path . join ( repo , 'scripts/standalone.ts' ) , 'export const outside = 1;\n' ) ;
381384 execFileSync ( 'git' , [ 'init' , '-q' ] , { cwd : repo } ) ;
382385 execFileSync ( 'git' , [ 'add' , '.' ] , { cwd : repo } ) ;
383386 execFileSync (
@@ -409,9 +412,32 @@ test('a renamed entry is followed to its path at the base, not treated as first-
409412 execFileSync ( 'git' , [ 'mv' , 'packages/demo/src/entry.ts' , 'packages/demo/src/moved.ts' ] , {
410413 cwd : repo ,
411414 } ) ;
412- expect ( renamedSince ( repo , 'HEAD' ) . get ( 'packages/demo/src/moved.ts' ) ) . toBe (
415+ const renamed = renamedSince ( repo , 'HEAD' ) ;
416+ const baseTree = createCommittedSourceTree ( repo , 'HEAD' ) ;
417+ expect ( renamed . get ( 'packages/demo/src/moved.ts' ) ) . toBe ( 'packages/demo/src/entry.ts' ) ;
418+ expect ( baseProductionPathOf ( repo , 'packages/demo/src/moved.ts' , baseTree , renamed ) ) . toBe (
413419 'packages/demo/src/entry.ts' ,
414420 ) ;
421+ execFileSync (
422+ 'git' ,
423+ [ 'mv' , 'packages/demo/src/facades/skip.test.ts' , 'packages/demo/src/fixture.ts' ] ,
424+ { cwd : repo } ,
425+ ) ;
426+ const withFixtureRename = renamedSince ( repo , 'HEAD' ) ;
427+ expect ( withFixtureRename . get ( 'packages/demo/src/fixture.ts' ) ) . toBe (
428+ 'packages/demo/src/facades/skip.test.ts' ,
429+ ) ;
430+ expect (
431+ baseProductionPathOf ( repo , 'packages/demo/src/fixture.ts' , baseTree , withFixtureRename ) ,
432+ ) . toBe ( null ) ;
433+ execFileSync ( 'git' , [ 'mv' , 'scripts/standalone.ts' , 'packages/demo/src/standalone.ts' ] , {
434+ cwd : repo ,
435+ } ) ;
436+ const withOutsideRename = renamedSince ( repo , 'HEAD' ) ;
437+ expect ( withOutsideRename . get ( 'packages/demo/src/standalone.ts' ) ) . toBe ( 'scripts/standalone.ts' ) ;
438+ expect (
439+ baseProductionPathOf ( repo , 'packages/demo/src/standalone.ts' , baseTree , withOutsideRename ) ,
440+ ) . toBe ( null ) ;
415441} ) ;
416442
417443test ( 'discovery is recursive and reads TRACKED files only' , ( ) => {
@@ -520,10 +546,9 @@ const baseTree = createCommittedSourceTree(repoRoot, mergeBase);
520546const renamedFrom = renamedSince ( repoRoot , mergeBase ) ;
521547const entries = eagerClosureEntries ( repoRoot ) ;
522548
523- /** The entry's path in the merge-base tree (renames followed), or null when it was not there . */
549+ /** The entry's readable source path in the merge-base tree, if it had one . */
524550function basePathOf ( entryFile : string ) : string | null {
525- const file = renamedFrom . get ( entryFile ) ?? entryFile ;
526- return baseTree . isFile ( absolute ( file ) ) ? file : null ;
551+ return baseProductionPathOf ( repoRoot , entryFile , baseTree , renamedFrom ) ;
527552}
528553
529554const baseGraphs = new Map < string , ReadonlyMap < string , string | null > > ( ) ;
0 commit comments