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

Randy Abernethy commented on THRIFT-2995:
-----------------------------------------

Hey Igor,

I agree.

The suggestion referenced in your issue was not recommending the centralization 
of exports in index so much as it was recommending not emitting require 
statements from the compiler (essentially the same issue raised here in a 
microcosm). The library in question was "q", which like "node-int64" is built 
into the node lib interface. These are probably the only two libs that should 
be in the index.js.

The nodejs lib has some organizational anomalies which tie to the problem you 
point out (the compiler is importing everything via thrift/index.js). Prior to 
today, one road block was that all of the transports  and protocols were in 
single files. Thanks to THRIFT-2964 protocols, transports and connection 
classes are all in their own files now. This will actually make it possible to 
selectively include just the protocol and transport you need. 

This is not a quickie patch. Removing everything from the index.js, which we 
should do, will require updating every example, the tutorial and all of the 
tests. It will also break all users when 0.9.3 comes out. While it is a bit of 
work, we should absolutely do this before v1.0.

Patches welcome!

-Randy

> 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