Search code examples
gitnode.jsclonerequirenpm

Should I clone a node library inside node_modules to modify it?


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!


Solution

  • 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.