cordova prepare does not call platform prepare hooks
If a prepare hook is defined in a platform block, it is not executed when cordova prepare is called without specifying a platform.
My expectation is that the platform prepare hooks will be still be called when a platform is not provided as an argument to the platform prepare command.
For example:
Given the following hook:
<platform name="android">
<hook type="after_prepare" src="scripts/androidBeforeBuild.js" />
...
</platform>
When executing the command:
cordova prepare
the hook will not be found or executed.
However when executing the command:
cordova prepare android
the hook will be found and run as expected.
I have observed this for project and plugin hooks.
Is this behaviour by design? My thinking is that it is then always safer to run the platform prepare command with an explicit platform.
Thanks.
Collecting Data...
Node version: v8.10.0
Cordova version: 8.0.0
I would also have expected all the hooks to run, and I don't see anything in the docs to suggest otherwise, so this seems like it's probably a bug (although it's also likely that it has always behaved this way)
Some related issues:
- https://github.com/kelvinhokk/cordova-plugin-localization-strings/issues/17
- https://github.com/akofman/cordova-plugin-add-swift-support/issues/3#issuecomment-224596597
Just encountered this behaviour today myself, while debugging a plugin which ultimately was due to me running cordova prepare not cordova prepare ios and wondering why a hook wasn't running that the plugin should have run.
Should anyone want to take a stab at this: the scripts are collected in cordova-lib/blob/master/src/hooks/scriptsFinder.js. There are three instances where opts.cordova.platforms is passed down to select for which platforms to get hooks. I guess this contains only platforms explicitly listed on the command line.
These arguments finally end up either in ConfigParser.prototype.getHookScripts or in PluginInfo.prototype.getHookScripts. IMHO, the best way to fix this would be to change these two methods to include all platform specific hooks if the platforms parameter is either empty or falsy.
I think I have a similar issue, was wondering if anyone encountered it.
I have an ios plugin that defines 4 hooks inside the ios platform, one of them is before_prepare.
before_prepare is not called when there's no plugins and platform folder, but if the plugins folder exists but the platform it will run when calling cordova platform add ios... O_o