proto-loader not populating file descriptor dependency list
Problem description
The *Definition structures that proto-loader returns each have a fileDescriptorProtos field which include the files needed to resolve each type. The file descriptor includes a "dependency list" of files that they require but this is currently always returning nothing
This was discussed in #79
Reproduction steps
This can be reproduced using the following two proto file definitions: sample.proto
syntax = "proto3";
package sample;
import 'vendor.proto';
service SampleService {
rpc Hello (HelloRequest) returns (HelloResponse) {}
}
message HelloRequest {
string hello = 1;
}
message HelloResponse {
vendor.HelloStatus status = 2;
}
vendor.proto
syntax = "proto3";
package vendor;
enum HelloStatus {
HELLO = 1;
WORLD = 2;
}
this then inspected using the following code:
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb';
import * as protoLoader from '@grpc/proto-loader';
const root = protoLoader.loadSync('sample.proto', { includeDirs: [__dirname] });
Object.values(root).forEach(({ fileDescriptorProtos }) => {
if (Array.isArray(fileDescriptorProtos)) {
fileDescriptorProtos.forEach((bin) => {
const proto = FileDescriptorProto.deserializeBinary(bin);
console.log(`File: ${proto.getName()}\tDependencies: ${proto.getDependencyList()}`);
/* output:
File: sample.proto Dependencies:
File: vendor.proto Dependencies:
File: sample.proto Dependencies:
File: vendor.proto Dependencies:
File: sample.proto Dependencies:
File: vendor.proto Dependencies:
*/
});
}
});
we would expect that sample.proto would include vendor.proto in its dependency list due to the import and usage of it in the HelloResponse field
Environment
- OS name, version and architecture: [e.g. Linux Ubuntu 18.04 amd64]: Mac OS 13.4.1
- Node version [e.g. 8.10.0]: v20.8.0
- Node installation method [e.g. nvm]: nvm
- If applicable, compiler version [e.g. clang 3.8.0-2ubuntu4]: N/A
- Package name and version [e.g. [email protected]]:
[email protected]
Additional context
We are working around this in the @grpc/reflection package by manually adding those dependencies based on the proto definitions with this visitor-pattern-based logic