BrianHenryIE / strauss

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

Strauss does not remove namespaced classes from the composer classmap files when optimize-autoloader is enabled #87

Closed estevao90 closed 7 months ago

estevao90 commented 8 months ago

When we have any namespaced class, and we use the optimize-autoloader (e.g., composer install --no-dev --optimize-autoloader ), Strauss does not remove moved files entries from the vendor/composer/autoload_classmap.php and vendor/composer/autoload_static.php files.

Example:

{
    "require": {
        "psr/container": "^1.1"
    },
    "extra": {
        "strauss": {
            "target_directory": "vendor-prefixed",
            "classmap_prefix": "Class_Prefix_",
            "constant_prefix": "Constant_",
            "namespace_prefix": "New\\Namespace",
            "delete_vendor_files": true,
            "packages": [
                "psr/container"
            ]
        }
    },
    "scripts": {
        "strauss": [
            "[ -f ./strauss.phar ] || curl -o strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.16.0/strauss.phar",
            "@php strauss.phar"
        ],
        "post-install-cmd": [
            "@strauss"
        ],
        "post-update-cmd": [
            "@strauss"
        ]
    }
}

When we run composer install and check the vendor/composer/autoload_classmap.php, this file doesn't contain the psr files entries.

However, if we delete the vendor/vendor-prefixed folders and run it again using the optimized version (composer install -o), the psr files are there:

See:

<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
    'Psr\\Container\\ContainerExceptionInterface' => $vendorDir . '/psr/container/src/ContainerExceptionInterface.php',
    'Psr\\Container\\ContainerInterface' => $vendorDir . '/psr/container/src/ContainerInterface.php',
    'Psr\\Container\\NotFoundExceptionInterface' => $vendorDir . '/psr/container/src/NotFoundExceptionInterface.php',
);

Same case for the vendor/composer/autoload_static.php file.

BrianHenryIE commented 8 months ago

Yeah, makes sense. See #34, #81, #69 and https://github.com/BrianHenryIE/strauss/commit/4e1a9b69946f19b183bad5b56662bfb5def320af for related issues/fixes. Thanks for reporting it.

BrianHenryIE commented 7 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