Skip to content

Commit

Permalink
Make it compatible with direct url of archive file in dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Feb 15, 2017
1 parent 6eb2039 commit e7f0360
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
36 changes: 35 additions & 1 deletion Converter/PackageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
*/
abstract class PackageUtil
{
/**
* @var string[]
*/
private static $extensions = array(
'.zip',
'.tar',
'.tar.gz',
'.tar.bz2',
'.tar.Z',
'.tar.xz',
'.bz2',
'.gz',
);

/**
* Checks if the version is a URL version.
*
Expand All @@ -41,7 +55,7 @@ public static function checkUrlVersion(AssetTypeInterface $assetType, $dependenc
if (preg_match('/(\:\/\/)|\@/', $version)) {
list($url, $version) = static::splitUrlVersion($version);

if (static::hasUrlDependencySupported($url)) {
if (!static::isUrlArchive($url) && static::hasUrlDependencySupported($url)) {
$vcsRepos[] = array(
'type' => sprintf('%s-vcs', $assetType->getName()),
'url' => $url,
Expand All @@ -67,6 +81,26 @@ public static function checkUrlVersion(AssetTypeInterface $assetType, $dependenc
return array($dependency, $version);
}

/**
* Check if the url is a url of a archive file.
*
* @param string $url The url
*
* @return bool
*/
public static function isUrlArchive($url)
{
if (0 === strpos($url, 'http')) {
foreach (self::$extensions as $extension) {
if (substr($url, -strlen($extension)) === $extension) {
return true;
}
}
}

return false;
}

/**
* Checks if the version is a alias version.
*
Expand Down
1 change: 1 addition & 0 deletions Tests/Converter/BowerPackageConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testConvert()
'ASSET/test-library17-file' => '*',
'ASSET/test-library18-file' => '1.2.3',
'ASSET/test-library19-file' => '*',
'ASSET/test-library20-file' => '*',
), $composer['require']);

$this->assertArrayHasKey('require-dev', $composer);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Converter/NpmPackageConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testConvert()
'ASSET/test-library17-file' => '*',
'ASSET/test-library18-file' => '1.2.3',
'ASSET/test-library19-file' => '*',
'ASSET/library20' => '1 || 2',
'ASSET/test-library20-file' => '*',
'ASSET/library21' => '1 || 2',
), $composer['require']);

$this->assertArrayHasKey('require-dev', $composer);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Fixtures/package/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"library16": "library16#>=1 <2",
"library17": "http://foobar.tld/library17-1.2.3.js",
"library18": "http://foobar.tld/library18.js#1.2.3",
"library19": "http://foobar.tld/library19.js"
"library19": "http://foobar.tld/library19.js",
"library20": "http://foobar.tld/library20/v1.2.tar.gz"
},
"devDependencies": {
"dev-library1": ">= 1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion Tests/Fixtures/package/npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"library17": "http://foobar.tld/library17-1.2.3.js",
"library18": "http://foobar.tld/library18.js#1.2.3",
"library19": "http://foobar.tld/library19.js",
"library20": "1 || 2"
"library20": "http://foobar.tld/library20/v1.2.tar.gz",
"library21": "1 || 2"
},
"devDependencies": {
"dev-library1": ">= 1.0.0",
Expand Down

0 comments on commit e7f0360

Please sign in to comment.