For tools in the npm ecosystem, the prepack
script is a useful opportunity to modify the package immediately before publication.
Unfortunately, it is not safe to modify package.json itself as part of the prepack script. Doing so will result in subtly broken packages.
This is true for all npm-compatible tools that I know of, including npm and yarn.