Skip to content

Commit

Permalink
Docs: Refactor findNodeModulesFile function to use require.resolve
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Stevens <jonathan.stevens@eventiva.co.uk>
  • Loading branch information
TGTGamer committed Mar 16, 2024
1 parent c8c0168 commit 817e3e8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/schema/src/utils/pkg-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ export function findUp<e extends boolean = false>(names: string[], cwd: string =
return findUp(names, up, multiple, result);
}


/**
* A function that finds a file within the node_modules directory by the provided name.
* It first searches for the node_modules directory using the findUp function, and if not found, returns undefined.
* It then splits the provided name into folder and file parts.
* It finds the location of the folder in the node_modules directory by checking for its existence.
* If the folder is not found, it returns undefined.
* It then constructs the file location by joining the folder location and the file name with a '.zmodel' extension if the file does not already have an extension.
* Returns the file location if it exists, otherwise returns undefined.
* Find a Node module/file given its name in a specific directory, with a fallback to the current working directory.
* If the name is empty, return undefined.
* Try to resolve the module/file using require.resolve with the specified directory as the starting point.
* Return the resolved path if successful, otherwise return undefined.
*
* @export
* @param name A string representing the name of the file to find in the node_modules folder
* @returns Path to a specific file within the node_modules directory
* @param {string} name The name of the module/file to find
* @param {string} [cwd=process.cwd()]
* @returns {*} Finds a specified module or file using require.resolve starting from a specified directory path, or the current working directory if not provided.
*/
export function findNodeModulesFile(name: string, cwd: string = process.cwd()) {
if (!name) return undefined;
Expand Down

0 comments on commit 817e3e8

Please sign in to comment.