Skip to content

Commit 1d9824c

Browse files
authored
Merge pull request #1478 from codeflash-ai/fix-package-json-config-override
Fix package.json config overriding closer pyproject.toml in monorepos
2 parents 6bda49b + fbd3a81 commit 1d9824c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

codeflash/code_utils/config_parser.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,24 @@ def find_conftest_files(test_paths: list[Path]) -> list[Path]:
8888
def parse_config_file(
8989
config_file_path: Path | None = None, override_formatter_check: bool = False
9090
) -> tuple[dict[str, Any], Path]:
91-
# First try package.json for JS/TS projects
9291
package_json_path = find_package_json(config_file_path)
92+
pyproject_toml_path = find_closest_config_file("pyproject.toml") if config_file_path is None else None
93+
94+
# When both config files exist, prefer the one closer to CWD.
95+
# This prevents a parent-directory package.json (e.g., monorepo root)
96+
# from overriding a closer pyproject.toml with [tool.codeflash].
97+
use_package_json = False
9398
if package_json_path:
99+
if pyproject_toml_path is None:
100+
use_package_json = True
101+
else:
102+
# Compare depth: more path parts = closer to CWD = more specific
103+
package_json_depth = len(package_json_path.parent.parts)
104+
pyproject_toml_depth = len(pyproject_toml_path.parent.parts)
105+
use_package_json = package_json_depth >= pyproject_toml_depth
106+
107+
if use_package_json:
108+
assert package_json_path is not None
94109
result = parse_package_json_config(package_json_path)
95110
if result is not None:
96111
config, path = result

0 commit comments

Comments
 (0)