Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WIP] [AssetMapper] Allow Asset Mapper to use other package resolvers#54133

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
adeys wants to merge6 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromadeys:asset-mapper-custom-resolver

Conversation

adeys
Copy link

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?yes
IssuesFix#53999
LicenseMIT

This PR allows to provide a specific package resolver when running theimportmap:require command.
This is useful when the required package cannot be built or found with the default package resolver (JsDeliver).

It adds aresolver option to the command that resolves to the default package resolver when none is provided.
The default package resolver can also be changed by mapping theasset_mapper.importmap.resolver service to a custom resolver implementing\Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface.
So the command will look like :
bin/console importmap:require some-package --resolver=resolver

For now only the base implementation is added. I'll provide one or two package resolvers as example

  • submit changes to the documentation
  • add more resolvers (unpkg ? jspm ?)

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@adeysadeys changed the title[AssetMapper] Allow Asset Mapper to use other package resolvers[WIP] [AssetMapper] Allow Asset Mapper to use other package resolversMar 1, 2024
@smnandre
Copy link
Member

How would you handle updates ? If you had to select a specific resolver to require a module, i guess the update won't go well unless using the same resolver ?

@@ -167,7 +168,7 @@
service('asset_mapper'),
service('asset_mapper.importmap.config_reader'),
service('asset_mapper.importmap.remote_package_downloader'),
service('asset_mapper.importmap.resolver'),
service('asset_mapper.importmap.resolver_registry'),
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest using a strategy/facade resolver with the same interface.. i don't think this registry should be exposed.. Maybe it would be better to mimic Notifier Transports class ?

Copy link
Author

Choose a reason for hiding this comment

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

I will check the Notifier Transports implementation then.

I exposed it here as I didn't have found another way to allow theImportMapManager to pick the right resolver depending on the package 😅

@@ -44,6 +44,7 @@ protected function configure(): void
->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The packages to add')
->addOption('entrypoint', null, InputOption::VALUE_NONE, 'Make the package(s) an entrypoint?')
->addOption('path', null, InputOption::VALUE_REQUIRED, 'The local path where the package lives relative to the project root')
->addOption('resolver', null, InputOption::VALUE_REQUIRED, 'The alias of the package resolver to use')
Copy link
Member

Choose a reason for hiding this comment

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

This,imho cannot offer a predictable DX as importmap:install / importmap:require / importmap:update (etc..) would then be inconsistent.

Copy link
Author

Choose a reason for hiding this comment

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

I think it won't have an impact as the resolver config is added to the importmap file.
During(importmap:install / importmap:update) commands, if a custom resolver was provided, it will be used, otherwise the default one (jsdeliver) will be used.
It will just be a matter of editingimportmap.php

{
return new self($importName, $importMapType, $path, $isEntrypoint, $version, $packageModuleSpecifier);
return new self($importName, $importMapType, $path, $isEntrypoint, $resolver, $version, $packageModuleSpecifier);
Copy link
Member

Choose a reason for hiding this comment

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

This would break BC no ?

Copy link
Author

Choose a reason for hiding this comment

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

IMHO no, as a default resolver is provided in the asset mapper config
As this part is not exposed (I think), it will just be resolved internally

@@ -27,7 +27,7 @@ public function __construct(
private readonly AssetMapperInterface $assetMapper,
private readonly ImportMapConfigReader $importMapConfigReader,
private readonly RemotePackageDownloader $packageDownloader,
private readonlyPackageResolverInterface $resolver,
private readonlyPackageResolverRegistry $resolverRegistry,
Copy link
Member

Choose a reason for hiding this comment

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

Cannot do this without breaking BC i think

Copy link
Author

Choose a reason for hiding this comment

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

I'd like to have a little explanation here then 😅

Choose a reason for hiding this comment

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

that's a BC break indeed for people that use the class directly without the FWB integration

@adeys
Copy link
Author

How would you handle updates ? If you had to select a specific resolver to require a module, i guess the update won't go well unless using the same resolver ?

As for now, there won't be any problem during update as theImportMapManager can pick the right resolver to check and perform the update for each package. Even if the resolver was changed, the default one will be used to get fresh package files as the old files are removed first in the upgrade process

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Sorry, the current BC layer (or lack of) needs to be improved to be up to our standards.
Think that the component can be used standalone. Seehttp://symfony.com/bc for what can and cannot be done. For most changes, we do have patterns to create working BC layers. Branch 6.4 contains a lot if you need inspiration. We're here to help also of course.

@@ -127,11 +133,11 @@ public function findRootImportMapEntry(string $moduleName): ?ImportMapEntry
return $entries->has($moduleName) ? $entries->get($moduleName) : null;
}

public function createRemoteEntry(string $importName, ImportMapType $type, string $version, string $packageModuleSpecifier, bool $isEntrypoint): ImportMapEntry
public function createRemoteEntry(string $importName, ImportMapType $type, string $version, string $packageModuleSpecifier, bool $isEntrypoint, ?string $resolver): ImportMapEntry

Choose a reason for hiding this comment

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

adding an argument is a BC break so we need to either find another approach or do a proper BC layer (using@param + func_get_arg, see branch 6.4 for inspiration)

@@ -26,6 +26,7 @@ private function __construct(
*/
public readonly string $path,
public readonly bool $isEntrypoint,
public readonly ?string $resolverAlias,

Choose a reason for hiding this comment

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

adding an new required argument is a BC break

@@ -27,7 +27,7 @@ public function __construct(
private readonly AssetMapperInterface $assetMapper,
private readonly ImportMapConfigReader $importMapConfigReader,
private readonly RemotePackageDownloader $packageDownloader,
private readonlyPackageResolverInterface $resolver,
private readonlyPackageResolverRegistry $resolverRegistry,

Choose a reason for hiding this comment

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

that's a BC break indeed for people that use the class directly without the FWB integration

@@ -112,6 +112,7 @@ private function updateImportMapConfig(bool $update, array $packagesToRequire, a
$entry->packageModuleSpecifier,
null,
$importName,
resolver: $entry->resolverAlias,

Choose a reason for hiding this comment

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

no named args if not needed please

/**
* Returns the alias of the resolver.
*/
public function getAlias(): string;

Choose a reason for hiding this comment

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

adding a method to an interface is a BC break also

@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@AienTech
Copy link

AienTech commentedAug 26, 2024
edited
Loading

Any plans to release this feature? or any work around suggestions till it is officially releases (I've already gave"symfony/asset-mapper": "7.2.x-dev" a shot)?

jsdelivr is causing some issues recently:

/** * Failed to bundle using Rollup v2.79.1: failed to resolve an internal import. * If you believe this to be an issue with jsDelivr, and not with the package itself, please open an issue at https://github.com/jsdelivr/jsdelivr */thrownewError('Failed to bundle using Rollup v2.79.1: failed to resolve an internal import. If you believe this to be an issue with jsDelivr, and not with the package itself, please open an issue at https://github.com/jsdelivr/jsdelivr');

and just out of curiosity, why not getting the packages directly from npmjs.org repos?

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@smnandresmnandresmnandre left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

[AssetMapper] Allow to import assets from url or using other resolvers
7 participants
@adeys@carsonbot@smnandre@AienTech@nicolas-grekas@fabpot@xabbuh

[8]ページ先頭

©2009-2025 Movatter.jp