Finding out the version of a package from within your app

Is there a way to find out the version of a package that an app is currently running?

My use case is showing the user a prompt in Telescope when an update for a package becomes available. I’m already getting the latest version available through Atmosphere’s API, now I just need to figure out the version the user is running.

What would be the best way to do that?

That’s a great question, sacha.

If I’m not mistaken, the Package global only contains the exports of the package and no meta-information.

Until that situation is deemed a problem to be remedied, I’d definitely just parse .meteor/versions using fs.readFileSync or similar

My package sanjo:meteor-files-helpers has a function for it. MeteorFilesHelpers.getPackageVersion('acme:package-name') (See https://github.com/Sanjo/meteor-meteor-files-helpers/blob/master/src/meteor_files_helpers.js#L81-L85).

1 Like

That’s awesome, I’ll have to take a look, thanks!

Does the deployed (bundled) app also contain the .versions file or is it a development-only thing?

It doesn’t, so although @Sanjo’s solution works great locally, I still haven’t found a solution that works for deployed apps. Maybe that’s something that needs to be added at the core level?

I’m making a package, rocket:module, that is relying on .versions, I’ve got a function called getInstalledVersion in there, among other things useful things that I’ll separate into another package. But yeah, I’ll need to find a solution for this same thing too!

A build plugin is only executed in the development environment. So you should be fine I think.

Also just in case not everyone knows this:

You can make your package debugOnly: true. This means that you package is only included while developing and is excluded when bundling for production.

Package.describe({
  ...
  debugOnly: true
});

You can use this for development packages like Mongol and Velocity.

1 Like

Any word on this, @sacha? It does seem like good metadata to keep around when loading up the application…

@dgreensp confirmed it’s not possible. I agree it’d be very helpful data to have around, but we’ll have to do without it for now I guess.

Yep. It’s very useful. But unfortunately not available, one of the solution is to copy the .meteor/version file to the private directory.

We can do a symlink (mac, linux) or do it when we deploying. (write as a build plugin)

I didn’t test the latter one, but it should work.

Arunoda’s idea would work. Then any server code can access the file since it will be published with the app.