Skip to content

Commit b0a7aa8

Browse files
authored
Add support for ignoring modules when syncing (#143)
1 parent 416feff commit b0a7aa8

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 1.16.0
2+
--------------
3+
* Add support for ignoring modules when syncing (#143)
4+
15
Version 1.15.1
26
--------------
37
* Correctly compute visibility of target given a child package wildcard (#141)

PUKU_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.1
1+
1.16.0

config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type Config struct {
4343
Stop *bool `json:"stop"`
4444
EnsureSubincludes *bool `json:"ensureSubincludes"`
4545
ExcludeBuiltinKinds []string `json:"excludeBuiltinKinds"`
46+
// This field allows skipping syncing certain packages into the BUILD file as go_repo targets,
47+
// Which can help deal with transitive dependencies that are not actually needed.
48+
IgnoreModulesForSync []string `json:"ignoreModulesForSync"`
4649
}
4750

4851
// TODO we should reload this during plz watch so this probably needs to become a member of Update
@@ -209,3 +212,10 @@ func (c *Config) GetKind(kind string) *kinds.Kind {
209212
}
210213
return nil
211214
}
215+
216+
func (c *Config) GetIgnoreModulesForSync() []string {
217+
if c.base != nil {
218+
return append(c.IgnoreModulesForSync, c.base.GetIgnoreModulesForSync()...)
219+
}
220+
return c.IgnoreModulesForSync
221+
}

sync/sync.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,17 @@ func (s *syncer) syncModFile(conf *config.Config, file *build.File, existingRule
122122
}
123123
}
124124

125+
ignoredModules := map[string]bool{}
126+
for _, mod := range conf.GetIgnoreModulesForSync() {
127+
ignoredModules[mod] = true
128+
}
129+
125130
// Check all modules listed in go.mod
126131
for _, req := range f.Require {
132+
if ignoredModules[req.Mod.Path] {
133+
continue
134+
}
135+
127136
// Find any matching replace directive
128137
var matchingReplace *modfile.Replace
129138
for _, replace := range f.Replace {

0 commit comments

Comments
 (0)