diff --git a/app/src/plugins.ts b/app/src/plugins.ts index 9af2ec5d3d5..72f246da6f9 100644 --- a/app/src/plugins.ts +++ b/app/src/plugins.ts @@ -98,17 +98,24 @@ const LEGACY_PLUGIN_PREFIX = 'terminus-' async function getCandidateLocationsInPluginDir (pluginDir: any): Promise<{ pluginDir: string, packageName: string }[]> { const candidateLocations: { pluginDir: string, packageName: string }[] = [] - if (await fs.exists(pluginDir)) { - const pluginNames = await fs.readdir(pluginDir) - if (await fs.exists(path.join(pluginDir, 'package.json'))) { - candidateLocations.push({ - pluginDir: path.dirname(pluginDir), - packageName: path.basename(pluginDir), - }) + return fs.exists(pluginDir).then((result) => { + if (result) { + return fs.readdir(pluginDir) + } else { + return Promise.resolve([]) } - + }).then((pluginNames) => { const promises = [] + promises.push(fs.exists(path.join(pluginDir, 'package.json')).then((result) => { + if (result) { + candidateLocations.push({ + pluginDir: path.dirname(pluginDir), + packageName: path.basename(pluginDir), + }) + } + })) + for (const packageName of pluginNames) { if ((packageName.startsWith(PLUGIN_PREFIX) || packageName.startsWith(LEGACY_PLUGIN_PREFIX)) && !PLUGIN_BLACKLIST.includes(packageName)) { const pluginPath = path.join(pluginDir, packageName) @@ -121,10 +128,13 @@ async function getCandidateLocationsInPluginDir (pluginDir: any): Promise<{ plug } } - await Promise.all(promises) - } + return Promise.all(promises) + }).then(() => { + return candidateLocations + }).catch(() => { + return candidateLocations + }) - return candidateLocations } async function getPluginCandidateLocation (paths: any): Promise<{ pluginDir: string, packageName: string }[]> {