How to share code between multi-apps from a monorepo

I have several services in a monorepo that use a shared library. I want to be able to install the shared library when running tests and deploying.

Here’s the layout

  • .platform
    • .platform/routes.yaml
  • quote-api
    • composer.json
  • events
    • composer.json

.platform/routes.yaml

"https://quote-api.{default}/":
    type: upstream
    upstream: "quote-api:http"

quote-api/composer.json

{
    "require": {
         "paqman/events": "*"
    },
    "repositories": [
        {
            "type": "path",
            "url": "../events"
        }
    ]
}

But when platform.sh is building each service, it says “Moving the application to the output directory” which I assume moves it to some sort of isolated area so now I get the error message:

Source path "../events" is not found for package paqman/events

Note: I do not want to use a package manager as I want to get the exact shared code with the commit (releasing a new package for a branch etc. would be difficult)

The build process starts by “chopping up” the repository into applications based on the .platform.app.yaml files (or source.roots in applications.yaml). Each application then has no knowledge of code outside of its sources.root, nor can it. The build process is based on the Git Tree ID, which is the hash of the files in a given directory. It cannot piecemeal assemble other directories without breaking the logic around whether a build is safe to reuse or not.

If you want to share code between applications, your options are:

  1. Use the package manager.
  2. Use a Git submodule
  3. Manually download the code from somewhere in the build script.