Description
Scenario: I'm using a 3rd party BaaS that uses the Rhino JS engine. The 3rd party (Gamesparks) seems to use a custom implementation of modules, such that each module when 'required' simply imports and runs the files required, exposing the local variables to any files that 'required' it. The modules themselves don't have global/export/default.
So the minimal protobufjs library (for Browsers) doesn't actually work. I was actually able to get protobuf working in this environment by grabbing the individual files (writer.js, reader.js, and util/minimal.js) and uploading them as "modules" and removing any reference to module specific commands/vars (e.g. export). I then uploaded a static proto file and changed the first few lines to to map the variables to the locally available variables from the fake "required" modules. I successfully was able to encode and decode from/to my proto class.
// ProtobufJSModule
var global = {};
require('ProtobufUtilModule');
require('ProtobufReaderModule');
require('ProtobufWriterModule');
var $protobuf = {};
$protobuf.Reader = Reader;
$protobuf.Writer = Writer;
$protobuf.util = util;
// Sample Static Converted Proto File
require('ProtobufJSModule');
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
// Exported root namespace
var $root = {};//$protobuf.roots["default"] || ($protobuf.roots["default"] = {});
$root.ProtoName = (function() { ... })();
I'd like to see if there's a way to compile the library from the source with these settings. I've looked at the index-minimal.js file to try and config the way I'd like the library to work, but I'm a bit out of my depth. BufferReader and BufferWriter are only for Node Buffers correct? My env only allows Array Buffers as far as I can tell, so I wouldn't need those files? How would I get the output to be be the files I need (Reader/Writer/Util) joined as one file, but not each as modules. They could be wrapped in functions/namespaces to prevent naming collisions, but they can't use export.
If the answer is there's no easy way to do that, and I should just fork it and patch the lib together myself, that's fine, I just wanted to make sure I explored all options to do it the better way first, so I can easily update the lib to any changes made in the src. Thanks for a wonderful framework!