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

Add GeneratedFile.jsDoc() and other features to @bufbuild/protoplugin #649

Merged
merged 10 commits into from Dec 8, 2023

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented Dec 7, 2023

Since we added exportDecl to to GeneratedFile in #648, it makes sense to add some more convenience methods to make the features more discoverable and require less imports:

  /**
   * Create a string literal.
   */
  string(string: string): Printable;

  /**
   * Create a JSDoc comment block with the given text. Line breaks and white-space
   * stay intact.
   */
  jsDoc(text: string, indentation?: string): JSDocBlock;

  /**
   * Create a JSDoc comment block for the given message, enumeration, or other
   * descriptor. The comment block will contain the original comments from the
   * protobuf source, and annotations such as `@generated from message MyMessage`.
   */
  jsDoc(
    desc: Exclude<AnyDesc, DescFile | DescExtension>,
    indentation?: string,
  ): JSDocBlock;
  • GeneratedFile.string replaces the now deprecated literalString from @bufbuild/protoplugin/ecmascript.
  • GeneratedFile.jsDoc replaces the now deprecated makeJsDoc and createJsDocBlock from @bufbuild/protoplugin/ecmascript.
  • GeneratedFile.export is now deprecated, as it turned out that it has little use in practice. Instead, we export createImportSymbol from @bufbuild/protoplugin/ecmascript now, which is much more flexible.
  • Schema has always been available from @bufbuild/protoplugin and @bufbuild/protoplugin/ecmascript, even though it is very much specific to ECMAScript. The former export is now deprecated.

As a diff, these are the changes you should make as a plugin author, to avoid the deprecated types:

- import { Schema } from "@bufbuild/protoplugin";
+ import { Schema } from "@bufbuild/protoplugin/ecmascript";

- import { makeJsDoc, createJsDocBlock } from "@bufbuild/protoplugin/ecmascript";
- import { literalString } from "@bufbuild/protoplugin/ecmascript";

- f.print('const typeName = ', literalString(message.typeName), ';');
+ f.print('const typeName = ', f.string(message.typeName), ';');

- f.print(makeJsDoc(enumeration));
+ f.print(f.jsDoc(enumeration));

timostamm added a commit to connectrpc/connect-es that referenced this pull request Dec 7, 2023
@timostamm timostamm merged commit 360bdb9 into main Dec 8, 2023
6 checks passed
@timostamm timostamm deleted the tstamm/protoplugin-improvements branch December 8, 2023 11:56
@smaye81 smaye81 mentioned this pull request Dec 12, 2023
smaye81 added a commit that referenced this pull request Dec 12, 2023
## 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
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

Successfully merging this pull request may close these issues.

None yet

2 participants