2

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?

Alexander Efimov
  • 2,685
  • 3
  • 18
  • 22

2 Answers2

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

No, there isn't. Currently there is no way to overwrite cwd value in npm. You should move directory and run it:

`$ cd SolutionDirectory/MyApp.Web/ && npm install`

Here is the similar discussion to this: https://github.com/npm/npm/pull/10958

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

Technically yes, but I guess you'd like to just do typings install with typings.json. How about to put typings.json to the same path with package.json and use npm lifecycle script?

$ ls
package.json typings.json
$ cat package.json
{
  "name": "name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "postinstall": "typings install"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typings": "^0.7.12"
  }
}
$ npm install
=> after npm install, typings install will start with typings.json
  1. Is the same doable for Nuget?

Nuget is also package manager, so it should has similar features, like nuget mirror command can be npm config set registry and nuget locales can be npm cache I guess. Technically it's a different software, but I think understanding about both softwares is good way to know the concept and summary of each others.

1

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.

sc3w
  • 1,154
  • 9
  • 21
  • Hmm...Tried that npm command and it didn't work neither reltive nor absolute path. However I get another error now. My package.json looks as following: { "name": "myapp", "version": "1.0.0", "description": "", "devDependencies": { "gulp": "3.9.0", "gulp-sass": "latest", "gulp-watch": "4.3.5" } } and the error is: npm : npm WARN install Couldn't install optional dependency: Unsupported At line:1 char:1 – Alexander Efimov Apr 25 '16 at 15:04
  • reference: https://docs.npmjs.com/cli/install, https://github.com/typings/typings/blob/master/docs/commands.md, https://docs.nuget.org/consume/command-line-reference – sc3w Apr 25 '16 at 15:07
  • @AlexanderEfimov seems like this is a known issue, here you might find some suggestions on how to solve it: https://github.com/npm/npm/issues/9204 – sc3w Apr 25 '16 at 15:28