The need to extend an npm package

The need to extend an npm package

Situation

So, I’ve written a simple Math library and distributed it as an npm package. For testing purposes, jasmine-node is used.

However, when it came to testing my logarithm functions, the supported methods didn’t totally fit my case. Specifically, I wanted to use to test that a log(0) equals to negative infinity. Having already used similar methods of the library, such as toBeNaN(), I was expecting that a similar method (i.e. toBeNegativeInfinity() ) would also exist.

Nonetheless, it didn’t and of course one could easily argue “why not working around it, like toEqual(-Infinity) ?”, but then, what is the point of having methods like toBeNaN()? We could also work around this with toBeEqual(NaN).

Solution

So, I decided to extend it a bit, because I didn’t want to wait  math.js already had a dependency on jasmine-node package, so, I had to provide my own (extended) version of jasmine-node. How could I do this?

  1. Fork jasmine-node
  2. Clone the forked repo locally
  3. Extend the library to my liking
  4. Distribute a new npm package out of the extended library (1)
  5. Replace jasmine-node dependency with jasmine-node-xt (2)
  6. Use the desired method as initially

Declarations

(0) : Following the concept of also extending the library I used, instead of just providing a PR and wait whether it will be accepted or not, I saved time from something that might never happen in the future from my side; on the other hand, I gained knowledge on an area I am not so experienced, so, even if the submitted PR is not gonna be accepted, I learned something new!
(1) : Required changes in package.json; here you also have to keep in mind the provided license from the original library – it might affect the way you wanna distribute your extended version of that library
(2) : First uninstall jasmine-node : npm uninstall –save-dev jasmine-node and then install our version: npm install –save-dev jasmine-node-xt

Easily change the remote upstream from a cloned repo

Easily change the remote upstream from a cloned repo

Situation

So, I was about to create the is-java-keyword package.

Common things, new project, etc., but thank God, I could already use my npm-boilerplate to create the skeleton and stuff.

So, I clone the project and started making the required code changes.
Once done, I had to commit, so git status was the command, but it also returned the following lines, which made my a bit skeptical, in terms of what I was doing:

“Oh, wait a sec., of course it’s gonna be pushing to the repo I cloned from”. On the other hand, I was too lazy to search for the command of amending the remote git repository of my local repo.
“Hold on, it shouldn’t be that difficult to do it manually. Check into ./git directory”:

Solved!

Closing Quote

Only by experimenting you get to know life better.