chore: add JSDocs

This commit is contained in:
Igor Randjelovic
2020-12-08 12:07:42 +01:00
parent d21776079f
commit de5f67f7c8
10 changed files with 131 additions and 0 deletions

View File

@@ -2,6 +2,12 @@ import { getPackageJson, getProjectRootPath } from './project';
import path from 'path';
// todo: memoize
/**
* Utility to get all dependencies from the project package.json.
* The result combines dependencies and devDependencies
*
* @returns string[] dependencies
*/
export function getAllDependencies(): string[] {
const packageJSON = getPackageJson();
@@ -12,11 +18,23 @@ export function getAllDependencies(): string[] {
}
// todo: memoize
/**
* Utility to check if the project has a specific dependency
* in either dependencies or devDependencies.
*
* @param {string} dependencyName
* @returns boolean
*/
export function hasDependency(dependencyName: string) {
return getAllDependencies().includes(dependencyName);
}
// todo: memoize
/**
* Utility to get the path (usually nested in node_modules) of a dependency.
*
* @param dependencyName
*/
export function getDependencyPath(dependencyName: string): string | null {
try {
const resolvedPath = require.resolve(`${dependencyName}/package.json`, {