From 781011a7071f15b2362300d30998f5cfe2def2f9 Mon Sep 17 00:00:00 2001 From: CFT-Chris Date: Fri, 31 May 2019 17:03:01 -0400 Subject: [PATCH] fix(cli): cordova plugins merges before clobbers --- cli/src/cordova.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/cli/src/cordova.ts b/cli/src/cordova.ts index 558150d77..7c0cb98b1 100644 --- a/cli/src/cordova.ts +++ b/cli/src/cordova.ts @@ -27,6 +27,7 @@ export function generateCordovaPluginsJSFile(config: Config, plugins: Plugin[], let mergesModule = ''; let runsModule = ''; let clobberKey = ''; + let mergeKey = ''; if (jsModule.clobbers) { jsModule.clobbers.map((clobber: any) => { clobbers.push(clobber.$.target); @@ -40,6 +41,7 @@ export function generateCordovaPluginsJSFile(config: Config, plugins: Plugin[], if (jsModule.merges) { jsModule.merges.map((merge: any) => { merges.push(merge.$.target); + mergeKey = merge.$.target; }); mergesModule = `, "merges": [ @@ -49,11 +51,15 @@ export function generateCordovaPluginsJSFile(config: Config, plugins: Plugin[], if (jsModule.runs) { runsModule = ',\n "runs": true'; } - const pluginModule = { clobber: clobberKey, pluginContent: `{ - "id": "${pluginId}.${jsModule.$.name}", - "file": "plugins/${pluginId}/${jsModule.$.src}", - "pluginId": "${pluginId}"${clobbersModule}${mergesModule}${runsModule} - }`}; + const pluginModule = { + clobber: clobberKey, + merge: mergeKey, + pluginContent: `{ + "id": "${pluginId}.${jsModule.$.name}", + "file": "plugins/${pluginId}/${jsModule.$.src}", + "pluginId": "${pluginId}"${clobbersModule}${mergesModule}${runsModule} + }` + }; pluginModules.push(pluginModule); }); pluginExports.push(`"${pluginId}": "${p.xml.$.version}"`); @@ -61,7 +67,17 @@ export function generateCordovaPluginsJSFile(config: Config, plugins: Plugin[], return ` cordova.define('cordova/plugin_list', function(require, exports, module) { module.exports = [ - ${pluginModules.sort((a, b) => a.clobber.localeCompare(b.clobber)).map(e => e.pluginContent).join(',\n ')} + ${pluginModules + .sort( + (a, b) => (a.clobber && b.clobber) // Clobbers in alpha order + ? a.clobber.localeCompare(b.clobber) + : ( (a.clobber || b.clobber) // Clobbers before anything else + ? b.clobber.localeCompare(a.clobber) + : a.merge.localeCompare(b.merge) // Merges in alpha order + ) + ) + .map(e => e.pluginContent) + .join(',\n ')} ]; module.exports.metadata = // TOP OF METADATA