Skip to content

Commit

Permalink
first running version of composer-asset-plugin v2
Browse files Browse the repository at this point in the history
  • Loading branch information
simialbi committed Jul 19, 2022
1 parent 58f4ae0 commit 98cff5d
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 72 deletions.
10 changes: 5 additions & 5 deletions Converter/NpmPackageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public static function revertName(string $name): string
/**
* Convert the npm licenses list.
*
* @param array|string $licenses The npm package licenses list
* @param array|string|null $licenses The npm package licenses list
*
* @return array|string
* @return array|string|null
*/
public static function convertLicenses(array|string $licenses): array|string
public static function convertLicenses(array|string|null $licenses): array|string|null
{
if (!\is_array($licenses)) {
return $licenses;
Expand All @@ -82,11 +82,11 @@ public static function convertLicenses(array|string $licenses): array|string
/**
* Convert the author section.
*
* @param string|null $value The current value
* @param string|array|null $value The current value
*
* @return array|null
*/
public static function convertAuthor(?string $value): array|null
public static function convertAuthor(string|array|null $value): array|null
{
if (null !== $value) {
$value = [$value];
Expand Down
2 changes: 1 addition & 1 deletion Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected static function cleanVersion(string $version, array $matches): array

$matches = [];
preg_match('/^[a-z]+/', $end, $matches);
$type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : null;
$type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : '';
$end = substr($end, \strlen($type));

return [$type, $version, $end];
Expand Down
26 changes: 19 additions & 7 deletions Installer/AssetInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Fxp\Composer\AssetPlugin\Config\Config;
use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
use Fxp\Composer\AssetPlugin\Util\AssetPlugin;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

/**
* Installer for asset packages.
Expand All @@ -42,7 +44,7 @@ class AssetInstaller extends LibraryInstaller
* @param AssetTypeInterface $assetType
* @param Filesystem|null $filesystem
*/
public function __construct(Config $config, IOInterface $io, Composer $composer, AssetTypeInterface $assetType, Filesystem $filesystem = null)
public function __construct(Config $config, IOInterface $io, Composer $composer, AssetTypeInterface $assetType, ?Filesystem $filesystem = null)
{
parent::__construct($io, $composer, $assetType->getComposerType(), $filesystem);

Expand Down Expand Up @@ -89,25 +91,35 @@ protected function getPackageBasePath(PackageInterface $package): string
/**
* {@inheritDoc}
*/
protected function installCode(PackageInterface $package): void
protected function installCode(PackageInterface $package): PromiseInterface|null
{
$package = AssetPlugin::addMainFiles($this->config, $package);

parent::installCode($package);
$promise = parent::installCode($package);
if (!$promise instanceof PromiseInterface) {
$promise = resolve();
}

$this->deleteIgnoredFiles($package);
return $promise->then(function () use ($package) {
$this->deleteIgnoredFiles($package);
});
}

/**
* {@inheritDoc}
*/
protected function updateCode(PackageInterface $initial, PackageInterface $target): void
protected function updateCode(PackageInterface $initial, PackageInterface $target): PromiseInterface|null
{
$target = AssetPlugin::addMainFiles($this->config, $target);

parent::updateCode($initial, $target);
$promise = parent::updateCode($initial, $target);
if (!$promise instanceof PromiseInterface) {
$promise = resolve();
}

$this->deleteIgnoredFiles($target);
return $promise->then(function () use ($target) {
$this->deleteIgnoredFiles($target);
});
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Package/AbstractLazyCompletePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getIncludePaths(): array
/**
* {@inheritDoc}
*/
public function getNotificationUrl(): string
public function getNotificationUrl(): ?string
{
$this->initialize();

Expand Down Expand Up @@ -129,7 +129,7 @@ public function getAuthors(): array
/**
* {@inheritDoc}
*/
public function getDescription(): string
public function getDescription(): ?string
{
$this->initialize();

Expand All @@ -139,7 +139,7 @@ public function getDescription(): string
/**
* {@inheritDoc}
*/
public function getHomepage(): string
public function getHomepage(): ?string
{
$this->initialize();

Expand Down
24 changes: 12 additions & 12 deletions Package/LazyCompletePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getTransportOptions(): array
/**
* {@inheritDoc}
*/
public function getTargetDir(): string
public function getTargetDir(): ?string
{
$this->initialize();

Expand Down Expand Up @@ -61,7 +61,7 @@ public function getBinaries(): array
/**
* {@inheritDoc}
*/
public function getInstallationSource(): string
public function getInstallationSource(): ?string
{
$this->initialize();

Expand All @@ -71,7 +71,7 @@ public function getInstallationSource(): string
/**
* {@inheritDoc}
*/
public function getSourceType(): string
public function getSourceType(): ?string
{
$this->initialize();

Expand All @@ -81,7 +81,7 @@ public function getSourceType(): string
/**
* {@inheritDoc}
*/
public function getSourceUrl(): string
public function getSourceUrl(): ?string
{
$this->initialize();

Expand All @@ -91,7 +91,7 @@ public function getSourceUrl(): string
/**
* {@inheritDoc}
*/
public function getSourceReference(): string
public function getSourceReference(): ?string
{
$this->initialize();

Expand All @@ -101,7 +101,7 @@ public function getSourceReference(): string
/**
* {@inheritDoc}
*/
public function getSourceMirrors(): array
public function getSourceMirrors(): ?array
{
$this->initialize();

Expand All @@ -121,7 +121,7 @@ public function getSourceUrls(): array
/**
* {@inheritDoc}
*/
public function getDistType(): string
public function getDistType(): ?string
{
$this->initialize();

Expand All @@ -131,7 +131,7 @@ public function getDistType(): string
/**
* {@inheritDoc}
*/
public function getDistUrl(): string
public function getDistUrl(): ?string
{
$this->initialize();

Expand All @@ -141,7 +141,7 @@ public function getDistUrl(): string
/**
* {@inheritDoc}
*/
public function getDistReference(): string
public function getDistReference(): ?string
{
$this->initialize();

Expand All @@ -151,7 +151,7 @@ public function getDistReference(): string
/**
* {@inheritDoc}
*/
public function getDistSha1Checksum(): string
public function getDistSha1Checksum(): ?string
{
$this->initialize();

Expand All @@ -161,7 +161,7 @@ public function getDistSha1Checksum(): string
/**
* {@inheritDoc}
*/
public function getDistMirrors(): array
public function getDistMirrors(): ?array
{
$this->initialize();

Expand All @@ -181,7 +181,7 @@ public function getDistUrls(): array
/**
* {@inheritDoc}
*/
public function getReleaseDate(): \DateTimeInterface
public function getReleaseDate(): ?\DateTimeInterface
{
$this->initialize();

Expand Down
2 changes: 1 addition & 1 deletion Package/Loader/LazyAssetPackageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function setAssetRepositoryManager(AssetRepositoryManager $assetRepositor
/**
* {@inheritDoc}
*/
public function load(LazyPackageInterface $package): LazyPackageInterface|false
public function load(LazyPackageInterface $package): CompletePackageInterface|false
{
if (isset($this->cache[$package->getUniqueName()])) {
return $this->cache[$package->getUniqueName()];
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
NPM/Bower Dependency Manager for Composer
=========================================
NPM/Bower Dependency Manager for Composer v2
============================================

[![Latest Version](https://img.shields.io/packagist/v/fxp/composer-asset-plugin.svg)](https://packagist.org/packages/fxp/composer-asset-plugin)
[![Build Status](https://img.shields.io/travis/com/fxpio/composer-asset-plugin.svg)](https://travis-ci.com/fxpio/composer-asset-plugin)
[![Coverage Status](https://img.shields.io/coveralls/fxpio/composer-asset-plugin.svg)](https://coveralls.io/r/fxpio/composer-asset-plugin)
[![SymfonyInsight](https://img.shields.io/symfony/i/grade/0d67ca33-5a72-46b8-b109-cfbf95673fce.svg)](https://insight.symfony.com/projects/0d67ca33-5a72-46b8-b109-cfbf95673fce)
[![Packagist Downloads](https://img.shields.io/packagist/dt/fxp/composer-asset-plugin.svg)](https://packagist.org/packages/fxp/composer-asset-plugin/stats)
[![Latest Stable Version](https://poser.pugx.org/simialbi/composer-asset-plugin/v/stable?format=flat-square)](https://packagist.org/packages/simialbi/composer-asset-plugin)
[![Total Downloads](https://poser.pugx.org/simialbi/composer-asset-plugin/downloads?format=flat-square)](https://packagist.org/packages/simialbi/composer-asset-plugin)
[![License](https://poser.pugx.org/simialbi/composer-asset-plugin/license?format=flat-square)](https://packagist.org/packages/simialbi/composer-asset-plugin)
[![build](https://github.com/simialbi/composer-asset-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/simialbi/composer-asset-plugin/actions/workflows/build.yml)

The Composer Asset Plugin allows you to manage project assets (css, js, etc.) in your `composer.json`
without installing NPM or Bower.
Expand Down Expand Up @@ -105,7 +104,7 @@ The bulk of the documentation is located in `Resources/doc/index.md`:

[Read the FAQs](Resources/doc/faqs.md)

[Read the Release Notes](https://github.com/fxpio/composer-asset-plugin/releases)
[Read the Release Notes](https://github.com/simialbi/composer-asset-plugin/releases)

Installation
------------
Expand Down
7 changes: 5 additions & 2 deletions Repository/AbstractAssetVcsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected function initLoader(): void
/**
* Initializes the root identifier.
*
* @param VcsDriverInterface $driver
* @return void
*/
protected function initRootIdentifier(VcsDriverInterface $driver): void
Expand Down Expand Up @@ -221,12 +222,12 @@ protected function createPackageName(): string
* @return array The package config
*/
#[ArrayShape(['name' => 'string', 'version' => 'string', 'type' => 'string'])]
protected function createMockOfPackageConfig(string $name, string $version)
protected function createMockOfPackageConfig(string $name, string $version): array
{
return [
'name' => $name,
'version' => $version,
'type' => $this->assetType->getComposerType(),
'type' => $this->assetType->getComposerType()
];
}

Expand Down Expand Up @@ -279,6 +280,7 @@ protected function preProcessAsset(array $data): array
* @param string $branch The branch name
*
* @return PackageInterface
* @throws \ReflectionException
*/
protected function overrideBranchAliasConfig(PackageInterface $package, string $aliasNormalized, string $branch): PackageInterface
{
Expand All @@ -303,6 +305,7 @@ protected function overrideBranchAliasConfig(PackageInterface $package, string $
*/
protected function addPackageAliases(PackageInterface $package, string $aliasNormalized): PackageInterface
{
/** @var \Composer\Package\BasePackage $package */
$alias = new AliasPackage($package, $aliasNormalized, $this->rootPackageVersion);
$this->addPackage($alias);

Expand Down
Loading

0 comments on commit 98cff5d

Please sign in to comment.