Search code examples
cordovaionic-frameworkcordova-plugins

Specify the version of a non-official plugin in package.json


We have an Ionic project and like this post Manage cordova plugins with npm + package.json, we would like to install the Cordova environment (plugins and platforms) with the following command "ionic state restore". It seems to be the best practice when multiple devs work together.

My question is, how to specify the version of a non-official plugin in package.json? We use, for example, this plugin https://github.com/Initsogar/cordova-webintent which is declared on our package.json like :

"cordovaPlugins": [
    "[email protected]",
    ...
    {
        "locator": "https://github.com/Initsogar/cordova-webintent.git",
        "id": "com.borismus.webintent"
    },
    ...
]

I'm not sure that's possible to specify the version for these plugins. So, if not, what do you recommand to me? Add to our repo the plugins folder?


Solution

  • Cordova CLI documentation mentions that you can specify a commit/tag/branch reference in the git url of the plugin. The plugin you have mentioned doesn't seem to have any tags defined. If it had a tag named "1.1.1", you can add it to your project like so:

    cordova plugin add https://github.com/Initsogar/cordova-webintent.git#1.1.1

    Regarding ionic state, "ionic state save" doesn't seem to preserve the git tag, so restoring using "ionic state restore" fetches the master branch. Furthermore, Ionic state commands may be deprecated in favour of "cordova plugin add --save" command in future versions of ionic.

    Since v4.3.0, Cordova has had the ability to save and restore platforms/plugins, and it seems to preserve the version tag and restore it correctly. So, to save a plugin using GitHub URL with version tag, append "--save" at the end of the plugin add command.

    cordova plugin add https://github.com/Initsogar/cordova-webintent.git#1.1.1 --save

    There is no separate restore command. Platforms and plugins are automatically restored from config.xml when the 'cordova prepare' command is run. See https://cordova.apache.org/docs/en/latest/platform_plugin_versioning_ref/ for more information.