Skip to content

Commit 817e3e8

Browse files
committed
Docs: Refactor findNodeModulesFile function to use require.resolve
Signed-off-by: Jonathan Stevens <jonathan.stevens@eventiva.co.uk>
1 parent c8c0168 commit 817e3e8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/schema/src/utils/pkg-utils.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ export function findUp<e extends boolean = false>(names: string[], cwd: string =
3737
return findUp(names, up, multiple, result);
3838
}
3939

40+
4041
/**
41-
* A function that finds a file within the node_modules directory by the provided name.
42-
* It first searches for the node_modules directory using the findUp function, and if not found, returns undefined.
43-
* It then splits the provided name into folder and file parts.
44-
* It finds the location of the folder in the node_modules directory by checking for its existence.
45-
* If the folder is not found, it returns undefined.
46-
* 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.
47-
* Returns the file location if it exists, otherwise returns undefined.
42+
* Find a Node module/file given its name in a specific directory, with a fallback to the current working directory.
43+
* If the name is empty, return undefined.
44+
* Try to resolve the module/file using require.resolve with the specified directory as the starting point.
45+
* Return the resolved path if successful, otherwise return undefined.
4846
*
4947
* @export
50-
* @param name A string representing the name of the file to find in the node_modules folder
51-
* @returns Path to a specific file within the node_modules directory
48+
* @param {string} name The name of the module/file to find
49+
* @param {string} [cwd=process.cwd()]
50+
* @returns {*} Finds a specified module or file using require.resolve starting from a specified directory path, or the current working directory if not provided.
5251
*/
5352
export function findNodeModulesFile(name: string, cwd: string = process.cwd()) {
5453
if (!name) return undefined;

0 commit comments

Comments
 (0)