Skip to content

Commit

Permalink
feat(linter): use require.resolve to detect version
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 3, 2023
1 parent ba868e0 commit 2fc2a16
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/eslint-plugin/src/utils/config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import { detectPackageManager } from '@nx/devkit';
import { execSync } from 'child_process';
import { accessSync } from 'fs';

/**
* Checks if package is available
* @param name name of the package
* @returns
*/
export function packageExists(name: string): boolean {
const pm = detectPackageManager();
if (pm === 'yarn') {
try {
execSync(`yarn info ${name}`);
return true;
} catch (e) {
return false;
}
}
try {
accessSync(`./node_modules/.bin/${name}`);
require.resolve(name);
return true;
} catch (e) {
} catch {
return false;
}
}

0 comments on commit 2fc2a16

Please sign in to comment.