-
Notifications
You must be signed in to change notification settings - Fork 3k
Resolve git dependencies with semver ranges #15308
Conversation
Thanks for getting this started! This is something the CLI team has wanted for a while now, but hasn't had the time to tackle themselves. Your approach seems sound, and is a good start. Part of the reason why the team hasn't gotten around to this is the large number of edge cases it exposes. This is also why I've marked this PR as "breaking", and why this probably won't land until around the time The most significant issue is that the DSL used for expressing SemVer ranges is inclusive enough that it will almost certainly collide with real repo commitishes (for instance, both There seem to be a few ways to work around this:
On the whole, given the priorities of the project, #1 is better. Even with that approach, this is still a breaking change, because it changes how What do you think? (In addition, whatever we decide to do, the |
Thanks for the reply! The current implementation definitely would break semver-valid branch names, in the case matching tags also exist. I did see some other suggestions in the various issue threads that I liked, which would solve the issue: Currently the We could instead borrow from the syntax of
How does that sound? |
It has the same problem as my approach #2, in that it will cause all older versions of npm to choke on dependencies so specified. So, I don't think it's an improvement over using an unlikely prefix. |
I would propose a third option:
This makes the only scenario where we pick the wrong thing be:
In that scenario we warn that we're picking the Because this approach biases toward branches/tags, it won't step on anyone's existing use cases. And If you said |
@othiym23 I agree it's not really an improvement on #2. I just thought it would be nicer syntax than a unlikely prefix, and would keep the semantics of the @iarna I do like the idea of making this Just Work for the majority of use cases. But, my only thought against it would be the added complexity of the resolution logic and potentially more edge cases which could be introduced. Using some variant of #1 would make it simpler to reason about, and more explicit that you are choosing to resolve semver. How much do we want to prioritize not breaking older versions of npm? The way I see it option #1 and #3 would result in older npm versions throwing some variant of this error: npm ERR! fatal: ambiguous argument '1.x': unknown revision or path not in the working tree.
npm ERR! Use '--' to separate paths from revisions, like this:
npm ERR! 'git <command> [<revision>...] -- [<file>...]' Option #2 or some variant of it would result in more undefined behavior. A quick test results in something like: npm ERR! fatal: remote error:
npm ERR! user/project@v1.x is not a valid repository name or when using npm ERR! enoent ENOENT: no such file or directory, open '/home/sankethkatta/user/project@v1.x' |
Looking through Bower's implementation, their logic goes like this:
So Bower seems to do the opposite of the third option, it biases towards semver over exact tags/branches. |
@sankethkatta I think the ultimate consensus on the cli team was that using an unlikely-to-be-in-use prefix on a comittish part of the specifier is the right answer, eg |
(Part of the thinking here is that npm really does work better with registry dependencies so while this is a use case we want to support, it's not a use case we want to encourage. As such having it be a bit ugly to use is perfectly ok.) |
Sounds good, I'll move forward on implementing with an unlikely prefix |
ba0f2d3
to
009dfe9
Compare
@iarna This should be ready to review. Let me know if I should expand on the documentation. I ended up choosing |
Bump, this is extremely important for corporate projects, relying on internal resources, that are updated regularly. |
Any news here? |
@StyleT we can't merge this until it's time for another major release, probably |
@zkat This is the best news I've heard all week. |
@AngefloMusic Whether or not the feature's there, you might want to consider some kind of private registry setup. Git support can never be nearly as fast as registry installs are. |
Should this now be closed due to #15666? |
@ljharb indeed! @sankethkatta this specific PR did not land because the changes that came with npm5 made the requirement completely different. That said, I linked this PR in the npm5 release notes, and attributed the feature to your name. Thank you for taking the time to figure this out and do the very important work of prototyping it and sussing out the specific API we needed for this. This is a feature a lot of people are excited about, and I'm really happy it was included in the release. Thank you. <3 |
Thanks @zkat! Much appreciated! I'm excited to start using it out :) |
Hey guys, so I'm a little confused now. Is it supported in npm5 or not and if so, how does it work? |
@krlwlfrt yes this is now supported in npm5. However, the docs have not been updated. For now, here are the docs from my diffs reproduced below: npm install
Installs the package from the hosted git provider, cloning it with
Git URLs as DependenciesGit urls can be of the form:
The In addition, a semver range may be used to resolve against git tags. In order to
|
Just to cross-reference with issue (#17190) Typing So... if you were to re-install a project you'd get a different version from what you actually specified. |
@sankethkatta where are you looking? I updated the docs for @kruncher cool. Nice catch 🙆 |
@zkat Ah missed it on the |
@sankethkatta aha, that's where that is! I'll totally take a PR to fix the latter, but I'd rather so the same kind of |
We use a private hosted gitlab-server and it doesn't work either with the latest npm or npm-canary. For example there is a tag on the Repo that ist name |
It's seems there is an issue with the semver feature using git urls, see #17621 |
It is working for me in npm v5.3.0 |
yarn will support semver on git repositories but without |
to clarify: it resolves tags first, branches second, and at last it tries semver on tags and branches, that's why it isn't breaking change and one is able to resolve any tag/branch |
Fixes: #3328
This would allow git dependencies to use semver ranges for the
commit-ish
, which will be compared against semver-valid git tags.For example take a project with the following tags:
Then we can require it as a dependency as so (or using any of the other allowed syntax for git):
^1.0.0
will be recognized as a semver range bysemver.validRange()
.In this case
next
would be filtered out, as it is not a valid semver tag, as determined bysemver.valid()
.semver.maxSatisfying()
the range will resolve tov1.2.0
.Let me know if you think this is the right direction for this feature and I'll add more tests to thoroughly check the behavior.