Skip to content

Prune repos published on packagist.org#121

Merged
schlessera merged 1 commit intowp-cli:masterfrom
aaemnnosttv:patch-1
Jan 5, 2022
Merged

Prune repos published on packagist.org#121
schlessera merged 1 commit intowp-cli:masterfrom
aaemnnosttv:patch-1

Conversation

@aaemnnosttv
Copy link
Copy Markdown
Contributor

This PR is intended to resolve the discrepancy between this package index and entries for packages by the same name on packagist.org.

The problem is that since this composer repository is no longer kept up to date, any packages referenced here end up getting stuck on old versions due to the precedence the wp-cli composer repository URL takes over the default packagist.org index. See wp-cli/package-command#141 (comment)

Releasing these packages from the index will ensure they continue to receive updates and are managed by the official Composer index instead.

I filtered this list using the following script which filters out lines for packages which exist on packagist.org by the exact same name. Perhaps it would make sense to include this in the scripts part of this repo for use in the future, but I can always include that in a separate PR.

<?php

$wp_cli_packages = file(
	'https://github.com/wp-cli/package-index/raw/master/repositories.txt',
	FILE_IGNORE_NEW_LINES
);

// Filter out lines for packages that are available on packagist.org

$wp_cli_only = array_filter(
	$wp_cli_packages,
	function ( $repo_url ) {
		$package_name = str_replace( 'https://github.com/', '', $repo_url );
		$packagist_res = json_decode(
			file_get_contents( "https://packagist.org/search.json?q={$package_name}" )
		);

		if ( ! $packagist_res ) {
			throw new Exception( "Invalid package search results for $package_name" );
		}
		// If no results, the package wasn't found on packagist!
		if ( ! $packagist_res->total ) {
			return true;
		}
		// Iterate over the results to ensure an exact match since search results return fuzzy matches.
		foreach ( $packagist_res->results as $p ) {
			if ( $p->name === $package_name ) {
				return false;
			}
		}
		
		// If we got this far, there were results but none that matched the specific package we were looking for.
		return true;
	}
);

// Output the filtered list of repositories
// which now only include packages that are only on the wp-cli package index.
echo join( "\n", $wp_cli_only ) . "\n";

Note: this is probably obvious but merging this would still require the index to be regenerated which I'm not sure is automated but just thought I would mention 😄

@swissspidy swissspidy requested a review from a team January 5, 2022 09:52
@schlessera schlessera merged commit 6ddcbec into wp-cli:master Jan 5, 2022
@schlessera
Copy link
Copy Markdown
Member

@aaemnnosttv I merged this as-is for now. It would be great to have a PR with the script as well for future updates.

@aaemnnosttv
Copy link
Copy Markdown
Contributor Author

Thank you @schlessera!

Here's the PR for the script 👍 #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants