function getChangedFiles
getChangedFiles(
metafile: AffectedMetafile,
esbuildCwd: string,
changedAbsPaths: ReadonlySet<string>,
testFiles: readonly string[]
): Set<string>

Returns the subset of testFiles (absolute paths) whose transitive imports, per the cached esbuild metafile, include any file in changedAbsPaths.

Memoizes "does this node transitively reach a changed file?" across all tests so total work is O(V+E) for the whole call, regardless of how many tests share dependencies. Cycles are handled by tracking the active recursion stack.

Paths in the metafile are relative to esbuildCwd; we resolve them against it so comparisons happen on normalized absolute paths.

const metafile: AffectedMetafile = {
  inputs: {
    'test/a-test.ts': { imports: [{ path: 'lib/util.ts' }] },
    'test/b-test.ts': { imports: [] },
    'lib/util.ts': {},
  },
};

getChangedFiles(metafile, '/proj', new Set(['/proj/lib/util.ts']), [
  '/proj/test/a-test.ts',
  '/proj/test/b-test.ts',
]);
// Set { '/proj/test/a-test.ts' } — only the test that transitively imports the change

Parameters

esbuildCwd: string
changedAbsPaths: ReadonlySet<string>
testFiles: readonly string[]

Return Type

Set<string>

Usage

import { getChangedFiles } from "lib/utils/get-changed-files.ts";