diff --git a/src/hooks/diagnostics.ts b/src/hooks/diagnostics.ts index 7ec5b9c1..d25e3f02 100644 --- a/src/hooks/diagnostics.ts +++ b/src/hooks/diagnostics.ts @@ -10,39 +10,39 @@ import { NpmModule } from '../shared/npmCommand.js'; type HookFunction = (options: { doctor: SfDoctor }) => Promise<[void]>; export const hook: HookFunction = (options) => Promise.all([registryCheck(options)]); -// eslint-disable-next-line @typescript-eslint/require-await const registryCheck = async (options: { doctor: SfDoctor }): Promise => { // find npm install const npm = new NpmModule(''); - const config = npm.run('config get registry').stdout.trim(); - const customRegistry = - process.env.npm_config_registry ?? process.env.NPM_CONFIG_REGISTRY ?? config !== 'https://registry.npmjs.org/' - ? config - : undefined; - // eslint-disable-next-line @typescript-eslint/no-floating-promises - [ - // npm and yarn registries - 'https://registry.npmjs.org', - 'https://registry.yarnpkg.com', - customRegistry, - ] - // incase customRegistry is undefined, prevent printing an extra line - .filter((u) => u) - .map(async (url) => { - try { - const results = npm.ping(url); - // timeout after 5000ms, error - if (!results || results.time > 5000) { - // to trigger the catch/fail below - throw Error; + await Promise.all( + [ + ...new Set([ + // npm and yarn registries + 'https://registry.npmjs.org', + 'https://registry.yarnpkg.com', + process.env.npm_config_registry ?? + process.env.NPM_CONFIG_REGISTRY ?? + npm.run('config get registry').stdout.trim(), + ]), + ] + // incase customRegistry is undefined, prevent printing an extra line + .filter((u) => u) + .map(async (url) => { + try { + const results = npm.ping(url); + + // timeout after 5000ms, error + if (!results || results.time > 5000) { + // to trigger the catch/fail below + throw Error; + } + await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: `can access: ${url}`, status: 'pass' }); + } catch (e) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: `can't access: ${url}`, status: 'fail' }); + options.doctor.addSuggestion( + `Cannot reach ${url} - potential network configuration error, check proxies, firewalls, environment variables` + ); } - await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: `can access: ${url}`, status: 'pass' }); - } catch (e) { - await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: `can't access: ${url}`, status: 'fail' }); - options.doctor.addSuggestion( - `Cannot reach ${url} - potential network configuration error, check proxies, firewalls, environment variables` - ); - } - }); + }) + ); };