Publish Library to npm
In this lesson, you will publish your streak-counter on npm as a package.
Resources
The following resources provide more information for this lesson:
- [pnpm publish docs](https://pnpm.io/cli/publish)
- [npm publish docs](https://docs.npmjs.com/cli/v9/commands/npm-publish?v=true)
- NPM Publish GitHub Action
- [@jsjoeio/streak-counter-2 on npm](https://www.npmjs.com/package/@jsjoeio/streak-counter-2)
- [publish.yaml](<https://github.com/typescript-course/typescript-from-scratch-tutorial/blob/8d18ccecefd875e3c65ef4c9bfa75f7243aad5bd/.github/workflows/publish.yaml>) GitHub workflow
Transcript
[0:00] [0: 00] After you create an npm account, go into Access Tokens and create a new token. For the token, select Automation, and then click Generate Token.
[0:08] [0: 08] Once you have your token, go to your GitHub repo settings, and go to Secrets, Actions. Create a New repository secret, and we'll call this NPM_TOKEN. Paste in your secret. We'll create a new file called .github/workflows/publish.yaml. Paste this in.
[0:28] [0: 28] The main thing I want to point out is we're adding a working directory to this job. We're adding the working directory because that's where we're working from. That way, we don't have to add it to every run step here.
[0:39] [0: 39] We're using an action to publish that corresponds to our environment secret or pointing to our package.json. We're setting access to public since it's a scoped package. Commit that, push it up.
[0:51] [0: 51] Now to GitHub, you should see a beautiful green checkmark, meaning everything was successful. Finally, if you head to npm, you'll see that it was successfully published.