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 2c29e8b9a1
commit 87e62cbb7f
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 17 additions and 14 deletions

View File

@ -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/');

8
dist/index.js vendored
View File

@ -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');

View File

@ -281,11 +281,15 @@ export async function getWpCliUrl(version: string): Promise<string> {
export async function addComposer(tools_list: string[]): Promise<string[]> {
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');