neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
134 stars 187 forks source link

BUGFIX: Discover autoloader from FLOW_ROOTPATH rather than __DIR__ #3343

Closed grebaldi closed 2 months ago

grebaldi commented 2 months ago

The Problem

In my development setups (for contribution), I prefer to have every repo that is under development installed via composer path repositories, like so:

{
    "name": "vendor/dev-distribution",
    "require": {
        "neos/flow-development-collection": "9.0.x-dev",
        "neos/neos-development-collection": "9.0.x-dev",
        "neos/neos-ui": "9.0.x-dev",
        "vendor/site": "^1.0"
    },
    "repositories": {
        "local": {
            "type": "path",
            "url": "./DistributionPackages/*"
        },
       "dev": {
            "type": "path",
            "url": "./DevelopmentPackages/*"
        }
    }
}

Now if I clone, say, neos/neos-development-collection into DevelopmentPackages/, composer will install the local version rather than the one from packagist.

This works for neos/neos-development-collection, neos/neos-ui and pretty much any other package around, but not for neos/flow-development-collection.

The flow CLI script makes the assumption that it is always located under Packages/*/ and uses this assumption to discover the autoload.php script. It does so starting at its own path using the __DIR__ constant.

Unfortunately, PHP resolves symlinks before it sets the __DIR__ constant. So when flow is installed via symlink, __DIR__ does not contain its symlinked location, but its real location. This way it guesses the wrong path for autoload.php, rendering the flow CLI script unusable.

The solution

The flow CLI script also figures out the FLOW_ROOTPATH. It does so just after the autoload discovery.

I guessed that it would be a safe assumption that the autoload.php can always be found under FLOW_ROOTPATH/Packages/Libraries/autoload.php. (though actually, this path may have been configured differently, but flow wouldn't be able to handle that as of right now)

Therefore, I moved the composer autload discovery below the FLOW_ROOTPATH discovery, to then use FLOW_ROOTPATH as a starting point.

I'm pretty sure this is applicable to lower branches as well, but I didn't test this yet, so I'm targeting 9.0 for now.

kitsunet commented 2 months ago

What a coincidence that I talked about this type of dev setup with @bwaidelich yesterday. I am all for changes that make this usecase easier. Wasn't aware this here is needed.

kdambekalns commented 2 months ago

I just wonder if this could be applied to 8.3?

kitsunet commented 2 months ago

I wouldn't mind it!

grebaldi commented 2 months ago

@kdambekalns

I just wonder if this could be applied to 8.3?

I think so, too. I'm going to rebase this on 8.3 as soon as I get around to testing it there (which hopefully will be today :)).

grebaldi commented 2 months ago

Done. Works well on 8.3 :)