Skip to content

Commit 4014c75

Browse files
authored
Round trip the PostgresSQL Removal. (#196)
* Round Trip Round 2 * Add git hook support.
1 parent 8e2b34a commit 4014c75

12 files changed

+227
-182
lines changed

README_COMPOSER.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11

22
To update only one thing whilst not bumping the transitive dependencies
33

4-
composer update tsugi/lib
5-
composer update symfony/browser-kit
4+
composer update tsugi/lib --no-dev
5+
composer update symfony/browser-kit --no-dev
66

77
And to ignore platform requirements:
88

9-
composer update tsugi/lib --ignore-platform-reqs
9+
composer update tsugi/lib --ignore-platform-reqs --no-dev
1010

1111
To advance dependencies
1212

13-
composer update --ignore-platform-reqs
13+
composer update --ignore-platform-reqs --no-dev
1414

1515
Make sure to allow it to work with any version of PHP
1616

1717
When advancing the version of PHP and moving from the php-84-x branch to master, update
1818
composer.json to master-dev hashes and type:
1919

20-
composer update tsugi/lib koseu/lib --ignore-platform-reqs
20+
composer update tsugi/lib koseu/lib --ignore-platform-reqs --no-dev
2121

2222
This way to does not trigger a fresh dependency advance across the board.
2323

24+
Run this before pushing for sanity check:
25+
26+
bash qa/pre-commit-vendor-check.sh
27+

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"react/dns" : ">=1.13.0",
3737
"react/socket" : ">=1.16.0",
3838

39-
"tsugi/lib": "dev-master#98f76a64ee0ea00287bebfffc35757fd29c583ca",
39+
"tsugi/lib": "dev-master#49b2107797f2936631739ccef847405b3d26a27a",
4040
"koseu/lib": "dev-master#c5a8e2bd56a33e1a65731a13ed4f350769c9ab3b"
4141
},
4242
"config": {

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

qa/install-git-hooks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
HOOK_DIR=".git/hooks"
5+
HOOK="$HOOK_DIR/pre-commit"
6+
7+
echo "🔧 Installing git pre-commit hook"
8+
9+
mkdir -p "$HOOK_DIR"
10+
11+
cat > "$HOOK" <<'EOF'
12+
#!/usr/bin/env bash
13+
set -e
14+
15+
echo "🚦 Running pre-commit vendor sanity check..."
16+
qa/pre-commit-vendor-check.sh
17+
EOF
18+
19+
chmod +x "$HOOK"
20+
21+
echo "✅ pre-commit hook installed"
22+

qa/pre-commit-vendor-check.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "🔍 Pre-commit vendor sanity check (prod-clean)"
5+
6+
### Must be run from repo root
7+
if [ ! -f composer.json ] || [ ! -d vendor ]; then
8+
echo "❌ Must be run from repo root with vendor present"
9+
exit 1
10+
fi
11+
12+
### 1. Hard fail if dev-only packages appear in autoload metadata
13+
echo "→ Checking autoload for dev-only packages"
14+
15+
DEV_PATTERNS=(
16+
phpunit
17+
mockery
18+
myclabs/deep-copy
19+
fakerphp
20+
)
21+
22+
for pat in "${DEV_PATTERNS[@]}"; do
23+
if grep -R "$pat" vendor/composer/autoload_files.php >/dev/null 2>&1; then
24+
echo "❌ Dev package '$pat' referenced in autoload_files.php"
25+
echo " Vendor was built with dev deps enabled"
26+
exit 1
27+
fi
28+
done
29+
30+
### 2. Autoload must actually work
31+
echo "→ Verifying PHP autoload"
32+
php -r "require 'vendor/autoload.php';" >/dev/null 2>&1 || {
33+
echo "❌ PHP autoload failed"
34+
exit 1
35+
}
36+
37+
### 3. Vendor must match composer.lock in *prod* mode
38+
echo "→ Verifying vendor matches composer.lock (no-dev)"
39+
composer install \
40+
--no-dev \
41+
--prefer-dist \
42+
--dry-run \
43+
--no-interaction \
44+
>/dev/null 2>&1 || {
45+
echo "❌ vendor/ does NOT match composer.lock for --no-dev"
46+
echo " Rebuild vendor with: composer install --no-dev"
47+
exit 1
48+
}
49+
50+
### 4. Guard against accidental dev files sneaking in
51+
echo "→ Checking for dev package directories"
52+
for pat in "${DEV_PATTERNS[@]}"; do
53+
if find vendor -type d -name "*$pat*" | grep -q .; then
54+
echo "❌ Dev package directory '$pat' present in vendor/"
55+
exit 1
56+
fi
57+
done
58+
59+
echo "✅ Vendor sanity check PASSED"
60+
echo "👍 Safe to git commit -a && git push"
61+

vendor/autoload.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
echo $err;
1515
}
1616
}
17-
throw new RuntimeException($err);
17+
trigger_error(
18+
$err,
19+
E_USER_ERROR
20+
);
1821
}
1922

2023
require_once __DIR__ . '/composer/autoload_real.php';

vendor/composer/InstalledVersions.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
*/
2727
class InstalledVersions
2828
{
29-
/**
30-
* @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
31-
* @internal
32-
*/
33-
private static $selfDir = null;
34-
3529
/**
3630
* @var mixed[]|null
3731
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
@@ -328,18 +322,6 @@ public static function reload($data)
328322
self::$installedIsLocalDir = false;
329323
}
330324

331-
/**
332-
* @return string
333-
*/
334-
private static function getSelfDir()
335-
{
336-
if (self::$selfDir === null) {
337-
self::$selfDir = strtr(__DIR__, '\\', '/');
338-
}
339-
340-
return self::$selfDir;
341-
}
342-
343325
/**
344326
* @return array[]
345327
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
@@ -354,7 +336,7 @@ private static function getInstalled()
354336
$copiedLocalDir = false;
355337

356338
if (self::$canGetVendors) {
357-
$selfDir = self::getSelfDir();
339+
$selfDir = strtr(__DIR__, '\\', '/');
358340
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
359341
$vendorDir = strtr($vendorDir, '\\', '/');
360342
if (isset(self::$installedByVendor[$vendorDir])) {

vendor/composer/autoload_real.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public static function getLoader()
2222
return self::$loader;
2323
}
2424

25-
require __DIR__ . '/platform_check.php';
26-
2725
spl_autoload_register(array('ComposerAutoloaderInit687bd735fc487d23f01529fcf7aa762c', 'loadClassLoader'), true, true);
2826
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
2927
spl_autoload_unregister(array('ComposerAutoloaderInit687bd735fc487d23f01529fcf7aa762c', 'loadClassLoader'));

0 commit comments

Comments
 (0)