BrianHenryIE / strauss

Prefix PHP namespaces and classnames to allow multiple versions of libraries to exist without conflict.
https://brianhenryie.github.io/strauss/
MIT License
142 stars 23 forks source link

Symfony polyfill-php80 stubs causing error #93

Closed JUVOJustin closed 6 months ago

JUVOJustin commented 7 months ago

When using strauss with some dependencies, it generally works. Especially when using with an empty or not existing vendor folder. However when running composer update i get the following error: Could not scan for classes inside "/var/www/html/wp-content/plugins/juvo-mail-editor/vendor/symfony/polyfill-php80/Resources/stubs" which does not appear to be a file nor a folder

{
  "name": "juvo/mail-editor",
  "description": "WordPress Plugin to easily modify mails and add new mail triggers",
  "keywords": [
    "wordpress",
    "mail",
    "editor"
  ],
  "type": "wordpress-plugin",
  "license": "GPL-3.0-or-later",
  "support": {
    "issues": "https://github.com/JUVOJustin/juvo-mail-editor/issues"
  },
  "authors": [
    {
      "name": "Justin Vogt",
      "email": "mail@justin-vogt.com",
      "homepage": "https://justin-vogt.com"
    }
  ],
  "require-dev": {
    "phpstan/phpstan": "^1.7",
    "php-stubs/acf-pro-stubs": "^6.0",
    "szepeviktor/phpstan-wordpress": "^1.1",
    "phpstan/extension-installer": "^1.1",
    "lipemat/phpstan-wordpress": "2.*",
    "squizlabs/php_codesniffer": "*",
    "dealerdirect/phpcodesniffer-composer-installer": "*",
    "wp-coding-standards/wpcs": "*"
  },
  "autoload": {
    "psr-4": {
      "JUVO_MailEditor\\": "src/",
      "JUVO_MailEditor\\Admin\\": "admin/"
    }
  },
  "require": {
    "cmb2/cmb2": "^2.9",
    "php": ">=7.2.0",
    "timber/timber": "^2.0.0",
    "symfony/polyfill-mbstring": "v1.20.0"
  },
  "scripts": {
    "sniff": "@php ./vendor/bin/phpcs -s ./",
    "test": "@php ./vendor/phpunit/phpunit/phpunit",
    "strauss": [
      "test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/latest/download/strauss.phar",
      "@php bin/strauss.phar"
    ],
    "post-install-cmd": [
      "@strauss"
    ],
    "post-update-cmd": [
      "@strauss"
    ],
    "static-analyse": "@php ./vendor/bin/phpstan analyse"
  },
  "extra": {
    "installer-paths": {
      "vendor/{$vendor}/{$name}/": [
        "type:wordpress-plugin"
      ]
    },
    "strauss": {
      "target_directory": "vendor/vendor-prefixed",
      "namespace_prefix": "JUVO_MailEditor\\Dependencies\\",
      "classmap_prefix": "JUVO_MailEditor",
      "constant_prefix": "JUVO_MAIL_EDITOR",
      "exclude_from_copy": {
        "namespaces": [
        ],
        "file_patterns": [
        ]
      },
      "exclude_from_prefix": {
        "packages": [
          "timber/timber"
        ],
        "namespaces": [
        ],
        "file_patterns": [
        ]
      },
      "delete_vendor_files": true
    }
  },
  "config": {
    "allow-plugins": {
      "composer/installers": true,
      "dealerdirect/phpcodesniffer-composer-installer": true,
      "phpstan/extension-installer": true
    }
  }
}

This can be "solved" by simply removing the vendor folder before running composer update. Is this some misconfiguration or an incompatibility?

BrianHenryIE commented 7 months ago

I thought it was nice to clean up empty folders after their contents are deleted with delete_vendor_files/delete_vendor_packages: https://github.com/BrianHenryIE/strauss/blob/f03e9176f463cf2c3f2fca5b2796c03c8e9e5729/src/Cleanup.php#L118

but then when composer update is run, or more specifically composer dump-autoload, it uses the original composer.json's autoload keys to determine which directories to scan for classes, and those directories no longer exist.

The autoload keys are stored in vendor/composer/installed.json and composer.lock but only vendor/composer/installed.json is important here.

I'll add some code so when directories are deleted, if they're present in installed.json I'll remove them from there too (or maybe update, I'll have to think about that). This is closely related to #87

Minimal reproduction:

{
  "name": "strauss/issue93",
  "require": {
    "symfony/polyfill-php80": "v1.29.0"
  },
  "extra": {
    "strauss": {
      "namespace_prefix": "Strauss\\Issue93\\",
      "delete_vendor_files": true
    }
  }
}
curl -o strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.17.0/strauss.phar;
chmod +x strauss.phar;
composer update; 
./strauss.phar;
composer dump-autoload;
Generating autoload files

In ClassMapGenerator.php line 129:

  Could not scan for classes inside "/path/to/vendor/symfony/polyfill-php80/Resources/stubs" which does not appear to be a file nor a folder                                                                                                                                                       

I'm working on a significant rewrite at the moment which will help close a few issues. Realistically it will be a while before I get to this.

https://github.com/brianhenryie/strauss/compare/master...use-files-objects-with-properties

JUVOJustin commented 7 months ago

Thank you very much for the in detail feedback. Really appreciate it! It is more or less easy to workaround, so i am happy with waiting for the rewrite. Thank you very mch

BrianHenryIE commented 6 months ago

Should be fixed in the latest release: https://github.com/BrianHenryIE/strauss/commit/f53236b08dd05a05921043e72b1c1bc156d20472

https://github.com/BrianHenryIE/strauss/blob/master/tests/Issues/StraussIssue93Test.php