from pathlib import Path
from typing import Set


def find_source_files(
    path: Path,
    extensions: Set[str] = {".ts", ".tsx", ".py"},
    skip_folders: Set[str] = {
        "tests",
        "test",
        "node_modules",
        "lib",
        ".git",
        ".ipynb_checkpoints",
    },
):
    """
    Find source files in given `path`.

    Args:
        path: Path to introspect
        extensions: Set of extensions to list
        skip_folders: Set of folders to ignore

    Returns
        List of files found
    """
    all_files = []
    for ext in extensions:
        for f in path.rglob(f"*{ext}"):
            parents = set(map(lambda p: p.name, f.parents))
            if len(parents.intersection(skip_folders)) > 0:
                continue

            all_files.append(f)

    return all_files