zkochan / packages

Zoltan Kochan's npm packages
MIT License
99 stars 26 forks source link

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

Open lachlancollins opened 3 months ago

lachlancollins commented 3 months ago

Problem

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

https://github.com/zkochan/packages/blob/2b2c832c563e27528c977d03cff31184337c924c/preferred-pm/test/index.js#L38-L42

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

https://github.com/zkochan/packages/blob/2b2c832c563e27528c977d03cff31184337c924c/preferred-pm/index.js#L41-L47

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.