DEV Community

Christian Duarte
Christian Duarte

Posted on

Lab 9 - NPM Release

Package and Registry...

For this weeks lab, I had to release my CLI tool to an official registry. For this I chose NPM. As well, I had to tag my release on GitHub as well as the registry.

The information I used in helping figure out how to do so can be found below.

NPM Docs

https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry
https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages
https://docs.npmjs.com/creating-node-js-modules

Articles

https://hackernoon.com/publishing-a-nodejs-cli-tool-to-npm-in-less-than-15-minutes

Bun Docs

https://bun.sh/docs/cli/publish

Git Tags

https://git-scm.com/book/en/v2/Git-Basics-Tagging

Errors with build command

GitHub Copilot. Used it for helping solve an error when I built my program. My error was that my index.ts converted to index.js was not present in my dist/ folder. This was because I had an issue with my tsConfig file. I could not find the fix online, but Copilot helped me find my importing error.

Process...

The process for this release was as follows:

  • Researched the registry I was going to upload to. Bun has a publish command, but it is not in effect yet so I had to convert to node project and build it that way.
  • Setup my package.json. Set up my package.json file to include the dist/ directory and the command to be used by my CLI tool once published as well as the version and description.
  • Reconfigured my project. Moved around some files and imports to allow for the project to be run as an NPM module. Without this I could not properly build the project to a js equivalent and publish it.
  • Ran the build script. Used bun run build to build the project to a js app from my ts files.
  • Made an npm account. Made an account with https://www.npmjs.com .
  • Signed in through terminal. Used npm login to sign in, and followed the instructions.
  • Ran the publish command. Used npm publish to submit to the registry.
  • Setup git tags. Set the git tags for my release version matching the npm registry version.
  • Saved changes. Saved, committed, and pushed my changes as well as the git tags and checked my actions to ensure all tests passed on remote.

Aha! or Stuck?...

Working on this lab I didn't have any aha moments, other than maybe being excited that I was able to actually push my module to the npm registry. My stuck moment was definitely trying to figure out why the build was working but no files were present in the dist/ folder.

Altered Code...

Overall I didn't have to alter that much code besides now rnning my program from init() outside of the commant.ts file. My init() runs through the test file or the index.ts/js file and calls the command.ts. I did have to restructure a bit, having to move my index.ts file into the src directory for my publish and build to function properly. I ensured that my program works through the NPM install and through the git repo locally while I was making changes, as well as making sure my tests never broke.

User Testing...

With user testing, we weren't able to come to any bugs that were code errors that I or contributors created. The only errors that occurred were from my friend's computer not having correct permissions on his system to run scripts, and hadn't installed Bun due to it being missing from my README steps. There were a bit of steps that I was missing in my README.md that I tried to not hint or influence how to fix at first. I was able to help and took notes of what went wrong though and those issues are now outlined as steps in my README.md. Everything that contributed to lack of understanding has now been updated in my README, but I always am open to feedback if further explanation is needed. If my friend finds any bugs in the future I'm sure he will let me know, the only thing we encountered however was that sometimes if he gave the tool 2 of the same file contents but with different file names, the syntax for markdown would be very off and incorrect, as well as displaying the second duplicate file name wrong. This is something I will have to work on with my prompt engineering, and I think that seeing this happen to users will help me tweak my prompts ever so slightly to be better for these use cases.

Installing...

Now that my project has been released as an NPM module, users can install it with the

npm install -g f2read

command. In order for the project to work though, users must follow the steps outlined in my README.md located here.

Top comments (0)