qossmic / deptrac

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

ComposerCollector doesn't allow to check exclusion from one of the packages #1434

Open neontsun opened 3 months ago

neontsun commented 3 months ago
deptrac:
  paths:
    - src/Shared/src
    - src/BoundedContext/Network/src
    - src/BoundedContext/Project/src
    - src/BoundedContext/System/src
  layers:
    - name: Domain
      collectors:
        - type: directory
          value: 'Domain/.*'
    - name: Application
      collectors:
        - type: directory
          value: 'Application/.*'
    - name: Infrastructure
      collectors:
        - type: directory
          value: 'Infrastructure/.*'
    - name: Presentation
      collectors:
        - type: directory
          value: 'Presentation/.*'
    - name: Vendor
      collectors:
        - type: composer
          composerPath: api/composer.json
          composerLockPath: api/composer.lock
          packages:
            - ramsey/uuid
            - symfony/serializer
            - php-ds/php-ds
            - psr/container
            - psr/log
            - psr/simple-cache
            - laravel/framework
            - sebastian/comparator
  ruleset:
    Domain:
    Application:
      - Domain
    Presentation:
      - Domain
      - Application
    Infrastructure:
      - Domain
      - Application
      - Presentation
      - Vendor

In the Vendor layer packages I have the sebastian/comparator package specified, which is ignored by ComposerCollector. My guess is that this package uses autoload/classmap in composer.json instead of psr-4.

SCR-20240715-txgp
patrickkusebauch commented 2 months ago

Hello, you are correct, it uses classmap to load the files. It not working is expected documented behavior. Straight from the composer collector 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. 

I would suggest using DirectoryCollector over the package's src dir instead.