*/
- public function getPackageVersion(string $url): ?string;
+ public function downloadPackages(array $importMapEntries, callable $progressCallback = null): array;
}
diff --git a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/ResolvedImportMapPackage.php b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/ResolvedImportMapPackage.php
index ed8a6cb854727..8c2c4e90e4bf2 100644
--- a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/ResolvedImportMapPackage.php
+++ b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/ResolvedImportMapPackage.php
@@ -11,15 +11,15 @@
namespace Symfony\Component\AssetMapper\ImportMap\Resolver;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapType;
use Symfony\Component\AssetMapper\ImportMap\PackageRequireOptions;
final class ResolvedImportMapPackage
{
public function __construct(
public readonly PackageRequireOptions $requireOptions,
- public readonly string $url,
- public readonly ?string $content = null,
- public readonly ?string $version = null,
+ public readonly string $version,
+ public readonly ImportMapType $type,
) {
}
}
diff --git a/src/Symfony/Component/AssetMapper/MappedAsset.php b/src/Symfony/Component/AssetMapper/MappedAsset.php
index 0f0bef63fee74..58bfc93e52fe6 100644
--- a/src/Symfony/Component/AssetMapper/MappedAsset.php
+++ b/src/Symfony/Component/AssetMapper/MappedAsset.php
@@ -27,8 +27,11 @@ final class MappedAsset
public readonly string $content;
public readonly string $digest;
public readonly bool $isPredigested;
+ public readonly bool $isVendor;
/**
+ * Assets whose content affects the content of this asset.
+ *
* @var MappedAsset[]
*/
private array $dependencies = [];
@@ -55,6 +58,7 @@ public function __construct(
string $content = null,
string $digest = null,
bool $isPredigested = null,
+ bool $isVendor = false,
array $dependencies = [],
array $fileDependencies = [],
array $javaScriptImports = [],
@@ -78,6 +82,7 @@ public function __construct(
if (null !== $isPredigested) {
$this->isPredigested = $isPredigested;
}
+ $this->isVendor = $isVendor;
$this->dependencies = $dependencies;
$this->fileDependencies = $fileDependencies;
$this->javaScriptImports = $javaScriptImports;
diff --git a/src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php b/src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php
index b99a904139c42..74642c012ee3e 100644
--- a/src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php
@@ -69,7 +69,7 @@ public function testAssetsAreCompiled()
$finder = new Finder();
$finder->in($targetBuildDir)->files();
- $this->assertCount(10, $finder); // 7 files + manifest.json & importmap.json + entrypoint.file6.json
+ $this->assertCount(12, $finder); // 9 files + manifest.json & importmap.json + entrypoint.file6.json
$this->assertFileExists($targetBuildDir.'/manifest.json');
$this->assertSame([
@@ -78,6 +78,8 @@ public function testAssetsAreCompiled()
'file2.js',
'file3.css',
'file4.js',
+ 'lodash.js',
+ 'stimulus.js',
'subdir/file5.js',
'subdir/file6.js',
], array_keys(json_decode(file_get_contents($targetBuildDir.'/manifest.json'), true)));
diff --git a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php
index 3010548b961d7..e30c4361e93dc 100644
--- a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php
@@ -40,7 +40,7 @@ public function testCompile(string $sourceLogicalName, string $input, array $exp
}
if ('module_in_importmap_remote' === $importName) {
- return new ImportMapEntry('module_in_importmap_local_asset', url: 'https://example.com/module.js');
+ return new ImportMapEntry('module_in_importmap_local_asset', version: '1.2.3');
}
return null;
diff --git a/src/Symfony/Component/AssetMapper/Tests/Factory/MappedAssetFactoryTest.php b/src/Symfony/Component/AssetMapper/Tests/Factory/MappedAssetFactoryTest.php
index c527b4678ba4c..c4b09bec5056a 100644
--- a/src/Symfony/Component/AssetMapper/Tests/Factory/MappedAssetFactoryTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/Factory/MappedAssetFactoryTest.php
@@ -113,6 +113,14 @@ public function testCreateMappedAssetWithPredigested()
$this->assertTrue($asset->isPredigested);
}
+ public function testCreateMappedAssetInVendor()
+ {
+ $assetMapper = $this->createFactory();
+ $asset = $assetMapper->createMappedAsset('lodash.js', __DIR__.'/../fixtures/assets/vendor/lodash.js');
+ $this->assertSame('lodash.js', $asset->logicalPath);
+ $this->assertTrue($asset->isVendor);
+ }
+
private function createFactory(AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
{
$compilers = [
@@ -137,7 +145,8 @@ private function createFactory(AssetCompilerInterface $extraCompiler = null): Ma
$factory = new MappedAssetFactory(
$pathResolver,
- $compiler
+ $compiler,
+ __DIR__.'/../fixtures/assets/vendor',
);
// mock the AssetMapper to behave like normal: by calling back to the factory
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php
index fe8bc62624677..07e6512696dea 100644
--- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php
@@ -19,7 +19,6 @@
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
use Symfony\Component\AssetMapper\ImportMap\ImportMapPackageAudit;
use Symfony\Component\AssetMapper\ImportMap\ImportMapPackageAuditVulnerability;
-use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -27,16 +26,14 @@
class ImportMapAuditorTest extends TestCase
{
private ImportMapConfigReader $importMapConfigReader;
- private PackageResolverInterface $packageResolver;
private HttpClientInterface $httpClient;
private ImportMapAuditor $importMapAuditor;
protected function setUp(): void
{
$this->importMapConfigReader = $this->createMock(ImportMapConfigReader::class);
- $this->packageResolver = $this->createMock(PackageResolverInterface::class);
$this->httpClient = new MockHttpClient();
- $this->importMapAuditor = new ImportMapAuditor($this->importMapConfigReader, $this->packageResolver, $this->httpClient);
+ $this->importMapAuditor = new ImportMapAuditor($this->importMapConfigReader, $this->httpClient);
}
public function testAudit()
@@ -70,17 +67,14 @@ public function testAudit()
$this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
'@hotwired/stimulus' => new ImportMapEntry(
importName: '@hotwired/stimulus',
- url: 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
version: '3.2.1',
),
'json5' => new ImportMapEntry(
importName: 'json5',
- url: 'https://cdn.jsdelivr.net/npm/json5@1.0.0/+esm',
version: '1.0.0',
),
'lodash' => new ImportMapEntry(
importName: 'lodash',
- url: 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
version: '4.17.21',
),
]));
@@ -126,7 +120,6 @@ public function testAuditWithVersionRange(bool $expectMatch, string $version, ?s
$this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
'json5' => new ImportMapEntry(
importName: 'json5',
- url: "https://cdn.jsdelivr.net/npm/json5@$version/+esm",
version: $version,
),
]));
@@ -149,40 +142,12 @@ public function provideAuditWithVersionRange(): iterable
yield [false, '1.2.0', '> 1.0.0, < 1.2.0'];
}
- public function testAuditWithVersionResolving()
- {
- $this->httpClient->setResponseFactory(new MockResponse('[]'));
- $this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
- '@hotwired/stimulus' => new ImportMapEntry(
- importName: '@hotwired/stimulus',
- url: 'https://unpkg.com/@hotwired/stimulus/dist/stimulus.js',
- version: '3.2.1',
- ),
- 'json5' => new ImportMapEntry(
- importName: 'json5',
- url: 'https://cdn.jsdelivr.net/npm/json5/+esm',
- ),
- 'lodash' => new ImportMapEntry(
- importName: 'lodash',
- url: 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
- ),
- ]));
- $this->packageResolver->method('getPackageVersion')->willReturn('1.2.3');
-
- $audit = $this->importMapAuditor->audit();
-
- $this->assertSame('3.2.1', $audit[0]->version);
- $this->assertSame('1.2.3', $audit[1]->version);
- $this->assertSame('1.2.3', $audit[2]->version);
- }
-
public function testAuditError()
{
$this->httpClient->setResponseFactory(new MockResponse('Server error', ['http_code' => 500]));
$this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
'json5' => new ImportMapEntry(
importName: 'json5',
- url: 'https://cdn.jsdelivr.net/npm/json5@1.0.0/+esm',
version: '1.0.0',
),
]));
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php
index 0b971934e8606..da6636ae822c1 100644
--- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php
@@ -43,11 +43,7 @@ public function testGetEntriesAndWriteEntries()
[
- 'url' => 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
- ],
- 'remote_package_downloaded' => [
- 'downloaded_to' => 'vendor/lodash.js',
- 'url' => 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
+ 'version' => '3.2.1',
],
'local_package' => [
'path' => 'app.js',
@@ -69,28 +65,23 @@ public function testGetEntriesAndWriteEntries()
$this->assertInstanceOf(ImportMapEntries::class, $entries);
/** @var ImportMapEntry[] $allEntries */
$allEntries = iterator_to_array($entries);
- $this->assertCount(5, $allEntries);
+ $this->assertCount(4, $allEntries);
$remotePackageEntry = $allEntries[0];
$this->assertSame('remote_package', $remotePackageEntry->importName);
$this->assertNull($remotePackageEntry->path);
- $this->assertSame('https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js', $remotePackageEntry->url);
- $this->assertFalse($remotePackageEntry->isDownloaded);
+ $this->assertSame('3.2.1', $remotePackageEntry->version);
$this->assertSame('js', $remotePackageEntry->type->value);
$this->assertFalse($remotePackageEntry->isEntrypoint);
- $remotePackageDownloadedEntry = $allEntries[1];
- $this->assertSame('https://ga.jspm.io/npm:lodash@4.17.21/lodash.js', $remotePackageDownloadedEntry->url);
- $this->assertSame('vendor/lodash.js', $remotePackageDownloadedEntry->path);
-
- $localPackageEntry = $allEntries[2];
- $this->assertNull($localPackageEntry->url);
+ $localPackageEntry = $allEntries[1];
+ $this->assertNull($localPackageEntry->version);
$this->assertSame('app.js', $localPackageEntry->path);
- $typeCssEntry = $allEntries[3];
+ $typeCssEntry = $allEntries[2];
$this->assertSame('css', $typeCssEntry->type->value);
- $entryPointEntry = $allEntries[4];
+ $entryPointEntry = $allEntries[3];
$this->assertTrue($entryPointEntry->isEntrypoint);
// now save the original raw data from importmap.php and delete the file
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php
index 2a7bcc519d2bc..51e4a25c60520 100644
--- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php
@@ -21,13 +21,12 @@
use Symfony\Component\AssetMapper\ImportMap\ImportMapType;
use Symfony\Component\AssetMapper\ImportMap\JavaScriptImport;
use Symfony\Component\AssetMapper\ImportMap\PackageRequireOptions;
+use Symfony\Component\AssetMapper\ImportMap\RemotePackageDownloader;
use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface;
use Symfony\Component\AssetMapper\ImportMap\Resolver\ResolvedImportMapPackage;
use Symfony\Component\AssetMapper\MappedAsset;
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface;
use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Contracts\HttpClient\HttpClientInterface;
-use Symfony\Contracts\HttpClient\ResponseInterface;
class ImportMapManagerTest extends TestCase
{
@@ -35,7 +34,7 @@ class ImportMapManagerTest extends TestCase
private PublicAssetsPathResolverInterface&MockObject $pathResolver;
private PackageResolverInterface&MockObject $packageResolver;
private ImportMapConfigReader&MockObject $configReader;
- private HttpClientInterface&MockObject $httpClient;
+ private RemotePackageDownloader&MockObject $remotePackageDownloader;
private ImportMapManager $importMapManager;
private Filesystem $filesystem;
@@ -65,6 +64,7 @@ public function testGetRawImportMapData(array $importMapEntries, array $mappedAs
$manager = $this->createImportMapManager();
$this->mockImportMap($importMapEntries);
$this->mockAssetMapper($mappedAssets);
+ $this->mockDownloader($importMapEntries);
$this->configReader->expects($this->any())
->method('getRootDirectory')
->willReturn('/fake/root');
@@ -74,40 +74,23 @@ public function testGetRawImportMapData(array $importMapEntries, array $mappedAs
public function getRawImportMapDataTests(): iterable
{
- yield 'it returns simple remote entry' => [
+ yield 'it returns remote downloaded entry' => [
[
new ImportMapEntry(
'@hotwired/stimulus',
- url: 'https://anyurl.com/stimulus'
- ),
- ],
- [],
- [
- '@hotwired/stimulus' => [
- 'path' => 'https://anyurl.com/stimulus',
- 'type' => 'js',
- ],
- ],
- ];
-
- yield 'it sets path to local path when remote package is downloaded' => [
- [
- new ImportMapEntry(
- '@hotwired/stimulus',
- path: 'vendor/stimulus.js',
- url: 'https://anyurl.com/stimulus',
- isDownloaded: true,
+ version: '1.2.3'
),
],
[
new MappedAsset(
- 'vendor/stimulus.js',
- publicPath: '/assets/vendor/stimulus.js',
+ 'vendor/@hotwired/stimulus.js',
+ self::$writableRoot.'/assets/vendor/@hotwired/stimulus.js',
+ publicPath: '/assets/vendor/@hotwired/stimulus-d1g35t.js',
),
],
[
'@hotwired/stimulus' => [
- 'path' => '/assets/vendor/stimulus.js',
+ 'path' => '/assets/vendor/@hotwired/stimulus-d1g35t.js',
'type' => 'js',
],
],
@@ -644,23 +627,15 @@ public function testGetEntrypointNames()
/**
* @dataProvider getRequirePackageTests
*/
- public function testRequire(array $packages, int $expectedProviderPackageArgumentCount, array $resolvedPackages, array $expectedImportMap, array $expectedDownloadedFiles)
+ public function testRequire(array $packages, int $expectedProviderPackageArgumentCount, array $resolvedPackages, array $expectedImportMap)
{
$manager = $this->createImportMapManager();
// physical file we point to in one test
$this->writeFile('assets/some_file.js', 'some file contents');
- // make it so that downloaded files are found in AssetMapper
$this->assetMapper->expects($this->any())
->method('getAssetFromSourcePath')
- ->willReturnCallback(function (string $sourcePath) use ($expectedDownloadedFiles) {
- foreach ($expectedDownloadedFiles as $file => $contents) {
- $expectedPath = self::$writableRoot.'/assets/vendor/'.$file;
- if (realpath($expectedPath) === realpath($sourcePath)) {
- return new MappedAsset('vendor/'.$file, $sourcePath);
- }
- }
-
+ ->willReturnCallback(function (string $sourcePath) {
if (str_ends_with($sourcePath, 'some_file.js')) {
// physical file we point to in one test
return new MappedAsset('some_file.js', $sourcePath);
@@ -685,8 +660,8 @@ public function testRequire(array $packages, int $expectedProviderPackageArgumen
$simplifiedEntries = [];
foreach ($entries as $entry) {
$simplifiedEntries[$entry->importName] = [
- 'url' => $entry->url,
- ($entry->isDownloaded ? 'downloaded_to' : 'path') => $entry->path,
+ 'version' => $entry->version,
+ 'path' => $entry->path,
'type' => $entry->type->value,
'entrypoint' => $entry->isEntrypoint,
];
@@ -695,7 +670,9 @@ public function testRequire(array $packages, int $expectedProviderPackageArgumen
$this->assertSame(array_keys($expectedImportMap), array_keys($simplifiedEntries));
foreach ($expectedImportMap as $name => $expectedData) {
foreach ($expectedData as $key => $val) {
- $this->assertSame($val, $simplifiedEntries[$name][$key]);
+ // correct windows paths for comparison
+ $actualPath = str_replace('\\', '/', $simplifiedEntries[$name][$key]);
+ $this->assertSame($val, $actualPath);
}
}
@@ -712,11 +689,6 @@ public function testRequire(array $packages, int $expectedProviderPackageArgumen
;
$manager->require($packages);
- foreach ($expectedDownloadedFiles as $file => $expectedContents) {
- $this->assertFileExists(self::$writableRoot.'/assets/vendor/'.$file);
- $actualContents = file_get_contents(self::$writableRoot.'/assets/vendor/'.$file);
- $this->assertSame($expectedContents, $actualContents);
- }
}
public static function getRequirePackageTests(): iterable
@@ -725,113 +697,60 @@ public static function getRequirePackageTests(): iterable
'packages' => [new PackageRequireOptions('lodash')],
'expectedProviderPackageArgumentCount' => 1,
'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
+ self::resolvedPackage('lodash', '1.2.3'),
],
'expectedImportMap' => [
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
+ 'version' => '1.2.3',
],
],
- 'expectedDownloadedFiles' => [],
];
yield 'require two packages' => [
'packages' => [new PackageRequireOptions('lodash'), new PackageRequireOptions('cowsay')],
'expectedProviderPackageArgumentCount' => 2,
'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
- self::resolvedPackage('cowsay', 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.js'),
+ self::resolvedPackage('lodash', '1.2.3'),
+ self::resolvedPackage('cowsay', '4.5.6'),
],
'expectedImportMap' => [
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
+ 'version' => '1.2.3',
],
'cowsay' => [
- 'url' => 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.js',
+ 'version' => '4.5.6',
],
],
- 'expectedDownloadedFiles' => [],
];
yield 'single_package_that_returns_as_two' => [
'packages' => [new PackageRequireOptions('lodash')],
'expectedProviderPackageArgumentCount' => 1,
'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
- self::resolvedPackage('lodash-dependency', 'https://ga.jspm.io/npm:lodash-dependency@9.8.7/lodash-dependency.js'),
+ self::resolvedPackage('lodash', '1.2.3'),
+ self::resolvedPackage('lodash-dependency', '9.8.7'),
],
'expectedImportMap' => [
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
+ 'version' => '1.2.3',
],
'lodash-dependency' => [
- 'url' => 'https://ga.jspm.io/npm:lodash-dependency@9.8.7/lodash-dependency.js',
+ 'version' => '9.8.7',
],
],
- 'expectedDownloadedFiles' => [],
];
yield 'single_package_with_version_constraint' => [
'packages' => [new PackageRequireOptions('lodash', '^1.2.3')],
'expectedProviderPackageArgumentCount' => 1,
'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.7/lodash.js'),
+ self::resolvedPackage('lodash', '1.2.7'),
],
'expectedImportMap' => [
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.7/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
-
- yield 'single_package_that_downloads' => [
- 'packages' => [new PackageRequireOptions('lodash', download: true)],
- 'expectedProviderPackageArgumentCount' => 1,
- 'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js', download: true, content: 'the code in lodash.js'),
- ],
- 'expectedImportMap' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- 'downloaded_to' => 'vendor/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [
- 'lodash.js' => 'the code in lodash.js',
- ],
- ];
-
- yield 'single_package_that_downloads_a_css_file' => [
- 'packages' => [new PackageRequireOptions('bootstrap/dist/css/bootstrap.min.css', download: true)],
- 'expectedProviderPackageArgumentCount' => 1,
- 'resolvedPackages' => [
- self::resolvedPackage('bootstrap/dist/css/bootstrap.min.css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css', download: true, content: 'some sweet CSS'),
- ],
- 'expectedImportMap' => [
- 'bootstrap/dist/css/bootstrap.min.css' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css',
- 'downloaded_to' => 'vendor/bootstrap/dist/css/bootstrap.min.css',
- 'type' => 'css',
- ],
- ],
- 'expectedDownloadedFiles' => [
- 'bootstrap/dist/css/bootstrap.min.css' => 'some sweet CSS',
- ],
- ];
-
- yield 'single_package_with_custom_import_name' => [
- 'packages' => [new PackageRequireOptions('lodash', importName: 'lodash-es')],
- 'expectedProviderPackageArgumentCount' => 1,
- 'resolvedPackages' => [
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js', importName: 'lodash-es'),
- ],
- 'expectedImportMap' => [
- 'lodash-es' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
+ 'version' => '1.2.7',
],
],
- 'expectedDownloadedFiles' => [],
];
yield 'single_package_with_a_path' => [
@@ -844,7 +763,6 @@ public static function getRequirePackageTests(): iterable
'path' => './assets/some_file.js',
],
],
- 'expectedDownloadedFiles' => [],
];
}
@@ -852,9 +770,9 @@ public function testRemove()
{
$manager = $this->createImportMapManager();
$this->mockImportMap([
- new ImportMapEntry('lodash', url: 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
- new ImportMapEntry('cowsay', path: 'vendor/moo.js', url: 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.umd.js', isDownloaded: true),
- new ImportMapEntry('chance', path: 'vendor/chance.js', url: 'https://ga.jspm.io/npm:chance@7.8.9/build/chance.js', isDownloaded: true),
+ new ImportMapEntry('lodash', version: '1.2.3'),
+ new ImportMapEntry('cowsay', version: '4.5.6'),
+ new ImportMapEntry('chance', version: '7.8.9'),
new ImportMapEntry('app', path: 'app.js'),
new ImportMapEntry('other', path: 'other.js'),
]);
@@ -864,12 +782,6 @@ public function testRemove()
new MappedAsset('app.js', self::$writableRoot.'/assets/app.js'),
]);
- $this->filesystem->mkdir(self::$writableRoot.'/assets/vendor');
- touch(self::$writableRoot.'/assets/vendor/moo.js');
- touch(self::$writableRoot.'/assets/vendor/chance.js');
- touch(self::$writableRoot.'/assets/app.js');
- touch(self::$writableRoot.'/assets/other.js');
-
$this->configReader->expects($this->once())
->method('writeEntries')
->with($this->callback(function (ImportMapEntries $entries) {
@@ -883,107 +795,73 @@ public function testRemove()
;
$manager->remove(['cowsay', 'app']);
- $this->assertFileDoesNotExist(self::$writableRoot.'/assets/vendor/moo.js');
- $this->assertFileDoesNotExist(self::$writableRoot.'/assets/app.js');
- $this->assertFileExists(self::$writableRoot.'/assets/vendor/chance.js');
- $this->assertFileExists(self::$writableRoot.'/assets/other.js');
}
public function testUpdateAll()
{
$manager = $this->createImportMapManager();
$this->mockImportMap([
- new ImportMapEntry('lodash', url: 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
- new ImportMapEntry('cowsay', path: 'vendor/moo.js', url: 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.umd.js', isDownloaded: true),
- new ImportMapEntry('bootstrap', url: 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.esm.js'),
+ new ImportMapEntry('lodash', version: '1.2.3'),
+ new ImportMapEntry('bootstrap', version: '5.1.3'),
new ImportMapEntry('app', path: 'app.js'),
]);
- $this->mockAssetMapper([
- new MappedAsset('vendor/moo.js', self::$writableRoot.'/assets/vendor/moo.js'),
- ], false);
- $this->assetMapper->expects($this->any())
- ->method('getAssetFromSourcePath')
- ->willReturnCallback(function (string $sourcePath) {
- if (str_ends_with($sourcePath, 'assets/vendor/cowsay.js')) {
- return new MappedAsset('vendor/cowsay.js');
- }
-
- return null;
- })
- ;
-
- $this->filesystem->mkdir(self::$writableRoot.'/assets/vendor');
- file_put_contents(self::$writableRoot.'/assets/vendor/moo.js', 'moo.js contents');
- file_put_contents(self::$writableRoot.'/assets/app.js', 'app.js contents');
-
$this->packageResolver->expects($this->once())
->method('resolvePackages')
->with($this->callback(function ($packages) {
$this->assertInstanceOf(PackageRequireOptions::class, $packages[0]);
/* @var PackageRequireOptions[] $packages */
- $this->assertCount(3, $packages);
+ $this->assertCount(2, $packages);
$this->assertSame('lodash', $packages[0]->packageName);
- $this->assertFalse($packages[0]->download);
-
- $this->assertSame('cowsay', $packages[1]->packageName);
- $this->assertTrue($packages[1]->download);
-
- $this->assertSame('bootstrap', $packages[2]->packageName);
+ $this->assertSame('bootstrap', $packages[1]->packageName);
return true;
}))
->willReturn([
- self::resolvedPackage('lodash', 'https://ga.jspm.io/npm:lodash@1.2.9/lodash.js'),
- self::resolvedPackage('cowsay', 'https://ga.jspm.io/npm:cowsay@4.5.9/cowsay.umd.js', download: true, content: 'contents of cowsay.js'),
- self::resolvedPackage('bootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.esm.js'),
+ self::resolvedPackage('lodash', '1.2.9'),
+ self::resolvedPackage('bootstrap', '5.2.3'),
])
;
$this->configReader->expects($this->once())
->method('writeEntries')
->with($this->callback(function (ImportMapEntries $entries) {
- $this->assertCount(4, $entries);
+ $this->assertCount(3, $entries);
$this->assertTrue($entries->has('lodash'));
- $this->assertTrue($entries->has('cowsay'));
$this->assertTrue($entries->has('bootstrap'));
$this->assertTrue($entries->has('app'));
- $this->assertSame('https://ga.jspm.io/npm:lodash@1.2.9/lodash.js', $entries->get('lodash')->url);
- $this->assertSame('https://ga.jspm.io/npm:cowsay@4.5.9/cowsay.umd.js', $entries->get('cowsay')->url);
- $this->assertSame('https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.esm.js', $entries->get('bootstrap')->url);
+ $this->assertSame('1.2.9', $entries->get('lodash')->version);
+ $this->assertSame('5.2.3', $entries->get('bootstrap')->version);
return true;
}))
;
$manager->update();
- $this->assertFileDoesNotExist(self::$writableRoot.'/assets/vendor/moo.js');
- $this->assertFileExists(self::$writableRoot.'/assets/vendor/cowsay.js');
- $actualContents = file_get_contents(self::$writableRoot.'/assets/vendor/cowsay.js');
- $this->assertSame('contents of cowsay.js', $actualContents);
}
public function testUpdateWithSpecificPackages()
{
$manager = $this->createImportMapManager();
$this->mockImportMap([
- new ImportMapEntry('lodash', url: 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js'),
- new ImportMapEntry('cowsay', path: 'vendor/cowsay.js', url: 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.umd.js', isDownloaded: true),
- new ImportMapEntry('bootstrap', url: 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.esm.js'),
+ new ImportMapEntry('lodash', version: '1.2.3'),
+ new ImportMapEntry('cowsay', version: '4.5.6'),
+ new ImportMapEntry('bootstrap', version: '5.1.3'),
new ImportMapEntry('app', path: 'app.js'),
]);
- $this->writeFile('assets/vendor/cowsay.js', 'cowsay.js original contents');
-
$this->packageResolver->expects($this->once())
->method('resolvePackages')
->willReturn([
- self::resolvedPackage('cowsay', 'https://ga.jspm.io/npm:cowsay@4.5.9/cowsay.umd.js', download: true, content: 'updated contents of cowsay.js'),
+ self::resolvedPackage('cowsay', '4.5.9'),
])
;
+ $this->remotePackageDownloader->expects($this->once())
+ ->method('downloadPackages');
+
$this->configReader->expects($this->any())
->method('getRootDirectory')
->willReturn(self::$writableRoot);
@@ -992,61 +870,14 @@ public function testUpdateWithSpecificPackages()
->with($this->callback(function (ImportMapEntries $entries) {
$this->assertCount(4, $entries);
- $this->assertSame('https://ga.jspm.io/npm:lodash@1.2.3/lodash.js', $entries->get('lodash')->url);
- $this->assertSame('https://ga.jspm.io/npm:cowsay@4.5.9/cowsay.umd.js', $entries->get('cowsay')->url);
+ $this->assertSame('1.2.3', $entries->get('lodash')->version);
+ $this->assertSame('4.5.9', $entries->get('cowsay')->version);
return true;
}))
;
- $this->mockAssetMapper([
- new MappedAsset('vendor/cowsay.js', self::$writableRoot.'/assets/vendor/cowsay.js'),
- ]);
-
$manager->update(['cowsay']);
- $actualContents = file_get_contents(self::$writableRoot.'/assets/vendor/cowsay.js');
- $this->assertSame('updated contents of cowsay.js', $actualContents);
- }
-
- public function testDownloadMissingPackages()
- {
- $manager = $this->createImportMapManager();
- $this->mockImportMap([
- new ImportMapEntry('@hotwired/stimulus', path: 'vendor/@hotwired/stimulus.js', url: 'https://cdn.jsdelivr.net/npm/stimulus@3.2.1/+esm', isDownloaded: true),
- new ImportMapEntry('lodash', path: 'vendor/lodash.js', url: 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js', isDownloaded: true),
- ]);
-
- $this->mockAssetMapper([
- // fake that vendor/lodash.js exists, but not stimulus
- new MappedAsset('vendor/lodash.js'),
- ], false);
- $this->assetMapper->expects($this->any())
- ->method('getAssetFromSourcePath')
- ->willReturnCallback(function (string $sourcePath) {
- if (str_ends_with($sourcePath, 'assets/vendor/@hotwired/stimulus.js')) {
- return new MappedAsset('vendor/@hotwired/stimulus.js');
- }
- })
- ;
-
- $response = $this->createMock(ResponseInterface::class);
- $response->expects($this->once())
- ->method('getContent')
- ->willReturn('contents of stimulus.js');
-
- $this->httpClient->expects($this->once())
- ->method('request')
- ->willReturn($response);
-
- $downloadedPackages = $manager->downloadMissingPackages();
- $this->assertCount(1, $downloadedPackages);
-
- $expectedDownloadedFiles = [
- '' => 'contents of stimulus.js',
- ];
- $downloadPath = self::$writableRoot.'/assets/vendor/@hotwired/stimulus.js';
- $this->assertFileExists($downloadPath);
- $this->assertSame('contents of stimulus.js', file_get_contents($downloadPath));
}
/**
@@ -1074,7 +905,6 @@ public static function getPackageNameTests(): iterable
'lodash',
[
'package' => 'lodash',
- 'registry' => '',
],
];
@@ -1082,24 +912,6 @@ public static function getPackageNameTests(): iterable
'lodash@^1.2.3',
[
'package' => 'lodash',
- 'registry' => '',
- 'version' => '^1.2.3',
- ],
- ];
-
- yield 'with_registry' => [
- 'npm:lodash',
- [
- 'package' => 'lodash',
- 'registry' => 'npm',
- ],
- ];
-
- yield 'with_registry_and_version' => [
- 'npm:lodash@^1.2.3',
- [
- 'package' => 'lodash',
- 'registry' => 'npm',
'version' => '^1.2.3',
],
];
@@ -1108,7 +920,6 @@ public static function getPackageNameTests(): iterable
'@hotwired/stimulus',
[
'package' => '@hotwired/stimulus',
- 'registry' => '',
],
];
@@ -1116,24 +927,6 @@ public static function getPackageNameTests(): iterable
'@hotwired/stimulus@^1.2.3',
[
'package' => '@hotwired/stimulus',
- 'registry' => '',
- 'version' => '^1.2.3',
- ],
- ];
-
- yield 'namespaced_package_with_registry_no_version' => [
- 'npm:@hotwired/stimulus',
- [
- 'package' => '@hotwired/stimulus',
- 'registry' => 'npm',
- ],
- ];
-
- yield 'namespaced_package_with_registry_and_version' => [
- 'npm:@hotwired/stimulus@^1.2.3',
- [
- 'package' => '@hotwired/stimulus',
- 'registry' => 'npm',
'version' => '^1.2.3',
],
];
@@ -1145,24 +938,23 @@ private function createImportMapManager(): ImportMapManager
$this->assetMapper = $this->createMock(AssetMapperInterface::class);
$this->configReader = $this->createMock(ImportMapConfigReader::class);
$this->packageResolver = $this->createMock(PackageResolverInterface::class);
- $this->httpClient = $this->createMock(HttpClientInterface::class);
+ $this->remotePackageDownloader = $this->createMock(RemotePackageDownloader::class);
return $this->importMapManager = new ImportMapManager(
$this->assetMapper,
$this->pathResolver,
$this->configReader,
- self::$writableRoot.'/assets/vendor',
+ $this->remotePackageDownloader,
$this->packageResolver,
- $this->httpClient,
);
}
- private static function resolvedPackage(string $packageName, string $url, bool $download = false, string $importName = null, string $content = null)
+ private static function resolvedPackage(string $packageName, string $version, ImportMapType $type = ImportMapType::JS)
{
return new ResolvedImportMapPackage(
- new PackageRequireOptions($packageName, download: $download, importName: $importName),
- $url,
- $content,
+ new PackageRequireOptions($packageName),
+ $version,
+ $type,
);
}
@@ -1231,6 +1023,25 @@ private function mockAssetMapper(array $mappedAssets, bool $mockGetAssetFromSour
;
}
+ /**
+ * @param ImportMapEntry[] $importMapEntries
+ */
+ private function mockDownloader(array $importMapEntries): void
+ {
+ $this->remotePackageDownloader->expects($this->any())
+ ->method('getDownloadedPath')
+ ->willReturnCallback(function (string $packageName) use ($importMapEntries) {
+ foreach ($importMapEntries as $entry) {
+ if ($entry->importName === $packageName) {
+ return self::$writableRoot.'/assets/vendor/'.$packageName.'.js';
+ }
+ }
+
+ return null;
+ })
+ ;
+ }
+
private function writeFile(string $filename, string $content): void
{
$path = \dirname(self::$writableRoot.'/'.$filename);
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/RemotePackageDownloaderTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/RemotePackageDownloaderTest.php
new file mode 100644
index 0000000000000..2aaee06c01793
--- /dev/null
+++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/RemotePackageDownloaderTest.php
@@ -0,0 +1,177 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\AssetMapper\Tests\ImportMap;
+
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapEntries;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapType;
+use Symfony\Component\AssetMapper\ImportMap\RemotePackageDownloader;
+use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface;
+use Symfony\Component\Filesystem\Filesystem;
+
+class RemotePackageDownloaderTest extends TestCase
+{
+ private Filesystem $filesystem;
+ private static string $writableRoot = __DIR__.'/../fixtures/importmaps_for_writing';
+
+ protected function setUp(): void
+ {
+ $this->filesystem = new Filesystem();
+ if (!file_exists(self::$writableRoot)) {
+ $this->filesystem->mkdir(self::$writableRoot);
+ }
+ }
+
+ protected function tearDown(): void
+ {
+ $this->filesystem->remove(self::$writableRoot);
+ }
+
+ public function testDownloadPackagesDownloadsEverythingWithNoInstalled()
+ {
+ $configReader = $this->createMock(ImportMapConfigReader::class);
+ $packageResolver = $this->createMock(PackageResolverInterface::class);
+
+ $entry1 = new ImportMapEntry('foo', version: '1.0.0');
+ $entry2 = new ImportMapEntry('bar.js/file', version: '1.0.0');
+ $entry3 = new ImportMapEntry('baz', version: '1.0.0', type: ImportMapType::CSS);
+ $importMapEntries = new ImportMapEntries([$entry1, $entry2, $entry3]);
+
+ $configReader->expects($this->once())
+ ->method('getEntries')
+ ->willReturn($importMapEntries);
+
+ $progressCallback = fn () => null;
+ $packageResolver->expects($this->once())
+ ->method('downloadPackages')
+ ->with(
+ ['foo' => $entry1, 'bar.js/file' => $entry2, 'baz' => $entry3],
+ $progressCallback
+ )
+ ->willReturn(['foo' => 'foo content', 'bar.js/file' => 'bar content', 'baz' => 'baz content']);
+
+ $downloader = new RemotePackageDownloader(
+ $configReader,
+ $packageResolver,
+ self::$writableRoot.'/assets/vendor',
+ );
+ $downloader->downloadPackages($progressCallback);
+
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/foo.js');
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/bar.js/file.js');
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/baz.css');
+ $this->assertEquals('foo content', file_get_contents(self::$writableRoot.'/assets/vendor/foo.js'));
+ $this->assertEquals('bar content', file_get_contents(self::$writableRoot.'/assets/vendor/bar.js/file.js'));
+ $this->assertEquals('baz content', file_get_contents(self::$writableRoot.'/assets/vendor/baz.css'));
+
+ $installed = require self::$writableRoot.'/assets/vendor/installed.php';
+ $this->assertEquals(
+ [
+ 'foo' => ['path' => 'foo.js', 'version' => '1.0.0'],
+ 'bar.js/file' => ['path' => 'bar.js/file.js', 'version' => '1.0.0'],
+ 'baz' => ['path' => 'baz.css', 'version' => '1.0.0'],
+ ],
+ $installed
+ );
+ }
+
+ public function testPackagesWithCorrectInstalledVersionSkipped()
+ {
+ $this->filesystem->mkdir(self::$writableRoot.'/assets/vendor');
+ $installed = [
+ 'foo' => ['path' => 'foo.js', 'version' => '1.0.0'],
+ 'bar.js/file' => ['path' => 'bar.js/file.js', 'version' => '1.0.0'],
+ 'baz' => ['path' => 'baz.css', 'version' => '1.0.0'],
+ ];
+ file_put_contents(
+ self::$writableRoot.'/assets/vendor/installed.php',
+ 'createMock(ImportMapConfigReader::class);
+ $packageResolver = $this->createMock(PackageResolverInterface::class);
+
+ // matches installed version and file exists
+ $entry1 = new ImportMapEntry('foo', version: '1.0.0');
+ file_put_contents(self::$writableRoot.'/assets/vendor/foo.js', 'original foo content');
+ // matches installed version but file does not exist
+ $entry2 = new ImportMapEntry('bar.js/file', version: '1.0.0');
+ // does not match installed version
+ $entry3 = new ImportMapEntry('baz', version: '1.1.0', type: ImportMapType::CSS);
+ file_put_contents(self::$writableRoot.'/assets/vendor/baz.css', 'original baz content');
+ $importMapEntries = new ImportMapEntries([$entry1, $entry2, $entry3]);
+
+ $configReader->expects($this->once())
+ ->method('getEntries')
+ ->willReturn($importMapEntries);
+
+ $packageResolver->expects($this->once())
+ ->method('downloadPackages')
+ ->willReturn(['bar.js/file' => 'new bar content', 'baz' => 'new baz content']);
+
+ $downloader = new RemotePackageDownloader(
+ $configReader,
+ $packageResolver,
+ self::$writableRoot.'/assets/vendor',
+ );
+ $downloader->downloadPackages();
+
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/foo.js');
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/bar.js/file.js');
+ $this->assertFileExists(self::$writableRoot.'/assets/vendor/baz.css');
+ $this->assertEquals('original foo content', file_get_contents(self::$writableRoot.'/assets/vendor/foo.js'));
+ $this->assertEquals('new bar content', file_get_contents(self::$writableRoot.'/assets/vendor/bar.js/file.js'));
+ $this->assertEquals('new baz content', file_get_contents(self::$writableRoot.'/assets/vendor/baz.css'));
+
+ $installed = require self::$writableRoot.'/assets/vendor/installed.php';
+ $this->assertEquals(
+ [
+ 'foo' => ['path' => 'foo.js', 'version' => '1.0.0'],
+ 'bar.js/file' => ['path' => 'bar.js/file.js', 'version' => '1.0.0'],
+ 'baz' => ['path' => 'baz.css', 'version' => '1.1.0'],
+ ],
+ $installed
+ );
+ }
+
+ public function testGetDownloadedPath()
+ {
+ $this->filesystem->mkdir(self::$writableRoot.'/assets/vendor');
+ $installed = [
+ 'foo' => ['path' => 'foo-path.js', 'version' => '1.0.0'],
+ ];
+ file_put_contents(
+ self::$writableRoot.'/assets/vendor/installed.php',
+ 'createMock(ImportMapConfigReader::class),
+ $this->createMock(PackageResolverInterface::class),
+ self::$writableRoot.'/assets/vendor',
+ );
+ $this->assertSame(realpath(self::$writableRoot.'/assets/vendor/foo-path.js'), realpath($downloader->getDownloadedPath('foo')));
+ }
+
+ public function testGetVendorDir()
+ {
+ $downloader = new RemotePackageDownloader(
+ $this->createMock(ImportMapConfigReader::class),
+ $this->createMock(PackageResolverInterface::class),
+ self::$writableRoot.'/assets/vendor',
+ );
+ $this->assertSame(realpath(self::$writableRoot.'/assets/vendor'), realpath($downloader->getVendorDir()));
+ }
+}
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php
index 220107953c0b3..2c667787e4e7b 100644
--- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php
+++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php
@@ -12,6 +12,8 @@
namespace Symfony\Component\AssetMapper\Tests\ImportMap\Resolver;
use PHPUnit\Framework\TestCase;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
+use Symfony\Component\AssetMapper\ImportMap\ImportMapType;
use Symfony\Component\AssetMapper\ImportMap\PackageRequireOptions;
use Symfony\Component\AssetMapper\ImportMap\Resolver\JsDelivrEsmResolver;
use Symfony\Component\HttpClient\MockHttpClient;
@@ -35,9 +37,7 @@ public function testResolvePackages(array $packages, array $expectedRequests, ar
$body = \is_array($expectedRequest['response']['body']) ? json_encode($expectedRequest['response']['body']) : $expectedRequest['response']['body'];
}
- return new MockResponse($body, [
- 'url' => $expectedRequest['response']['url'] ?? '/anything',
- ]);
+ return new MockResponse($body);
};
}
@@ -49,11 +49,10 @@ public function testResolvePackages(array $packages, array $expectedRequests, ar
foreach ($actualResolvedPackages as $package) {
$packageName = $package->requireOptions->packageName;
$this->assertArrayHasKey($packageName, $expectedResolvedPackages);
- $this->assertSame($expectedResolvedPackages[$packageName]['url'], $package->url);
- if (isset($expectedResolvedPackages[$packageName]['content'])) {
- $this->assertSame($expectedResolvedPackages[$packageName]['content'], $package->content);
- }
+ $this->assertSame($expectedResolvedPackages[$packageName]['version'], $package->version);
}
+
+ $this->assertSame(\count($expectedRequests), $httpClient->getRequestsCount());
}
public static function provideResolvePackagesTests(): iterable
@@ -67,7 +66,6 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/lodash@1.2.3/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm'],
],
[
'url' => '/v1/packages/npm/lodash@1.2.3/entrypoints',
@@ -76,7 +74,7 @@ public static function provideResolvePackagesTests(): iterable
],
'expectedResolvedPackages' => [
'lodash' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
+ 'version' => '1.2.3',
],
],
];
@@ -90,7 +88,6 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/lodash@2.1.3/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/lodash.js@2.1.3/+esm'],
],
[
'url' => '/v1/packages/npm/lodash@2.1.3/entrypoints',
@@ -99,7 +96,7 @@ public static function provideResolvePackagesTests(): iterable
],
'expectedResolvedPackages' => [
'lodash' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@2.1.3/+esm',
+ 'version' => '2.1.3',
],
],
];
@@ -113,7 +110,6 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/@hotwired/stimulus@3.1.3/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/@hotwired/stimulus.js@3.1.3/+esm'],
],
[
'url' => '/v1/packages/npm/@hotwired/stimulus@3.1.3/entrypoints',
@@ -122,7 +118,7 @@ public static function provideResolvePackagesTests(): iterable
],
'expectedResolvedPackages' => [
'@hotwired/stimulus' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@hotwired/stimulus.js@3.1.3/+esm',
+ 'version' => '3.1.3',
],
],
];
@@ -136,16 +132,11 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/chart.js@3.0.1/auto/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/chart.js@3.0.1/auto/+esm'],
- ],
- [
- 'url' => '/v1/packages/npm/chart.js@3.0.1/entrypoints',
- 'response' => ['body' => ['entrypoints' => []]],
],
],
'expectedResolvedPackages' => [
'chart.js/auto' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/chart.js@3.0.1/auto/+esm',
+ 'version' => '3.0.1',
],
],
];
@@ -159,113 +150,44 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/@chart/chart.js@3.0.1/auto/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/@chart/chart.js@3.0.1/auto/+esm'],
- ],
- [
- 'url' => '/v1/packages/npm/@chart/chart.js@3.0.1/entrypoints',
- 'response' => ['body' => ['entrypoints' => []]],
],
],
'expectedResolvedPackages' => [
'@chart/chart.js/auto' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@chart/chart.js@3.0.1/auto/+esm',
- ],
- ],
- ];
-
- yield 'require package with simple download' => [
- 'packages' => [new PackageRequireOptions('lodash', download: true)],
- 'expectedRequests' => [
- [
- 'url' => '/v1/packages/npm/lodash/resolved?specifier=%2A',
- 'response' => ['body' => ['version' => '1.2.3']],
- ],
- [
- 'url' => '/lodash@1.2.3/+esm',
- 'response' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
- 'body' => 'contents of file',
- ],
- ],
- [
- 'url' => '/v1/packages/npm/lodash@1.2.3/entrypoints',
- 'response' => ['body' => ['entrypoints' => []]],
- ],
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
- 'content' => 'contents of file',
+ 'version' => '3.0.1',
],
],
];
- yield 'require package download with import dependencies' => [
- 'packages' => [new PackageRequireOptions('lodash', download: true)],
+ yield 'require package that imports another' => [
+ 'packages' => [new PackageRequireOptions('@chart/chart.js/auto', '^3')],
'expectedRequests' => [
- // lodash
[
- 'url' => '/v1/packages/npm/lodash/resolved?specifier=%2A',
- 'response' => ['body' => ['version' => '1.2.3']],
- ],
- [
- 'url' => '/lodash@1.2.3/+esm',
- 'response' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
- 'body' => 'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";console.log("yo");',
- ],
+ 'url' => '/v1/packages/npm/@chart/chart.js/resolved?specifier=%5E3',
+ 'response' => ['body' => ['version' => '3.0.1']],
],
[
- 'url' => '/v1/packages/npm/lodash@1.2.3/entrypoints',
- 'response' => ['body' => ['entrypoints' => []]],
+ 'url' => '/@chart/chart.js@3.0.1/auto/+esm',
+ 'response' => ['body' => 'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";function e(){}const i=(()='],
],
- // @kurkle/color
[
'url' => '/v1/packages/npm/@kurkle/color/resolved?specifier=0.3.2',
'response' => ['body' => ['version' => '0.3.2']],
],
[
'url' => '/@kurkle/color@0.3.2/+esm',
- 'response' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@kurkle/color@0.3.2/+esm',
- 'body' => 'import*as t from"/npm/@popperjs/core@2.11.7/+esm";// hello world',
- ],
],
[
'url' => '/v1/packages/npm/@kurkle/color@0.3.2/entrypoints',
'response' => ['body' => ['entrypoints' => []]],
],
- // @popperjs/core
- [
- 'url' => '/v1/packages/npm/@popperjs/core/resolved?specifier=2.11.7',
- 'response' => ['body' => ['version' => '2.11.7']],
- ],
- [
- 'url' => '/@popperjs/core@2.11.7/+esm',
- 'response' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/+esm',
- // point back to the original to try to confuse things or cause extra work
- 'body' => 'import*as t from"/npm/lodash@1.2.9/+esm";// hello from popper',
- ],
- ],
- [
- 'url' => '/v1/packages/npm/@popperjs/core@2.11.7/entrypoints',
- 'response' => ['body' => ['entrypoints' => []]],
- ],
],
'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
- // file was updated correctly
- 'content' => 'import{Color as t}from"@kurkle/color";console.log("yo");',
+ '@chart/chart.js/auto' => [
+ 'version' => '3.0.1',
],
'@kurkle/color' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@kurkle/color@0.3.2/+esm',
- 'content' => 'import*as t from"@popperjs/core";// hello world',
- ],
- '@popperjs/core' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/+esm',
- 'content' => 'import*as t from"lodash";// hello from popper',
+ 'version' => '0.3.2',
],
],
];
@@ -280,12 +202,11 @@ public static function provideResolvePackagesTests(): iterable
[
// CSS is detected: +esm is left off
'url' => '/bootstrap@3.3.0/dist/css/bootstrap.min.css',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@3.3.0/dist/css/bootstrap.min.css'],
],
],
'expectedResolvedPackages' => [
'bootstrap/dist/css/bootstrap.min.css' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@3.3.0/dist/css/bootstrap.min.css',
+ 'version' => '3.3.0',
],
],
];
@@ -299,7 +220,6 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/bootstrap@5.2.0/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/+esm'],
],
[
'url' => '/v1/packages/npm/bootstrap@5.2.0/entrypoints',
@@ -314,15 +234,14 @@ public static function provideResolvePackagesTests(): iterable
[
// grab the found CSS
'url' => '/bootstrap@5.2.0/dist/css/bootstrap.min.css',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/css/bootstrap.min.css'],
],
],
'expectedResolvedPackages' => [
'bootstrap' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/+esm',
+ 'version' => '5.2.0',
],
'bootstrap/dist/css/bootstrap.min.css' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/css/bootstrap.min.css',
+ 'version' => '5.2.0',
],
],
];
@@ -336,17 +255,155 @@ public static function provideResolvePackagesTests(): iterable
],
[
'url' => '/bootstrap@5.2.0/dist/modal.js/+esm',
- 'response' => ['url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/modal.js+esm'],
],
],
'expectedResolvedPackages' => [
'bootstrap/dist/modal.js' => [
- 'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/modal.js+esm',
+ 'version' => '5.2.0',
],
],
];
}
+ /**
+ * @dataProvider provideDownloadPackagesTests
+ */
+ public function testDownloadPackages(array $importMapEntries, array $expectedRequests, array $expectedContents)
+ {
+ $responses = [];
+ foreach ($expectedRequests as $expectedRequest) {
+ $responses[] = function ($method, $url) use ($expectedRequest) {
+ $this->assertSame('GET', $method);
+ $this->assertStringEndsWith($expectedRequest['url'], $url);
+
+ return new MockResponse($expectedRequest['body']);
+ };
+ }
+
+ $httpClient = new MockHttpClient($responses);
+
+ $provider = new JsDelivrEsmResolver($httpClient);
+ $actualContents = $provider->downloadPackages($importMapEntries);
+ $this->assertCount(\count($expectedContents), $actualContents);
+ $actualContents = array_map('trim', $actualContents);
+ $this->assertSame($expectedContents, $actualContents);
+ $this->assertSame(\count($expectedRequests), $httpClient->getRequestsCount());
+ }
+
+ public static function provideDownloadPackagesTests()
+ {
+ yield 'single package' => [
+ ['lodash' => new ImportMapEntry('lodash', version: '1.2.3')],
+ [
+ [
+ 'url' => '/lodash@1.2.3/+esm',
+ 'body' => 'lodash contents',
+ ],
+ ],
+ [
+ 'lodash' => 'lodash contents',
+ ],
+ ];
+
+ yield 'package with path' => [
+ ['lodash' => new ImportMapEntry('chart.js/auto', version: '4.5.6')],
+ [
+ [
+ 'url' => '/chart.js@4.5.6/auto/+esm',
+ 'body' => 'chart.js contents',
+ ],
+ ],
+ [
+ 'lodash' => 'chart.js contents',
+ ],
+ ];
+
+ yield 'css file' => [
+ ['lodash' => new ImportMapEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS)],
+ [
+ [
+ 'url' => '/bootstrap@5.0.6/dist/bootstrap.css',
+ 'body' => 'bootstrap.css contents',
+ ],
+ ],
+ [
+ 'lodash' => 'bootstrap.css contents',
+ ],
+ ];
+
+ yield 'multiple files' => [
+ [
+ 'lodash' => new ImportMapEntry('lodash', version: '1.2.3'),
+ 'chart.js/auto' => new ImportMapEntry('chart.js/auto', version: '4.5.6'),
+ 'bootstrap/dist/bootstrap.css' => new ImportMapEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS),
+ ],
+ [
+ [
+ 'url' => '/lodash@1.2.3/+esm',
+ 'body' => 'lodash contents',
+ ],
+ [
+ 'url' => '/chart.js@4.5.6/auto/+esm',
+ 'body' => 'chart.js contents',
+ ],
+ [
+ 'url' => '/bootstrap@5.0.6/dist/bootstrap.css',
+ 'body' => 'bootstrap.css contents',
+ ],
+ ],
+ [
+ 'lodash' => 'lodash contents',
+ 'chart.js/auto' => 'chart.js contents',
+ 'bootstrap/dist/bootstrap.css' => 'bootstrap.css contents',
+ ],
+ ];
+
+ yield 'make imports relative' => [
+ [
+ '@chart.js/auto' => new ImportMapEntry('chart.js/auto', version: '1.2.3'),
+ ],
+ [
+ [
+ 'url' => '/chart.js@1.2.3/auto/+esm',
+ 'body' => 'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";function e(){}const i=(()=',
+ ],
+ ],
+ [
+ '@chart.js/auto' => 'import{Color as t}from"@kurkle/color";function e(){}const i=(()=',
+ ],
+ ];
+
+ yield 'js importmap is removed' => [
+ [
+ '@chart.js/auto' => new ImportMapEntry('chart.js/auto', version: '1.2.3'),
+ ],
+ [
+ [
+ 'url' => '/chart.js@1.2.3/auto/+esm',
+ 'body' => 'as Ticks,ta as TimeScale,ia as TimeSeriesScale,oo as Title,wo as Tooltip,Ci as _adapters,us as _detectPlatform,Ye as animator,Si as controllers,tn as default,St as defaults,Pn as elements,qi as layouts,ko as plugins,na as registerables,Ps as registry,sa as scales};
+ //# sourceMappingURL=/sm/bc823a081dbde2b3a5424732858022f831d3f2978d59498cd938e0c2c8cf9ec0.map',
+ ],
+ ],
+ [
+ '@chart.js/auto' => 'as Ticks,ta as TimeScale,ia as TimeSeriesScale,oo as Title,wo as Tooltip,Ci as _adapters,us as _detectPlatform,Ye as animator,Si as controllers,tn as default,St as defaults,Pn as elements,qi as layouts,ko as plugins,na as registerables,Ps as registry,sa as scales};',
+ ],
+ ];
+
+ yield 'css file removes importmap' => [
+ ['lodash' => new ImportMapEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS)],
+ [
+ [
+ 'url' => '/bootstrap@5.0.6/dist/bootstrap.css',
+ 'body' => 'print-table-row{display:table-row!important}.d-print-table-cell{display:table-cell!important}.d-print-flex{display:flex!important}.d-print-inline-flex{display:inline-flex!important}.d-print-none{display:none!important}}
+ /*# sourceMappingURL=bootstrap.min.css.map */',
+ ],
+ ],
+ [
+ 'lodash' => 'print-table-row{display:table-row!important}.d-print-table-cell{display:table-cell!important}.d-print-flex{display:flex!important}.d-print-inline-flex{display:inline-flex!important}.d-print-none{display:none!important}}',
+ ],
+ ];
+ }
+
/**
* @dataProvider provideImportRegex
*/
@@ -392,21 +449,4 @@ public static function provideImportRegex(): iterable
],
];
}
-
- /**
- * @dataProvider provideGetPackageVersion
- */
- public function testGetPackageVersion(string $url, ?string $expected)
- {
- $resolver = new JsDelivrEsmResolver();
-
- $this->assertSame($expected, $resolver->getPackageVersion($url));
- }
-
- public static function provideGetPackageVersion(): iterable
- {
- yield 'with no result' => ['https://cdn.jsdelivr.net/npm/lodash.js/+esm', null];
- yield 'with a package name' => ['https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm', '1.2.3'];
- yield 'with a dash in the package_name' => ['https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/+esm', '2.11.7'];
- }
}
diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JspmResolverTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JspmResolverTest.php
deleted file mode 100644
index aa90991141454..0000000000000
--- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JspmResolverTest.php
+++ /dev/null
@@ -1,178 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\AssetMapper\Tests\ImportMap\Resolver;
-
-use PHPUnit\Framework\TestCase;
-use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
-use Symfony\Component\AssetMapper\ImportMap\PackageRequireOptions;
-use Symfony\Component\AssetMapper\ImportMap\Resolver\JspmResolver;
-use Symfony\Component\HttpClient\MockHttpClient;
-use Symfony\Component\HttpClient\Response\MockResponse;
-
-class JspmResolverTest extends TestCase
-{
- /**
- * @dataProvider provideResolvePackagesTests
- */
- public function testResolvePackages(array $packages, array $expectedInstallRequest, array $responseMap, array $expectedResolvedPackages, array $expectedDownloadedFiles)
- {
- $expectedRequestBody = [
- 'install' => $expectedInstallRequest,
- 'flattenScope' => true,
- 'env' => ['browser', 'module', 'production'],
- ];
- $responseData = [
- 'map' => [
- 'imports' => $responseMap,
- ],
- ];
-
- $responses = [];
- $responses[] = function ($method, $url, $options) use ($responseData, $expectedRequestBody) {
- $this->assertSame('POST', $method);
- $this->assertSame('https://api.jspm.io/generate', $url);
- $this->assertSame($expectedRequestBody, json_decode($options['body'], true));
-
- return new MockResponse(json_encode($responseData));
- };
- // mock the "file download" requests
- foreach ($expectedDownloadedFiles as $file) {
- $responses[] = new MockResponse(sprintf('contents of %s', $file));
- }
-
- $httpClient = new MockHttpClient($responses);
-
- $provider = new JspmResolver($httpClient, ImportMapManager::PROVIDER_JSPM);
- $actualResolvedPackages = $provider->resolvePackages($packages);
- $this->assertCount(\count($expectedResolvedPackages), $actualResolvedPackages);
- foreach ($actualResolvedPackages as $package) {
- $packageName = $package->requireOptions->packageName;
- $this->assertArrayHasKey($packageName, $expectedResolvedPackages);
- $this->assertSame($expectedResolvedPackages[$packageName]['url'], $package->url);
- }
- }
-
- public static function provideResolvePackagesTests(): iterable
- {
- yield 'require single lodash package' => [
- 'packages' => [new PackageRequireOptions('lodash')],
- 'expectedInstallRequest' => ['lodash'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
-
- yield 'require two packages' => [
- 'packages' => [new PackageRequireOptions('lodash'), new PackageRequireOptions('cowsay')],
- 'expectedInstallRequest' => ['lodash', 'cowsay'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- 'cowsay' => 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- 'cowsay' => [
- 'url' => 'https://ga.jspm.io/npm:cowsay@4.5.6/cowsay.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
-
- yield 'single_package_that_returns_as_two' => [
- 'packages' => [new PackageRequireOptions('lodash')],
- 'expectedInstallRequest' => ['lodash'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- 'lodash-dependency' => 'https://ga.jspm.io/npm:lodash-dependency@9.8.7/lodash-dependency.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- 'lodash-dependency' => [
- 'url' => 'https://ga.jspm.io/npm:lodash-dependency@9.8.7/lodash-dependency.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
-
- yield 'single_package_with_version_constraint' => [
- 'packages' => [new PackageRequireOptions('lodash', '^1.2.3')],
- 'expectedInstallRequest' => ['lodash@^1.2.3'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.7/lodash.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.7/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
-
- yield 'single_package_that_downloads' => [
- 'packages' => [new PackageRequireOptions('lodash', download: true)],
- 'expectedInstallRequest' => ['lodash'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- 'downloaded_to' => 'vendor/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [
- 'assets/vendor/lodash.js',
- ],
- ];
-
- yield 'single_package_with_jspm_custom_registry' => [
- 'packages' => [new PackageRequireOptions('lodash', registryName: 'jspm')],
- 'expectedInstallRequest' => ['jspm:lodash'],
- 'responseMap' => [
- 'lodash' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- 'expectedResolvedPackages' => [
- 'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@1.2.3/lodash.js',
- ],
- ],
- 'expectedDownloadedFiles' => [],
- ];
- }
-
- /**
- * @dataProvider provideGetPackageVersion
- */
- public function testGetPackageVersion(string $url, ?string $expected)
- {
- $resolver = new JspmResolver();
-
- $this->assertSame($expected, $resolver->getPackageVersion($url));
- }
-
- public static function provideGetPackageVersion(): iterable
- {
- yield 'with no result' => ['https://ga.jspm.io/npm:lodash/lodash.js', null];
- yield 'with a package name' => ['https://ga.jspm.io/npm:lodash@1.2.3/lodash.js', '1.2.3'];
- yield 'with a dash in the package_name' => ['https://ga.jspm.io/npm:lodash-dependency@9.8.7/lodash-dependency.js', '9.8.7'];
- }
-}
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php b/src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php
index 31641188b0fa8..03b8212518094 100644
--- a/src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php
@@ -43,7 +43,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'http_client' => true,
'assets' => null,
'asset_mapper' => [
- 'paths' => ['dir1', 'dir2'],
+ 'paths' => ['dir1', 'dir2', 'assets/vendor'],
],
'test' => true,
]);
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/installed.php b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/installed.php
new file mode 100644
index 0000000000000..564dfcb1286d3
--- /dev/null
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/installed.php
@@ -0,0 +1,12 @@
+
+ array (
+ 'version' => '3.2.1',
+ 'path' => 'stimulus.js',
+ ),
+ 'lodash' =>
+ array (
+ 'version' => '4.17.21',
+ 'path' => 'lodash.js',
+ ),
+);
\ No newline at end of file
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/lodash.js b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/lodash.js
new file mode 100644
index 0000000000000..cc0f2d7280f3b
--- /dev/null
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/lodash.js
@@ -0,0 +1 @@
+console.log("lodash.js");
\ No newline at end of file
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/stimulus.js b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/stimulus.js
new file mode 100644
index 0000000000000..75fe110601c1c
--- /dev/null
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/assets/vendor/stimulus.js
@@ -0,0 +1 @@
+console.log("stimulus.js");
\ No newline at end of file
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmap.php b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmap.php
index c563f9b07282d..5c3ce6a1e535b 100644
--- a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmap.php
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmap.php
@@ -11,10 +11,10 @@
return [
'@hotwired/stimulus' => [
- 'url' => 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
+ 'version' => '3.2.1',
],
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
+ 'version' => '4.17.21',
],
'file6' => [
'path' => 'subdir/file6.js',
diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/importmap.php b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/importmap.php
index d63a73a2cad00..49390b47cb396 100644
--- a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/importmap.php
+++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/importmap.php
@@ -11,11 +11,10 @@
return [
'@hotwired/stimulus' => [
- 'url' => 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
+ 'version' => '3.2.1',
],
'lodash' => [
- 'url' => 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
- 'downloaded_to' => 'vendor/lodash.js',
+ 'version' => '4.17.21',
],
'app' => [
'path' => 'app.js',
diff --git a/src/Symfony/Component/AssetMapper/composer.json b/src/Symfony/Component/AssetMapper/composer.json
index 0c0f82bb816bf..33b0a2e89367d 100644
--- a/src/Symfony/Component/AssetMapper/composer.json
+++ b/src/Symfony/Component/AssetMapper/composer.json
@@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.1",
+ "symfony/deprecation-contracts": "^2.5|^3",
"symfony/filesystem": "^5.4|^6.0|^7.0",
"symfony/http-client": "^5.4|^6.0|^7.0"
},
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy