Cordova plugins with npm dependencies


I’ve been looking into why some Cordova plugins are not behaving as expected.

Consider this plugin cordova-android-support-gradle-release, installed via
meteor add cordova:cordova-android-support-gradle-release

In the plugin.xml file some hooks are defined (e.g. the after_plugin_install hook). After the meteor process installs the plugin, we get the following output:

%% Executing script found in plugin cordova-android-support-gradle-release for hook "after_plugin_install": plugins/cordova-android-support-gradle-release/scripts/apply-changes.js cordova-android-support-gradle-release: ERROR: EXCEPTION: Failed to load dependencies. If using cordova@6 CLI, ensure this plugin is installed with the --fetch option: Error: Cannot find module 'semver'

The script is trying to require the semver npm package, which is listed as a dependency in the plugin’s package.json file. Meteor seems to ignore the npm dependencies of cordova plugins. Of course we can do meteor npm i semver@x.x.x and install the package at the app level, or install it globally, but this is a manual process for each cordova plugin & every npm dependency. I’m curious what others are doing in scenarios like this?

Another query, plugins relying on npm scripts.
Particularly cordova.plugins.diagnostic (which is quite useful). The scripts property of pagkage.json has a postinstall script:

"postinstall": "node ./scripts/apply-modules.js"

The script is supposed to read a <preference name="" value=""> from the cordova build’s config.xml and then modify the plugin’s plugin.xml accordingly.
This doesn’t happen in Meteor, which in this case results in all the diagnostic “modules” being installed thereby adding unnecessary permissions to the AndroidManifest (and iOS plist).

I can’t find any Cordova documentation re. using npm scripts this way. But doing so using vanilla cordova clearly presents no issues.

Warm regards,

1 Like