forking a compiled npm package

pnpm allows you to install packages straight from github, but if the package has a build step (e.g. typescript compilation) it’ll likely be missing the js that you would be running. there doesn’t seem to be a standard way to set a project up so that the build step only runs if it needs to, so many projects don’t include a prepare script to run the build.

so a workaround i ended up with is to build it locally, compile a tarball, publish italso probably works to copy the tarball into your project repo and do a local install from a relative path and skip the publish step, and install it. here’s the steps:

  1. push your fork up to github
  2. run the build step locally
  3. create a tarball of the package with pnpm pack
  4. create a github release, gh release create
  5. upload the tarball to the github release, copy the url, it’ll look something like https://github.com/$owner/$repo/releases/download/$tag/$package.tgz
  6. switch to the project where you want to install the fork, and run pnpm add $tarball_url

i found that i also had to setup some pnpm overrides to deal with workspace:* dependencies that were giving me trouble.

© 2024 peter schilling