From 36284e1bb6513c1025924c78c238e6fc45e5c1cf Mon Sep 17 00:00:00 2001 From: Maxim Belov Date: Wed, 23 Oct 2024 03:56:39 +0300 Subject: [PATCH] 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 --- spec/cordova/platform/addHelper.spec.js | 22 ++++++++++++++++------ src/cordova/platform/addHelper.js | 11 ++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/spec/cordova/platform/addHelper.spec.js b/spec/cordova/platform/addHelper.spec.js index 7515afd00..ba4a99f9e 100644 --- a/spec/cordova/platform/addHelper.spec.js +++ b/spec/cordova/platform/addHelper.spec.js @@ -340,14 +340,24 @@ describe('cordova/platform/addHelper', function () { }); }); - it('should invoke plugman.install with correct plugin ID for a scoped plugin', () => { - const scopedPluginId = '@cordova/cordova-plugin-scoped'; - cordova_util.findPlugins.and.returnValue([scopedPluginId]); + it('should invoke plugman.install with correct plugin ID for a scoped plugins', () => { + const pkgJsonPluginIds = ['@cordova/cordova-plugin-scoped', 'cordova-plugin-whitelist']; + platform_addHelper.__set__({ + readPackageJsonIfExists: jasmine.createSpy('readPackageJsonIfExists').and.returnValue({ + ...package_json_mock, + cordova: { + plugins: Object.fromEntries(pkgJsonPluginIds.map(pluginId => [pluginId, {}])) + } + }) + }); + cordova_util.findPlugins.and.returnValue([pkgJsonPluginIds[1], pkgJsonPluginIds[0]]); return installPluginsForNewPlatformWithTestArgs().then(() => { - expect(plugman.install).toHaveBeenCalledTimes(1); - const pluginId = plugman.install.calls.argsFor(0)[2]; - expect(pluginId).toBe(scopedPluginId); + expect(plugman.install).toHaveBeenCalledTimes(pkgJsonPluginIds.length); + const installedPluginIds = pkgJsonPluginIds.map(function (pkgJsonPluginId, index) { + return plugman.install.calls.argsFor(index)[2]; + }); + expect(installedPluginIds).toEqual(pkgJsonPluginIds); }); }); diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js index 5bb803080..d72f283b7 100644 --- a/src/cordova/platform/addHelper.js +++ b/src/cordova/platform/addHelper.js @@ -291,13 +291,22 @@ function installPluginsForNewPlatform (platform, projectRoot, opts) { // Get a list of all currently installed plugins, ignoring those that have already been installed for this platform // during prepare (installed from config.xml). const platformJson = PlatformJson.load(plugins_dir, platform); - const plugins = cordova_util.findPlugins(plugins_dir).filter(function (plugin) { + let plugins = cordova_util.findPlugins(plugins_dir).filter(function (plugin) { return !platformJson.isPluginInstalled(plugin); }); if (plugins.length === 0) { return Promise.resolve(); } + // If package.json includes the plugins, we use that for proper sort order + const pkgJson = readPackageJsonIfExists(projectRoot); + if (pkgJson?.cordova?.plugins) { + const pkgPluginIDs = Object.keys(pkgJson.cordova.plugins); + plugins = plugins.sort(function (a, b) { + return pkgPluginIDs.indexOf(a) - pkgPluginIDs.indexOf(b); + }); + } + const output = path.join(projectRoot, 'platforms', platform); const plugman = require('../../plugman/plugman'); const fetchMetadata = require('../../plugman/util/metadata');