qossmic / deptrac

Keep your architecture clean.
https://qossmic.github.io/deptrac
MIT License
2.66k stars 134 forks source link

Add a setting to separate packages from require and require-dev sections for Composer collector #1438

Open Kaspiman opened 2 months ago

Kaspiman commented 2 months ago

Hello! I have an idea!

https://qossmic.github.io/deptrac/collectors/#composer-collector

According to documentation:

The composer collector allows you to define dependencies on composer require or require-dev packages that follow PSR-0 or PSR-4 autoloading convention. With this collector you can for example enforce: - That your require-dev dependencies are only used in you non-production code (like DB migrations or SA tools)

As I understand it, you need to list the packages manually? What if we add a setting for require and require-dev separation?

Use case: i have Application layer (it could relate only require-section packages) and Test layer (it could relate require and require-dev packages).

For example:

deptrac:
  layers:
    - name: ComposerRequire
      collectors:
        - type: composer
          composerPath: composer.json
          composerLockPath: composer.lock
          require: true
          requireDev: false
     - name: ComposerRequireDev
      collectors:
        - type: composer
          composerPath: composer.json
          composerLockPath: composer.lock
          require: false
          requireDev: true
patrickkusebauch commented 2 months ago

IMO this is something you can already do relatively easily with the PhP config file:

I am wary of adding functionality to the project that can be easily done in userspace. But that is just my opinion. It may be a good topic for a blog post though.

Kaspiman commented 2 months ago

Often, not all packages are listed in the root composer.json file. For example, I have a SDK for microservices, it has a dozen more dependencies. I want to allow my Infrastructure layer to use all dependencies from the require section. However, the require dev section will only be available in the Test layer. I don't want and can't put all the dependencies into a composer.json file, it will be impossible to support.

ivoron commented 2 months ago

good idea! I would like this feature in my projects

patrickkusebauch commented 2 months ago

Often, not all packages are listed in the root composer.json file. For example, I have a SDK for microservices, it has a dozen more dependencies. I want to allow my Infrastructure layer to use all dependencies from the require section. However, the require dev section will only be available in the Test layer. I don't want and can't put all the dependencies into a composer.json file, it will be impossible to support.

I don't think I follow. What I am suggesting is the same thing as you are suggesting in terms of functionality. The difference is that you propose to have it as part of the tool and I propose to have it in userspace.