-
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
link: override dependency versions with the current dependent package #51
link: override dependency versions with the current dependent package #51
Conversation
@Stebalien PTAL. Although sub-optimal this still seems like a useful flag while developing across packages (especially for new developers who may not be familiarized with the |
(Another possible enhancement for this PR or a new one: detect already linked packages and un-link+link them again. At the moment it would seem that the |
link.go
Outdated
@@ -53,21 +57,33 @@ unlinked QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw /home/user/go/src/github | |||
Name: "a,all", | |||
Usage: "Remove all existing symlinks and reinstate the gx packages. Use with -r.", | |||
}, | |||
cli.StringFlag{ | |||
Name: "p,parent", |
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.
I'd leave this out. We can consider adding a -C
flag (like git) later but that's leave that until we need it (and then make it a global option).
link.go
Outdated
@@ -19,30 +19,34 @@ var LinkCommand = cli.Command{ | |||
Usage: "Symlink packages to their dvcsimport repos, for local development.", | |||
Description: `gx-go link eases local development by symlinking actual workspace repositories on demand. | |||
|
|||
Example workflow: | |||
Links the specified dependency package (by name or hash) used by the | |||
parent package (in the CWD or specified by --parent). The link is done |
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.
I'd just say "the current" package and drop the "parent" package language.
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.
I'd prefer to maintain the parent-child relationship concept, because everything is a package here but, depending on where you're looking from (in what part of the code you're in), that package is either a dependency (and that distinction is important because a dependency in a package.json
doesn't have the same information as the actual package) or the package that's importing that dependency. The term "current" doesn't seem to carry that relationship meaning, is there another term you'd prefer?
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.
When I'm using GX, I'm usually working on a gx package. The "current" package is the package I'm currently working on.
For example:
gx-go link
replaces the target gx package (either by name or hash) with a symlink to the appropriate dvcs repo in your GOPATH. To make this "symlinked" repo usable as a gx package,gx-go link
rewrites the target package's dvcs imports using the target package'spackage.json
. Unfortunately, this can cause build errors in packages depending on this package if these dependent packages specify alternative, conflicting dependency versions. We can work around this by askinggx
to rewrite the target package using dependencies from the current package (the package you're trying to build) first, falling back on the target package'spackage.json
file. We can do this by passing the--deps=mine
flag.
That is a bit wordy and you're right, "current" may not be quite right.
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 leave it at "the current dependent package". Nice text (I like it wordy :), I'll add it to the usage doc.
link.go
Outdated
linked QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw /home/user/go/src/github.com/multiformats/go-multihash | ||
linked QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52 /home/user/go/src/github.com/ipfs/go-log | ||
If the dependency versions of the parent package don't match the ones in | ||
the dependency being linked use the --sync flag to resolve the conflicts |
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.
"linked, use the"
link.go
Outdated
linked package). Note that this won't sync dependencies between different | ||
packages being linked. (Note: Make sure all the dependencies of the parent | ||
package are available to build its rewrite map if using --sync, e.g., by | ||
calling 'gx install --global'.) |
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 has a lot of parentheses. It'll probably read better if we're more direct. I.e., instead of saying "resolve the conflicts (...how it does it...", just say what it does.
link.go
Outdated
}, | ||
cli.BoolFlag{ | ||
Name: "s,sync", | ||
Usage: "Synchronize the dependencies of the linked package with the ones of its parent.", |
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.
Again, I'd like to get rid of the "parent" terminology (packages have reverse-dependencies and dependent packages but they don't really have "parents").
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.
Would you prefer to use "dependent"?
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.
I would, but then you have to answer the question "which dependent". The answer is "the current one".
link.go
Outdated
Usage: "Specify the path of the parent package of the linked dependency (default: CWD).", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "s,sync", |
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.
"sync" feels like like the wrong term here (feels bidirectional). Maybe "--override-deps"? We could even go for --deps=mine
(eventually adding --deps=theirs
).
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.
Yes, I don't really like "sync" but couldn't come up with something better. Let's go with --deps=
and use the term that will replace "parent" here, e.g., --deps=<package-that-is-including-this-package>
.
We should probably do that but we can do it in a new patch. |
Thinking about this, we could actually use the dependencies specified in the original gxed package (the one we're replacing with a symlink). That would be the most conservative approach (effectively "downgrading" dependencies. The only difference is that, if the target repo has added a new dependency also present in the current/parent package, we'll use the version in the target repo, not the current/parent. However, using the package.json of the current/parent isn't foolproof either (e.g., the target could have added a dependency that we don't have, one that depends on packages we do depend on but depends on different versions). The other approach would be to do a fake gx-workspace update. However, that's way more work. |
Let's have both options: |
In this case, the other strategy would really be "original" or "replaced" (dependency is could either mean the dependency that I'm replacing/linking or the one I'm linking to). I'm really confused why you feel so strongly about keeping the terminology absolute. Personally, I find it extremely confusing (depending on the context). When I see an absolute term, I think "oh, they must not mean my current package, otherwise they would have just said that". Specifically, when I see "dependent", my first thought is "which dependent?". |
Ok, let me rethink that and get back to you. I think that my main objection is about the code and not the UX. From the point of the user who just runs |
Ah, yes, that's totally reasonable. |
(This patch changes the current API.) Add `--override-deps` flag to (in the case a of a dependency version mismatch) replace the dependency version of the target package with the one in the current dependent package. (Most of the implementation logic for this feature had to be added to the `post-install` hook which also has a new `--override-deps` flag.) Require the command to be run inside a package. Refactor the link/unlink functions. Give more visibility to the options that allows specifying a dependency to link by its name.
@Stebalien Could you take another look please? Changed the terminology to target/current (using your command description) and renamed the option |
1 similar comment
Ok, this looks correct. Sorry this took so long, I'm very unsure of how any of this code works so I kept on punting. |
This PR extracts the
--sync
feature from #48 (now named--override-deps
) without thevendor/
support (that has some implementation problems, see #46 (comment)).As with the imported PR, this command now requires
gx-go link
to be run inside the parent package of the dependency even though the link is still done to the global workspace. This breaks API but it makes it easier to reason about the code and about the link being done, and in most use cases the developer was already calling the command from a package anyway.Closes #46.