Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from bare git file repo

Tags:

git

npm

git-bare

how can I install an npm module from a bare git repo folder?

So I have a folder that contains a git repo. It was created with git init --bare. Now I want npm to fetch the latest version of the master branch, and there a package.json file is avaliable.

What is the right way to do this?

I tried stuff like:

npm install git+file:///W:/my/git/repo/ -g
npm install git+file:///W:/my/git/repo/#master -g
npm install file:///W:/my/git/repo/ -g --from-git

Is it even possible?

The npm log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'file:///W:/my/git/repo/',
1 verbose cli   '-g',
1 verbose cli   '--from-git' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose cache add [ 'file:///W:/my/git/repo/', null ]
6 verbose cache add name=undefined spec="file:///W:/my/git/repo/" args=["file:///W:/my/git/repo/",null]
7 verbose parsed url { protocol: 'file:',
7 verbose parsed url   slashes: true,
7 verbose parsed url   auth: null,
7 verbose parsed url   host: '',
7 verbose parsed url   port: null,
7 verbose parsed url   hostname: '',
7 verbose parsed url   hash: null,
7 verbose parsed url   search: null,
7 verbose parsed url   query: null,
7 verbose parsed url   pathname: '/W:/my/git/repo/',
7 verbose parsed url   path: '/W:/my/git/repo/',
7 verbose parsed url   href: 'file:///W:/my/git/repo/' }
8 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
9 verbose lock file:///W:/my/git/repo/ C:\Users\myusername\AppData\Roaming\npm-cache\cc42952a--W-my-git-repo.lock
10 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
11 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
12 error addLocal Could not install file:///W:/my/git/repo/
13 error Error: ENOENT, stat 'C:\test\file:\W:\my\git\repo'
14 error If you need help, you may report this *entire* log,
14 error including the npm and node versions, at:
14 error     <http://github.com/npm/npm/issues>
15 error System Windows_NT 6.2.9200
16 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "file:///W:/my/git/repo/" "-g" "--from-git"
17 error cwd C:\test
18 error node -v v0.10.29
19 error npm -v 1.4.14
20 error path C:\test\file:\W:\my\git\repo
21 error code ENOENT
22 error errno 34
23 verbose exit [ 34, true ]
like image 594
Lux Avatar asked Nov 23 '22 16:11

Lux


1 Answers

I have a hacky answer, which might be better than no answer at all. Use Git's URL rewriting feature:

git config --global url.file://.insteadOf git+file://
npm install git+file:///c:\dev\code\mymod

It generates warnings about not being able to fetch remotes, etc., but it installs the module and npm exits with a success code.

This works because the git+ prefix makes NPM pass the whole path to Git, and then the URL rewrite rule turns git+file:// (an invalid Git protocol string) into file:// (a valid Git protocol string).

like image 174
chris Avatar answered Dec 12 '22 22:12

chris