rethinkdb / horizon

Horizon is a realtime, open-source backend for JavaScript apps.
MIT License
6.78k stars 349 forks source link

Project Structure to enable Github npm dependencies #790

Open lirbank opened 8 years ago

lirbank commented 8 years ago

So, I had this idea it would be nice for contributors/early adopters to be able to depend directly on github repositories. Say I made a hack to fix something for react-native, but it's just a hack so it will never be a PR. Then, if each horizon component (client, server, cli) had their own github repo, so package.json is in the root, it's possible to use a github repo+branch as version in the app package.json. Eg. npm only allows Github dependencies if the package.json is in the root of the repo, and they have no plans of changing that.

Reason? A github dependency will work for testing on staging servers (eg Heroku etc), whereas a filesystem dependency won't, plus it's nice to have the code on Github.

For example, today I have to do something like this (see postinstall), pretty nasty:

{
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "postinstall": "test -d ./node_modules/@horizon || (rm -fR node_modules/@horizon && git clone https://github.com/lirbank/horizon.git node_modules/@horizon --branch react-native-tmp-fix --single-branch && cd node_modules/@horizon/client/ && npm install)"
  },
  "dependencies": {
    "react": "15.2.1",
    "react-native": "0.31.0"
  }
}

In the next example I've created a new branch react-native-client where I deleted everything in the root of the project and moved everything in client/to the root. Now the clients package.json is in the root of the repo and I can use regular dependencies:

{
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
  },
  "dependencies": {
    "@horizon/client": "git://github.com/lirbank/horizon.git#react-native-client",
    "react": "15.2.1",
    "react-native": "0.31.0"
  }
}

I get if you don't want to change the whole project structure just for this, but figured it was worth bringing it up. Are there other approaches? Git submodules?

Just an idea, feel free to close if it doesn't makes any sense.

lirbank commented 8 years ago

Relates to https://discuss.horizon.io/t/npm-install-current-github-version/308/7

deontologician commented 8 years ago

I think the monorepo concept is just incompatible with how npm wants to deal with github packages. Though I think we could do something like publish nightlies. Incidentally, the number of npm packages we have in the repo is about to shoot up a lot in the plugins release, so I think making them individual repositories isn't great for a few reasons. Not the least of which is that issues spread across multiple repositories is a huge pain