Repository navigation
Treat the module as the main module with -main - #44
logica0419 wants to merge 7 commits into
Conversation
2475ed2 to
3ec0d75
Compare
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
3ec0d75 to
8aff22d
Compare
bobg
left a comment
There was a problem hiding this comment.
Thank you for another high-quality contribution! This time I have a couple of changes to request.
First, according to the docs for modfile, the choice of Parse or ParseLax depends mainly on whether the module in question is the "main" one or not, and applies to exclude directives as well (and possibly others), not just replace directives. As such, it seems to me that the option we want is not whether to handle replace directives but, more broadly, whether to treat the module as the "main" one. (Default: false.) How do you feel about revising this PR to do that?
Second, you've added logic that chooses between a call to scanDep and scanLocalDep. Could you recast that as a choice between using a local and non-local implementation of the depScanner interface?
| if err := s.scanDep(r.Mod); err != nil { | ||
|
|
||
| mod := r.Mod | ||
| if !s.IgnoreReplace && len(f.Replace) > 0 { |
There was a problem hiding this comment.
Please avoid deeply nested if conditions. This is better:
if s.IgnoreReplace {
continue
}
if len(f.Replace) == 0 {
continue
}
rep := findReplace(f.Replace, mod)
if rep == nil {
continue
}
...etc...Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
|
@bobg
I wasn't familiar with the criteria for choosing between Parse and ParseLax, so I looked into them. |
replace directives when scanning dependenciesThere was a problem hiding this comment.
🟡 Changes recommended
Regression tests cover only local-directory replacements, leaving replacement path/version selection, resulting Go minimums, and exact-version versus wildcard precedence unverified.
1 open issue
What changed in this PR
Adds opt-in main-module handling to mingo, addressing #43 by honoring replace directives during dependency scanning while preserving the default behavior.
Changes:
- Adds the CLI
-mainflag and libraryScanner.Mainoption. - Resolves replacements to local directories or alternate module versions.
- Documents the option and adds regression tests for local replacements and default behavior.
| File | Description |
|---|---|
| testdata/issue43/main.go | Adds a fixture importing the replaced dependency. |
| testdata/issue43/localdep/go.mod | Declares the local replacement module. |
| testdata/issue43/localdep/dep.go | Provides the local dependency package. |
| testdata/issue43/go.mod | Configures the local replacement fixture. |
| scan.go | Adds the Scanner.Main option. |
| regression_test.go | Tests local replacement handling and default behavior. |
| Readme.md | Documents -main and replacement behavior. |
| deps.go | Parses and resolves replacements in main-module mode. |
| cmd/mingo/main.go | Connects the -main flag to the scanner. |
Review effort: Balanced
| eff.Version = mv.Version | ||
| } | ||
|
|
||
| return eff, s.depScanner |
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
bobg
left a comment
There was a problem hiding this comment.
My turn to apologize for the delay in reviewing these latest changes. I've been trying to figure out what's been nagging at me about this PR.
I realized it's the way that this replace logic - while perfectly fine on its own, as near as I can tell - is only a piece of the full dependency-resolution process that the real Go toolchain follows. To do it the right way requires also paying attention to exclude directives, any go.work file that may exist, etc.
I'm not aware of any standard(ish) library that does all this, but I do know of a command that does: go list -deps -json. I have taken the liberty of rewriting Mingo's dependency-scanning logic in terms of go list at #45.
As such I think this PR is now obsolete; my apologies, and my thanks, for your contribution and patience. Can I further prevail upon you to take a look at the new PR?
Fixes #43
With -main,
scanDeps()now parses go.mod withmodfile.Parse()and followsreplacedirectives.Default stays
ParseLax().