tommedema / serverless-mono-example

Example repo on how to use yarn workspaces together with the serverless framework.
124 stars 10 forks source link

Hoisting + Packaging Issue #6

Open AmberDean opened 5 years ago

AmberDean commented 5 years ago

I've tried out your example and noticed that the camelcase dependency for the "random" package doesn't actually get hoisted.

When you add a dependency that does get hoisted, ie bluebird, it seems to break serverless' packaging logic. Serverless depends on 'npm ls --production=true --parseable=true' when it is excluding dev dependencies. It looks like the 'npm ls' command gets confused when it tries to find @org/random's new bluebird dependency, since it is hoisted and does not exist in @org/random/node_modules, even though it is in sls-random/node_modules.

My current workaround is to manually build my own list of 'include' files, write the list to a json file, and then reference that json file in the serverless.yml file.

tommedema commented 5 years ago

@AmberDean I believe I'm aware of this issue, it's noted under known issues in the readme

Is this similar to your workaround? https://github.com/tommedema/serverless-mono-example/commit/e0f97a081f35b181d55a2523cb583168e685698d

AmberDean commented 5 years ago

I ended up taking a different approach where I recursively parsed the package.json files for production dependencies, built a json file, and referenced that file when setting the package configuration.

package:
  include: ${file(include.json):paths}
  exclude:
    - ./**
    - '!dist/**'
  excludeDevDependencies: false

I'm guessing that your method is more robust than mine.