parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.95k stars 4.78k forks source link

Using parse-server as git dependency #1120

Closed steven-supersolid closed 8 years ago

steven-supersolid commented 8 years ago

In order to use parse-server in production we need to have the option to apply our own hotfixes outside the release cycle (these fixes will also be submitted as PRs). I hope we won't need to use this option but imagine there is a critical production issue that we can't wait for a PR to be checked and a release made.

I was initially unsuccessful specifying the dependency as: "parse-server": "git://github.com/ParsePlatform/parse-server.git#someCommitHash" because node_modules/parse-server/bin/parse-server.js includes code from the lib folder.

I fixed this in my repo by adding the contents of the lib folder (and removing lib from .gitignore). This works but I wonder if we should instead be building with babel to the bin folder? I'm unfamiliar with building and publishing npm modules so not sure of best practice.

flovilmart commented 8 years ago

the best practice would be to add a git submodule and use npm link.

at the root of your git repo:

git submodule add git://github.com/ParsePlatform/parse-server.git
npm link parse-server ./parse-server
cd parse-server
git checkout "commit/branch"
cd ..
git commit -am 'uses parse-server on commit ...'
flovilmart commented 8 years ago

I wonder if we should instead be building with babel to the bin folder

The bin folder is usually reserved for command line tools and executables

steven-supersolid commented 8 years ago

Thanks, I'll try what you suggested. Assuming npm link will still work when deployed e.g. to Heroku?

Just out of interest, any idea why parse-server is using a bin folder? Looking at other depencies, those do not, e.g. body-parser, express

flovilmart commented 8 years ago

this is just to put some global scripts there like parse-server.

Let's say you have this architecture:

my_project | |- config.json |- package.json |- node_modules/parse-server

in your package.json, you can set

{
  "scripts": {
      "start": "parse-server ./config.json" 
  }
}

then just run npm start

flovilmart commented 8 years ago

if npm link don't survive the heroku deploy, you an use file

steven-supersolid commented 8 years ago

So using npm link actually set up the dependency as file, which worked locally.

To deploy to Heroku I initialise the app folder as a new repo (it actually is a sub-folder 'server' of our git project), add files and git push -f to the Heroku remote.

This doesn't work with the submodule because submodule files cannot be re-added. Instead I tried adding as a subtree. This at least gets parse-server pushed to Heroku but there is an error when the build pack attempts to build parse-server, because babel cannot be found.

I guess I could add the dev-dependencies of parse-server as dependencies of my app.

remote: -----> Building dependencies
remote:        Pruning any extraneous modules
remote:        unbuild hello@1.0.0
remote:        Installing node modules (package.json)
remote:
remote:        > parse-server@2.2.0 prepublish /tmp/build_e4af8ab8a7598af5c0c09f7f9c933a95/parse-server
remote:        > npm run build
remote:
remote:
remote:        > parse-server@2.2.0 build /tmp/build_e4af8ab8a7598af5c0c09f7f9c933a95/parse-server
remote:        > babel src/ -d lib/
remote:
remote:        sh: 1: babel: not found
flovilmart commented 8 years ago

you may need to run npm install in your sub folder parse-server

steven-supersolid commented 8 years ago

That unfortunately doesn't work, I guess because node_modules is in .gitignore. Also I'm not sure I want to push node_modules with every deploy. Also I shouldn't need to build parse-server with every deploy.

I'm actually thinking to go back to my first approach, make a branch on my fork whenever I want to update parse-server, then build and push lib to that branch.

I could skip a step if lib was un-ignored in parse-server but I guess there's a reason it is ignored?

steven-supersolid commented 8 years ago

BTW, thanks for working through this with me :)

flovilmart commented 8 years ago

yes it's ignored as the project is build and we don't have pre-commit hooks. That would force everyone to make sure lib is properly build, and it doesn't make sense from a version control point of view.

I'm not sure why the submodules don't work with heroku. what do you mean by submodule files cannot be re-added. This should be fully supported: https://devcenter.heroku.com/articles/git-submodules#git-submodules

As long as you have the proper commit stored in your parent

steven-supersolid commented 8 years ago

It's perhaps how my project is structured:

project (git://xxx) /client /server /server/parse-server

To deploy, instead of pushing the entire project I run a script such as:

cd server
git init
git add .
git commit --message "deploy"
call heroku git:remote nameOfRemote
git push --force heroku master
rmdir /S /Q .git

git add won't add files in parse-server as this is a submodule. However, this does work if I use a subtree instead, or I could temporarily convert parse-server from a submodule folder to a regular folder in the build script.

What doesn't work is that parse-server is still not built at this point so the Heroku build script runs build, which fails because babel is missing on the Heroku build instance. I could include it by adding to my project dependencies (Heroku doesn't use dev-dependencies for production builds) but then would need to maintain.

flovilmart commented 8 years ago

yes you can't add file, so use your fork, add multiple remotes :)

That is cleaner to keep parse-server as a submodule this way you can/could seamlessly jump across commits, forks etc...