Fix reading composer package type for older versions

This commit is contained in:
Shivam Mathur 2022-07-20 19:24:19 +05:30
parent e57ea715eb
commit 66f24470dc
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
2 changed files with 8 additions and 3 deletions

View File

@ -201,11 +201,15 @@ Function Add-ComposertoolHelper() {
[string] [string]
$composer_args $composer_args
) )
$tool_version = $release.split(':')[1]
if($NULL -eq $tool_version) {
$tool_version = '*'
}
if($scope -eq 'global') { if($scope -eq 'global') {
if(Test-Path $composer_lock) { if(Test-Path $composer_lock) {
Remove-Item -Path $composer_lock -Force Remove-Item -Path $composer_lock -Force
} }
if((composer global show $prefix$tool -a 2>&1 | findstr '^type *: *composer-plugin') -and ($composer_args -ne '')) { if((composer global show $prefix$tool $tool_version -a 2>&1 | findstr '^type *: *composer-plugin') -and ($composer_args -ne '')) {
composer global config --no-plugins allow-plugins."$prefix$tool" true >$null 2>&1 composer global config --no-plugins allow-plugins."$prefix$tool" true >$null 2>&1
} }
composer global require $prefix$release $composer_args >$null 2>&1 composer global require $prefix$release $composer_args >$null 2>&1

View File

@ -160,9 +160,10 @@ add_composertool_helper() {
scope=$4 scope=$4
composer_args=$5 composer_args=$5
enable_extensions curl mbstring openssl enable_extensions curl mbstring openssl
tool_version=${release##*:}; [ "$tool_version" = "$tool" ] && tool_version="*"
if [ "$scope" = "global" ]; then if [ "$scope" = "global" ]; then
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
if composer global show "$prefix$tool" -a 2>&1 | grep -qE '^type *: *composer-plugin' && [ -n "$composer_args" ]; then if composer global show "$prefix$tool" "$tool_version" -a 2>&1 | grep -qE '^type *: *composer-plugin' && [ -n "$composer_args" ]; then
composer global config --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1 composer global config --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1
fi fi
composer global require "$prefix$release" "$composer_args" >/dev/null 2>&1 composer global require "$prefix$release" "$composer_args" >/dev/null 2>&1
@ -172,7 +173,7 @@ add_composertool_helper() {
if ! [ -d "$scoped_dir" ]; then if ! [ -d "$scoped_dir" ]; then
mkdir -p "$scoped_dir" mkdir -p "$scoped_dir"
echo '{}' | tee "$scoped_dir/composer.json" >/dev/null echo '{}' | tee "$scoped_dir/composer.json" >/dev/null
if composer show "$prefix$tool" -d "$scoped_dir" -a 2>&1 | grep -qE '^type *: *composer-plugin' && [ -n "$composer_args" ]; then if composer show "$prefix$tool" "$tool_version" -d "$scoped_dir" -a 2>&1 | grep -qE '^type *: *composer-plugin' && [ -n "$composer_args" ]; then
composer config -d "$scoped_dir" --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1 composer config -d "$scoped_dir" --no-plugins allow-plugins."$prefix$tool" true >/dev/null 2>&1
fi fi
composer require "$prefix$release" -d "$scoped_dir" "$composer_args" >/dev/null 2>&1 composer require "$prefix$release" -d "$scoped_dir" "$composer_args" >/dev/null 2>&1