Rules Changes on Branch Pipeline: Work differently on first push

I am developing a CI/CD pipeline for a node application. To utilize the benefits of caching, I run a .pre stage job that updates the cache if there is any change in the package.json or package-lock.json file. The rules part of that job is

    - if: '$CI_COMMIT_BRANCH'
        - package.json
        - package-lock.json

This works well for me except for one case. The job runs always runs at the first commit of every branch pipeline. This is undesirable (but expected according to the documentation) since it also runs when there is no change to the package.json file How can I modify the rules such that this is not the case? I have tried rules:changes:compares_to with the main branch but that results in the stage rerunning on every branch commit if there’s a change in the file from the main branch.

I don’t think there is a simply way around it.