From e1cc0966b3594e7afc380f5cd585eb6c5973c7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Mon, 1 Feb 2021 00:32:21 +0900 Subject: [PATCH] fix: plugin podspec with no config elements (#1067) --- bin/templates/scripts/cordova/Api.js | 86 +++++++++++++++------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index ae8d09767..9490f62aa 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -354,52 +354,60 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp events.emit('verbose', 'Adding pods since the plugin contained '); podSpecs.forEach(obj => { // declarations - Object.keys(obj.declarations).forEach(key => { - if (obj.declarations[key] === 'true') { - const declaration = Podfile.proofDeclaration(key); + if (obj.declarations) { + Object.keys(obj.declarations).forEach(key => { + if (obj.declarations[key] === 'true') { + const declaration = Podfile.proofDeclaration(key); + const podJson = { + declaration + }; + const val = podsjsonFile.getDeclaration(declaration); + if (val) { + podsjsonFile.incrementDeclaration(declaration); + } else { + podJson.count = 1; + podsjsonFile.setJsonDeclaration(declaration, podJson); + podfileFile.addDeclaration(podJson.declaration); + } + } + }); + } + + // sources + if (obj.sources) { + Object.keys(obj.sources).forEach(key => { const podJson = { - declaration + source: obj.sources[key].source }; - const val = podsjsonFile.getDeclaration(declaration); + const val = podsjsonFile.getSource(key); if (val) { - podsjsonFile.incrementDeclaration(declaration); + podsjsonFile.incrementSource(key); } else { podJson.count = 1; - podsjsonFile.setJsonDeclaration(declaration, podJson); - podfileFile.addDeclaration(podJson.declaration); + podsjsonFile.setJsonSource(key, podJson); + podfileFile.addSource(podJson.source); } - } - }); - // sources - Object.keys(obj.sources).forEach(key => { - const podJson = { - source: obj.sources[key].source - }; - const val = podsjsonFile.getSource(key); - if (val) { - podsjsonFile.incrementSource(key); - } else { - podJson.count = 1; - podsjsonFile.setJsonSource(key, podJson); - podfileFile.addSource(podJson.source); - } - }); + }); + } + // libraries - Object.keys(obj.libraries).forEach(key => { - const podJson = Object.assign({}, obj.libraries[key]); - if (podJson.spec) { - podJson.spec = getVariableSpec(podJson.spec, installOptions); - } - const val = podsjsonFile.getLibrary(key); - if (val) { - events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); - podsjsonFile.incrementLibrary(key); - } else { - podJson.count = 1; - podsjsonFile.setJsonLibrary(key, podJson); - podfileFile.addSpec(podJson.name, podJson); - } - }); + if (obj.libraries) { + Object.keys(obj.libraries).forEach(key => { + const podJson = Object.assign({}, obj.libraries[key]); + if (podJson.spec) { + podJson.spec = getVariableSpec(podJson.spec, installOptions); + } + const val = podsjsonFile.getLibrary(key); + if (val) { + events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + podsjsonFile.incrementLibrary(key); + } else { + podJson.count = 1; + podsjsonFile.setJsonLibrary(key, podJson); + podfileFile.addSpec(podJson.name, podJson); + } + }); + } }); }