DutchKev DutchKev - 15 days ago 5x
Git Question

NPM - Fork module, change code and send PR to author

For a particular npm package I want to create a PR with some code changes.. The author of the package told me, to create a PR from a particular branch..

All fine so far, I can change the url + branch inside the package.json and load the specific branch as npm module.. Also npm install works fine.

But then I want to change some code in that node_modules/module folder and create a PR from the code changes..

The only thing I can make to work for sure, is to first fork the entire repo in a separate folder, than checkout X branch, than change code, copy/past it to the node_modules/module folder every time I wanna check my code changes.. And than push it to my personal github page, and from there create a pull request..

But its really frustrating to copy/past my changes every time to the node_modules/module folder.

What is the best way to change a npm package and create PR for it, while still keeping the code inside the node_modules folder, so code changes can be checked?



You're looking for npm link:

$ git clone your/npm-repo-fork
$ cd npm-repo-fork

# Link the project as a local dependency
$ npm link
$ cd ../some/other/project

# Use the linked project
$ npm link name-of-npm-dependency

# Now you can edit npm-repo-fork and the changes
# will be picked up by some/other/project
$ cd ../../../npm-repo-fork