Checking for platform and plugin updates in your Cordova project

This post is more than 2 years old.

Earlier today the Cordova team announced an important update for the iOS platform (Apache Cordova iOS 3.9.2). I thought it might be worthwhile to discuss how you can check your platforms and plugins for updates. It isn't a complex process, but it is probably something to make part of your routine management in your organization. As I don't manage one application but build lots of silly demos, I don't necessarily have to worry so much about this. Despite that, I was curious so I did a bit of digging.

Let's discuss platforms first. In a Cordova project, you can type cordova platforms to get a list of installed and available platforms. Here is an example:

shot1

Notice how at the end of each installed platform the current version is printed. Cool. But given that you aren't following the Cordova blog, how would you know a newer version of the iOS platform existed?

Shaz (from the Cordova team) pointed out that the CLI supports a "check" command - this was something I had missed! According to the CLI docs, running cordova platform check will "list platforms which can be updated by cordova platform update".

Cool. Unfortunately, in my testing, it was pretty broken. I tested against three or four projects and only once did it see an update and it never reported that my iOS platform could be updated. From what I can tell with conversations with Shaz and others, this feature hasn't been properly tested yet so it needs some work. However, if you are reading this in the future, try this first as it is the most direct way of reporting on your platforms. If your curious about the bugs I reported, you can find them here: CB-9951 and CB-9953.

The alternative for now is to use npm. The platform code all exists on npm and all you need to do is figure out the package name of the platform itself. This is rather easy to guess for iOS and Android:

shot2

If you choose to update, you can simply cordova platform update ios and if you decide you made a huge mistake, you can install an earlier version by doing cordova platform update ios@X where X is a version. To be honest, in the past I've also remove and re-added a platform. That's silly, but I've done it.

So - what about plugins? Running cordova plugin ls will report on installed plugins and their versions:

shot3

Unfortunately, there is no "check" command like we have with platforms (broken or not), so you'll need to use npm info again to see if new versions exist:

shot4

There is no upgrade command either, but you can rm and add a plugin in a few seconds so just do that and you're set.

But wait! There's more. Don't forget your CLI also has a version. It is easy to check both your version and the latest release:

shot5

So now that you've chewed on that a bit - let's hear from Steven Gill, also from the Cordova project:

Btw, the plan is to move towards stop advising users to update platforms independently (except patch releases like this one). Instead we will only tell users to update cli and add a command (cordova update) that would update necessary platforms and plugins based on new pinned versions in cordova-lib. (Plugins will start to be pinned soon). That way we can verify the mix of plugins, platforms and tools have been tested together.

So my translation is - it's going to get simpler. That's goodgreat.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Steven Gill posted on 11/5/2015 at 1:54 AM

Great post! Only thing worth adding is that cordova is looking to add a `npm outdated` type command. Most likely `cordova outdated`. It would do a similar thing.
`

Comment 2 by RobPosener posted on 11/5/2015 at 8:27 AM

Well summarised Raymond.
This post explains a real problem with Cordova... even with a single app (but using lots of plugins) it is really difficult keeping track of if an app is using current versions of npm, platform, and plugins.

BTW: entering $ cordova plugins check == cordova plugins ls.

Comment 3 (In reply to #2) by Raymond Camden posted on 11/5/2015 at 2:51 PM

Let me reply to this first: "cordova plugins check == cordova plugins ls" Not sure I get what you are saying there. If check worked correctly, then it would do more than just a ls.

"This post explains a real problem with Cordova... even with a single app
(but using lots of plugins) it is really difficult keeping track of if
an app is using current versions of npm, platform, and plugins."

I think you are right about it being an issue, but I'm not sure it is something that is solvable. Application development is complex. You can't always make it simple. At least with this particular issue it isn't necessarily something you have to do often. When Cordova updates the X platform, you don't have to race out and update unless there is some crucial security fix you want deployed.

Comment 4 (In reply to #3) by RobPosener posted on 11/5/2015 at 5:09 PM

To clarify:
Entering "cordova plugins check" gives identical results to entering "cordova plugins ls". Its almost like there is a stub there for "check" that currently has identical code to "ls". Kinda surprising... it should throw an error or say "experimental" or something different. It doesn't act like the "cordova platform check" which displays the useful "No platforms can be updated at this time" message. "cordova plugins check" does not display any similar message.

I don't buy your "complexity" point. If software can display the current version in use and can display the current version available then combining the 2 would be trivial. Further, most developers I know want to upgrade to the latest tools as soon as they are available for a whole host of reasons. The effort required to check this currently on a weekly basis is just crazy.

Further, the fact that "platforms" does check and "plugins" doesn't check is just another example of the inconsistencies in the cli, that IMHO has grown topsy turvey without a clear roadmap and consistent syntax over the past 18 months (although it is getting better and it is only through people like you pointing out these inconsistencies that something is being done to fix them). Its almost like the Cordova developers don't "get" how hard it is to become productive with their endeavours.

Comment 5 by Steve Hardin @jstevehardin posted on 11/5/2015 at 6:06 PM

This was a pain point for us in the past (keeping platform/plugins up to date), but now we purge the 'platforms' and 'plugins' directories after updating the Cordova CLI and/or during a final beta before app submission. We use a "hook" to automatically install the plugins developed by Holly Schinsky discussed here: http://devgirl.org/2013/11/... This resolved a many issues for us, as we were fighting compile errors in Xcode and forgetting to update plugins.

Comment 6 (In reply to #4) by Raymond Camden posted on 11/6/2015 at 1:44 PM

I didn't say this couldn't be fixed. It should be fixed. It can be improved. My point about complexity was more a high level comment. Building an app will naturally involve some complexity imo.

As to your general comments about Cordova - remember - this is an open source project. Nothing is done in secret. You can sign up for the dev list and help flesh out issues like this, let them know when things are confusing, etc. That's the role I try to provide for the project as I don't have a lot of time to work on the core code itself. That may sound a bit like "It's OSS you can fix it yourself" which is not what I'm trying to say, but Cordova does rely on a 100% volunteer force of people. :)

Comment 7 by Jan Piotrowski posted on 11/7/2015 at 6:39 PM

Hmm, `cordova platform check` only executes my hooks... no output. (Cordova CLI: 5.3.1)

Comment 8 (In reply to #7) by Raymond Camden posted on 11/9/2015 at 2:40 PM

As I said - it seems to be quite buggy. :) Can you add this to my bug reports?

Comment 9 (In reply to #8) by Jan Piotrowski posted on 11/9/2015 at 2:46 PM

Commented on your issue.

(By the way, one of your issues says "project" instead of "platform" in the issue title)

Comment 10 by jcesar posted on 11/12/2015 at 12:18 PM

there is a typo "you can type cordova platforms to get a list of installed and available plugins."

Comment 11 (In reply to #10) by Raymond Camden posted on 11/12/2015 at 2:17 PM

Sorry - where is the typo?

Comment 12 (In reply to #11) by jcesar posted on 11/12/2015 at 2:23 PM

should be "you can type cordova platforms to get a list of installed and available platforms." not plugins

Comment 13 (In reply to #12) by Raymond Camden posted on 11/12/2015 at 2:25 PM

Ah thanks!

Comment 14 by Dave Alden posted on 12/11/2015 at 12:09 PM

It would be great if cordova support could be added for managing plugin updates. But in the meantime, I got tired of manually checking for plugin updates so created a tool to do it for me: https://github.com/dpa99c/c...