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

Feature: Importmap option #596

Closed
pcj opened this issue Jun 14, 2022 · 2 comments · Fixed by #672
Closed

Feature: Importmap option #596

pcj opened this issue Jun 14, 2022 · 2 comments · Fixed by #672
Labels

Comments

@pcj
Copy link

pcj commented Jun 14, 2022

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?

@paralin
Copy link
Collaborator

paralin commented Jun 15, 2022

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

iamricard added a commit to iamricard/ts-proto that referenced this issue Sep 20, 2022
This commit adds a new feature that aims to provide the same
functionality as `M` for the go compiler (https://developers.google.com/protocol-buffers/docs/reference/go-generated#package).
I opted for not modifying the type map, because we'll also want to
figure out whether or not we need to generate the file, so we'll be
acessing the `options.M` everywhere and I found it less confusing to
always get mapping information from `options.M` instead of `options.M`
or the type map depending on the decision that we're making (we need to
know if we need to do a relative import or just the raw provided
import too).

Fixes stephenh#596
iamricard added a commit to iamricard/ts-proto that referenced this issue Sep 20, 2022
This commit adds a new feature that aims to provide the same
functionality as `M` for the go compiler (https://developers.google.com/protocol-buffers/docs/reference/go-generated#package).
I opted for not modifying the type map, because we'll also want to
figure out whether or not we need to generate the file, so we'll be
acessing the `options.M` everywhere and I found it less confusing to
always get mapping information from `options.M` instead of `options.M`
or the type map depending on the decision that we're making (we need to
know if we need to do a relative import or just the raw provided
import too).

Fixes stephenh#596
iamricard added a commit to iamricard/ts-proto that referenced this issue Sep 20, 2022
This commit adds a new feature that aims to provide the same
functionality as `M` for the go compiler (https://developers.google.com/protocol-buffers/docs/reference/go-generated#package).
I opted for not modifying the type map, because we'll also want to
figure out whether or not we need to generate the file, so we'll be
acessing the `options.M` everywhere and I found it less confusing to
always get mapping information from `options.M` instead of `options.M`
or the type map depending on the decision that we're making (we need to
know if we need to do a relative import or just the raw provided
import too).

Fixes stephenh#596
iamricard added a commit to iamricard/ts-proto that referenced this issue Sep 20, 2022
This commit adds a new feature that aims to provide the same
functionality as `M` for the go compiler (https://developers.google.com/protocol-buffers/docs/reference/go-generated#package).
I opted for not modifying the type map, because we'll also want to
figure out whether or not we need to generate the file, so we'll be
accessing the `options.M` everywhere and I found it less confusing to
always get mapping information from `options.M` instead of `options.M`
or the type map depending on the decision that we're making (we need to
know if we need to do a relative import or just the raw provided
import too).

Fixes stephenh#596
stephenh pushed a commit that referenced this issue Sep 21, 2022
This commit adds a new feature that aims to provide the same
functionality as `M` for the go compiler (https://developers.google.com/protocol-buffers/docs/reference/go-generated#package).
I opted for not modifying the type map, because we'll also want to
figure out whether or not we need to generate the file, so we'll be
accessing the `options.M` everywhere and I found it less confusing to
always get mapping information from `options.M` instead of `options.M`
or the type map depending on the decision that we're making (we need to
know if we need to do a relative import or just the raw provided
import too).

Fixes #596
stephenh pushed a commit that referenced this issue Sep 21, 2022
# [1.126.0](v1.125.0...v1.126.0) (2022-09-21)

### Features

* **options:** adds protoc-gen-go-like M option ([#672](#672)) ([9304e5d](9304e5d)), closes [#596](#596)
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 1.126.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants