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!: improve detect algorithm, detect runs null when dismatch, fix #9 #10

Merged
merged 3 commits into from
Aug 24, 2024

Conversation

antfu
Copy link
Member

@antfu antfu commented Aug 24, 2024

Change to scan the lock and package.json at the same time and return the first match. Ideally it would be sightly more efficient as the lookup will only happen once now

@antfu antfu changed the title fix: improve detect algorithm, fix #9 fix!: improve detect algorithm, detect runs null when dismatch, fix #9 Aug 24, 2024
const lockPath = await findUp(Object.keys(LOCKS), { cwd })
let packageJsonPath: string | undefined
export interface DetectResult {
agent: Agent
Copy link
Collaborator

Choose a reason for hiding this comment

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

a bit unrelated to the issue being solved here, but I though I'd mention that the other thing that might be helpful here is to return the package manager. most usages I've seen are just looking for that and so always end up having to do agent.split('@')[0]

Copy link
Member Author

Choose a reason for hiding this comment

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

We can do another PR to separate that fields

for (const directory of lookup(cwd)) {
// Look up for lock files
for (const lock of Object.keys(LOCKS)) {
if (await fileExists(path.join(directory, lock))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this would solve the reported issue. I understood the issue to be something like:

rootproj
  |-package.json
  |-pnpm.lock
  |-packages
        |- subproj
              |- package.json (contains packageManager field)

So I think we'd need to check for the presence of the packageManager field independently of checking for the lockfile

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's the new behaviour. Instead of findUp separately for locks and packageManager field, now we check both in each directory up (the lookup function) and get the closest match

@antfu antfu merged commit 6d8f66e into main Aug 24, 2024
2 checks passed
@antfu antfu deleted the feat/detect-recurisve branch August 24, 2024 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants