From 87e62cbb7f1f196fda82cb871c31d8a6c51387d9 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 25 Oct 2020 00:55:01 +0530 Subject: [PATCH] Fix composer version for prestissimo & composer-prefetcher to v1 --- __tests__/tools.test.ts | 15 +++++---------- dist/index.js | 8 ++++++-- src/tools.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 632724e0..9b527ead 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -228,6 +228,9 @@ 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 () => { @@ -277,7 +280,7 @@ describe('Tools tests', () => { it('checking getCleanedToolsList', async () => { const tools_list: string[] = await tools.getCleanedToolsList( - 'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, hirak/prestissimo, narrowspark/automatic-composer-prefetcher, phpspec/phpspec, symfony/flex' + 'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex' ); expect(tools_list).toStrictEqual([ 'composer', @@ -286,8 +289,6 @@ describe('Tools tests', () => { 'composer-unused', 'vapor-cli', 'phinx', - 'prestissimo', - 'composer-prefetcher', 'phpspec', 'flex' ]); @@ -433,7 +434,6 @@ describe('Tools tests', () => { 'blackfire', 'blackfire-player', 'composer-normalize', - 'composer-prefetcher:1.2.3', 'composer-require-checker', 'composer-unused', 'cs2pr:1.2.3', @@ -522,9 +522,6 @@ describe('Tools tests', () => { expect(script).toContain( 'add_composertool composer-unused composer-unused icanhazstring/' ); - expect(script).toContain( - 'add_composertool composer-prefetcher composer-prefetcher:1.2.3 narrowspark/automatic-' - ); expect(script).toContain( 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony version' ); @@ -551,7 +548,6 @@ describe('Tools tests', () => { 'php-config', 'phpize', 'phpmd', - 'prestissimo', 'symfony', 'wp-cli' ]; @@ -576,7 +572,6 @@ describe('Tools tests', () => { expect(script).toContain( 'Add-Tool https://deployer.org/deployer.phar deployer "-V"' ); - expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/'); expect(script).toContain( 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"' ); @@ -608,7 +603,7 @@ describe('Tools tests', () => { ); expect(script).toContain( - 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer' + 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer' ); expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/'); expect(script).toContain('Add-Composertool phinx phinx robmorgan/'); diff --git a/dist/index.js b/dist/index.js index d4ab418a..67e39ec8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2006,11 +2006,15 @@ exports.getWpCliUrl = getWpCliUrl; async function addComposer(tools_list) { const regex_any = /^composer($|:.*)/; const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/; + 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 (matches[0]) { - case undefined: + switch (true) { + case regex_composer1_tools.test(tools_list.join(' ')): + composer = 'composer:1'; + break; + case matches[0] == undefined: break; default: composer = matches[matches.length - 1].replace(/v([1-2])/, '$1'); diff --git a/src/tools.ts b/src/tools.ts index 922a1678..75aace92 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -281,11 +281,15 @@ 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]$)/; + 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 (matches[0]) { - case undefined: + switch (true) { + case regex_composer1_tools.test(tools_list.join(' ')): + composer = 'composer:1'; + break; + case matches[0] == undefined: break; default: composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');