hsiaoairplane
hsiaoairplane

Reputation: 511

npm install private git repository with .git folder and .gitignore file

I am using npm to download a private git repository with npm install command. However, the downloaded repository does not contain a .git folder or a .gitignore file. Is there any way that I can solve this problem?

Upvotes: 1

Views: 618

Answers (2)

hsiaoairplane
hsiaoairplane

Reputation: 511

I found the way to generate .git folder and .gitignore via git command. I write the script in postinstall field of package.json. Here is my example of package.json.

...
"dependencies": {
    "test": "git+ssh://[email protected]/repo.git"
},
"scripts": {
    "start": "npm config set tmp `pwd`",
    "postinstall": "cd node_module/repo && mv .npmignore .gitignore && git clone --no-checkout repo && mv repo/.git/ .git/ && git read-tree --reset HEAD && rm -r repo"
}
...

Then first I run npm start to setup npm tmp config, then I run npm install to generate .git folder and .gitignore file back.

However, I encounter another problem that the content of downloaded package.json will change with add more content like "_id", "_resolved", "_from", etc. Not knowing how to solve this problem now.

Upvotes: 0

aadarshsg
aadarshsg

Reputation: 2089

npm install does not install git files.

Upvotes: 1

Related Questions