browserify / browser-resolve

resolve function which support the browser field in package.json
MIT License
102 stars 70 forks source link

Chrome App sockets #17

Closed amiuhle closed 11 years ago

amiuhle commented 11 years ago

I made an effort to get the MongoDB NodeJS drivers to run on Google Chrome Apps using browserify. To achieve that, I did the following:

require('process').registerBinding('tcp_wrap', require('tcp_wrap-chromeify'));

I didn't add the required projects to the package.json yet, because the plugins written by me aren't published yet. You can see it in action here: https://github.com/amiuhle/chrome-mongo-admin

Tests that were already there are passing, but I didn't add new ones yet. I wanted to make sure that you're willing to pull this stuff in, or if you think it makes more sense if i permanently fork this as node-chrome-resolve or something...

amiuhle commented 11 years ago

Might fix #15?

dominictarr commented 11 years ago

you should publish the modules to npm, using a git install path is only a last resort.

I get the impression that this will only work in chrome apps? is that correct?

amiuhle commented 11 years ago

you should publish the modules to npm, using a git install path is only a last resort.

I know, and I'm planning to, but I thought I'd wait until it's more complete. Currently, I have only tested the client part of NodeJS TCP... Or is it commom practice to publish stuff right away, even while in early development?

I get the impression that this will only work in chrome apps? is that correct?

builtin/util and the stuff in builtin/process will work everywhere. builtin/stream should work in all modern Browsers.

For the dns-chromeify, net-chromeify and tcp_wrap-chromeify part, it's a little more complicated. net-chromeify is a pretty straightforward port of the NodeJS net package. It internally requires dns and process.binding('tcp_wrap'). The developer will have to call

require('process').registerBinding('tcp_wrap', { TCP: { /* some object implementing the interface */ });

Otherwise, it won't work at all. tcp_wrap-chromeify implements the interface using the chrome.socket API, which is only available in Chrome Packaged Apps. If someone were to write a tcp_wrap implementation that wraps websockets or uses some other Browser Extension API, it will work.

dns-chromeify checks if the chrome.experimental.dns object is available, which is also only available for Chrome Packaged Apps. If the API is not available, it will just return the requested hostname instead of the IP address, which works fine in my implementation, because the wrapped chrome.sockets doesn't need an IP address to open a connection, it will also accept a hostname.

defunctzombie commented 11 years ago

I won't be merging this. Chrome App specific things do not belong in this module. You should use them explicitly in your projects.

I will be exposing a way to have users of this module specify their own shims.

dominictarr commented 11 years ago

@amiuhle also see this issue https://github.com/substack/node-browserify/issues/356

amiuhle commented 11 years ago

@shtylman Okay. Will you merge the stuff in builtin/util and in builtin/process if I make a separate pull request?

defunctzombie commented 11 years ago

The until stuff yes. The process stuff I am not sure. Is this something supported in node? On Apr 24, 2013 11:57 AM, "amiuhle" notifications@github.com wrote:

@shtylman https://github.com/shtylman Okay. Will you merge the stuff in builtin/util and in builtin/process if I make a separate pull request?

— Reply to this email directly or view it on GitHubhttps://github.com/shtylman/node-browser-resolve/pull/17#issuecomment-16943050 .