go work sync
cmp a/go.mod a/want_go.mod
cmp b/go.mod b/want_go.mod

-- go.work --
go 1.18

use (
	./a
	./b
)

-- a/go.mod --
go 1.18

module example.com/a

require (
	example.com/p v1.0.0
	example.com/q v1.1.0
	example.com/r v1.0.0
)

replace (
	example.com/p => ../p
	example.com/q => ../q
	example.com/r => ../r
)
-- a/want_go.mod --
go 1.18

module example.com/a

require (
	example.com/p v1.1.0
	example.com/q v1.1.0
)

replace (
	example.com/p => ../p
	example.com/q => ../q
	example.com/r => ../r
)
-- a/a.go --
package a

import (
	"example.com/p"
	"example.com/q"
)

func Foo() {
	p.P()
	q.Q()
}
-- b/go.mod --
go 1.18

module example.com/b

require (
	example.com/p v1.1.0
	example.com/q v1.0.0
)

replace (
	example.com/p => ../p
	example.com/q => ../q
)
-- b/want_go.mod --
go 1.18

module example.com/b

require (
	example.com/p v1.1.0
	example.com/q v1.1.0
)

replace (
	example.com/p => ../p
	example.com/q => ../q
)
-- b/b.go --
package b

import (
	"example.com/p"
	"example.com/q"
)

func Foo() {
	p.P()
	q.Q()
}
-- p/go.mod --
go 1.18

module example.com/p
-- p/p.go --
package p

func P() {}
-- q/go.mod --
go 1.18

module example.com/q
-- q/q.go --
package q

func Q() {}
-- r/go.mod --
go 1.18

module example.com/r
-- r/q.go --
package r

func R() {}