aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 820 forks source link

Using yarn instead of npm to install function's dependencies #6035

Open karol-szymanowski opened 3 years ago

karol-szymanowski commented 3 years ago

In my project, we use yarn and yarn workspaces to manage all dependencies, and I noticed that every time functions are deployed or mocked, the package-lock.json file is generated. Is there a way to set yarn as the default tool or ideally disable installing dependencies step?

RossWilliams commented 3 years ago

My memory of this code is that amplify will look for a yarn.lock file in your directory. If found, yarn is used, else npm

See here, https://github.com/aws-amplify/amplify-cli/blob/e1e07b245db0963c4655e646c53e7615febe2930/packages/amplify-cli/src/packageManagerHelpers.ts#L18

karol-szymanowski commented 3 years ago

In this case, it makes it incompatible with yarn workspaces, because when used, the file yarn.lock is generated only in project's root directory. I think the "install dependencies" step should be optional and there should be a flag to toggle it because it might cause conflicts when using different building tools/flows.

Does this behavior also apply to the frontend or is it just only for functions?

amcdnl commented 3 years ago

Its not clean but I've been doing something like this for some time now:

image

and then in each function I have a nohoist setup:

image

its not perfect but its a attempt to get it working.

PatrykMilewski commented 3 years ago

Having the same issue with Yarn workspaces. When using amplify push, Amplify is installing function dependencies and also purges all other dependnecies of monorepo, which of course breaks everything,