Context
I’ve been trying to learn Effect-TS by working on a little http-client for the spotify api. It ain’t much yet, but one of the goals in this project was learning how to publish an npm package.
Quite happy with the workflow so far.
Now, onto how it’s done. These are the main tools I used:
- Github Actions
- tsup: for bundling the typescript
- Changesets
Changesets
This tool does a lot of the publishing heavylifting.
- Maintaining the changelog
- Publishing to npm after merging into main and providing a changeset
- Coupled with github actions to automate the process
Permissions (npm & repo)
- You need to create a token on npmjs.org
- Add that token to your repo’s environment variables. Mine’s named
NPM_TOKEN
- Add the changeset bot to your repo
- Navigate to
Repo settings > Actions > General > Workflow permissions
and allow read and write permissions, and also allow github actions to create and approve pull requests
Challenges I faced
I had the release workflow running, but it wasn’t publishing the package to npm.
Running changeset publish
was givinig me the following output
🦋 warn No unpublished projects to publish
Ultimately, I made these changes and things resolved themselves:
spotify-effect/package.json
- "private": "false",
+ "publishConfig": {
+ "access": "public"
+ },
spotify-effect/.changeset/config.json
- "access": "restricted",
+ "access": "public",
Learning Resources
- Matt Pocock was a big help
- Changeset Release Action
- Tobias Davis' “Adding Changesets to Your GitHub Repository”
- Web Dev Simplified’s video
- Github’s Publishing Node.js packages was pretty helpful too