8000 bug #52325 [AssetMapper] jsdelivr "no version" import syntax (weaverr… · symfony/symfony@60dec0b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 60dec0b

Browse files
committed
bug #52325 [AssetMapper] jsdelivr "no version" import syntax (weaverryan)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] jsdelivr "no version" import syntax | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT Hi! Another new import case from jsdelivr - found in a real project. The module in question - https://cdn.jsdelivr.net/npm/`@toast`-ui/editor@3.2.2/+esm This is, I believe, a misconfiguration in that package (PR opened) where they `import` `prosemirror-transform` but do not list this as a dependency in their `package.json`. Regardless, we now handle this. And i've removed a warning about this... as the user has done nothing wrong. Cheers! Commits ------- f77a188 [AssetMapper] jsdelivr "no version" import syntax
2 parents 009f68b + f77a188 commit 60dec0b

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

src/Symfony/Component/AssetMapper/Command/VersionProblemCommandTrait.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ private function renderVersionProblems(ImportMapVersionChecker $importMapVersion
2929
continue;
3030
}
3131

32-
if (null === $problem->requiredVersionConstraint) {
33-
$output->writeln(sprintf('[warning] <info>%s</info> appears to import <info>%s</info> but this is not listed as a dependency of <info>%s</info>. This is odd and could be a misconfiguration of that package.', $problem->packageName, $problem->dependencyPackageName, $problem->packageName));
34-
35-
continue;
36-
}
37-
3832
$output->writeln(sprintf('[warning] <info>%s</info> requires <info>%s</info>@<comment>%s</comment> but version <comment>%s</comment> is installed.', $problem->packageName, $problem->dependencyPackageName, $problem->requiredVersionConstraint, $problem->installedVersion));
3933
}
4034
}

src/Symfony/Component/AssetMapper/ImportMap/ImportMapVersionChecker.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ public function checkVersions(): array
8787
}
8888

8989
$dependencyPackageName = $entries->get($dependencyName)->getPackageName();
90-
$dependencyVersionConstraint = $packageDependencies[$dependencyPackageName] ?? null;
91-
92-
if (null === $dependencyVersionConstraint) {
93-
$problems[] = new PackageVersionProblem($packageName, $dependencyPackageName, $dependencyVersionConstraint, $entries->get($dependencyName)->version);
9490

91+
if (!isset($packageDependencies[$dependencyPackageName])) {
9592
continue;
9693
}
9794

95+
$dependencyVersionConstraint = $packageDependencies[$dependencyPackageName];
96+
9897
if (!$this->isVersionSatisfied($dependencyVersionConstraint, $entries->get($dependencyName)->version)) {
9998
$problems[] = new PackageVersionProblem($packageName, $dependencyPackageName, $dependencyVersionConstraint, $entries->get($dependencyName)->version);
10099
}

src/Symfony/Component/AssetMapper/ImportMap/PackageVersionProblem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class PackageVersionProblem
1616
public function __construct(
1717
public readonly string $packageName,
1818
public readonly string $dependencyPackageName,
19-
public readonly ?string $requiredVersionConstraint,
19+
public readonly string $requiredVersionConstraint,
2020
public readonly ?string $installedVersion
2121
) {
2222
}

src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2626
public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm';
2727
public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints';
2828

29-
public const IMPORT_REGEX = '{from"/npm/((?:@[^/]+/)?[^@]+)@([^/]+)((?:/[^/]+)*?)/\+esm"}';
29+
public const IMPORT_REGEX = '{from"/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm"}';
3030

3131
private HttpClientInterface $httpClient;
3232

@@ -222,7 +222,7 @@ private function fetchPackageRequirementsFromImports(string $content): array
222222
preg_match_all(self::IMPORT_REGEX, $content, $matches);
223223
$dependencies = [];
224224
foreach ($matches[1] as $index => $packageName) {
225-
$version = $matches[2][$index];
225+
$version = $matches[2][$index] ?: null;
226226
$packageName .= $matches[3][$index]; // add the path if any
227227

228228
$dependencies[] = new PackageRequireOptions($packageName, $version);

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapVersionCheckerTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,6 @@ public static function getCheckVersionsTests()
220220
],
221221
];
222222

223-
yield 'single that imports something that is not required by the package' => [
224-
[
225-
self::createRemoteEntry('foo', version: '1.0.0'),
226-
self::createRemoteEntry('bar', version: '1.5.0'),
227-
],
228-
[
229-
'foo' => ['bar'],
230-
'bar' => [],
231-
],
232-
[
233-
[
234-
'url' => '/foo/1.0.0',
235-
'response' => [
236-
'dependencies' => [],
237-
],
238-
],
239-
],
240-
[
241-
new PackageVersionProblem('foo', 'bar', null, '1.5.0'),
242-
],
243-
];
244-
245223
yield 'single with npm-style constraint' => [
246224
[
247225
self::createRemoteEntry('foo', version: '1.0.0'),

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ public static function provideImportRegex(): iterable
513513
['locutus/php/strings/vsprintf', '2.0.16'],
514514
],
515515
];
516+
517+
yield 'import statements without a version' => [
518+
'import{ReplaceAroundStep as c,canSplit as d,StepMap as p,liftTarget as f}from"/npm/prosemirror-transform/+esm";import{PluginKey as h,EditorState as m,TextSelection as v,Plugin as g,AllSelection as y,Selection as b,NodeSelection as w,SelectionRange as k}from"/npm/prosemirror-state@1.4.3/+esm";',
519+
[
520+
['prosemirror-transform', ''],
521+
['prosemirror-state', '1.4.3'],
522+
],
523+
];
524+
525+
yield 'import statements without a version and with paths' => [
526+
'import{ReplaceAroundStep as c,canSplit as d,StepMap as p,liftTarget as f}from"/npm/prosemirror-transform/php/strings/vsprintf/+esm";import{PluginKey as h,EditorState as m,TextSelection as v,Plugin as g,AllSelection as y,Selection as b,NodeSelection as w,SelectionRange as k}from"/npm/prosemirror-state@1.4.3/php/strings/sprintf/+esm";',
527+
[
528+
['prosemirror-transform/php/strings/vsprintf', ''],
529+
['prosemirror-state/php/strings/sprintf', '1.4.3'],
530+
],
531+
];
516532
}
517533

518534
private static function createRemoteEntry(string $importName, string $version, ImportMapType $type = ImportMapType::JS, string $packageSpecifier = null): ImportMapEntry

0 commit comments

Comments
 (0)
0