Search code examples
npmbowerbower-installnpm-installtsd

Custom paths for package managers like Nuget/npm/bower/typings


I'm setting up a project in Visual Studio based on AngularJS and Typescript and it's a bit discouraging that I have to deal with yet another package manager as soon as I need to install dependencies.

The issue I have is that package managers require files containing dependencies to be located in a particular place.

Let's take npm for example. I place packages.json at ./SolutionDirectory/MyApp.Web/ But when I run npm install, I just get ENOENT: No such file or directory. because cwd is ./SolutionDirectory

It works fine if I'm doing cd ./SolutionDirectory/MyApp.Web and run npm install after that.

For bower I was able to handle similar issue by just passing additional arguments like:

bower install --config.cwd=./SolutionDirectory/MyApp.Web/app/lib --config.directory=vendor

This command just gets bower.json from ./SolutionDirectory/MyApp.Web/app/lib and installs packages to ./SolutionDirectory/MyApp.Web/app/lib/vendor

  1. Is there a way to have same thing to pass packages.json location to npm before it installs?

  2. Is there a way to pass typings.json location to typings before it installs? to pass target directory location for typings installed?

  3. Is the same doable for Nuget?


Solution

  • For npm:

    npm install <folder>

    <folder> is the path to the folder which contains the package.json file.

    For typings:

    typings install [<name>=]<location>

    <location> is the path to the typings.json

    For NuGet:

    nuget install packageId|pathToPackagesConfig [options]

    pathToPackagesConfig is the path to the packages.config file.

    So, to answer the question, yes it's possible to specify a path to the config file's location for all of these package managers.