diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 022eb41c..cba96b43 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.5.4", + "version": "0.5.5", "author": "Google Inc.", "contributors": [ { diff --git a/packages/proto-loader/src/index.ts b/packages/proto-loader/src/index.ts index b29e26f3..ffef89d3 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -369,23 +369,29 @@ export function loadSync( } // Load Google's well-known proto files that aren't exposed by Protobuf.js. -{ - // Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp, - // and wrappers. compiler/plugin is excluded in Protobuf.js and here. - const wellKnownProtos = ['api', 'descriptor', 'source_context', 'type']; - const sourceDir = path.join( - path.dirname(require.resolve('protobufjs')), - 'google', - 'protobuf' - ); - for (const proto of wellKnownProtos) { - const file = path.join(sourceDir, `${proto}.proto`); - const descriptor = Protobuf.loadSync(file).toJSON(); +// Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp, +// and wrappers. compiler/plugin is excluded in Protobuf.js and here. - Protobuf.common( - proto, - (descriptor.nested!.google as Protobuf.INamespace).nested! - ); - } -} +// Using constant strings for compatibility with tools like Webpack +const apiDescriptor = require('protobufjs/google/protobuf/api.json'); +const descriptorDescriptor = require('protobufjs/google/protobuf/descriptor.json'); +const sourceContextDescriptor = require('protobufjs/google/protobuf/source_context.json'); +const typeDescriptor = require('protobufjs/google/protobuf/type.json'); + +Protobuf.common( + 'api', + apiDescriptor.nested.google.nested.protobuf.nested +); +Protobuf.common( + 'descriptor', + descriptorDescriptor.nested.google.nested.protobuf.nested +); +Protobuf.common( + 'source_context', + sourceContextDescriptor.nested.google.nested.protobuf.nested +); +Protobuf.common( + 'type', + typeDescriptor.nested.google.nested.protobuf.nested +); diff --git a/packages/proto-loader/test_protos/well_known.proto b/packages/proto-loader/test_protos/well_known.proto index dd70402b..3ff2292f 100644 --- a/packages/proto-loader/test_protos/well_known.proto +++ b/packages/proto-loader/test_protos/well_known.proto @@ -19,3 +19,7 @@ import "google/protobuf/descriptor.proto"; extend google.protobuf.FieldOptions { bool redact = 52000; } + +message DescriptorHolder { + google.protobuf.DescriptorProto descriptor = 1; +}