Skip to content

Commit 70adb48

Browse files
committed
perf(build): remove vendor/ from PHAR — no production PHP dependencies
The project has zero PHP production dependencies (requires only php>=8.4). All tools (PHPStan, Psalm, Rector, CS-Fixer, PHPUnit) are require-dev and are called via the target project's vendor/bin/, not bundled in the PHAR. The old build-phar.php was iterating the entire vendor/ tree (thousands of files from PHPStan, Psalm, Rector, PHPUnit, CS-Fixer), causing ~50s build times and a massive PHAR (~30 MB). New approach: include only the 8 Composer autoload files needed to bootstrap the classloader, plus src/ (38 files). Result: Before: ~50s build, ~30 MB PHAR After: 0.07s build, 0.14 MB PHAR
1 parent e86f018 commit 70adb48

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

bin/build-phar.php

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,29 @@
3232
}
3333
echo " + src/: $added PHP files\n";
3434

35-
// ── 2. Add vendor/ (PHP files only, no tests/docs) ─────────
36-
$vendorDir = $root . '/vendor';
37-
$excludeDirs = ['Tests', 'tests', 'test', 'doc', 'docs', 'examples', '.github'];
38-
39-
$vendorIt = new RecursiveIteratorIterator(
40-
new RecursiveDirectoryIterator($vendorDir, FilesystemIterator::SKIP_DOTS),
41-
RecursiveIteratorIterator::LEAVES_ONLY
42-
);
35+
// ── 2. Add vendor/composer/ autoload files only ────────────
36+
// No PHP production dependencies — only the generated autoloader is needed.
37+
$autoloadFiles = [
38+
'vendor/autoload.php',
39+
'vendor/composer/autoload_classmap.php',
40+
'vendor/composer/autoload_namespaces.php',
41+
'vendor/composer/autoload_psr4.php',
42+
'vendor/composer/autoload_real.php',
43+
'vendor/composer/autoload_static.php',
44+
'vendor/composer/ClassLoader.php',
45+
'vendor/composer/platform_check.php',
46+
];
4347

4448
$vendorAdded = 0;
45-
foreach ($vendorIt as $file) {
46-
if (!$file->isFile()) continue;
47-
$path = $file->getPathname();
48-
49-
// Skip test/doc directories
50-
$skip = false;
51-
foreach ($excludeDirs as $ex) {
52-
if (str_contains($path, DIRECTORY_SEPARATOR . $ex . DIRECTORY_SEPARATOR)) {
53-
$skip = true;
54-
break;
55-
}
49+
foreach ($autoloadFiles as $rel) {
50+
$abs = $root . '/' . $rel;
51+
if (file_exists($abs)) {
52+
$phar[$rel] = file_get_contents($abs);
53+
$vendorAdded++;
5654
}
57-
if ($skip) continue;
58-
59-
// Only PHP and JSON files
60-
$ext = $file->getExtension();
61-
if (!in_array($ext, ['php', 'json'], true)) continue;
62-
63-
$relative = 'vendor/' . substr($path, strlen($vendorDir) + 1);
64-
$phar[$relative] = file_get_contents($path);
65-
$vendorAdded++;
6655
}
67-
echo " + vendor/: $vendorAdded files\n";
56+
echo " + vendor/composer/: $vendorAdded autoload files\n";
57+
6858

6959
// ── 3. Add LICENSE ──────────────────────────────────────────
7060
$phar['LICENSE'] = file_get_contents($root . '/LICENSE');

0 commit comments

Comments
 (0)