[ 
https://issues.apache.org/jira/browse/THRIFT-2995?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14315482#comment-14315482
 ] 

Andrew de Andrade commented on THRIFT-2995:
-------------------------------------------

Igor,

The nodejs code was never designed for browserify/webpack. I have been working 
on making the nodejs code browserify friendly (see my other patches and 
issues). In one of my patches I introduce a browser.js file that can be 
required with {{var thrift = require('thrift/browser');}}.

There are a bunch of changes that need to be made to make things lightweight 
for the browser beyond lightening up the index.js file. One of the main changes 
that needs to be made is not having a default transport and protocol (instead 
it should throw (developer error)). Without this change, TBinaryProtocol and 
TBufferedTransport will be included with every browser build even if you decide 
to use something else like TJSONProtocol.

Q is another thing that needs to be removed and moved to it's own generator 
(for those that want promise support), but that is a huge change that requires 
a major refactor. Furthermore, there are more important things to fix first 
like the extensive use of try/catch for error handling (see THRIFT-2997 and 
THRIFT-2932).

Please check out my other patches and feel free to cc me on any issues that 
involve the nodejs lib and its usage in the browser since that is my number one 
priority right now. 

If you're interested in committing patches (always welcome), we can coordinate 
on things that need to be tackled.

> nodejs: index.js requires too much
> ----------------------------------
>
>                 Key: THRIFT-2995
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2995
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Library
>    Affects Versions: 0.9.2
>         Environment: webpack
>            Reporter: Igor Tkach
>
> THRIFT-2387 requested centralizing external exports in index.js. Required 
> modules that are now in  index.js create unnecessary and problematic 
> dependencies  which make it impossible to use thrift module in browser via 
> tools like webpack. Client code may avoid using {{require('thrift')}} import 
> like so:
> {code:javascript}
> var options = {
>     transport: require('thrift/transport').TBufferedTransport,
>     protocol: require('thrift/protocol').TBinaryProtocol,
>     path: "/",
>     headers: {"Connection": "close"},
>     https: false,
>     responseType: 'arraybuffer'
>   };
>   var httpConnection = require('thrift/http_connection');
>   var con = httpConnection.createHttpConnection("localhost", 8888, options);
>   var client = httpConnection.createHttpClient(MyService, con);
> {code}   
> but unfortunately generated {{MyService}} nodejs module contains  
> {{require('thrift')}} which tries to bring in connection, ws_connection, 
> server and web_server all of which of course are unwanted in the browser and 
> depend on node modules that can't work in the browser.
>   



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to