-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is the order of fileDesc
dependencies in generated code deterministic?
#1030
Comments
The dependencies are provided by the compiler in the field Can you verify that it's not the compiler introducing the changes? This should be as simple as dumping a descriptor set when you generate code ( |
Thanks for the debugging tips. I ran Although it's not protobuf-es introducing the non-determinism, would it be possible for protobuf-es to sort the dependencies before generating the code so that the output is deterministic regardless? |
Hm, sorting in protoc-gen-es could have unintended side-effects, we'd have to think this through. At the very least, it will change the import order for many users... I think it would be much preferable to get to the bottom of the issue. This could be a bug in To unblock you, you could add this file: // src/protoc-gen-es-sort-deps.cjs
const { runNodeJs } = require("@bufbuild/protoplugin");
const { protocGenEs } = require("@bufbuild/protoc-gen-es/dist/cjs/src/protoc-gen-es-plugin.js");
runNodeJs({
name: "sort-deps",
version: "v0",
run(req) {
req.protoFile.forEach(f => f.dependency.sort());
return protocGenEs.run(req);
}
}); It simply wraps protoc-gen-es and sorts dependencies. To use it, replace protoc-gen-es in buf.gen.yaml with: version: v2
inputs:
- directory: proto
plugins:
- local: ["node", "src/protoc-gen-es-sort-deps.cjs"]
opt: target=ts
out: src/gen |
Nice one, thanks for the workaround. I think this is probably a bug in I've raised it as bufbuild/buf#3506, so I'll close this one. |
Since upgrading to protobuf-es v2 we've been getting diffs in our generated code that look like
It seems to flip-flop between ordering
file_protoc_gen_openapiv2_options_annotations
andfile_google_api_field_behavior
first in the dependencies (and similarly higher up in the file, where they are imported).Is it possible that these dependencies aren't deterministically ordered?
The text was updated successfully, but these errors were encountered: