$meta) { if (is_string($path) && is_array($meta) && $this->isPlatformSpecific($meta)) { $platformPaths[] = $path; } } $entries = []; foreach ($packages as $path => $meta) { if (! is_string($path)) { continue; } if (! is_array($meta)) { continue; } if ($this->isPlatformSpecific($meta)) { continue; } if ($this->isBundledUnderPlatform($path, $platformPaths)) { continue; } $version = $meta['version'] ?? null; $entries[$path] = is_string($version) ? $version : ''; } ksort($entries); $encoded = json_encode($entries, JSON_UNESCAPED_SLASHES); return $encoded === false ? null : hash('xxh128', $encoded); } /** * @param array $meta */ private function isPlatformSpecific(array $meta): bool { return isset($meta['os']) || isset($meta['cpu']) || isset($meta['libc']); } /** * @param list $platformPaths */ private function isBundledUnderPlatform(string $path, array $platformPaths): bool { return array_any($platformPaths, fn (string $platformPath): bool => str_starts_with($path, $platformPath.'/node_modules/')); } }