-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix gx-go rewrite behaviour when arguments are provided #52
base: master
Are you sure you want to change the base?
Conversation
'gx-go rewrite' is now recursive when arguments are not specified, but when they are, it isn't. This can create a problem in dependency is not specified in package.json.
Before the errors where ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is by no means your responsibility but please add the PR description as part of the usage documentation of the gx-go rewrite
command since I wasn't even aware of what was the use case for adding arguments to that command (and I'm pretty sure many more users aren't).
main.go
Outdated
keepSet[arg] = struct{}{} | ||
} | ||
undo := c.Bool("undo") | ||
for a, b := range mapping { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename these variables to something more descriptive.
main.go
Outdated
return fmt.Errorf("%s not found", arg) | ||
keepSet[arg] = struct{}{} | ||
} | ||
undo := c.Bool("undo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this up and have buildRewriteMapping
and this added logic refer the local undo
variable.
gx-go rewrite
is now recursive, that is it doesn't require all the packages used as imports be listed inpackage.json
. However,gx-go rewrite <arg> ...
is not. This can create problems when trying rewrite a dep, used but not specified inpackage.json
.This fixed it by first creating the rewrite map then filtering map based on the arguments if specified.
This also means that it will not return an error if a package specified on the command line was not used as an import. However, I actually see that as a plus.
I needed this when discovering some bugs when pushing through the go-cid changes. I wanted to selectively rewrite all involved dependencies, but didn't want to pull in git versions of everything. This initially failed because some of the
package.json
files do not directly specify all imports used.This is a change in behavior, so if this will break things I can make it an option, but thought I didn't see a strong need to preserve the old behavior.
Also, the
--fix
option ignores both--dry-run
and any arguments. This should eventually be fixed but for now I just detected it and returned an error.