aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.57k stars 3.87k forks source link

(cdk-cli): (Does't use pnpm to install dependencies when invoked with pnpx) #23205

Open ShivamJoker opened 1 year ago

ShivamJoker commented 1 year ago

Describe the bug

When I try to init CDK with pnpm it starts installing dependencies using npm

screenshot showing npm install getting executed

Expected Behavior

CDK should use pnpm to install dependencies instead of just going for npm

Current Behavior

Installs package using npm

Reproduction Steps

Create a new project with

pnpx cdk init app --language typescript

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.53.0

Framework Version

No response

Node.js Version

16

OS

Arch Linux

Language

Typescript

Language Version

No response

Other information

No response

peterwoodworth commented 1 year ago

Under the hood we're executing an npm install while cdk init command is being ran. We could potentially allow for pnpm as well https://github.com/aws/aws-cdk/blob/482dcca501b42d4a1f537274e47193f4db6768ef/packages/aws-cdk/lib/init.ts#L300

ShivamJoker commented 1 year ago

I see, I am up for contribution. How do we know which package manager was used to initiate the install?

Does it get passed in command line arguments? process.args

peterwoodworth commented 1 year ago

Glad to hear you're interested in contributing! Be sure to check out our contributing guide

I'm not sure there's a way to detect if cdk init was called with pnpx. We may have to introduce a cli option for this

ShivamJoker commented 1 year ago

@peterwoodworth I found a library which parses the package manager from environment variable - https://github.com/zkochan/packages/tree/main/which-pm-runs

I will integrate this with fallback to npm.

Let me know if this works for you.

mrgrain commented 1 year ago

@ShivamJoker The templates are currently fixed for npm. Not that we would never want to support anything else, but they are deliberately basic.

If you are looking at improving your personal/company workflow. May I suggest you have a look at projen which fully support pnpm

ShivamJoker commented 1 year ago

The templates are currently fixed for npm

@mrgrain I don't see the downside of improving the developer experience. Why to force people to use npm if there are better tools available.

I looked at projen but it seems like a 3rd party tool which should not be recommended for several reasons like if its updated properly, if it has bugs or security flaws and if we encounter any issues then AWS won't take any responsibility.

tripplilley commented 1 year ago

The templates are currently fixed for npm

@mrgrain The Yarn Rulebook advises using $npm_execpath instead of npm run in package.json scripts. That might help?

It's at least portable amongst npm, pnpm, and yarn (all I've tested so far).

mrgrain commented 1 year ago

Absolutely. I reckon there are 3 places that would need to be adjusted: