Update command: not working at all #1054

Closed
bdkjones opened this Issue Jan 18, 2014 · 25 comments

Projects

None yet
@bdkjones

Environment:

Mac OS 10.9.1, Bower 1.2.8, Node 0.10.20

Steps to reproduce:

  1. Create a new folder on the desktop.
  2. Open terminal and cd to your new folder.
  3. Run this command: bower install jquery#2.0.1
  4. Run bower list and verify that jQuery 2.0.1 is installed.
  5. Run bower update
  6. Run bower list and find that jQuery 2.0.1 is still installed and that Bower reports 2.0.3 as the latest available version.

Expected Results:

After running bower update, jQuery 2.0.1 should be replaced with jQuery 2.0.3.

Actual Results:

jQuery is not updated to the latest version available.

Extra information:

  1. Adding --force and/or --force-latest has no effect.
  2. The presence of a bower.json file in the project's root folder has no effect.
  3. Note that I'm using jQuery as an example --- the same issue manifests for all packages I attempt to update.
  4. I have some old projects lying around that have older versions of various libraries (jQuery, Foundation, etc) that were installed using Bower, but were installed without a specific target hashtag. That is, I did: bower install jQuery to get the latest version available at that time. These projects also fail to update if I run bower update on them.

Other

I'm not an expert with bower, but according to every tutorial I can find online, the above process should automatically update my installed components to the latest available versions. Apologies in advance if the reason for the failure is a misunderstanding on my part.

@xzyfer
xzyfer commented Jan 18, 2014

I have experienced bower update intermittently doesn't pick up changes. In my cases it was usually caused bower's cache. Try bower cache clean before bower update.

@bdkjones

Yep. I've been trying to debug this for about 4 hours and cleaned the cache. No difference. It's also worth pointing out that when I run bower list, bower correctly shows me that the latest version of jQuery is 2.0.3. It knows there's a newer version available; it's just not updating to it.

@xzyfer
xzyfer commented Jan 18, 2014

Can you sluppy your bower.json?

@bdkjones

I've tried both with and without a bower.json file for the project. When I used one, I just did bower init and entered fake names, descriptions, etc.

@xzyfer
xzyfer commented Jan 18, 2014

Does bower update work without a bower.json file? I thought it was required to determine which version it can be safely updated to.

If you haven't already try adding the jquery#~2.0.1 dep in you bower.json? Otherwise I'm out of ideas :)

@bdkjones

That's what I'm confused about: none of the tutorials online talk about creating or editing a bower.json file as a prerequisite to updating components. I'll give your suggestion a shot.

However, I'd argue that bower should ALWAYS update to the latest version of a package UNLESS a user has specifically placed a limitation into a bower.json file. That is, if no bower.json file exists, or no version limitation is specified for a package, bower update ought to just update that package to the latest available version.

That's the more logical, expected behavior.

@kostaspt

It's the same way NPM works.

If you say "2.0.1" you want this specific version only, or else your code may break. If you say "~2.0.1", it's like you are saying you want >=2.0.1, but also <2.1.0.

So in your case, the bower list informs you that there is a new version, but bower update won't update it, because that's what you said it to do. :)

@bdkjones

Okay, but why then will bower not update old projects where I installed a package without specifying a version?

If I did bower install jquery three months ago (without the hashtag to specify a given version), running bower update still does nothing.

Sent from my iPhone

On Jan 18, 2014, at 1:17 PM, Konstantinos Pittas notifications@github.com wrote:

It's the same way NPM works.

If you say "2.0.1" you want this specific version only, or else your code may break. If you say "~2.0.1", it's like you are saying you want >=2.0.1, but also <2.1.0.

So in your case, the bower list informs you that there is a new version, but bower update won't update it, because that's what you said it to do. :)


Reply to this email directly or view it on GitHub.

@kostaspt

Try running bower init. Keep pressing Enter until the bower.json is generated.

If the dependencies look like this:

dependencies: {
    jquery: '2.0.1'
}

maybe bower installed it without the tilde in the version. If it was a bug, it should be fixed now, because I run bower install jquery now and it adds as dependency jquery: '~2.0.3'.

If it has the tilde and still not updating, then sure is a bug.

@veilig2000

I've been having this same issue. I have multiple packages that just refuse to update.

as one example (using bower version 1.3.2):

cat bower.json

...
"ng-file-upload": "~1.2",
...

bower list

...
├── ng-file-upload#1.2.11 (latest is 1.3.1)
...

I've cleared my bower cache many times but the only thing that seems to work is when I update the version in my bower.json file to explicitly state what version I want to use

ie: this should pull my 1.2.11 version up to 1.3.1 (but it doesn't)

$ bower update ng-file-upload 
bower ng-file-upload#~1.2       cached git://github.com/danialfarid/angular-file-upload-bower.git#1.2.11
bower ng-file-upload#~1.2     validate 1.2.11 against git://github.com/danialfarid/angular-file-upload-bower.git#~1.2

Even forcing it doesn't work

$ bower cache clean
bower deleted       Cached package angular-file-upload: /Users/veilig/.cache/packages/b3119113c333700fef5a047c8bce705e/1.2.11
bower deleted       Cached package angular-file-upload: /Users/veilig/.cache/packages/b3119113c333700fef5a047c8bce705e/1.3.1

$ bower update ng-file-upload -F
bower ng-file-upload#~1.2   not-cached git://github.com/danialfarid/angular-file-upload-bower.git#~1.2
bower ng-file-upload#~1.2      resolve git://github.com/danialfarid/angular-file-upload-bower.git#~1.2
bower ng-file-upload#~1.2     download https://github.com/danialfarid/angular-file-upload-bower/archive/1.2.11.tar.gz
bower ng-file-upload#~1.2      extract archive.tar.gz
bower ng-file-upload#~1.2     resolved git://github.com/danialfarid/angular-file-upload-bower.git#1.2.11

If I manually go in and update my bower.json entry, to specify a new version - then everything works.

This will bring it up to v1.3.1 cat bower.json

...
"ng-file-upload": "~1.3",
...

As will this cat bower.json

...
"ng-file-upload": "~1",
...

neither of which, I shouldn't have to do.

$ bower update ng-file-upload
bower ng-file-upload#~1.3   not-cached git://github.com/danialfarid/angular-file-upload-bower.git#~1.3
bower ng-file-upload#~1.3      resolve git://github.com/danialfarid/angular-file-upload-bower.git#~1.3
bower ng-file-upload#~1.3     download https://github.com/danialfarid/angular-file-upload-bower/archive/1.3.1.tar.gz
bower ng-file-upload#~1.3      extract archive.tar.gz
bower ng-file-upload#~1.3     resolved git://github.com/danialfarid/angular-file-upload-bower.git#1.3.1
bower ng-file-upload#~1.3      install ng-file-upload#1.3.1

ng-file-upload#1.3.1 public/bower_components/ng-file-upload
@engina
engina commented Apr 30, 2014

I agree that this is an issue.

Unless the package version is not restricted by bower.json it should be updated to any version which is backward compatible.

Let me speculate a flow chart.

Is there an update?
|- Yes, is it major?
|   |- Yes, major
|   |  |- Is it forced? 
|   |     |- Yes? UPDATE!
|   |     |- No? Warn that this is a major update that is kept back.
|   |- No, not major
|      |- bower.json restricts this update?
|      |- Yes
|      |   |- Is it forced?
|      |      |- Yes! Update bower.json and UPDATE the package!
|      |      |- No, warn that bower.json restricts this update.
|      |- No, UPDATE!
|- No, do nothing.

(Major as in semver.)

@arcseldon

Just wishing to add support for what has already been discussed. As a user of Bower (on Mac OSX 10.9.2 using Bower 1.3.2) - the bower update behaviour is either buggy or downright unintuitive (if that is indeed the expected behaviour). You would expect bower update (in particular with a force) to go ahead and update the bower.json file AND the dependencies - certainly minor versions. It simply isn't doing that. It is listing the newer versions correctly, downloading them, but NOT updating bower.json. To then have to go in and hand edit the bower.json file for a project with many dependencies is not ideal. Yes, bower is a great tool, but for this particular feature, believe it could be alot better for the user.

@sheerun
Contributor
sheerun commented May 10, 2014

bower.json is not meant to be updated (except when using --save which is only for convenience). It won't be updated for the same reason why Gemfile is not being updated when issuing bundle update. On the other hand lockfile in shrinkwrap feature (#505) should and will be updated.

@bdkjones hardcored jquery version to 2.0.1 in bower.json, so it won't be updated on bower update. This is expected behavior. bower update updates packages in bower_componentsto latest available versions, but respecting version ranges specified in bower.json.

The @veilig2000 issue of not being able to update 1.2.11 to 1.3.1 is caused by node-semver semantics which are different for ~1.2.3 (>=1.2.3-0 <1.3.0-0) and ~1.2 (>=1.2.0-0 <1.3.0-0). If he were using ^1.2 which means >=1.2.0-0 <2.0.0-0 bower would update to 1.3.1.

Forced updates by @engina are not necessary because it's enough to edit allowed version range in bower.json and run bower update. Version ranges have support for both minor and major versions.


tl;dr; This is expected behavior. Wait for shrinkwrap feature (#505) for updateable bower.lock.

@sheerun sheerun closed this May 10, 2014
@arcseldon

@sheerun - thank you for your prompt reply. You seem to provide adequate justification so if this is more about educating the users rather than a limitation etc then fair enough. Perhaps a flag somewhere to indicate "yes, I know what I am doing, go ahead and update bower.json to the latest version and keep it compatible with what bower is downloading for me" would be nice. My original understanding was that the force option would provide such a feature.

@sheerun
Contributor
sheerun commented May 10, 2014

@arcseldon bower update won't ever update bower.json. It only updates bower_components with respect to what's in bower.json. Actually it's pretty much synonym to bower install.

@arcseldon

@sheerun - I think that is basically the source of confusion right there: " bower update won't ever update bower.json. It only updates bower_components with respect to what's in bower.json. Actually it's pretty much synonym to bower install." I was expecting bower update to pretty much be just that - a way to update / upgrade dependencies. Anyhow, thinking it through and listening to your replies, I am certainly not opposed to the existing behaviour. It makes a lot of sense in fact. Thanks again.

@sheerun
Contributor
sheerun commented May 10, 2014

I think bower update in current form is confusing and it is shame it was implemented at all, but it's too late to deprecate. In 2.0 bower update will update bower.lock so it will be more useful.

I'd be happy if you sent PR with clarification in bower update --help. Something like:

Bower won't update bower.json. Only components in bower_components are updated.

I'd also be happy with warning on bower install <package> without --save flag, like:

It is recommended to use --save or --save-dev flag or edit bower.json manually.

@benschwarz What do you think?

@bdkjones

I agree. I think the command is very poorly implemented. It doesn't do what 98% of users expect it to do. I've trashed the whole thing and just use --install for everything in CodeKit.

@laurelnaiad
Contributor

When doing early stage development on a project, or as an early step in a vNext for an existing project, it would be nice to be able to ask bower to just go to the latest available version of all components in bower.json -- in order words, you're at a stage in development where you want to throw caution to the wind and jump to the latest versions, letting the chips fall where they may and working out the kinks.

So far, all I've found is that I can do a regex replace on my bower.json file to replace all of the semver specs with the word "latest" and then wipe out bower_components and rerun bower install... which gets me half way there... but there is no way to then ask bower to switch those references to anything semver-related (based on what ended up being installed), and so manual (or scripted work) ensues to get the new version numbers into the file. I guess it's a fairly trivial script to write and I guess I'm going to write it, but my hope is that this feature will become available at some point so that this isn't a point where you need to script your build in unwieldy ways....

@mryellow
mryellow commented Dec 3, 2014

So in short, bower update isn't for updating packages and doesn't really do anything of value?

bower install is best practice?

@sheerun
Contributor
sheerun commented Dec 3, 2014

as for now yes

@bdkjones
bdkjones commented Dec 4, 2014

Are there any plans to actually fix this, or should the command just be removed entirely? It's been... a while.

@sheerun
Contributor
sheerun commented Dec 4, 2014

We can't remove it because it breaks compatibility.

There are plans to change behavior in next major, but bower has no resources to do so.

@ssolida
ssolida commented Dec 19, 2014

could we have a "bower upgrade" to do the upgrading job ?

@andrenarchy andrenarchy referenced this issue in paperhive/paperhive-frontend Apr 5, 2015
Merged

travis: use caching of installed packages #116

@franciscop

Could @bdkjones please add the solution at the top? I had to read through all of the messages to find the fix (just running a bower install XXX to update the package to the last version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment