Skip to content

Commit 36284e1

Browse files
authored
fix(ios): Prevent mix build phases (#933)
* fix(addHelper): Apply plugins sort from package.json * fix lint error * fix unit tests * fix e2e tests * fix coverage
1 parent ea4ef36 commit 36284e1

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

spec/cordova/platform/addHelper.spec.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,24 @@ describe('cordova/platform/addHelper', function () {
340340
});
341341
});
342342

343-
it('should invoke plugman.install with correct plugin ID for a scoped plugin', () => {
344-
const scopedPluginId = '@cordova/cordova-plugin-scoped';
345-
cordova_util.findPlugins.and.returnValue([scopedPluginId]);
343+
it('should invoke plugman.install with correct plugin ID for a scoped plugins', () => {
344+
const pkgJsonPluginIds = ['@cordova/cordova-plugin-scoped', 'cordova-plugin-whitelist'];
345+
platform_addHelper.__set__({
346+
readPackageJsonIfExists: jasmine.createSpy('readPackageJsonIfExists').and.returnValue({
347+
...package_json_mock,
348+
cordova: {
349+
plugins: Object.fromEntries(pkgJsonPluginIds.map(pluginId => [pluginId, {}]))
350+
}
351+
})
352+
});
353+
cordova_util.findPlugins.and.returnValue([pkgJsonPluginIds[1], pkgJsonPluginIds[0]]);
346354

347355
return installPluginsForNewPlatformWithTestArgs().then(() => {
348-
expect(plugman.install).toHaveBeenCalledTimes(1);
349-
const pluginId = plugman.install.calls.argsFor(0)[2];
350-
expect(pluginId).toBe(scopedPluginId);
356+
expect(plugman.install).toHaveBeenCalledTimes(pkgJsonPluginIds.length);
357+
const installedPluginIds = pkgJsonPluginIds.map(function (pkgJsonPluginId, index) {
358+
return plugman.install.calls.argsFor(index)[2];
359+
});
360+
expect(installedPluginIds).toEqual(pkgJsonPluginIds);
351361
});
352362
});
353363

src/cordova/platform/addHelper.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,22 @@ function installPluginsForNewPlatform (platform, projectRoot, opts) {
291291
// Get a list of all currently installed plugins, ignoring those that have already been installed for this platform
292292
// during prepare (installed from config.xml).
293293
const platformJson = PlatformJson.load(plugins_dir, platform);
294-
const plugins = cordova_util.findPlugins(plugins_dir).filter(function (plugin) {
294+
let plugins = cordova_util.findPlugins(plugins_dir).filter(function (plugin) {
295295
return !platformJson.isPluginInstalled(plugin);
296296
});
297297
if (plugins.length === 0) {
298298
return Promise.resolve();
299299
}
300300

301+
// If package.json includes the plugins, we use that for proper sort order
302+
const pkgJson = readPackageJsonIfExists(projectRoot);
303+
if (pkgJson?.cordova?.plugins) {
304+
const pkgPluginIDs = Object.keys(pkgJson.cordova.plugins);
305+
plugins = plugins.sort(function (a, b) {
306+
return pkgPluginIDs.indexOf(a) - pkgPluginIDs.indexOf(b);
307+
});
308+
}
309+
301310
const output = path.join(projectRoot, 'platforms', platform);
302311
const plugman = require('../../plugman/plugman');
303312
const fetchMetadata = require('../../plugman/util/metadata');

0 commit comments

Comments
 (0)