danlucraft / git.js

pure-Javascript Git implementation
http://danlucraft.com/
MIT License
1.31k stars 79 forks source link

node patterns #2

Open isaacs opened 13 years ago

isaacs commented 13 years ago
  1. There should be a package.json file so that it can be published and installed via npm.
  2. The dependencies should be loaded as dependencies in the node_modules folder in the node case, and listed in the package.json file. (npm install can pick them all up.)
  3. Don't modify require.paths, which is deprecated as of node 0.3, and completely gone in 0.5.
  4. Prefer using exports rather than globals.
  5. It's be nice to have a node client as well as a server, perhaps even more valuable. (In particular, it'd be really nice to use this in npm for a few things, where I'm instead shelling out to the command line git program.)

It may be worthwhile to check out requirejs or browserify to be able to use exactly the same patterns in both the browser and Node.

danlucraft commented 13 years ago

Thanks for this. This was next on my list but I don't have any experience of this so it's really helpful.

I'm including a wrapper for shelling out in this too (it will be useful for generating test repos), so if you can point me at your use cases in npm I can implement those first.

Cheers.

isaacs commented 13 years ago

Right now, the npm submodule command will look up a package's repository information, and then create a submodule. https://github.com/isaacs/npm/blob/master/lib/submodule.js

Other commands simply abort when they encounter a .git folder, and refuse to clobber it. So, once you submodule something, you must use git to update it from then on. It'd be nice if npm update could detect git submodules and update them by pulling from the appropriate remote ref. (This is planned, but it's yet another point where I have to shell out to a random cli util.)

To use this in npm, however, it can't depend on underscore, use global variables, or modify require.paths, and the client should be easier to get at programmatically, not through the cli.

isaacs commented 13 years ago

Also, I'd like to be able to install packages from git:// urls as well as https?:// urls, and either clone into ./node_modules/pkgname if it's missing, or fetch the specified commit from the remote if it's already there. A lot of people have asked for this repeatedly, and it'd be a pretty nice feature, I just didn't want to increase my dependence on having git installed at the target. HTTP is easier, since that's built into node.

chrisdickinson commented 13 years ago

@danlucraft I'd love to help out with this. I've got some experience with the git internals (was working on my own implementation of git in javascript previously) -- it'd be super helpful if we could split this into discrete issues so I could work on tiny bits on my own and submit changes to you via pull requests (e.g., "add git wire protocol support", "add loose object write support", "add pack file write support", "npm-ify module"). Only if you have the time though! Great work!

danlucraft commented 13 years ago

Hi Chris,

of course, tempusfugit wasn't it? Sounds like a plan :)

chrisdickinson commented 13 years ago

Apologies for the patchbomb bombardment; I put in a fair amount of work in this evening on refactoring this to use commonjs idioms: https://github.com/chrisdickinson/git.js/tree/feature/commonjs. Putting together an in-browser build script plus tests is my next step.