How can I commit changes that I've made in nod

2019-07-10 02:33发布

Sometimes it's easier to maintain a fork of a node package for your module, I'd like to be able to edit a module that's in node_modues that I've installed via npm install githubaccount/myrepo.git.

Currently any changed that I made to a file I have to copy back to the repo. This is tedious.

How can I edit modules in npm and have them tracked by Git?

Python's pip has an option where you can define an 'egg' which symlinks a clone of the repo to the site_packages folder. I know it's a different system, but I've found it really quite useful in the past.

标签: node.js git npm
1条回答
别忘想泡老子
2楼-- · 2019-07-10 03:33

You can use the npm link command to do this. Here's how to use that. Let's assume that your npm module is located in ~/npm-module and your project using the npm module is in ~/my-project.

cd ~

# First clone the npm module
git clone https://..../npm-module.git

# Go into the module's directory:
cd npm-module

# Link the module
npm link

# CD into the project using the npm module
cd ../my-project

# Link the module
npm link npm-module

The first call to npm link will create a link in npm's cache directory pointing to your local clone of the npm-module. The second call will link it into the project that's using the module (into the node_modules folder).

If you take a look at your project's node_modules folder, you will see that it now contains a symbolic link to the npm-module's sources. Any changes you make in that folder will also be in the cloned project. You can commit changes there and push them back to your remote.

This is similar to what you do with Python's egg feature.

Here's the npm link documentation.

查看更多
登录 后发表回答