Fix composer version for prestissimo & composer-prefetcher to v1

This commit is contained in:
Shivam Mathur 2020-10-25 00:55:01 +05:30
parent b108a66489
commit d0591e6d7c
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 20 additions and 22 deletions

View File

@ -261,6 +261,9 @@ describe('Tools tests', () => {
expect( expect(
await tools.addComposer(['a', 'b', 'c', 'composer:v2']) await tools.addComposer(['a', 'b', 'c', 'composer:v2'])
).toStrictEqual(['composer:2', 'a', 'b', 'c']); ).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 () => { it('checking getComposerUrl', async () => {
@ -310,15 +313,9 @@ describe('Tools tests', () => {
it('checking getCleanedToolsList', async () => { it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList( const tools_list: string[] = await tools.getCleanedToolsList(
'tool, composer:1.2.3, robmorgan/phinx, hirak/prestissimo, narrowspark/automatic-composer-prefetcher' 'tool, composer:1.2.3, robmorgan/phinx'
); );
expect(tools_list).toStrictEqual([ expect(tools_list).toStrictEqual(['composer', 'tool', 'phinx']);
'composer',
'tool',
'phinx',
'prestissimo',
'composer-prefetcher'
]);
}); });
it('checking addArchive', async () => { it('checking addArchive', async () => {
@ -433,7 +430,7 @@ describe('Tools tests', () => {
}); });
it('checking addTools on darwin', async () => { it('checking addTools on darwin', async () => {
const script: string = await tools.addTools( const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3', 'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, phpize, php-config, symfony:1.2.3',
'7.4', '7.4',
'darwin' 'darwin'
); );
@ -462,12 +459,6 @@ describe('Tools tests', () => {
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive' 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'
); );
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'
);
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony' 'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony'
); );
@ -476,7 +467,7 @@ describe('Tools tests', () => {
}); });
it('checking addTools on windows', async () => { it('checking addTools on windows', async () => {
const script: string = await tools.addTools( const script: string = await tools.addTools(
'codeception, cs2pr, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exist', 'codeception, cs2pr, deployer, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exist, composer',
'7.4', '7.4',
'win32' 'win32'
); );
@ -489,7 +480,6 @@ describe('Tools tests', () => {
expect(script).toContain( expect(script).toContain(
'Add-Tool https://deployer.org/deployer.phar deployer' 'Add-Tool https://deployer.org/deployer.phar deployer'
); );
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
expect(script).toContain( expect(script).toContain(
'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd' 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd'
); );
@ -511,7 +501,7 @@ describe('Tools tests', () => {
'win32' 'win32'
); );
expect(script).toContain( 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 prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/'); expect(script).toContain('Add-Composertool phinx phinx robmorgan/');

8
dist/index.js vendored
View File

@ -1895,11 +1895,15 @@ exports.getSymfonyUri = getSymfonyUri;
async function addComposer(tools_list) { async function addComposer(tools_list) {
const regex_any = /^composer($|:.*)/; const regex_any = /^composer($|:.*)/;
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/; 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)); const matches = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer'; let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool)); tools_list = tools_list.filter(tool => !regex_any.test(tool));
switch (matches[0]) { switch (true) {
case undefined: case regex_composer1_tools.test(tools_list.join(' ')):
composer = 'composer:1';
break;
case matches[0] == undefined:
break; break;
default: default:
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1'); composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');

View File

@ -283,11 +283,15 @@ export async function getSymfonyUri(
export async function addComposer(tools_list: string[]): Promise<string[]> { export async function addComposer(tools_list: string[]): Promise<string[]> {
const regex_any = /^composer($|:.*)/; const regex_any = /^composer($|:.*)/;
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/; 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)); const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer'; let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool)); tools_list = tools_list.filter(tool => !regex_any.test(tool));
switch (matches[0]) { switch (true) {
case undefined: case regex_composer1_tools.test(tools_list.join(' ')):
composer = 'composer:1';
break;
case matches[0] == undefined:
break; break;
default: default:
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1'); composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');