Skip to content

Commit

Permalink
refactor: without undefined, defers npm run
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 23, 2024
1 parent b5bca46 commit 122d38d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/hooks/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ 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<void> => {
// 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) => {

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() ??
'https://registry.npmjs.org',
]),
].map(async (url) => {
try {
const results = npm.ping(url);

Expand All @@ -44,5 +41,6 @@ const registryCheck = async (options: { doctor: SfDoctor }): Promise<void> => {
`Cannot reach ${url} - potential network configuration error, check proxies, firewalls, environment variables`
);
}
});
})
);
};

0 comments on commit 122d38d

Please sign in to comment.