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

Commit93f53fe

Browse files
bug#51065 [AssetMapper] Fixing import parsing from jsdelivr (weaverryan)
This PR was merged into the 6.3 branch.Discussion----------[AssetMapper] Fixing import parsing from jsdelivr| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets | None - thanks to conversation with `@bendavies` on Slack!| License | MIT| Doc PR | n/aFound with:https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/+esmWith the `importmap:require --download` option, we parse those `import` statements to discover which dependencies we also need to download. If a package required 2 imports and both do *not* have an `@` in their name (i.e. a namespaced package), the regex matched both package strings as a single package - so it would see the package name as `jquery@3.7.0/+esm";import e from"/npm/popper.js@1.16.1/+esm`.Cheers!Commits-------9918d35 [AssetMapper] Fixing import parsing from jsdelivr
2 parents0f3e24c +9918d35 commit93f53fe

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2525
publicconstURL_PATTERN_VERSION ='https://data.jsdelivr.com/v1/packages/npm/%s/resolved?specifier=%s';
2626
publicconstURL_PATTERN_DIST ='https://cdn.jsdelivr.net/npm/%s@%s%s/+esm';
2727

28+
publicconstIMPORT_REGEX ='{from"/npm/([^@]*@?[\S]+)@([^/]+)/\+esm"}';
29+
2830
privateHttpClientInterface$httpClient;
2931

3032
publicfunction__construct(
@@ -129,8 +131,7 @@ public function resolvePackages(array $packagesToRequire): array
129131
privatefunctionparseJsDelivrImports(string$content,array &$dependencies,bool$download,bool$preload):string
130132
{
131133
// imports from jsdelivr follow a predictable format
132-
$regex ='{from"/npm/([^@]*@?[^@]+)@([^/]+)/\+esm"}';
133-
$content =preg_replace_callback($regex,function ($matches)use (&$dependencies,$download,$preload) {
134+
$content =preg_replace_callback(self::IMPORT_REGEX,function ($matches)use (&$dependencies,$download,$preload) {
134135
$packageName =$matches[1];
135136
$version =$matches[2];
136137

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,22 @@ public static function provideResolvePackagesTests(): iterable
234234
],
235235
];
236236
}
237+
238+
publicfunctiontestImportRegex()
239+
{
240+
$subject ='import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";import t from"/npm/jquery@3.7.0/+esm";import e from"/npm/popper.js@1.16.1/+esm";console.log("yo");';
241+
preg_match_all(JsDelivrEsmResolver::IMPORT_REGEX,$subject,$matches);
242+
243+
$this->assertCount(3,$matches[0]);
244+
$this->assertSame([
245+
'@kurkle/color',
246+
'jquery',
247+
'popper.js',
248+
],$matches[1]);
249+
$this->assertSame([
250+
'0.3.2',
251+
'3.7.0',
252+
'1.16.1',
253+
],$matches[2]);
254+
}
237255
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp