Ad

Should I Clone A Node Library Inside Node_modules To Modify It?

- 1 answer

I'm using Poet for a blogging/static site generator engine and it's great.

It is currently a dependency listed in my packages.json, so I simply npm install it and require it in my express app.

However, I'd like to change one behavior in the library (especifically the way a "post.preview" is constructed, which right now simply gets the first line, and I'd like to perhaps be able to configure a number of lines for each post).

To do that, I'm considering cloning the repo and making the change.

But I'm wondering if I should:

  • Clone it directly to my blog/node_modules/poet and require it as usual or,
  • Clone it to a different folder and require it from a different path.

Keep in mind that I'd like to publish soon to Heroku or Nodejitsu.

What are your thoughts on that?

UPDATE: I had a few problems having a git repo with the cloned lib under my git repo. It somehow added the whole folder as a file. I promptly removed '.git' from the lib folder and everything went back to normal... I don't know the cause of this behavior!

Ad

Answer

IMHO, a good practice is to clone and keep this repository into the folder /lib. Once you feel you are done with your changes, push them into your version, and make the right references to your copy in the package.json file.

Now, if you think your changes could be introduced into the module, make the pull request.

My two cents.

Ad
source: stackoverflow.com
Ad