Repository: cordova-lib Updated Branches: refs/heads/master fbad9b8ee -> e4c216e20
CB-12838 : prevented sorting and aphabetizing platforms and plugins in pkgjson and config Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/e4c216e2 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/e4c216e2 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/e4c216e2 Branch: refs/heads/master Commit: e4c216e20cb879bcf0b4e7127b9b3f8a1b79c875 Parents: fbad9b8 Author: Audrey So <[email protected]> Authored: Tue Jul 11 17:21:41 2017 -0700 Committer: Audrey So <[email protected]> Committed: Wed Aug 16 09:47:57 2017 -0700 ---------------------------------------------------------------------- integration-tests/pkgJson-restore.spec.js | 10 ++++---- src/cordova/platform/addHelper.js | 2 +- src/cordova/restore-util.js | 33 ++++++++++++++++---------- 3 files changed, 27 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e4c216e2/integration-tests/pkgJson-restore.spec.js ---------------------------------------------------------------------- diff --git a/integration-tests/pkgJson-restore.spec.js b/integration-tests/pkgJson-restore.spec.js index 80ae1f8..8b814a0 100644 --- a/integration-tests/pkgJson-restore.spec.js +++ b/integration-tests/pkgJson-restore.spec.js @@ -981,9 +981,9 @@ describe('update pkg.json AND config.xml to include all plugins and merge unique expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toEqual({ variable_1: ' ', variable_2: ' ', variable_3: 'value_3' }); // Expect config.xml to have the plugins from pkg.json. expect(Object.keys(configPlugins).length === 3); - expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(0); - expect(configPlugins.indexOf('cordova-plugin-device')).toEqual(1); - expect(configPlugins.indexOf('cordova-plugin-splashscreen')).toEqual(2); + expect(configPlugins.indexOf('cordova-plugin-device')).toEqual(0); + expect(configPlugins.indexOf('cordova-plugin-splashscreen')).toEqual(1); + expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(2); // Expect all 3 plugins to be restored. expect(path.join(pluginsFolderPath13, 'cordova-plugin-device')).toExist(); expect(path.join(pluginsFolderPath13, 'cordova-plugin-camera')).toExist(); @@ -1110,8 +1110,8 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables } // Config.xml now has the camera, splashscreen, and device plugin expect(Object.keys(configPlugins).length === 3); - expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(0); - expect(configPlugins.indexOf('cordova-plugin-splashscreen')).toEqual(1); + expect(configPlugins.indexOf('cordova-plugin-splashscreen')).toEqual(0); + expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(1); expect(configPlugins.indexOf('cordova-plugin-device')).toEqual(2); // Pkg.json has all 3 plugins with the correct specs expect(Object.keys(pkgJson.cordova.plugins).length === 3); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e4c216e2/src/cordova/platform/addHelper.js ---------------------------------------------------------------------- diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js index 878cd5a..702543c 100644 --- a/src/cordova/platform/addHelper.js +++ b/src/cordova/platform/addHelper.js @@ -267,7 +267,7 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) { }); // Save to package.json. if (modifiedPkgJson === true) { - pkgJson.cordova.platforms = pkgJson.cordova.platforms.sort(); + pkgJson.cordova.platforms = pkgJson.cordova.platforms; fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2), 'utf8'); } }); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e4c216e2/src/cordova/restore-util.js ---------------------------------------------------------------------- diff --git a/src/cordova/restore-util.js b/src/cordova/restore-util.js index db32678..dde4e79 100644 --- a/src/cordova/restore-util.js +++ b/src/cordova/restore-util.js @@ -103,7 +103,6 @@ function installPlatformsFromConfigXML (platforms, opts) { return a; }, []); comboArray = uniq; - comboArray = comboArray.sort(); // No platforms to restore from either config.xml or package.json. if (comboArray.length <= 0) { @@ -121,7 +120,7 @@ function installPlatformsFromConfigXML (platforms, opts) { pkgJson.cordova.platforms = []; } // If comboArray has the same platforms as pkg.json, no modification to pkg.json. - if (comboArray.toString() === pkgJson.cordova.platforms.sort().toString()) { + if (comboArray.toString() === pkgJson.cordova.platforms.toString()) { events.emit('verbose', 'Config.xml and package.json platforms are the same. No pkg.json modification.'); } else { // Modify pkg.json to include the elements. @@ -308,9 +307,9 @@ function installPluginsFromConfigXML (args) { }); // Check to see if pkg.json plugin(id) and config plugin(id) match. - if (comboPluginIdArray.sort().toString() !== pluginIdConfig.sort().toString()) { + if (comboPluginIdArray.toString() !== pluginIdConfig.toString()) { // If there is a config plugin that does NOT already exist in - // mergedPluginDataArray, add it and its variables. + // comboPluginIdArray, add it and its variables. pluginIdConfig.forEach(function (item) { if (comboPluginIdArray.indexOf(item) < 0) { comboPluginIdArray.push(item); @@ -341,19 +340,29 @@ function installPluginsFromConfigXML (args) { fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2), 'utf8'); } } - // Write config.xml (only if plugins exist in package.json). + // Write to config.xml (only if it is different from package.json in content) comboPluginIdArray.forEach(function (plugID) { + var configXMLPlugin = cfg.getPlugin(plugID); if (pluginIdConfig.indexOf(plugID) < 0) { pluginIdConfig.push(plugID); - } - cfg.removePlugin(plugID); - if (mergedPluginSpecs[plugID]) { + if (mergedPluginSpecs[plugID]) { + cfg.removePlugin(plugID); + cfg.addPlugin({name: plugID, spec: mergedPluginSpecs[plugID]}, comboObject[plugID]); + modifiedConfigXML = true; + } else { + cfg.removePlugin(plugID); + cfg.addPlugin({name: plugID}, comboObject[plugID]); + modifiedConfigXML = true; + } + + // Write only if the plugin variables or specs are different from pkgJson + } else if (((pluginIdConfig.indexOf(plugID) >= 0) && (mergedPluginSpecs[plugID]) && + (configXMLPlugin.variables !== comboObject[plugID])) || + ((mergedPluginSpecs[plugID] !== configXMLPlugin.spec) || + (configXMLPlugin.variables !== comboObject[plugID]))) { + cfg.removePlugin(plugID); cfg.addPlugin({name: plugID, spec: mergedPluginSpecs[plugID]}, comboObject[plugID]); modifiedConfigXML = true; - // If no spec, just add the plugin. - } else { - cfg.addPlugin({name: plugID}, comboObject[plugID]); - modifiedConfigXML = true; } }); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
