Skip to content
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

Different TS output on macOS & Windows #1072

Open
NfNitLoop opened this issue Feb 22, 2025 · 3 comments
Open

Different TS output on macOS & Windows #1072

NfNitLoop opened this issue Feb 22, 2025 · 3 comments

Comments

@NfNitLoop
Copy link

I'm using protobuf-es from Deno, using the script I linked to over here: #293 (comment)

The TypeScript output on Windows and macOS has some whitespace differences. In comments like this:

/**
 * Comment followed by an empty line.
 *
 * Another comment.
 */

the * characters on a single line have a trailing space on macOS, and none on Windows.

It's a minor issue, but is a bit of an annoyance if I'm regenerating the file on different computers. Makes for noisy git diffs.

@timostamm
Copy link
Member

Thanks for the report, Cody. Generated code should be identical, regardless of the platform it's generated on.

But I'm not sure that this is a bug in protoc-gen-es - it might be an issue in the compiler. This can be isolated by compiling the Protobuf source to a set of descriptors first, then generating code on both platforms from this set of descriptors.

With buf:

buf build -o descriptors.binpb
buf generate descriptors.binpb

With protoc:

protoc -o descriptors.binpb -I proto proto/example.proto
protoc --descriptor_set_in=descriptors.binpb ...

Could you give this a try? If protoc-gen-es still generates different code, this is a bug in protoc-gen-es. If it doesn't, it's an issue in the compiler.

@NfNitLoop
Copy link
Author

I realized that it could be in either place, but wasn't sure how to debug. Thanks for the steps! I'll try to test that this evening and get back to you!

@timostamm
Copy link
Member

If you're using git, this might be caused by the setting core.autocrlf = true. It'll automatically convert LF to CRLF when checking out files. protoc doesn't normalize line endings in comments, and neither does buf. So the LF or CRLF end up verbatim in the generated comment.

I'm not sure if a Protobuf compiler should normalize line endings in comments 🤔

If this is caused by git, I suggest trying to disable the option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants