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

Support target prefix in plugin option rewrite_imports #998

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented Oct 28, 2024

With the plugin option rewrite_imports, it's possible to modify generated import paths - more details in #947 (comment).

It currently isn't possible to specify a target package with a colon:

protoc-gen-es: invalid option "rewrite_imports=@bufbuild/protobuf:npm:@bufbuild/protobuf": must be in the form of <pattern>:<target>

This relaxes the check to accept one or more colons in the target. As a result, it is now possible to add an "npm:" specifier to generated imports from @bufbuild/protobuf for Deno:

version: v2
plugins:
  - local: protoc-gen-es
    opt:
      - target=ts
      - rewrite_imports=@bufbuild/protobuf:npm:@bufbuild/protobuf
      - rewrite_imports=@bufbuild/protobuf/codegenv1:npm:@bufbuild/protobuf/codegenv1
    out: src/gen

This generates imports with the prefixes:

import { fileDesc, messageDesc } from "npm:@bufbuild/protobuf/codegenv1";
import type { Message } from "npm:@bufbuild/protobuf";
...

Closes #992.

@timostamm timostamm merged commit 1270562 into main Oct 28, 2024
23 checks passed
@timostamm timostamm deleted the tstamm/Update-plugin-option-rewrite_imports-to-support-target-prefix branch October 28, 2024 14:22
@smaye81 smaye81 mentioned this pull request Oct 28, 2024
smaye81 added a commit that referenced this pull request Oct 28, 2024
## What's Changed
* Support target prefix in plugin option rewrite_imports @timostamm in
#998

**Full Changelog**:
v2.2.0...v2.2.1
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.

Allow custom import prefix
2 participants