zkochan / packages

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

[preferred-pm] Reporting Yarn when inside an NPM workspace #180

Closed erunion closed 8 months ago

erunion commented 1 year ago

If you run the following code snippet from inside of a workspace directory in an NPM package (like packages/<pkgname>), the call to findYarnWorkspaceRoot() in preferred-pm ends up thinking that we're using Yarn.

import preferredPM from 'preferred-pm';

preferredPM(process.cwd()).then(pm => console.log(pm));

I'm not exactly sure how to fix this because you can't easily know if you're in an NPM workspace without recursively parsing the parent directories until you find a package.json and see the workspaces key.

wesleytodd commented 11 months ago

I think the only correct answer here is to not check for the existence of the workspaces key as an indicator of yarn usage. I think what needs to happen is to find the "root" and then look for the lockfile there. Since yarn does not allow turning off lockfiles, you can assume that if there is no yarn.lock there but you have a workspaces key then it is an npm project.