Keeping track of node_modules with npm shinkwrap and git - node.js

I'm on a node project with a launcher and several homemade plugins. Those plugins are marked as dependencies in the launcher package.json with the git repo adress.
I recently tried npm shrinkwrap which perfectly give me the commit used for each of my plugins but any dev on plugins will break this. I trid to use npm link for my git repo, but they aren't tracked by shrinkwrap anymore.
So basically, how can I have cloned repo for my plugins where I can work and a way to get a snapshot of my dependencies at a precise moment?
Thank you for any lead you could give me.

Related

Ignore a specific package while installing dependencies using 'npm install'

I have a node package react-native-push-notification for which i have made some changes in the packages to fulfil my requirement. But every time i do a npm install the new (original package without my changes) package overlaps with my current package.
Is there any way i can restrict npm install to ignore my modified package? And also i want to push this package to git.
Any lead will be highly appreciated.
If I understand you correctly you have made some changes to the already existing node package react-native-push-notification and you would rather use your own version of it than the original.
You have a couple of options:
In package.json change react-native-push-notification to point to your git repo (e.g. your fork on github). This is not ideal since it makes semver problematic. But it works.
Rename your fork of the package and use that directly from npm. E.g. rename to react-native-push-notification2 or even better, use a scoped package name e.g. #yournick/react-native-push-notification and publish that to npm. Change your package.json to use this package instead.
Convince the authors of the original package to incorporate your changes. This is the ideal solution, but might be difficult to get your patch merged etc.
patch-package is exactly what you're looking for: https://github.com/ds300/patch-package
It will preserve your changes even after running npm install.
The best way to handle this would be to fork the repo https://help.github.com/articles/fork-a-repo/.
This way, you have control of the contents of the package.
Then update your package.json with your repo address.
I also would recommend not pushing your packages to Git. Packages are already under version control (in their own repo) and pushing to Git just bloats your repo for no reason.
Yes you can do it very easily. Fist of all go to the plugin GitHub repository then fork it to your profile. Before if you want to install this plugin from the direct repo, you have to run this command -
npm i https://github.com/zo0r/react-native-push-notification.git
But after successful fork, it will install the modified files that you have made changes and the command should be -
npm i https://github.com/YourUserName/react-native-push-notification.git
and boom your modified files never will change.

Packaging a Wordpress Theme made with Roots (Sage)

I am just getting into the GIT / GULP / Bower workflow. I am basically a complete noob. I have a WordPresstheme being developed on my local machine via MAMP.
Say I wanted to package it up and open it on another Machine, either with Mamp or Wamp.
I don't think I can zip the theme folder with all the NPM Nodules, so what would be the best steps to take to avoid any or minimal bugs.
If you're using git you need to commit and push your changes to a remote repo. Then pull the repo down to the second machine and re-run the build process.
In roots sage 8 that will mean:
Installing bower and npm globally (if you haven't already done so)
Installing the bower npm packages for you project
Running the gulp build task
In Sage the npm modules, bower packages and dist folders are ignored by git because they are listed in .gitignore.
In general it's usually considered good practice NOT to commit any dependancies to your projects repo.

How to check out a JHipster project in multiple development environments

I'm evaluating JHipster; it looks great for rapid development!
Maybe a novice question: I see that the generated .gitignore ignores certain things, e.g.
/node/**
/node_modules/**
So, if I check in the generated project to a repository, and then some other developer in my team checks it out in his environment, the project would not work in his environment. Would it?
Was curious to know how to handle this. Thanks.
Since your git repo won't track node packages, others using your git repo will need install node.js, then run npm install to download all the node packages.
It's similar to them having to have java and maven installed on their environment.
Update: A developer will run 'git clone '. The source (not including node or bower) will be on their workstation. Once they've installed node.js, they'll run 'npm install' and the node directories will be created automatically for your project by downloading them from the Internet. That way you don't need to keep all your node libraries in your own git repository ...just their package name and version in the package.json file (similar to maven dependencies in pom.xml).
No one should commit the node_modules or bower_components to git, what you would do is share the project like you share the maven projects.
Write in the read me what needs to be done to get them ready, for example the installation of yo, bower, grunt or gulp and generator-jhipster.
What is very nice about liquibase, each developer can have his own version of the database, and every commit has its own database version.
What we our team does, if a developer adds something to node js package.json then we mention it in the comment: npm install needed and the same applies for bower.
That way you keep all your environments clean, and if you would like to install continuous integration like "Jenkins or Teamcity" then you make sure Jenkins is building rebuilding the whole project.

How do I develop npm installed packages along with my app?

I'm working on my application. In parallel, I'm working on updating(and adding to) a couple of the npm installed submodules at the same time.
In my package.json dependencies I have:
"zeke-bootstrap": "git://github.com/twilson63/zeke-bootstrap.git",
When I do npm install, it goes and checks out the repository and puts it under node modules just fine. My question is how to I setup this directory so that I can use git, and do commits, and eventually a push to send my changes in my dependent directory back up to github?
Thanks,
Fred
You can checkout your git repo in the node_modules folder under the same folder name as your module and node will automatically use it. However, I don't think its a very good idea. Modules are modules because they are meant to be developed separately.

Caching Node.js git dependencies on Heroku

The new Node.js Heroku build pack (https://blog.heroku.com/archives/2013/12/10/new-node-buildpack) caches node_modules.
As of #4104 Git dependencies are now always updated. This renders caching useless for Git dependencies.
It appears that the only way to avoid this is by appending the commit hash to the dependency.
E.g. "mincer": "git://github.com/vjpr/mincer.git#35d9768"
I have about 5 modules that I npm link during development. They includ public modules not ready for public distribution, private modules, and forks of public modules.
So what I am looking at is creating a pre-commit hook which will update every git dependency in package.json with its latest commit hash (i.e. git rev-parse HEAD).
It feels similar to what git submodules does behind the scenes.
The pre-commit hook will use npm install --link --save GIT_URL#SHA to modify the package.json.
Before implementing the hook, I was wondering if there are any simpler alternatives? (Other than committing my node_modules which I am not a fan of.)
Some alternatives I thought of:
Push public modules to Travis CI with an auto-publish hook. (I think it would be silly to publish a fork of a public module to npm if I am just waiting pull-requests to go through.)
Use GemFury - hosted npm registry ($9 month is expensive. Not sure if it proxies requests to the main npm registry if it can't find them. It would have to be made to be the main registry in .npmrc for the caching to work.)
Use nodejitsu private registrys.
Remove node_modules from .gitignore on a separate branch and re-base for every deploy. (Seems tedious and packing up the npm linked repos would add complexity).
npm shrinkwrap. The new Heroku buildpack respects shrinkwrap. It doesn't seem to play well with npm link.
UPDATE: Shrinkwrap does not work with npm linked repos - the links are lost.
Cheers.
Here is a gist I am using to accomplish my original idea:
https://gist.github.com/vjpr/2783a2745c614acc5d75

Resources