import pathlib
import json


def apply_package_release_id(
    package_file: pathlib.Path, release_id: str
) -> str:
    """
    Apply calculated release id to ``package.json`` file.

    Args:
        package_file: ``package.json`` file to read and modify.
        release_id: release id to apply.

    Returns:
        Package name read from ``package.json`` file.
    """
    with package_file.open(mode="r") as f:
        content = json.load(f)

    content["version"] = release_id

    # write modified json
    with package_file.open(mode="w") as f:
        json.dump(content, f)

    return content["name"]