diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 4bc7db4f..015caf08 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -222,9 +222,17 @@ describe('Tools tests', () => { 'a', 'b' ]); + expect(await tools.addComposer(['a', 'b', 'composer:1.2'])).toStrictEqual([ + 'composer', + 'a', + 'b' + ]); expect( await tools.addComposer(['a', 'b', 'composer:1.2.3']) - ).toStrictEqual(['composer', 'a', 'b']); + ).toStrictEqual(['composer:1.2.3', 'a', 'b']); + expect( + await tools.addComposer(['a', 'b', 'composer:v1.2.3']) + ).toStrictEqual(['composer:1.2.3', 'a', 'b']); expect( await tools.addComposer(['a', 'b', 'composer:snapshot']) ).toStrictEqual(['composer:snapshot', 'a', 'b']); @@ -304,7 +312,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, phpspec/phpspec, symfony/flex' + 'tool, composer:1.2, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex' ); expect(tools_list).toStrictEqual([ 'composer', diff --git a/dist/index.js b/dist/index.js index a44fb254..a13b9c05 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2022,7 +2022,7 @@ exports.getWpCliUrl = getWpCliUrl; */ async function addComposer(tools_list) { const regex_any = /^composer($|:.*)/; - const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/; + 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'; @@ -2034,7 +2034,7 @@ async function addComposer(tools_list) { case matches[0] == undefined: break; default: - composer = matches[matches.length - 1].replace(/v([1-2])/, '$1'); + composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1'); break; } tools_list.unshift(composer); diff --git a/src/tools.ts b/src/tools.ts index 050802d4..5914099b 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -305,7 +305,7 @@ 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_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'; @@ -317,7 +317,7 @@ export async function addComposer(tools_list: string[]): Promise { case matches[0] == undefined: break; default: - composer = matches[matches.length - 1].replace(/v([1-2])/, '$1'); + composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1'); break; } tools_list.unshift(composer);