refactor: skip autoload-dev dirs in class discovery#6540
Closed
gharlan wants to merge 2 commits into
Closed
Conversation
ClassDiscovery::getRelevantPaths() treated every non-vendor PSR-4 prefix as project code, so the root package's autoload-dev directories (tests, dev tooling such as the custom rector rules under .tools/rector/) were scanned too. Those classes never carry runtime attributes, so discovering them is wasted work — and getReflections() calls class_exists() on them, which autoloads dev-only vendor code: touching a Redaxo\Rector\* rule pulls in its Rector\AbstractRector parent and thus rector's scoped vendor autoloader. Read the root composer.json and exclude its autoload-dev PSR-4 directories, so only runtime-relevant code (core, addons, the project's production autoload) is scanned. In a --no-dev install autoload-dev is not registered anyway, so this aligns dev with prod.
Member
Author
|
Closing: excluding the root package's The real problem this was meant to mitigate (rector's scoped vendor shadowing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ClassDiscovery::getRelevantPaths()treated every non-vendor PSR-4 prefix as project-level code. In a dev install that also pulls in the root package'sautoload-devdirectories —tests/, and dev tooling such as the custom rector rules under.tools/rector/.Those classes never carry runtime attributes, so discovering them is pure overhead. Worse,
getReflections()callsclass_exists()on them, which autoloads dev-only vendor code: touching aRedaxo\Rector\*rule loads itsRector\AbstractRectorparent, which triggers rector's scoped vendor autoloader. That scoped vendor ships its owninstalled.php, so once its loader is registered it shadowsInstalledVersions::getRootPackage()(which then returnsrector/rector-srcwithdev=false).This reads the root
composer.jsonand excludes itsautoload-devPSR-4 directories from discovery, so only runtime-relevant code (core, addons, the project's production autoload) is scanned. In a--no-devinstallautoload-devisn't registered anyway, so this simply aligns dev with prod.Measured locally: relevant classes dropped 350 → 284, and a cold-cache
console migrateno longer registers rector's loader.