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

Added support for cjs output #303

Merged
merged 3 commits into from
Dec 14, 2023
Merged

Added support for cjs output #303

merged 3 commits into from
Dec 14, 2023

Conversation

paul-sachs
Copy link
Collaborator

@paul-sachs paul-sachs commented Dec 13, 2023

Fixes #297

Add support for CommonJS with the new plugin option:

js_import_style

By default, protoc-gen-connect-query(and all other plugins based on @bufbuild/protoplugin) generate ECMAScript import and export statements. For use cases where CommonJS is difficult to avoid, this option can be used to generate CommonJSrequire() calls.

Example buf.gen.yaml

version: v1
plugins:
  - plugin: es
    out: src/gen
    opt: js_import_style=legacy_commonjs
  - plugin: connect-query
    out: src/gen
    opt: js_import_style=legacy_commonjs

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, just one suggestion, see below.

Can we give an example buf.gen.yaml in the next release notes, similar to this one?

packages/protoc-gen-connect-query/snapshots/buf.gen.yaml Outdated Show resolved Hide resolved
@paul-sachs paul-sachs merged commit 7ee2820 into main Dec 14, 2023
5 checks passed
@paul-sachs paul-sachs deleted the psachs/commonjs-option branch December 14, 2023 14:40
@paul-sachs paul-sachs mentioned this pull request Dec 14, 2023
paul-sachs added a commit that referenced this pull request Dec 14, 2023
## What's Changed
* Update imports to include file extensions by @paul-sachs in
#299 and
#307
* Added support for cjs output by @paul-sachs in
#303
* Loosen peer dependency requirement by @paul-sachs in
#306

## CJS output

By default,
[protoc-gen-connect-query](https://www.npmjs.com/package/@connectrpc/protoc-gen-connect-query)
(and all other plugins based on
[@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
generate ECMAScript `import` and `export` statements. For use cases
where CommonJS is difficult to avoid, a new plugin option has been added
named `js_import_style` which can be used to generate CommonJS
`require()` calls.

Here is an example
[buf.gen.yaml](https://buf.build/docs/configuration/v1/buf-gen-yaml):

```yaml
version: v1
plugins:
  # You'll need @bufbuild/protoc-gen-es v1.6.0 or later
  - plugin: es
    out: src/gen
    opt: js_import_style=legacy_commonjs
  - plugin: protoc-gen-connect-query
    out: src/gen
    opt: js_import_style=legacy_commonjs
```

To view the full PR, see **Added support for cjs output** by @paul-sachs
in #303

**Full Changelog**:
v1.0.0...v1.1.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.

Support CommonJS in protoc-gen-connect-query
2 participants