-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[AssetMapper] Add command to download missing downloaded packages #51351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-grekas
merged 1 commit into
symfony:6.4
from
jmsche:asset-mapper-download-missing
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\AssetMapper\Command; | ||
|
||
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
/** | ||
* Downloads all assets that should be downloaded. | ||
* | ||
* @author Jonathan Scheiber <[email protected]> | ||
*/ | ||
#[AsCommand(name: 'importmap:install', description: 'Downloads all assets that should be downloaded.')] | ||
final class ImportMapInstallCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly ImportMapManager $importMapManager, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$downloadedPackages = $this->importMapManager->downloadMissingPackages(); | ||
$io->success(sprintf('Downloaded %d assets.', \count($downloadedPackages))); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,6 +373,43 @@ public function testUpdate() | |
$this->assertSame('contents of cowsay.js', $actualContents); | ||
} | ||
|
||
public function testDownloadMissingPackages() | ||
{ | ||
$rootDir = __DIR__.'/../fixtures/download'; | ||
$manager = $this->createImportMapManager(['assets' => ''], $rootDir); | ||
|
||
$this->packageResolver->expects($this->once()) | ||
->method('resolvePackages') | ||
->willReturn([ | ||
self::resolvedPackage('@hotwired/stimulus', 'https://cdn.jsdelivr.net/npm/[email protected]/+esm', true, content: 'contents of stimulus.js'), | ||
]) | ||
; | ||
|
||
$downloadedPackages = $manager->downloadMissingPackages(); | ||
$actualImportMap = require $rootDir.'/importmap.php'; | ||
$expectedImportMap = [ | ||
'@hotwired/stimulus' => [ | ||
'downloaded_to' => 'vendor/@hotwired/stimulus.js', | ||
'url' => 'https://cdn.jsdelivr.net/npm/[email protected]/+esm', | ||
], | ||
'lodash' => [ | ||
'downloaded_to' => 'vendor/lodash.js', | ||
'url' => 'https://ga.jspm.io/npm:[email protected]/lodash.js', | ||
], | ||
]; | ||
$this->assertEquals($expectedImportMap, $actualImportMap); | ||
|
||
$expectedDownloadedFiles = [ | ||
'assets/vendor/@hotwired/stimulus.js' => 'contents of stimulus.js', | ||
]; | ||
foreach ($expectedDownloadedFiles as $file => $expectedContents) { | ||
$this->assertFileExists($rootDir.'/'.$file); | ||
$actualContents = file_get_contents($rootDir.'/'.$file); | ||
$this->assertSame($expectedContents, $actualContents); | ||
unlink($rootDir.'/'.$file); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider getPackageNameTests | ||
*/ | ||
|
1 change: 1 addition & 0 deletions
1
src/Symfony/Component/AssetMapper/Tests/fixtures/download/assets/vendor/lodash.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('fake downloaded lodash.js'); |
21 changes: 21 additions & 0 deletions
21
src/Symfony/Component/AssetMapper/Tests/fixtures/download/importmap.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return [ | ||
'@hotwired/stimulus' => [ | ||
'downloaded_to' => 'vendor/@hotwired/stimulus.js', | ||
'url' => 'https://cdn.jsdelivr.net/npm/[email protected]/+esm', | ||
], | ||
'lodash' => [ | ||
'downloaded_to' => 'vendor/lodash.js', | ||
'url' => 'https://ga.jspm.io/npm:[email protected]/lodash.js', | ||
], | ||
]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.