Skip to content

Commit

Permalink
Replace usage of Object.assign
Browse files Browse the repository at this point in the history
The grpc-web service stub code generated by ts-protoc-gen is invoking an ES6 function (`Object.assign`) which is tricking webpack into treating the modules as ES6 modules instead of ES5 modules.

Replacing the `Object.assign` invocation with some vanilla ES5 results in webpack correctly identify the module as a CommonJS module and thereby exposing the `exports` object to the scope of the function.

Fixes #103
  • Loading branch information
jonny-improbable committed Sep 12, 2018
1 parent 5b06c73 commit 71f1c3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions examples/generated/proto/examplecom/simple_service_pb_service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion examples/generated/proto/orphan_pb_service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/service/grpcweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ function printUnaryStubMethod(printer: CodePrinter, method: RPCMethodDescriptor)
.printLn(`onEnd: function (response) {`)
.indent().printLn(`if (callback) {`)
.indent().printLn(`if (response.status !== grpc.Code.OK) {`)
.indent().printLn(`callback(Object.assign(new Error(response.statusMessage), { code: response.status, metadata: response.trailers }), null);`)
.indent().printLn(`var err = new Error(response.statusMessage);`)
.printLn(`err.code = response.status;`)
.printLn(`err.metadata = response.trailers;`)
.printLn(`callback(err, null);`)
.dedent().printLn(`} else {`)
.indent().printLn(`callback(null, response.message);`)
.dedent().printLn(`}`)
Expand Down

0 comments on commit 71f1c3a

Please sign in to comment.