Skip to content

Commit

Permalink
examples: nodejs: using import_style=commonjs_strict avoids global na…
Browse files Browse the repository at this point in the history
…mespace pollution
  • Loading branch information
JamesDunne committed Jun 19, 2021
1 parent 616ab1d commit 0ca99e2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/nodejs/generate.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grpc_tools_node_protoc --proto_path=../../protos/sni --js_out=import_style=commonjs,binary:./ --grpc_out=grpc_js:. ../../protos/sni/sni.proto
grpc_tools_node_protoc --proto_path=../../protos/sni --js_out=import_style=commonjs_strict,binary:./ --grpc_out=grpc_js:. ../../protos/sni/sni.proto
4 changes: 2 additions & 2 deletions examples/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('./sni_pb');
const messages = require('./sni_pb');
const services = require('./sni_grpc_pb');
const grpc = require('@grpc/grpc-js');

Expand All @@ -8,7 +8,7 @@ async function main() {
const client = new services.DevicesClient(target, grpc.credentials.createInsecure());

async function getDevices() {
const req = new proto.DevicesRequest();
const req = new messages.DevicesRequest();

//request.addKinds("retroarch");

Expand Down
3 changes: 3 additions & 0 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"dependencies": {
"@grpc/grpc-js": "^1.3.2",
"google-protobuf": "^3.17.3"
},
"devDependencies": {
"grpc-tools": "^1.8.1"
}
}
62 changes: 31 additions & 31 deletions examples/nodejs/sni_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();

goog.exportSymbol('proto.AddressSpace', null, global);
goog.exportSymbol('proto.DetectMemoryMappingRequest', null, global);
goog.exportSymbol('proto.DetectMemoryMappingResponse', null, global);
goog.exportSymbol('proto.DeviceCapability', null, global);
goog.exportSymbol('proto.DevicesRequest', null, global);
goog.exportSymbol('proto.DevicesResponse', null, global);
goog.exportSymbol('proto.DevicesResponse.Device', null, global);
goog.exportSymbol('proto.GetMemoryMappingRequest', null, global);
goog.exportSymbol('proto.MemoryMapping', null, global);
goog.exportSymbol('proto.MemoryMappingResponse', null, global);
goog.exportSymbol('proto.MultiReadMemoryRequest', null, global);
goog.exportSymbol('proto.MultiReadMemoryResponse', null, global);
goog.exportSymbol('proto.MultiWriteMemoryRequest', null, global);
goog.exportSymbol('proto.MultiWriteMemoryResponse', null, global);
goog.exportSymbol('proto.PauseEmulationRequest', null, global);
goog.exportSymbol('proto.PauseEmulationResponse', null, global);
goog.exportSymbol('proto.PauseToggleEmulationRequest', null, global);
goog.exportSymbol('proto.PauseToggleEmulationResponse', null, global);
goog.exportSymbol('proto.ReadMemoryRequest', null, global);
goog.exportSymbol('proto.ReadMemoryResponse', null, global);
goog.exportSymbol('proto.ResetSystemRequest', null, global);
goog.exportSymbol('proto.ResetSystemResponse', null, global);
goog.exportSymbol('proto.SetMemoryMappingRequest', null, global);
goog.exportSymbol('proto.SingleReadMemoryRequest', null, global);
goog.exportSymbol('proto.SingleReadMemoryResponse', null, global);
goog.exportSymbol('proto.SingleWriteMemoryRequest', null, global);
goog.exportSymbol('proto.SingleWriteMemoryResponse', null, global);
goog.exportSymbol('proto.WriteMemoryRequest', null, global);
goog.exportSymbol('proto.WriteMemoryResponse', null, global);
var proto = {};

goog.exportSymbol('AddressSpace', null, proto);
goog.exportSymbol('DetectMemoryMappingRequest', null, proto);
goog.exportSymbol('DetectMemoryMappingResponse', null, proto);
goog.exportSymbol('DeviceCapability', null, proto);
goog.exportSymbol('DevicesRequest', null, proto);
goog.exportSymbol('DevicesResponse', null, proto);
goog.exportSymbol('DevicesResponse.Device', null, proto);
goog.exportSymbol('GetMemoryMappingRequest', null, proto);
goog.exportSymbol('MemoryMapping', null, proto);
goog.exportSymbol('MemoryMappingResponse', null, proto);
goog.exportSymbol('MultiReadMemoryRequest', null, proto);
goog.exportSymbol('MultiReadMemoryResponse', null, proto);
goog.exportSymbol('MultiWriteMemoryRequest', null, proto);
goog.exportSymbol('MultiWriteMemoryResponse', null, proto);
goog.exportSymbol('PauseEmulationRequest', null, proto);
goog.exportSymbol('PauseEmulationResponse', null, proto);
goog.exportSymbol('PauseToggleEmulationRequest', null, proto);
goog.exportSymbol('PauseToggleEmulationResponse', null, proto);
goog.exportSymbol('ReadMemoryRequest', null, proto);
goog.exportSymbol('ReadMemoryResponse', null, proto);
goog.exportSymbol('ResetSystemRequest', null, proto);
goog.exportSymbol('ResetSystemResponse', null, proto);
goog.exportSymbol('SetMemoryMappingRequest', null, proto);
goog.exportSymbol('SingleReadMemoryRequest', null, proto);
goog.exportSymbol('SingleReadMemoryResponse', null, proto);
goog.exportSymbol('SingleWriteMemoryRequest', null, proto);
goog.exportSymbol('SingleWriteMemoryResponse', null, proto);
goog.exportSymbol('WriteMemoryRequest', null, proto);
goog.exportSymbol('WriteMemoryResponse', null, proto);
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
Expand Down

0 comments on commit 0ca99e2

Please sign in to comment.