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 plugin option to add .js at end of imports #656

Open
Levyks opened this issue Aug 25, 2024 · 1 comment
Open

Add plugin option to add .js at end of imports #656

Levyks opened this issue Aug 25, 2024 · 1 comment

Comments

@Levyks
Copy link

Levyks commented Aug 25, 2024

Currently, protobuf-ts create files with imports like this:

// @generated by protobuf-ts 2.9.4
// @generated from protobuf file "connection_handler.proto" (package "myapp.connection_handler", syntax proto3)
// tslint:disable
import { Empty } from "./common";

However, when using type: "module" and depending on your tsconfig, you're forced to put the .js extension for it to work, would it be possible to add an option to the plugin to generate it like this?

// @generated by protobuf-ts 2.9.4
// @generated from protobuf file "connection_handler.proto" (package "myapp.connection_handler", syntax proto3)
// tslint:disable
import { Empty } from "./common.js";
@Levyks
Copy link
Author

Levyks commented Aug 25, 2024

In the meanwhile, if anyone is facing the same issue, I was able to get around it by installing replace-in-files-cli and doing this in my compile script:

{
  "scripts": {
    "compile:protos": "protoc --ts_out ./your_out_dir --proto_path ../proto ../proto/*.proto && replace-in-files --regex='import (.*?) from \"\\.\\/(.*?)\";' --replacement='import $1 from \"./$2.js\";' './your_out_dir/*.ts'"
  }
}

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

1 participant