Git ignore, purpose of src/packages


#1

This may be a question of how we should organise our development project. In our V2 world we use the overlays folder, so our application code is in a sub-folder of OS.js. I was thinking to do something similar in V3: my applications would each be a package, and the instructions for creating a package say it’s OK to put it in the OS.js/src folder. I realise that I could put it somewhere else, but the src approach seems reasonable to me. We plan to put our whole OS.js tree into our git. [There’s a whole extra discussion on handling updates to OS.js, which may lead us to do something else, but let’s just go with this simple scenario for now.]

That now leads to the question of the Git ignore file.

The OS.js installation has this .gitignore file

.swp
.tern-*
node_modules
src/packages/*
/packages.json
/sessions
/.env*
/session-store.db

Two questions about whether to adapt it for our development use.

I can understand why the node_modules is excluded in the delivery of OS.js, however for our purposes, delivering a system I think we need to include node_modules into git. Wisdom seems to have changed on this topic but this article seems quite persuasive:

https://web.archive.org/web20150116024411/http://www.futurealoof.com:80/posts/nodemodules-in-git.html

Concerning our packages. I had assumed that my new packages should go under src/packages, however I see that’s ignored too. So what is that packages folder for? And where should my stuff go.

Thanks.


#2

The OS.js repository basically is an “overlay”, or to be correct your distribution.

You’re free to do whatever you want in here. The code that comes with the repo is just a bare-bones setup.

A very good reason not to include this is that the contents might depend on the platform you’re running on. So if something is built from source, you cannot use that on another machine. It also seriously bloats and slows down the repo.

The package-lock.json file has the responsibility of making node_modules/ the “same” on all machines.

I won’t stop you, but this will bloat the repository. At least consider using a git submodule for it.

The link is broken.

The src/packages folder is the default output path of npm run package:create.

It goes wherever you like. It really does not matter since it all operates via npm.

If you’re planning on having a monorepo, then use src/pacakges if that’s the easiest. And if you’re adding things other than packages, just stick it in another folder in src/ or maybe under src/client/ if it’s client-side stuff.


#3

Just to elaborate. Packages are managed by npm, so you can place then wherever you want. The src/packages directory is just the location I chose for npm run package:create. The name and location of that folder is not actually relevant.

For things like Service Providers, you can do something similar. Use ex. src/client/providers and then in src/client/index.js register them as per usual.


#4

Thanks. The discussions about node_modules in git start from

https://stackoverflow.com/questions/11459475/should-i-check-in-node-modules-to-git-when-creating-a-node-js-app-on-heroku and Mikael Roger’s opinion, link there, sounded convincing.

I was concerned about bloat, but was about to bite the bullet. I have time to rethink.

Concerning src/packages it’s in the default git ignore, I’m inferring that if we use package:create then we probably need to stop ignoring it.


#5

For deployment, I guess it makes sense in some contexts. But if I was about to do this, I’d create a separate git-repo containing all node_modules/ and use git submodule for maintaining. That way you don’t have to worry about polluting your git history and repository size.

We have a lot of repos at work that contains node_modules/ and they are a total pain to clone, because they have been maintained over such a long time and the node modules directory has gone through many iterations. Even though I have 100Mbit it feels like an eternity sometimes.

Yeah. Just edit the gitignore.

Btw, it is totally safe to modify everything in the OS.js repo as you should use npm update to upgrade and not git pull (just remove .git and make it your own). If anything requires modification I will make a notice that shows when npm-update is run and link to the appropriate migration article:

https://manual.os-js.org/v3/guide/migrate/