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

Allow custom import prefix #992

Open
DrBlury opened this issue Oct 18, 2024 · 4 comments
Open

Allow custom import prefix #992

DrBlury opened this issue Oct 18, 2024 · 4 comments

Comments

@DrBlury
Copy link

DrBlury commented Oct 18, 2024

With Deno 2 comes support for NPM packages.
I would like to use the generated code in my Deno 2 Project but it creates the imports without the npm: prefix. Editing this in manually works no issues.

Providing an optional import prefix would resolve this issue.
I understand that this is not a bug but I think this would benefit everyone using Deno 2 in the future.

@lenaramisch
Copy link

Great idea! We are facing the same problem while switching our services from nodejs to deno2. An optional import prefix would definitely help! 👍

@TheSortex
Copy link

TheSortex commented Oct 18, 2024

I support this idea. Helps us too!

@timostamm
Copy link
Member

This is about the npm-specifier for import statements, as in:

import express from "npm:[email protected]";

And the goal would be to change generated imports for the runtime library:

import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1";
import type { UInt32Value } from "@bufbuild/protobuf/wkt";

To... what exactly?

Should it be npm:@bufbuild/protobuf/codegenv1, or npm:@bufbuild/protobuf/[email protected] or npm:@bufbuild/[email protected]/codegenv1?

@DrBlury
Copy link
Author

DrBlury commented Oct 18, 2024

@timostamm Adding a prefix via options for the protoc-gen-es plugin would do the trick and would be flexible for the future. Default empty string.

So option 1 would be perfect! :)

version: v2
inputs:
  - directory: proto
plugins:
  - local: protoc-gen-es
    opt: 
      - target=ts
      - json_types=false
      - import_prefix='npm:'
    out: src/domain/model

should be enough. The imports which work are the following:

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

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

No branches or pull requests

4 participants