Skip to content

Commit

Permalink
fix(ios): Prevent mix build phases (#933)
Browse files Browse the repository at this point in the history
* fix(addHelper): Apply plugins sort from package.json

* fix lint error

* fix unit tests

* fix e2e tests

* fix coverage
  • Loading branch information
MaximBelov authored Oct 23, 2024
1 parent ea4ef36 commit 36284e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
22 changes: 16 additions & 6 deletions spec/cordova/platform/addHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
11 changes: 10 additions & 1 deletion src/cordova/platform/addHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 36284e1

Please sign in to comment.