8000 [AssetMapper] jsdelivr "no version" import syntax by weaverryan · Pull Request #52325 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[AssetMapper] jsdelivr "no version" import syntax #52325

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
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
[AssetMapper] jsdelivr "no version" import syntax
  • Loading branch information
weaverryan authored and fabpot committed Oct 27, 2023
commit f77a188394a7b74aeeef6713180ddc6cbaacd840
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ private function renderVersionProblems(ImportMapVersionChecker $importMapVersion
continue;
}

if (null === $problem->requiredVersionConstraint) {
$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));

continue;
}

$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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ public function checkVersions(): array
}

$dependencyPackageName = $entries->get($dependencyName)->getPackageName();
$dependencyVersionConstraint = $packageDependencies[$dependencyPackageName] ?? null;

if (null === $dependencyVersionConstraint) {
$problems[] = new PackageVersionProblem($packageName, $dependencyPackageName, $dependencyVersionConstraint, $entries->get($dependencyName)->version);

if (!isset($packageDependencies[$dependencyPackageName])) {
continue;
}

$dependencyVersionConstraint = $packageDependencies[$dependencyPackageName];

if (!$this->isVersionSatisfied($dependencyVersionConstraint, $entries->get($dependencyName)->version)) {
$problems[] = new PackageVersionProblem($packageName, $dependencyPackageName, $dependencyVersionConstraint, $entries->get($dependencyName)->version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PackageVersionProblem
public function __construct(
public readonly string $packageName,
public readonly string $dependencyPackageName,
public readonly ?string $requiredVersionConstraint,
public readonly string $requiredVersionConstraint,
public readonly ?string $installedVersion
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm';
public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints';

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

private HttpClientInterface $httpClient;

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

$dependencies[] = new PackageRequireOptions($packageName, $version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,28 +220,6 @@ public static function getCheckVersionsTests()
],
];

yield 'single that imports something that is not required by the package' => [
[
self::createRemoteEntry('foo', version: '1.0.0'),
self::createRemoteEntry('bar', version: '1.5.0'),
],
[
'foo' => ['bar'],
'bar' => [],
],
[
[
'url' => '/foo/1.0.0',
'response' => [
'dependencies' => [],
],
],
],
[
new PackageVersionProblem('foo', 'bar', null, '1.5.0'),
],
];

yield 'single with npm-style constraint' => [
[
self::createRemoteEntry('foo', version: '1.0.0'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ public static function provideImportRegex(): iterable
['locutus/php/strings/vsprintf', '2.0.16'],
],
];

yield 'import statements without a version' => [
'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";',
[
['prosemirror-transform', ''],
['prosemirror-state', '1.4.3'],
],
];

yield 'import statements without a version and with paths' => [
'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";',
[
['prosemirror-transform/php/strings/vsprintf', ''],
['prosemirror-state/php/strings/sprintf', '1.4.3'],
],
];
}

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