Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevina
Copy link

@kevina kevina commented Sep 10, 2018

gx-go rewrite is now recursive, that is it doesn't require all the packages used as imports be listed in package.json. However, gx-go rewrite <arg> ... is not. This can create problems when trying rewrite a dep, used but not specified in package.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.

'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.
@kevina kevina changed the title Fix gx-go rewrite behaviour when argumts are provided Fix gx-go rewrite behaviour when arguments are provided Sep 10, 2018
Copy link
Collaborator

@schomatis schomatis left a 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 {
Copy link
Collaborator

@schomatis schomatis Oct 5, 2018

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")
Copy link
Collaborator

@schomatis schomatis Oct 5, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants