-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
[AssetMapper] Allow to define entrypoint in importmap.php #1026
base: 2.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -147,7 +147,7 @@ private function resolveImportMapPackages($phpPackage): array | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
$dependencies = []; | ||||||||||||||
|
||||||||||||||
$entrypoints = $packageJson->read()['symfony']['entrypoints'] ?? []; | ||||||||||||||
foreach ($packageJson->read()['symfony']['importmap'] ?? [] as $importMapName => $constraintConfig) { | ||||||||||||||
if (\is_array($constraintConfig)) { | ||||||||||||||
$constraint = $constraintConfig['version'] ?? []; | ||||||||||||||
|
@@ -163,6 +163,7 @@ private function resolveImportMapPackages($phpPackage): array | |||||||||||||
|
||||||||||||||
$dependencies[$importMapName] = [ | ||||||||||||||
'path' => $path, | ||||||||||||||
'entrypoint' => \in_array($importMapName, $entrypoints, true), | ||||||||||||||
]; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (update) collapsed my comment here: it was not constructiveBy definition, a dependency cannot be an importmap entrypoint :) |
||||||||||||||
|
||||||||||||||
continue; | ||||||||||||||
|
@@ -239,7 +240,7 @@ private function shouldUpdateConstraint(string $existingConstraint, string $cons | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @param array<string, array{path?: string, package?: string, version?: string}> $importMapEntries | ||||||||||||||
* @param array<string, array{path?: string, package?: string, version?: string, entrypoint?: bool}> $importMapEntries | ||||||||||||||
*/ | ||||||||||||||
private function updateImportMap(array $importMapEntries): void | ||||||||||||||
{ | ||||||||||||||
|
@@ -267,8 +268,14 @@ private function updateImportMap(array $importMapEntries): void | |||||||||||||
$this->io->writeError(sprintf('Updating package <comment>%s</> from <info>%s</> to <info>%s</>.', $name, $version, $versionConstraint)); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$arguments = []; | ||||||||||||||
fabpot marked this conversation as resolved.
Show resolved
Hide resolved
Jibbarth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
if (isset($importMapEntry['entrypoint']) && true === $importMapEntry['entrypoint']) { | ||||||||||||||
$arguments[] = '--entrypoint'; | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This must be updated (moved in the code -- see below) as it will potentially generate an incorrect state. Entrypoints cannot be remote packages.In ImportMapGenerator if ($rootImportEntries->get($entryName)->isRemotePackage()) {
throw new \InvalidArgumentException(\sprintf('The entrypoint "%s" is a remote package and cannot be used as an entrypoint.', $entryName));
} Remote package = package with a versionIn ImportMapEntry.php public function isRemotePackage(): bool
{
return null !== $this->version;
} Version and path are exclusive propertiesIn ImportMapConfigReader.php if (isset($data['version'])) {
throw new RuntimeException(\sprintf('The importmap entry "%s" cannot have both a "path" and "version" option.', $importName));
} Package have either version or pathIn ImportMapConfigReader.php if (null === $version) {
throw new RuntimeException(\sprintf('The importmap entry "%s" must have either a "path" or "version" option.', $importName));
} Tip So entrypoints must be local. And this must be moved line Another question: should we allow overriding existing user entrypoints? Do we want to allow that ? |
||||||||||||||
|
||||||||||||||
if (isset($importMapEntry['path'])) { | ||||||||||||||
$arguments = [$name, '--path='.$importMapEntry['path']]; | ||||||||||||||
$arguments[] = $name; | ||||||||||||||
$arguments[] = '--path='.$importMapEntry['path']; | ||||||||||||||
$this->scriptExecutor->execute( | ||||||||||||||
'symfony-cmd', | ||||||||||||||
'importmap:require', | ||||||||||||||
|
@@ -283,7 +290,7 @@ private function updateImportMap(array $importMapEntries): void | |||||||||||||
if ($importMapEntry['package'] !== $name) { | ||||||||||||||
$packageName .= '='.$name; | ||||||||||||||
} | ||||||||||||||
$arguments = [$packageName]; | ||||||||||||||
$arguments[] = $packageName; | ||||||||||||||
$this->scriptExecutor->execute( | ||||||||||||||
'symfony-cmd', | ||||||||||||||
'importmap:require', | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took some time to refresh my memory and re-read all this code 😅
So .. nope : this is not related to importmap entrypoints, but to stimulus bundle + controllers.json file. Thus should not be used here :)
Should not be used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a pure technical level, we may want to use another key, and definitively one nested under the
importmap
key.The [symfony][entrypoints] is used by flex and is or has been used by stimulus bundle / stimulus bridge / webpack encore bundle.
flex/src/PackageJsonSynchronizer.php
Lines 365 to 370 in 1418926
Meaning it would have different meaning, and
behaviour
, wether someone uses Webpack or AssetMapper.Maybe there is something to do in the symfony[importmap][ PACKAGE_NAME ] key.
Currently we allow here two shapes
and
As seen in my other comment, the first one is out of scope (entrypoints cannot have version).
But I suppose you could here allow another array syntax, like
Or something like replace
path:
withentrypoint:
(that would give the path and specifu an entrypointà)