From a4e2c791a91582ae36d652a7566f24f41f45830f Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Sat, 7 Dec 2019 19:37:37 +0530 Subject: [PATCH] syntax fixes in cli/api.js --- cli/api.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/cli/api.js b/cli/api.js index 3d5f80d2..832b7328 100644 --- a/cli/api.js +++ b/cli/api.js @@ -56,23 +56,29 @@ const getParsedFile = memoize(() => recast.parse(getFileContents())); const getProperties = memoize(() => getParsedFile().program.body.map(obj => obj)); const getPlugins = memoize(() => { - let plugins; - getProperties().find(property => { - return Object.values(property.expression.right.properties).filter(plugin => - plugin.key.name === 'plugins' ? (plugins = plugin.value.elements) : null - ); - }); - return plugins; + const properties = getProperties(); + for (let i = 0; i < properties.length; i++) { + const rightProperties = Object.values(properties[i].expression.right.properties); + for (let j = 0; j < rightProperties.length; j++) { + const plugin = rightProperties[j]; + if (plugin.key.name === 'plugins') { + return plugin.value.elements; + } + } + } }); const getLocalPlugins = memoize(() => { - let localPlugins; - getProperties().find(property => { - return Object.values(property.expression.right.properties).filter(plugin => - plugin.key.name === 'localPlugins' ? (localPlugins = plugin.value.elements) : null - ); - }); - return localPlugins; + const properties = getProperties(); + for (let i = 0; i < properties.length; i++) { + const rightProperties = Object.values(properties[i].expression.right.properties); + for (let j = 0; j < rightProperties.length; j++) { + const plugin = rightProperties[j]; + if (plugin.key.name === 'localPlugins') { + return plugin.value.elements; + } + } + } }); function exists() { @@ -80,9 +86,9 @@ function exists() { } function isInstalled(plugin, locally) { - const array = locally ? getLocalPlugins() : getPlugins(); + const array = (locally ? getLocalPlugins() : getPlugins()) || []; if (array && Array.isArray(array)) { - return array.find(entry => entry.value === plugin) !== undefined; + return array.some(entry => entry.value === plugin); } return false; } @@ -114,7 +120,7 @@ function getPackageName(plugin) { } function install(plugin, locally) { - const array = locally ? getLocalPlugins() : getPlugins(); + const array = (locally ? getLocalPlugins() : getPlugins()) || []; return existsOnNpm(plugin) .catch(err => { const {statusCode} = err;