HelloWorld
HelloWorld

Reputation: 11247

npm link a local module to a specific branch

I am trying to test a branch of a local module in a separate project.

Normally, I npm link the local module to my dev environment. The module link is always on the master. I'd like to have separate branches and npm link a specific branch of the module in a separate project.

I tried using some syntax in this post such as npm link modlue#nameOfBranch

I know you can install a specific git branch from GitHub based on the npm docs. But ideally, I would like to work on the modules branch, make updates, then have those changes instantly reflected via the npm link in my working project.

Upvotes: 9

Views: 1961

Answers (1)

Arghya Saha
Arghya Saha

Reputation: 5713

If I understand your question correctly then you are already having a project say project_1 which is using another local project say project_2 as a dependency using npm link. Now you are trying to create another new project say project_3 which would be using project_2's different branch as a dependency. You don't want your project_1 from using project_2's master as a dependency.

The best solution can think of is creating another new project which would be the replica of project_2 name it as project_2' and then start working on a different branch and use npm link to use it as dev dependency. So whenever you update it locally you can find the changes without having to update it.

You cannot work with the same project_2 because once you check out the branch then git changes at the file system level. No two projects can work with different branches.

Upvotes: 7

Related Questions