Skip to content

Commit

Permalink
refactor: env, env, or config
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 23, 2024
1 parent 342bd84 commit 62b1fef
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/hooks/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ export const hook: HookFunction = (options) => Promise.all([registryCheck(option
const registryCheck = async (options: { doctor: SfDoctor }): Promise<void> => {
// find npm install
const npm = new NpmModule('');
const config = npm.run('config get registry').stdout.trim();

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()
? config
: 'https://registry.npmjs.org',
process.env.NPM_CONFIG_REGISTRY ??
npm.run('config get registry').stdout.trim(),
]),
].map(async (url) => {
try {
const results = npm.ping(url);
]
// 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;
// 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`
);
}
})
})
);
};

0 comments on commit 62b1fef

Please sign in to comment.