Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 8: How do you add plugins that are not in npm registry?

I have a series of plugins that are not published in the npm registry and for various reasons, they will never be. These exist as GitHub repos.

Given that cordova 8 (actually starting 7.1.0) has removed nofetch how do we specify cordova plugins in config.xml (or package.json) that install these plugins when the user does a cordova prepare ?

Example: This is in package.json (as well as config.xml)

 <plugin name="org.devgeeks.Canvas2ImagePlugin" spec="https://github.com/devgeeks/Canvas2ImagePlugin.git">

When you do cordova prepare

Discovered plugin "org.devgeeks.Canvas2ImagePlugin" in config.xml. Adding it to the project
Failed to restore plugin "org.devgeeks.Canvas2ImagePlugin" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin https://github.com/devgeeks/Canvas2ImagePlugin via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Failed to get absolute path to installed module

However manually doing the same thing works just fine:

cordova plugin add  https://github.com/devgeeks/Canvas2ImagePlugin.git
Installing "org.devgeeks.Canvas2ImagePlugin" for android
Installing "org.devgeeks.Canvas2ImagePlugin" for ios
Adding org.devgeeks.Canvas2ImagePlugin to package.json
Saved plugin info for "org.devgeeks.Canvas2ImagePlugin" to config.xml

This particular plugin does not have an npm registry. The same holds true for any other plugin that doesn't have an npm registry.

like image 794
user1361529 Avatar asked Jun 07 '18 20:06

user1361529


People also ask

How do I use Cordova plugins?

First, you have to pass the plugin-spec command in the command prompt. Then, plugin-spec is saved into the xml and package. json file of an app. After saving the file, we can publish the latest plugin version to npm that our current project supports.


1 Answers

(Not marking this as an answer, because I did the opposite of what I wanted to do)

I gave up trying to do this. It was much simpler to publish my changes to the npm registry with a different ID. I personally think this is a terrible mechanism - I consider the npm registry as a 'good list of plugins' and really shouldn't be littered with modifications that don't add a global value, but I found no option.

So I:

  • Changed the ids of all my changed plugins to originalplugin-myid-fork
  • Published them to npm registry
  • Changed my package.json and config.xml to just refer to these ids as they are now on npm registry (I like them both to be in sync)

Backstory (for context and what I tried):

My criteria was to make it easy for my users to install my software simply by doing npm install && bower install && cordova prepare

  • The problem is npm install would create the plugin shims inside node_modules which had the same ids as the original plugins.
  • Even though my config.xml and package.json had a spec="my fork url", for whatever reason, cordova prepare would go looking for that id in the npm registry and start complaining.
  • In fact, after doing npm install a manual install of cordova plugin add https://mygit.git would fail with the same error. The only way to make this manual command work again was to remove that plugin's definition from node_modules.
  • I also saw --no-registry option - could never get it working - kept complaining about missing local paths.
  • Around this time, I said meh and decided it was not worth it and lets go dirty the registry with my forks
like image 85
user1361529 Avatar answered Sep 23 '22 05:09

user1361529