Running npm installation only if necessary and / or partially

We call Gulp from our csproj , since we are using Visual Studio 2013 for this project:

 <Target Name="AfterBuild"> <Exec Command="gulp" /> </Target> 

However, since we are still developing this new project, we often extend gulpfile.js to include new packages. The developer will do, for example. npm install gulp-util --save-dev and write a new task, and all is well.

Then the developer checks gulpfile.js and packages.json for our VCS. Currently:

  • Teamcity has an extra build step of npm install ;
  • Each developer must run npm install manually;

To remember what needs to be done manually is not a great place. At some point, we had it in our csproj file inside Task ...

  <Exec command="npm install" /> 

... immediately before gulp exec, so the developers couldn’t forget to complete this manual step. However, this may take one or even several seconds for each assembly (re), which is annoying.

Is there a better way to solve this problem? How do you handle packages.json updates in projects where large (ish) teams are developed using Visual Studio?

+6
source share
3 answers

Unfortunately, there is no way to install only new packages in npm, but you can try to reduce the time spent at this point with tools such as npm-fast-install or npm_lazy .

+2
source

npm-install-missing combines npm outdated and npm install to install all missing dependencies in the dependency tree.

You can add it to your project as follows:

 <Target Name="AfterBuild"> <Exec command="npm-install-missing" /> <Exec Command="gulp" /> </Target> 
0
source

The approach that works for me is to use MSBuild incremental build support in combination with the stamp file:

 <PropertyGroup> <!-- File with mtime of last successful npm install --> <NpmInstallStampFile>node_modules/.install-stamp</NpmInstallStampFile> </PropertyGroup> <Target Name="NpmInstall" BeforeTargets="BeforeBuild" Inputs="package.json" Outputs="$(NpmInstallStampFile)"> <Exec Command="npm install" /> <Touch Files="$(NpmInstallStampFile)" AlwaysCreate="true" /> </Target> 

NpmInstall Target only works when package.json newer than node_modules/.install-stamp , and it affects this file after a successful npm install . This npm install method runs only once after every change to package.json .

0
source

All Articles