Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs tools for VS2015 with local dependencies

I'm trying to build a node js project with NodeJS tools for VS2015.

In this solution, there is a main project that has sub-projects in sub folders, i.e. each sub-folder has their own package.json with its own code and each one declares their own dependencies to other projects.

The problem I have is that when I do "npm install" in the main project, "npm" downloads the packages from npm registry.

I know that could use:

"dependencies": {
    "common": "file:path/to/common",
}

But this approach forces me to manually maintain two package.json files and rename it on every commit (the project is open source, on github); It is cumbersome and error prone.

My question is: Can I configure the NodeJS tools for VS to handle two different configurations for debug and release? i.e. In a similar way that I can do it in a C# project.

Something like using a package.Debug.json file... any other approach is welcome.

like image 241
rnrneverdies Avatar asked Jan 20 '16 19:01

rnrneverdies


1 Answers

To do it, you can use npm-link for create a link between the package and its source code (This post about that is very interesting: npm link: developing your own npm modules without tears)

In your case:

  • Execute npm link for each subproject
  • In main project, execute npm link subproject1 ... npm link subprojectN

I have tested it with Visual Studio 2015 creating a solution with two projects

nodejs-projectdeps
|- nodejs-projectdeps-main
|- nodejs-projectdeps-module1

package.json for nodejs-projectdeps-main

{
  "name": "nodejs-projectdeps-main",
  "version": "0.0.0",
  "description": "nodejs-projectdeps-main",
  "main": "app.js",
  "dependencies": {
    "azure": "^0.10.6",
    "nodejs-projectdeps-module1": "0.0.0"
  }
} 

package.json for nodejs-projectdeps-module1

{
  "name": "nodejs-projectdeps-module1",
  "version": "0.0.0",
  "description": "nodejs-projectdeps-module1",
  "main": "app.js",
  "dependencies": {
    "dockerctl": "0.0.0"
  }
}

Then I executed npm link in the nodejs-projectdeps-module1 project folder and the result was:

C:\Users\...\npm\node_modules\nodejs-projectdeps-module1 
  -> C:\src\nodejs-projectdeps\nodejs-projectdeps-module1

After I executed npm link in the nodejs-projectdeps-module1 project folder and the result was:

C:\src\nodejs-projectdeps-main\node_modules\nodejs-projectdeps-module1 
  -> C:\Users\...\npm\node_modules\nodejs-projectdeps-module1 
    -> C:\src\nodejs-projectdeps\nodejs-projectdeps-module1

After all, the solution in Visual Studio 2015 shows the dependencies in this way:

Visual Studio NodeJs Solution

Update: The source of my test code is published on GitHub

like image 195
rsciriano Avatar answered Sep 18 '22 15:09

rsciriano