From 09222f42ae488a3194a252117f236798df25a1f4 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 17 Nov 2020 19:03:45 +0530 Subject: [PATCH] Skip prestissimo and composer-prefetcher unless composer:v1 is specified --- __tests__/tools.test.ts | 4 +--- dist/index.js | 4 ---- src/scripts/win32.ps1 | 13 +++++++++---- src/tools.ts | 4 ---- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 1a371458..026b190d 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -251,9 +251,6 @@ describe('Tools tests', () => { expect( await tools.addComposer(['a', 'b', 'c', 'composer:v2']) ).toStrictEqual(['composer:2', 'a', 'b', 'c']); - expect( - await tools.addComposer(['hirak', 'b', 'c', 'composer:v2']) - ).toStrictEqual(['composer:1', 'hirak', 'b', 'c']); }); it('checking getComposerUrl', async () => { @@ -629,6 +626,7 @@ describe('Tools tests', () => { }); it('checking addTools with composer tool using user/tool as input', async () => { const listOfTools = [ + 'composer:v1', 'hirak/prestissimo', 'narrowspark/automatic-composer-prefetcher', 'robmorgan/phinx' diff --git a/dist/index.js b/dist/index.js index 83dc03c9..c1193fa8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2023,14 +2023,10 @@ exports.getWpCliUrl = getWpCliUrl; async function addComposer(tools_list) { const regex_any = /^composer($|:.*)/; const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/; - const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/; const matches = tools_list.filter(tool => regex_valid.test(tool)); let composer = 'composer'; tools_list = tools_list.filter(tool => !regex_any.test(tool)); switch (true) { - case regex_composer1_tools.test(tools_list.join(' ')): - composer = 'composer:1'; - break; case matches[0] == undefined: break; default: diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 5611ec6b..375b6da1 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -222,12 +222,12 @@ Function Get-ToolVersion() { $version_regex = "[0-9]+((\.{1}[0-9]+)+)(\.{0})(-[a-z0-9]+){0,1}" if($tool -eq 'composer') { if ($param -eq 'snapshot') { - $trunk = Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } - $commit = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value } - return "$trunk+$commit" + $composer_version = (Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }) + '+' + (Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value }) } else { - return Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } + $composer_version = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } } + Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global + return "$composer_version" } return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value } } @@ -310,6 +310,11 @@ Function Add-Composertool() { [string] $prefix ) + if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") { + Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool" + Add-Log $cross $tool "Skipped" + Return + } composer global require $prefix$release 2>&1 | out-null $json = findstr $prefix$tool $env:APPDATA\Composer\composer.json if(Test-Path $composer_bin\composer) { diff --git a/src/tools.ts b/src/tools.ts index 1a17502c..24c3a2e0 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -306,14 +306,10 @@ export async function getWpCliUrl(version: string): Promise { export async function addComposer(tools_list: string[]): Promise { const regex_any = /^composer($|:.*)/; const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/; - const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/; const matches: string[] = tools_list.filter(tool => regex_valid.test(tool)); let composer = 'composer'; tools_list = tools_list.filter(tool => !regex_any.test(tool)); switch (true) { - case regex_composer1_tools.test(tools_list.join(' ')): - composer = 'composer:1'; - break; case matches[0] == undefined: break; default: