Skip to content
← Public packages

@kentcdodds/codemod-runner

Run codemods over your own saved packages: scan, dry-run with real publish checks and diffs, apply, and revert.

src/scan-paths.ts

20 lines · 793 B · TypeScript
/** Source-like paths the scan detect pass actually needs to read. */
const scanTextFilePattern =
	/\.(?:[cm]?[jt]s|[jt]sx|json|jsonc|md|mdx|txt|html|css|ya?ml|toml)$/

/** Generated declarations duplicate .ts/.js sources and inflate per-file reads. */
const generatedDeclarationPattern = /\.d\.[cm]?ts$/

/**
 * Scan opens a throwaway session and reads each path via repo_read_file.
 * At ~1s/file with concurrency 8, a 69-file package (e.g. discord plus
 * generated .d.ts) spends the entire ~90s sandbox before detect runs.
 * Detect only sees source text, so skip binaries and generated decls.
 */
export function selectScanPaths(paths: Array<string>): Array<string> {
	return paths.filter(
		(path) =>
			scanTextFilePattern.test(path) &&
			!generatedDeclarationPattern.test(path),
	)
}