Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Component\AssetMapper\Factory\MappedAssetFactory;
use Symfony\Component\AssetMapper\ImportMap\ImportMapAuditor;
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
use Symfony\Component\AssetMapper\ImportMap\ImportMapGenerator;
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
use Symfony\Component\AssetMapper\ImportMap\ImportMapRenderer;
use Symfony\Component\AssetMapper\ImportMap\ImportMapUpdateChecker;
Expand Down Expand Up @@ -101,7 +102,7 @@
->args([
service('asset_mapper.public_assets_path_resolver'),
service('asset_mapper'),
service('asset_mapper.importmap.manager'),
service('asset_mapper.importmap.generator'),
service('filesystem'),
param('kernel.project_dir'),
abstract_arg('public directory name'),
Expand Down Expand Up @@ -137,7 +138,7 @@

->set('asset_mapper.compiler.javascript_import_path_compiler', JavaScriptImportPathCompiler::class)
->args([
service('asset_mapper.importmap.manager'),
service('asset_mapper.importmap.config_reader'),
abstract_arg('missing import mode'),
service('logger'),
])
Expand All @@ -153,13 +154,19 @@
->set('asset_mapper.importmap.manager', ImportMapManager::class)
->args([
service('asset_mapper'),
service('asset_mapper.public_assets_path_resolver'),
service('asset_mapper.importmap.config_reader'),
service('asset_mapper.importmap.remote_package_downloader'),
service('asset_mapper.importmap.resolver'),
])
->alias(ImportMapManager::class, 'asset_mapper.importmap.manager')

->set('asset_mapper.importmap.generator', ImportMapGenerator::class)
->args([
service('asset_mapper'),
service('asset_mapper.public_assets_path_resolver'),
service('asset_mapper.importmap.config_reader'),
])

->set('asset_mapper.importmap.remote_package_storage', RemotePackageStorage::class)
->args([
abstract_arg('vendor directory'),
Expand All @@ -183,7 +190,7 @@

->set('asset_mapper.importmap.renderer', ImportMapRenderer::class)
->args([
service('asset_mapper.importmap.manager'),
service('asset_mapper.importmap.generator'),
service('assets.packages')->nullOnInvalid(),
param('kernel.charset'),
abstract_arg('polyfill URL'),
Expand All @@ -205,7 +212,6 @@
->set('asset_mapper.importmap.command.require', ImportMapRequireCommand::class)
->args([
service('asset_mapper.importmap.manager'),
param('kernel.project_dir'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument wasn't used - unrelated to this PR

service('asset_mapper.importmap.version_checker'),
])
->tag('console.command')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\AssetMapper\AssetMapper;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
use Symfony\Component\AssetMapper\ImportMap\ImportMapGenerator;
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -38,7 +38,7 @@ final class AssetMapperCompileCommand extends Command
public function __construct(
private readonly PublicAssetsPathResolverInterface $publicAssetsPathResolver,
private readonly AssetMapperInterface $assetMapper,
private readonly ImportMapManager $importMapManager,
private readonly ImportMapGenerator $importMapGenerator,
private readonly Filesystem $filesystem,
private readonly string $projectDir,
private readonly string $publicDirName,
Expand Down Expand Up @@ -81,12 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$manifestPath = $outputDir.'/'.AssetMapper::MANIFEST_FILE_NAME;
$files[] = $manifestPath;

$importMapPath = $outputDir.'/'.ImportMapManager::IMPORT_MAP_CACHE_FILENAME;
$importMapPath = $outputDir.'/'.ImportMapGenerator::IMPORT_MAP_CACHE_FILENAME;
$files[] = $importMapPath;

$entrypointFilePaths = [];
foreach ($this->importMapManager->getEntrypointNames() as $entrypointName) {
$dumpedEntrypointPath = $outputDir.'/'.sprintf(ImportMapManager::ENTRYPOINT_CACHE_FILENAME_PATTERN, $entrypointName);
foreach ($this->importMapGenerator->getEntrypointNames() as $entrypointName) {
$dumpedEntrypointPath = $outputDir.'/'.sprintf(ImportMapGenerator::ENTRYPOINT_CACHE_FILENAME_PATTERN, $entrypointName);
$files[] = $dumpedEntrypointPath;
$entrypointFilePaths[$entrypointName] = $dumpedEntrypointPath;
}
Expand All @@ -105,12 +105,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->filesystem->dumpFile($manifestPath, json_encode($manifest, \JSON_PRETTY_PRINT));
$io->comment(sprintf('Manifest written to <info>%s</info>', $this->shortenPath($manifestPath)));

$this->filesystem->dumpFile($importMapPath, json_encode($this->importMapManager->getRawImportMapData(), \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG));
$this->filesystem->dumpFile($importMapPath, json_encode($this->importMapGenerator->getRawImportMapData(), \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG));
$io->comment(sprintf('Import map data written to <info>%s</info>.', $this->shortenPath($importMapPath)));

$entrypointNames = $this->importMapManager->getEntrypointNames();
$entrypointNames = $this->importMapGenerator->getEntrypointNames();
foreach ($entrypointFilePaths as $entrypointName => $path) {
$this->filesystem->dumpFile($path, json_encode($this->importMapManager->getEntrypointMetadata($entrypointName), \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG));
$this->filesystem->dumpFile($path, json_encode($this->importMapGenerator->findEagerEntrypointImports($entrypointName), \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG));
}
$styledEntrypointNames = array_map(fn (string $entrypointName) => sprintf('<info>%s</>', $entrypointName), $entrypointNames);
$io->comment(sprintf('Entrypoint metadata written for <comment>%d</> entrypoints (%s).', \count($entrypointNames), implode(', ', $styledEntrypointNames)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ final class ImportMapRequireCommand extends Command

public function __construct(
private readonly ImportMapManager $importMapManager,
private readonly string $projectDir,
private readonly ImportMapVersionChecker $importMapVersionChecker,
) {
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\Exception\CircularAssetsException;
use Symfony\Component\AssetMapper\Exception\RuntimeException;
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
use Symfony\Component\AssetMapper\ImportMap\JavaScriptImport;
use Symfony\Component\AssetMapper\MappedAsset;

Expand All @@ -32,7 +32,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
private const IMPORT_PATTERN = '/(?:import\s*(?:(?:\*\s*as\s+\w+|[\w\s{},*]+)\s*from\s*)?|\bimport\()\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]?/m';

public function __construct(
private readonly ImportMapManager $importMapManager,
private readonly ImportMapConfigReader $importMapConfigReader,
private readonly string $missingImportMode = self::MISSING_IMPORT_WARN,
private readonly ?LoggerInterface $logger = null,
) {
Expand Down Expand Up @@ -139,7 +139,7 @@ private function isCommentedOut(mixed $offsetStart, string $fullContent): bool

private function findAssetForBareImport(string $importedModule, AssetMapperInterface $assetMapper): ?MappedAsset
{
if (!$importMapEntry = $this->importMapManager->findRootImportMapEntry($importedModule)) {
if (!$importMapEntry = $this->importMapConfigReader->findRootImportMapEntry($importedModule)) {
// don't warn on missing non-relative (bare) imports: these could be valid URLs

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public function writeEntries(ImportMapEntries $entries): void
EOF);
}

public function findRootImportMapEntry(string $moduleName): ?ImportMapEntry
{
$entries = $this->getEntries();

return $entries->has($moduleName) ? $entries->get($moduleName) : null;
}

public function createRemoteEntry(string $importName, ImportMapType $type, string $version, string $packageModuleSpecifier, bool $isEntrypoint): ImportMapEntry
{
$path = $this->remotePackageStorage->getDownloadPath($packageModuleSpecifier, $type);
Expand Down
Loading