How to add a package dependency to a shopware 6 plugin?

How do I add a package to my shopware 6 plugin?
I want to create an extension to the current behaviour of uploading media files. That’s why I want to install this composer package in my plugin: GitHub - runelaenen/sw6-media-optimizer: Image Optimizer for Shopware 6 💙

I can do this by running composer require runelaenen/sw6-media-optimizer off course. but this will just install the package in the vendor dir in my plugin. during development I don’t have any access to package classes etc.

Also, when this dependency is listed in the requirements of the composer.json file, it is not possible to install my plugin. As the requirements for this package are not met.

I also tried running composer update in the root directory of my shopware 6 installation. to no effect, the dependency is not installed, or listed during the composer update.

How does this work? how do I get a dependency into shopware that is just a regular github package?

IF you don’t have any „require“ package in your composer.json file, you can run composer require runelaenen/sw6-media-optimizer directly where your composer.json file is.
IF you have some dependencies into „require“ key in composer.json:
You need to run composer require runelaenen/sw6-media-optimizer anywhere you want in a folder OUTSIDE your plugin (choose „n“ on prompt).
After that, you’ll see a „vendor“ folder created.
Copy the „vendor“ to your CompanyModule plugin folder.
Only in this mode your dependency will be accesible when you’ll install the plugin.
I think that another option can be a shell „exec“ from PHP in install method to make sure your dependency is installed via composer, but not tested this.
Also please refer to: shopware - How to require a composer package inside a plugin? - Stack Overflow