-
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
Add CommonJS support as a plugin option #648
Conversation
Do you also want to update the docs here? https://github.com/bufbuild/protobuf-es/blob/main/docs/generated_code.md?plain=1#L81-L86 |
Thanks! Updated in 526fe50. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
## What's Changed * Add CommonJS support as a plugin option by @timostamm in [#648](#648) * Add `GeneratedFile.jsDoc()` and other features to `@bufbuild/protoplugin` by @timostamm in [#649](#649) **Full Changelog**: v1.5.1...v1.6.0
This PR adds support for generating JavaScript for the CommonJS module system.
When the plugin option
js_import_style
is set tolegacy_commonjs
, generated JavaScript will userequire()
to import, and theexports
variable to export.Here is a shortened example, generated from example.proto:
As you can see, strict mode is enabled. For best interoperability, we define __esModule.
For plugin authors:
exportDecl
instead of printing anexport
statement. For example, usef.print(f.exportDecl("abstract class", "MyClass"), " {}")
instead off.print("export abstract class MyClass {}")
.transpile
function needs to handle the new 4th argumentjsImportStyle
to support CommonJS output.Closes #587.