-
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 the option to transpile target files #228
Conversation
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.
Very excited for this :)
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.
This looks pretty great to me, just needs a little bit of tidying up, see the two comments below.
Can you remove packages/protoplugin-test/descriptorset.bin
and then add it to .gitignore
? I know we check in generated source files, but this binary file is not very useful in git.
This release includes the following: ## 🚨 Breaking Changes 🚨 - #233 - If you have been inspecting fields (`DescField`) from createDescriptorSet(), you will need to update your code to use the new `fieldKind` discriminator. The `kind` property no longer contains values such as `map_field` and `message_field` for their respective types of `DescField`. Instead, a new type has been added named `fieldKind`, which allows you to further identify the kind of field a `DescField` represents (`map`, `enum`, `message`, etc.) - #228 - If you have been using `createEcmaScriptPlugin` to create your own plugin, the signature has changed. Previously, the function accepted a single generator function for generating your output files. This has been split up into separate functions for TypeScript (`generateTs`), JavaScript (`generateJs`), and declaration files (`generateDts`). See the [plugin docs](https://github.com/bufbuild/protobuf-es/blob/main/docs/writing_plugins.md) for more information on usage. ## Enhancements * Add plugin example for creating a Twirp client by @smaye81 #250 * Export printable type by @fubhy #255 * Extend documentation for PlainMessage and PartialMessage by @timostamm #248 * Add convenience functions for retrieving custom options by @smaye81 #244 * Clean up descriptor discrimination by @timostamm #233 * Add a plugin option to keep empty files by @timostamm #229 * Add the option to transpile target files by @smaye81 #228 ## Bugfixes * Fix TypeScript file generation bug by @smaye81 #253 * Fix: arbitrary imports by @fubhy #254 ## New Contributors @fubhy made their first contributions in #254 and #255.
This release includes the following: ## 🚨 Breaking Changes 🚨 - #233 - If you have been inspecting fields (`DescField`) from createDescriptorSet(), you will need to update your code to use the new `fieldKind` discriminator. The `kind` property no longer contains values such as `map_field` and `message_field` for their respective types of `DescField`. Instead, a new type has been added named `fieldKind`, which allows you to further identify the kind of field a `DescField` represents (`map`, `enum`, `message`, etc.) - #228 - If you have been using `createEcmaScriptPlugin` to create your own plugin, the signature has changed. Previously, the function accepted a single generator function for generating your output files. This has been split up into separate functions for TypeScript (`generateTs`), JavaScript (`generateJs`), and declaration files (`generateDts`). See the [plugin docs](https://github.com/bufbuild/protobuf-es/blob/main/docs/writing_plugins.md) for more information on usage. ## Enhancements * Add plugin example for creating a Twirp client by @smaye81 #250 * Export printable type by @fubhy #255 * Extend documentation for PlainMessage and PartialMessage by @timostamm #248 * Add convenience functions for retrieving custom options by @smaye81 #244 * Clean up descriptor discrimination by @timostamm #233 * Add a plugin option to keep empty files by @timostamm #229 * Add the option to transpile target files by @smaye81 #228 ## Bugfixes * Fix TypeScript file generation bug by @smaye81 #253 * Fix: arbitrary imports by @fubhy #254 ## New Contributors @fubhy made their first contributions in #254 and #255.
This adds the ability to transpile generated
.ts
files into.js
and/or.d.ts
files. Users can provide the following 3 functions to generate code in their plugin:generateTs
generateJs
generateDts
The
generateTs
function is required, but the latter two are optional. If one or the other (or both) are not provided, then the framework will auto-transpile the generated TypeScript files to generate the desired code. Note that this is all dependent on the provided target outs. For example, iftarget=js
and nogenerateJs
orgenerateDts
is provided, the framework will only transpile JavaScript files (ignoring declaration files). In essence, the framework will only transpile files if needed and even then, will only transpile the ones being requested.It is worth noting that transpilation is an expensive process so if performance is a concern, plugin authors should pass all 3 functions as the plugin code generation process is much faster (
protoc-gen-es
uses this approach).When auto-transpiling, the framework uses an older, pinned version of TypeScript for stability (at press time
4.5.2
). The compiler options used are intentionally lenient so that the odds of generating code under most circumstances are high. If this is not desirable for plugin authors, they also have the option to provide their owntranspile
function as part of the plugin initialization configuration. If they provide their own, then thistranspile
function will be invoked instead and the framework's transpilation process will be bypassed.For an example of implementing a transpiler, see
packages/protoplugin/src/ecmascript/transpile.ts
.