-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: find up #1019
Refactor: find up #1019
Conversation
multiple paths and add detailed JSDoc comments for better understanding and documentation
…of findUp function for improved clarity and consistency Signed-off-by: Jonathan Stevens <[email protected]>
…utility function to locate package.json file in the directory hierarchy (respecting deprecation a171002) Signed-off-by: Jonathan Stevens <[email protected]>
…n instead of findPackageJson for better clarity and consistency (respecting deprecation a171002) Signed-off-by: Jonathan Stevens <[email protected]>
…better clarity and consistency with other utility functions. This change improves code readability and maintainability. (respecting deprecation a171002) Signed-off-by: Jonathan Stevens <[email protected]>
WalkthroughWalkthroughThe recent updates primarily focus on improving how package.json files are located within a project. The introduction of the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- packages/schema/src/cli/cli-util.ts (2 hunks)
- packages/schema/src/plugins/prisma/schema-generator.ts (2 hunks)
- packages/schema/src/utils/pkg-utils.ts (3 hunks)
Additional comments: 7
packages/schema/src/utils/pkg-utils.ts (3)
- 7-16: The introduction of the generic type
FindUp
is a significant improvement, allowing thefindUp
function to return different types based on themultiple
flag. This change enhances the function's versatility, enabling it to accommodate various use cases more effectively.- 32-39: The modifications to the
findUp
function incorporate the newFindUp
generic type and add support for searching multiple paths. The logic appears sound, correctly handling both single and multiple search scenarios. However, it's important to ensure that the recursive call on line 39 properly accumulates results inmultiple
search scenarios without losing context or duplicating entries.- 110-114: Adding a deprecation notice for
findPackageJson
and recommending the use offindUp
instead is a good practice. It helps guide developers towards using the more versatile and improvedfindUp
function. Ensure that all references tofindPackageJson
within the project are updated to usefindUp
, and consider adding a timeline or version number for whenfindPackageJson
will be removed to help with planning.packages/schema/src/cli/cli-util.ts (2)
- 16-16: The replacement of
findPackageJson
withfindUp
from../utils/pkg-utils
is a positive change, aligning with the project's goal to improve file search functionality. This modification leverages the enhanced capabilities offindUp
, making the file search more versatile and efficient.- 283-283: The usage of
findUp
to locate thepackage.json
file withingetDefaultSchemaLocation
function is correctly implemented. This change ensures that the function benefits from the improved search capabilities offindUp
, potentially handling more complex directory structures more effectively.packages/schema/src/plugins/prisma/schema-generator.ts (2)
- 51-51: The replacement of
findPackageJson
withfindUp
inschema-generator.ts
is consistent with the project's efforts to enhance file search functionality. UtilizingfindUp
for locating thepackage.json
file ingetDefaultPrismaOutputFile
function is a logical step that leverages the improved capabilities offindUp
.- 453-453: The implementation of
findUp
withingetDefaultPrismaOutputFile
to locate thepackage.json
file is correctly done. This change ensures that Prisma schema generation can benefit from the more versatile and efficient file search capabilities provided byfindUp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/schema/src/utils/pkg-utils.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/schema/src/utils/pkg-utils.ts
Looks like all the tests for this passed now, I think merge of this is the only think left to do before I can rebase #1021 and mark that ready to review :) |
Sure. I'm merging it now. |
Goal
Starts #1008
Refactor to make better use of this function and ensure multiple directories can be found such as needed for
node_module
directories to ensure support for mono-reposDetails as follows.
findUp (): String | String[] | undefined
Summary
The
findUp
function is used to search for file paths by recursively searching parent directories based on a given list of names and the current working directory. It can return a single path or multiple paths, depending on the specified flag. If no paths are found, it returns undefined.Example Usage
Code Analysis
Inputs
names
(array of strings): An array of names to search for within the directory.cwd
(string, optional): The current working directory. Defaults to the process's current working directory.multiple
(boolean, optional): A flag indicating whether to search for multiple levels of files. Defaults to false.result
(array of strings, optional): An array to store the accumulated results when searching for multiple paths.Flow
findUp
function with the parent directory as the new current working directory.Outputs
Tests
findup.spec.js
Total: 7 milliseconds
✓ 9
✓ should return the name of the first matching file when multiple is false and a match is found - 3 milliseconds
✓ should return undefined when no matches are found - 1 millisecond
✓ should search for specified files in parent directories starting from the given current working directory (cwd) - 0 milliseconds
✓ should accumulate results when multiple is true and matches are found - 2 milliseconds
✓ should return undefined when names array is empty - 0 milliseconds
✓ should return undefined when cwd is not a valid directory - 0 milliseconds
✓ should return undefined when no matches are found and multiple is true - 1 millisecond
✓ should return undefined when no matches are found and multiple is false - 0 milliseconds
✓ should return undefined when names array contains an empty string - 0 milliseconds
Tests can be found here: https://bit.cloud/tgtgamer/experiments/findup/~tests
Summary by CodeRabbit