Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deploy a node.js program with a modified npm package?

Tags:

node.js

npm

I'm using the jsdom package for node.js, but I ran into a problem with it. I fixed it my manually editing the source in /node_modules/jsdom/lib/jsdom/level2/languages on my computer, and it works. However, now I want to publish my program to another server.

What is the best way of handling this modified dependency? In general, how should I go about handling dependencies that are modified from the npm install?

like image 906
Lance Fisher Avatar asked Jul 10 '11 01:07

Lance Fisher


2 Answers

Well, the right thing to do is submit a patch to the maintainer so it can be fixed upstream (long term). In the mean time just keep your modified file around and after you install the main package, rename the original file (mv file.js file.js.ORIG) and then symlink in your copy (ln -s ../../../patches/jsdom/level2/languages/file.js file.js).

That's a quick and dirty option. Another option would be to build a new npm tarball with your modified source and point NPM at that. The npm install command can take a local filesystem path to a .tar.gz archive. That would work as well.

like image 95
Peter Lyons Avatar answered Oct 30 '22 04:10

Peter Lyons


If the fix is already included in the codebase, but not released to npm yet, you can use npm to install a tarball instead of a registered package. Github provides a tarball for each commit, just click downloads.

So for this particular problem with jsdom. You can use the following npm command:

npm install https://github.com/tmpvar/jsdom/tarball/4cf155a1624b3fb54b2eec536a0c060ec1bab4ab

It also works in package.json:

"dependencies" : {
  "jsdom" : "https://github.com/tmpvar/jsdom/tarball/4cf155a1624b3fb54b2eec536a0c060ec1bab4ab"
}

Read more here: https://github.com/tmpvar/jsdom/commit/4cf155a1624b3fb54b2eec536a0c060ec1bab4ab#commitcomment-475293

Thanks tmpvar!

like image 44
Lance Fisher Avatar answered Oct 30 '22 03:10

Lance Fisher