Return package version


#1

Is there any way to return the package version of a certain package, is something like this pre built in to atom?


#2

Nothing pre-built, no … but you could do:

path = require('path')

version = require(path.join(atom.getConfigDirPath(), "packages/package-name/package.json")).version

#3

Thanks how can i call it?


#4

What do you want the UI to look like? You need to have some way to specify the package and then show the version. That would require you to write your own package.

If you just want to do it once or twice you can type it into the chrome dev inspector.


#5

You categorized this post as packages so I assumed that you’re developing a package. If you’re not, then this should probably be under the support category. Also, what do you mean by “call it”? How would you specify which package you are wanting version information for?


#6

I just wanted some text in a drop down menu to show the version but it doesn’t really matter now seeing how i end up editing that file every version as you can see

'menu': [
  {
    'label': 'Packages'
    'submenu': [
      'label': 'Language-Skript: v1.6.0'
      'submenu': [
        {
          'label': 'Addon Versions (19)'
          'submenu': [
            {
              'label': 'Aliases: Coming soon'
            }
            {
              'label': 'Skript: v2.2'
            }
            {
              'label': 'skQuery: v3.21.4'
            }
            {
              'label': 'AuthMe SkAddon: v1.1'
            }

Im trying to make this package as low profile as i can https://github.com/Skript-Atom/Language-Skript/


#7

Atom actually does have this ability built in using package metadata, although it isn’t exactly documented. The only catch is that the package you want to check the version for has to be loaded (ie. not disabled), but this way you aren’t waiting on the file system to load any files already in memory (package.json).

version = atom.packages.getLoadedPackage('package-name').metadata.version;

The .metadata member of a package essentially contains the contents of that package’s package.json file.

Also, a note on documentation: There is a documented function getAvailablePackageMetadata which will return an array of all packages’ metadata objects, including disabled packages, but it is relatively painful to search through and doesn’t cache the metadata of unloaded packages. This means that disabled packages will affect the run time of getAvailablePackageMetadata much more than loaded packages. However, while using the .metadata member of loaded packages is faster, there is no mention of it or anything like it in the Package documentation.