-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathvalidate-split-packages.php
More file actions
103 lines (85 loc) · 3.04 KB
/
validate-split-packages.php
File metadata and controls
103 lines (85 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/php -q
<?php
declare(strict_types=1);
/*
* Compare split packages' composer.json with ROOT composer.json in regard to dependency constraints.
*/
use Cake\Utility\Inflector;
$options = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
];
if (!empty($_SERVER['PWD'])) {
array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
}
foreach ($options as $file) {
if (file_exists($file)) {
define('COMPOSER_INSTALL', $file);
break;
}
}
require COMPOSER_INSTALL;
$path = dirname(__DIR__) . DS . 'src' . DS;
$di = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::LEAVES_ONLY);
/** @var array<\SplFileInfo> $iterator */
$iterator = new RegexIterator($iterator, '~/src/\w+/composer.json$~');
$packages = [];
$code = 0;
foreach ($iterator as $file) {
$filePath = $file->getPath();
$package = substr($filePath, strrpos($filePath, '/') + 1);
if ($package === 'ORM') {
$fullName = 'cakephp/orm';
} else {
$fullName = 'cakephp/' . Inflector::dasherize($package);
}
$packages[$fullName] = $package;
}
ksort($packages);
$mainJsonContent = file_get_contents(dirname(__FILE__, 2) . DS . 'composer.json');
$mainJson = json_decode($mainJsonContent, true);
$mainReplace = $mainJson['replace'];
$missing = [];
foreach ($packages as $fullPackageName => $package) {
if (!empty($mainReplace[$fullPackageName])) {
unset($mainReplace[$fullPackageName]);
continue;
}
$missing[] = $package;
}
if ($mainReplace) {
echo "\033[31m" . ' * Missing "replace" statement in ROOT composer.json for package `' . $package . '`' . "\033[0m" . PHP_EOL;
$code = 1;
}
if ($missing) {
echo "\033[31m" . ' * Extra "replace" statement in ROOT composer.json for non-existent package(s) `' . implode(', ', $missing) . '`' . "\033[0m" . PHP_EOL;
$code = 1;
}
$mainRequire = $mainJson['require'];
$issues = [];
foreach ($packages as $package) {
$content = file_get_contents($path . $package . DS . 'composer.json');
$json = json_decode($content, true);
$require = $json['require'] ?? [];
foreach ($require as $packageName => $constraint) {
if (isset($packages[$packageName])) {
continue;
}
if (!isset($mainRequire[$packageName])) {
$issues[$package][] = 'Missing package requirement `' . $packageName . ': ' . $constraint . '` in ROOT composer.json';
continue;
}
if ($mainRequire[$packageName] !== $constraint) {
$issues[$package][] = 'Package requirement `' . $packageName . ': ' . $constraint . '` does not match the one in ROOT composer.json (`' . $mainRequire[$packageName] . '`)';
}
}
}
foreach ($issues as $packageName => $packageIssues) {
echo "\033[31m" . $packageName . ':' . "\033[0m" . PHP_EOL;
foreach ($packageIssues as $issue) {
echo "\033[31m" . ' - ' . $issue . "\033[0m" . PHP_EOL;
$code = 1;
}
}
exit($code);