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

preferred-pm: Test for pnpm-workspace passes incorrectly #197

Open
lachlancollins opened this issue Jul 16, 2024 · 0 comments
Open

preferred-pm: Test for pnpm-workspace passes incorrectly #197

lachlancollins opened this issue Jul 16, 2024 · 0 comments

Comments

@lachlancollins
Copy link

lachlancollins commented Jul 16, 2024

Problem

The following test is supposed to check if pnpm-workspace.yaml is present at ./test/pnpm-workspace/pnpm-workspace.yaml:

test('prefer pnpm inside a pnpm workspace', async t => {
const pm = await preferredPM(path.join(__dirname, 'pnpm-workspace/packages/pkg'))
t.deepEqual(pm, { name: 'pnpm', version: '>=3' })
t.end()
})

However, the source is actually looking up for pnpm-lock.yaml:

const { findUp } = await import('find-up-simple')
if (await findUp('pnpm-lock.yaml', { cwd: pkgPath })) {
return {
name: 'pnpm',
version: '>=3'
}
}

If you delete this monorepo's pnpm-lock.yaml, the test fails.

Solution

Ideally, this package should look up the directory tree for either pnpm-lock.yaml or pnpm-workspace.yaml:

const { findUp } = await import('find-up-simple')
if (await findUp('pnpm-lock.yaml', { cwd: pkgPath }) || await findUp('pnpm-workspace.yaml', { cwd: pkgPath })) {
   ...
}

// alternatively can use findUpSync
const { findUpSync } = await import('find-up-simple')
if (findUpSync('pnpm-lock.yaml', { cwd: pkgPath }) || findUpSync('pnpm-workspace.yaml', { cwd: pkgPath })) {
   ...
}

Something similar could probably be done for checking for root-level package-lock.json or yarn.lock too.

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

No branches or pull requests

1 participant