Skip to content
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

fix: recursively search for packer lock file for all 3 packers supported #502

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

Dutzu
Copy link
Contributor

@Dutzu Dutzu commented Oct 9, 2023

This is a quick fix for issue #485.

I stumbled upon it by accident but basically I had a yarn.lock file in my home folder, and because the mechanism for recursively finding the lock file of the project runs up the directory chain outside of the scope of the repo, it could happen.

In the issue i described 2 possible solutions i could see, and decided to push this parallel search as an easy way to fix it. It should basically look recursively up the folder tree for either a package-lock, yarn-lock or pnpm-lock file and stop when it finds one of them rather than first looking for a yarn.lock up into infinity and if it can't find one, move on to the next possible packer lock file and so forth...

@floydspace
Copy link
Owner

Hi @Dutzu
I got the problem your PR is solving, and thank you for the fix.
I'm happy to merge it, but could you please first fix failing tests run on your PR?

@floydspace
Copy link
Owner

and I'm thinking should we reuse the https://github.com/sindresorhus/find-up
so we don't have to maintain this part

@Dutzu
Copy link
Contributor Author

Dutzu commented Oct 10, 2023

Sorry about that. I thought I could quickly pull it off in the browser editor. FIxed the code now.

As for replacing it with find-up.....your call, but for such a small piece of logic, I wouldn't. Sounds like a pad-left type of scenario.

@floydspace
Copy link
Owner

floydspace commented Oct 10, 2023

hey @Dutzu
I'm ready to approve it, wanted to make a little fix, but couldn't in your branch, could you please either allow me to commit or simply make this patch

diff --git a/src/utils.ts b/src/utils.ts
index a49442f..f1d59cd 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -47,9 +47,9 @@ const isPathRoot = (p: string) => rootOf(p) === path.resolve(p);
 const findUpIO = (names: string[], directory = process.cwd()): IOO.IOOption<string> =>
   pipe(path.resolve(directory), (dir) =>
     pipe(
-      IO.of(names.map((name) => safeFileExistsIO(path.join(dir, name))).some((value) => value())),
-      IO.chain((exists: boolean) => {
-        if (exists) return IOO.some(dir);
+      IO.sequenceArray(names.map((name) => safeFileExistsIO(path.join(dir, name)))),
+      IO.chain((exist) => {
+        if (exist.some(Boolean)) return IOO.some(dir);
         if (isPathRoot(dir)) return IOO.none;
         return findUpIO(names, path.dirname(dir));
       })

if you are not familiar with functional programming, it's not the best practice to unwrap Monad (... value() ...) and then wrap it back (IO.of).
It's possible to do that within the Monad, sequenceArray lazily evaluates each file existence and transfers the aggregated result to the chained function

@Dutzu
Copy link
Contributor Author

Dutzu commented Oct 11, 2023

Yep, you got it right, unfortunately I haven't done much functional programming. This was my first encounter with fp-ts.

I applied your patch and also gave you rights to the fork in case more touch-ups are needed.

Copy link
Owner

@floydspace floydspace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Dutzu approved

@floydspace floydspace merged commit fdf091e into floydspace:master Oct 11, 2023
3 checks passed
@github-actions
Copy link

🎉 This PR is included in version 1.48.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants