ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

Feature: Importmap option

Open pcj opened this issue 3 years ago • 1 comments

Currently, a proto import such as import google/protobuf/empty.proto generates an import statement like:

import { Empty } from "../../../../../google/protobuf/empty";

This assumes the file layout has ../../../../../google/protobuf/empty.ts in the correct place. However, it is desirable to map this to a different location such as ../../../../../external/com_google_protobuf/google/protobuf/empty.ts, or even some node_module like @google/wellknowntypes...

protoc-gen-go has a similar need for mapping imports and supports the M option, used like --go_opt=Mtest.proto=github.com/example.com/test.

emitImportedFiles=true is a possible workaround, but has other drawbacks and cannot be used in our case.

I propose a similar option, for example --ts_opt=M./google/protobuf/empty=./external/com_google_protobuf/google/protobuf/empty that would generate:

import { Empty } from "../../../../../external/com_google_protobuf/google/protobuf/empty";

This would involve PRs to both ts-proto and ts-poet.

Would you be amenable to such PRs?

pcj avatar Jun 14 '22 21:06 pcj

I also need this option, particularly because I import files from vendor/ and want to map the vendor/ path to the repo root.

paralin avatar Jun 15 '22 04:06 paralin

:tada: This issue has been resolved in version 1.126.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

stephenh avatar Sep 21 '22 00:09 stephenh