Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow subdirectories within git repos in npm install #2974

Open
SLaks opened this Issue · 22 comments
@SLaks

I would like to be able to run npm install for a package.json file in a subdirectory of a git repo.

This would be useful for projects that use releases systems (such as nzakas/parserlib), and for git repos that contain multiple npm packages .

Can this be added?

@SLaks SLaks referenced this issue in CSSLint/parser-lib
Closed

Release only timestamp #45

@guybrush

cd subdirectory && npm install :D

@strk

Same problem I have with https://github.com/nmrugg/LZMA-JS - the actual module (package.json) is in a src/ subdirectory, but I don't find a way to reference that subdir from the package.json of a module that depends on it.
Is that possible ? (can't script a cd && npm install in package.json, can I?)

@guybrush

you could try something like {"scripts":{"install":"cd src && npm install"}} in your package.json.

but that is just not how its meant to be done

but I don't find a way to reference that subdir from the package.json of a module that depends on it

when your module depends on another module that other module will be installed in node_modules/<module-name> and in that directory there will be its package.json. thats not only how npm does it - thats how the node-modules work, see http://nodejs.org/api/modules.html#modules_all_together

so i am pretty sure, the way how it works now will not change (its set in stone)

@isaacs
Owner

@SLaks There's no plans to do this. If npm installs a git repo, it assumes that the git repo is the package. I don't really know how we could specify a sub-path easily, since all parts of the git url are already used for other things. For example, git://x.com/path/to/whatever#some-branch. Where would you put the subpath in there, such that it can be deterministically differentiated from the path to the repo in all cases? I don't see any way to do it without resorting to some awful hacks.

How would you express this?

@strk
@djMax

+1 for this use case. For me, it's about including tests from other components (Java components). We use mocha to test these things, and service A wants to import service B's tests but we can't use npm because it doesn't have the concept of branches. Since the tests will be against some branch of service A, AND because the tests are part of the service rather than their own repo, we would benefit from subtree installs in GIT. Maybe another argument like --nodedir?

@secrettriangle

This would be great. I'm using highlight.js which stores its source, including package.json, in src/.

@bitdivine

This would indeed be great. As it is I will have to make a whole bunch of dummy projects. I hope that I can simply have each main project as a git submodule and put a link called package.json to the real package.json. That might break though...

@lukaslehmann

any news on that? or is there a workaround for that case?

@adrai

+1

@gaboom

+1 Unfortunately not all npm git repos can store their contained npm module in their root's!

git://user@example.com/path/to/resource//path/to/directory#commit-ref

@SLaks

@gaboom: That's actually a breaking change, in the (admittedly unlikely) case of // appearing in a git URL path.

@gaboom

Hmm,
git://user@example.com/path/to/resource/[path/to/directory]#commit-ref
brackets are only legal as IPv6 literal hostnames, needs to be escaped otherwise.

@fwestrom

I could definitely use this feature too.

We have a Git repository with several of our product's subsystems, and I want to be able to use npm to install individual micro-services as packages from their subdirectories (services/{package-name}/package.json).

@banks

Another +1, I agree URL syntax is ugly but apache/thrift is a good example of a nodejs project embedded in a bigger repo and trying to work with a non-tagged release is made very hard without this feature.

@AnmAtAnm

Another +1.

@nevcos

Another +1. Need to import other module that's not in the root and don't want to create a specific project for that module.

@lukaslehmann

Another +1

@charliezhang

strongly +1

@bttf

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.