Local dependencies using the tools for NodeJS in VS2015

2

I'm trying to compile a project from nodejs, with VS2015.

The main project has sub projects in sub folders, that is to say that in each sub-folder there is a package.json with its own code and each one declares the dependencies to the other projects.

The problem I have is that when I try to run any example of the main project, instead of using the sub-folders packages, it downloads all the packages from npm registry .

My question is: How can I configure visual studio to use the code of the sub-projects without downloading the packages from the internet?

    
asked by rnrneverdies 20.01.2016 в 15:47
source

2 answers

1

The functionality you're looking for is provided by npm-link that allows you to establish a symbolic link to the source code of a package and so you can debug without going crazy. (This article in English is very interesting: npm link: developing your own npm modules without tears )

The way to use it in your case would be the following:

  • In each of the subprojects you execute npm link
  • In the main project npm link subproyecto1 ... npm link subproyectoN

I've done a test with Visual Studio 2015 creating a solution with two projects

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

package.json file of 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 file of 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 have executed npm link in the project portfolio nodejs-projectdeps-module1 with the following result:

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

Then I have executed npm link nodejs-projectdeps-module1 in the project folder nodejs-projectdeps-main and the result has been:

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

This is how the solution is in Visual Studio 2015 showing the dependencies between packages:

Update : The source code of the tests I have done is published in GitHub

    
answered by 19.02.2016 / 20:15
source
0

You can specify in your file package.json the dependency to a local repository instead of specifying the version.

For example:

{
    ...
    "dependencies": {
        "bar": "file:ruta/a/tu/proyecto"
    }
}

More information at: package.json - Local Paths

    
answered by 20.01.2016 в 16:17