nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

CLI doesn't use yarn to install package? #1115

Open vegawong opened 3 years ago

vegawong commented 3 years ago

image

My project has the yarn.lock file but not package-lock.json. Should it auto use yarn to install package?

I saw the source at https://github.com/nestjs/nest-cli/blob/8d8c1fdc5616b0d6d553dbc87ddaf38979c12187/lib/package-managers/package-manager.factory.ts#L25.

jmcdo29 commented 3 years ago

Can you provide reproduction steps for this?

vegawong commented 3 years ago

@jmcdo29 https://codesandbox.io/s/smoosh-snow-j0yvf In codesanbox, create a teminal and type input yarn exec nest g res user modules

jmcdo29 commented 3 years ago

@kamilmysliwiec it looks like the schematics generator doesn't take into account the package manager. I'm trying to look into where that can be added. Let me know if you know where off the top of your head

kamilmysliwiec commented 3 years ago

https://github.com/nestjs/schematics/blob/master/src/lib/resource/resource.factory.ts#L180-L186

The NodePackageInstallTask function takes an options object as a parameter. @jmcdo29 one of the available configuration properties is the packageManager which we could use to determine what package manager should be used (I'm not sure what managers are supported though, but Yarn is certainly one of them). Now, to decide what package manager is being used by the project, we could check whether package-lock.json or yarn.lock file is present in the root directory.

vegawong commented 3 years ago

How can i use yarn? Any cli option support or config support?

jmcdo29 commented 3 years ago

We'll need to make an update to the schematics that Kamil pointed out. You're welcome to make a PR or wait for one of us to have the time to do it

RileyMShea commented 3 years ago

In lieu of deprecating yarn support entirely, I'd like to advocate that yarn be presented as yarn (experimental) when given the option to choose a package manager with nest new. There are simply too many breaking issues with yarn and nestjs, presenting yarn and npm to the user as equally supported options is setting them up for a bad time. They're going to find out the yarn support isn't there eventually, so might as well be upfront with them about it.

kamilmysliwiec commented 3 years ago

yarn works totally fine with Nest CLI and there's no reason to flag it as experimental (especially after 3-4 years when all yarn users have been successfully using it with Nest). This issue is mainly about the new resource schematic that we added a few months ago and the "packages installation" part is actually just a minor thing that shouldn't have any impact on the application itself.

Let me lock this issue to prevent future off-topic. We'll look into this issue as soon as we can.