commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

Allow package.json to be located in subdirectories by processing paths

Open MaxiGalaxi opened this issue 9 months ago • 6 comments

Description

Enable the NpmProvider to locate and process package.json files that are not in the root directory by correctly handling and resolving paths from the project root.

Possible Solution

npm_provider.py:

@property
def package_file(self) -> Path:
    package_path = next(
        (Path(p) for p in self.config.settings["version_files"] if p.endswith("package.json")),
        None
    )
    if package_path is None:
        raise FileNotFoundError("No package.json found in version_files")
    return package_path

Additional context

No response

Additional context

No response

MaxiGalaxi avatar Apr 01 '25 11:04 MaxiGalaxi

The possible solution LGTM. @woile @Lee-W wdyt?

bearomorphism avatar Dec 03 '25 14:12 bearomorphism

What about the --config parameter?

woile avatar Dec 03 '25 18:12 woile

Then user needs to type --config every time they run cz (iirc there is no corresponding configuration file option for --config)

I think that is bad user experience.

bearomorphism avatar Dec 04 '25 02:12 bearomorphism

Not a JS developer. Is it a common practice in JS? If so, we should include it. If not, I think the user should customize the provider or we should allow it to be config through config file

Lee-W avatar Dec 04 '25 03:12 Lee-W

iirc most of the time package.json is located at project root, but there may be exceptions

can't the problem be solved by just specifying version_files?

bearomorphism avatar Dec 04 '25 03:12 bearomorphism

Is it a common practice in JS?

The same chances of finding a pyproject.toml in a different folder. Which IMO, would be in monorepos:

root-project/
├── project-a/
│   └── package.json
└── project-b/
    └── pyproject.toml

Then user needs to type --config every time they run cz (iirc there is no corresponding configuration file option for --config)

My expectation is for users to run cz bump in the CI, not so much locally, the other commands shouldn't be affected by this. That being said, --config would be part of the solution in this case. I think the solution is actually moving .cz.toml to the project where the package.json is and then using cz bump --config project/.cz.toml or cd project; cz bump.

The proposed solution doesn't cover the presence of N+1 package.json files, and increases complexity, how would we handle more than 1? Instead, for monorepos, we are using a cz.toml per sub-project.

woile avatar Dec 04 '25 07:12 woile