Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm link a local module to a specific branch

Tags:

git

npm

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.

like image 220
HelloWorld Avatar asked Oct 12 '18 18:10

HelloWorld


People also ask

How do I link a local npm module?

Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.

Is npm install branch specific?

The npm installation from GitHub is quite useful for testing packages. It also gives the flexibility to install any specific branch, version, tag, and so on.


1 Answers

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.

like image 127
argo Avatar answered Sep 26 '22 08:09

argo