Skip to content

Commit 8d84a65

Browse files
committed
Add experimental -M support for go import path overrides
1 parent 32f63ba commit 8d84a65

3 files changed

Lines changed: 59 additions & 21 deletions

File tree

docs/docs/configuration/plugin.mdx

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,51 +265,50 @@ protoc --go_temporal_opt=ignore-acronyms=AWS;SQL
265265
</TabItem>
266266
</Tabs>
267267

268-
### nexus
268+
### module-map [EXPERIMENTAL]
269269

270-
`bool`
270+
`[]string`
271271

272-
Enables experimental [Nexus generation](/docs/guides/nexus).
272+
Repeated set of `<proto_file>=<go_import_path>` (e.g. -Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb)
273273

274274
<Tabs>
275-
<TabItem value="nexus-buf" label="Buf">
275+
<TabItem value="module-map-buf" label="Buf">
276276
```yaml title="buf.gen.yaml"
277277
plugins:
278278
- plugin: go_temporal
279279
out: gen
280280
opt:
281-
- nexus=true
281+
- Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb
282282
strategy: all
283283
```
284284
</TabItem>
285-
<TabItem value="nexus-protoc" label="Protoc">
285+
<TabItem value="module-map-protoc" label="Protoc">
286286
```sh
287-
protoc --go_temporal_opt=nexus=trues
287+
protoc --go_temporal_opt=Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb
288288
```
289289
</TabItem>
290290
</Tabs>
291291

292-
### nexus-exclude-service-tags
292+
### nexus
293293

294-
`string`
294+
`bool`
295295

296-
Semicolon-delimited list of Nexus service tags to exclude from generation.
296+
Enables experimental [Nexus generation](/docs/guides/nexus).
297297

298298
<Tabs>
299-
<TabItem value="nexus-exclude-service-tags-buf" label="Buf">
299+
<TabItem value="nexus-buf" label="Buf">
300300
```yaml title="buf.gen.yaml"
301301
plugins:
302302
- plugin: go_temporal
303303
out: gen
304-
opt:
304+
opt:
305305
- nexus=true
306-
- nexus-exclude-service-tags=disabled;internal
307306
strategy: all
308307
```
309308
</TabItem>
310-
<TabItem value="nexus-exclude-service-tags-protoc" label="Protoc">
309+
<TabItem value="nexus-protoc" label="Protoc">
311310
```sh
312-
protoc --go_temporal_opt=nexus=true,nexus-exclude-service-tags=disabled;internal
311+
protoc --go_temporal_opt=nexus=trues
313312
```
314313
</TabItem>
315314
</Tabs>
@@ -339,27 +338,27 @@ protoc --go_temporal_opt=nexus=true,nexus-exclude-operation-tags=disabled;intern
339338
</TabItem>
340339
</Tabs>
341340

342-
### nexus-include-service-tags
341+
### nexus-exclude-service-tags
343342

344343
`string`
345344

346-
Semicolon-delimited list of Nexus service tags to include in generation.
345+
Semicolon-delimited list of Nexus service tags to exclude from generation.
347346

348347
<Tabs>
349-
<TabItem value="nexus-include-service-tags-buf" label="Buf">
348+
<TabItem value="nexus-exclude-service-tags-buf" label="Buf">
350349
```yaml title="buf.gen.yaml"
351350
plugins:
352351
- plugin: go_temporal
353352
out: gen
354353
opt:
355354
- nexus=true
356-
- nexus-include-service-tags=enabled;internal
355+
- nexus-exclude-service-tags=disabled;internal
357356
strategy: all
358357
```
359358
</TabItem>
360-
<TabItem value="nexus-include-service-tags-protoc" label="Protoc">
359+
<TabItem value="nexus-exclude-service-tags-protoc" label="Protoc">
361360
```sh
362-
protoc --go_temporal_opt=nexus=true,nexus-include-service-tags=enabled;internal
361+
protoc --go_temporal_opt=nexus=true,nexus-exclude-service-tags=disabled;internal
363362
```
364363
</TabItem>
365364
</Tabs>
@@ -389,6 +388,31 @@ protoc --go_temporal_opt=nexus=true,nexus-include-operation-tags=enabled;interna
389388
</TabItem>
390389
</Tabs>
391390

391+
### nexus-include-service-tags
392+
393+
`string`
394+
395+
Semicolon-delimited list of Nexus service tags to include in generation.
396+
397+
<Tabs>
398+
<TabItem value="nexus-include-service-tags-buf" label="Buf">
399+
```yaml title="buf.gen.yaml"
400+
plugins:
401+
- plugin: go_temporal
402+
out: gen
403+
opt:
404+
- nexus=true
405+
- nexus-include-service-tags=enabled;internal
406+
strategy: all
407+
```
408+
</TabItem>
409+
<TabItem value="nexus-include-service-tags-protoc" label="Protoc">
410+
```sh
411+
protoc --go_temporal_opt=nexus=true,nexus-include-service-tags=enabled;internal
412+
```
413+
</TabItem>
414+
</Tabs>
415+
392416
### patches
393417

394418
`string`

internal/plugin/parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func parse(p *Plugin) (*Manifest, error) {
130130
}
131131

132132
for _, file := range p.Files {
133+
if goImportPath, ok := p.moduleMap[string(file.Desc.FullName())]; ok {
134+
file.GoImportPath = protogen.GoImportPath(goImportPath)
135+
}
133136
if !file.Generate {
134137
continue
135138
}

internal/plugin/plugin.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Config struct {
4343
EnableDebugLogging bool
4444
EnablePatchSupport bool
4545
EnableXNS bool
46+
ModuleMap []string
4647
NexusEnabled bool
4748
NexusExcludeOperationTags string
4849
NexusIncludeOperationTags string
@@ -66,6 +67,7 @@ type Plugin struct {
6667
excludeServiceTags map[string]struct{}
6768
includeOperationTags map[string]struct{}
6869
includeServiceTags map[string]struct{}
70+
moduleMap map[string]string
6971
}
7072

7173
func Run(commit, version string) {
@@ -88,6 +90,7 @@ func New(commit, version string) *Plugin {
8890
flags.BoolVar(&cfg.EnablePatchSupport, "enable-patch-support", false, "enables support for alta/protopatch renaming")
8991
flags.BoolVar(&cfg.EnableXNS, "enable-xns", false, "enable experimental cross-namespace workflow client")
9092
flags.StringVar(&cfg.IgnoreAcronyms, "ignore-acronyms", "", "semicolon-delimited string of acronyms to ignore when converting generated output to camel case")
93+
flags.StringArrayVarP(&cfg.ModuleMap, "module-map", "M", []string{}, "[EXPERIMENTAL] list of <proto_file>=<go_import_path> (e.g. -Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb)")
9194
flags.BoolVar(&cfg.NexusEnabled, "nexus", false, "enable nexus handler generation")
9295
flags.StringVar(&cfg.NexusExcludeOperationTags, "nexus-exclude-operation-tags", "", "semicolon-delimited list of operation tags to exclude from nexus generation")
9396
flags.StringVar(&cfg.NexusIncludeOperationTags, "nexus-include-operation-tags", "", "semicolon-delimited list of operation tags to include in nexus generation")
@@ -116,6 +119,14 @@ func (p *Plugin) Run(plugin *protogen.Plugin) (err error) {
116119
plugin.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO3
117120
plugin.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2023
118121

122+
for _, m := range p.cfg.ModuleMap {
123+
fields := strings.SplitN(m, "=", 2)
124+
if len(fields) != 2 {
125+
return fmt.Errorf("invalid module map: %s", m)
126+
}
127+
p.moduleMap[fields[0]] = fields[1]
128+
}
129+
119130
p.Plugin = plugin
120131
services, err := parse(p)
121132
if err != nil {

0 commit comments

Comments
 (0)